.gdbinit errors are annoyingly hard to spot

I wasted almost an hour of my time recently trying to figure out how to configure a home directory .gdbinit file. It’s been some time since I had to set up a new firmware project to debug with GDB, but I figured I could just copy the .gdbinit file from a working past project to the new project directory to do basic GDB setup scoped specifically to that directory. The only commands I needed to run were simple: load a binary, connect to the target, and run. The whopping four-line .gdbinit text is below.

target extended-remote :3333
load
b main
c

When running GDB, however, I was greeted with this error:

[1747] brianteam@BTeams-MacBook-Pro ~/.../project/project-firmware (master) $ arm-none-eabi-gdb
GNU gdb (Arm GNU Toolchain 11.3.Rel1) 12.1.90.20220802-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin19.6.0 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.linaro.org/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
No symbol table is loaded.  Use the "file" command.
warning: File "/Users/brianteam/Developer/project/project-firmware/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
        add-auto-load-safe-path /Users/brianteam/Developer/project/project-firmware/.gdbinit
line to your configuration file "/Users/brianteam/.gdbinit".
To completely disable this security protection add
        set auto-load safe-path /
line to your configuration file "/Users/brianteam/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
        info "(gdb)Auto-loading safe path"
(gdb)

It seemed simple enough - I’m probably just running a newer version of GDB that now has more restrictions for loading .gdbinit files. No problem, I added the add-auto-load-safe-path line to my home directory .gdbinit file and re-ran GDB. For some reason, I got what I thought was the exact same output.

[1748] brianteam@BTeams-MacBook-Pro ~/.../project/project-firmware (master) arm-none-eabi-gdb
GNU gdb (Arm GNU Toolchain 11.3.Rel1) 12.1.90.20220802-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin19.6.0 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.linaro.org/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
/Users/brianteam/.gdbinit:1: Error in sourced command file:
No symbol table is loaded.  Use the "file" command.
warning: File "/Users/brianteam/Developer/project/project-firmware/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
        add-auto-load-safe-path /Users/brianteam/Developer/project/project-firmware/.gdbinit
line to your configuration file "/Users/brianteam/.gdbinit".
To completely disable this security protection add
        set auto-load safe-path /
line to your configuration file "/Users/brianteam/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
        info "(gdb)Auto-loading safe path"
(gdb)

Odd, but I tried the second option for adding all directories to the safe load path to see if it was a path issue. Still the same error. I went down a deep rabbit hole of listing the order in which different .gdbinit files were sourced, making changes to my local and home directory file, and more. Nothing I did could get the error to go away.

At some point probably around minute 45 of this detour from actual productive work, I went down the output line by line and realized how dumb I had been. Halfway down the output and right between the version header and the auto-load warning was this annoying little line:

/Users/brianteam/.gdbinit:1: Error in sourced command file:

The entire time the .gdbinit file had been getting sourced just fine, there was just an error so it was failing out at line one. I assumed that if there was an issue with the file it would fail harder than just a single output line and continuation of normal startup. I don’t even remember what the problem was at this point, I think I probably had an extra space character in between a dash and the next letter of the command.

Clearly, this is almost entirely my fault and again, very dumb, but I feel like errors in sourced config files could be displayed a bit more obviously to the user. Even just separating it with a newline above and below would have helped tremendously. At least I’ll never make that mistake again.