2019-06-26 14:09:09 +00:00
|
|
|
//===- InlineInfo.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
Add lookup functions for efficient lookups of addresses when using GsymReader classes.
Summary:
Lookup functions are designed to not fully decode a FunctionInfo, LineTable or InlineInfo, they decode only what is needed into a LookupResult object. This allows lookups to avoid costly memory allocations and avoid parsing large amounts of information one a suitable match is found.
LookupResult objects contain the address that was looked up, the concrete function address range, the name of the concrete function, and a list of source locations. One for each inline function, and one for the concrete function. This allows one address to turn into multiple frames and improves the signal you get when symbolicating addresses in GSYM files.
Reviewers: labath, aprantl
Subscribers: mgorny, hiraditya, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70993
2019-12-03 16:44:02 -08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-06-26 14:09:09 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/GSYM/FileEntry.h"
|
2019-09-04 17:32:51 +00:00
|
|
|
#include "llvm/DebugInfo/GSYM/FileWriter.h"
|
Add lookup functions for efficient lookups of addresses when using GsymReader classes.
Summary:
Lookup functions are designed to not fully decode a FunctionInfo, LineTable or InlineInfo, they decode only what is needed into a LookupResult object. This allows lookups to avoid costly memory allocations and avoid parsing large amounts of information one a suitable match is found.
LookupResult objects contain the address that was looked up, the concrete function address range, the name of the concrete function, and a list of source locations. One for each inline function, and one for the concrete function. This allows one address to turn into multiple frames and improves the signal you get when symbolicating addresses in GSYM files.
Reviewers: labath, aprantl
Subscribers: mgorny, hiraditya, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70993
2019-12-03 16:44:02 -08:00
|
|
|
#include "llvm/DebugInfo/GSYM/GsymReader.h"
|
2019-06-26 14:09:09 +00:00
|
|
|
#include "llvm/DebugInfo/GSYM/InlineInfo.h"
|
2019-09-04 17:32:51 +00:00
|
|
|
#include "llvm/Support/DataExtractor.h"
|
2019-06-26 14:09:09 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace gsym;
|
|
|
|
|
|
|
|
|
|
|
|
raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const InlineInfo &II) {
|
|
|
|
if (!II.isValid())
|
|
|
|
return OS;
|
|
|
|
bool First = true;
|
|
|
|
for (auto Range : II.Ranges) {
|
|
|
|
if (First)
|
|
|
|
First = false;
|
|
|
|
else
|
|
|
|
OS << ' ';
|
|
|
|
OS << Range;
|
|
|
|
}
|
|
|
|
OS << " Name = " << HEX32(II.Name) << ", CallFile = " << II.CallFile
|
|
|
|
<< ", CallLine = " << II.CallFile << '\n';
|
|
|
|
for (const auto &Child : II.Children)
|
|
|
|
OS << Child;
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2019-06-28 10:06:11 +00:00
|
|
|
static bool getInlineStackHelper(const InlineInfo &II, uint64_t Addr,
|
2019-06-26 14:09:09 +00:00
|
|
|
std::vector<const InlineInfo *> &InlineStack) {
|
|
|
|
if (II.Ranges.contains(Addr)) {
|
|
|
|
// If this is the top level that represents the concrete function,
|
|
|
|
// there will be no name and we shoud clear the inline stack. Otherwise
|
|
|
|
// we have found an inline call stack that we need to insert.
|
|
|
|
if (II.Name != 0)
|
|
|
|
InlineStack.insert(InlineStack.begin(), &II);
|
|
|
|
for (const auto &Child : II.Children) {
|
|
|
|
if (::getInlineStackHelper(Child, Addr, InlineStack))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return !InlineStack.empty();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-05 00:09:22 +00:00
|
|
|
std::optional<InlineInfo::InlineArray>
|
|
|
|
InlineInfo::getInlineStack(uint64_t Addr) const {
|
2019-06-26 14:09:09 +00:00
|
|
|
InlineArray Result;
|
|
|
|
if (getInlineStackHelper(*this, Addr, Result))
|
|
|
|
return Result;
|
2022-12-02 21:11:39 -08:00
|
|
|
return std::nullopt;
|
2019-06-26 14:09:09 +00:00
|
|
|
}
|
2019-09-04 17:32:51 +00:00
|
|
|
|
Add lookup functions for efficient lookups of addresses when using GsymReader classes.
Summary:
Lookup functions are designed to not fully decode a FunctionInfo, LineTable or InlineInfo, they decode only what is needed into a LookupResult object. This allows lookups to avoid costly memory allocations and avoid parsing large amounts of information one a suitable match is found.
LookupResult objects contain the address that was looked up, the concrete function address range, the name of the concrete function, and a list of source locations. One for each inline function, and one for the concrete function. This allows one address to turn into multiple frames and improves the signal you get when symbolicating addresses in GSYM files.
Reviewers: labath, aprantl
Subscribers: mgorny, hiraditya, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70993
2019-12-03 16:44:02 -08:00
|
|
|
/// Skip an InlineInfo object in the specified data at the specified offset.
|
|
|
|
///
|
|
|
|
/// Used during the InlineInfo::lookup() call to quickly skip child InlineInfo
|
|
|
|
/// objects where the addres ranges isn't contained in the InlineInfo object
|
|
|
|
/// or its children. This avoids allocations by not appending child InlineInfo
|
|
|
|
/// objects to the InlineInfo::Children array.
|
|
|
|
///
|
|
|
|
/// \param Data The binary stream to read the data from.
|
|
|
|
///
|
|
|
|
/// \param Offset The byte offset within \a Data.
|
|
|
|
///
|
|
|
|
/// \param SkippedRanges If true, address ranges have already been skipped.
|
|
|
|
|
|
|
|
static bool skip(DataExtractor &Data, uint64_t &Offset, bool SkippedRanges) {
|
|
|
|
if (!SkippedRanges) {
|
2022-04-22 12:58:13 +03:00
|
|
|
if (skipRanges(Data, Offset) == 0)
|
Add lookup functions for efficient lookups of addresses when using GsymReader classes.
Summary:
Lookup functions are designed to not fully decode a FunctionInfo, LineTable or InlineInfo, they decode only what is needed into a LookupResult object. This allows lookups to avoid costly memory allocations and avoid parsing large amounts of information one a suitable match is found.
LookupResult objects contain the address that was looked up, the concrete function address range, the name of the concrete function, and a list of source locations. One for each inline function, and one for the concrete function. This allows one address to turn into multiple frames and improves the signal you get when symbolicating addresses in GSYM files.
Reviewers: labath, aprantl
Subscribers: mgorny, hiraditya, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70993
2019-12-03 16:44:02 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool HasChildren = Data.getU8(&Offset) != 0;
|
|
|
|
Data.getU32(&Offset); // Skip Inline.Name.
|
|
|
|
Data.getULEB128(&Offset); // Skip Inline.CallFile.
|
|
|
|
Data.getULEB128(&Offset); // Skip Inline.CallLine.
|
|
|
|
if (HasChildren) {
|
|
|
|
while (skip(Data, Offset, false /* SkippedRanges */))
|
|
|
|
/* Do nothing */;
|
|
|
|
}
|
|
|
|
// We skipped a valid InlineInfo.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A Lookup helper functions.
|
|
|
|
///
|
|
|
|
/// Used during the InlineInfo::lookup() call to quickly only parse an
|
|
|
|
/// InlineInfo object if the address falls within this object. This avoids
|
|
|
|
/// allocations by not appending child InlineInfo objects to the
|
|
|
|
/// InlineInfo::Children array and also skips any InlineInfo objects that do
|
|
|
|
/// not contain the address we are looking up.
|
|
|
|
///
|
|
|
|
/// \param Data The binary stream to read the data from.
|
|
|
|
///
|
|
|
|
/// \param Offset The byte offset within \a Data.
|
|
|
|
///
|
|
|
|
/// \param BaseAddr The address that the relative address range offsets are
|
|
|
|
/// relative to.
|
|
|
|
|
|
|
|
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset,
|
|
|
|
uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs,
|
|
|
|
llvm::Error &Err) {
|
|
|
|
InlineInfo Inline;
|
2022-04-22 12:58:13 +03:00
|
|
|
decodeRanges(Inline.Ranges, Data, BaseAddr, Offset);
|
Add lookup functions for efficient lookups of addresses when using GsymReader classes.
Summary:
Lookup functions are designed to not fully decode a FunctionInfo, LineTable or InlineInfo, they decode only what is needed into a LookupResult object. This allows lookups to avoid costly memory allocations and avoid parsing large amounts of information one a suitable match is found.
LookupResult objects contain the address that was looked up, the concrete function address range, the name of the concrete function, and a list of source locations. One for each inline function, and one for the concrete function. This allows one address to turn into multiple frames and improves the signal you get when symbolicating addresses in GSYM files.
Reviewers: labath, aprantl
Subscribers: mgorny, hiraditya, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70993
2019-12-03 16:44:02 -08:00
|
|
|
if (Inline.Ranges.empty())
|
|
|
|
return true;
|
|
|
|
// Check if the address is contained within the inline information, and if
|
|
|
|
// not, quickly skip this InlineInfo object and all its children.
|
|
|
|
if (!Inline.Ranges.contains(Addr)) {
|
|
|
|
skip(Data, Offset, true /* SkippedRanges */);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The address range is contained within this InlineInfo, add the source
|
|
|
|
// location for this InlineInfo and any children that contain the address.
|
|
|
|
bool HasChildren = Data.getU8(&Offset) != 0;
|
|
|
|
Inline.Name = Data.getU32(&Offset);
|
|
|
|
Inline.CallFile = (uint32_t)Data.getULEB128(&Offset);
|
|
|
|
Inline.CallLine = (uint32_t)Data.getULEB128(&Offset);
|
|
|
|
if (HasChildren) {
|
|
|
|
// Child address ranges are encoded relative to the first address in the
|
|
|
|
// parent InlineInfo object.
|
2022-04-22 12:58:13 +03:00
|
|
|
const auto ChildBaseAddr = Inline.Ranges[0].start();
|
Add lookup functions for efficient lookups of addresses when using GsymReader classes.
Summary:
Lookup functions are designed to not fully decode a FunctionInfo, LineTable or InlineInfo, they decode only what is needed into a LookupResult object. This allows lookups to avoid costly memory allocations and avoid parsing large amounts of information one a suitable match is found.
LookupResult objects contain the address that was looked up, the concrete function address range, the name of the concrete function, and a list of source locations. One for each inline function, and one for the concrete function. This allows one address to turn into multiple frames and improves the signal you get when symbolicating addresses in GSYM files.
Reviewers: labath, aprantl
Subscribers: mgorny, hiraditya, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70993
2019-12-03 16:44:02 -08:00
|
|
|
bool Done = false;
|
|
|
|
while (!Done)
|
|
|
|
Done = lookup(GR, Data, Offset, ChildBaseAddr, Addr, SrcLocs, Err);
|
|
|
|
}
|
|
|
|
|
2022-12-05 00:09:22 +00:00
|
|
|
std::optional<FileEntry> CallFile = GR.getFile(Inline.CallFile);
|
Add lookup functions for efficient lookups of addresses when using GsymReader classes.
Summary:
Lookup functions are designed to not fully decode a FunctionInfo, LineTable or InlineInfo, they decode only what is needed into a LookupResult object. This allows lookups to avoid costly memory allocations and avoid parsing large amounts of information one a suitable match is found.
LookupResult objects contain the address that was looked up, the concrete function address range, the name of the concrete function, and a list of source locations. One for each inline function, and one for the concrete function. This allows one address to turn into multiple frames and improves the signal you get when symbolicating addresses in GSYM files.
Reviewers: labath, aprantl
Subscribers: mgorny, hiraditya, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70993
2019-12-03 16:44:02 -08:00
|
|
|
if (!CallFile) {
|
|
|
|
Err = createStringError(std::errc::invalid_argument,
|
|
|
|
"failed to extract file[%" PRIu32 "]",
|
|
|
|
Inline.CallFile);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Add a DWARF transformer class that converts DWARF to GSYM.
Summary:
The DWARF transformer is added as a class so it can be unit tested fully.
The DWARF is converted to GSYM format and handles many special cases for functions:
- omit functions in compile units with 4 byte addresses whose address is UINT32_MAX (dead stripped)
- omit functions in compile units with 8 byte addresses whose address is UINT64_MAX (dead stripped)
- omit any functions whose high PC is <= low PC (dead stripped)
- StringTable builder doesn't copy strings, so we need to make backing copies of strings but only when needed. Many strings come from sections in object files and won't need to have backing copies, but some do.
- When a function doesn't have a mangled name, store the fully qualified name by creating a string by traversing the parent decl context DIEs and then. If we don't do this, we end up having cases where some function might appear in the GSYM as "erase" instead of "std::vector<int>::erase".
- omit any functions whose address isn't in the optional TextRanges member variable of DwarfTransformer. This allows object file to register address ranges that are known valid code ranges and can help omit functions that should have been dead stripped, but just had their low PC values set to zero. In this case we have many functions that all appear at address zero and can omit these functions by making sure they fall into good address ranges on the object file. Many compilers do this when the DWARF has a DW_AT_low_pc with a DW_FORM_addr, and a DW_AT_high_pc with a DW_FORM_data4 as the offset from the low PC. In this case the linker can't write the same address to both the high and low PC since there is only a relocation for the DW_AT_low_pc, so many linkers tend to just zero it out.
Reviewers: aprantl, dblaikie, probinson
Subscribers: mgorny, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74450
2020-02-11 16:05:59 -08:00
|
|
|
if (CallFile->Dir || CallFile->Base) {
|
|
|
|
SourceLocation SrcLoc;
|
|
|
|
SrcLoc.Name = SrcLocs.back().Name;
|
2020-02-15 21:28:36 -08:00
|
|
|
SrcLoc.Offset = SrcLocs.back().Offset;
|
Add a DWARF transformer class that converts DWARF to GSYM.
Summary:
The DWARF transformer is added as a class so it can be unit tested fully.
The DWARF is converted to GSYM format and handles many special cases for functions:
- omit functions in compile units with 4 byte addresses whose address is UINT32_MAX (dead stripped)
- omit functions in compile units with 8 byte addresses whose address is UINT64_MAX (dead stripped)
- omit any functions whose high PC is <= low PC (dead stripped)
- StringTable builder doesn't copy strings, so we need to make backing copies of strings but only when needed. Many strings come from sections in object files and won't need to have backing copies, but some do.
- When a function doesn't have a mangled name, store the fully qualified name by creating a string by traversing the parent decl context DIEs and then. If we don't do this, we end up having cases where some function might appear in the GSYM as "erase" instead of "std::vector<int>::erase".
- omit any functions whose address isn't in the optional TextRanges member variable of DwarfTransformer. This allows object file to register address ranges that are known valid code ranges and can help omit functions that should have been dead stripped, but just had their low PC values set to zero. In this case we have many functions that all appear at address zero and can omit these functions by making sure they fall into good address ranges on the object file. Many compilers do this when the DWARF has a DW_AT_low_pc with a DW_FORM_addr, and a DW_AT_high_pc with a DW_FORM_data4 as the offset from the low PC. In this case the linker can't write the same address to both the high and low PC since there is only a relocation for the DW_AT_low_pc, so many linkers tend to just zero it out.
Reviewers: aprantl, dblaikie, probinson
Subscribers: mgorny, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74450
2020-02-11 16:05:59 -08:00
|
|
|
SrcLoc.Dir = GR.getString(CallFile->Dir);
|
|
|
|
SrcLoc.Base = GR.getString(CallFile->Base);
|
|
|
|
SrcLoc.Line = Inline.CallLine;
|
|
|
|
SrcLocs.back().Name = GR.getString(Inline.Name);
|
2022-04-22 12:58:13 +03:00
|
|
|
SrcLocs.back().Offset = Addr - Inline.Ranges[0].start();
|
Add a DWARF transformer class that converts DWARF to GSYM.
Summary:
The DWARF transformer is added as a class so it can be unit tested fully.
The DWARF is converted to GSYM format and handles many special cases for functions:
- omit functions in compile units with 4 byte addresses whose address is UINT32_MAX (dead stripped)
- omit functions in compile units with 8 byte addresses whose address is UINT64_MAX (dead stripped)
- omit any functions whose high PC is <= low PC (dead stripped)
- StringTable builder doesn't copy strings, so we need to make backing copies of strings but only when needed. Many strings come from sections in object files and won't need to have backing copies, but some do.
- When a function doesn't have a mangled name, store the fully qualified name by creating a string by traversing the parent decl context DIEs and then. If we don't do this, we end up having cases where some function might appear in the GSYM as "erase" instead of "std::vector<int>::erase".
- omit any functions whose address isn't in the optional TextRanges member variable of DwarfTransformer. This allows object file to register address ranges that are known valid code ranges and can help omit functions that should have been dead stripped, but just had their low PC values set to zero. In this case we have many functions that all appear at address zero and can omit these functions by making sure they fall into good address ranges on the object file. Many compilers do this when the DWARF has a DW_AT_low_pc with a DW_FORM_addr, and a DW_AT_high_pc with a DW_FORM_data4 as the offset from the low PC. In this case the linker can't write the same address to both the high and low PC since there is only a relocation for the DW_AT_low_pc, so many linkers tend to just zero it out.
Reviewers: aprantl, dblaikie, probinson
Subscribers: mgorny, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74450
2020-02-11 16:05:59 -08:00
|
|
|
SrcLocs.push_back(SrcLoc);
|
|
|
|
}
|
Add lookup functions for efficient lookups of addresses when using GsymReader classes.
Summary:
Lookup functions are designed to not fully decode a FunctionInfo, LineTable or InlineInfo, they decode only what is needed into a LookupResult object. This allows lookups to avoid costly memory allocations and avoid parsing large amounts of information one a suitable match is found.
LookupResult objects contain the address that was looked up, the concrete function address range, the name of the concrete function, and a list of source locations. One for each inline function, and one for the concrete function. This allows one address to turn into multiple frames and improves the signal you get when symbolicating addresses in GSYM files.
Reviewers: labath, aprantl
Subscribers: mgorny, hiraditya, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70993
2019-12-03 16:44:02 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Error InlineInfo::lookup(const GsymReader &GR, DataExtractor &Data,
|
|
|
|
uint64_t BaseAddr, uint64_t Addr,
|
|
|
|
SourceLocations &SrcLocs) {
|
|
|
|
// Call our recursive helper function starting at offset zero.
|
|
|
|
uint64_t Offset = 0;
|
|
|
|
llvm::Error Err = Error::success();
|
|
|
|
::lookup(GR, Data, Offset, BaseAddr, Addr, SrcLocs, Err);
|
|
|
|
return Err;
|
|
|
|
}
|
|
|
|
|
2019-09-04 17:32:51 +00:00
|
|
|
/// Decode an InlineInfo in Data at the specified offset.
|
|
|
|
///
|
|
|
|
/// A local helper function to decode InlineInfo objects. This function is
|
|
|
|
/// called recursively when parsing child InlineInfo objects.
|
|
|
|
///
|
|
|
|
/// \param Data The data extractor to decode from.
|
|
|
|
/// \param Offset The offset within \a Data to decode from.
|
|
|
|
/// \param BaseAddr The base address to use when decoding address ranges.
|
|
|
|
/// \returns An InlineInfo or an error describing the issue that was
|
|
|
|
/// encountered during decoding.
|
|
|
|
static llvm::Expected<InlineInfo> decode(DataExtractor &Data, uint64_t &Offset,
|
|
|
|
uint64_t BaseAddr) {
|
|
|
|
InlineInfo Inline;
|
|
|
|
if (!Data.isValidOffset(Offset))
|
|
|
|
return createStringError(std::errc::io_error,
|
|
|
|
"0x%8.8" PRIx64 ": missing InlineInfo address ranges data", Offset);
|
2022-04-22 12:58:13 +03:00
|
|
|
decodeRanges(Inline.Ranges, Data, BaseAddr, Offset);
|
2019-09-04 17:32:51 +00:00
|
|
|
if (Inline.Ranges.empty())
|
|
|
|
return Inline;
|
|
|
|
if (!Data.isValidOffsetForDataOfSize(Offset, 1))
|
|
|
|
return createStringError(std::errc::io_error,
|
|
|
|
"0x%8.8" PRIx64 ": missing InlineInfo uint8_t indicating children",
|
|
|
|
Offset);
|
|
|
|
bool HasChildren = Data.getU8(&Offset) != 0;
|
|
|
|
if (!Data.isValidOffsetForDataOfSize(Offset, 4))
|
|
|
|
return createStringError(std::errc::io_error,
|
|
|
|
"0x%8.8" PRIx64 ": missing InlineInfo uint32_t for name", Offset);
|
|
|
|
Inline.Name = Data.getU32(&Offset);
|
|
|
|
if (!Data.isValidOffset(Offset))
|
|
|
|
return createStringError(std::errc::io_error,
|
|
|
|
"0x%8.8" PRIx64 ": missing ULEB128 for InlineInfo call file", Offset);
|
|
|
|
Inline.CallFile = (uint32_t)Data.getULEB128(&Offset);
|
|
|
|
if (!Data.isValidOffset(Offset))
|
|
|
|
return createStringError(std::errc::io_error,
|
|
|
|
"0x%8.8" PRIx64 ": missing ULEB128 for InlineInfo call line", Offset);
|
|
|
|
Inline.CallLine = (uint32_t)Data.getULEB128(&Offset);
|
|
|
|
if (HasChildren) {
|
|
|
|
// Child address ranges are encoded relative to the first address in the
|
|
|
|
// parent InlineInfo object.
|
2022-04-22 12:58:13 +03:00
|
|
|
const auto ChildBaseAddr = Inline.Ranges[0].start();
|
2019-09-04 17:32:51 +00:00
|
|
|
while (true) {
|
|
|
|
llvm::Expected<InlineInfo> Child = decode(Data, Offset, ChildBaseAddr);
|
|
|
|
if (!Child)
|
|
|
|
return Child.takeError();
|
|
|
|
// InlineInfo with empty Ranges termintes a child sibling chain.
|
|
|
|
if (Child.get().Ranges.empty())
|
|
|
|
break;
|
|
|
|
Inline.Children.emplace_back(std::move(*Child));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Inline;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Expected<InlineInfo> InlineInfo::decode(DataExtractor &Data,
|
|
|
|
uint64_t BaseAddr) {
|
|
|
|
uint64_t Offset = 0;
|
|
|
|
return ::decode(Data, Offset, BaseAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Error InlineInfo::encode(FileWriter &O, uint64_t BaseAddr) const {
|
|
|
|
// Users must verify the InlineInfo is valid prior to calling this funtion.
|
|
|
|
// We don't want to emit any InlineInfo objects if they are not valid since
|
|
|
|
// it will waste space in the GSYM file.
|
|
|
|
if (!isValid())
|
|
|
|
return createStringError(std::errc::invalid_argument,
|
|
|
|
"attempted to encode invalid InlineInfo object");
|
2022-04-22 12:58:13 +03:00
|
|
|
encodeRanges(Ranges, O, BaseAddr);
|
2019-09-04 17:32:51 +00:00
|
|
|
bool HasChildren = !Children.empty();
|
|
|
|
O.writeU8(HasChildren);
|
|
|
|
O.writeU32(Name);
|
|
|
|
O.writeULEB(CallFile);
|
|
|
|
O.writeULEB(CallLine);
|
|
|
|
if (HasChildren) {
|
|
|
|
// Child address ranges are encoded as relative to the first
|
|
|
|
// address in the Ranges for this object. This keeps the offsets
|
|
|
|
// small and allows for efficient encoding using ULEB offsets.
|
2022-04-22 12:58:13 +03:00
|
|
|
const uint64_t ChildBaseAddr = Ranges[0].start();
|
2019-09-04 17:32:51 +00:00
|
|
|
for (const auto &Child : Children) {
|
|
|
|
// Make sure all child address ranges are contained in the parent address
|
|
|
|
// ranges.
|
|
|
|
for (const auto &ChildRange: Child.Ranges) {
|
|
|
|
if (!Ranges.contains(ChildRange))
|
|
|
|
return createStringError(std::errc::invalid_argument,
|
|
|
|
"child range not contained in parent");
|
|
|
|
}
|
|
|
|
llvm::Error Err = Child.encode(O, ChildBaseAddr);
|
|
|
|
if (Err)
|
|
|
|
return Err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Terminate child sibling chain by emitting a zero. This zero will cause
|
|
|
|
// the decodeAll() function above to return false and stop the decoding
|
|
|
|
// of child InlineInfo objects that are siblings.
|
|
|
|
O.writeULEB(0);
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
2023-07-31 22:19:46 -07:00
|
|
|
|
|
|
|
static uint64_t GetTotalNumChildren(const InlineInfo &II) {
|
|
|
|
uint64_t NumChildren = II.Children.size();
|
|
|
|
for (const auto &Child : II.Children)
|
|
|
|
NumChildren += GetTotalNumChildren(Child);
|
|
|
|
return NumChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InlineInfo::operator<(const InlineInfo &RHS) const {
|
|
|
|
return GetTotalNumChildren(*this) < GetTotalNumChildren(RHS);
|
|
|
|
}
|