[llvm] r300624 - [XRay][tools] Add option to llvm-xray extract to symbolize functions
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 16:23:54 PDT 2017
Author: dberris
Date: Tue Apr 18 18:23:54 2017
New Revision: 300624
URL: http://llvm.org/viewvc/llvm-project?rev=300624&view=rev
Log:
[XRay][tools] Add option to llvm-xray extract to symbolize functions
Summary:
This allows us to, if the symbol names are available in the binary, be
able to provide the function name in the YAML output.
Reviewers: dblaikie, pelikan
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D32153
Added:
llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap-symbolize.ll
Modified:
llvm/trunk/include/llvm/XRay/InstrumentationMap.h
llvm/trunk/tools/llvm-xray/xray-extract.cc
Modified: llvm/trunk/include/llvm/XRay/InstrumentationMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/XRay/InstrumentationMap.h?rev=300624&r1=300623&r2=300624&view=diff
==============================================================================
--- llvm/trunk/include/llvm/XRay/InstrumentationMap.h (original)
+++ llvm/trunk/include/llvm/XRay/InstrumentationMap.h Tue Apr 18 18:23:54 2017
@@ -59,6 +59,7 @@ struct YAMLXRaySledEntry {
yaml::Hex64 Function;
SledEntry::FunctionKinds Kind;
bool AlwaysInstrument;
+ std::string FunctionName;
};
/// The InstrumentationMap represents the computed function id's and indicated
@@ -115,6 +116,7 @@ template <> struct MappingTraits<xray::Y
IO.mapRequired("function", Entry.Function);
IO.mapRequired("kind", Entry.Kind);
IO.mapRequired("always-instrument", Entry.AlwaysInstrument);
+ IO.mapOptional("function-name", Entry.FunctionName);
}
static constexpr bool flow = true;
Added: llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap-symbolize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap-symbolize.ll?rev=300624&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap-symbolize.ll (added)
+++ llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap-symbolize.ll Tue Apr 18 18:23:54 2017
@@ -0,0 +1,10 @@
+; This tests that we can extract the instrumentation map and symbolize the
+; function addresses.
+; RUN: llvm-xray extract %S/Inputs/elf64-example.bin -s | FileCheck %s
+
+; CHECK: ---
+; CHECK-NEXT: - { id: 1, address: 0x000000000041C900, function: 0x000000000041C900, kind: function-enter, always-instrument: true, function-name: {{.*foo.*}} }
+; CHECK-NEXT: - { id: 1, address: 0x000000000041C912, function: 0x000000000041C900, kind: function-exit, always-instrument: true, function-name: {{.*foo.*}} }
+; CHECK-NEXT: - { id: 2, address: 0x000000000041C930, function: 0x000000000041C930, kind: function-enter, always-instrument: true, function-name: {{.*bar.*}} }
+; CHECK-NEXT: - { id: 2, address: 0x000000000041C946, function: 0x000000000041C930, kind: function-exit, always-instrument: true, function-name: {{.*bar.*}} }
+; CHECK-NEXT: ...
Modified: llvm/trunk/tools/llvm-xray/xray-extract.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-extract.cc?rev=300624&r1=300623&r2=300624&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-extract.cc (original)
+++ llvm/trunk/tools/llvm-xray/xray-extract.cc Tue Apr 18 18:23:54 2017
@@ -16,6 +16,7 @@
#include <type_traits>
#include <utility>
+#include "func-id-helper.h"
#include "xray-registry.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ObjectFile.h"
@@ -45,10 +46,18 @@ static cl::opt<std::string>
static cl::alias ExtractOutput2("o", cl::aliasopt(ExtractOutput),
cl::desc("Alias for -output"),
cl::sub(Extract));
+static cl::opt<bool> ExtractSymbolize("symbolize", cl::value_desc("symbolize"),
+ cl::init(false),
+ cl::desc("symbolize functions"),
+ cl::sub(Extract));
+static cl::alias ExtractSymbolize2("s", cl::aliasopt(ExtractSymbolize),
+ cl::desc("alias for -symbolize"),
+ cl::sub(Extract));
namespace {
-void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS) {
+void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS,
+ FuncIdConversionHelper &FH) {
// First we translate the sleds into the YAMLXRaySledEntry objects in a deque.
std::vector<YAMLXRaySledEntry> YAMLSleds;
auto Sleds = Map.sleds();
@@ -58,7 +67,8 @@ void exportAsYAML(const InstrumentationM
if (!FuncId)
return;
YAMLSleds.push_back({*FuncId, Sled.Address, Sled.Function, Sled.Kind,
- Sled.AlwaysInstrument});
+ Sled.AlwaysInstrument,
+ ExtractSymbolize ? FH.SymbolOrNumber(*FuncId) : ""});
}
Output Out(OS, nullptr, 0);
Out << YAMLSleds;
@@ -80,6 +90,13 @@ static CommandRegistration Unused(&Extra
if (EC)
return make_error<StringError>(
Twine("Cannot open file '") + ExtractOutput + "' for writing.", EC);
- exportAsYAML(*InstrumentationMapOrError, OS);
+ const auto &FunctionAddresses =
+ InstrumentationMapOrError->getFunctionAddresses();
+ symbolize::LLVMSymbolizer::Options Opts(
+ symbolize::FunctionNameKind::LinkageName, true, true, false, "");
+ symbolize::LLVMSymbolizer Symbolizer(Opts);
+ llvm::xray::FuncIdConversionHelper FuncIdHelper(ExtractInput, Symbolizer,
+ FunctionAddresses);
+ exportAsYAML(*InstrumentationMapOrError, OS, FuncIdHelper);
return Error::success();
});
More information about the llvm-commits
mailing list