1// Check that ASan dumps the CPU registers on a SIGSEGV.
2
3// RUN: %clangxx_asan %s -o %t
4// RUN: not %run %t 2>&1 | FileCheck %s
5
6#include <assert.h>
7#include <stdio.h>
8#include <sys/mman.h>
9
10int main() {
11 fprintf(stderr, format: "Hello\n");
12 char *ptr;
13
14 ptr = (char *)mmap(NULL, len: 0x10000, PROT_NONE, MAP_ANON | MAP_PRIVATE, fd: -1, offset: 0);
15 assert(ptr && "failed to mmap");
16
17 fprintf(stderr, format: sizeof(uintptr_t) == 8 ? "p = 0x%016lx\n" : "p = 0x%08lx\n", (uintptr_t)ptr);
18 // CHECK: p = [[ADDR:0x[0-9]+]]
19
20 char c = *ptr; // BOOM
21 // CHECK: ERROR: AddressSanitizer: {{SEGV|BUS}}
22 // CHECK: Register values:
23 // CHECK: [[ADDR]]
24 fprintf(stderr, format: "World\n");
25 return c;
26}
27

source code of compiler-rt/test/asan/TestCases/Darwin/dump_registers.cpp