1// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s
2// RUN: %clangxx -O3 %s -o %t && %env_tool_opts=stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s
3// RUN: %env_tool_opts=stack_trace_format=frame%n_lineno%l %run %t 2>&1 | FileCheck %s --check-prefix=CUSTOM
4// RUN: %env_tool_opts=symbolize_inline_frames=false:stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s --check-prefix=NOINLINE
5// RUN: %env_tool_opts=stack_trace_format='"frame:%n address:%%p"' %run %t 2>&1 | FileCheck %s --check-prefix=NOSYMBOLIZE
6
7// UNSUPPORTED: darwin
8
9// TODO(yln): temporary failing due to refactoring
10// UNSUPPORTED: ubsan
11
12#include <sanitizer/common_interface_defs.h>
13
14static inline void FooBarBaz() {
15 __sanitizer_print_stack_trace();
16}
17
18int main() {
19 FooBarBaz();
20 return 0;
21}
22// CHECK: {{ #0 0x.* in __sanitizer_print_stack_trace}}
23// CHECK: {{ #1 0x.* in FooBarBaz(\(\))? .*}}print-stack-trace.cpp:[[@LINE-8]]
24// CHECK: {{ #2 0x.* in main.*}}print-stack-trace.cpp:[[@LINE-5]]
25
26// CUSTOM: frame1_lineno[[@LINE-11]]
27// CUSTOM: frame2_lineno[[@LINE-8]]
28
29// NOINLINE: #0 0x{{.*}} in __sanitizer_print_stack_trace
30// NOINLINE: #1 0x{{.*}} in main{{.*}}print-stack-trace.cpp:[[@LINE-15]]
31
32// NOSYMBOLIZE: frame:0 address:{{0x.*}}
33// NOSYMBOLIZE: frame:1 address:{{0x.*}}
34// NOSYMBOLIZE: frame:2 address:{{0x.*}}
35

source code of compiler-rt/test/sanitizer_common/TestCases/print-stack-trace.cpp