When a new object file is read (for example, due to the file
command, or because the inferior has loaded a shared library),
gdb will look for a file named objfile-gdb.py,
where objfile is the object file's real name, formed by ensuring
that the file name is absolute, following all symlinks, and resolving
.
and ..
components. If this file exists and is
readable, gdb will evaluate it as a Python script.
If this file does not exist, and if the parameter
debug-file-directory
is set (see Separate Debug Files),
then gdb will use the file named
debug-file-directory/real-name, where
real-name is the object file's real name, as described above.
Finally, if this file does not exist, then gdb will look for
a file named data-directory/python/auto-load/real-name, where
data-directory is gdb's data directory (available via
show data-directory
, see Data Files), and real-name
is the object file's real name, as described above.
When reading an auto-loaded file, gdb sets the “current
objfile”. This is available via the gdb.current_objfile
function (see Objfiles In Python). This can be useful for
registering objfile-specific pretty-printers.
The auto-loading feature is useful for supplying application-specific debugging commands and scripts. You can enable or disable this feature, and view its current state.
maint set python auto-load [yes|no]
show python auto-load
gdb does not track which files it has already auto-loaded. So, your ‘-gdb.py’ file should take care to ensure that it may be evaluated multiple times without error.