gdb: Add custom script for breakpoint with conditions on backtrace

This commit is contained in:
Sanchayan Maity 2022-04-03 10:31:28 +05:30
parent bbb5057eb1
commit bc5d78ee5f

View file

@ -0,0 +1,37 @@
# https://osa1.net/posts/2020-04-25-breakpoint-backtrace-conditionals.html
import gdb # type: ignore
class FrameBp(gdb.Breakpoint):
def __init__(self, spec, *args, frame=None, **kwargs):
self.frame = frame
super().__init__(spec, *args, **kwargs)
def stop(self):
frame = gdb.selected_frame().older()
while frame:
if frame.name() == self.frame:
return True
frame = frame.older()
return False
class FrameBP(gdb.Command):
def __init__(self):
super().__init__("framebp", gdb.COMMAND_USER)
def complete(self, _text, _word):
return gdb.COMPLETE_SYMBOL
def invoke(self, args, _from_tty):
args = args.split()
if len(args) != 2:
print("Need function name and frame as arguments")
return
FrameBp(args[0], frame=args[1])
FrameBP()