| 1 | // Use the clang feature for custom xray event logging. |
| 2 | // |
| 3 | // RUN: %clangxx_xray -std=c++11 %s -o %t |
| 4 | // RUN: XRAY_OPTIONS="patch_premain=false verbosity=1 xray_logfile_base=custom-event-logging.xray-" %run %t 2>&1 | FileCheck %s |
| 5 | // RUN: %clangxx_xray -std=c++11 -fpic -fpie %s -o %t |
| 6 | // RUN: XRAY_OPTIONS="patch_premain=false verbosity=1 xray_logfile_base=custom-event-logging.xray-" %run %t 2>&1 | FileCheck %s |
| 7 | // FIXME: Support this in non-x86_64 as well |
| 8 | // REQUIRES: target={{(aarch64|x86_64)-.*linux.*}} |
| 9 | // REQUIRES: built-in-llvm-tree |
| 10 | #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(format: "before calling the custom logging...\n" ); |
| 16 | __xray_customevent(CustomLogged, sizeof(CustomLogged)); |
| 17 | printf(format: "after calling the custom logging...\n" ); |
| 18 | } |
| 19 | |
| 20 | void myprinter(void* ptr, size_t size) { |
| 21 | printf(format: "%.*s\n" , static_cast<int>(size), static_cast<const char*>(ptr)); |
| 22 | } |
| 23 | |
| 24 | int main() { |
| 25 | foo(); |
| 26 | // CHECK: before calling the custom logging... |
| 27 | // CHECK-NEXT: after calling the custom logging... |
| 28 | printf(format: "setting up custom event handler...\n" ); |
| 29 | // CHECK-NEXT: setting up custom event handler... |
| 30 | __xray_set_customevent_handler(entry: 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(format: "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 | |