-
Notifications
You must be signed in to change notification settings - Fork 160
/
disas.py
37 lines (33 loc) · 1.03 KB
/
disas.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
31
32
33
34
35
36
37
"""
## disas
Python implementation of the `disas` command.
"""
def disas():
frame = gdb.selected_frame()
# TODO: make this work for files without debugging info.
# block() is only available with it.
#
# What we need is to use symbol information instead.
# ELF symboltable symbols have the initial address
# and the size attributes, so that should be enough.
block = frame.block()
# Find the current function if in an inner block.
while block:
if block.function:
break
block = block.superblock
start = block.start
end = block.end
arch = frame.architecture()
pc = gdb.selected_frame().pc()
instructions = arch.disassemble(start, end - 1)
for instruction in instructions:
print('{:x} {}'.format(instruction['addr'], instruction['asm']))
gdb.execute('file disas_py.out', to_string=True)
gdb.execute('start', to_string=True)
disas()
# Test from the inner block.
gdb.execute('break 9', to_string=True)
gdb.execute('continue', to_string=True)
print()
disas()