43 lines · cpp
1// Use the clang feature for custom xray event logging.2//3// RUN: %clangxx_xray -std=c++11 %s -o %t4// RUN: env XRAY_OPTIONS="patch_premain=false verbosity=1 xray_logfile_base=custom-event-logging.xray-" %run %t 2>&1 | FileCheck %s5// RUN: %clangxx_xray -std=c++11 -fpic -fpie %s -o %t6// RUN: env XRAY_OPTIONS="patch_premain=false verbosity=1 xray_logfile_base=custom-event-logging.xray-" %run %t 2>&1 | FileCheck %s7// FIXME: Support this in non-x86_64 as well8// REQUIRES: target={{(aarch64|x86_64)-.*linux.*}}9// REQUIRES: built-in-llvm-tree10#include <cstdio>11#include "xray/xray_interface.h"12 13[[clang::xray_always_instrument]] void foo() {14 static constexpr char CustomLogged[] = "hello custom logging!";15 printf("before calling the custom logging...\n");16 __xray_customevent(CustomLogged, sizeof(CustomLogged));17 printf("after calling the custom logging...\n");18}19 20void myprinter(void* ptr, size_t size) {21 printf("%.*s\n", static_cast<int>(size), static_cast<const char*>(ptr));22}23 24int main() {25 foo();26 // CHECK: before calling the custom logging...27 // CHECK-NEXT: after calling the custom logging...28 printf("setting up custom event handler...\n");29 // CHECK-NEXT: setting up custom event handler...30 __xray_set_customevent_handler(myprinter);31 __xray_patch();32 // CHECK-NEXT: before calling the custom logging...33 foo();34 // CHECK-NEXT: hello custom logging!35 // CHECK-NEXT: after calling the custom logging...36 printf("removing custom event handler...\n");37 // CHECK-NEXT: removing custom event handler...38 __xray_remove_customevent_handler();39 foo();40 // CHECK-NEXT: before calling the custom logging...41 // CHECK-NEXT: after calling the custom logging...42}43