[PATCH] D58493: [libsanitizer] Handle assembler-generated dwarf info in backtrace
    Tom de Vries via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Thu Feb 21 01:53:32 PST 2019
    
    
  
vries created this revision.
vries added reviewers: kcc, m.ostapenko, jakubjelinek.
Herald added subscribers: Sanitizers, llvm-commits, jdoerfert, aprantl, kubamracek.
Herald added projects: LLVM, Sanitizers.
[ This patch attempts to fix a problem, for which another patch was submitted earlier ( https://reviews.llvm.org/D34149 ).  ]
Consider this test-case, which generates a segmentation fault:
...
int
main (void)
{
  void *ptr = (void *)0x01;
  int value = *((int *) ptr);
  return 0;
}
...
Using LD_PRELOAD we can see how libasan handles the segfault:
...
$ LD_PRELOAD=install/lib64/libasan.so ./a.out
...
Focusing just on the backtrace part for main we have:
...
  #0 0x4004a6 in main (a.out+0x4004a6)
...
and when compiled with -g, we have instead instead:
...
  #0 0x4004a6 in main test.c:5
...
When we compile the test-case to assembly without -g, but compile the
assembly with -g like this:
...
$ gcc test.c -S
$ gcc test.s -gdwarf-2 -c
$ gcc test.o
...
we get this, similar to the case without -g:
...
  #0 0x400481 in main (a.out+0x400481)
...
In this case, the executable contains DWARF file and line number information
for the assembly file, but it's not used because the function name is
missing in the DWARF .debug_info.
This patch fixes this, allowing us to get:
...
  #0 0x400481 in main test.s:14
...
Repository:
  rCRT Compiler Runtime
https://reviews.llvm.org/D58493
Files:
  libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc
Index: libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc
===================================================================
--- libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc
+++ libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc
@@ -109,14 +109,13 @@
                                        const char *filename, int lineno,
                                        const char *function) {
   SymbolizeCodeCallbackArg *cdata = (SymbolizeCodeCallbackArg *)vdata;
-  if (function) {
-    AddressInfo *info = cdata->get_new_frame(addr);
+  AddressInfo *info = cdata->get_new_frame(addr);
+  if (filename)
+    info->file = internal_strdup(filename);
+  info->line = lineno;
+  if (function)
     info->function = DemangleAlloc(function, /*always_alloc*/ true);
-    if (filename)
-      info->file = internal_strdup(filename);
-    info->line = lineno;
-    cdata->frames_symbolized++;
-  }
+  cdata->frames_symbolized++;
   return 0;
 }
 
@@ -161,7 +160,11 @@
   data.frames_symbolized = 0;
   backtrace_pcinfo((backtrace_state *)state_, addr, SymbolizeCodePCInfoCallback,
                    ErrorCallback, &data);
-  if (data.frames_symbolized > 0)
+  if (data.frames_symbolized == 1 && data.last->info.function == 0)
+    /* Augment the frame by trying to fill in the missing function with
+       backtrace_syminfo.  */
+    data.frames_symbolized = 0;
+  else if (data.frames_symbolized > 0)
     return true;
   backtrace_syminfo((backtrace_state *)state_, addr, SymbolizeCodeCallback,
                     ErrorCallback, &data);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58493.187737.patch
Type: text/x-patch
Size: 1588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190221/83489e46/attachment.bin>
    
    
More information about the llvm-commits
mailing list