Commit 8af731c1 authored by Ben Gamari's avatar Ben Gamari 🐢

gdb: Be more cautious when search for containing closure

parent e0150433
......@@ -153,28 +153,28 @@ def find_containing_closure(inferior: gdb.Inferior,
bs = None
try:
bs = inferior.read_memory(start.addr(), word_size)
addr = Ptr.unpack(bs)
sym = find_symbol_name(addr)
# Is this an info table pointer?
if sym is not None and sym.endswith('_info'): # and sym.value == addr:
info = ghc_heap.get_itbl(gdb.parse_and_eval('(StgClosure *) %d' % start.addr()))
if int(info['type']) in closure.stack_frame_types:
return find_containing_stack(inferior, addr)
nptrs = int(info['layout']['payload']['ptrs'])
#print(ptr, i, info, nptrs)
if int(info['type']) == closure.ClosureType.IND_STATIC:
if ptr.addr() - start.addr() > 8:
# Only trace the indirectee of IND_STATICs
return None
elif i <= nptrs + 5: # A bit of fudge for the headers
return start
else:
print('suspicious info table: too far (field=%s, info@%s=%s, nptrs=%d, i=%d)' % (ptr, start, sym, nptrs, i))
return None
except gdb.MemoryError:
continue
addr = Ptr.unpack(bs)
sym = find_symbol_name(addr)
# Is this an info table pointer?
if sym is not None and sym.endswith('_info'): # and sym.value == addr:
info = ghc_heap.get_itbl(gdb.parse_and_eval('(StgClosure *) %d' % start.addr()))
if int(info['type']) in closure.stack_frame_types:
return find_containing_stack(inferior, addr)
nptrs = int(info['layout']['payload']['ptrs'])
#print(ptr, i, info, nptrs)
if int(info['type']) == closure.ClosureType.IND_STATIC:
if ptr.addr() - start.addr() > 8:
# Only trace the indirectee of IND_STATICs
return None
elif i <= nptrs + 5: # A bit of fudge for the headers
return start
else:
print('suspicious info table: too far (field=%s, info@%s=%s, nptrs=%d, i=%d)' % (ptr, start, sym, nptrs, i))
return None
return None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment