Next: , Previous: ABI, Up: Controlling GDB


22.8 Automatically loading associated files

gdb sometimes reads files with commands and settings automatically, without being explicitly told so by the user. We call this feature auto-loading. While auto-loading is useful for automatically adapting gdb to the needs of your project, it can sometimes produce unexpected results or introduce security risks (e.g., if the file comes from untrusted sources).

There are various kinds of files gdb can automatically load. In addition to these files, gdb supports auto-loading code written in various extension languages. See Auto-loading extensions.

Note that loading of these associated files (including the local .gdbinit file) requires accordingly configured auto-load safe-path (see Auto-loading safe path).

For these reasons, gdb includes commands and options to let you control when to auto-load files and which files should be auto-loaded.

set auto-load off
Globally disable loading of all auto-loaded files. You may want to use this command with the ‘-iex’ option (see Option -init-eval-command) such as:
          $ gdb -iex "set auto-load off" untrusted-executable corefile

Be aware that system init file (see System-wide configuration) and init files from your home directory (see Home Directory Init File) still get read (as they come from generally trusted directories). To prevent gdb from auto-loading even those init files, use the -nx option (see Mode Options), in addition to set auto-load no.


show auto-load
Show whether auto-loading of each specific ‘auto-load’ file(s) is enabled or disabled.
          (gdb) show auto-load
          gdb-scripts:  Auto-loading of canned sequences of commands scripts is on.
          libthread-db:  Auto-loading of inferior specific libthread_db is on.
          local-gdbinit:  Auto-loading of .gdbinit script from current directory
                          is on.
          python-scripts:  Auto-loading of Python scripts is on.
          safe-path:  List of directories from which it is safe to auto-load files
                      is $debugdir:$datadir/auto-load.
          scripts-directory:  List of directories from which to load auto-loaded scripts
                              is $debugdir:$datadir/auto-load.


info auto-load
Print whether each specific ‘auto-load’ file(s) have been auto-loaded or not.
          (gdb) info auto-load
          gdb-scripts:
          Loaded  Script
          Yes     /home/user/gdb/gdb-gdb.gdb
          libthread-db:  No auto-loaded libthread-db.
          local-gdbinit:  Local .gdbinit file "/home/user/gdb/.gdbinit" has been
                          loaded.
          python-scripts:
          Loaded  Script
          Yes     /home/user/gdb/gdb-gdb.py

These are gdb control commands for the auto-loading:

See set auto-load off. Disable auto-loading globally.
See show auto-load. Show setting of all kinds of files.
See info auto-load. Show state of all kinds of files.
See set auto-load gdb-scripts. Control for gdb command scripts.
See show auto-load gdb-scripts. Show setting of gdb command scripts.
See info auto-load gdb-scripts. Show state of gdb command scripts.
See set auto-load python-scripts. Control for gdb Python scripts.
See show auto-load python-scripts. Show setting of gdb Python scripts.
See info auto-load python-scripts. Show state of gdb Python scripts.
See set auto-load guile-scripts. Control for gdb Guile scripts.
See show auto-load guile-scripts. Show setting of gdb Guile scripts.
See info auto-load guile-scripts. Show state of gdb Guile scripts.
See set auto-load scripts-directory. Control for gdb auto-loaded scripts location.
See show auto-load scripts-directory. Show gdb auto-loaded scripts location.
See add-auto-load-scripts-directory. Add directory for auto-loaded scripts location list.
See set auto-load local-gdbinit. Control for init file in the current directory.
See show auto-load local-gdbinit. Show setting of init file in the current directory.
See info auto-load local-gdbinit. Show state of init file in the current directory.
See set auto-load libthread-db. Control for thread debugging library.
See show auto-load libthread-db. Show setting of thread debugging library.
See info auto-load libthread-db. Show state of thread debugging library.
See set auto-load safe-path. Control directories trusted for automatic loading.
See show auto-load safe-path. Show directories trusted for automatic loading.
See add-auto-load-safe-path. Add directory trusted for automatic loading.