Skip to content

Commit f186fe3

Browse files
author
Alex B
committed
Address Feedback Nr.1
1 parent 02d9fb8 commit f186fe3

File tree

7 files changed

+67
-85
lines changed

7 files changed

+67
-85
lines changed

llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,17 @@ struct FunctionInfo {
187187
///
188188
/// \param Addr The address to lookup.
189189
///
190+
/// \param MergedFuncsData A pointer to an optional DataExtractor that, if
191+
/// non-null, will be set to the raw data of the MergedFunctionInfo, if
192+
/// present.
193+
///
190194
/// \returns An LookupResult or an error describing the issue that was
191195
/// encountered during decoding. An error should only be returned if the
192196
/// address is not contained in the FunctionInfo or if the data is corrupted.
193-
static llvm::Expected<LookupResult> lookup(DataExtractor &Data,
194-
const GsymReader &GR,
195-
uint64_t FuncAddr,
196-
uint64_t Addr);
197+
static llvm::Expected<LookupResult>
198+
lookup(DataExtractor &Data, const GsymReader &GR, uint64_t FuncAddr,
199+
uint64_t Addr,
200+
std::optional<DataExtractor> *MergedFuncsData = nullptr);
197201

198202
uint64_t startAddress() const { return Range.start(); }
199203
uint64_t endAddress() const { return Range.end(); }

llvm/include/llvm/DebugInfo/GSYM/GsymReader.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,17 @@ class GsymReader {
127127
/// is much faster for lookups.
128128
///
129129
/// \param Addr A virtual address from the orignal object file to lookup.
130+
///
131+
/// \param MergedFuncsData A pointer to an optional DataExtractor that, if
132+
/// non-null, will be set to the raw data of the MergedFunctionInfo, if
133+
/// present.
134+
///
130135
/// \returns An expected LookupResult that contains only the information
131136
/// needed for the current address, or an error object that indicates reason
132137
/// for failing to lookup the address.
133-
llvm::Expected<LookupResult> lookup(uint64_t Addr) const;
138+
llvm::Expected<LookupResult>
139+
lookup(uint64_t Addr,
140+
std::optional<DataExtractor> *MergedFuncsData = nullptr) const;
134141

135142
/// Lookup all merged functions for a given address.
136143
///
@@ -139,6 +146,7 @@ class GsymReader {
139146
/// with the primary LookupResult.
140147
///
141148
/// \param Addr The address to lookup.
149+
///
142150
/// \returns A vector of LookupResult objects, where the first element is the
143151
/// primary result, followed by results for any merged functions
144152
llvm::Expected<std::vector<LookupResult>> lookupAll(uint64_t Addr) const;

llvm/include/llvm/DebugInfo/GSYM/LookupResult.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "llvm/ADT/AddressRanges.h"
1313
#include "llvm/ADT/StringRef.h"
14-
#include "llvm/Support/DataExtractor.h"
1514
#include <inttypes.h>
1615
#include <vector>
1716

@@ -51,17 +50,6 @@ struct LookupResult {
5150
/// array, and the concrete function will appear at the end of the array.
5251
SourceLocations Locations;
5352
std::string getSourceFile(uint32_t Index) const;
54-
55-
/// Optional DataExtractor containing the merged functions data.
56-
/// This is only populated during lookups if merged function information
57-
/// was present. This is an optimization to avoid parsing the
58-
/// MergedFunctionsInfo data unless needed.
59-
std::optional<DataExtractor> MergedFunctionsData;
60-
61-
/// The binary data used to decode the FunctionInfo from which this
62-
/// LookupResult was created. This can be used to re-decode the entire
63-
/// FunctionInfo if desired.
64-
std::optional<DataExtractor> FunctionInfoData;
6553
};
6654

6755
inline bool operator==(const LookupResult &LHS, const LookupResult &RHS) {

llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,12 @@ llvm::Expected<uint64_t> FunctionInfo::encode(FileWriter &Out,
235235
return FuncInfoOffset;
236236
}
237237

238-
llvm::Expected<LookupResult> FunctionInfo::lookup(DataExtractor &Data,
239-
const GsymReader &GR,
240-
uint64_t FuncAddr,
241-
uint64_t Addr) {
238+
llvm::Expected<LookupResult>
239+
FunctionInfo::lookup(DataExtractor &Data, const GsymReader &GR,
240+
uint64_t FuncAddr, uint64_t Addr,
241+
std::optional<DataExtractor> *MergedFuncsData) {
242242
LookupResult LR;
243243
LR.LookupAddr = Addr;
244-
LR.FunctionInfoData = Data;
245244
uint64_t Offset = 0;
246245
LR.FuncRange = {FuncAddr, FuncAddr + Data.getU32(&Offset)};
247246
uint32_t NameOffset = Data.getU32(&Offset);
@@ -292,7 +291,8 @@ llvm::Expected<LookupResult> FunctionInfo::lookup(DataExtractor &Data,
292291

293292
case InfoType::MergedFunctionsInfo:
294293
// Store the merged functions data for later parsing, if needed.
295-
LR.MergedFunctionsData = InfoData;
294+
if (MergedFuncsData)
295+
*MergedFuncsData = InfoData;
296296
break;
297297

298298
case InfoType::InlineInfo:

llvm/lib/DebugInfo/GSYM/GsymReader.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,36 +334,39 @@ GsymReader::getFunctionInfoAtIndex(uint64_t Idx) const {
334334
return ExpectedData.takeError();
335335
}
336336

337-
llvm::Expected<LookupResult> GsymReader::lookup(uint64_t Addr) const {
337+
llvm::Expected<LookupResult>
338+
GsymReader::lookup(uint64_t Addr,
339+
std::optional<DataExtractor> *MergedFunctionsData) const {
338340
uint64_t FuncStartAddr = 0;
339341
if (auto ExpectedData = getFunctionInfoDataForAddress(Addr, FuncStartAddr))
340-
return FunctionInfo::lookup(*ExpectedData, *this, FuncStartAddr, Addr);
342+
return FunctionInfo::lookup(*ExpectedData, *this, FuncStartAddr, Addr,
343+
MergedFunctionsData);
341344
else
342345
return ExpectedData.takeError();
343346
}
344347

345348
llvm::Expected<std::vector<LookupResult>>
346349
GsymReader::lookupAll(uint64_t Addr) const {
347350
std::vector<LookupResult> Results;
351+
std::optional<DataExtractor> MergedFunctionsData;
348352

349-
// First perform a lookup to get the primary function info result
350-
auto MainResult = lookup(Addr);
353+
// First perform a lookup to get the primary function info result.
354+
auto MainResult = lookup(Addr, &MergedFunctionsData);
351355
if (!MainResult)
352356
return MainResult.takeError();
353357

354-
// Add the main result as the first entry
358+
// Add the main result as the first entry.
355359
Results.push_back(std::move(*MainResult));
356360

357-
// Now process any merged functions data that was found during the lookup
358-
if (MainResult->MergedFunctionsData) {
359-
// Get data extractors for each merged function
361+
// Now process any merged functions data that was found during the lookup.
362+
if (MergedFunctionsData) {
363+
// Get data extractors for each merged function.
360364
auto ExpectedMergedFuncExtractors =
361-
MergedFunctionsInfo::getFuncsDataExtractors(
362-
*MainResult->MergedFunctionsData);
365+
MergedFunctionsInfo::getFuncsDataExtractors(*MergedFunctionsData);
363366
if (!ExpectedMergedFuncExtractors)
364367
return ExpectedMergedFuncExtractors.takeError();
365368

366-
// Process each merged function data
369+
// Process each merged function data.
367370
for (DataExtractor &MergedData : *ExpectedMergedFuncExtractors) {
368371
if (auto FI = FunctionInfo::lookup(MergedData, *this,
369372
MainResult->FuncRange.start(), Addr)) {

llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-merged-funcs-dwarf.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
# RUN: llvm-gsymutil --verify %t.keep.gSYM --address 0x248 | FileCheck --check-prefix=CHECK-NORMAL-LOOKUP %s
7070

7171
# CHECK-MERGED-LOOKUP: Found 3 functions at address 0x0000000000000248:
72-
# CHECK-MERGED-LOOKUP: 0x0000000000000248: my_func_01 @ /tmp/test_gsym_yaml/out/file_01.cpp:5
73-
# CHECK-MERGED-LOOKUP: 0x0000000000000248: my_func_02 @ /tmp/test_gsym_yaml/out/file_02.cpp:5
74-
# CHECK-MERGED-LOOKUP: 0x0000000000000248: my_func_03 @ /tmp/test_gsym_yaml/out/file_03.cpp:5
72+
# CHECK-MERGED-LOOKUP-NEXT: 0x0000000000000248: my_func_02 @ /tmp/test_gsym_yaml/out/file_02.cpp:5
73+
# CHECK-MERGED-LOOKUP-NEXT-NEXT: 0x0000000000000248: my_func_01 @ /tmp/test_gsym_yaml/out/file_01.cpp:5
74+
# CHECK-MERGED-LOOKUP-NEXT-NEXT: 0x0000000000000248: my_func_03 @ /tmp/test_gsym_yaml/out/file_03.cpp:5
7575

7676
# CHECK-NORMAL-LOOKUP: 0x0000000000000248: my_func_01 @ /tmp/test_gsym_yaml/out/file_01.cpp:5
7777

llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -507,61 +507,40 @@ static llvm::Error convertFileToGSYM(OutputAggregator &Out) {
507507
return Error::success();
508508
}
509509

510-
static void doLookupMergedFunctions(GsymReader &Gsym, uint64_t Addr,
511-
raw_ostream &OS) {
512-
if (auto Results = Gsym.lookupAll(Addr)) {
513-
OS << "Found " << Results->size() << " functions at address " << HEX64(Addr)
514-
<< ":\n";
515-
for (size_t i = 0; i < Results->size(); ++i) {
516-
if (Verbose) {
517-
if (auto FI = FunctionInfo::decode(*Results->at(i).FunctionInfoData,
518-
Results->at(i).FuncRange.start())) {
519-
OS << "FunctionInfo for " << HEX64(Addr) << ":\n";
520-
Gsym.dump(OS, *FI);
521-
OS << "\nLookupResults for " << HEX64(Addr) << ":\n";
522-
}
523-
}
524-
525-
// Print the primary function lookup result
526-
OS << " " << Results->at(i);
527-
528-
if (i != Results->size() - 1)
529-
OS << "\n";
530-
}
531-
} else {
532-
if (Verbose)
533-
OS << "\nLookupResult for " << HEX64(Addr) << ":\n";
510+
static void doLookup(GsymReader &Gsym, uint64_t Addr, raw_ostream &OS) {
511+
auto logError = [Addr, &OS](Error E) {
534512
OS << HEX64(Addr) << ": ";
535-
logAllUnhandledErrors(Results.takeError(), OS, "error: ");
536-
}
537-
if (Verbose)
538-
OS << "\n";
539-
}
513+
logAllUnhandledErrors(std::move(E), OS, "error: ");
514+
};
540515

541-
static void doLookup(GsymReader &Gsym, uint64_t Addr, raw_ostream &OS) {
542516
if (UseMergedFunctions) {
543-
doLookupMergedFunctions(Gsym, Addr, OS);
544-
return;
545-
}
546-
547-
if (auto Result = Gsym.lookup(Addr)) {
548-
// If verbose is enabled, dump the full function info for the address.
549-
if (Verbose) {
550-
if (auto FI = Gsym.getFunctionInfo(Addr)) {
551-
OS << "FunctionInfo for " << HEX64(Addr) << ":\n";
552-
Gsym.dump(OS, *FI);
553-
OS << "\nLookupResult for " << HEX64(Addr) << ":\n";
517+
if (auto Results = Gsym.lookupAll(Addr)) {
518+
OS << "Found " << Results->size() << " functions at address "
519+
<< HEX64(Addr) << ":\n";
520+
for (size_t i = 0; i < Results->size(); ++i) {
521+
OS << " " << Results->at(i);
522+
523+
if (i != Results->size() - 1)
524+
OS << "\n";
554525
}
555526
}
556-
OS << Result.get();
557-
} else {
558-
if (Verbose)
559-
OS << "\nLookupResult for " << HEX64(Addr) << ":\n";
560-
OS << HEX64(Addr) << ": ";
561-
logAllUnhandledErrors(Result.takeError(), OS, "error: ");
527+
} else { /* UseMergedFunctions == false */
528+
if (auto Result = Gsym.lookup(Addr)) {
529+
OS << Result.get();
530+
} else {
531+
logError(Result.takeError());
532+
return;
533+
}
562534
}
563-
if (Verbose)
535+
536+
if (Verbose) {
537+
if (auto FI = Gsym.getFunctionInfo(Addr)) {
538+
OS << "FunctionInfo for " << HEX64(Addr) << ":\n";
539+
Gsym.dump(OS, *FI);
540+
OS << "\nLookupResult for " << HEX64(Addr) << ":\n";
541+
}
564542
OS << "\n";
543+
}
565544
}
566545

567546
int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {

0 commit comments

Comments
 (0)