-
Notifications
You must be signed in to change notification settings - Fork 160
/
continue_return.py
30 lines (27 loc) · 921 Bytes
/
continue_return.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
## Continue until return
http://stackoverflow.com/questions/3649468/setting-breakpoint-in-gdb-where-the-function-returns
"""
class ContinueReturn(gdb.Command):
def __init__(self):
super().__init__(
'continue-return',
gdb.COMMAND_RUNNING,
gdb.COMPLETE_NONE,
False
)
def invoke(self, arg, from_tty):
thread = gdb.inferiors()[0].threads()[0]
while thread.is_valid():
gdb.execute('ni', to_string=True)
frame = gdb.selected_frame()
arch = frame.architecture()
pc = gdb.selected_frame().pc()
instruction = arch.disassemble(pc)[0]['asm']
if instruction.startswith('retq '):
break
ContinueReturn()
gdb.execute('file continue_return_py.out', to_string=True)
gdb.execute('start', to_string=True)
gdb.execute('continue-return')
gdb.execute('disas')