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?
OK for stage4/stage1?
Thanks,
- Tom
2016-02-18 Tom de Vries <t...@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')