1 // Check that we can get the first function argument logged
2 // using a custom logging function.
3 //
4 // RUN: %clangxx_xray -std=c++11 %s -o %t
5 // RUN: rm -f arg1-logger-*
6 // RUN: XRAY_OPTIONS="patch_premain=true verbosity=1 xray_mode=xray-basic \
7 // RUN: xray_logfile_base=arg1-logger-" %run %t 2>&1 | FileCheck %s
8 //
9 // After all that, clean up the XRay log file.
10 //
11 // RUN: rm -f arg1-logger-*
12 //
13 // At the time of writing, the ARM trampolines weren't written yet.
14 // XFAIL: arm || aarch64 || mips
15 // See the mailing list discussion of r296998.
16 // UNSUPPORTED: powerpc64le
17
18 #include "xray/xray_interface.h"
19
20 #include <cinttypes>
21 #include <cstdio>
22
arg1logger(int32_t fn,XRayEntryType t,uint64_t a1)23 void arg1logger(int32_t fn, XRayEntryType t, uint64_t a1) {
24 printf("Arg1: %" PRIx64 ", XRayEntryType %u\n", a1, t);
25 }
26
foo(void *)27 [[clang::xray_always_instrument, clang::xray_log_args(1)]] void foo(void *) {}
28
main()29 int main() {
30 // CHECK: XRay: Log file in 'arg1-logger-{{.*}}'
31
32 __xray_set_handler_arg1(arg1logger);
33 foo(nullptr);
34 // CHECK: Arg1: 0, XRayEntryType 3
35
36 __xray_remove_handler_arg1();
37 foo((void *) 0xBADC0DE);
38 // nothing expected to see here
39
40 __xray_set_handler_arg1(arg1logger);
41 foo((void *) 0xDEADBEEFCAFE);
42 // CHECK-NEXT: Arg1: deadbeefcafe, XRayEntryType 3
43 foo((void *) -1);
44 // CHECK-NEXT: Arg1: ffffffffffffffff, XRayEntryType 3
45 }
46