コード例 #1
0
 def invoke(self, args, from_tty):
     print('C++ objects of memory on heap')
     print('-----------------------------')
     argv = args.split(' ')
     from heap.cplusplus import get_class_name
     ms = glibc_arenas.get_ms()
     for i, chunk in enumerate(ms.iter_chunks()):
         if not chunk.is_inuse():
             continue
         mem = chunk.as_mem()
         size = chunk.chunksize()
         cpp_class = get_class_name(mem, size)
         if not cpp_class:
             continue
         if args and cpp_class.find(argv[0]) < 0:
             continue
         try:
             objsize = caching_lookup_type(cpp_class).sizeof
             if (size / objsize >= 2):
                 cpp_class += "[%d]" % (size / objsize)
         except:
             objsize = "?"
         u = Usage(mem, size)
         #hd = hexdump_as_bytes(mem, 32)
         print('%6i: %s -> %s %8i bytes %100s | %s bytes/obj' %
               (i, fmt_addr(mem), fmt_addr(mem + size - 1), size, cpp_class,
                objsize))
     print("\n")
コード例 #2
0
ファイル: __init__.py プロジェクト: iafilatov/gdb-heap
def categorize(u, usage_set):
    '''Given an in-use block, try to guess what it's being used for
    If usage_set is provided, this categorization may lead to further
    categorizations'''
    from heap.cpython import as_python_object, obj_addr_to_gc_addr
    addr, size = u.start, u.size
    pyop = as_python_object(addr)
    if pyop:
        u.obj = pyop
        try:
            return pyop.categorize()
        except (RuntimeError, UnicodeEncodeError, UnicodeDecodeError) as e:
            # If something went wrong, assume that this wasn't really a python
            # object, and fall through:
            print("couldn't categorize pyop:", pyop)
            print(e)
            pass

    # PyPy detection:
    from heap.pypy import pypy_categorizer
    cat = pypy_categorizer(addr, size)
    if cat:
        return cat

    # C++ detection: only enabled if we can capture "execute"; there seems to
    # be a bad interaction between pagination and redirection: all output from
    # "heap" disappears in the fallback form of execute, unless we "set pagination off"
    from heap.compat import has_gdb_execute_to_string
    #  Disable for now, see https://bugzilla.redhat.com/show_bug.cgi?id=620930
    if False: # has_gdb_execute_to_string:
        from heap.cplusplus import get_class_name
        cpp_cls = get_class_name(addr, size)
        if cpp_cls:
            return Category('C++', cpp_cls)

    # GObject detection:
    # FIXME: disabled because glib for python is ages old
    # from heap.gobject import as_gtype_instance
    # ginst = as_gtype_instance(addr, size)
    # if ginst:
    #     u.obj = ginst
    #     return ginst.categorize()

    s = as_nul_terminated_string(addr, size)
    if s and len(s) > 2:
        return Category('C', 'string data')

    # Uncategorized:
    return Category('uncategorized', '', '%s bytes' % size)
コード例 #3
0
ファイル: __init__.py プロジェクト: doctau/gdb-heap
def categorize(u, usage_set):
    '''Given an in-use block, try to guess what it's being used for
    If usage_set is provided, this categorization may lead to further
    categorizations'''
    from heap.cpython import as_python_object, obj_addr_to_gc_addr
    addr, size = u.start, u.size
    pyop = as_python_object(addr)
    if pyop:
        u.obj = pyop
        try:
            return pyop.categorize()
        except (RuntimeError, UnicodeEncodeError, UnicodeDecodeError):
            # If something went wrong, assume that this wasn't really a python
            # object, and fall through:
            print "couldn't categorize pyop:", pyop
            pass

    # PyPy detection:
    from heap.pypy import pypy_categorizer
    cat = pypy_categorizer(addr, size)
    if cat:
        return cat

    # C++ detection: only enabled if we can capture "execute"; there seems to
    # be a bad interaction between pagination and redirection: all output from
    # "heap" disappears in the fallback form of execute, unless we "set pagination off"
    from heap.compat import has_gdb_execute_to_string
    #  Disable for now, see https://bugzilla.redhat.com/show_bug.cgi?id=620930
    if False: # has_gdb_execute_to_string:
        from heap.cplusplus import get_class_name
        cpp_cls = get_class_name(addr, size)
        if cpp_cls:
            return Category('C++', cpp_cls)

    # GObject detection:
    from gobject import as_gtype_instance
    ginst = as_gtype_instance(addr, size)
    if ginst:
        u.obj = ginst
        return ginst.categorize()

    s = as_nul_terminated_string(addr, size)
    if s and len(s) > 2:
        return Category('C', 'string data')

    # Uncategorized:
    return Category('uncategorized', '', '%s bytes' % size)