[PATCH] DOT a function directly from a gdb session

Steven Bosscher stevenb.gcc@gmail.com
Wed Dec 12 14:12:00 GMT 2012

On Wed, Dec 12, 2012 at 2:53 PM, Marek Polacek wrote:
> On Wed, Dec 12, 2012 at 01:53:53PM +0100, Richard Biener wrote:
>> This adds the function print_graph_cfg that you can call from a
>> gdb session and directly pipes a dot representation of the
>> function to 'dot -Tx11'.  The only change needed to the now very
>> good dumping code is splitting out the actual worker without
>> the FILE handling.
> Thanks, I like it.  Just a little correction: from gdb session we want
> probably call debug_dot_cfg (cfun).
> Also, usually I get an ICE, e.g.:
> (gdb) b cleanup_cfg
> Breakpoint 1 at 0xe7f260: file /home/marek/src/gcc/gcc/cfgcleanup.c, line 2946.
> (gdb) r
> Starting program: /home/marek/rh/x/trunk/gcc/cc1plus -O2 -ftracer -fno-tree-dce -fno-tree-sra x.c -quiet
> Breakpoint 1, cleanup_cfg (mode=16) at /home/marek/src/gcc/gcc/cfgcleanup.c:2946
> 2946    {
> (gdb) call debug_dot_cfg(cfun)
> Detaching after fork from child process 2458.
> x.c: In function ‘int main()’:
> x.c:9:1: internal compiler error: in pre_and_rev_post_order_compute, at cfganal.c:869
>  }
>  ^
> 0x78fb4c pre_and_rev_post_order_compute(int*, int*, bool)
>         /home/marek/src/gcc/gcc/cfganal.c:869
> 0xebceb2 print_graph_cfg_1
>         /home/marek/src/gcc/gcc/graph.c:186
> 0xebd2a1 debug_dot_cfg(function*)
>         /home/marek/src/gcc/gcc/graph.c:259
> When I can call debug_dot_cfg and when not?

There are several warts that need addressing for GCC 4.9. I'm aware of
the following bugs. There may be others, if you find any please let me

1. dumping for debug_dot_cfg (struct function *fn), fn != cfun
This doesn't work with non-loop dumping because
pre_and_rev_post_order_compute only works on cfun. Much of the CFG
infrastructure hasn't been fully converted yet to work on any
arbitrary CFG. Historically, there would be only one CFG at a time,
but with cgraph we now maintain CFGs (and even loops) for functions
throughout the compilation process. I'm planning to fix most issues
for GCC 4.9.

2. dumping with unreachable blocks
The CFG dumpers actually handle this (since my latest patch to
graph.c) but pre_and_rev_post_order_compute does not. If you remove
the assert there, it will work. Again, for GCC 4.9 we'll have to look
into a better solution for this (e.g. only conditionally assert, on

3. dumping with loops but incorrect loop tree
If the loop tree isn't up to date, get_loop_body* will not work
properly and dumping the CFG will crash. I don't know of any means to
check the state of the loop tree and fall back to non-loop dumping.

4. dumping with some of the more exotic tree dumping flags
Not sure if all of them work, I haven't tested all combinations (vops,
stmtaddr, etc.).


More information about the Gcc-patches mailing list