1// RUN: %clangxx %s -g -O0 -o %t-with-debug
2
3// With debug info atos reports the source location, but no function offset. We fallback to dladdr() to retrieve the function offset.
4// RUN: %env_tool_opts=verbosity=2,stack_trace_format='"function_name:%f function_offset:%q"' %run %t-with-debug > %t-with-debug.output 2>&1
5// RUN: FileCheck -input-file=%t-with-debug.output %s
6
7// Without debug info atos reports the function offset and so dladdr() fallback is not used.
8// RUN: rm -rf %t-with-debug.dSYM
9// RUN: %env_tool_opts=verbosity=2,stack_trace_format='"function_name:%f function_offset:%q"' %run %t-with-debug > %t-no-debug.output 2>&1
10// RUN: FileCheck -input-file=%t-no-debug.output %s
11
12#include <sanitizer/common_interface_defs.h>
13#include <stdio.h>
14
15void baz() {
16 printf(format: "Do stuff in baz\n");
17 __sanitizer_print_stack_trace();
18}
19
20void bar() {
21 printf(format: "Do stuff in bar\n");
22 baz();
23}
24
25void foo() {
26 printf(format: "Do stuff in foo\n");
27 bar();
28}
29
30int main() {
31 printf(format: "Do stuff in main\n");
32 foo();
33 return 0;
34}
35
36// CHECK: Using atos found at:
37
38// These `function_offset` patterns are designed to disallow `0x0` which is the
39// value printed for `kUnknown`.
40// CHECK: function_name:baz{{(\(\))?}} function_offset:0x{{0*[1-9a-f][0-9a-f]*$}}
41// CHECK: function_name:bar{{(\(\))?}} function_offset:0x{{0*[1-9a-f][0-9a-f]*$}}
42// CHECK: function_name:foo{{(\(\))?}} function_offset:0x{{0*[1-9a-f][0-9a-f]*$}}
43// CHECK: function_name:main{{(\(\))?}} function_offset:0x{{0*[1-9a-f][0-9a-f]*$}}
44

source code of compiler-rt/test/sanitizer_common/TestCases/Darwin/symbolizer-function-offset-atos.cpp