[Lldb-commits] [lldb] r156590 - in /lldb/branches/lldb-platform-work: ./ examples/darwin/heap_find/heap.py examples/darwin/heap_find/heap/heap_find.cpp examples/python/crashlog.py llvm.zip scripts/clang.complete-type-isSafeToConvert.diff

Johnny Chen johnny.chen at apple.com
Thu May 10 16:50:14 PDT 2012


Author: johnny
Date: Thu May 10 18:50:14 2012
New Revision: 156590

URL: http://llvm.org/viewvc/llvm-project?rev=156590&view=rev
Log:
Merge changes from ToT trunk.

Added:
    lldb/branches/lldb-platform-work/scripts/clang.complete-type-isSafeToConvert.diff
      - copied unchanged from r156588, lldb/trunk/scripts/clang.complete-type-isSafeToConvert.diff
Modified:
    lldb/branches/lldb-platform-work/   (props changed)
    lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap.py
    lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap/heap_find.cpp
    lldb/branches/lldb-platform-work/examples/python/crashlog.py
    lldb/branches/lldb-platform-work/llvm.zip

Propchange: lldb/branches/lldb-platform-work/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 10 18:50:14 2012
@@ -1 +1 @@
-/lldb/trunk:154223-156562
+/lldb/trunk:154223-156588

Modified: lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap.py
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap.py?rev=156590&r1=156589&r2=156590&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap.py (original)
+++ lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap.py Thu May 10 18:50:14 2012
@@ -79,7 +79,54 @@
     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):
+    address = int(stack_history_entry.address)
+    if address:
+        type_flags = int(stack_history_entry.type_flags)
+        argument = int(stack_history_entry.argument)
+        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, address, type_flag_strings[type_flags], argument)
+        frame_idx = 0
+        idx = 0
+        pc = int(stack_history_entry.frames[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
+                idx = idx + 1
+                pc = int(stack_history_entry.frames[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 *)0x%x)' % (addr)
+    print 'expr = "%s"' % (expr)
+    expr_sbvalue = lldb.frame.EvaluateExpression (expr)
+    if expr_sbvalue.error.Success():
+        if expr_sbvalue.unsigned:
+            expr_value = lldb.value(expr_sbvalue)  
+            #print 'expr_value = ', expr_value
+            idx = 0;
+            stack_history_entry = expr_value[idx]
+            while int(stack_history_entry.address) != 0:
+                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 +233,9 @@
                     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)

Modified: lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap/heap_find.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap/heap_find.cpp?rev=156590&r1=156589&r2=156590&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap/heap_find.cpp (original)
+++ lldb/branches/lldb-platform-work/examples/darwin/heap_find/heap/heap_find.cpp Thu May 10 18:50:14 2012
@@ -68,7 +68,9 @@
 #include <ctype.h>
 #include <mach/mach.h>
 #include <malloc/malloc.h>
+extern "C" {
 #include <stack_logging.h>
+}
 #include <stdio.h>
 #include <stdlib.h>
 #include <vector>
@@ -117,8 +119,18 @@
     intptr_t offset;
 };
 
+struct malloc_stack_entry
+{
+    void *address;
+    uint64_t argument;
+    uint32_t type_flags;
+    std::vector<uintptr_t> frames;
+};
+
+
 std::vector<malloc_match> g_matches;
 const void *g_lookup_addr = 0;
+std::vector<malloc_stack_entry> g_malloc_stack_history;
 mach_vm_address_t g_stack_frames[MAX_FRAMES];
 uint32_t g_stack_frames_count = 0;
 
@@ -242,6 +254,50 @@
     }
 }
 
+static void 
+get_stack_for_address_enumerator(mach_stack_logging_record_t stack_record, void *task_ptr)
+{
+    uint32_t num_frames = 0;
+    kern_return_t err = __mach_stack_logging_frames_for_uniqued_stack (*(task_t *)task_ptr, 
+                                                                       stack_record.stack_identifier,
+                                                                       g_stack_frames,
+                                                                       MAX_FRAMES,
+                                                                       &num_frames);    
+    g_malloc_stack_history.resize(g_malloc_stack_history.size() + 1);
+    g_malloc_stack_history.back().address = (void *)stack_record.address;
+    g_malloc_stack_history.back().type_flags = stack_record.type_flags;
+    g_malloc_stack_history.back().argument = stack_record.argument;
+    if (num_frames > 0)
+        g_malloc_stack_history.back().frames.assign(g_stack_frames, g_stack_frames + num_frames);
+    g_malloc_stack_history.back().frames.push_back(0); // Terminate the frames with zero
+}
+
+malloc_stack_entry *
+get_stack_history_for_address (const void * addr)
+{
+    // typedef struct {
+    //  uint32_t        type_flags;
+    //  uint64_t        stack_identifier;
+    //  uint64_t        argument;
+    //  mach_vm_address_t   address;
+    // } mach_stack_logging_record_t;
+    std::vector<malloc_stack_entry> empty;
+    g_malloc_stack_history.swap(empty);
+    task_t task = mach_task_self();
+    kern_return_t err = __mach_stack_logging_enumerate_records (task,
+                                                                (mach_vm_address_t)addr, 
+                                                                get_stack_for_address_enumerator,
+                                                                &task);
+    // Append an empty entry
+    if (g_malloc_stack_history.empty())
+        return NULL;
+    g_malloc_stack_history.resize(g_malloc_stack_history.size() + 1);
+    g_malloc_stack_history.back().address = 0;
+    g_malloc_stack_history.back().type_flags = 0;
+    g_malloc_stack_history.back().argument = 0;
+    return g_malloc_stack_history.data();
+}
+
 //----------------------------------------------------------------------
 // find_pointer_in_heap
 //

Modified: lldb/branches/lldb-platform-work/examples/python/crashlog.py
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/examples/python/crashlog.py?rev=156590&r1=156589&r2=156590&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/examples/python/crashlog.py (original)
+++ lldb/branches/lldb-platform-work/examples/python/crashlog.py Thu May 10 18:50:14 2012
@@ -213,8 +213,14 @@
                 elif line.startswith ('Identifier:'):
                     self.process_identifier = line[11:].strip()
                 elif line.startswith ('Version:'):
-                    (self.process_version, compatability_version) = line[8:].strip().split()
-                    self.process_compatability_version = compatability_version.strip('()')
+                    version_string = line[8:].strip()
+                    matched_pair = re.search("(.+)\((.+)\)", version_string)
+                    if matched_pair:
+                        self.process_version = matched_pair.group(1)
+                        self.process_compatability_version = matched_pair.group(2)
+                    else:
+                        self.process = version_string
+                        self.process_compatability_version = version_string
                 elif line.startswith ('Parent Process:'):
                     (self.parent_process_name, pid_with_brackets) = line[15:].strip().split()
                     self.parent_process_id = pid_with_brackets.strip('[]') 

Modified: lldb/branches/lldb-platform-work/llvm.zip
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/llvm.zip?rev=156590&r1=156589&r2=156590&view=diff
==============================================================================
Binary files - no diff available.





More information about the lldb-commits mailing list