-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
49 lines (39 loc) · 1.21 KB
/
util.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
try:
import gdb
except ImportError as e:
raise ImportError("This script must be run in GDB: ", str(e))
from libstdcxx.v6.printers import StdMapPrinter, StdVectorPrinter, StdListPrinter
import re
def print_stack_trace():
gdb.execute('bt')
def StdMapToDict(iMap):
it = StdMapPrinter('map', iMap).children()
res = {}
for key, value in it:
m = re.search(r'[(\d{1,3})]', key)
if m:
count = int(m.group(1))
if count % 2 == 0:
# it is key
k = '{}'.format(value)
else:
res[k] = value.referenced_value()
return res
def stdVectorToPyList(typename, vector):
'''
Given std::vector in gdb.Value, return a list of gdb.Value of the list's elements
'''
rslist = []
elements = StdVectorPrinter(typename, vector).children()
for (_, val) in iter(elements):
rslist.append(val)
return rslist
def stdListToPyList(typename, list):
'''
Given std::list in gdb.Value, return a list of gdb.Value of the list's elements
'''
rslist = []
nodes = StdListPrinter(typename, list).children()
for (_, val) in iter(nodes):
rslist.append(val)
return rslist