summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Darwin/dump_registers.cc
diff options
context:
space:
mode:
authorKuba Mracek <mracek@apple.com>2016-11-26 00:50:08 +0000
committerKuba Mracek <mracek@apple.com>2016-11-26 00:50:08 +0000
commit1db1375b1bbba6ca06ff7dd0f9132d4dea61cc1d (patch)
treecd78bfc5265abd5226f19c83be0bc514966967d7 /test/asan/TestCases/Darwin/dump_registers.cc
parentcbb51ab7b2ca8d2e9f142ff43b36bf5fbffd388b (diff)
downloadcompiler-rt-1db1375b1bbba6ca06ff7dd0f9132d4dea61cc1d.tar.gz
[asan] Add a "dump_registers" flag to print out CPU registers after a SIGSEGV
This patch prints out all CPU registers after a SIGSEGV. These are available in the signal handler context. Only implemented for Darwin. Can be turned off with the dump_registers flag. Differential Revision: https://reviews.llvm.org/D11365 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@287957 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan/TestCases/Darwin/dump_registers.cc')
-rw-r--r--test/asan/TestCases/Darwin/dump_registers.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/asan/TestCases/Darwin/dump_registers.cc b/test/asan/TestCases/Darwin/dump_registers.cc
new file mode 100644
index 000000000..884ad2ed4
--- /dev/null
+++ b/test/asan/TestCases/Darwin/dump_registers.cc
@@ -0,0 +1,26 @@
+// Check that ASan dumps the CPU registers on a SIGSEGV.
+
+// RUN: %clangxx_asan %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdio.h>
+
+int main() {
+ fprintf(stderr, "Hello\n");
+ char *ptr;
+
+ if (sizeof(void *) == 8)
+ ptr = (char *)0x6666666666666666;
+ else if (sizeof(void *) == 4)
+ ptr = (char *)0x55555555;
+ else
+ assert(0 && "Your computer is weird.");
+
+ char c = *ptr; // BOOM
+ // CHECK: ERROR: AddressSanitizer: SEGV
+ // CHECK: Register values:
+ // CHECK: {{0x55555555|0x6666666666666666}}
+ fprintf(stderr, "World\n");
+ return c;
+}