1 // RUN: %clangxx -O0 %s -o %t
2 // RUN: %env_tool_opts=strip_path_prefix=/TestCases/ %run %t 2>&1 | FileCheck %s
4 // Tests __sanitizer_symbolize_pc.
6 // FIXME: Investigate why it does not print GLOBAL_VAR_ABC.
7 // XFAIL: hwasan && target=aarch64{{.*}}
8 // LSan tests fail on Darwin
9 // UNSUPPORTED: darwin && lsan
10 // tsan and ubsan are supported on darwin, but they currently fail
11 // on some platforms likely because the test platform is too old
12 // UNSUPPORTED: darwin && tsan
13 // UNSUPPORTED: darwin && ubsan
16 #include <sanitizer/common_interface_defs.h>
20 void SymbolizeSmallBuffer() {
21 char data
[] = "abcdef";
22 __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data
, 0);
23 printf("UNCHANGED '%s'\n", data
);
24 __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data
, 1);
25 printf("EMPTY '%s'\n", data
);
26 __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data
,
28 printf("PARTIAL '%s'\n", data
);
31 void SymbolizeCaller() {
33 __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data
,
35 printf("FIRST_FORMAT %s\n", data
);
36 __sanitizer_symbolize_pc(__sanitizer_return_address(),
37 "FUNC:%f LINE:%l FILE:%s", data
, sizeof(data
));
38 printf("SECOND_FORMAT %s\n", data
);
39 __sanitizer_symbolize_pc(__sanitizer_return_address(),
40 "LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
41 "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
42 "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
43 "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
44 "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"
45 "FUNC:%f LINE:%l FILE:%s",
47 printf("LONG_FORMAT %s\n", data
);
54 struct s
SymbolizeSRet() {
56 __sanitizer_symbolize_pc(__sanitizer_return_address(),
57 "FUNC:%f LINE:%l FILE:%s", data
, sizeof(data
));
58 printf("SRET: %s\n", data
);
63 void SymbolizeData() {
65 __sanitizer_symbolize_global(&GLOBAL_VAR_ABC
, "%g %s:%l", data
, sizeof(data
));
66 printf("GLOBAL: %s\n", data
);
70 // CHECK: UNCHANGED 'abcdef'
72 // CHECK: PARTIAL '0x{{.*}}'
73 SymbolizeSmallBuffer();
75 // CHECK: FIRST_FORMAT 0x{{.*}} in main symbolize_pc.cpp:[[@LINE+2]]
76 // CHECK: SECOND_FORMAT FUNC:main LINE:[[@LINE+1]] FILE:symbolize_pc.cpp
80 // CHECK: SRET: FUNC:main LINE:[[@LINE+1]] FILE:symbolize_pc.cpp
83 // CHECK: GLOBAL: GLOBAL_VAR_ABC