diff options
author | Kuba Brecka <kuba.brecka@gmail.com> | 2015-01-22 23:36:47 +0000 |
---|---|---|
committer | Kuba Brecka <kuba.brecka@gmail.com> | 2015-01-22 23:36:47 +0000 |
commit | 1c29934203d703e76a41e3ac679b9469eca18976 (patch) | |
tree | cfbf671873aaf8372e6db0c2dfbd243974562aa9 /test | |
parent | 278371ed0f8902553b82d58378b809a7ce1cb6aa (diff) |
Fix/workaround for OS X truncated stacktraces taken by external tools
This patch is a proposed solution for https://code.google.com/p/address-sanitizer/issues/detail?id=375:
When the stacktraces are captured and printed by ASan itself, they are fine, but when the program has already printed the report (or is just printing it), capturing a stacktrace via other means is broken. "Other means" include OS X CrashReporter, debuggers or calling backtrace() within the program. For example calling backtrace() from a sanitizer_set_death_callback function prints a very truncated stacktrace.
Reviewed at http://reviews.llvm.org/D7103
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@226878 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/asan/TestCases/Darwin/crashlog-stacktraces.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/asan/TestCases/Darwin/crashlog-stacktraces.c b/test/asan/TestCases/Darwin/crashlog-stacktraces.c new file mode 100644 index 000000000..e9af5396e --- /dev/null +++ b/test/asan/TestCases/Darwin/crashlog-stacktraces.c @@ -0,0 +1,43 @@ +// 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 |