]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gdbhooks: Add attempt to invoke on-gcc-hooks-load
authorAlex Coplan <alex.coplan@arm.com>
Mon, 5 Aug 2024 07:45:58 +0000 (08:45 +0100)
committerAlex Coplan <alex.coplan@arm.com>
Mon, 5 Aug 2024 07:45:58 +0000 (08:45 +0100)
This extends GCC's GDB hooks to attempt invoking the user-defined
command "on-gcc-hooks-load".  The idea is that users can define the
command in their .gdbinit to override the default values of parameters
defined by GCC's GDB extensions.

For example, together with the previous patch, I can add the following
fragment to my .gdbinit:

define on-gcc-hooks-load
  set gcc-dot-cmd xdot
end

which means, once the GCC extensions get loaded, whenever I invoke
dot-fn then the graph will be rendered using xdot.

The try/except should make this patch a no-op for users that don't
currently define this command.  I looked for a way to test explicitly
for whether a GDB command exists but didn't find one.

This is needed because the user's .gdbinit is sourced before GCC's GDB
extensions are loaded, and GCC-specific parameters can't be configured
before they are defined.

gcc/ChangeLog:

* gdbhooks.py: Add attempted call to "on-gcc-hooks-load" once
we've finished loading the hooks.

gcc/gdbhooks.py

index db8ce0d071bb294d33062302cb9b26e4e2f46b50..7a64c03b8acb51559cf88caf7e93463968784bf9 100644 (file)
@@ -865,4 +865,12 @@ class DotFn(gdb.Command):
 
 DotFn()
 
+# Try and invoke the user-defined command "on-gcc-hooks-load".  Doing
+# this allows users to customize the GCC extensions once they've been
+# loaded by defining the hook in their .gdbinit.
+try:
+    gdb.execute('on-gcc-hooks-load')
+except gdb.error:
+    pass
+
 print('Successfully loaded GDB hooks for GCC')