Skip to content

Commit 91bd4d3

Browse files
author
xialu
committed
add util
1 parent 0d22299 commit 91bd4d3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

util.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import gdb
33
except ImportError as e:
44
raise ImportError("This script must be run in GDB: ", str(e))
5+
6+
from libstdcxx.v6.printers import StdMapPrinter, StdVectorPrinter, StdListPrinter
7+
import re
58

69

710
def print_stack_trace():
@@ -20,3 +23,41 @@ def norm_type(tp):
2023
return norm_type(pointee_type)
2124
return pointee_type
2225
return tp
26+
27+
28+
def StdMapToDict(iMap):
29+
it = StdMapPrinter('map', iMap).children()
30+
res = {}
31+
for key, value in it:
32+
m = re.search('\[(\d{1,3})\]', key)
33+
if m:
34+
count = int(m.group(1))
35+
if count % 2 == 0:
36+
# it is key
37+
k = '{}'.format(value)
38+
else:
39+
res[k] = value.referenced_value()
40+
return res
41+
42+
def stdVectorToPyList(typename, vector):
43+
'''
44+
Given std::vector in gdb.Value, return a list of gdb.Value of the list's elements
45+
'''
46+
rslist = []
47+
elements = StdVectorPrinter(typename, vector).children()
48+
for (_, val) in iter(elements):
49+
rslist.append(val)
50+
51+
return rslist
52+
53+
def stdListToPyList(typename, list):
54+
'''
55+
Given std::list in gdb.Value, return a list of gdb.Value of the list's elements
56+
'''
57+
rslist = []
58+
nodes = StdListPrinter(typename, list).children()
59+
for (_, val) in iter(nodes):
60+
rslist.append(val)
61+
62+
return rslist
63+

0 commit comments

Comments
 (0)