-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshow_frame.py
executable file
·82 lines (67 loc) · 2.28 KB
/
show_frame.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
__author__="Brian Hone"
import sys, os, string, pprint
import gdb
sym_types = {
gdb.SYMBOL_LOC_UNDEF : "undefined",
gdb.SYMBOL_LOC_CONST : "constant_int",
gdb.SYMBOL_LOC_STATIC : "fixed_address",
gdb.SYMBOL_LOC_REGISTER : "register",
gdb.SYMBOL_LOC_ARG : "argument",
gdb.SYMBOL_LOC_REF_ARG : "ref_arg",
gdb.SYMBOL_LOC_REGPARM_ADDR : "register_pointer",
gdb.SYMBOL_LOC_LOCAL : "local",
gdb.SYMBOL_LOC_TYPEDEF : "local_typedef",
gdb.SYMBOL_LOC_BLOCK : "block",
gdb.SYMBOL_LOC_CONST_BYTES : "byte_sequence",
gdb.SYMBOL_LOC_UNRESOLVED : "unresolved_address",
gdb.SYMBOL_LOC_OPTIMIZED_OUT : "optimized_out",
gdb.SYMBOL_LOC_COMPUTED : "local_computation"
}
def describe( var, sym ):
''' Gather information about a given variable '''
## Get Type
var_type = str(var.type)
size = 0
## Attempt to figure out its size, base type, min val, max val
if var_type.find( 'std::vector' ) >= 0:
ptr = var['_M_impl' ]['_M_start' ]
end = var['_M_impl' ]['_M_finish' ]
size = end - ptr
pass
elif var_type.find( 'boost::numeric::ublas::vector' ) >= 0:
size = var['data_']['size_']
elif var_type.find( 'std::map' ) >= 0:
pass
elif var_type.find( 'std::list' ) >= 0:
pass
elif var_type.find( 'Eigen' ) >= 0:
pass
elif var_type.find( '[' ) >= 0 and var_type.find( ']' ) > var_type.find( '[' ):
pass
return [ str(var_type), sym_types[ sym.addr_class ], eval(str(size)) ]
# end describe
class ShowFrame( gdb.Command ):
def __init__( self ):
super( ShowFrame, self ).__init__("show_frame", gdb.COMMAND_OBSCURE )
# def __init__
def invoke( self, arg, from_tty ):
###
# Get to the frame and block we want
#
frame = gdb.selected_frame()
block = gdb.selected_frame().block()
frame_vars = {}
###
# Walk through the symbols in the block
#
for sym in block:
###
# Retreive the symbols from the frame
#
var = frame.read_var( sym )
frame_vars[ str(sym) ] = describe( var, sym )
print((pprint.pformat( frame_vars )))
# def invoke
# end class StemPlotter
ShowFrame()