https://gcc.gnu.org/g:f01df5e47b2551e0f435a9efa8e0a30142f3d46b
commit r15-2715-gf01df5e47b2551e0f435a9efa8e0a30142f3d46b Author: Alex Coplan <alex.cop...@arm.com> Date: Mon Aug 5 08:45:58 2024 +0100 gdbhooks: Add attempt to invoke on-gcc-hooks-load 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. Diff: --- gcc/gdbhooks.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py index db8ce0d071bb..7a64c03b8acb 100644 --- a/gcc/gdbhooks.py +++ b/gcc/gdbhooks.py @@ -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')