[LVI] Add trunc to i1 handling. (#124480)
[llvm-project.git] / compiler-rt / test / xray / TestCases / Posix / patching-unpatching-dso.cpp
blob640cf9bcc1a341a59d70fbeb1637a79943e5ecdb
1 // Check that we can patch and un-patch on demand, and that logging gets invoked
2 // appropriately.
3 //
5 // RUN: split-file %s %t
6 // RUN: %clangxx_xray -g -fPIC -fxray-instrument -fxray-shared -shared -std=c++11 %t/testlib.cpp -o %t/testlib.so
7 // RUN: %clangxx_xray -g -fPIC -fxray-instrument -fxray-shared -std=c++11 %t/main.cpp %t/testlib.so -Wl,-rpath,%t -o %t/main.o
9 // RUN: XRAY_OPTIONS="patch_premain=false" %run %t/main.o 2>&1 | FileCheck %s
11 // REQUIRES: target={{(aarch64|x86_64)-.*}}
13 //--- main.cpp
15 #include "xray/xray_interface.h"
17 #include <cstdio>
19 bool called = false;
21 void test_handler(int32_t fid, XRayEntryType type) {
22 printf("called: %d, type=%d\n", fid, static_cast<int32_t>(type));
23 called = true;
26 [[clang::xray_always_instrument]] void instrumented_in_executable() {
27 printf("instrumented_in_executable called\n");
30 extern void instrumented_in_dso();
32 int main() {
33 __xray_set_handler(test_handler);
34 instrumented_in_executable();
35 // CHECK: instrumented_in_executable called
36 instrumented_in_dso();
37 // CHECK: instrumented_in_dso called
38 auto status = __xray_patch();
39 printf("patching status: %d\n", static_cast<int32_t>(status));
40 // CHECK-NEXT: patching status: 1
41 instrumented_in_executable();
42 // CHECK-NEXT: called: {{.*}}, type=0
43 // CHECK-NEXT: instrumented_in_executable called
44 // CHECK-NEXT: called: {{.*}}, type=1
45 instrumented_in_dso();
46 // CHECK-NEXT: called: {{.*}}, type=0
47 // CHECK-NEXT: instrumented_in_dso called
48 // CHECK-NEXT: called: {{.*}}, type=1
49 status = __xray_unpatch();
50 printf("patching status: %d\n", static_cast<int32_t>(status));
51 // CHECK-NEXT: patching status: 1
52 instrumented_in_executable();
53 // CHECK-NEXT: instrumented_in_executable called
54 instrumented_in_dso();
55 // CHECK-NEXT: instrumented_in_dso called
56 status = __xray_patch();
57 printf("patching status: %d\n", static_cast<int32_t>(status));
58 // CHECK-NEXT: patching status: 1
59 __xray_remove_handler();
60 instrumented_in_executable();
61 // CHECK-NEXT: instrumented_in_executable called
62 instrumented_in_dso();
63 // CHECK-NEXT: instrumented_in_dso called
64 status = __xray_unpatch();
65 printf("patching status: %d\n", static_cast<int32_t>(status));
66 // CHECK-NEXT: patching status: 1
69 //--- testlib.cpp
71 #include <cstdio>
73 [[clang::xray_always_instrument]] void instrumented_in_dso() {
74 printf("instrumented_in_dso called\n");