On 17/02/16 14:42, Richard Biener wrote:
On Wed, Feb 17, 2016 at 1:41 PM, Tom de Vries<tom_devr...@mentor.com>  wrote:
>Hi,
>
>once in a while I'm in a gdb debug session debugging cc1, and want to print
>the current function to file.
>
>There's a debug function debug_function that prints a function to stderr,
>and there are methods to redirect output of a command to a file (
>https://sourceware.org/gdb/onlinedocs/gdb/Logging-Output.html  ).
>
>And there's a function dump_function_to_file that takes a FILE* parameter,
>which could be combined with open/close calls in gdb.
>
>But I think a short-hand is easier.
>
>This patch adds a function debug_function_to_file. It can f.i. be called as:
>...
>(gdb) call debug_function_to_file (cfun.decl, "foo.1.txt", 0)
>...
>
>Hmm, now I wonder if the order 'cfun.decl, 0, "foo.1.txt"' would make more
>sense (first two parameters the same as in debug_function).
>
>OK for stage1 trunk if bootstrap and reg-test succeeds?

Bonus for making this a helper in gdbhooks.py instead, using
fopen/fclose and the existing inferior calls.

[ Right, I forgot about those gdb helpers. I haven't used them before, it's probably time to start using those.

I've made an init file ~/.gdbgccinit (a stripped version of <build>/gcc/.gdbinit):
...
$ cat ~/.gdbgccinit
source <trunk-sources>/gcc/gdbinit.in
python import sys; sys.path.append('<trunk-sources>/gcc'); import gdbhooks
...

and a script gdbgcc:
...
$ cat ~/bin/gdbgcc
#!/bin/sh

base=$(basename "$2")

case "$base" in
    cc1|cc1plus|f951|lto1)
        gdbopt="-x ~/.gdbgccinit"
        ;;
    *)
        gdbopt=""
        ;;
esac

exec gdb $gdbopt "$@"
...

and that allows me to do -wrapper gdbgcc,--args, and import the helpers for cc1, and skip them for as.

That seems to work, though I'm curious what approaches other people use. ]

I'll take a look at implementing this in gdbhooks.py (or gdbinit.in perhaps?).

Thanks,
- Tom

Reply via email to