aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 18:43:11 +0900
committerNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 18:43:11 +0900
commit0e1a753549b29ff1f5a190aca83b803a33b51628 (patch)
treee5578f8810c65711304128d0c8add7fa1f77b9d8 /llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp
parent3c6252260ee11e3a453076b4d96ffffe20d49998 (diff)
parentbdcf47e4bcb92889665825654bb80a8bbe30379e (diff)
downloadllvm-users/chapuni/cov/single/if.zip
llvm-users/chapuni/cov/single/if.tar.gz
llvm-users/chapuni/cov/single/if.tar.bz2
Merge branch 'users/chapuni/cov/single/base' into users/chapuni/cov/single/ifusers/chapuni/cov/single/if
Conflicts: clang/lib/CodeGen/CoverageMappingGen.cpp
Diffstat (limited to 'llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp')
-rw-r--r--llvm/lib/DebugInfo/GSYM/MergedFunctionsInfo.cpp53
1 files changed, 45 insertions, 8 deletions
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,