[llvm-commits] [compiler-rt] r162754 - in /compiler-rt/trunk/lib/asan: asan_allocator.cc asan_report.cc asan_stack.cc asan_stack.h asan_thread.h

Kostya Serebryany kcc at google.com
Tue Aug 28 06:49:49 PDT 2012


Author: kcc
Date: Tue Aug 28 08:49:49 2012
New Revision: 162754

URL: http://llvm.org/viewvc/llvm-project?rev=162754&view=rev
Log:
[asan] even more refactoring to move StackTrace to sanitizer_common

Modified:
    compiler-rt/trunk/lib/asan/asan_allocator.cc
    compiler-rt/trunk/lib/asan/asan_report.cc
    compiler-rt/trunk/lib/asan/asan_stack.cc
    compiler-rt/trunk/lib/asan/asan_stack.h
    compiler-rt/trunk/lib/asan/asan_thread.h

Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=162754&r1=162753&r2=162754&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Tue Aug 28 08:49:49 2012
@@ -605,17 +605,17 @@
     StackTrace free_stack;
     StackTrace::UncompressStack(&free_stack, m->compressed_free_stack(),
                                     m->compressed_free_stack_size());
-    free_stack.PrintStack();
+    PrintStack(&free_stack);
     Printf("previously allocated by thread T%d here:\n",
                alloc_thread->tid());
 
-    alloc_stack.PrintStack();
+    PrintStack(&alloc_stack);
     t->summary()->Announce();
     free_thread->Announce();
     alloc_thread->Announce();
   } else {
     Printf("allocated by thread T%d here:\n", alloc_thread->tid());
-    alloc_stack.PrintStack();
+    PrintStack(&alloc_stack);
     t->summary()->Announce();
     alloc_thread->Announce();
   }

Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=162754&r1=162753&r2=162754&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Tue Aug 28 08:49:49 2012
@@ -258,13 +258,13 @@
              asanThreadRegistry().GetCurrentTidOrInvalid());
   Printf("AddressSanitizer can not provide additional info.\n");
   GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp);
-  stack.PrintStack();
+  PrintStack(&stack);
 }
 
 void ReportDoubleFree(uptr addr, StackTrace *stack) {
   ScopedInErrorReport in_report;
   Report("ERROR: AddressSanitizer attempting double-free on %p:\n", addr);
-  stack->PrintStack();
+  PrintStack(stack);
   DescribeHeapAddress(addr, 1);
 }
 
@@ -272,7 +272,7 @@
   ScopedInErrorReport in_report;
   Report("ERROR: AddressSanitizer attempting free on address "
              "which was not malloc()-ed: %p\n", addr);
-  stack->PrintStack();
+  PrintStack(stack);
   DescribeHeapAddress(addr, 1);
 }
 
@@ -281,7 +281,7 @@
   Report("ERROR: AddressSanitizer attempting to call "
              "malloc_usable_size() for pointer which is "
              "not owned: %p\n", addr);
-  stack->PrintStack();
+  PrintStack(stack);
   DescribeHeapAddress(addr, 1);
 }
 
@@ -290,7 +290,7 @@
   Report("ERROR: AddressSanitizer attempting to call "
              "__asan_get_allocated_size() for pointer which is "
              "not owned: %p\n", addr);
-  stack->PrintStack();
+  PrintStack(stack);
   DescribeHeapAddress(addr, 1);
 }
 
@@ -301,7 +301,7 @@
   Report("ERROR: AddressSanitizer %s-param-overlap: "
              "memory ranges [%p,%p) and [%p, %p) overlap\n", \
              function, offset1, offset1 + length1, offset2, offset2 + length2);
-  stack->PrintStack();
+  PrintStack(stack);
   DescribeAddress((uptr)offset1, length1);
   DescribeAddress((uptr)offset2, length2);
 }
@@ -315,7 +315,7 @@
              "AddressSanitizer is ignoring this error on Mac OS now.\n",
              addr);
   PrintZoneForPointer(addr, zone_ptr, zone_name);
-  stack->PrintStack();
+  PrintStack(stack);
   DescribeHeapAddress(addr, 1);
 }
 
@@ -326,7 +326,7 @@
              "This is an unrecoverable problem, exiting now.\n",
              addr);
   PrintZoneForPointer(addr, zone_ptr, zone_name);
-  stack->PrintStack();
+  PrintStack(stack);
   DescribeHeapAddress(addr, 1);
 }
 
@@ -337,7 +337,7 @@
              "This is an unrecoverable problem, exiting now.\n",
              addr);
   PrintZoneForPointer(addr, zone_ptr, zone_name);
-  stack->PrintStack();
+  PrintStack(stack);
   DescribeHeapAddress(addr, 1);
 }
 
@@ -401,7 +401,7 @@
              access_size, (void*)addr, curr_tid);
 
   GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp);
-  stack.PrintStack();
+  PrintStack(&stack);
 
   DescribeAddress(addr, access_size);
 

Modified: compiler-rt/trunk/lib/asan/asan_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.cc?rev=162754&r1=162753&r2=162754&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.cc Tue Aug 28 08:49:49 2012
@@ -20,10 +20,10 @@
 
 static __asan_symbolize_callback symbolize_callback;
 
