diff options
author | Dean Michael Berris <dberris@google.com> | 2017-03-06 07:25:41 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2017-03-06 07:25:41 +0000 |
commit | a814c94163cc12df9c7b533cec22ea7cc4c20688 (patch) | |
tree | b957784bcb79019169a85adb3d175636c523afab /compiler-rt/lib/xray/xray_interface.cc | |
parent | 418da3fe80230c26afaa29db0787f709c67c74c3 (diff) | |
download | bcm5719-llvm-a814c94163cc12df9c7b533cec22ea7cc4c20688.tar.gz bcm5719-llvm-a814c94163cc12df9c7b533cec22ea7cc4c20688.zip |
[XRay] [compiler-rt] Allow logging the first argument of a function call.
Summary:
Functions with the LOG_ARGS_ENTRY sled kind at their beginning will be handled
in a way to (optionally) pass their first call argument to your logging handler.
For practical and performance reasons, only the first argument is supported, and
only up to 64 bits.
Reviewers: javed.absar, dberris
Reviewed By: dberris
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D29703
llvm-svn: 297000
Diffstat (limited to 'compiler-rt/lib/xray/xray_interface.cc')
-rw-r--r-- | compiler-rt/lib/xray/xray_interface.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/compiler-rt/lib/xray/xray_interface.cc b/compiler-rt/lib/xray/xray_interface.cc index 306dbcae720..39cf8efb340 100644 --- a/compiler-rt/lib/xray/xray_interface.cc +++ b/compiler-rt/lib/xray/xray_interface.cc @@ -48,6 +48,9 @@ static const int16_t cSledLength = 8; // This is the function to call when we encounter the entry or exit sleds. std::atomic<void (*)(int32_t, XRayEntryType)> XRayPatchedFunction{nullptr}; +// This is the function to call from the arg1-enabled sleds/trampolines. +std::atomic<void (*)(int32_t, XRayEntryType, uint64_t)> XRayArgLogger{nullptr}; + // MProtectHelper is an RAII wrapper for calls to mprotect(...) that will undo // any successful mprotect(...) changes. This is used to make a page writeable // and executable, and upon destruction if it was successful in doing so returns @@ -185,7 +188,7 @@ XRayPatchingStatus controlPatching(bool Enable) XRAY_NEVER_INSTRUMENT { bool Success = false; switch (Sled.Kind) { case XRayEntryType::ENTRY: - Success = patchFunctionEntry(Enable, FuncId, Sled); + Success = patchFunctionEntry(Enable, FuncId, Sled, __xray_FunctionEntry); break; case XRayEntryType::EXIT: Success = patchFunctionExit(Enable, FuncId, Sled); @@ -193,6 +196,9 @@ XRayPatchingStatus controlPatching(bool Enable) XRAY_NEVER_INSTRUMENT { case XRayEntryType::TAIL: Success = patchFunctionTailExit(Enable, FuncId, Sled); break; + case XRayEntryType::LOG_ARGS_ENTRY: + Success = patchFunctionEntry(Enable, FuncId, Sled, __xray_ArgLoggerEntry); + break; default: Report("Unsupported sled kind: %d\n", int(Sled.Kind)); continue; @@ -211,3 +217,16 @@ XRayPatchingStatus __xray_patch() XRAY_NEVER_INSTRUMENT { XRayPatchingStatus __xray_unpatch() XRAY_NEVER_INSTRUMENT { return controlPatching(false); } + +int __xray_set_handler_arg1(void (*Handler)(int32_t, XRayEntryType, uint64_t)) +{ + if (!XRayInitialized.load(std::memory_order_acquire)) { + return 0; + } + // A relaxed write might not be visible even if the current thread gets + // scheduled on a different CPU/NUMA node. We need to wait for everyone to + // have this handler installed for consistency of collected data across CPUs. + XRayArgLogger.store(Handler, std::memory_order_release); + return 1; +} +int __xray_remove_handler_arg1() { return __xray_set_handler_arg1(nullptr); } |