Message ID | 56C5FEBB.5000805@mentor.com |
---|---|
State | New |
Headers | show |
On Thu, 2016-02-18 at 18:26 +0100, Tom de Vries wrote: > On 18/02/16 16:43, Tom de Vries wrote: > > On 18/02/16 16:27, Richard Biener wrote: > > > > > > I would be nice if we could avoid the ${1,2,3} printouts > > > > > > and value > > > > > > > > > > history > > > > > > > > > > assignments, but I'm not sure how to do that. > > > > > > > > > > > > > > > > > > > > > > Using gdb.parse_and_eval does the trick. > > > > > > > > This updated version uses gdb.parse_and_eval, and adds error > > handling. > > And this updated version adds handling different number of arguments, > and a help text. I think this could be ready for committing. > > Is a bootstrap/regtest useful/necessary? I don't think so; I don't think we have any automated coverage for gdb_hooks.py. Presumably you've tested it by hand. What version of Python do you have embedded in gdb? (IIRC some people have Python 2, others Python 3) > + print ("Too little arguments") Nit: can you change this to "Not enough arguments". > OK for stage4/stage1? Looks reasonable to me.
On Thu, Feb 18, 2016 at 8:41 PM, David Malcolm <dmalcolm@redhat.com> wrote: > On Thu, 2016-02-18 at 18:26 +0100, Tom de Vries wrote: >> On 18/02/16 16:43, Tom de Vries wrote: >> > On 18/02/16 16:27, Richard Biener wrote: >> > > > > > I would be nice if we could avoid the ${1,2,3} printouts >> > > > > > and value >> > > > > > > > > > history >> > > > > > > > > > assignments, but I'm not sure how to do that. >> > > > > > > > > > >> > > > >> > > > >> > > > Using gdb.parse_and_eval does the trick. >> > > > >> > >> > This updated version uses gdb.parse_and_eval, and adds error >> > handling. >> >> And this updated version adds handling different number of arguments, >> and a help text. I think this could be ready for committing. >> >> Is a bootstrap/regtest useful/necessary? > > I don't think so; I don't think we have any automated coverage for > gdb_hooks.py. Presumably you've tested it by hand. > > What version of Python do you have embedded in gdb? (IIRC some people > have Python 2, others Python 3) > >> + print ("Too little arguments") > > Nit: can you change this to "Not enough arguments". > > >> OK for stage4/stage1? > > Looks reasonable to me. Ok for stage4. Thanks, Richard.
2016-02-18 Tom de Vries <tom@codesourcery.com> * gdbhooks.py (class debug_function_to_file): Add and instantiate. Add debug-function-to-file to gdbhooks.py --- gcc/gdbhooks.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py index 0d5cc97..cffac2a 100644 --- a/gcc/gdbhooks.py +++ b/gcc/gdbhooks.py @@ -589,4 +589,68 @@ class BreakOnPass(gdb.Command): BreakOnPass() +class debug_function_to_file(gdb.Command): + """ + A custom command to dump a gimple/rtl function to file. By default, it + dumps the current function using 0 as dump_flags, but the function and flags + can also be specified. + + Examples of use: + (gdb) debug-function-to-file foo.1 + (gdb) debug-function-to-file foo.1 cfun->decl + (gdb) debug-function-to-file foo.1 cfun->decl 0 + (gdb) debug-function-to-file foo.1 cfun->decl dump_flags + """ + + def __init__(self): + gdb.Command.__init__(self, 'debug-function-to-file', gdb.COMMAND_USER) + + def invoke(self, arg, from_tty): + # Parse args, check number of args + args = gdb.string_to_argv(arg) + if len(args) > 3: + print ("Too many arguments") + return + if len(args) == 0: + print ("Too little arguments") + return + + # Set filename + filename = args[0] + + # Set func + if len(args) >= 2: + funcname = args[1] + printfuncname = "function %s" % funcname + else: + funcname = "cfun ? cfun->decl : current_function_decl" + printfuncname = "current function" + func = gdb.parse_and_eval(funcname) + if func == 0: + print ("Could not find %s" % printfuncname) + return + + # Set flags + if len(args) >= 3: + flags = gdb.parse_and_eval(args[2]) + else: + flags = 0 + + # Open file + fp = gdb.parse_and_eval("fopen (\"%s\", \"w\")" % filename) + if fp == 0: + print ("Could not open file: %s" % filename) + return + + # Dump function to file + dumpargs = "(tree)%u, (FILE *)%u, %u" % (func, fp, flags) + _ = gdb.parse_and_eval("dump_function_to_file (%s)" % dumpargs) + + # Close file + ret = gdb.parse_and_eval("fclose ((FILE *)%u)" % fp) + if ret != 0: + print ("Could not close file: %s" % filename) + +debug_function_to_file() + print('Successfully loaded GDB hooks for GCC')