gdb: Add custom script for breakpoint with conditions on backtrace
This commit is contained in:
parent
bbb5057eb1
commit
bc5d78ee5f
1 changed files with 37 additions and 0 deletions
37
gdb/.gdbinit.d/scripts/framebp.py
Normal file
37
gdb/.gdbinit.d/scripts/framebp.py
Normal 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()
|
Loading…
Reference in a new issue