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. As an alternative (to avoid having the callback), I considered having the user define a convenience variable with a well-known name and using that (if defined) in gdbhooks.py to set the default value for gcc-dot-cmd. But that seemed like a hack. I'd be interested to hear from any GDB experts if there's a better way of managing configuration like this. Tested by invoking dot-fn with/without the above fragment in my .gdbinit and observing the change in dot renderer. OK to install? Thanks, Alex gcc/ChangeLog: * gdbhooks.py: Add attempted call to "on-gcc-hooks-load" once we've finished loading the hooks.
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py index db8ce0d071b..7a64c03b8ac 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')