summaryrefslogtreecommitdiff
path: root/data/eo/eo_gdb.py
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2016-12-07 12:50:52 +0000
committerTom Hacohen <tom@stosb.com>2016-12-07 12:51:54 +0000
commitddf940320dba33e9b3e52aa5ba4ddc1b8ca1c499 (patch)
tree53e85613b7f75c36cb80d230bbaca4f7e7c18002 /data/eo/eo_gdb.py
parent5614e46f1f01aa02a779358177907fc08223f3ac (diff)
Eo gdb: Be more strict with types and convert Eo * to uintptr_t.
This should make the results cleaner and also solve potential conversion issues in some version combinations of gdb and python.
Diffstat (limited to '')
-rw-r--r--data/eo/eo_gdb.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/data/eo/eo_gdb.py b/data/eo/eo_gdb.py
index ec4d21cef1..e02dd10ebf 100644
--- a/data/eo/eo_gdb.py
+++ b/data/eo/eo_gdb.py
@@ -56,7 +56,9 @@ MASK_GENERATIONS = (MAX_GENERATIONS - 1)
56MASK_OBJ_TAG = (1 << (REF_TAG_SHIFT)) 56MASK_OBJ_TAG = (1 << (REF_TAG_SHIFT))
57 57
58 58
59null_ptr = gdb.parse_and_eval('(_Eo_Object *) 0') 59null_void_ptr = gdb.parse_and_eval('(_Eo_Object *) 0')
60null_eo_object_ptr = gdb.parse_and_eval('(_Eo_Object *) 0')
61zero_uintptr_t = gdb.parse_and_eval('(uintptr_t) 0')
60 62
61 63
62class Eo_resolve(gdb.Function): 64class Eo_resolve(gdb.Function):
@@ -64,7 +66,7 @@ class Eo_resolve(gdb.Function):
64 gdb.Function.__init__(self, 'eo_resolve') 66 gdb.Function.__init__(self, 'eo_resolve')
65 67
66 def invoke(self, arg): 68 def invoke(self, arg):
67 obj_id = int(arg) 69 obj_id = int(arg.cast(zero_uintptr_t.type))
68 70
69 mid_table_id = (obj_id >> SHIFT_MID_TABLE_ID) & MASK_MID_TABLE_ID 71 mid_table_id = (obj_id >> SHIFT_MID_TABLE_ID) & MASK_MID_TABLE_ID
70 table_id = (obj_id >> SHIFT_TABLE_ID) & MASK_TABLE_ID 72 table_id = (obj_id >> SHIFT_TABLE_ID) & MASK_TABLE_ID
@@ -74,20 +76,20 @@ class Eo_resolve(gdb.Function):
74 76
75 if (obj_id == 0) or (tag_bit == 0): 77 if (obj_id == 0) or (tag_bit == 0):
76 gdb.write('Pointer is NULL or not a valid object.\n') 78 gdb.write('Pointer is NULL or not a valid object.\n')
77 return null_ptr 79 return null_eo_object_ptr
78 80
79 entries = gdb.parse_and_eval('_eo_gdb_main_domain->tables[0]->' + 81 entries = gdb.parse_and_eval('_eo_gdb_main_domain->tables[0]->' +
80 'eo_ids_tables[{0}]'.format(mid_table_id)) 82 'eo_ids_tables[{0}]'.format(mid_table_id))
81 83
82 if int(entries) == 0: 84 if int(entries) == 0:
83 gdb.write('Pointer is not a valid object.\n') 85 gdb.write('Pointer is not a valid object.\n')
84 return null_ptr 86 return null_eo_object_ptr
85 87
86 entry = entries[table_id]['entries'][entry_id] 88 entry = entries[table_id]['entries'][entry_id]
87 89
88 if (not entry['active']) or (int(entry['generation']) != generation): 90 if (not entry['active']) or (int(entry['generation']) != generation):
89 gdb.write('Pointer is no longer active.\n') 91 gdb.write('Pointer is no longer active.\n')
90 return null_ptr 92 return null_eo_object_ptr
91 93
92 return entry['ptr'] 94 return entry['ptr']
93 95
@@ -100,11 +102,11 @@ class Eo_data_get(gdb.Function):
100 gdb.Function.__init__(self, 'eo_data_get') 102 gdb.Function.__init__(self, 'eo_data_get')
101 103
102 def invoke(self, ptr, kls_name): 104 def invoke(self, ptr, kls_name):
103 ptr = ptr.cast(null_ptr.type) # Make sure it's the right type 105 ptr = ptr.cast(null_eo_object_ptr.type) # Cast to correct type
104 106
105 if int(ptr) == 0: 107 if int(ptr) == 0:
106 gdb.write('Object is not a valid pointer (NULL).\n') 108 gdb.write('Object is not a valid pointer (NULL).\n')
107 return null_ptr 109 return null_void_ptr
108 110
109 kls_name = kls_name.string() 111 kls_name = kls_name.string()
110 extns = ptr['klass']['mro'] 112 extns = ptr['klass']['mro']
@@ -119,7 +121,7 @@ class Eo_data_get(gdb.Function):
119 if kls is None: 121 if kls is None:
120 gdb.write('Class "{}" not found in the object mro.\n' 122 gdb.write('Class "{}" not found in the object mro.\n'
121 .format(kls_name)) 123 .format(kls_name))
122 return null_ptr 124 return null_void_ptr
123 125
124 # Check if not mixin 126 # Check if not mixin
125 if int(kls['desc']['type']) != 3: 127 if int(kls['desc']['type']) != 3:
@@ -128,7 +130,7 @@ class Eo_data_get(gdb.Function):
128 else: 130 else:
129 extn_off = ptr['klass']['extn_data_off'] 131 extn_off = ptr['klass']['extn_data_off']
130 if int(extn_off) == 0: 132 if int(extn_off) == 0:
131 return null_ptr 133 return null_void_ptr
132 134
133 i = 0 135 i = 0
134 while int(extn_off[i]['klass']) != 0: 136 while int(extn_off[i]['klass']) != 0:
@@ -138,7 +140,7 @@ class Eo_data_get(gdb.Function):
138 .format(ptr, kls['data_offset'])) 140 .format(ptr, kls['data_offset']))
139 i += 1 141 i += 1
140 142
141 return null_ptr 143 return null_void_ptr
142 144
143 145
144Eo_data_get() 146Eo_data_get()