Skip to content

Commit

Permalink
[XRay][tools] Support new kinds of instrumentation map entries
Browse files Browse the repository at this point in the history
Summary:
When extracting the instrumentation map from a binary, we should be able
to recognize the new kinds of instrumentation sleds we've been emitting
with the compiler using -fxray-instrument. This change adds a test for
all the kinds of sleds we currently support (sans the tail-call sled,
which is a bit harder to force in a simple prebuilt input).

Reviewers: kpw, dblaikie

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D36819

llvm-svn: 311305
  • Loading branch information
deanberris committed Aug 21, 2017
1 parent bd6dc14 commit c5caf3e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion llvm/include/llvm/XRay/InstrumentationMap.h
Expand Up @@ -38,7 +38,7 @@ Expected<InstrumentationMap> loadInstrumentationMap(StringRef Filename);
struct SledEntry {
/// Each entry here represents the kinds of supported instrumentation map
/// entries.
enum class FunctionKinds { ENTRY, EXIT, TAIL };
enum class FunctionKinds { ENTRY, EXIT, TAIL, LOG_ARGS_ENTER, CUSTOM_EVENT };

/// The address of the sled.
uint64_t Address;
Expand Down Expand Up @@ -106,6 +106,10 @@ template <> struct ScalarEnumerationTraits<xray::SledEntry::FunctionKinds> {
IO.enumCase(Kind, "function-enter", xray::SledEntry::FunctionKinds::ENTRY);
IO.enumCase(Kind, "function-exit", xray::SledEntry::FunctionKinds::EXIT);
IO.enumCase(Kind, "tail-exit", xray::SledEntry::FunctionKinds::TAIL);
IO.enumCase(Kind, "log-args-enter",
xray::SledEntry::FunctionKinds::LOG_ARGS_ENTER);
IO.enumCase(Kind, "custom-event",
xray::SledEntry::FunctionKinds::CUSTOM_EVENT);
}
};

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/XRay/InstrumentationMap.cpp
Expand Up @@ -104,7 +104,8 @@ loadELF64(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
static constexpr SledEntry::FunctionKinds Kinds[] = {
SledEntry::FunctionKinds::ENTRY, SledEntry::FunctionKinds::EXIT,
SledEntry::FunctionKinds::TAIL,
};
SledEntry::FunctionKinds::LOG_ARGS_ENTER,
SledEntry::FunctionKinds::CUSTOM_EVENT};
if (Kind >= sizeof(Kinds))
return errorCodeToError(
std::make_error_code(std::errc::executable_format_error));
Expand Down
Binary file added llvm/test/tools/llvm-xray/X86/Inputs/all-sleds.o
Binary file not shown.
11 changes: 11 additions & 0 deletions llvm/test/tools/llvm-xray/X86/extract-all-sledtypes.txt
@@ -0,0 +1,11 @@
# Test that we can extract all the sled types we know about. This is built with
# a a file with functions always instrumented, and using the built-ins and
# intrinsics supported by clang. Those are built with:
#
# clang++ -c all-sleds.cc -o all-sleds.o -fpic -std=c++11 -fxray-instrument
#
# RUN: llvm-xray extract %S/Inputs/all-sleds.o -s | FileCheck %s
# CHECK-DAG: {{kind:.function-enter}}
# CHECK-DAG: {{kind:.function-exit}}
# CHECK-DAG: {{kind:.custom-event}}
# CHECK-DAG: {{kind:.log-args-enter}}

0 comments on commit c5caf3e

Please sign in to comment.