diff mbox series

[1/2] gdbhooks: Make dot viewer configurable

Message ID ZqtR+OglZdpSkZ0i@arm.com
State New
Headers show
Series [1/2] gdbhooks: Make dot viewer configurable | expand

Commit Message

Alex Coplan Aug. 1, 2024, 9:14 a.m. UTC
Hi,

This adds a new GDB parameter 'gcc-dot-cmd' which allows the user to
configure the command used to render the CFG within dot-fn.

E.g. with this patch the user can change their dot viewer like so:

(gdb) show gcc-dot-cmd
The current value of 'gcc-dot-cmd' is "dot -Tx11".
(gdb) set gcc-dot-cmd xdot
(gdb) dot-fn # opens in xdot

The second patch in this series adds a hook which users can define in
their .gdbinit in order to be called when the GCC extensions have
finished loading, thus allowing users to automatically configure
gcc-dot-cmd as desired in their .gdbinit.

Manually tested by debugging an x86 -> aarch64 cross, changing the
parameter, and invoking dot-fn.

OK to install?

Thanks,
Alex

gcc/ChangeLog:

	* gdbhooks.py (GCCDotCmd): New.
	(gcc_dot_cmd): New. Use it ...
	(DotFn.invoke): ... here.
iff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 92e38880a70..db8ce0d071b 100644

Comments

David Malcolm Aug. 2, 2024, 11:17 p.m. UTC | #1
On Thu, 2024-08-01 at 10:14 +0100, Alex Coplan wrote:
> Hi,
> 
> This adds a new GDB parameter 'gcc-dot-cmd' which allows the user to
> configure the command used to render the CFG within dot-fn.
> 
> E.g. with this patch the user can change their dot viewer like so:
> 
> (gdb) show gcc-dot-cmd
> The current value of 'gcc-dot-cmd' is "dot -Tx11".
> (gdb) set gcc-dot-cmd xdot
> (gdb) dot-fn # opens in xdot
> 
> The second patch in this series adds a hook which users can define in
> their .gdbinit in order to be called when the GCC extensions have
> finished loading, thus allowing users to automatically configure
> gcc-dot-cmd as desired in their .gdbinit.
> 
> Manually tested by debugging an x86 -> aarch64 cross, changing the
> parameter, and invoking dot-fn.
> 
> OK to install?

Thanks; both patches look good to me.
Dave

> 
> Thanks,
> Alex
> 
> gcc/ChangeLog:
> 
>         * gdbhooks.py (GCCDotCmd): New.
>         (gcc_dot_cmd): New. Use it ...
>         (DotFn.invoke): ... here.
diff mbox series

Patch

--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -783,6 +783,18 @@  class DumpFn(gdb.Command):
 
 DumpFn()
 
+class GCCDotCmd(gdb.Parameter):
+    """
+    This parameter controls the command used to render dot files within
+    GCC's dot-fn command.  It will be invoked as gcc-dot-cmd <dot-file>.
+    """
+    def __init__(self):
+        super(GCCDotCmd, self).__init__('gcc-dot-cmd',
+                gdb.COMMAND_NONE, gdb.PARAM_STRING)
+        self.value = "dot -Tx11"
+
+gcc_dot_cmd = GCCDotCmd()
+
 class DotFn(gdb.Command):
     """
     A custom command to show a gimple/rtl function control flow graph.
@@ -848,7 +860,8 @@  class DotFn(gdb.Command):
             return
 
         # Show graph in temp file
-        os.system("( dot -Tx11 \"%s\"; rm \"%s\" ) &" % (filename, filename))
+        dot_cmd = gcc_dot_cmd.value
+        os.system("( %s \"%s\"; rm \"%s\" ) &" % (dot_cmd, filename, filename))
 
 DotFn()