File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 2
2
import gdb
3
3
except ImportError as e :
4
4
raise ImportError ("This script must be run in GDB: " , str (e ))
5
+
6
+ from libstdcxx .v6 .printers import StdMapPrinter , StdVectorPrinter , StdListPrinter
7
+ import re
5
8
6
9
7
10
def print_stack_trace ():
@@ -20,3 +23,41 @@ def norm_type(tp):
20
23
return norm_type (pointee_type )
21
24
return pointee_type
22
25
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
+
You can’t perform that action at this time.
0 commit comments