As the files of inferior can come from untrusted source (such as submitted by an application user) gdb does not always load any files automatically. gdb provides the ‘set auto-load safe-path’ setting to list directories trusted for loading files not explicitly requested by user. Each directory can also be a shell wildcard pattern.
If the path is not set properly you will see a warning and the file will not get loaded:
$ ./gdb -q ./gdb Reading symbols from /home/user/gdb/gdb...done. warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To instruct gdb to go ahead and use the init files anyway, invoke gdb like this:
$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
The list of trusted directories is controlled by the following commands:
set auto-load safe-path[directories]
FNM_PATHNAMEfor system function
fnmatch(see fnmatch). If you omit directories, ‘auto-load safe-path’ will be reset to its default value as specified during gdb compilation.
The list of directories uses path separator (‘:’ on GNU and Unix systems, ‘;’ on MS-Windows and MS-DOS) to separate directories, similarly to the PATH environment variable.
show auto-load safe-path
This variable defaults to what
--with-auto-load-dir has been configured
to (see with-auto-load-dir). $debugdir and $datadir
substitution applies the same as for set auto-load scripts-directory.
set auto-load safe-path value can be also overriden by
gdb configuration option --with-auto-load-safe-path.
Setting this variable to / disables this security protection, corresponding gdb configuration option is --without-auto-load-safe-path. This variable is supposed to be set to the system directories writable by the system superuser only. Users can add their source directories in init files in their home directories (see Home Directory Init File). See also deprecated init file in the current directory (see Init File in the Current Directory during Startup).
To force gdb to load the files it declined to load in the previous example, you could use one of the following ways:
On the other hand you can also explicitly forbid automatic files loading which also suppresses any such warning messages:
This setting applies to the file names as entered by user. If no entry matches gdb tries as a last resort to also resolve all the file names into their canonical form (typically resolving symbolic links) and compare the entries again. gdb already canonicalizes most of the filenames on its own before starting the comparison so a canonical form of directories is recommended to be entered.