76 lines · cpp
1// Check that we can patch and un-patch on demand, and that logging gets invoked2// appropriately.3//4 5// RUN: split-file %s %t6// RUN: %clangxx_xray -g -fPIC -fxray-instrument -fxray-shared -shared -std=c++11 %t/testlib.cpp -o %t/testlib.so7// RUN: %clangxx_xray -g -fPIC -fxray-instrument -fxray-shared -std=c++11 %t/main.cpp %t/testlib.so -Wl,-rpath,%t -o %t/main.o8 9// RUN: env XRAY_OPTIONS="patch_premain=false" %run %t/main.o 2>&1 | FileCheck %s10 11// REQUIRES: target={{(aarch64|x86_64)-.*}}12 13//--- main.cpp14 15#include "xray/xray_interface.h"16 17#include <cstdio>18 19bool called = false;20 21void test_handler(int32_t fid, XRayEntryType type) {22 printf("called: %d, type=%d\n", fid, static_cast<int32_t>(type));23 called = true;24}25 26[[clang::xray_always_instrument]] void instrumented_in_executable() {27 printf("instrumented_in_executable called\n");28}29 30extern void instrumented_in_dso();31 32int main() {33 __xray_set_handler(test_handler);34 instrumented_in_executable();35 // CHECK: instrumented_in_executable called36 instrumented_in_dso();37 // CHECK: instrumented_in_dso called38 auto status = __xray_patch();39 printf("patching status: %d\n", static_cast<int32_t>(status));40 // CHECK-NEXT: patching status: 141 instrumented_in_executable();42 // CHECK-NEXT: called: {{.*}}, type=043 // CHECK-NEXT: instrumented_in_executable called44 // CHECK-NEXT: called: {{.*}}, type=145 instrumented_in_dso();46 // CHECK-NEXT: called: {{.*}}, type=047 // CHECK-NEXT: instrumented_in_dso called48 // CHECK-NEXT: called: {{.*}}, type=149 status = __xray_unpatch();50 printf("patching status: %d\n", static_cast<int32_t>(status));51 // CHECK-NEXT: patching status: 152 instrumented_in_executable();53 // CHECK-NEXT: instrumented_in_executable called54 instrumented_in_dso();55 // CHECK-NEXT: instrumented_in_dso called56 status = __xray_patch();57 printf("patching status: %d\n", static_cast<int32_t>(status));58 // CHECK-NEXT: patching status: 159 __xray_remove_handler();60 instrumented_in_executable();61 // CHECK-NEXT: instrumented_in_executable called62 instrumented_in_dso();63 // CHECK-NEXT: instrumented_in_dso called64 status = __xray_unpatch();65 printf("patching status: %d\n", static_cast<int32_t>(status));66 // CHECK-NEXT: patching status: 167}68 69//--- testlib.cpp70 71#include <cstdio>72 73[[clang::xray_always_instrument]] void instrumented_in_dso() {74 printf("instrumented_in_dso called\n");75}76