@@ -162,24 +162,50 @@ def load(address, size=4):
162
162
def load_pointer (address ):
163
163
return struct .unpack ("<I" , load (address ))[0 ]
164
164
165
- heap_start , heap_size = symbols ["heap" ]
165
+ if "heap" in symbols :
166
+ heap_start , heap_size = symbols ["heap" ]
167
+ else :
168
+ print ("no static heap" )
169
+ allocations_start , allocations_size = symbols ["allocations" ]
170
+ allocations = load (allocations_start , allocations_size )
171
+ first_zero = True
172
+ potential_heap = None
173
+ # The heap is the last left hand allocated section that should span all the way to the
174
+ # right side list.
175
+ for address , size in struct .iter_unpack ("<II" , allocations ):
176
+ print (address , size )
177
+ if address == 0 and first_zero :
178
+ first_zero = False
179
+ if first_zero :
180
+ potential_heap = (address , size )
181
+
182
+ if not first_zero and address != 0 :
183
+ if address != potential_heap [0 ] + potential_heap [1 ]:
184
+ print ("no active heap" )
185
+ return
186
+ else :
187
+ heap_start , heap_size = potential_heap
188
+ break
189
+ print ("found heap" , heap_start , heap_size )
166
190
heap = load (heap_start , heap_size )
167
191
total_byte_len = len (heap )
168
192
169
193
# These change every run so we load them from the symbol table
170
194
mp_state_ctx = symbols ["mp_state_ctx" ][0 ]
171
195
manual_symbol_map ["mp_state_ctx+20" ] = "mp_state_ctx.vm.last_pool"
172
196
last_pool = load_pointer (mp_state_ctx + 20 ) # (gdb) p &mp_state_ctx.vm.last_pool
173
- manual_symbol_map ["mp_state_ctx+104 " ] = "mp_state_ctx.vm.dict_main.map.table"
174
- dict_main_table = load_pointer (mp_state_ctx + 104 ) # (gdb) p &mp_state_ctx.vm.dict_main.map.table
197
+ manual_symbol_map ["mp_state_ctx+108 " ] = "mp_state_ctx.vm.dict_main.map.table"
198
+ dict_main_table = load_pointer (mp_state_ctx + 108 ) # (gdb) p &mp_state_ctx.vm.dict_main.map.table
175
199
manual_symbol_map ["mp_state_ctx+84" ] = "mp_state_ctx.vm.mp_loaded_modules_dict.map.table"
176
200
imports_table = load_pointer (mp_state_ctx + 84 ) # (gdb) p &mp_state_ctx.vm.mp_loaded_modules_dict.map.table
177
201
178
- manual_symbol_map ["mp_state_ctx+120" ] = "mp_state_ctx.vm.mp_sys_path_obj.items"
179
- manual_symbol_map ["mp_state_ctx+136" ] = "mp_state_ctx.vm.mp_sys_argv_obj.items"
202
+ manual_symbol_map ["mp_state_ctx+124" ] = "mp_state_ctx.vm.mp_sys_path_obj.items"
203
+ manual_symbol_map ["mp_state_ctx+140" ] = "mp_state_ctx.vm.mp_sys_argv_obj.items"
204
+ manual_symbol_map ["mp_state_ctx+96&quo
6DB6
t; ] = "mp_state_ctx.vm.dict_main"
205
+ manual_symbol_map ["0x200015e0" ] = "mp_state_ctx.vm.dict_main"
180
206
181
207
for i in range (READLINE_HIST_SIZE ):
182
- manual_symbol_map ["mp_state_ctx+{}" .format (144 + i * 4 )] = "mp_state_ctx.vm.readline_hist[{}]" .format (i )
208
+ manual_symbol_map ["mp_state_ctx+{}" .format (148 + i * 4 )] = "mp_state_ctx.vm.readline_hist[{}]" .format (i )
183
209
184
210
tuple_type = symbols ["mp_type_tuple" ][0 ]
185
211
type_type = symbols ["mp_type_type" ][0 ]
@@ -192,6 +218,8 @@ def load_pointer(address):
192
218
193
219
dynamic_type = 0x40000000 # placeholder, doesn't match any memory
194
220
221
+ long_lived_start = load_pointer (mp_state_ctx + 272 ) # (gdb) p &mp_state_ctx.mem.gc_lowest_long_lived_ptr
222
+
195
223
type_colors = {
196
224
dict_type : "red" ,
197
225
property_type : "yellow" ,
@@ -252,9 +280,14 @@ def save_allocated_block(end, current_allocation):
252
280
table = "<<table bgcolor=\" gray\" border=\" 1\" cellpadding=\" 0\" cellspacing=\" 0\" ><tr><td colspan=\" 4\" port=\" 0\" height=\" 18\" width=\" 80\" >0x{:08x}</td></tr>{}</table>>" .format (address , rows )
253
281
254
282
ownership_graph .add_node (address , label = table , style = "invisible" , shape = "plaintext" )
283
+ print ("add 0x{:08x}" .format (address ))
255
284
potential_type = None
256
285
node = ownership_graph .get_node (address )
257
286
node .attr ["height" ] = 0.25 * current_allocation
287
+ if address >= long_lived_start :
288
+ node .attr ["fontcolor" ] = "hotpink"
289
+ else :
290
+ node .attr ["fontcolor" ] = "black"
258
291
block_data [address ] = data
259
292
for k in range (len (data ) // 4 ):
260
293
word = struct .unpack_from ("<I" , data , offset = (k * 4 ))[0 ]
@@ -270,6 +303,7 @@ def save_allocated_block(end, current_allocation):
270
303
bgcolor = type_colors [potential_type ]
271
304
elif print_unknown_types :
272
305
print ("unknown type" , hex (potential_type ))
306
+
273
307
node .attr ["label" ] = "<" + node .attr ["label" ].replace ("\" gray\" " , "\" " + bgcolor + "\" " ) + ">"
274
308
275
309
if potential_type == str_type and k == 3 :
@@ -285,7 +319,7 @@ def save_allocated_block(end, current_allocation):
285
319
if k < 4 :
286
320
port = 0
287
321
ownership_graph .add_edge (address , word , tailport = str (port )+ ":_" )
288
- # print(" 0x{:08x}".format(word))
322
+ print (" 0x{:08x}" .format (word ))
289
323
if address in qstr_pools :
290
324
if k > 0 :
291
325
qstr_chunks .append (word )
@@ -421,6 +455,7 @@ def format(obj):
421
455
node .attr ["label" ] = "<<table bgcolor=\" gold\" border=\" 1\" cellpadding=\" 0\" cellspacing=\" 0\" ><tr><td colspan=\" 2\" >0x{:08x}</td></tr>{}</table>>" .format (block , rows )
422
456
423
457
for node , degree in ownership_graph .in_degree_iter ():
458
+ print (node , degree )
424
459
if degree == 0 :
425
460
address_bytes = struct .pack ("<I" , int (node ))
426
461
location = - 1
@@ -434,6 +469,8 @@ def format(obj):
434
469
source = manual_symbol_map [source ]
435
470
if "readline_hist" in source :
436
471
string_blocks .append (int (node ))
472
+ if pointer_location > heap_start + heap_size :
473
+ source = "stack " + source
437
474
ownership_graph .add_edge (source , node )
438
475
439
476
for block in string_blocks :
@@ -517,7 +554,11 @@ def format(obj):
517
554
wrapped .append (html .escape (printable_qstrs [i :i + 16 ]))
518
555
node = ownership_graph .get_node (block )
519
556
node .attr ["label" ] = "<<table border=\" 1\" cellspacing=\" 0\" bgcolor=\" lightsalmon\" width=\" 80\" ><tr><td height=\" 18\" >0x{:08x}</td></tr><tr><td height=\" {}\" >{}</td></tr></table>>" .format (block , 18 * (len (wrapped ) - 1 ), "<br/>" .join (wrapped ))
520
- node .attr ["fontname" ] = "FiraCode-Medium"
557
+ node .attr ["fontname" ] = "FiraCode-Bold"
558
+ if block >= long_lived_start :
559
+ node .attr ["fontcolor" ] = "hotpink"
560
+ else :
561
+ node .attr ["fontcolor" ] = "black"
521
562
node .attr ["fontpath" ] = "/Users/tannewt/Library/Fonts/"
522
563
node .attr ["fontsize" ] = 8
523
564
0 commit comments