brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 2dbc681 Raw
57 lines · c
1// Check that we can patch and un-patch on demand, and that logging gets invoked2// appropriately.3//4// Do not run on powerpc64le, as linking XRay with C compiler causes linker error5// due to std::__throw_system_error(int) being present in XRay libraries.6// See https://github.com/llvm/llvm-project/issues/1415987//8// RUN: %clang_xray -fxray-instrument -std=c23 %s -o %t9// RUN: env XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s10// RUN: %clang_xray -fxray-instrument -fno-xray-function-index -std=c23 %s -o %t11// RUN: env XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s12 13// UNSUPPORTED: target-is-mips64,target-is-mips64el14// UNSUPPORTED: target=powerpc64le-{{.*}}15 16#include "xray/xray_interface.h"17 18#include <stdio.h>19 20bool called = false;21 22void test_handler(int32_t fid, enum XRayEntryType type) {23  printf("called: %d, type=%d\n", fid, (int32_t)(type));24  called = true;25}26 27[[clang::xray_always_instrument]] void always_instrument() {28  printf("always instrumented called\n");29}30 31int main() {32  __xray_set_handler(test_handler);33  always_instrument();34  // CHECK: always instrumented called35  auto status = __xray_patch();36  printf("patching status: %d\n", (int32_t)status);37  // CHECK-NEXT: patching status: 138  always_instrument();39  // CHECK-NEXT: called: {{.*}}, type=040  // CHECK-NEXT: always instrumented called41  // CHECK-NEXT: called: {{.*}}, type=142  status = __xray_unpatch();43  printf("patching status: %d\n", (int32_t)status);44  // CHECK-NEXT: patching status: 145  always_instrument();46  // CHECK-NEXT: always instrumented called47  status = __xray_patch();48  printf("patching status: %d\n", (int32_t)status);49  // CHECK-NEXT: patching status: 150  __xray_remove_handler();51  always_instrument();52  // CHECK-NEXT: always instrumented called53  status = __xray_unpatch();54  printf("patching status: %d\n", (int32_t)status);55  // CHECK-NEXT: patching status: 156}57