-static const char *StripPathPrefix(const char *filepath) {
-  const char *path_prefix = flags()->strip_path_prefix;
-  if (filepath == internal_strstr(filepath, path_prefix))
-    return filepath + internal_strlen(path_prefix);
+static const char *StripPathPrefix(const char *filepath,
+                                   const char *strip_file_prefix) {
+  if (filepath == internal_strstr(filepath, strip_file_prefix))
+    return filepath + internal_strlen(strip_file_prefix);
   return filepath;
 }
 
@@ -39,7 +39,9 @@
   return pc - 1;
 }
 
-void StackTrace::PrintStack(uptr *addr, uptr size) {
+void StackTrace::PrintStack(uptr *addr, uptr size,
+                            bool symbolize, const char *strip_file_prefix,
+                            SymbolizeCallback symbolize_callback ) {
   MemoryMappingLayout proc_maps;
   uptr frame_num = 0;
   for (uptr i = 0; i < size && addr[i]; i++) {
@@ -50,15 +52,14 @@
       // We can't know anything about the string returned by external
       // symbolizer, but if it starts with filename, try to strip path prefix
       // from it.
-      Printf("  #%zu 0x%zx %s\n", frame_num, pc, StripPathPrefix(buff));
+      Printf("  #%zu 0x%zx %s\n", frame_num, pc,
+             StripPathPrefix(buff, strip_file_prefix));
       frame_num++;
       continue;
     }
     AddressInfo addr_frames[64];
-    uptr addr_frames_num = 0;
-    if (flags()->symbolize) {
-      addr_frames_num = SymbolizeCode(pc, addr_frames, ARRAY_SIZE(addr_frames));
-    }
+    uptr addr_frames_num =
+      symbolize ? SymbolizeCode(pc, addr_frames, ARRAY_SIZE(addr_frames)) : 0;
     if (addr_frames_num > 0) {
       for (uptr j = 0; j < addr_frames_num; j++) {
         AddressInfo &info = addr_frames[j];
@@ -67,11 +68,11 @@
           Printf(" in %s", info.function);
         }
         if (info.file) {
-          Printf(" %s:%d:%d", StripPathPrefix(info.file), info.line,
-                                  info.column);
+          Printf(" %s:%d:%d", StripPathPrefix(info.file, strip_file_prefix),
+                 info.line, info.column);
         } else if (info.module) {
-          Printf(" (%s+0x%zx)", StripPathPrefix(info.module),
-                                    info.module_offset);
+          Printf(" (%s+0x%zx)", StripPathPrefix(info.module, strip_file_prefix),
+                 info.module_offset);
         }
         Printf("\n");
         info.Clear();
@@ -82,8 +83,8 @@
       char filename[4096];
       if (proc_maps.GetObjectNameAndOffset(pc, &offset,
                                            filename, sizeof(filename))) {
-        Printf("    #%zu 0x%zx (%s+0x%zx)\n",
-                   frame_num, pc, StripPathPrefix(filename), offset);
+        Printf("    #%zu 0x%zx (%s+0x%zx)\n", frame_num, pc,
+               StripPathPrefix(filename, strip_file_prefix), offset);
       } else {
         Printf("    #%zu 0x%zx\n", frame_num, pc);
       }
@@ -222,6 +223,12 @@
 #endif  // __WORDSIZE
 }
 
+void PrintStack(StackTrace *stack) {
+  stack->PrintStack(stack->trace, stack->size, flags()->symbolize,
+                    flags()->strip_path_prefix, symbolize_callback);
+}
+
+
 }  // namespace __asan
 
 // ------------------ Interface -------------- {{{1

Modified: compiler-rt/trunk/lib/asan/asan_stack.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.h?rev=162754&r1=162753&r2=162754&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.h (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.h Tue Aug 28 08:49:49 2012
@@ -21,13 +21,14 @@
 static const uptr kStackTraceMax = 64;
 
 struct StackTrace {
+  typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,
+                                     int out_size);
   uptr size;
   uptr max_size;
   uptr trace[kStackTraceMax];
-  static void PrintStack(uptr *addr, uptr size);
-  void PrintStack() {
-    PrintStack(this->trace, this->size);
-  }
+  static void PrintStack(uptr *addr, uptr size,
+                         bool symbolize, const char *strip_file_prefix,
+                         SymbolizeCallback symbolize_callback);
   void CopyTo(uptr *dst, uptr dst_size) {
     for (uptr i = 0; i < size && i < dst_size; i++)
       dst[i] = trace[i];
@@ -53,7 +54,8 @@
                               u32 *compressed, uptr size);
 };
 
-void GetStackTrace(StackTrace *trace, uptr max_s, uptr pc, uptr bp);
+void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp);
+void PrintStack(StackTrace *stack);
 
 
 
@@ -100,7 +102,7 @@
 #define PRINT_CURRENT_STACK()                    \
   {                                              \
     GET_STACK_TRACE_HERE(kStackTraceMax);        \
-    stack.PrintStack();                          \
+    PrintStack(&stack);                          \
   }
 
 #endif  // ASAN_STACK_H

Modified: compiler-rt/trunk/lib/asan/asan_thread.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.h?rev=162754&r1=162753&r2=162754&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.h (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.h Tue Aug 28 08:49:49 2012
@@ -45,7 +45,7 @@
     if (!announced_) {
       announced_ = true;
       Printf("Thread T%d created by T%d here:\n", tid_, parent_tid_);
-      stack_.PrintStack();
+      PrintStack(&stack_);
     }
   }
   u32 tid() { return tid_; }





More information about the llvm-commits mailing list