1 // Check that we can turn a function id to a function address, and also get the 2 // maximum function id for the current binary. 3 // 4 // RUN: %clangxx_xray -std=c++11 %s -o %t 5 // RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false" %run %t 6 7 // UNSUPPORTED: target-is-mips64,target-is-mips64el 8 9 #include "xray/xray_interface.h" 10 #include <algorithm> 11 #include <cassert> 12 #include <cstdio> 13 #include <iterator> 14 #include <set> 15 16 [[clang::xray_always_instrument]] void bar(){} 17 18 [[clang::xray_always_instrument]] void foo() { 19 bar(); 20 } 21 22 [[clang::xray_always_instrument]] int main(int argc, char *argv[]) { 23 assert(__xray_max_function_id() != 0 && "we need xray instrumentation!"); 24 std::set<void *> must_be_instrumented = {reinterpret_cast<void *>(&foo), 25 reinterpret_cast<void *>(&bar), 26 reinterpret_cast<void *>(&main)}; 27 std::set<void *> all_instrumented; 28 for (auto i = __xray_max_function_id(); i != 0; --i) { 29 auto addr = __xray_function_address(i); 30 all_instrumented.insert(reinterpret_cast<void *>(addr)); 31 } 32 assert(all_instrumented.size() == __xray_max_function_id() && 33 "each function id must be assigned to a unique function"); 34 35 std::set<void *> not_instrumented; 36 std::set_difference( 37 must_be_instrumented.begin(), must_be_instrumented.end(), 38 all_instrumented.begin(), all_instrumented.end(), 39 std::inserter(not_instrumented, not_instrumented.begin())); 40 assert( 41 not_instrumented.empty() && 42 "we should see all explicitly instrumented functions with function ids"); 43 return not_instrumented.empty() ? 0 : 1; 44 } 45