Open GoogleCodeExporter opened 9 years ago
// RUN: %clang_asan -O0 %s -o %t
// RUN: not %run %t 2>&1 | FileCheck %s
#include <execinfo.h>
#include <sanitizer/common_interface_defs.h>
#include <stdio.h>
#include <stdlib.h>
void death_function() {
fprintf(stderr, "DEATH CALLBACK\n");
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
fprintf(stderr, "%s\n", strs[i]);
}
free(strs);
fprintf(stderr, "END OF BACKTRACE\n");
}
int fault_function() {
char *x = (char*)malloc(10 * sizeof(char));
free(x);
return x[5]; // BOOM
}
int main() {
__sanitizer_set_death_callback(death_function);
fault_function();
return 0;
}
// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
// CHECK: {{READ of size 1 at 0x.* thread T0}}
// CHECK: {{ #0 0x.* in fault_function}}
// CHECK: DEATH CALLBACK
// CHECK: death_function
// CHECK: fault_function
// CHECK: main
// CHECK: END OF BACKTRACE
Original comment by kuba.brecka@gmail.com
on 21 Jan 2015 at 3:42
Isn't unwind info sufficient for CrashReporter to unwind the stack? Note that
ASan runtime is able to successfully unwind despite the missing stack traces.
Can we just pass the stack trace collected by ASan to CrashReporter?
Original comment by ramosian.glider@gmail.com
on 21 Jan 2015 at 8:29
Although CrashReporter has some private API to add information to a crashlog,
that would only add additional information. The main stack trace is still taken
by CrashReporter itself, and tools that work with crash logs will use this
trace.
But I'm more surprised that LLDB is actually truncating the stack trace as
well, which makes debugging terrible, and that also makes this look like
something worth fixing in ASan itself.
It also seems to me that this could be done by forcing having a stackframe in
__asan_report_error only, by using the ENABLE_FRAME_POINTER macro, which we're
already using elsewhere (asan_mac.cc). What do you think?
Original comment by kuba.brecka@gmail.com
on 21 Jan 2015 at 6:41
Seems like a bug or limitation in LLDB. It's probably worth working around in
ASan, but it would be good to get this reduced and filed upstream with LLDB too.
Original comment by rnk@google.com
on 21 Jan 2015 at 6:50
Submitted a proposed patch into http://reviews.llvm.org/D7103
Original comment by kuba.brecka@gmail.com
on 21 Jan 2015 at 7:18
So doesn't CrashReporter use unwind info rather than frame pointers to unwind
the stack?
I'm ok with the proposed patch, but still curious why it's necessary.
Original comment by ramosian.glider@gmail.com
on 22 Jan 2015 at 1:53
CrashReporter and backtrace() currently unwind via eh_frame and/or stack
frames. That works fine for most code, including system libraries, because on
OS X system libraries (usually) don't use -fomit-frame-pointer. LLDB does know
how to use the compact unwind info, but apparently for i386 there is a separate
bug in LLDB, which I filed as rdar://problem/19570035.
Anyway, if it's okay, I'm going to submit the proposed workaround that forces a
proper stack frame on __asan_report_error (http://reviews.llvm.org/D7103).
Original comment by kuba.brecka@gmail.com
on 22 Jan 2015 at 11:30
Committed the workaround in r226878.
Original comment by kuba.brecka@gmail.com
on 22 Jan 2015 at 11:39
The LLDB issue is fixed with r226889:
http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20150119/015056.html
Original comment by kuba.brecka@gmail.com
on 23 Jan 2015 at 3:29
Original issue reported on code.google.com by
kuba.brecka@gmail.com
on 21 Jan 2015 at 3:41