forked from cirosantilli/cpp-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
call_graph_rbreak_directory.py
56 lines (47 loc) · 1.35 KB
/
call_graph_rbreak_directory.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
## Call graph rbreak directory
rbreak only inside a directory to limit the startup overhead.
"""
import os
# The directory path to break at.
path = u'multifile/d'
depth_string = 4 * ' '
gdb.execute('file multifile/main.out', to_string=True)
for root, dirs, files in os.walk(path):
for basename in files:
path = os.path.abspath(os.path.join(root, basename))
gdb.execute('rbreak {}:.'.format(path), to_string=True)
gdb.execute('run', to_string=True)
thread = gdb.inferiors()[0].threads()[0]
while thread.is_valid():
frame = gdb.selected_frame()
symtab = frame.find_sal().symtab
stack_depth = 0
f = frame
while f:
stack_depth += 1
f = f.older()
# Not present for files without debug symbols.
source_path = '???'
if symtab:
#source_path = symtab.fullname()
source_path = symtab.filename
# Not present for files without debug symbols.
args = '???'
block = None
try:
block = frame.block()
except:
pass
if block:
args = ''
for symbol in block:
if symbol.is_argument:
args += '{} = {}, '.format(symbol.name, symbol.value(frame))
print('{}{} : {} : {}'.format(
stack_depth * depth_string,
source_path,
frame.name(),
args
))
gdb.execute('continue', to_string=True)