[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / symbolize_pc.cpp
blobf495e2cefdd74b34886b067ae2f1adf33f961d3f
1 // RUN: %clangxx -O0 %s -o %t
2 // RUN: %env_tool_opts=strip_path_prefix=/TestCases/ %run %t 2>&1 | FileCheck %s
3 //
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
15 #include <stdio.h>
16 #include <sanitizer/common_interface_defs.h>
18 int GLOBAL_VAR_ABC;
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,
27 sizeof(data));
28 printf("PARTIAL '%s'\n", data);
31 void SymbolizeCaller() {
32 char data[100];
33 __sanitizer_symbolize_pc(__sanitizer_return_address(), "%p %F %L", data,
34 sizeof(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",
46 data, sizeof(data));
47 printf("LONG_FORMAT %s\n", data);
50 struct s {
51 int i;
54 struct s SymbolizeSRet() {
55 char data[100];
56 __sanitizer_symbolize_pc(__sanitizer_return_address(),
57 "FUNC:%f LINE:%l FILE:%s", data, sizeof(data));
58 printf("SRET: %s\n", data);
59 struct s s = {1};
60 return s;
63 void SymbolizeData() {
64 char data[100];
65 __sanitizer_symbolize_global(&GLOBAL_VAR_ABC, "%g %s:%l", data, sizeof(data));
66 printf("GLOBAL: %s\n", data);
69 int main() {
70 // CHECK: UNCHANGED 'abcdef'
71 // CHECK: EMPTY ''
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
77 SymbolizeCaller();
79 struct s s;
80 // CHECK: SRET: FUNC:main LINE:[[@LINE+1]] FILE:symbolize_pc.cpp
81 s = SymbolizeSRet();
83 // CHECK: GLOBAL: GLOBAL_VAR_ABC
84 SymbolizeData();