From b6657afbf2e4f85db5e0f27b359543c3577a8e23 Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Fri, 5 May 2017 01:27:11 +0000 Subject: [XRay][compiler-rt] Add function id utilities for XRay Summary: This change allows us to provide users and implementers of XRay handlers a means of converting XRay function id's to addresses. This, in combination with the facilities provided in D32695, allows users to find out: - How many function id's there are defined in the current binary. - Get the address of the function associated with this function id. - Patch only specific functions according to their requirements. While we don't directly provide symbolization support in XRay, having the function's address lets users determine this information easily either during runtime, or offline with tools like 'addr2line'. Reviewers: dblaikie, echristo, pelikan Subscribers: kpw, llvm-commits Differential Revision: https://reviews.llvm.org/D32846 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@302210 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/xray/xray_interface.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib/xray') diff --git a/lib/xray/xray_interface.cc b/lib/xray/xray_interface.cc index 73cca80bc..26f0ab122 100644 --- a/lib/xray/xray_interface.cc +++ b/lib/xray/xray_interface.cc @@ -255,7 +255,7 @@ XRayPatchingStatus patchFunction(int32_t FuncId, // FuncId must be a positive number, less than the number of functions // instrumented. - if (FuncId <= 0 || static_cast(FuncId) >= InstrMap.Functions) { + if (FuncId <= 0 || static_cast(FuncId) > InstrMap.Functions) { Report("Invalid function id provided: %d\n", FuncId); return XRayPatchingStatus::FAILED; } @@ -302,3 +302,15 @@ int __xray_set_handler_arg1(void (*Handler)(int32_t, XRayEntryType, uint64_t)) { return 1; } int __xray_remove_handler_arg1() { return __xray_set_handler_arg1(nullptr); } + +uintptr_t __xray_function_address(int32_t FuncId) XRAY_NEVER_INSTRUMENT { + __sanitizer::SpinMutexLock Guard(&XRayInstrMapMutex); + if (FuncId <= 0 || static_cast(FuncId) > XRayInstrMap.Functions) + return 0; + return XRayInstrMap.SledsIndex[FuncId - 1].Begin->Address; +} + +size_t __xray_max_function_id() XRAY_NEVER_INSTRUMENT { + __sanitizer::SpinMutexLock Guard(&XRayInstrMapMutex); + return XRayInstrMap.Functions; +} -- cgit v1.2.3