Skip to content

Instantly share code, notes, and snippets.

@theIDinside
Created April 27, 2022 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theIDinside/405bbba5eca8bbc57c52442b40406f5a to your computer and use it in GitHub Desktop.
Save theIDinside/405bbba5eca8bbc57c52442b40406f5a to your computer and use it in GitHub Desktop.
Custom breakpoint
import gdb
open_files = {}
class PrintArgsBreakpoint(gdb.Breakpoint):
def __init__(self, fn_name, filename):
super(PrintArgsBreakpoint, self).__init__(fn_name)
self.filename = filename
self.fn_name = fn_name
self.file_opened = False
def stop(self):
global open_files
file = open_files.get(self.filename)
if file is None:
file = open(self.filename, 'a')
open_files[self.filename] = file
self.file_opened = True
s = gdb.execute("info args", to_string=True)
res = "arguments for '{}'\n--------------\n{}--------------\n\n".format(self.fn_name, s)
file.write(res)
file.flush()
# we return false to not stop; making GDB just carry on merrily (as if it was executing "continue"
return False
class FnBreakpointPrintArgs(gdb.Command):
def __init__(self):
super(FnBreakpointPrintArgs, self).__init__("bpargs", gdb.COMMAND_USER)
self.name = "bpargs"
def invoke(self, args, from_tty):
[expr, filename] = gdb.string_to_argv(args)
print("logging args of function {} > {}".format(expr, filename))
bp = PrintArgsBreakpoint(expr, filename)
cmd = FnBreakpointPrintArgs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment