[PATCH] [compiler-rt] Fix/workaround for OS X truncated stacktraces taken by external tools
Kuba Brecka
kuba.brecka at gmail.com
Wed Jan 21 11:20:43 PST 2015
Adding the testcase into the patch.
http://reviews.llvm.org/D7103
Files:
lib/asan/asan_mac.cc
lib/asan/asan_report.cc
lib/sanitizer_common/sanitizer_internal_defs.h
test/asan/TestCases/Darwin/crashlog-stacktraces.c
Index: lib/asan/asan_mac.cc
===================================================================
--- lib/asan/asan_mac.cc
+++ lib/asan/asan_mac.cc
@@ -374,13 +374,6 @@
work(); \
}
-// Forces the compiler to generate a frame pointer in the function.
-#define ENABLE_FRAME_POINTER \
- do { \
- volatile uptr enable_fp; \
- enable_fp = GET_CURRENT_FRAME(); \
- } while (0)
-
INTERCEPTOR(void, dispatch_async,
dispatch_queue_t dq, void(^work)(void)) {
ENABLE_FRAME_POINTER;
Index: lib/asan/asan_report.cc
===================================================================
--- lib/asan/asan_report.cc
+++ lib/asan/asan_report.cc
@@ -937,6 +937,8 @@
void __asan_report_error(uptr pc, uptr bp, uptr sp, uptr addr, int is_write,
uptr access_size) {
+ ENABLE_FRAME_POINTER;
+
// Determine the error type.
const char *bug_descr = "unknown-crash";
if (AddrIsInMem(addr)) {
Index: lib/sanitizer_common/sanitizer_internal_defs.h
===================================================================
--- lib/sanitizer_common/sanitizer_internal_defs.h
+++ lib/sanitizer_common/sanitizer_internal_defs.h
@@ -325,4 +325,11 @@
} while (internal_iserror(res, &rverrno) && rverrno == EINTR); \
}
+// Forces the compiler to generate a frame pointer in the function.
+#define ENABLE_FRAME_POINTER \
+ do { \
+ volatile uptr enable_fp; \
+ enable_fp = GET_CURRENT_FRAME(); \
+ } while (0)
+
#endif // SANITIZER_DEFS_H
Index: test/asan/TestCases/Darwin/crashlog-stacktraces.c
===================================================================
--- test/asan/TestCases/Darwin/crashlog-stacktraces.c
+++ 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
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7103.18541.patch
Type: text/x-patch
Size: 3102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150121/dbe299a3/attachment.bin>
More information about the llvm-commits
mailing list