52 lines · cpp
1// Check that we can patch and un-patch on demand, and that logging gets invoked2// appropriately.3//4// RUN: %clangxx_xray -fxray-instrument -std=c++11 %s -o %t5// RUN: env XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s6// RUN: %clangxx_xray -fxray-instrument -fno-xray-function-index -std=c++11 %s -o %t7// RUN: env XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s8 9// UNSUPPORTED: target-is-mips64,target-is-mips64el10 11#include "xray/xray_interface.h"12 13#include <cstdio>14 15bool called = false;16 17void test_handler(int32_t fid, XRayEntryType type) {18 printf("called: %d, type=%d\n", fid, static_cast<int32_t>(type));19 called = true;20}21 22[[clang::xray_always_instrument]] void always_instrument() {23 printf("always instrumented called\n");24}25 26int main() {27 __xray_set_handler(test_handler);28 always_instrument();29 // CHECK: always instrumented called30 auto status = __xray_patch();31 printf("patching status: %d\n", static_cast<int32_t>(status));32 // CHECK-NEXT: patching status: 133 always_instrument();34 // CHECK-NEXT: called: {{.*}}, type=035 // CHECK-NEXT: always instrumented called36 // CHECK-NEXT: called: {{.*}}, type=137 status = __xray_unpatch();38 printf("patching status: %d\n", static_cast<int32_t>(status));39 // CHECK-NEXT: patching status: 140 always_instrument();41 // CHECK-NEXT: always instrumented called42 status = __xray_patch();43 printf("patching status: %d\n", static_cast<int32_t>(status));44 // CHECK-NEXT: patching status: 145 __xray_remove_handler();46 always_instrument();47 // CHECK-NEXT: always instrumented called48 status = __xray_unpatch();49 printf("patching status: %d\n", static_cast<int32_t>(status));50 // CHECK-NEXT: patching status: 151}52