| 1 | // RUN: %clangxx_xray %s -o %t |
| 2 | // RUN: env XRAY_OPTIONS=patch_premain=false:verbosity=1 %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | // REQUIRES: target={{(aarch64|x86_64)-.*linux.*}} |
| 5 | |
| 6 | #include <assert.h> |
| 7 | #include <stdio.h> |
| 8 | #include "xray/xray_interface.h" |
| 9 | |
| 10 | [[clang::xray_always_instrument]] void foo() { |
| 11 | static constexpr char CustomLogged[] = "hello custom logging!" ; |
| 12 | printf(format: "before calling the custom logging...\n" ); |
| 13 | __xray_typedevent(42, CustomLogged, sizeof(CustomLogged)); |
| 14 | printf(format: "after calling the custom logging...\n" ); |
| 15 | } |
| 16 | |
| 17 | static void myprinter(size_t type, const void *ptr, size_t size) { |
| 18 | assert(type == 42); |
| 19 | printf(format: "%.*s\n" , static_cast<int>(size), static_cast<const char*>(ptr)); |
| 20 | } |
| 21 | |
| 22 | int main() { |
| 23 | // CHECK: before calling the custom logging... |
| 24 | // CHECK-NEXT: after calling the custom logging... |
| 25 | foo(); |
| 26 | __xray_set_typedevent_handler(entry: myprinter); |
| 27 | __xray_patch(); |
| 28 | // CHECK-NEXT: before calling the custom logging... |
| 29 | // CHECK-NEXT: hello custom logging! |
| 30 | // CHECK-NEXT: after calling the custom logging... |
| 31 | foo(); |
| 32 | // CHECK-NEXT: before calling the custom logging... |
| 33 | // CHECK-NEXT: after calling the custom logging... |
| 34 | __xray_remove_typedevent_handler(); |
| 35 | foo(); |
| 36 | } |
| 37 | |