]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/xray/TestCases/Linux/patching-unpatching.cc
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / xray / TestCases / Linux / patching-unpatching.cc
1 // Check that we can patch and un-patch on demand, and that logging gets invoked
2 // appropriately.
3 //
4 // RUN: %clangxx_xray -fxray-instrument -std=c++11 %s -o %t
5 // RUN: XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s
6
7 // UNSUPPORTED: target-is-mips64,target-is-mips64el
8
9 #include "xray/xray_interface.h"
10
11 #include <cstdio>
12
13 bool called = false;
14
15 void test_handler(int32_t fid, XRayEntryType type) {
16 printf("called: %d, type=%d\n", fid, static_cast<int32_t>(type));
17 called = true;
18 }
19
20 [[clang::xray_always_instrument]] void always_instrument() {
21 printf("always instrumented called\n");
22 }
23
24 int main() {
25 __xray_set_handler(test_handler);
26 always_instrument();
27 // CHECK: always instrumented called
28 auto status = __xray_patch();
29 printf("patching status: %d\n", static_cast<int32_t>(status));
30 // CHECK-NEXT: patching status: 1
31 always_instrument();
32 // CHECK-NEXT: called: {{.*}}, type=0
33 // CHECK-NEXT: always instrumented called
34 // CHECK-NEXT: called: {{.*}}, type=1
35 status = __xray_unpatch();
36 printf("patching status: %d\n", static_cast<int32_t>(status));
37 // CHECK-NEXT: patching status: 1
38 always_instrument();
39 // CHECK-NEXT: always instrumented called
40 status = __xray_patch();
41 printf("patching status: %d\n", static_cast<int32_t>(status));
42 // CHECK-NEXT: patching status: 1
43 __xray_remove_handler();
44 always_instrument();
45 // CHECK-NEXT: always instrumented called
46 status = __xray_unpatch();
47 printf("patching status: %d\n", static_cast<int32_t>(status));
48 // CHECK-NEXT: patching status: 1
49 }