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.
Thanks,
- Tom
Add debug-function-to-file to gdbhooks.py
---
gcc/gdbhooks.py | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 0d5cc97..c19e823 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -589,4 +589,36 @@ class BreakOnPass(gdb.Command):
BreakOnPass()
+class debug_function_to_file(gdb.Command):
+ def __init__(self):
+ gdb.Command.__init__(self, 'debug-function-to-file', gdb.COMMAND_USER)
+
+ def invoke(self, arg, from_tty):
+ # Find function
+ fn = gdb.parse_and_eval("cfun ? cfun->decl : current_function_decl")
+ if fn == 0:
+ print ("Could not find current function")
+ return
+
+ # Open file
+ file = arg
+ fp = gdb.parse_and_eval("fopen (%s, \"w\")" % file)
+ if fp == 0:
+ print ("Could not open file: %s" % file)
+ return
+
+ # Set flags
+ flags = 0
+
+ # Dump function to file
+ dumpargs = "(tree)%u, (FILE *)%u, %u" % (fn, 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" % file)
+
+debug_function_to_file()
+
print('Successfully loaded GDB hooks for GCC')