Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions heap/cpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def safe_tp_name(self):
def categorize(self):
# Python objects will be categorized as ("python", tp_name), but
# old-style classes have to do more work
import pdb; pdb.set_trace()
return Category('python', self.safe_tp_name())

def as_malloc_addr(self):
Expand Down Expand Up @@ -355,7 +356,7 @@ def categorize_refs(self, usage_set, level=0, detail=None):
# and mark the dict's PyDictEntry with our typename:
attr_dict.categorize_refs(usage_set, level=level+1,
detail='%s.__dict__' % self.safe_tp_name())
return True
return True

def get_attr_dict(self):
'''
Expand Down Expand Up @@ -454,12 +455,16 @@ def as_python_object(addr):
_type_PyGC_Head_ptr = _type_PyGC_Head.pointer()
gc_ptr = gdb.Value(addr).cast(_type_PyGC_Head_ptr)
# print gc_ptr.dereference()
if gc_ptr['gc']['gc_refs'] == -3: #FIXME: need to cover other values

PYGC_REFS_REACHABLE = -3

if gc_ptr['gc']['gc_refs'] == PYGC_REFS_REACHABLE: # FIXME: need to cover other values
pyop = is_pyobject_ptr(gdb.Value(addr + _type_PyGC_Head.sizeof))
if pyop:
return pyop
# Doesn't look like a python object, implicit return None


class ArenaObject(WrappedPointer):
'''
Wrapper around Python's struct arena_object*
Expand Down Expand Up @@ -500,6 +505,7 @@ def __init__(self, gdbval):
# memory are untouched since malloc:
self.pool_address = self.field('pool_address')


class ArenaDetection(object):
'''Detection of CPython arenas, done as an object so that we can cache state'''
def __init__(self):
Expand Down Expand Up @@ -582,6 +588,7 @@ def python_categorization(usage_set):

from heap.commands import need_debuginfo


class HeapCPythonAllocators(gdb.Command):
"For CPython: display information on the allocators"
def __init__(self):
Expand All @@ -602,5 +609,6 @@ def invoke(self, args, from_tty):
t.write(sys.stdout)
print


def register_commands():
HeapCPythonAllocators()