Add debug-function-to-file to gdbhooks.py
---
gcc/gdbhooks.py | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
@@ -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')