llvm.org GIT mirror llvm / 44292db
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300624 91177308-0d34-0410-b5e6-96231b3b80d8 Dean Michael Berris 2 years ago
3 changed file(s) with 32 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
5858 yaml::Hex64 Function;
5959 SledEntry::FunctionKinds Kind;
6060 bool AlwaysInstrument;
61 std::string FunctionName;
6162 };
6263
6364 /// The InstrumentationMap represents the computed function id's and indicated
114115 IO.mapRequired("function", Entry.Function);
115116 IO.mapRequired("kind", Entry.Kind);
116117 IO.mapRequired("always-instrument", Entry.AlwaysInstrument);
118 IO.mapOptional("function-name", Entry.FunctionName);
117119 }
118120
119121 static constexpr bool flow = true;
0 ; This tests that we can extract the instrumentation map and symbolize the
1 ; function addresses.
2 ; RUN: llvm-xray extract %S/Inputs/elf64-example.bin -s | FileCheck %s
3
4 ; CHECK: ---
5 ; CHECK-NEXT: - { id: 1, address: 0x000000000041C900, function: 0x000000000041C900, kind: function-enter, always-instrument: true, function-name: {{.*foo.*}} }
6 ; CHECK-NEXT: - { id: 1, address: 0x000000000041C912, function: 0x000000000041C900, kind: function-exit, always-instrument: true, function-name: {{.*foo.*}} }
7 ; CHECK-NEXT: - { id: 2, address: 0x000000000041C930, function: 0x000000000041C930, kind: function-enter, always-instrument: true, function-name: {{.*bar.*}} }
8 ; CHECK-NEXT: - { id: 2, address: 0x000000000041C946, function: 0x000000000041C930, kind: function-exit, always-instrument: true, function-name: {{.*bar.*}} }
9 ; CHECK-NEXT: ...
1515 #include
1616 #include
1717
18 #include "func-id-helper.h"
1819 #include "xray-registry.h"
1920 #include "llvm/Object/ELF.h"
2021 #include "llvm/Object/ObjectFile.h"
4445 static cl::alias ExtractOutput2("o", cl::aliasopt(ExtractOutput),
4546 cl::desc("Alias for -output"),
4647 cl::sub(Extract));
48 static cl::opt ExtractSymbolize("symbolize", cl::value_desc("symbolize"),
49 cl::init(false),
50 cl::desc("symbolize functions"),
51 cl::sub(Extract));
52 static cl::alias ExtractSymbolize2("s", cl::aliasopt(ExtractSymbolize),
53 cl::desc("alias for -symbolize"),
54 cl::sub(Extract));
4755
4856 namespace {
4957
50 void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS) {
58 void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS,
59 FuncIdConversionHelper &FH) {
5160 // First we translate the sleds into the YAMLXRaySledEntry objects in a deque.
5261 std::vector YAMLSleds;
5362 auto Sleds = Map.sleds();
5766 if (!FuncId)
5867 return;
5968 YAMLSleds.push_back({*FuncId, Sled.Address, Sled.Function, Sled.Kind,
60 Sled.AlwaysInstrument});
69 Sled.AlwaysInstrument,
70 ExtractSymbolize ? FH.SymbolOrNumber(*FuncId) : ""});
6171 }
6272 Output Out(OS, nullptr, 0);
6373 Out << YAMLSleds;
7989 if (EC)
8090 return make_error(
8191 Twine("Cannot open file '") + ExtractOutput + "' for writing.", EC);
82 exportAsYAML(*InstrumentationMapOrError, OS);
92 const auto &FunctionAddresses =
93 InstrumentationMapOrError->getFunctionAddresses();
94 symbolize::LLVMSymbolizer::Options Opts(
95 symbolize::FunctionNameKind::LinkageName, true, true, false, "");
96 symbolize::LLVMSymbolizer Symbolizer(Opts);
97 llvm::xray::FuncIdConversionHelper FuncIdHelper(ExtractInput, Symbolizer,
98 FunctionAddresses);
99 exportAsYAML(*InstrumentationMapOrError, OS, FuncIdHelper);
83100 return Error::success();
84101 });