diff options
Diffstat (limited to 'llvm/lib/DebugInfo/GSYM')
-rw-r--r-- | llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/GSYM/GsymReader.cpp | 42 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp | 53 |
4 files changed, 96 insertions, 15 deletions
diff --git a/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp b/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp index 85b41e2..c112c0b 100644 --- a/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp +++ b/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp @@ -151,7 +151,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionYAML) Error CallSiteInfoLoader::loadYAML(StringRef YAMLFile) { // Step 1: Read YAML file - auto BufferOrError = MemoryBuffer::getFile(YAMLFile); + auto BufferOrError = MemoryBuffer::getFile(YAMLFile, /*IsText=*/true); if (!BufferOrError) return errorCodeToError(BufferOrError.getError()); diff --git a/llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp b/llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp index dd754c70..785a8da 100644 --- a/llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp +++ b/llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp @@ -235,10 +235,10 @@ llvm::Expected<uint64_t> FunctionInfo::encode(FileWriter &Out, return FuncInfoOffset; } -llvm::Expected<LookupResult> FunctionInfo::lookup(DataExtractor &Data, - const GsymReader &GR, - uint64_t FuncAddr, - uint64_t Addr) { +llvm::Expected<LookupResult> +FunctionInfo::lookup(DataExtractor &Data, const GsymReader &GR, + uint64_t FuncAddr, uint64_t Addr, + std::optional<DataExtractor> *MergedFuncsData) { LookupResult LR; LR.LookupAddr = Addr; uint64_t Offset = 0; @@ -289,6 +289,12 @@ llvm::Expected<LookupResult> FunctionInfo::lookup(DataExtractor &Data, return ExpectedLE.takeError(); break; + case InfoType::MergedFunctionsInfo: + // Store the merged functions data for later parsing, if needed. + if (MergedFuncsData) + *MergedFuncsData = InfoData; + break; + case InfoType::InlineInfo: // We will parse the inline info after our line table, but only if // we have a line entry. diff --git a/llvm/lib/DebugInfo/GSYM/GsymReader.cpp b/llvm/lib/DebugInfo/GSYM/GsymReader.cpp index fa5476d..0a5bb7c 100644 --- a/llvm/lib/DebugInfo/GSYM/GsymReader.cpp +++ b/llvm/lib/DebugInfo/GSYM/GsymReader.cpp @@ -334,14 +334,52 @@ GsymReader::getFunctionInfoAtIndex(uint64_t Idx) const { return ExpectedData.takeError(); } -llvm::Expected<LookupResult> GsymReader::lookup(uint64_t Addr) const { +llvm::Expected<LookupResult> +GsymReader::lookup(uint64_t Addr, + std::optional<DataExtractor> *MergedFunctionsData) const { uint64_t FuncStartAddr = 0; if (auto ExpectedData = getFunctionInfoDataForAddress(Addr, FuncStartAddr)) - return FunctionInfo::lookup(*ExpectedData, *this, FuncStartAddr, Addr); + return FunctionInfo::lookup(*ExpectedData, *this, FuncStartAddr, Addr, + MergedFunctionsData); else return ExpectedData.takeError(); } +llvm::Expected<std::vector<LookupResult>> +GsymReader::lookupAll(uint64_t Addr) const { + std::vector<LookupResult> Results; + std::optional<DataExtractor> MergedFunctionsData; + + // First perform a lookup to get the primary function info result. + auto MainResult = lookup(Addr, &MergedFunctionsData); + if (!MainResult) + return MainResult.takeError(); + + // Add the main result as the first entry. + Results.push_back(std::move(*MainResult)); + + // Now process any merged functions data that was found during the lookup. + if (MergedFunctionsData) { + // Get data extractors for each merged function. + auto ExpectedMergedFuncExtractors = + MergedFunctionsInfo::getFuncsDataExtractors(*MergedFunctionsData); + if (!ExpectedMergedFuncExtractors) + return ExpectedMergedFuncExtractors.takeError(); + + // Process each merged function data. + for (DataExtractor &MergedData : *ExpectedMergedFuncExtractors) { + if (auto FI = FunctionInfo::lookup(MergedData, *this, + MainResult->FuncRange.start(), Addr)) { + Results.push_back(std::move(*FI)); + } else { + return FI.takeError(); + } + } + } + + return Results; +} + void GsymReader::dump(raw_ostream &OS) { const auto &Header = getHeader(); // Dump the GSYM header. diff --git a/llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp b/llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp index 4efae22..d2c28f3 100644 --- a/llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp +++ b/llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp @@ -35,22 +35,59 @@ llvm::Error MergedFunctionsInfo::encode(FileWriter &Out) const { llvm::Expected<MergedFunctionsInfo> MergedFunctionsInfo::decode(DataExtractor &Data, uint64_t BaseAddr) { MergedFunctionsInfo MFI; + auto FuncExtractorsOrError = MFI.getFuncsDataExtractors(Data); + + if (!FuncExtractorsOrError) + return FuncExtractorsOrError.takeError(); + + for (DataExtractor &FuncData : *FuncExtractorsOrError) { + llvm::Expected<FunctionInfo> FI = FunctionInfo::decode(FuncData, BaseAddr); + if (!FI) + return FI.takeError(); + MFI.MergedFunctions.push_back(std::move(*FI)); + } + + return MFI; +} + +llvm::Expected<std::vector<DataExtractor>> +MergedFunctionsInfo::getFuncsDataExtractors(DataExtractor &Data) { + std::vector<DataExtractor> Results; uint64_t Offset = 0; + + // Ensure there is enough data to read the function count. + if (!Data.isValidOffsetForDataOfSize(Offset, 4)) + return createStringError( + std::errc::io_error, + "unable to read the function count at offset 0x%8.8" PRIx64, Offset); + uint32_t Count = Data.getU32(&Offset); for (uint32_t i = 0; i < Count; ++i) { + // Ensure there is enough data to read the function size. + if (!Data.isValidOffsetForDataOfSize(Offset, 4)) + return createStringError( + std::errc::io_error, + "unable to read size of function %u at offset 0x%8.8" PRIx64, i, + Offset); + uint32_t FnSize = Data.getU32(&Offset); - DataExtractor FnData(Data.getData().substr(Offset, FnSize), + + // Ensure there is enough data for the function content. + if (!Data.isValidOffsetForDataOfSize(Offset, FnSize)) + return createStringError( + std::errc::io_error, + "function data is truncated for function %u at offset 0x%8.8" PRIx64 + ", expected size %u", + i, Offset, FnSize); + + // Extract the function data. + Results.emplace_back(Data.getData().substr(Offset, FnSize), Data.isLittleEndian(), Data.getAddressSize()); - llvm::Expected<FunctionInfo> FI = - FunctionInfo::decode(FnData, BaseAddr + Offset); - if (!FI) - return FI.takeError(); - MFI.MergedFunctions.push_back(std::move(*FI)); + Offset += FnSize; } - - return MFI; + return Results; } bool operator==(const MergedFunctionsInfo &LHS, |