1 //===- xray_interface.h -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file is a part of XRay, a dynamic runtime instrumentation system. 11 // 12 // APIs for controlling XRay functionality explicitly. 13 //===----------------------------------------------------------------------===// 14 15 #ifndef XRAY_XRAY_INTERFACE_H 16 #define XRAY_XRAY_INTERFACE_H 17 18 #include <cstddef> 19 #include <cstdint> 20 21 extern "C" { 22 23 /// Synchronize this with AsmPrinter::SledKind in LLVM. 24 enum XRayEntryType { 25 ENTRY = 0, 26 EXIT = 1, 27 TAIL = 2, 28 LOG_ARGS_ENTRY = 3, 29 CUSTOM_EVENT = 4, 30 }; 31 32 /// Provide a function to invoke for when instrumentation points are hit. This 33 /// is a user-visible control surface that overrides the default implementation. 34 /// The function provided should take the following arguments: 35 /// 36 /// - function id: an identifier that indicates the id of a function; this id 37 /// is generated by xray; the mapping between the function id 38 /// and the actual function pointer is available through 39 /// __xray_table. 40 /// - entry type: identifies what kind of instrumentation point was 41 /// encountered (function entry, function exit, etc.). See the 42 /// enum XRayEntryType for more details. 43 /// 44 /// The user handler must handle correctly spurious calls after this handler is 45 /// removed or replaced with another handler, because it would be too costly for 46 /// XRay runtime to avoid spurious calls. 47 /// To prevent circular calling, the handler function itself and all its 48 /// direct&indirect callees must not be instrumented with XRay, which can be 49 /// achieved by marking them all with: __attribute__((xray_never_instrument)) 50 /// 51 /// Returns 1 on success, 0 on error. 52 extern int __xray_set_handler(void (*entry)(int32_t, XRayEntryType)); 53 54 /// This removes whatever the currently provided handler is. Returns 1 on 55 /// success, 0 on error. 56 extern int __xray_remove_handler(); 57 58 /// Use XRay to log the first argument of each (instrumented) function call. 59 /// When this function exits, all threads will have observed the effect and 60 /// start logging their subsequent affected function calls (if patched). 61 /// 62 /// Returns 1 on success, 0 on error. 63 extern int __xray_set_handler_arg1(void (*)(int32_t, XRayEntryType, uint64_t)); 64 65 /// Disables the XRay handler used to log first arguments of function calls. 66 /// Returns 1 on success, 0 on error. 67 extern int __xray_remove_handler_arg1(); 68 69 /// Provide a function to invoke when XRay encounters a custom event. 70 extern int __xray_set_customevent_handler(void (*entry)(void*, std::size_t)); 71 72 /// This removes whatever the currently provided custom event handler is. 73 /// Returns 1 on success, 0 on error. 74 extern int __xray_remove_customevent_handler(); 75 76 enum XRayPatchingStatus { 77 NOT_INITIALIZED = 0, 78 SUCCESS = 1, 79 ONGOING = 2, 80 FAILED = 3, 81 }; 82 83 /// This tells XRay to patch the instrumentation points. See XRayPatchingStatus 84 /// for possible result values. 85 extern XRayPatchingStatus __xray_patch(); 86 87 /// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible 88 /// result values. 89 extern XRayPatchingStatus __xray_unpatch(); 90 91 /// This patches a specific function id. See XRayPatchingStatus for possible 92 /// result values. 93 extern XRayPatchingStatus __xray_patch_function(int32_t FuncId); 94 95 /// This unpatches a specific function id. See XRayPatchingStatus for possible 96 /// result values. 97 extern XRayPatchingStatus __xray_unpatch_function(int32_t FuncId); 98 99 /// This function returns the address of the function provided a valid function 100 /// id. We return 0 if we encounter any error, even if 0 may be a valid function 101 /// address. 102 extern uintptr_t __xray_function_address(int32_t FuncId); 103 104 /// This function returns the maximum valid function id. Returns 0 if we 105 /// encounter errors (when there are no instrumented functions, etc.). 106 extern size_t __xray_max_function_id(); 107 108 } // end extern "C" 109 110 #endif // XRAY_XRAY_INTERFACE_H 111