summaryrefslogtreecommitdiffstats
path: root/lldb/examples/darwin/heap_find/heap.py
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-05-10 23:17:28 +0000
committerGreg Clayton <gclayton@apple.com>2012-05-10 23:17:28 +0000
commitd9fc53509e8c0d8abf5aee0d6dbe492bdc8298a3 (patch)
tree4f6ab0fbfc022018a3aa67bc4889372405b1f71c /lldb/examples/darwin/heap_find/heap.py
parent6062da47b8a2b78a53afa5f9400c2c5f42854cf5 (diff)
downloadbcm5719-llvm-d9fc53509e8c0d8abf5aee0d6dbe492bdc8298a3.tar.gz
bcm5719-llvm-d9fc53509e8c0d8abf5aee0d6dbe492bdc8298a3.zip
Added the ability to get the stack history for a malloc block. This is a work in progress. Checking this in so I can work on it some more.
llvm-svn: 156584
Diffstat (limited to 'lldb/examples/darwin/heap_find/heap.py')
-rw-r--r--lldb/examples/darwin/heap_find/heap.py47
1 files changed, 45 insertions, 2 deletions
diff --git a/lldb/examples/darwin/heap_find/heap.py b/lldb/examples/darwin/heap_find/heap.py
index 27f27811cc2..9f68497dd6b 100644
--- a/lldb/examples/darwin/heap_find/heap.py
+++ b/lldb/examples/darwin/heap_find/heap.py
@@ -79,7 +79,48 @@ def add_common_options(parser):
parser.add_option('-m', '--memory', action='store_true', dest='memory', help='dump the memory for each matching block', default=False)
parser.add_option('-f', '--format', type='string', dest='format', help='the format to use when dumping memory if --memory is specified', default=None)
parser.add_option('-s', '--stack', action='store_true', dest='stack', help='gets the stack that allocated each malloc block if MallocStackLogging is enabled', default=False)
- #parser.add_option('-S', '--stack-history', action='store_true', dest='stack_history', help='gets the stack history for all allocations whose start address matches each malloc block if MallocStackLogging is enabled', default=False)
+ parser.add_option('-S', '--stack-history', action='store_true', dest='stack_history', help='gets the stack history for all allocations whose start address matches each malloc block if MallocStackLogging is enabled', default=False)
+
+type_flag_strings = [ 'free', 'generic', 'alloc', 'dealloc' ];
+
+def dump_stack_history_entry(stack_history_entry, idx):
+ if stack_history_entry.addr != 0:
+ symbolicator = lldb.utils.symbolication.Symbolicator()
+ symbolicator.target = lldb.target
+ global type_flag_strings
+ print 'stack_history_entry[%u]: addr = 0x%x, type=%s, arg=%u, frames=' % (idx, stack_history_entry.address, type_flag_strings[stack_history_entry.type_flags], stack_history_entry.argument)
+ frame_idx = 0
+ pc = int(stack_history_entry.frames[frame_idx])
+ while pc != 0:
+ if pc >= 0x1000:
+ frames = symbolicator.symbolicate(pc)
+ if frames:
+ for frame in frames:
+ print '[%3u] %s' % (frame_idx, frame)
+ frame_idx += 1
+ else:
+ print '[%3u] 0x%x' % (frame_idx, pc)
+ frame_idx += 1
+ frame_idx = frame_idx + 1
+ pc = int(stack_history_entry.frames[frame_idx])
+ else:
+ pc = 0
+
+def dump_stack_history_entries(addr):
+ # malloc_stack_entry *get_stack_history_for_address (const void * addr)
+
+ expr = 'get_stack_history_for_address((void *)%s)' % addr
+ expr_sbvalue = lldb.frame.EvaluateExpression (expr)
+ if expr_sbvalue.error.Success():
+ if expr_sbvalue.unsigned:
+ expr_value = lldb.value(expr_sbvalue)
+ idx = 0;
+ stack_history_entry = expr_value[idx]
+ while stack_history_entry.address:
+ dump_stack_history_entry(stack_history_entry, idx)
+ idx = idx + 1
+ stack_history_entry = expr_value[idx]
+
def heap_search(options, arg_str):
dylid_load_err = load_dylib()
@@ -186,7 +227,9 @@ def heap_search(options, arg_str):
memory_command = "memory read -f %s 0x%x 0x%x" % (memory_format, malloc_addr, malloc_addr + malloc_size)
lldb.debugger.GetCommandInterpreter().HandleCommand(memory_command, cmd_result)
print cmd_result.GetOutput()
- if options.stack:
+ if options.stack_history:
+ dump_stack_history_entries(malloc_addr)
+ elif options.stack:
symbolicator = lldb.utils.symbolication.Symbolicator()
symbolicator.target = lldb.target
expr_str = "g_stack_frames_count = sizeof(g_stack_frames)/sizeof(uint64_t); (int)__mach_stack_logging_get_frames((unsigned)mach_task_self(), 0x%xull, g_stack_frames, g_stack_frames_count, &g_stack_frames_count)" % (malloc_addr)
OpenPOWER on IntegriCloud