1 // Allow having both the no-arg and arg1 logging implementation live together,
2 // and be called in the correct cases.
3 //
4 // RUN: rm -f arg0-arg1-logging-*
5 // RUN: %clangxx_xray -std=c++11 %s -o %t
6 // RUN: XRAY_OPTIONS="patch_premain=true verbosity=1 xray_logfile_base=arg0-arg1-logging-" %run %t
7 //
8 // TODO: Support these in ARM and PPC
9 // XFAIL: arm || aarch64 || mips
10 // UNSUPPORTED: powerpc64le
11
12 #include "xray/xray_interface.h"
13 #include <cassert>
14 #include <cstdio>
15
16 using namespace std;
17
18 bool arg0loggercalled = false;
arg0logger(int32_t,XRayEntryType)19 void arg0logger(int32_t, XRayEntryType) { arg0loggercalled = true; }
20
arg0fn()21 [[clang::xray_always_instrument]] void arg0fn() { printf("hello, arg0!\n"); }
22
23 bool arg1loggercalled = false;
arg1logger(int32_t,XRayEntryType,uint64_t)24 void arg1logger(int32_t, XRayEntryType, uint64_t) { arg1loggercalled = true; }
25
26 [[ clang::xray_always_instrument, clang::xray_log_args(1) ]] void
arg1fn(uint64_t arg1)27 arg1fn(uint64_t arg1) {
28 printf("hello, arg1!\n");
29 }
30
main(int argc,char * argv[])31 int main(int argc, char *argv[]) {
32 __xray_set_handler(arg0logger);
33 __xray_set_handler_arg1(arg1logger);
34 arg0fn();
35 arg1fn(0xcafef00d);
36 __xray_remove_handler_arg1();
37 __xray_remove_handler();
38 assert(arg0loggercalled && arg1loggercalled);
39 }
40