-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
56 lines (43 loc) · 1.46 KB
/
common.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
try:
import gdb
except ImportError as e:
raise ImportError("This script must be run in GDB: ", str(e))
def disable_prompt():
gdb.execute("set pagination off")
gdb.execute ('set confirm off')
def not_handle_SIGSEGV():
'''usuall for java, we don't need to handle SIGSEGV'''
gdb.execute("handle SIGSEGV nostop noprint pass")
def enable_logging(logging_file):
gdb.execute('set logging file ' + logging_file)
gdb.execute('set logging on')
def dynamic_value(val):
'''val must be pointer or a reference'''
return val.cast(val.dynamic_type)
def norm_type(tp):
'''return the pointee type if the type is pointter'''
if tp.code == gdb.TYPE_CODE_PTR:
pointee_type = tp.target()
if pointee_type.code == gdb.TYPE_CODE_PTR:
return norm_type(pointee_type)
return pointee_type
return tp
def is_null(val):
if val.type.code == gdb.TYPE_CODE_PTR:
return int(val) == 0
return False
def deref(pointer):
'''dereference pointer to get value'''
# TODO: use loop to support nested pointers
val = pointer
if val.type.code == gdb.TYPE_CODE_PTR:
if is_null(val):
raise Exception("nullptr")
val = dynamic_value(val)
val = val.referenced_value()
if val.type.code == gdb.TYPE_CODE_PTR:
if is_null(val):
raise Exception("nullptr")
val = dynamic_value(val)
val = val.referenced_value()
return val