diff options
author | Dean Michael Berris <dberris@google.com> | 2017-05-05 01:27:11 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2017-05-05 01:27:11 +0000 |
commit | b6657afbf2e4f85db5e0f27b359543c3577a8e23 (patch) | |
tree | 230a396473ba1bf02e6348b3eaf24e0fbf3c365f /test | |
parent | daf4d1dbabac3085ea44745f44decc99449e5771 (diff) |
[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
Diffstat (limited to 'test')
-rw-r--r-- | test/xray/TestCases/Linux/func-id-utils.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/xray/TestCases/Linux/func-id-utils.cc b/test/xray/TestCases/Linux/func-id-utils.cc new file mode 100644 index 000000000..834e7b499 --- /dev/null +++ b/test/xray/TestCases/Linux/func-id-utils.cc @@ -0,0 +1,46 @@ +// Check that we can turn a function id to a function address, and also get the +// maximum function id for the current binary. +// +// RUN: %clangxx_xray -std=c++11 %s -o %t +// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false" %run %t | FileCheck %s + +#include "xray/xray_interface.h" +#include <algorithm> +#include <cstdio> +#include <set> +#include <iterator> + +[[clang::xray_always_instrument]] void bar(){ + // do nothing! +} + + [[clang::xray_always_instrument]] void foo() { + bar(); +} + +[[clang::xray_always_instrument]] int main(int argc, char *argv[]) { + printf("max function id: %zu\n", __xray_max_function_id()); + // CHECK: max function id: [[MAX:.*]] + + std::set<void *> must_be_instrumented; + must_be_instrumented.insert(reinterpret_cast<void*>(&foo)); + must_be_instrumented.insert(reinterpret_cast<void*>(&bar)); + printf("addresses:\n"); + std::set<void *> all_instrumented; + for (auto i = __xray_max_function_id(); i != 0; --i) { + auto addr = __xray_function_address(i); + printf("#%lu -> @%04lx\n", i, addr); + all_instrumented.insert(reinterpret_cast<void *>(addr)); + } + + // CHECK-LABEL: addresses: + // CHECK: #[[MAX]] -> @[[ADDR:.*]] + // CHECK-NOT: #0 -> @{{.*}} + std::set<void *> common; + + std::set_intersection(all_instrumented.begin(), all_instrumented.end(), + must_be_instrumented.begin(), + must_be_instrumented.end(), + std::inserter(common, common.begin())); + return common == must_be_instrumented ? 0 : 1; +} |