2017-03-01 09:14:23 +08:00
|
|
|
//===- DWARFContext.cpp ---------------------------------------------------===//
|
2011-09-14 03:42:23 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +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
|
2011-09-14 03:42:23 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-05-04 00:02:29 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-07-19 15:03:58 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2017-03-01 09:14:23 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-05-04 00:02:29 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2017-06-24 05:57:40 +08:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2015-01-31 02:07:45 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
|
2017-03-01 09:14:23 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
|
2018-08-01 06:19:19 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugAddr.h"
|
2015-01-31 02:07:45 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
|
2017-05-04 00:02:29 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"
|
2017-03-01 09:14:23 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
|
2016-12-17 17:10:32 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
|
2018-10-31 09:12:58 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
|
2018-02-02 20:35:52 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
|
2017-03-01 09:14:23 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
|
2015-11-12 03:28:21 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
|
2017-05-04 00:02:29 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFVerifier.h"
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-30 05:41:21 +08:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2017-01-11 23:26:41 +08:00
|
|
|
#include "llvm/Object/Decompressor.h"
|
2016-07-07 00:56:42 +08:00
|
|
|
#include "llvm/Object/MachO.h"
|
2017-03-01 09:14:23 +08:00
|
|
|
#include "llvm/Object/ObjectFile.h"
|
[DWARF] Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation entries
Summary:
getRelocatedValue may compute incorrect value for SHT_RELA-typed relocation entries.
// DWARFDataExtractor.cpp
uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint32_t *Off,
...
// This formula is correct for REL, but may be incorrect for RELA if the value
// stored in the location (getUnsigned(Off, Size)) is not zero.
return getUnsigned(Off, Size) + Rel->Value;
In this patch, we
* refactor these visit* functions to include a new parameter `uint64_t A`.
Since these visit* functions are no longer used as visitors, rename them to resolve*.
+ REL: A is used as the addend. A is the value stored in the location where the
relocation applies: getUnsigned(Off, Size)
+ RELA: The addend encoded in RelocationRef is used, e.g. getELFAddend(R)
* and add another set of supports* functions to check if a given relocation type is handled.
DWARFObjInMemory uses them to fail early.
Reviewers: echristo, dblaikie
Reviewed By: echristo
Subscribers: mgorny, aprantl, aheejin, fedor.sergeev, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D57939
llvm-svn: 356729
2019-03-22 10:43:11 +08:00
|
|
|
#include "llvm/Object/RelocationResolver.h"
|
2017-03-01 09:14:23 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/DataExtractor.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
2011-09-16 00:57:13 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2017-03-01 09:14:23 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2017-09-14 06:09:01 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-30 05:41:21 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2018-04-15 06:07:23 +08:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2011-09-14 09:09:52 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-09-16 04:43:22 +08:00
|
|
|
#include <algorithm>
|
2017-03-01 09:14:23 +08:00
|
|
|
#include <cstdint>
|
2018-07-24 07:27:45 +08:00
|
|
|
#include <deque>
|
2017-05-03 04:28:33 +08:00
|
|
|
#include <map>
|
2017-03-01 09:14:23 +08:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2011-09-14 03:42:23 +08:00
|
|
|
using namespace llvm;
|
2011-09-16 02:02:20 +08:00
|
|
|
using namespace dwarf;
|
2013-05-30 11:05:14 +08:00
|
|
|
using namespace object;
|
2011-09-14 03:42:23 +08:00
|
|
|
|
2014-04-22 06:55:11 +08:00
|
|
|
#define DEBUG_TYPE "dwarf"
|
|
|
|
|
2017-06-24 05:57:40 +08:00
|
|
|
using DWARFLineTable = DWARFDebugLine::LineTable;
|
|
|
|
using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
|
|
|
|
using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
|
2012-10-17 07:46:25 +08:00
|
|
|
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-30 05:41:21 +08:00
|
|
|
DWARFContext::DWARFContext(std::unique_ptr<const DWARFObject> DObj,
|
|
|
|
std::string DWPName)
|
|
|
|
: DIContext(CK_DWARF), DWPName(std::move(DWPName)), DObj(std::move(DObj)) {}
|
|
|
|
|
|
|
|
DWARFContext::~DWARFContext() = default;
|
|
|
|
|
2017-09-14 02:22:59 +08:00
|
|
|
/// Dump the UUID load command.
|
|
|
|
static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj) {
|
|
|
|
auto *MachO = dyn_cast<MachOObjectFile>(&Obj);
|
|
|
|
if (!MachO)
|
|
|
|
return;
|
|
|
|
for (auto LC : MachO->load_commands()) {
|
|
|
|
raw_ostream::uuid_t UUID;
|
|
|
|
if (LC.C.cmd == MachO::LC_UUID) {
|
|
|
|
if (LC.C.cmdsize < sizeof(UUID) + sizeof(LC.C)) {
|
|
|
|
OS << "error: UUID load command is too short.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OS << "UUID: ";
|
|
|
|
memcpy(&UUID, LC.Ptr+sizeof(LC.C), sizeof(UUID));
|
|
|
|
OS.write_uuid(UUID);
|
2018-01-06 05:44:17 +08:00
|
|
|
Triple T = MachO->getArchTriple();
|
|
|
|
OS << " (" << T.getArchName() << ')';
|
2017-09-14 02:22:59 +08:00
|
|
|
OS << ' ' << MachO->getFileName() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-22 03:38:13 +08:00
|
|
|
using ContributionCollection =
|
|
|
|
std::vector<Optional<StrOffsetsContributionDescriptor>>;
|
|
|
|
|
|
|
|
// Collect all the contributions to the string offsets table from all units,
|
|
|
|
// sort them by their starting offsets and remove duplicates.
|
|
|
|
static ContributionCollection
|
2018-08-03 03:29:38 +08:00
|
|
|
collectContributionData(DWARFContext::unit_iterator_range Units) {
|
2017-12-22 03:38:13 +08:00
|
|
|
ContributionCollection Contributions;
|
2018-08-03 03:29:38 +08:00
|
|
|
for (const auto &U : Units)
|
|
|
|
Contributions.push_back(U->getStringOffsetsTableContribution());
|
2017-12-22 03:38:13 +08:00
|
|
|
// Sort the contributions so that any invalid ones are placed at
|
|
|
|
// the start of the contributions vector. This way they are reported
|
|
|
|
// first.
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 10:13:45 +08:00
|
|
|
llvm::sort(Contributions,
|
2018-04-02 00:18:49 +08:00
|
|
|
[](const Optional<StrOffsetsContributionDescriptor> &L,
|
|
|
|
const Optional<StrOffsetsContributionDescriptor> &R) {
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 10:13:45 +08:00
|
|
|
if (L && R)
|
|
|
|
return L->Base < R->Base;
|
2018-04-02 00:18:49 +08:00
|
|
|
return R.hasValue();
|
|
|
|
});
|
2017-12-22 03:38:13 +08:00
|
|
|
|
|
|
|
// Uniquify contributions, as it is possible that units (specifically
|
|
|
|
// type units in dwo or dwp files) share contributions. We don't want
|
|
|
|
// to report them more than once.
|
|
|
|
Contributions.erase(
|
|
|
|
std::unique(Contributions.begin(), Contributions.end(),
|
|
|
|
[](const Optional<StrOffsetsContributionDescriptor> &L,
|
|
|
|
const Optional<StrOffsetsContributionDescriptor> &R) {
|
|
|
|
if (L && R)
|
|
|
|
return L->Base == R->Base && L->Size == R->Size;
|
|
|
|
return false;
|
|
|
|
}),
|
|
|
|
Contributions.end());
|
|
|
|
return Contributions;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpDWARFv5StringOffsetsSection(
|
|
|
|
raw_ostream &OS, StringRef SectionName, const DWARFObject &Obj,
|
|
|
|
const DWARFSection &StringOffsetsSection, StringRef StringSection,
|
2018-08-03 03:29:38 +08:00
|
|
|
DWARFContext::unit_iterator_range Units, bool LittleEndian) {
|
|
|
|
auto Contributions = collectContributionData(Units);
|
2017-07-20 06:27:28 +08:00
|
|
|
DWARFDataExtractor StrOffsetExt(Obj, StringOffsetsSection, LittleEndian, 0);
|
2017-12-22 03:38:13 +08:00
|
|
|
DataExtractor StrData(StringSection, LittleEndian, 0);
|
2017-06-06 09:22:34 +08:00
|
|
|
uint64_t SectionSize = StringOffsetsSection.Data.size();
|
2017-12-22 03:38:13 +08:00
|
|
|
uint32_t Offset = 0;
|
|
|
|
for (auto &Contribution : Contributions) {
|
|
|
|
// Report an ill-formed contribution.
|
|
|
|
if (!Contribution) {
|
2017-06-06 09:22:34 +08:00
|
|
|
OS << "error: invalid contribution to string offsets table in section ."
|
|
|
|
<< SectionName << ".\n";
|
|
|
|
return;
|
|
|
|
}
|
2017-12-22 03:38:13 +08:00
|
|
|
|
|
|
|
dwarf::DwarfFormat Format = Contribution->getFormat();
|
|
|
|
uint16_t Version = Contribution->getVersion();
|
|
|
|
uint64_t ContributionHeader = Contribution->Base;
|
|
|
|
// In DWARF v5 there is a contribution header that immediately precedes
|
|
|
|
// the string offsets base (the location we have previously retrieved from
|
|
|
|
// the CU DIE's DW_AT_str_offsets attribute). The header is located either
|
|
|
|
// 8 or 16 bytes before the base, depending on the contribution's format.
|
|
|
|
if (Version >= 5)
|
|
|
|
ContributionHeader -= Format == DWARF32 ? 8 : 16;
|
|
|
|
|
|
|
|
// Detect overlapping contributions.
|
|
|
|
if (Offset > ContributionHeader) {
|
|
|
|
OS << "error: overlapping contributions to string offsets table in "
|
|
|
|
"section ."
|
2017-06-06 09:22:34 +08:00
|
|
|
<< SectionName << ".\n";
|
|
|
|
return;
|
|
|
|
}
|
2017-12-22 03:38:13 +08:00
|
|
|
// Report a gap in the table.
|
|
|
|
if (Offset < ContributionHeader) {
|
|
|
|
OS << format("0x%8.8x: Gap, length = ", Offset);
|
|
|
|
OS << (ContributionHeader - Offset) << "\n";
|
2017-06-06 09:22:34 +08:00
|
|
|
}
|
2017-12-22 09:12:24 +08:00
|
|
|
OS << format("0x%8.8x: ", (uint32_t)ContributionHeader);
|
2018-05-11 04:02:34 +08:00
|
|
|
// In DWARF v5 the contribution size in the descriptor does not equal
|
|
|
|
// the originally encoded length (it does not contain the length of the
|
|
|
|
// version field and the padding, a total of 4 bytes). Add them back in
|
|
|
|
// for reporting.
|
|
|
|
OS << "Contribution size = " << (Contribution->Size + (Version < 5 ? 0 : 4))
|
2017-12-22 03:38:13 +08:00
|
|
|
<< ", Format = " << (Format == DWARF32 ? "DWARF32" : "DWARF64")
|
2017-06-06 09:22:34 +08:00
|
|
|
<< ", Version = " << Version << "\n";
|
|
|
|
|
2017-12-22 03:38:13 +08:00
|
|
|
Offset = Contribution->Base;
|
|
|
|
unsigned EntrySize = Contribution->getDwarfOffsetByteSize();
|
|
|
|
while (Offset - Contribution->Base < Contribution->Size) {
|
2017-06-06 09:22:34 +08:00
|
|
|
OS << format("0x%8.8x: ", Offset);
|
2017-12-22 03:38:13 +08:00
|
|
|
// FIXME: We can only extract strings if the offset fits in 32 bits.
|
2017-06-30 00:52:08 +08:00
|
|
|
uint64_t StringOffset =
|
|
|
|
StrOffsetExt.getRelocatedValue(EntrySize, &Offset);
|
2017-12-22 03:38:13 +08:00
|
|
|
// Extract the string if we can and display it. Otherwise just report
|
|
|
|
// the offset.
|
|
|
|
if (StringOffset <= std::numeric_limits<uint32_t>::max()) {
|
2017-06-06 09:22:34 +08:00
|
|
|
uint32_t StringOffset32 = (uint32_t)StringOffset;
|
2017-08-08 00:08:11 +08:00
|
|
|
OS << format("%8.8x ", StringOffset32);
|
2017-06-06 09:22:34 +08:00
|
|
|
const char *S = StrData.getCStr(&StringOffset32);
|
|
|
|
if (S)
|
|
|
|
OS << format("\"%s\"", S);
|
|
|
|
} else
|
2017-08-07 21:30:03 +08:00
|
|
|
OS << format("%16.16" PRIx64 " ", StringOffset);
|
2017-06-06 09:22:34 +08:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
}
|
2017-12-22 03:38:13 +08:00
|
|
|
// Report a gap at the end of the table.
|
|
|
|
if (Offset < SectionSize) {
|
|
|
|
OS << format("0x%8.8x: Gap, length = ", Offset);
|
|
|
|
OS << (SectionSize - Offset) << "\n";
|
|
|
|
}
|
2017-06-06 09:22:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dump a DWARF string offsets section. This may be a DWARF v5 formatted
|
|
|
|
// string offsets section, where each compile or type unit contributes a
|
|
|
|
// number of entries (string offsets), with each contribution preceded by
|
|
|
|
// a header containing size and version number. Alternatively, it may be a
|
|
|
|
// monolithic series of string offsets, as generated by the pre-DWARF v5
|
|
|
|
// implementation of split DWARF.
|
2018-08-02 04:46:46 +08:00
|
|
|
static void dumpStringOffsetsSection(raw_ostream &OS, StringRef SectionName,
|
|
|
|
const DWARFObject &Obj,
|
|
|
|
const DWARFSection &StringOffsetsSection,
|
|
|
|
StringRef StringSection,
|
2018-08-03 03:29:38 +08:00
|
|
|
DWARFContext::unit_iterator_range Units,
|
2018-08-02 04:46:46 +08:00
|
|
|
bool LittleEndian, unsigned MaxVersion) {
|
2017-06-06 09:22:34 +08:00
|
|
|
// If we have at least one (compile or type) unit with DWARF v5 or greater,
|
|
|
|
// we assume that the section is formatted like a DWARF v5 string offsets
|
|
|
|
// section.
|
|
|
|
if (MaxVersion >= 5)
|
2017-07-20 06:27:28 +08:00
|
|
|
dumpDWARFv5StringOffsetsSection(OS, SectionName, Obj, StringOffsetsSection,
|
2018-08-03 03:29:38 +08:00
|
|
|
StringSection, Units, LittleEndian);
|
2017-06-06 09:22:34 +08:00
|
|
|
else {
|
|
|
|
DataExtractor strOffsetExt(StringOffsetsSection.Data, LittleEndian, 0);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
uint64_t size = StringOffsetsSection.Data.size();
|
|
|
|
// Ensure that size is a multiple of the size of an entry.
|
|
|
|
if (size & ((uint64_t)(sizeof(uint32_t) - 1))) {
|
|
|
|
OS << "error: size of ." << SectionName << " is not a multiple of "
|
|
|
|
<< sizeof(uint32_t) << ".\n";
|
|
|
|
size &= -(uint64_t)sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
DataExtractor StrData(StringSection, LittleEndian, 0);
|
|
|
|
while (offset < size) {
|
|
|
|
OS << format("0x%8.8x: ", offset);
|
|
|
|
uint32_t StringOffset = strOffsetExt.getU32(&offset);
|
|
|
|
OS << format("%8.8x ", StringOffset);
|
|
|
|
const char *S = StrData.getCStr(&StringOffset);
|
|
|
|
if (S)
|
|
|
|
OS << format("\"%s\"", S);
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-01 06:19:19 +08:00
|
|
|
// Dump the .debug_addr section.
|
|
|
|
static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData,
|
|
|
|
DIDumpOptions DumpOpts, uint16_t Version,
|
|
|
|
uint8_t AddrSize) {
|
|
|
|
uint32_t Offset = 0;
|
|
|
|
while (AddrData.isValidOffset(Offset)) {
|
|
|
|
DWARFDebugAddrTable AddrTable;
|
|
|
|
uint32_t TableOffset = Offset;
|
2018-08-23 20:43:33 +08:00
|
|
|
if (Error Err = AddrTable.extract(AddrData, &Offset, Version, AddrSize,
|
|
|
|
DWARFContext::dumpWarning)) {
|
2018-08-01 06:19:19 +08:00
|
|
|
WithColor::error() << toString(std::move(Err)) << '\n';
|
|
|
|
// Keep going after an error, if we can, assuming that the length field
|
|
|
|
// could be read. If it couldn't, stop reading the section.
|
|
|
|
if (!AddrTable.hasValidLength())
|
|
|
|
break;
|
|
|
|
uint64_t Length = AddrTable.getLength();
|
|
|
|
Offset = TableOffset + Length;
|
|
|
|
} else {
|
|
|
|
AddrTable.dump(OS, DumpOpts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 09:12:58 +08:00
|
|
|
// Dump the .debug_rnglists or .debug_rnglists.dwo section (DWARF v5).
|
2019-02-27 21:17:36 +08:00
|
|
|
static void dumpRnglistsSection(
|
|
|
|
raw_ostream &OS, DWARFDataExtractor &rnglistData,
|
|
|
|
llvm::function_ref<Optional<object::SectionedAddress>(uint32_t)>
|
|
|
|
LookupPooledAddress,
|
|
|
|
DIDumpOptions DumpOpts) {
|
2018-05-19 04:12:54 +08:00
|
|
|
uint32_t Offset = 0;
|
2018-10-31 09:12:58 +08:00
|
|
|
while (rnglistData.isValidOffset(Offset)) {
|
|
|
|
llvm::DWARFDebugRnglistTable Rnglists;
|
|
|
|
uint32_t TableOffset = Offset;
|
|
|
|
if (Error Err = Rnglists.extract(rnglistData, &Offset)) {
|
2018-05-19 04:12:54 +08:00
|
|
|
WithColor::error() << toString(std::move(Err)) << '\n';
|
2018-10-31 09:12:58 +08:00
|
|
|
uint64_t Length = Rnglists.length();
|
|
|
|
// Keep going after an error, if we can, assuming that the length field
|
|
|
|
// could be read. If it couldn't, stop reading the section.
|
|
|
|
if (Length == 0)
|
2018-05-19 04:12:54 +08:00
|
|
|
break;
|
2018-10-31 09:12:58 +08:00
|
|
|
Offset = TableOffset + Length;
|
2018-05-19 04:12:54 +08:00
|
|
|
} else {
|
2018-10-31 09:12:58 +08:00
|
|
|
Rnglists.dump(OS, LookupPooledAddress, DumpOpts);
|
2018-05-19 04:12:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-22 19:30:54 +08:00
|
|
|
static void dumpLoclistsSection(raw_ostream &OS, DIDumpOptions DumpOpts,
|
|
|
|
DWARFDataExtractor Data,
|
|
|
|
const MCRegisterInfo *MRI,
|
|
|
|
Optional<uint64_t> DumpOffset) {
|
|
|
|
uint32_t Offset = 0;
|
|
|
|
DWARFDebugLoclists Loclists;
|
|
|
|
|
|
|
|
DWARFListTableHeader Header(".debug_loclists", "locations");
|
|
|
|
if (Error E = Header.extract(Data, &Offset)) {
|
|
|
|
WithColor::error() << toString(std::move(E)) << '\n';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Header.dump(OS, DumpOpts);
|
|
|
|
DataExtractor LocData(Data.getData().drop_front(Offset),
|
|
|
|
Data.isLittleEndian(), Header.getAddrSize());
|
|
|
|
|
2018-10-25 18:56:44 +08:00
|
|
|
Loclists.parse(LocData, Header.getVersion());
|
2018-10-22 19:30:54 +08:00
|
|
|
Loclists.dump(OS, 0, MRI, DumpOffset);
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
void DWARFContext::dump(
|
|
|
|
raw_ostream &OS, DIDumpOptions DumpOpts,
|
|
|
|
std::array<Optional<uint64_t>, DIDT_ID_Count> DumpOffsets) {
|
|
|
|
|
2017-09-12 06:59:45 +08:00
|
|
|
uint64_t DumpType = DumpOpts.DumpType;
|
2017-06-02 02:18:23 +08:00
|
|
|
|
2017-09-14 06:09:01 +08:00
|
|
|
StringRef Extension = sys::path::extension(DObj->getFileName());
|
|
|
|
bool IsDWO = (Extension == ".dwo") || (Extension == ".dwp");
|
|
|
|
|
|
|
|
// Print UUID header.
|
2017-09-14 02:22:59 +08:00
|
|
|
const auto *ObjFile = DObj->getFile();
|
|
|
|
if (DumpType & DIDT_UUID)
|
|
|
|
dumpUUID(OS, *ObjFile);
|
|
|
|
|
2017-09-14 06:09:01 +08:00
|
|
|
// Print a header for each explicitly-requested section.
|
|
|
|
// Otherwise just print one for non-empty sections.
|
2017-09-16 07:04:04 +08:00
|
|
|
// Only print empty .dwo section headers when dumping a .dwo file.
|
2017-09-14 06:09:01 +08:00
|
|
|
bool Explicit = DumpType != DIDT_All && !IsDWO;
|
2017-09-16 07:04:04 +08:00
|
|
|
bool ExplicitDWO = Explicit && IsDWO;
|
|
|
|
auto shouldDump = [&](bool Explicit, const char *Name, unsigned ID,
|
2018-11-13 02:53:28 +08:00
|
|
|
StringRef Section) -> Optional<uint64_t> * {
|
2017-09-16 07:04:04 +08:00
|
|
|
unsigned Mask = 1U << ID;
|
|
|
|
bool Should = (DumpType & Mask) && (Explicit || !Section.empty());
|
2018-11-13 02:53:28 +08:00
|
|
|
if (!Should)
|
|
|
|
return nullptr;
|
|
|
|
OS << "\n" << Name << " contents:\n";
|
|
|
|
return &DumpOffsets[ID];
|
2017-09-14 06:09:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Dump individual sections.
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_abbrev", DIDT_ID_DebugAbbrev,
|
|
|
|
DObj->getAbbrevSection()))
|
2013-01-26 04:26:43 +08:00
|
|
|
getDebugAbbrev()->dump(OS);
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(ExplicitDWO, ".debug_abbrev.dwo", DIDT_ID_DebugAbbrev,
|
|
|
|
DObj->getAbbrevDWOSection()))
|
2017-09-14 06:09:01 +08:00
|
|
|
getDebugAbbrevDWO()->dump(OS);
|
2011-09-14 09:09:52 +08:00
|
|
|
|
2018-11-08 05:39:09 +08:00
|
|
|
auto dumpDebugInfo = [&](const char *Name, unit_iterator_range Units) {
|
|
|
|
OS << '\n' << Name << " contents:\n";
|
2018-11-13 02:53:28 +08:00
|
|
|
if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
|
2018-11-08 05:39:09 +08:00
|
|
|
for (const auto &U : Units)
|
|
|
|
U->getDIEForOffset(DumpOffset.getValue())
|
|
|
|
.dump(OS, 0, DumpOpts.noImplicitRecursion());
|
2018-10-06 04:55:20 +08:00
|
|
|
else
|
|
|
|
for (const auto &U : Units)
|
|
|
|
U->dump(OS, DumpOpts);
|
2017-09-16 07:04:04 +08:00
|
|
|
};
|
2018-11-08 05:39:09 +08:00
|
|
|
if ((DumpType & DIDT_DebugInfo)) {
|
|
|
|
if (Explicit || getNumCompileUnits())
|
|
|
|
dumpDebugInfo(".debug_info", info_section_units());
|
|
|
|
if (ExplicitDWO || getNumDWOCompileUnits())
|
|
|
|
dumpDebugInfo(".debug_info.dwo", dwo_info_section_units());
|
|
|
|
}
|
2014-01-09 07:29:59 +08:00
|
|
|
|
2018-08-03 03:29:38 +08:00
|
|
|
auto dumpDebugType = [&](const char *Name, unit_iterator_range Units) {
|
2017-09-17 00:58:18 +08:00
|
|
|
OS << '\n' << Name << " contents:\n";
|
2018-08-03 03:29:38 +08:00
|
|
|
for (const auto &U : Units)
|
2018-11-13 02:53:28 +08:00
|
|
|
if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugTypes])
|
2018-08-03 03:29:38 +08:00
|
|
|
U->getDIEForOffset(*DumpOffset)
|
2018-08-02 04:46:46 +08:00
|
|
|
.dump(OS, 0, DumpOpts.noImplicitRecursion());
|
|
|
|
else
|
2018-08-03 03:29:38 +08:00
|
|
|
U->dump(OS, DumpOpts);
|
2017-09-17 00:58:18 +08:00
|
|
|
};
|
|
|
|
if ((DumpType & DIDT_DebugTypes)) {
|
|
|
|
if (Explicit || getNumTypeUnits())
|
2018-08-02 04:54:11 +08:00
|
|
|
dumpDebugType(".debug_types", types_section_units());
|
2017-09-17 00:58:18 +08:00
|
|
|
if (ExplicitDWO || getNumDWOTypeUnits())
|
2018-08-02 04:54:11 +08:00
|
|
|
dumpDebugType(".debug_types.dwo", dwo_types_section_units());
|
2014-03-13 15:52:54 +08:00
|
|
|
}
|
2014-01-09 13:08:24 +08:00
|
|
|
|
2018-11-13 02:53:28 +08:00
|
|
|
if (const auto *Off = shouldDump(Explicit, ".debug_loc", DIDT_ID_DebugLoc,
|
|
|
|
DObj->getLocSection().Data)) {
|
|
|
|
getDebugLoc()->dump(OS, getRegisterInfo(), *Off);
|
2013-06-20 05:37:13 +08:00
|
|
|
}
|
2018-11-13 02:53:28 +08:00
|
|
|
if (const auto *Off =
|
|
|
|
shouldDump(Explicit, ".debug_loclists", DIDT_ID_DebugLoclists,
|
|
|
|
DObj->getLoclistsSection().Data)) {
|
2018-10-22 19:30:54 +08:00
|
|
|
DWARFDataExtractor Data(*DObj, DObj->getLoclistsSection(), isLittleEndian(),
|
|
|
|
0);
|
2018-11-13 02:53:28 +08:00
|
|
|
dumpLoclistsSection(OS, DumpOpts, Data, getRegisterInfo(), *Off);
|
2018-10-22 19:30:54 +08:00
|
|
|
}
|
2018-11-13 02:53:28 +08:00
|
|
|
if (const auto *Off =
|
|
|
|
shouldDump(ExplicitDWO, ".debug_loc.dwo", DIDT_ID_DebugLoc,
|
|
|
|
DObj->getLocDWOSection().Data)) {
|
|
|
|
getDebugLocDWO()->dump(OS, 0, getRegisterInfo(), *Off);
|
2014-03-25 09:44:02 +08:00
|
|
|
}
|
|
|
|
|
2018-11-13 02:53:28 +08:00
|
|
|
if (const auto *Off = shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
|
|
|
|
DObj->getDebugFrameSection()))
|
|
|
|
getDebugFrame()->dump(OS, getRegisterInfo(), *Off);
|
2017-09-18 22:15:57 +08:00
|
|
|
|
2018-11-13 02:53:28 +08:00
|
|
|
if (const auto *Off = shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
|
|
|
|
DObj->getEHFrameSection()))
|
|
|
|
getEHFrame()->dump(OS, getRegisterInfo(), *Off);
|
2013-02-06 07:30:58 +08:00
|
|
|
|
2017-09-12 06:59:45 +08:00
|
|
|
if (DumpType & DIDT_DebugMacro) {
|
2017-09-14 06:09:01 +08:00
|
|
|
if (Explicit || !getDebugMacro()->empty()) {
|
|
|
|
OS << "\n.debug_macinfo contents:\n";
|
|
|
|
getDebugMacro()->dump(OS);
|
|
|
|
}
|
2015-11-12 17:38:54 +08:00
|
|
|
}
|
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_aranges", DIDT_ID_DebugAranges,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getARangeSection())) {
|
2017-09-14 06:09:01 +08:00
|
|
|
uint32_t offset = 0;
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor arangesData(DObj->getARangeSection(), isLittleEndian(), 0);
|
2013-01-26 04:26:43 +08:00
|
|
|
DWARFDebugArangeSet set;
|
|
|
|
while (set.extract(arangesData, &offset))
|
|
|
|
set.dump(OS);
|
|
|
|
}
|
2011-09-15 10:12:05 +08:00
|
|
|
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
auto DumpLineSection = [&](DWARFDebugLine::SectionParser Parser,
|
2018-11-13 02:53:28 +08:00
|
|
|
DIDumpOptions DumpOpts,
|
|
|
|
Optional<uint64_t> DumpOffset) {
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
while (!Parser.done()) {
|
|
|
|
if (DumpOffset && Parser.getOffset() != *DumpOffset) {
|
2018-08-23 20:43:33 +08:00
|
|
|
Parser.skip(dumpWarning);
|
2015-05-20 05:54:32 +08:00
|
|
|
continue;
|
2017-11-22 23:33:17 +08:00
|
|
|
}
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
OS << "debug_line[" << format("0x%8.8x", Parser.getOffset()) << "]\n";
|
2017-11-22 23:33:17 +08:00
|
|
|
if (DumpOpts.Verbose) {
|
2018-08-23 20:43:33 +08:00
|
|
|
Parser.parseNext(dumpWarning, dumpWarning, &OS);
|
2017-11-22 23:33:17 +08:00
|
|
|
} else {
|
2018-08-23 20:43:33 +08:00
|
|
|
DWARFDebugLine::LineTable LineTable =
|
|
|
|
Parser.parseNext(dumpWarning, dumpWarning);
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
LineTable.dump(OS, DumpOpts);
|
2013-01-26 04:26:43 +08:00
|
|
|
}
|
2011-09-16 02:02:20 +08:00
|
|
|
}
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
};
|
|
|
|
|
2018-11-13 02:53:28 +08:00
|
|
|
if (const auto *Off = shouldDump(Explicit, ".debug_line", DIDT_ID_DebugLine,
|
|
|
|
DObj->getLineSection().Data)) {
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
DWARFDataExtractor LineData(*DObj, DObj->getLineSection(), isLittleEndian(),
|
|
|
|
0);
|
|
|
|
DWARFDebugLine::SectionParser Parser(LineData, *this, compile_units(),
|
2018-08-02 04:46:46 +08:00
|
|
|
type_units());
|
2018-11-13 02:53:28 +08:00
|
|
|
DumpLineSection(Parser, DumpOpts, *Off);
|
2011-09-16 02:02:20 +08:00
|
|
|
}
|
2011-09-16 00:57:13 +08:00
|
|
|
|
2018-11-13 02:53:28 +08:00
|
|
|
if (const auto *Off =
|
|
|
|
shouldDump(ExplicitDWO, ".debug_line.dwo", DIDT_ID_DebugLine,
|
|
|
|
DObj->getLineDWOSection().Data)) {
|
2017-11-22 23:33:17 +08:00
|
|
|
DWARFDataExtractor LineData(*DObj, DObj->getLineDWOSection(),
|
|
|
|
isLittleEndian(), 0);
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
DWARFDebugLine::SectionParser Parser(LineData, *this, dwo_compile_units(),
|
2018-08-02 04:46:46 +08:00
|
|
|
dwo_type_units());
|
2018-11-13 02:53:28 +08:00
|
|
|
DumpLineSection(Parser, DumpOpts, *Off);
|
2014-02-25 07:58:54 +08:00
|
|
|
}
|
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_cu_index", DIDT_ID_DebugCUIndex,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getCUIndexSection())) {
|
2017-09-14 06:09:01 +08:00
|
|
|
getCUIndex().dump(OS);
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_tu_index", DIDT_ID_DebugTUIndex,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getTUIndexSection())) {
|
2017-09-14 06:09:01 +08:00
|
|
|
getTUIndex().dump(OS);
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_str", DIDT_ID_DebugStr,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getStringSection())) {
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor strData(DObj->getStringSection(), isLittleEndian(), 0);
|
2017-09-14 06:09:01 +08:00
|
|
|
uint32_t offset = 0;
|
2013-01-26 04:26:43 +08:00
|
|
|
uint32_t strOffset = 0;
|
|
|
|
while (const char *s = strData.getCStr(&offset)) {
|
|
|
|
OS << format("0x%8.8x: \"%s\"\n", strOffset, s);
|
|
|
|
strOffset = offset;
|
|
|
|
}
|
2011-09-16 00:57:13 +08:00
|
|
|
}
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(ExplicitDWO, ".debug_str.dwo", DIDT_ID_DebugStr,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getStringDWOSection())) {
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor strDWOData(DObj->getStringDWOSection(), isLittleEndian(), 0);
|
2017-09-14 06:09:01 +08:00
|
|
|
uint32_t offset = 0;
|
2014-01-09 08:13:35 +08:00
|
|
|
uint32_t strDWOOffset = 0;
|
|
|
|
while (const char *s = strDWOData.getCStr(&offset)) {
|
|
|
|
OS << format("0x%8.8x: \"%s\"\n", strDWOOffset, s);
|
|
|
|
strDWOOffset = offset;
|
2014-01-09 07:29:59 +08:00
|
|
|
}
|
2014-01-09 08:13:35 +08:00
|
|
|
}
|
2018-01-26 06:02:36 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_line_str", DIDT_ID_DebugLineStr,
|
|
|
|
DObj->getLineStringSection())) {
|
|
|
|
DataExtractor strData(DObj->getLineStringSection(), isLittleEndian(), 0);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
uint32_t strOffset = 0;
|
|
|
|
while (const char *s = strData.getCStr(&offset)) {
|
2018-02-24 07:01:06 +08:00
|
|
|
OS << format("0x%8.8x: \"", strOffset);
|
|
|
|
OS.write_escaped(s);
|
|
|
|
OS << "\"\n";
|
2018-01-26 06:02:36 +08:00
|
|
|
strOffset = offset;
|
|
|
|
}
|
|
|
|
}
|
2014-01-09 07:29:59 +08:00
|
|
|
|
2018-08-01 06:19:19 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_addr", DIDT_ID_DebugAddr,
|
|
|
|
DObj->getAddrSection().Data)) {
|
|
|
|
DWARFDataExtractor AddrData(*DObj, DObj->getAddrSection(),
|
|
|
|
isLittleEndian(), 0);
|
|
|
|
dumpAddrSection(OS, AddrData, DumpOpts, getMaxVersion(), getCUAddrSize());
|
|
|
|
}
|
|
|
|
|
2018-10-31 09:12:58 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_ranges", DIDT_ID_DebugRanges,
|
|
|
|
DObj->getRangeSection().Data)) {
|
|
|
|
uint8_t savedAddressByteSize = getCUAddrSize();
|
|
|
|
DWARFDataExtractor rangesData(*DObj, DObj->getRangeSection(),
|
|
|
|
isLittleEndian(), savedAddressByteSize);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
DWARFDebugRangeList rangeList;
|
|
|
|
while (rangesData.isValidOffset(offset)) {
|
|
|
|
if (Error E = rangeList.extract(rangesData, &offset)) {
|
|
|
|
WithColor::error() << toString(std::move(E)) << '\n';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rangeList.dump(OS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-20 14:16:25 +08:00
|
|
|
auto LookupPooledAddress = [&](uint32_t Index) -> Optional<SectionedAddress> {
|
|
|
|
const auto &CUs = compile_units();
|
|
|
|
auto I = CUs.begin();
|
|
|
|
if (I == CUs.end())
|
|
|
|
return None;
|
|
|
|
return (*I)->getAddrOffsetSectionItem(Index);
|
|
|
|
};
|
|
|
|
|
2018-02-02 20:35:52 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_rnglists", DIDT_ID_DebugRnglists,
|
|
|
|
DObj->getRnglistsSection().Data)) {
|
2018-05-19 04:12:54 +08:00
|
|
|
DWARFDataExtractor RnglistData(*DObj, DObj->getRnglistsSection(),
|
2018-10-31 09:12:58 +08:00
|
|
|
isLittleEndian(), 0);
|
|
|
|
dumpRnglistsSection(OS, RnglistData, LookupPooledAddress, DumpOpts);
|
2018-05-19 04:12:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldDump(ExplicitDWO, ".debug_rnglists.dwo", DIDT_ID_DebugRnglists,
|
|
|
|
DObj->getRnglistsDWOSection().Data)) {
|
|
|
|
DWARFDataExtractor RnglistData(*DObj, DObj->getRnglistsDWOSection(),
|
2018-10-31 09:12:58 +08:00
|
|
|
isLittleEndian(), 0);
|
|
|
|
dumpRnglistsSection(OS, RnglistData, LookupPooledAddress, DumpOpts);
|
2018-02-02 20:35:52 +08:00
|
|
|
}
|
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_pubnames", DIDT_ID_DebugPubnames,
|
2018-11-12 02:57:28 +08:00
|
|
|
DObj->getPubNamesSection().Data))
|
|
|
|
DWARFDebugPubTable(*DObj, DObj->getPubNamesSection(), isLittleEndian(), false)
|
2017-09-16 01:39:50 +08:00
|
|
|
.dump(OS);
|
2013-02-13 00:20:28 +08:00
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_pubtypes", DIDT_ID_DebugPubtypes,
|
2018-11-12 02:57:28 +08:00
|
|
|
DObj->getPubTypesSection().Data))
|
|
|
|
DWARFDebugPubTable(*DObj, DObj->getPubTypesSection(), isLittleEndian(), false)
|
2017-09-16 01:39:50 +08:00
|
|
|
.dump(OS);
|
2013-09-26 07:02:41 +08:00
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_gnu_pubnames", DIDT_ID_DebugGnuPubnames,
|
2018-11-12 02:57:28 +08:00
|
|
|
DObj->getGnuPubNamesSection().Data))
|
|
|
|
DWARFDebugPubTable(*DObj, DObj->getGnuPubNamesSection(), isLittleEndian(),
|
2016-12-17 17:10:32 +08:00
|
|
|
true /* GnuStyle */)
|
2017-09-16 01:39:50 +08:00
|
|
|
.dump(OS);
|
2013-09-25 03:50:00 +08:00
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_gnu_pubtypes", DIDT_ID_DebugGnuPubtypes,
|
2018-11-12 02:57:28 +08:00
|
|
|
DObj->getGnuPubTypesSection().Data))
|
|
|
|
DWARFDebugPubTable(*DObj, DObj->getGnuPubTypesSection(), isLittleEndian(),
|
2016-12-17 17:10:32 +08:00
|
|
|
true /* GnuStyle */)
|
2017-09-16 01:39:50 +08:00
|
|
|
.dump(OS);
|
2013-09-20 07:01:29 +08:00
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_str_offsets", DIDT_ID_DebugStrOffsets,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getStringOffsetSection().Data))
|
2018-08-02 04:46:46 +08:00
|
|
|
dumpStringOffsetsSection(OS, "debug_str_offsets", *DObj,
|
|
|
|
DObj->getStringOffsetSection(),
|
2018-08-03 03:29:38 +08:00
|
|
|
DObj->getStringSection(), normal_units(),
|
|
|
|
isLittleEndian(), getMaxVersion());
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(ExplicitDWO, ".debug_str_offsets.dwo", DIDT_ID_DebugStrOffsets,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getStringOffsetDWOSection().Data))
|
2018-08-03 03:29:38 +08:00
|
|
|
dumpStringOffsetsSection(OS, "debug_str_offsets.dwo", *DObj,
|
|
|
|
DObj->getStringOffsetDWOSection(),
|
|
|
|
DObj->getStringDWOSection(), dwo_units(),
|
2018-10-06 04:55:20 +08:00
|
|
|
isLittleEndian(), getMaxDWOVersion());
|
2014-11-15 00:15:53 +08:00
|
|
|
|
2018-11-03 04:34:40 +08:00
|
|
|
if (shouldDump(Explicit, ".gdb_index", DIDT_ID_GdbIndex,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getGdbIndexSection())) {
|
2016-09-23 19:01:53 +08:00
|
|
|
getGdbIndex().dump(OS);
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".apple_names", DIDT_ID_AppleNames,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getAppleNamesSection().Data))
|
2017-09-29 02:10:52 +08:00
|
|
|
getAppleNames().dump(OS);
|
2014-11-15 00:15:53 +08:00
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".apple_types", DIDT_ID_AppleTypes,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getAppleTypesSection().Data))
|
2017-09-29 08:33:22 +08:00
|
|
|
getAppleTypes().dump(OS);
|
2014-11-15 00:15:53 +08:00
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".apple_namespaces", DIDT_ID_AppleNamespaces,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getAppleNamespacesSection().Data))
|
2017-09-29 08:52:33 +08:00
|
|
|
getAppleNamespaces().dump(OS);
|
2014-11-15 00:15:53 +08:00
|
|
|
|
2017-09-16 07:04:04 +08:00
|
|
|
if (shouldDump(Explicit, ".apple_objc", DIDT_ID_AppleObjC,
|
2017-09-16 01:39:50 +08:00
|
|
|
DObj->getAppleObjCSection().Data))
|
2017-09-29 08:52:33 +08:00
|
|
|
getAppleObjC().dump(OS);
|
[DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.
Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).
I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).
In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.
Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42297
llvm-svn: 323638
2018-01-29 19:08:32 +08:00
|
|
|
if (shouldDump(Explicit, ".debug_names", DIDT_ID_DebugNames,
|
|
|
|
DObj->getDebugNamesSection().Data))
|
|
|
|
getDebugNames().dump(OS);
|
2011-09-14 03:42:23 +08:00
|
|
|
}
|
|
|
|
|
2017-05-23 14:48:53 +08:00
|
|
|
DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) {
|
2018-08-02 04:54:11 +08:00
|
|
|
parseDWOUnits(LazyParse);
|
2017-07-30 23:15:58 +08:00
|
|
|
|
2017-07-30 16:12:07 +08:00
|
|
|
if (const auto &CUI = getCUIndex()) {
|
|
|
|
if (const auto *R = CUI.getFromHash(Hash))
|
2018-08-02 04:54:11 +08:00
|
|
|
return dyn_cast_or_null<DWARFCompileUnit>(
|
|
|
|
DWOUnits.getUnitForIndexEntry(*R));
|
2017-07-30 16:12:07 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's no index, just search through the CUs in the DWO - there's
|
|
|
|
// probably only one unless this is something like LTO - though an in-process
|
|
|
|
// built/cached lookup table could be used in that case to improve repeated
|
|
|
|
// lookups of different CUs in the DWO.
|
2018-05-23 01:27:31 +08:00
|
|
|
for (const auto &DWOCU : dwo_compile_units()) {
|
|
|
|
// Might not have parsed DWO ID yet.
|
|
|
|
if (!DWOCU->getDWOId()) {
|
|
|
|
if (Optional<uint64_t> DWOId =
|
|
|
|
toUnsigned(DWOCU->getUnitDIE().find(DW_AT_GNU_dwo_id)))
|
|
|
|
DWOCU->setDWOId(*DWOId);
|
|
|
|
else
|
|
|
|
// No DWO ID?
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-23 14:48:53 +08:00
|
|
|
if (DWOCU->getDWOId() == Hash)
|
2018-08-02 04:43:47 +08:00
|
|
|
return dyn_cast<DWARFCompileUnit>(DWOCU.get());
|
2018-05-23 01:27:31 +08:00
|
|
|
}
|
2017-05-23 14:48:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-03 04:28:33 +08:00
|
|
|
DWARFDie DWARFContext::getDIEForOffset(uint32_t Offset) {
|
2018-08-02 04:54:11 +08:00
|
|
|
parseNormalUnits();
|
|
|
|
if (auto *CU = NormalUnits.getUnitForOffset(Offset))
|
2017-05-03 04:28:33 +08:00
|
|
|
return CU->getDIEForOffset(Offset);
|
|
|
|
return DWARFDie();
|
|
|
|
}
|
|
|
|
|
2017-09-18 22:15:57 +08:00
|
|
|
bool DWARFContext::verify(raw_ostream &OS, DIDumpOptions DumpOpts) {
|
2017-05-03 04:28:33 +08:00
|
|
|
bool Success = true;
|
2017-09-13 17:43:05 +08:00
|
|
|
DWARFVerifier verifier(OS, *this, DumpOpts);
|
2017-07-27 08:59:33 +08:00
|
|
|
|
2017-07-20 10:06:52 +08:00
|
|
|
Success &= verifier.handleDebugAbbrev();
|
2017-09-18 22:15:57 +08:00
|
|
|
if (DumpOpts.DumpType & DIDT_DebugInfo)
|
2017-07-27 08:59:33 +08:00
|
|
|
Success &= verifier.handleDebugInfo();
|
2017-09-18 22:15:57 +08:00
|
|
|
if (DumpOpts.DumpType & DIDT_DebugLine)
|
2017-07-27 08:59:33 +08:00
|
|
|
Success &= verifier.handleDebugLine();
|
2017-07-26 08:52:31 +08:00
|
|
|
Success &= verifier.handleAccelTables();
|
2017-05-02 06:07:02 +08:00
|
|
|
return Success;
|
|
|
|
}
|
2017-06-14 08:17:55 +08:00
|
|
|
|
2015-11-17 08:39:55 +08:00
|
|
|
const DWARFUnitIndex &DWARFContext::getCUIndex() {
|
|
|
|
if (CUIndex)
|
|
|
|
return *CUIndex;
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor CUIndexData(DObj->getCUIndexSection(), isLittleEndian(), 0);
|
2015-11-17 08:39:55 +08:00
|
|
|
|
2015-12-02 14:21:34 +08:00
|
|
|
CUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
|
2015-11-17 08:39:55 +08:00
|
|
|
CUIndex->parse(CUIndexData);
|
|
|
|
return *CUIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DWARFUnitIndex &DWARFContext::getTUIndex() {
|
|
|
|
if (TUIndex)
|
|
|
|
return *TUIndex;
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor TUIndexData(DObj->getTUIndexSection(), isLittleEndian(), 0);
|
2015-11-17 08:39:55 +08:00
|
|
|
|
2015-12-02 14:21:34 +08:00
|
|
|
TUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_TYPES);
|
2015-11-17 08:39:55 +08:00
|
|
|
TUIndex->parse(TUIndexData);
|
|
|
|
return *TUIndex;
|
|
|
|
}
|
|
|
|
|
2016-09-23 19:01:53 +08:00
|
|
|
DWARFGdbIndex &DWARFContext::getGdbIndex() {
|
|
|
|
if (GdbIndex)
|
|
|
|
return *GdbIndex;
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor GdbIndexData(DObj->getGdbIndexSection(), true /*LE*/, 0);
|
2016-09-23 19:01:53 +08:00
|
|
|
GdbIndex = llvm::make_unique<DWARFGdbIndex>();
|
|
|
|
GdbIndex->parse(GdbIndexData);
|
|
|
|
return *GdbIndex;
|
|
|
|
}
|
|
|
|
|
2011-09-14 03:42:23 +08:00
|
|
|
const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
|
|
|
|
if (Abbrev)
|
|
|
|
return Abbrev.get();
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor abbrData(DObj->getAbbrevSection(), isLittleEndian(), 0);
|
2011-09-14 03:42:23 +08:00
|
|
|
|
|
|
|
Abbrev.reset(new DWARFDebugAbbrev());
|
2014-04-26 05:10:56 +08:00
|
|
|
Abbrev->extract(abbrData);
|
2011-09-14 03:42:23 +08:00
|
|
|
return Abbrev.get();
|
|
|
|
}
|
|
|
|
|
2013-01-03 07:52:13 +08:00
|
|
|
const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() {
|
|
|
|
if (AbbrevDWO)
|
|
|
|
return AbbrevDWO.get();
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor abbrData(DObj->getAbbrevDWOSection(), isLittleEndian(), 0);
|
2013-01-03 07:52:13 +08:00
|
|
|
AbbrevDWO.reset(new DWARFDebugAbbrev());
|
2014-04-26 05:10:56 +08:00
|
|
|
AbbrevDWO->extract(abbrData);
|
2013-01-03 07:52:13 +08:00
|
|
|
return AbbrevDWO.get();
|
|
|
|
}
|
|
|
|
|
2013-06-20 05:37:13 +08:00
|
|
|
const DWARFDebugLoc *DWARFContext::getDebugLoc() {
|
|
|
|
if (Loc)
|
|
|
|
return Loc.get();
|
|
|
|
|
2017-06-30 00:52:08 +08:00
|
|
|
Loc.reset(new DWARFDebugLoc);
|
2018-08-02 04:43:47 +08:00
|
|
|
// Assume all units have the same address byte size.
|
2017-06-30 00:52:08 +08:00
|
|
|
if (getNumCompileUnits()) {
|
2017-07-20 06:27:28 +08:00
|
|
|
DWARFDataExtractor LocData(*DObj, DObj->getLocSection(), isLittleEndian(),
|
2018-08-02 04:43:47 +08:00
|
|
|
getUnitAtIndex(0)->getAddressByteSize());
|
2017-06-30 00:52:08 +08:00
|
|
|
Loc->parse(LocData);
|
|
|
|
}
|
2013-06-20 05:37:13 +08:00
|
|
|
return Loc.get();
|
|
|
|
}
|
|
|
|
|
2018-10-22 19:30:54 +08:00
|
|
|
const DWARFDebugLoclists *DWARFContext::getDebugLocDWO() {
|
2014-03-25 09:44:02 +08:00
|
|
|
if (LocDWO)
|
|
|
|
return LocDWO.get();
|
|
|
|
|
2018-10-22 19:30:54 +08:00
|
|
|
LocDWO.reset(new DWARFDebugLoclists());
|
2018-04-06 16:49:57 +08:00
|
|
|
// Assume all compile units have the same address byte size.
|
2018-10-10 02:38:55 +08:00
|
|
|
// FIXME: We don't need AddressSize for split DWARF since relocatable
|
|
|
|
// addresses cannot appear there. At the moment DWARFExpression requires it.
|
|
|
|
DataExtractor LocData(DObj->getLocDWOSection().Data, isLittleEndian(), 4);
|
2018-10-25 18:56:44 +08:00
|
|
|
// Use version 4. DWO does not support the DWARF v5 .debug_loclists yet and
|
|
|
|
// that means we are parsing the new style .debug_loc (pre-standatized version
|
|
|
|
// of the .debug_loclists).
|
|
|
|
LocDWO->parse(LocData, 4 /* Version */);
|
2014-03-25 09:44:02 +08:00
|
|
|
return LocDWO.get();
|
|
|
|
}
|
|
|
|
|
2011-09-14 09:09:52 +08:00
|
|
|
const DWARFDebugAranges *DWARFContext::getDebugAranges() {
|
|
|
|
if (Aranges)
|
|
|
|
return Aranges.get();
|
|
|
|
|
|
|
|
Aranges.reset(new DWARFDebugAranges());
|
2012-11-16 16:36:25 +08:00
|
|
|
Aranges->generate(this);
|
2011-09-14 09:09:52 +08:00
|
|
|
return Aranges.get();
|
|
|
|
}
|
|
|
|
|
2013-02-06 07:30:58 +08:00
|
|
|
const DWARFDebugFrame *DWARFContext::getDebugFrame() {
|
|
|
|
if (DebugFrame)
|
|
|
|
return DebugFrame.get();
|
|
|
|
|
|
|
|
// There's a "bug" in the DWARFv3 standard with respect to the target address
|
|
|
|
// size within debug frame sections. While DWARF is supposed to be independent
|
|
|
|
// of its container, FDEs have fields with size being "target address size",
|
|
|
|
// which isn't specified in DWARF in general. It's only specified for CUs, but
|
|
|
|
// .eh_frame can appear without a .debug_info section. Follow the example of
|
|
|
|
// other tools (libdwarf) and extract this from the container (ObjectFile
|
|
|
|
// provides this information). This problem is fixed in DWARFv4
|
|
|
|
// See this dwarf-discuss discussion for more details:
|
|
|
|
// http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
|
2018-03-08 08:46:53 +08:00
|
|
|
DWARFDataExtractor debugFrameData(DObj->getDebugFrameSection(),
|
|
|
|
isLittleEndian(), DObj->getAddressSize());
|
2018-12-18 18:37:42 +08:00
|
|
|
DebugFrame.reset(new DWARFDebugFrame(getArch(), false /* IsEH */));
|
2016-01-26 23:09:42 +08:00
|
|
|
DebugFrame->parse(debugFrameData);
|
|
|
|
return DebugFrame.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const DWARFDebugFrame *DWARFContext::getEHFrame() {
|
|
|
|
if (EHFrame)
|
|
|
|
return EHFrame.get();
|
|
|
|
|
2018-03-08 08:46:53 +08:00
|
|
|
DWARFDataExtractor debugFrameData(DObj->getEHFrameSection(), isLittleEndian(),
|
|
|
|
DObj->getAddressSize());
|
2018-12-18 18:37:42 +08:00
|
|
|
DebugFrame.reset(new DWARFDebugFrame(getArch(), true /* IsEH */));
|
2013-02-06 07:30:58 +08:00
|
|
|
DebugFrame->parse(debugFrameData);
|
|
|
|
return DebugFrame.get();
|
|
|
|
}
|
|
|
|
|
2015-11-12 17:38:54 +08:00
|
|
|
const DWARFDebugMacro *DWARFContext::getDebugMacro() {
|
|
|
|
if (Macro)
|
|
|
|
return Macro.get();
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
DataExtractor MacinfoData(DObj->getMacinfoSection(), isLittleEndian(), 0);
|
2015-11-12 17:38:54 +08:00
|
|
|
Macro.reset(new DWARFDebugMacro());
|
|
|
|
Macro->parse(MacinfoData);
|
|
|
|
return Macro.get();
|
|
|
|
}
|
|
|
|
|
[DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.
Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).
I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).
In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.
Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42297
llvm-svn: 323638
2018-01-29 19:08:32 +08:00
|
|
|
template <typename T>
|
|
|
|
static T &getAccelTable(std::unique_ptr<T> &Cache, const DWARFObject &Obj,
|
|
|
|
const DWARFSection &Section, StringRef StringSection,
|
|
|
|
bool IsLittleEndian) {
|
2017-09-29 02:10:52 +08:00
|
|
|
if (Cache)
|
|
|
|
return *Cache;
|
|
|
|
DWARFDataExtractor AccelSection(Obj, Section, IsLittleEndian, 0);
|
|
|
|
DataExtractor StrData(StringSection, IsLittleEndian, 0);
|
[DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.
Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).
I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).
In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.
Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42297
llvm-svn: 323638
2018-01-29 19:08:32 +08:00
|
|
|
Cache.reset(new T(AccelSection, StrData));
|
2017-12-12 02:22:47 +08:00
|
|
|
if (Error E = Cache->extract())
|
|
|
|
llvm::consumeError(std::move(E));
|
2017-09-29 02:10:52 +08:00
|
|
|
return *Cache;
|
|
|
|
}
|
|
|
|
|
[DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.
Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).
I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).
In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.
Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42297
llvm-svn: 323638
2018-01-29 19:08:32 +08:00
|
|
|
const DWARFDebugNames &DWARFContext::getDebugNames() {
|
|
|
|
return getAccelTable(Names, *DObj, DObj->getDebugNamesSection(),
|
|
|
|
DObj->getStringSection(), isLittleEndian());
|
|
|
|
}
|
|
|
|
|
2018-01-22 21:17:23 +08:00
|
|
|
const AppleAcceleratorTable &DWARFContext::getAppleNames() {
|
2017-09-29 02:10:52 +08:00
|
|
|
return getAccelTable(AppleNames, *DObj, DObj->getAppleNamesSection(),
|
|
|
|
DObj->getStringSection(), isLittleEndian());
|
|
|
|
}
|
|
|
|
|
2018-01-22 21:17:23 +08:00
|
|
|
const AppleAcceleratorTable &DWARFContext::getAppleTypes() {
|
2017-09-29 08:33:22 +08:00
|
|
|
return getAccelTable(AppleTypes, *DObj, DObj->getAppleTypesSection(),
|
|
|
|
DObj->getStringSection(), isLittleEndian());
|
|
|
|
}
|
|
|
|
|
2018-01-22 21:17:23 +08:00
|
|
|
const AppleAcceleratorTable &DWARFContext::getAppleNamespaces() {
|
2017-09-29 08:52:33 +08:00
|
|
|
return getAccelTable(AppleNamespaces, *DObj,
|
|
|
|
DObj->getAppleNamespacesSection(),
|
|
|
|
DObj->getStringSection(), isLittleEndian());
|
|
|
|
}
|
|
|
|
|
2018-01-22 21:17:23 +08:00
|
|
|
const AppleAcceleratorTable &DWARFContext::getAppleObjC() {
|
2017-09-29 08:52:33 +08:00
|
|
|
return getAccelTable(AppleObjC, *DObj, DObj->getAppleObjCSection(),
|
|
|
|
DObj->getStringSection(), isLittleEndian());
|
|
|
|
}
|
|
|
|
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
const DWARFDebugLine::LineTable *
|
2015-05-20 05:54:32 +08:00
|
|
|
DWARFContext::getLineTableForUnit(DWARFUnit *U) {
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
Expected<const DWARFDebugLine::LineTable *> ExpectedLineTable =
|
2018-08-23 20:43:33 +08:00
|
|
|
getLineTableForUnit(U, dumpWarning);
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
if (!ExpectedLineTable) {
|
2018-08-23 20:43:33 +08:00
|
|
|
dumpWarning(ExpectedLineTable.takeError());
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return *ExpectedLineTable;
|
|
|
|
}
|
|
|
|
|
2018-05-21 23:30:54 +08:00
|
|
|
Expected<const DWARFDebugLine::LineTable *> DWARFContext::getLineTableForUnit(
|
|
|
|
DWARFUnit *U, std::function<void(Error)> RecoverableErrorCallback) {
|
2011-09-16 04:43:18 +08:00
|
|
|
if (!Line)
|
2017-06-30 00:52:08 +08:00
|
|
|
Line.reset(new DWARFDebugLine);
|
2015-11-18 05:08:05 +08:00
|
|
|
|
2016-12-14 02:25:19 +08:00
|
|
|
auto UnitDIE = U->getUnitDIE();
|
|
|
|
if (!UnitDIE)
|
2015-05-20 05:54:32 +08:00
|
|
|
return nullptr;
|
2015-11-18 05:08:05 +08:00
|
|
|
|
2017-01-14 05:08:18 +08:00
|
|
|
auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list));
|
2016-12-15 06:38:08 +08:00
|
|
|
if (!Offset)
|
2014-04-15 14:32:26 +08:00
|
|
|
return nullptr; // No line table for this compile unit.
|
2011-09-16 04:43:18 +08:00
|
|
|
|
2016-12-15 06:38:08 +08:00
|
|
|
uint32_t stmtOffset = *Offset + U->getLineTableOffset();
|
2011-09-16 04:43:18 +08:00
|
|
|
// See if the line table is cached.
|
2012-10-17 07:46:25 +08:00
|
|
|
if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset))
|
2011-09-16 04:43:18 +08:00
|
|
|
return lt;
|
|
|
|
|
2017-05-05 02:29:44 +08:00
|
|
|
// Make sure the offset is good before we try to parse.
|
2017-06-30 00:52:08 +08:00
|
|
|
if (stmtOffset >= U->getLineSection().Data.size())
|
2017-09-13 17:43:05 +08:00
|
|
|
return nullptr;
|
2017-05-05 02:29:44 +08:00
|
|
|
|
2011-09-16 04:43:18 +08:00
|
|
|
// We have to parse it first.
|
2017-07-20 06:27:28 +08:00
|
|
|
DWARFDataExtractor lineData(*DObj, U->getLineSection(), isLittleEndian(),
|
2017-06-30 00:52:08 +08:00
|
|
|
U->getAddressByteSize());
|
[DWARF] Rework debug line parsing to use llvm::Error and callbacks
Reviewed by: dblaikie, JDevlieghere, espindola
Differential Revision: https://reviews.llvm.org/D44560
Summary:
The .debug_line parser previously reported errors by printing to stderr and
return false. This is not particularly helpful for clients of the library code,
as it prevents them from handling the errors in a manner based on the calling
context. This change switches to using llvm::Error and callbacks to indicate
what problems were detected during parsing, and has updated clients to handle
the errors in a location-specific manner. In general, this means that they
continue to do the same thing to external users. Below, I have outlined what
the known behaviour changes are, relating to this change.
There are two levels of "errors" in the new error mechanism, to broadly
distinguish between different fail states of the parser, since not every
failure will prevent parsing of the unit, or of subsequent unit. Malformed
table errors that prevent reading the remainder of the table (reported by
returning them) and other minor issues representing problems with parsing that
do not prevent attempting to continue reading the table (reported by calling a
specified callback funciton). The only example of this currently is when the
last sequence of a unit is unterminated. However, I think it would be good to
change the handling of unrecognised opcodes to report as minor issues as well,
rather than just printing to the stream if --verbose is used (this would be a
subsequent change however).
I have substantially extended the DwarfGenerator to be able to handle
custom-crafted .debug_line sections, allowing for comprehensive unit-testing
of the parser code. For now, I am just adding unit tests to cover the basic
error reporting, and positive cases, and do not currently intend to test every
part of the parser, although the framework should be sufficient to do so at a
later point.
Known behaviour changes:
- The dump function in DWARFContext now does not attempt to read subsequent
tables when searching for a specific offset, if the unit length field of a
table before the specified offset is a reserved value.
- getOrParseLineTable now returns a useful Error if an invalid offset is
encountered, rather than simply a nullptr.
- The parse functions no longer use `WithColor::warning` directly to report
errors, allowing LLD to call its own warning function.
- The existing parse error messages have been updated to not specifically
include "warning" in their message, allowing consumers to determine what
severity the problem is.
- If the line table version field appears to have a value less than 2, an
informative error is returned, instead of just false.
- If the line table unit length field uses a reserved value, an informative
error is returned, instead of just false.
- Dumping of .debug_line.dwo sections is now implemented the same as regular
.debug_line sections.
- Verbose dumping of .debug_line[.dwo] sections now prints the prologue, if
there is a prologue error, just like non-verbose dumping.
As a helper for the generator code, I have re-added emitInt64 to the
AsmPrinter code. This previously existed, but was removed way back in r100296,
presumably because it was dead at the time.
This change also requires a change to LLD, which will be committed separately.
llvm-svn: 331971
2018-05-10 18:51:33 +08:00
|
|
|
return Line->getOrParseLineTable(lineData, stmtOffset, *this, U,
|
2018-05-21 23:30:54 +08:00
|
|
|
RecoverableErrorCallback);
|
2011-09-15 10:12:05 +08:00
|
|
|
}
|
|
|
|
|
2018-08-02 04:54:11 +08:00
|
|
|
void DWARFContext::parseNormalUnits() {
|
|
|
|
if (!NormalUnits.empty())
|
2014-03-13 15:52:54 +08:00
|
|
|
return;
|
2018-11-08 05:39:09 +08:00
|
|
|
DObj->forEachInfoSections([&](const DWARFSection &S) {
|
|
|
|
NormalUnits.addUnitsForSection(*this, S, DW_SECT_INFO);
|
|
|
|
});
|
2018-08-02 04:54:11 +08:00
|
|
|
NormalUnits.finishedInfoUnits();
|
2017-07-20 06:27:28 +08:00
|
|
|
DObj->forEachTypesSections([&](const DWARFSection &S) {
|
2018-08-02 04:54:11 +08:00
|
|
|
NormalUnits.addUnitsForSection(*this, S, DW_SECT_TYPES);
|
2017-07-13 05:08:24 +08:00
|
|
|
});
|
2013-09-24 06:44:47 +08:00
|
|
|
}
|
|
|
|
|
2018-08-02 04:54:11 +08:00
|
|
|
void DWARFContext::parseDWOUnits(bool Lazy) {
|
|
|
|
if (!DWOUnits.empty())
|
2014-03-13 15:52:54 +08:00
|
|
|
return;
|
2018-11-08 05:39:09 +08:00
|
|
|
DObj->forEachInfoDWOSections([&](const DWARFSection &S) {
|
|
|
|
DWOUnits.addUnitsForDWOSection(*this, S, DW_SECT_INFO, Lazy);
|
|
|
|
});
|
2018-08-02 04:54:11 +08:00
|
|
|
DWOUnits.finishedInfoUnits();
|
2017-07-20 06:27:28 +08:00
|
|
|
DObj->forEachTypesDWOSections([&](const DWARFSection &S) {
|
2018-08-02 04:54:11 +08:00
|
|
|
DWOUnits.addUnitsForDWOSection(*this, S, DW_SECT_TYPES, Lazy);
|
2017-07-13 05:08:24 +08:00
|
|
|
});
|
2014-01-09 13:08:24 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 15:49:50 +08:00
|
|
|
DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) {
|
2018-08-02 04:54:11 +08:00
|
|
|
parseNormalUnits();
|
|
|
|
return dyn_cast_or_null<DWARFCompileUnit>(
|
|
|
|
NormalUnits.getUnitForOffset(Offset));
|
2011-09-16 04:43:22 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 15:49:50 +08:00
|
|
|
DWARFCompileUnit *DWARFContext::getCompileUnitForAddress(uint64_t Address) {
|
2011-09-16 05:59:13 +08:00
|
|
|
// First, get the offset of the compile unit.
|
2012-08-30 15:49:50 +08:00
|
|
|
uint32_t CUOffset = getDebugAranges()->findAddress(Address);
|
2011-09-16 04:43:22 +08:00
|
|
|
// Retrieve the compile unit.
|
2012-08-30 15:49:50 +08:00
|
|
|
return getCompileUnitForOffset(CUOffset);
|
|
|
|
}
|
|
|
|
|
2017-10-26 05:56:41 +08:00
|
|
|
DWARFContext::DIEsForAddress DWARFContext::getDIEsForAddress(uint64_t Address) {
|
|
|
|
DIEsForAddress Result;
|
|
|
|
|
|
|
|
DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
|
|
|
|
if (!CU)
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
Result.CompileUnit = CU;
|
|
|
|
Result.FunctionDIE = CU->getSubroutineForAddress(Address);
|
|
|
|
|
|
|
|
std::vector<DWARFDie> Worklist;
|
|
|
|
Worklist.push_back(Result.FunctionDIE);
|
|
|
|
while (!Worklist.empty()) {
|
|
|
|
DWARFDie DIE = Worklist.back();
|
|
|
|
Worklist.pop_back();
|
|
|
|
|
2019-04-04 01:13:45 +08:00
|
|
|
if (!DIE.isValid())
|
|
|
|
continue;
|
|
|
|
|
2017-10-26 05:56:41 +08:00
|
|
|
if (DIE.getTag() == DW_TAG_lexical_block &&
|
|
|
|
DIE.addressRangeContainsAddress(Address)) {
|
|
|
|
Result.BlockDIE = DIE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto Child : DIE)
|
|
|
|
Worklist.push_back(Child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2019-02-27 21:17:36 +08:00
|
|
|
/// TODO: change input parameter from "uint64_t Address"
|
|
|
|
/// into "SectionedAddress Address"
|
2017-02-07 04:19:02 +08:00
|
|
|
static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU,
|
|
|
|
uint64_t Address,
|
|
|
|
FunctionNameKind Kind,
|
|
|
|
std::string &FunctionName,
|
|
|
|
uint32_t &StartLine) {
|
2014-04-19 05:36:39 +08:00
|
|
|
// The address may correspond to instruction in some inlined function,
|
|
|
|
// so we have to build the chain of inlined functions and take the
|
2017-02-07 04:19:02 +08:00
|
|
|
// name of the topmost function in it.
|
2016-12-14 02:25:19 +08:00
|
|
|
SmallVector<DWARFDie, 4> InlinedChain;
|
|
|
|
CU->getInlinedChainForAddress(Address, InlinedChain);
|
2017-02-07 04:19:02 +08:00
|
|
|
if (InlinedChain.empty())
|
2014-04-19 05:36:39 +08:00
|
|
|
return false;
|
2017-02-07 04:19:02 +08:00
|
|
|
|
|
|
|
const DWARFDie &DIE = InlinedChain[0];
|
|
|
|
bool FoundResult = false;
|
|
|
|
const char *Name = nullptr;
|
|
|
|
if (Kind != FunctionNameKind::None && (Name = DIE.getSubroutineName(Kind))) {
|
2014-04-19 05:36:39 +08:00
|
|
|
FunctionName = Name;
|
2017-02-07 04:19:02 +08:00
|
|
|
FoundResult = true;
|
2014-04-19 05:36:39 +08:00
|
|
|
}
|
2017-02-07 04:19:02 +08:00
|
|
|
if (auto DeclLineResult = DIE.getDeclLine()) {
|
|
|
|
StartLine = DeclLineResult;
|
|
|
|
FoundResult = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FoundResult;
|
2014-04-19 05:36:39 +08:00
|
|
|
}
|
|
|
|
|
2019-02-27 21:17:36 +08:00
|
|
|
DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
|
2014-05-16 05:24:32 +08:00
|
|
|
DILineInfoSpecifier Spec) {
|
2014-04-19 05:36:39 +08:00
|
|
|
DILineInfo Result;
|
|
|
|
|
2019-02-27 21:17:36 +08:00
|
|
|
DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address);
|
2012-08-30 15:49:50 +08:00
|
|
|
if (!CU)
|
2014-04-19 05:36:39 +08:00
|
|
|
return Result;
|
2019-02-27 21:17:36 +08:00
|
|
|
|
|
|
|
getFunctionNameAndStartLineForAddress(CU, Address.Address, Spec.FNKind,
|
|
|
|
Result.FunctionName, Result.StartLine);
|
2014-05-16 05:24:32 +08:00
|
|
|
if (Spec.FLIKind != FileLineInfoKind::None) {
|
2019-02-27 21:17:36 +08:00
|
|
|
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
|
|
|
|
LineTable->getFileLineInfoForAddress(
|
|
|
|
{Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
|
|
|
|
Spec.FLIKind, Result);
|
|
|
|
}
|
2012-08-30 15:49:50 +08:00
|
|
|
}
|
2014-04-19 05:36:39 +08:00
|
|
|
return Result;
|
2011-09-16 04:43:22 +08:00
|
|
|
}
|
2011-12-20 10:50:00 +08:00
|
|
|
|
2019-02-27 21:17:36 +08:00
|
|
|
DILineInfoTable DWARFContext::getLineInfoForAddressRange(
|
|
|
|
object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Spec) {
|
2013-01-26 08:28:05 +08:00
|
|
|
DILineInfoTable Lines;
|
2019-02-27 21:17:36 +08:00
|
|
|
DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address);
|
2013-01-26 08:28:05 +08:00
|
|
|
if (!CU)
|
|
|
|
return Lines;
|
|
|
|
|
|
|
|
std::string FunctionName = "<invalid>";
|
2017-02-07 04:19:02 +08:00
|
|
|
uint32_t StartLine = 0;
|
2019-02-27 21:17:36 +08:00
|
|
|
getFunctionNameAndStartLineForAddress(CU, Address.Address, Spec.FNKind,
|
|
|
|
FunctionName, StartLine);
|
2013-01-26 08:28:05 +08:00
|
|
|
|
|
|
|
// If the Specifier says we don't need FileLineInfo, just
|
|
|
|
// return the top-most function at the starting address.
|
2014-05-16 05:24:32 +08:00
|
|
|
if (Spec.FLIKind == FileLineInfoKind::None) {
|
2014-04-19 05:36:39 +08:00
|
|
|
DILineInfo Result;
|
|
|
|
Result.FunctionName = FunctionName;
|
2017-02-07 04:19:02 +08:00
|
|
|
Result.StartLine = StartLine;
|
2019-02-27 21:17:36 +08:00
|
|
|
Lines.push_back(std::make_pair(Address.Address, Result));
|
2013-01-26 08:28:05 +08:00
|
|
|
return Lines;
|
|
|
|
}
|
|
|
|
|
2014-09-04 14:14:40 +08:00
|
|
|
const DWARFLineTable *LineTable = getLineTableForUnit(CU);
|
2013-01-26 08:28:05 +08:00
|
|
|
|
|
|
|
// Get the index of row we're looking for in the line table.
|
|
|
|
std::vector<uint32_t> RowVector;
|
2019-02-27 21:17:36 +08:00
|
|
|
if (!LineTable->lookupAddressRange({Address.Address, Address.SectionIndex},
|
|
|
|
Size, RowVector)) {
|
2013-01-26 08:28:05 +08:00
|
|
|
return Lines;
|
2019-02-27 21:17:36 +08:00
|
|
|
}
|
2013-01-26 08:28:05 +08:00
|
|
|
|
2014-03-13 15:52:54 +08:00
|
|
|
for (uint32_t RowIndex : RowVector) {
|
2013-01-26 08:28:05 +08:00
|
|
|
// Take file number and line/column from the row.
|
|
|
|
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
|
2014-04-19 05:36:39 +08:00
|
|
|
DILineInfo Result;
|
2014-09-19 23:11:51 +08:00
|
|
|
LineTable->getFileNameByIndex(Row.File, CU->getCompilationDir(),
|
|
|
|
Spec.FLIKind, Result.FileName);
|
2014-04-19 05:36:39 +08:00
|
|
|
Result.FunctionName = FunctionName;
|
|
|
|
Result.Line = Row.Line;
|
|
|
|
Result.Column = Row.Column;
|
2017-02-07 04:19:02 +08:00
|
|
|
Result.StartLine = StartLine;
|
2019-02-27 21:17:36 +08:00
|
|
|
Lines.push_back(std::make_pair(Row.Address.Address, Result));
|
2013-01-26 08:28:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Lines;
|
|
|
|
}
|
|
|
|
|
2014-05-16 05:24:32 +08:00
|
|
|
DIInliningInfo
|
2019-02-27 21:17:36 +08:00
|
|
|
DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
|
2014-05-16 05:24:32 +08:00
|
|
|
DILineInfoSpecifier Spec) {
|
2014-04-19 06:22:44 +08:00
|
|
|
DIInliningInfo InliningInfo;
|
|
|
|
|
2019-02-27 21:17:36 +08:00
|
|
|
DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address);
|
2012-09-04 16:12:33 +08:00
|
|
|
if (!CU)
|
2014-04-19 06:22:44 +08:00
|
|
|
return InliningInfo;
|
2012-09-04 16:12:33 +08:00
|
|
|
|
2014-04-19 06:22:44 +08:00
|
|
|
const DWARFLineTable *LineTable = nullptr;
|
2016-12-14 02:25:19 +08:00
|
|
|
SmallVector<DWARFDie, 4> InlinedChain;
|
2019-02-27 21:17:36 +08:00
|
|
|
CU->getInlinedChainForAddress(Address.Address, InlinedChain);
|
2016-12-14 02:25:19 +08:00
|
|
|
if (InlinedChain.size() == 0) {
|
2014-04-19 06:22:44 +08:00
|
|
|
// If there is no DIE for address (e.g. it is in unavailable .dwo file),
|
|
|
|
// try to at least get file/line info from symbol table.
|
2014-05-16 05:24:32 +08:00
|
|
|
if (Spec.FLIKind != FileLineInfoKind::None) {
|
2014-04-19 06:22:44 +08:00
|
|
|
DILineInfo Frame;
|
2014-09-04 14:14:40 +08:00
|
|
|
LineTable = getLineTableForUnit(CU);
|
2019-02-27 21:17:36 +08:00
|
|
|
if (LineTable && LineTable->getFileLineInfoForAddress(
|
|
|
|
{Address.Address, Address.SectionIndex},
|
|
|
|
CU->getCompilationDir(), Spec.FLIKind, Frame))
|
2014-04-19 06:22:44 +08:00
|
|
|
InliningInfo.addFrame(Frame);
|
|
|
|
}
|
|
|
|
return InliningInfo;
|
|
|
|
}
|
2012-09-04 16:12:33 +08:00
|
|
|
|
2017-04-18 04:10:39 +08:00
|
|
|
uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
|
2016-12-14 02:25:19 +08:00
|
|
|
for (uint32_t i = 0, n = InlinedChain.size(); i != n; i++) {
|
|
|
|
DWARFDie &FunctionDIE = InlinedChain[i];
|
2014-04-19 05:36:39 +08:00
|
|
|
DILineInfo Frame;
|
2012-09-04 16:12:33 +08:00
|
|
|
// Get function name if necessary.
|
2016-12-14 02:25:19 +08:00
|
|
|
if (const char *Name = FunctionDIE.getSubroutineName(Spec.FNKind))
|
2014-05-16 05:24:32 +08:00
|
|
|
Frame.FunctionName = Name;
|
2017-02-07 04:19:02 +08:00
|
|
|
if (auto DeclLineResult = FunctionDIE.getDeclLine())
|
|
|
|
Frame.StartLine = DeclLineResult;
|
2014-05-16 05:24:32 +08:00
|
|
|
if (Spec.FLIKind != FileLineInfoKind::None) {
|
2012-09-04 16:12:33 +08:00
|
|
|
if (i == 0) {
|
|
|
|
// For the topmost frame, initialize the line table of this
|
|
|
|
// compile unit and fetch file/line info from it.
|
2014-09-04 14:14:40 +08:00
|
|
|
LineTable = getLineTableForUnit(CU);
|
2012-09-04 16:12:33 +08:00
|
|
|
// For the topmost routine, get file/line info from line table.
|
2014-09-19 23:11:51 +08:00
|
|
|
if (LineTable)
|
2019-02-27 21:17:36 +08:00
|
|
|
LineTable->getFileLineInfoForAddress(
|
|
|
|
{Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
|
|
|
|
Spec.FLIKind, Frame);
|
2012-09-04 16:12:33 +08:00
|
|
|
} else {
|
|
|
|
// Otherwise, use call file, call line and call column from
|
|
|
|
// previous DIE in inlined chain.
|
2014-09-19 23:11:51 +08:00
|
|
|
if (LineTable)
|
|
|
|
LineTable->getFileNameByIndex(CallFile, CU->getCompilationDir(),
|
|
|
|
Spec.FLIKind, Frame.FileName);
|
2014-04-19 05:36:39 +08:00
|
|
|
Frame.Line = CallLine;
|
|
|
|
Frame.Column = CallColumn;
|
2017-04-18 04:10:39 +08:00
|
|
|
Frame.Discriminator = CallDiscriminator;
|
2012-09-04 16:12:33 +08:00
|
|
|
}
|
|
|
|
// Get call file/line/column of a current DIE.
|
|
|
|
if (i + 1 < n) {
|
2017-04-18 04:10:39 +08:00
|
|
|
FunctionDIE.getCallerFrame(CallFile, CallLine, CallColumn,
|
|
|
|
CallDiscriminator);
|
2012-09-04 16:12:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
InliningInfo.addFrame(Frame);
|
|
|
|
}
|
|
|
|
return InliningInfo;
|
|
|
|
}
|
|
|
|
|
2017-05-23 08:30:42 +08:00
|
|
|
std::shared_ptr<DWARFContext>
|
|
|
|
DWARFContext::getDWOContext(StringRef AbsolutePath) {
|
2017-05-23 14:48:53 +08:00
|
|
|
if (auto S = DWP.lock()) {
|
2017-05-23 08:30:42 +08:00
|
|
|
DWARFContext *Ctxt = S->Context.get();
|
|
|
|
return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
|
|
|
|
}
|
|
|
|
|
2017-05-23 14:48:53 +08:00
|
|
|
std::weak_ptr<DWOFile> *Entry = &DWOFiles[AbsolutePath];
|
|
|
|
|
|
|
|
if (auto S = Entry->lock()) {
|
|
|
|
DWARFContext *Ctxt = S->Context.get();
|
|
|
|
return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<OwningBinary<ObjectFile>> Obj = [&] {
|
|
|
|
if (!CheckedForDWP) {
|
2017-07-30 09:34:08 +08:00
|
|
|
SmallString<128> DWPName;
|
|
|
|
auto Obj = object::ObjectFile::createObjectFile(
|
|
|
|
this->DWPName.empty()
|
|
|
|
? (DObj->getFileName() + ".dwp").toStringRef(DWPName)
|
|
|
|
: StringRef(this->DWPName));
|
2017-05-23 14:48:53 +08:00
|
|
|
if (Obj) {
|
|
|
|
Entry = &DWP;
|
|
|
|
return Obj;
|
|
|
|
} else {
|
|
|
|
CheckedForDWP = true;
|
|
|
|
// TODO: Should this error be handled (maybe in a high verbosity mode)
|
|
|
|
// before falling back to .dwo files?
|
|
|
|
consumeError(Obj.takeError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return object::ObjectFile::createObjectFile(AbsolutePath);
|
|
|
|
}();
|
|
|
|
|
2017-05-23 08:30:42 +08:00
|
|
|
if (!Obj) {
|
|
|
|
// TODO: Actually report errors helpfully.
|
|
|
|
consumeError(Obj.takeError());
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-05-23 14:48:53 +08:00
|
|
|
|
|
|
|
auto S = std::make_shared<DWOFile>();
|
2017-05-23 08:30:42 +08:00
|
|
|
S->File = std::move(Obj.get());
|
2017-07-20 06:27:28 +08:00
|
|
|
S->Context = DWARFContext::create(*S->File.getBinary());
|
2017-05-23 14:48:53 +08:00
|
|
|
*Entry = S;
|
2017-05-23 08:30:42 +08:00
|
|
|
auto *Ctxt = S->Context.get();
|
|
|
|
return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
|
|
|
|
}
|
|
|
|
|
2017-04-12 16:59:15 +08:00
|
|
|
static Error createError(const Twine &Reason, llvm::Error E) {
|
|
|
|
return make_error<StringError>(Reason + toString(std::move(E)),
|
|
|
|
inconvertibleErrorCode());
|
|
|
|
}
|
|
|
|
|
2017-05-28 02:10:23 +08:00
|
|
|
/// SymInfo contains information about symbol: it's address
|
|
|
|
/// and section index which is -1LL for absolute symbols.
|
|
|
|
struct SymInfo {
|
|
|
|
uint64_t Address;
|
|
|
|
uint64_t SectionIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Returns the address of symbol relocation used against and a section index.
|
|
|
|
/// Used for futher relocations computation. Symbol's section load address is
|
|
|
|
static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj,
|
|
|
|
const RelocationRef &Reloc,
|
|
|
|
const LoadedObjectInfo *L,
|
|
|
|
std::map<SymbolRef, SymInfo> &Cache) {
|
|
|
|
SymInfo Ret = {0, (uint64_t)-1LL};
|
2017-04-12 16:59:15 +08:00
|
|
|
object::section_iterator RSec = Obj.section_end();
|
|
|
|
object::symbol_iterator Sym = Reloc.getSymbol();
|
|
|
|
|
2017-05-28 02:10:23 +08:00
|
|
|
std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();
|
2017-04-12 16:59:15 +08:00
|
|
|
// First calculate the address of the symbol or section as it appears
|
|
|
|
// in the object file
|
|
|
|
if (Sym != Obj.symbol_end()) {
|
[DWARF] - Speedup handling of relocations in DWARFContextInMemory.
I am working on a speedup of building .gdb_index in LLD and
noticed that relocations that are proccessed in DWARFContextInMemory often uses
the same symbol in a row. This patch introduces caching to reduce the relocations
proccessing time.
For benchmark,
I took debug LLC binary objects configured with -ggnu-pubnames and linked it using LLD.
Link time without --gdb-index is about 4,45s.
Link time with --gdb-index: a) Without patch: 19,16s b) With patch: 15,52s
That means time spent on --gdb-index in this configuration is
19,16s - 4,45s = 14,71s (without patch) vs 15,52s - 4,45s = 11,07s (with patch).
Differential revision: https://reviews.llvm.org/D31136
llvm-svn: 303051
2017-05-15 19:45:28 +08:00
|
|
|
bool New;
|
2017-05-28 02:10:23 +08:00
|
|
|
std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}});
|
[DWARF] - Speedup handling of relocations in DWARFContextInMemory.
I am working on a speedup of building .gdb_index in LLD and
noticed that relocations that are proccessed in DWARFContextInMemory often uses
the same symbol in a row. This patch introduces caching to reduce the relocations
proccessing time.
For benchmark,
I took debug LLC binary objects configured with -ggnu-pubnames and linked it using LLD.
Link time without --gdb-index is about 4,45s.
Link time with --gdb-index: a) Without patch: 19,16s b) With patch: 15,52s
That means time spent on --gdb-index in this configuration is
19,16s - 4,45s = 14,71s (without patch) vs 15,52s - 4,45s = 11,07s (with patch).
Differential revision: https://reviews.llvm.org/D31136
llvm-svn: 303051
2017-05-15 19:45:28 +08:00
|
|
|
if (!New)
|
|
|
|
return CacheIt->second;
|
|
|
|
|
2017-04-12 16:59:15 +08:00
|
|
|
Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
|
|
|
|
if (!SymAddrOrErr)
|
2017-06-28 16:21:19 +08:00
|
|
|
return createError("failed to compute symbol address: ",
|
2017-04-12 16:59:15 +08:00
|
|
|
SymAddrOrErr.takeError());
|
|
|
|
|
|
|
|
// Also remember what section this symbol is in for later
|
|
|
|
auto SectOrErr = Sym->getSection();
|
|
|
|
if (!SectOrErr)
|
2017-06-28 16:21:19 +08:00
|
|
|
return createError("failed to get symbol section: ",
|
2017-04-12 16:59:15 +08:00
|
|
|
SectOrErr.takeError());
|
|
|
|
|
|
|
|
RSec = *SectOrErr;
|
2017-05-28 02:10:23 +08:00
|
|
|
Ret.Address = *SymAddrOrErr;
|
2017-04-12 16:59:15 +08:00
|
|
|
} else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
|
|
|
|
RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
|
2017-05-28 02:10:23 +08:00
|
|
|
Ret.Address = RSec->getAddress();
|
2017-04-12 16:59:15 +08:00
|
|
|
}
|
|
|
|
|
2017-05-28 02:10:23 +08:00
|
|
|
if (RSec != Obj.section_end())
|
|
|
|
Ret.SectionIndex = RSec->getIndex();
|
|
|
|
|
2017-04-12 16:59:15 +08:00
|
|
|
// If we are given load addresses for the sections, we need to adjust:
|
|
|
|
// SymAddr = (Address of Symbol Or Section in File) -
|
|
|
|
// (Address of Section in File) +
|
|
|
|
// (Load Address of Section)
|
|
|
|
// RSec is now either the section being targeted or the section
|
|
|
|
// containing the symbol being targeted. In either case,
|
|
|
|
// we need to perform the same computation.
|
|
|
|
if (L && RSec != Obj.section_end())
|
|
|
|
if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
|
2017-05-28 02:10:23 +08:00
|
|
|
Ret.Address += SectionLoadAddress - RSec->getAddress();
|
[DWARF] - Speedup handling of relocations in DWARFContextInMemory.
I am working on a speedup of building .gdb_index in LLD and
noticed that relocations that are proccessed in DWARFContextInMemory often uses
the same symbol in a row. This patch introduces caching to reduce the relocations
proccessing time.
For benchmark,
I took debug LLC binary objects configured with -ggnu-pubnames and linked it using LLD.
Link time without --gdb-index is about 4,45s.
Link time with --gdb-index: a) Without patch: 19,16s b) With patch: 15,52s
That means time spent on --gdb-index in this configuration is
19,16s - 4,45s = 14,71s (without patch) vs 15,52s - 4,45s = 11,07s (with patch).
Differential revision: https://reviews.llvm.org/D31136
llvm-svn: 303051
2017-05-15 19:45:28 +08:00
|
|
|
|
|
|
|
if (CacheIt != Cache.end())
|
|
|
|
CacheIt->second = Ret;
|
|
|
|
|
2017-04-12 16:59:15 +08:00
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isRelocScattered(const object::ObjectFile &Obj,
|
|
|
|
const RelocationRef &Reloc) {
|
2017-04-13 17:52:50 +08:00
|
|
|
const MachOObjectFile *MachObj = dyn_cast<MachOObjectFile>(&Obj);
|
|
|
|
if (!MachObj)
|
2017-04-12 16:59:15 +08:00
|
|
|
return false;
|
|
|
|
// MachO also has relocations that point to sections and
|
|
|
|
// scattered relocations.
|
|
|
|
auto RelocInfo = MachObj->getRelocation(Reloc.getRawDataRefImpl());
|
|
|
|
return MachObj->isRelocationScattered(RelocInfo);
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
ErrorPolicy DWARFContext::defaultErrorHandler(Error E) {
|
2018-04-15 06:07:23 +08:00
|
|
|
WithColor::error() << toString(std::move(E)) << '\n';
|
2017-07-20 06:27:28 +08:00
|
|
|
return ErrorPolicy::Continue;
|
|
|
|
}
|
2017-05-05 18:52:39 +08:00
|
|
|
|
2017-07-25 03:34:26 +08:00
|
|
|
namespace {
|
|
|
|
struct DWARFSectionMap final : public DWARFSection {
|
|
|
|
RelocAddrMap Relocs;
|
|
|
|
};
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
class DWARFObjInMemory final : public DWARFObject {
|
|
|
|
bool IsLittleEndian;
|
|
|
|
uint8_t AddressSize;
|
|
|
|
StringRef FileName;
|
2017-08-15 20:32:54 +08:00
|
|
|
const object::ObjectFile *Obj = nullptr;
|
2017-08-15 23:54:43 +08:00
|
|
|
std::vector<SectionName> SectionNames;
|
2017-07-20 06:27:28 +08:00
|
|
|
|
2018-11-08 05:39:09 +08:00
|
|
|
using InfoSectionMap = MapVector<object::SectionRef, DWARFSectionMap,
|
2017-07-20 06:27:28 +08:00
|
|
|
std::map<object::SectionRef, unsigned>>;
|
|
|
|
|
2018-11-08 05:39:09 +08:00
|
|
|
InfoSectionMap InfoSections;
|
|
|
|
InfoSectionMap TypesSections;
|
|
|
|
InfoSectionMap InfoDWOSections;
|
|
|
|
InfoSectionMap TypesDWOSections;
|
2017-07-20 06:27:28 +08:00
|
|
|
|
|
|
|
DWARFSectionMap LocSection;
|
2018-10-22 19:30:54 +08:00
|
|
|
DWARFSectionMap LocListsSection;
|
2017-07-20 06:27:28 +08:00
|
|
|
DWARFSectionMap LineSection;
|
|
|
|
DWARFSectionMap RangeSection;
|
2018-02-02 20:35:52 +08:00
|
|
|
DWARFSectionMap RnglistsSection;
|
2017-07-20 06:27:28 +08:00
|
|
|
DWARFSectionMap StringOffsetSection;
|
|
|
|
DWARFSectionMap LineDWOSection;
|
|
|
|
DWARFSectionMap LocDWOSection;
|
|
|
|
DWARFSectionMap StringOffsetDWOSection;
|
|
|
|
DWARFSectionMap RangeDWOSection;
|
2018-05-19 04:12:54 +08:00
|
|
|
DWARFSectionMap RnglistsDWOSection;
|
2017-07-20 06:27:28 +08:00
|
|
|
DWARFSectionMap AddrSection;
|
|
|
|
DWARFSectionMap AppleNamesSection;
|
|
|
|
DWARFSectionMap AppleTypesSection;
|
|
|
|
DWARFSectionMap AppleNamespacesSection;
|
|
|
|
DWARFSectionMap AppleObjCSection;
|
[DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.
Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).
I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).
In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.
Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42297
llvm-svn: 323638
2018-01-29 19:08:32 +08:00
|
|
|
DWARFSectionMap DebugNamesSection;
|
2018-11-12 02:57:28 +08:00
|
|
|
DWARFSectionMap PubNamesSection;
|
|
|
|
DWARFSectionMap PubTypesSection;
|
|
|
|
DWARFSectionMap GnuPubNamesSection;
|
|
|
|
DWARFSectionMap GnuPubTypesSection;
|
2017-07-20 06:27:28 +08:00
|
|
|
|
|
|
|
DWARFSectionMap *mapNameToDWARFSection(StringRef Name) {
|
|
|
|
return StringSwitch<DWARFSectionMap *>(Name)
|
|
|
|
.Case("debug_loc", &LocSection)
|
2018-10-22 19:30:54 +08:00
|
|
|
.Case("debug_loclists", &LocListsSection)
|
2017-07-20 06:27:28 +08:00
|
|
|
.Case("debug_line", &LineSection)
|
|
|
|
.Case("debug_str_offsets", &StringOffsetSection)
|
|
|
|
.Case("debug_ranges", &RangeSection)
|
2018-02-02 20:35:52 +08:00
|
|
|
.Case("debug_rnglists", &RnglistsSection)
|
2017-07-20 06:27:28 +08:00
|
|
|
.Case("debug_loc.dwo", &LocDWOSection)
|
|
|
|
.Case("debug_line.dwo", &LineDWOSection)
|
[DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.
Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).
I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).
In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.
Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42297
llvm-svn: 323638
2018-01-29 19:08:32 +08:00
|
|
|
.Case("debug_names", &DebugNamesSection)
|
2018-05-19 04:12:54 +08:00
|
|
|
.Case("debug_rnglists.dwo", &RnglistsDWOSection)
|
2017-07-20 06:27:28 +08:00
|
|
|
.Case("debug_str_offsets.dwo", &StringOffsetDWOSection)
|
|
|
|
.Case("debug_addr", &AddrSection)
|
|
|
|
.Case("apple_names", &AppleNamesSection)
|
2018-11-12 02:57:28 +08:00
|
|
|
.Case("debug_pubnames", &PubNamesSection)
|
|
|
|
.Case("debug_pubtypes", &PubTypesSection)
|
|
|
|
.Case("debug_gnu_pubnames", &GnuPubNamesSection)
|
|
|
|
.Case("debug_gnu_pubtypes", &GnuPubTypesSection)
|
2017-07-20 06:27:28 +08:00
|
|
|
.Case("apple_types", &AppleTypesSection)
|
|
|
|
.Case("apple_namespaces", &AppleNamespacesSection)
|
|
|
|
.Case("apple_namespac", &AppleNamespacesSection)
|
|
|
|
.Case("apple_objc", &AppleObjCSection)
|
|
|
|
.Default(nullptr);
|
|
|
|
}
|
2017-05-05 18:52:39 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
StringRef AbbrevSection;
|
|
|
|
StringRef ARangeSection;
|
|
|
|
StringRef DebugFrameSection;
|
|
|
|
StringRef EHFrameSection;
|
|
|
|
StringRef StringSection;
|
|
|
|
StringRef MacinfoSection;
|
|
|
|
StringRef AbbrevDWOSection;
|
|
|
|
StringRef StringDWOSection;
|
|
|
|
StringRef CUIndexSection;
|
|
|
|
StringRef GdbIndexSection;
|
|
|
|
StringRef TUIndexSection;
|
2018-01-26 06:02:36 +08:00
|
|
|
StringRef LineStringSection;
|
2017-07-20 06:27:28 +08:00
|
|
|
|
2018-07-24 07:27:45 +08:00
|
|
|
// A deque holding section data whose iterators are not invalidated when
|
|
|
|
// new decompressed sections are inserted at the end.
|
|
|
|
std::deque<SmallString<0>> UncompressedSections;
|
2017-07-20 06:27:28 +08:00
|
|
|
|
|
|
|
StringRef *mapSectionToMember(StringRef Name) {
|
|
|
|
if (DWARFSection *Sec = mapNameToDWARFSection(Name))
|
|
|
|
return &Sec->Data;
|
|
|
|
return StringSwitch<StringRef *>(Name)
|
|
|
|
.Case("debug_abbrev", &AbbrevSection)
|
|
|
|
.Case("debug_aranges", &ARangeSection)
|
|
|
|
.Case("debug_frame", &DebugFrameSection)
|
|
|
|
.Case("eh_frame", &EHFrameSection)
|
|
|
|
.Case("debug_str", &StringSection)
|
|
|
|
.Case("debug_macinfo", &MacinfoSection)
|
|
|
|
.Case("debug_abbrev.dwo", &AbbrevDWOSection)
|
|
|
|
.Case("debug_str.dwo", &StringDWOSection)
|
|
|
|
.Case("debug_cu_index", &CUIndexSection)
|
|
|
|
.Case("debug_tu_index", &TUIndexSection)
|
|
|
|
.Case("gdb_index", &GdbIndexSection)
|
2018-01-26 06:02:36 +08:00
|
|
|
.Case("debug_line_str", &LineStringSection)
|
2017-07-20 06:27:28 +08:00
|
|
|
// Any more debug info sections go here.
|
|
|
|
.Default(nullptr);
|
|
|
|
}
|
2017-05-05 18:52:39 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
/// If Sec is compressed section, decompresses and updates its contents
|
|
|
|
/// provided by Data. Otherwise leaves it unchanged.
|
|
|
|
Error maybeDecompress(const object::SectionRef &Sec, StringRef Name,
|
|
|
|
StringRef &Data) {
|
|
|
|
if (!Decompressor::isCompressed(Sec))
|
|
|
|
return Error::success();
|
2017-05-05 18:52:39 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
Expected<Decompressor> Decompressor =
|
|
|
|
Decompressor::create(Name, Data, IsLittleEndian, AddressSize == 8);
|
|
|
|
if (!Decompressor)
|
|
|
|
return Decompressor.takeError();
|
2017-05-05 18:52:39 +08:00
|
|
|
|
2018-07-24 07:27:45 +08:00
|
|
|
SmallString<0> Out;
|
2017-07-20 06:27:28 +08:00
|
|
|
if (auto Err = Decompressor->resizeAndDecompress(Out))
|
|
|
|
return Err;
|
2017-06-28 16:21:19 +08:00
|
|
|
|
2018-07-24 07:27:45 +08:00
|
|
|
UncompressedSections.push_back(std::move(Out));
|
2017-07-20 06:27:28 +08:00
|
|
|
Data = UncompressedSections.back();
|
2013-04-23 18:17:34 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
return Error::success();
|
|
|
|
}
|
2017-01-11 23:26:41 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
public:
|
|
|
|
DWARFObjInMemory(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
|
|
|
|
uint8_t AddrSize, bool IsLittleEndian)
|
|
|
|
: IsLittleEndian(IsLittleEndian) {
|
|
|
|
for (const auto &SecIt : Sections) {
|
|
|
|
if (StringRef *SectionData = mapSectionToMember(SecIt.first()))
|
|
|
|
*SectionData = SecIt.second->getBuffer();
|
2018-11-08 05:39:09 +08:00
|
|
|
else if (SecIt.first() == "debug_info")
|
|
|
|
// Find debug_info and debug_types data by section rather than name as
|
|
|
|
// there are multiple, comdat grouped, of these sections.
|
|
|
|
InfoSections[SectionRef()].Data = SecIt.second->getBuffer();
|
|
|
|
else if (SecIt.first() == "debug_info.dwo")
|
|
|
|
InfoDWOSections[SectionRef()].Data = SecIt.second->getBuffer();
|
|
|
|
else if (SecIt.first() == "debug_types")
|
|
|
|
TypesSections[SectionRef()].Data = SecIt.second->getBuffer();
|
|
|
|
else if (SecIt.first() == "debug_types.dwo")
|
|
|
|
TypesDWOSections[SectionRef()].Data = SecIt.second->getBuffer();
|
2017-07-20 06:27:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
|
|
|
|
function_ref<ErrorPolicy(Error)> HandleError)
|
|
|
|
: IsLittleEndian(Obj.isLittleEndian()),
|
2017-08-15 20:32:54 +08:00
|
|
|
AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()),
|
|
|
|
Obj(&Obj) {
|
2017-07-20 06:27:28 +08:00
|
|
|
|
2017-08-15 23:54:43 +08:00
|
|
|
StringMap<unsigned> SectionAmountMap;
|
2017-07-20 06:27:28 +08:00
|
|
|
for (const SectionRef &Section : Obj.sections()) {
|
|
|
|
StringRef Name;
|
|
|
|
Section.getName(Name);
|
2017-08-15 23:54:43 +08:00
|
|
|
++SectionAmountMap[Name];
|
|
|
|
SectionNames.push_back({ Name, true });
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
// Skip BSS and Virtual sections, they aren't interesting.
|
|
|
|
if (Section.isBSS() || Section.isVirtual())
|
|
|
|
continue;
|
2017-07-13 09:03:28 +08:00
|
|
|
|
2017-09-26 22:22:35 +08:00
|
|
|
// Skip sections stripped by dsymutil.
|
|
|
|
if (Section.isStripped())
|
|
|
|
continue;
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
StringRef Data;
|
|
|
|
section_iterator RelocatedSection = Section.getRelocatedSection();
|
|
|
|
// Try to obtain an already relocated version of this section.
|
|
|
|
// Else use the unrelocated section from the object file. We'll have to
|
|
|
|
// apply relocations ourselves later.
|
|
|
|
if (!L || !L->getLoadedSectionContents(*RelocatedSection, Data))
|
|
|
|
Section.getContents(Data);
|
|
|
|
|
|
|
|
if (auto Err = maybeDecompress(Section, Name, Data)) {
|
|
|
|
ErrorPolicy EP = HandleError(createError(
|
|
|
|
"failed to decompress '" + Name + "', ", std::move(Err)));
|
|
|
|
if (EP == ErrorPolicy::Halt)
|
|
|
|
return;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compressed sections names in GNU style starts from ".z",
|
|
|
|
// at this point section is decompressed and we drop compression prefix.
|
|
|
|
Name = Name.substr(
|
|
|
|
Name.find_first_not_of("._z")); // Skip ".", "z" and "_" prefixes.
|
|
|
|
|
|
|
|
// Map platform specific debug section names to DWARF standard section
|
|
|
|
// names.
|
|
|
|
Name = Obj.mapDebugSectionName(Name);
|
|
|
|
|
|
|
|
if (StringRef *SectionData = mapSectionToMember(Name)) {
|
|
|
|
*SectionData = Data;
|
|
|
|
if (Name == "debug_ranges") {
|
|
|
|
// FIXME: Use the other dwo range section when we emit it.
|
|
|
|
RangeDWOSection.Data = Data;
|
|
|
|
}
|
2018-11-08 05:39:09 +08:00
|
|
|
} else if (Name == "debug_info") {
|
|
|
|
// Find debug_info and debug_types data by section rather than name as
|
|
|
|
// there are multiple, comdat grouped, of these sections.
|
|
|
|
InfoSections[Section].Data = Data;
|
|
|
|
} else if (Name == "debug_info.dwo") {
|
|
|
|
InfoDWOSections[Section].Data = Data;
|
2017-07-20 06:27:28 +08:00
|
|
|
} else if (Name == "debug_types") {
|
|
|
|
TypesSections[Section].Data = Data;
|
|
|
|
} else if (Name == "debug_types.dwo") {
|
|
|
|
TypesDWOSections[Section].Data = Data;
|
2013-05-30 11:05:14 +08:00
|
|
|
}
|
2012-11-13 05:40:38 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
if (RelocatedSection == Obj.section_end())
|
2014-01-09 13:08:24 +08:00
|
|
|
continue;
|
2012-11-13 05:40:38 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
StringRef RelSecName;
|
|
|
|
StringRef RelSecData;
|
|
|
|
RelocatedSection->getName(RelSecName);
|
2017-05-17 20:10:51 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
// If the section we're relocating was relocated already by the JIT,
|
|
|
|
// then we used the relocated version above, so we do not need to process
|
|
|
|
// relocations for it now.
|
|
|
|
if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData))
|
2017-05-17 20:10:51 +08:00
|
|
|
continue;
|
2015-05-22 05:24:32 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
// In Mach-o files, the relocations do not need to be applied if
|
|
|
|
// there is no load offset to apply. The value read at the
|
|
|
|
// relocation point already factors in the section address
|
|
|
|
// (actually applying the relocations will produce wrong results
|
|
|
|
// as the section address will be added twice).
|
|
|
|
if (!L && isa<MachOObjectFile>(&Obj))
|
2017-05-17 20:10:51 +08:00
|
|
|
continue;
|
2017-07-20 06:27:28 +08:00
|
|
|
|
|
|
|
RelSecName = RelSecName.substr(
|
|
|
|
RelSecName.find_first_not_of("._z")); // Skip . and _ prefixes.
|
|
|
|
|
|
|
|
// TODO: Add support for relocations in other sections as needed.
|
|
|
|
// Record relocations for the debug_info and debug_line sections.
|
|
|
|
DWARFSectionMap *Sec = mapNameToDWARFSection(RelSecName);
|
|
|
|
RelocAddrMap *Map = Sec ? &Sec->Relocs : nullptr;
|
|
|
|
if (!Map) {
|
2018-11-08 05:39:09 +08:00
|
|
|
// Find debug_info and debug_types relocs by section rather than name
|
|
|
|
// as there are multiple, comdat grouped, of these sections.
|
|
|
|
if (RelSecName == "debug_info")
|
|
|
|
Map = &static_cast<DWARFSectionMap &>(InfoSections[*RelocatedSection])
|
|
|
|
.Relocs;
|
|
|
|
else if (RelSecName == "debug_info.dwo")
|
|
|
|
Map = &static_cast<DWARFSectionMap &>(
|
|
|
|
InfoDWOSections[*RelocatedSection])
|
|
|
|
.Relocs;
|
|
|
|
else if (RelSecName == "debug_types")
|
2017-07-20 06:27:28 +08:00
|
|
|
Map =
|
|
|
|
&static_cast<DWARFSectionMap &>(TypesSections[*RelocatedSection])
|
|
|
|
.Relocs;
|
|
|
|
else if (RelSecName == "debug_types.dwo")
|
|
|
|
Map = &static_cast<DWARFSectionMap &>(
|
|
|
|
TypesDWOSections[*RelocatedSection])
|
|
|
|
.Relocs;
|
|
|
|
else
|
|
|
|
continue;
|
2017-05-17 20:10:51 +08:00
|
|
|
}
|
2012-11-13 05:40:38 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
if (Section.relocation_begin() == Section.relocation_end())
|
2017-05-17 20:10:51 +08:00
|
|
|
continue;
|
2017-07-20 06:27:28 +08:00
|
|
|
|
|
|
|
// Symbol to [address, section index] cache mapping.
|
|
|
|
std::map<SymbolRef, SymInfo> AddrCache;
|
[DWARF] Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation entries
Summary:
getRelocatedValue may compute incorrect value for SHT_RELA-typed relocation entries.
// DWARFDataExtractor.cpp
uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint32_t *Off,
...
// This formula is correct for REL, but may be incorrect for RELA if the value
// stored in the location (getUnsigned(Off, Size)) is not zero.
return getUnsigned(Off, Size) + Rel->Value;
In this patch, we
* refactor these visit* functions to include a new parameter `uint64_t A`.
Since these visit* functions are no longer used as visitors, rename them to resolve*.
+ REL: A is used as the addend. A is the value stored in the location where the
relocation applies: getUnsigned(Off, Size)
+ RELA: The addend encoded in RelocationRef is used, e.g. getELFAddend(R)
* and add another set of supports* functions to check if a given relocation type is handled.
DWARFObjInMemory uses them to fail early.
Reviewers: echristo, dblaikie
Reviewed By: echristo
Subscribers: mgorny, aprantl, aheejin, fedor.sergeev, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D57939
llvm-svn: 356729
2019-03-22 10:43:11 +08:00
|
|
|
bool (*Supports)(uint64_t);
|
|
|
|
RelocationResolver Resolver;
|
|
|
|
std::tie(Supports, Resolver) = getRelocationResolver(Obj);
|
2017-07-20 06:27:28 +08:00
|
|
|
for (const RelocationRef &Reloc : Section.relocations()) {
|
|
|
|
// FIXME: it's not clear how to correctly handle scattered
|
|
|
|
// relocations.
|
|
|
|
if (isRelocScattered(Obj, Reloc))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Expected<SymInfo> SymInfoOrErr =
|
|
|
|
getSymbolInfo(Obj, Reloc, L, AddrCache);
|
|
|
|
if (!SymInfoOrErr) {
|
|
|
|
if (HandleError(SymInfoOrErr.takeError()) == ErrorPolicy::Halt)
|
|
|
|
return;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
[DWARF] Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation entries
Summary:
getRelocatedValue may compute incorrect value for SHT_RELA-typed relocation entries.
// DWARFDataExtractor.cpp
uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint32_t *Off,
...
// This formula is correct for REL, but may be incorrect for RELA if the value
// stored in the location (getUnsigned(Off, Size)) is not zero.
return getUnsigned(Off, Size) + Rel->Value;
In this patch, we
* refactor these visit* functions to include a new parameter `uint64_t A`.
Since these visit* functions are no longer used as visitors, rename them to resolve*.
+ REL: A is used as the addend. A is the value stored in the location where the
relocation applies: getUnsigned(Off, Size)
+ RELA: The addend encoded in RelocationRef is used, e.g. getELFAddend(R)
* and add another set of supports* functions to check if a given relocation type is handled.
DWARFObjInMemory uses them to fail early.
Reviewers: echristo, dblaikie
Reviewed By: echristo
Subscribers: mgorny, aprantl, aheejin, fedor.sergeev, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D57939
llvm-svn: 356729
2019-03-22 10:43:11 +08:00
|
|
|
// Check if Resolver can handle this relocation type early so as not to
|
|
|
|
// handle invalid cases in DWARFDataExtractor.
|
|
|
|
//
|
|
|
|
// TODO Don't store Resolver in every RelocAddrEntry.
|
|
|
|
if (Supports && Supports(Reloc.getType())) {
|
|
|
|
Map->try_emplace(Reloc.getOffset(),
|
|
|
|
RelocAddrEntry{SymInfoOrErr->SectionIndex, Reloc,
|
|
|
|
Resolver, SymInfoOrErr->Address});
|
|
|
|
} else {
|
2017-07-20 06:27:28 +08:00
|
|
|
SmallString<32> Type;
|
|
|
|
Reloc.getTypeName(Type);
|
|
|
|
ErrorPolicy EP = HandleError(
|
|
|
|
createError("failed to compute relocation: " + Type + ", ",
|
|
|
|
errorCodeToError(object_error::parse_failed)));
|
|
|
|
if (EP == ErrorPolicy::Halt)
|
|
|
|
return;
|
|
|
|
}
|
2012-11-13 05:40:38 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-15 23:54:43 +08:00
|
|
|
|
|
|
|
for (SectionName &S : SectionNames)
|
|
|
|
if (SectionAmountMap[S.Name] > 1)
|
|
|
|
S.IsNameUnique = false;
|
2012-11-13 05:40:38 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
Optional<RelocAddrEntry> find(const DWARFSection &S,
|
|
|
|
uint64_t Pos) const override {
|
|
|
|
auto &Sec = static_cast<const DWARFSectionMap &>(S);
|
|
|
|
RelocAddrMap::const_iterator AI = Sec.Relocs.find(Pos);
|
|
|
|
if (AI == Sec.Relocs.end())
|
|
|
|
return None;
|
|
|
|
return AI->second;
|
2017-01-21 03:03:14 +08:00
|
|
|
}
|
|
|
|
|
2017-08-15 20:32:54 +08:00
|
|
|
const object::ObjectFile *getFile() const override { return Obj; }
|
|
|
|
|
2017-08-15 23:54:43 +08:00
|
|
|
ArrayRef<SectionName> getSectionNames() const override {
|
|
|
|
return SectionNames;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
bool isLittleEndian() const override { return IsLittleEndian; }
|
|
|
|
StringRef getAbbrevDWOSection() const override { return AbbrevDWOSection; }
|
|
|
|
const DWARFSection &getLineDWOSection() const override {
|
|
|
|
return LineDWOSection;
|
|
|
|
}
|
|
|
|
const DWARFSection &getLocDWOSection() const override {
|
|
|
|
return LocDWOSection;
|
|
|
|
}
|
|
|
|
StringRef getStringDWOSection() const override { return StringDWOSection; }
|
|
|
|
const DWARFSection &getStringOffsetDWOSection() const override {
|
|
|
|
return StringOffsetDWOSection;
|
|
|
|
}
|
|
|
|
const DWARFSection &getRangeDWOSection() const override {
|
|
|
|
return RangeDWOSection;
|
|
|
|
}
|
2018-05-19 04:12:54 +08:00
|
|
|
const DWARFSection &getRnglistsDWOSection() const override {
|
|
|
|
return RnglistsDWOSection;
|
|
|
|
}
|
2017-07-20 06:27:28 +08:00
|
|
|
const DWARFSection &getAddrSection() const override { return AddrSection; }
|
|
|
|
StringRef getCUIndexSection() const override { return CUIndexSection; }
|
|
|
|
StringRef getGdbIndexSection() const override { return GdbIndexSection; }
|
|
|
|
StringRef getTUIndexSection() const override { return TUIndexSection; }
|
|
|
|
|
|
|
|
// DWARF v5
|
|
|
|
const DWARFSection &getStringOffsetSection() const override {
|
|
|
|
return StringOffsetSection;
|
|
|
|
}
|
2018-01-26 06:02:36 +08:00
|
|
|
StringRef getLineStringSection() const override { return LineStringSection; }
|
2017-07-20 06:27:28 +08:00
|
|
|
|
|
|
|
// Sections for DWARF5 split dwarf proposal.
|
2018-11-08 05:39:09 +08:00
|
|
|
void forEachInfoDWOSections(
|
|
|
|
function_ref<void(const DWARFSection &)> F) const override {
|
|
|
|
for (auto &P : InfoDWOSections)
|
|
|
|
F(P.second);
|
2017-07-20 06:27:28 +08:00
|
|
|
}
|
|
|
|
void forEachTypesDWOSections(
|
|
|
|
function_ref<void(const DWARFSection &)> F) const override {
|
|
|
|
for (auto &P : TypesDWOSections)
|
|
|
|
F(P.second);
|
|
|
|
}
|
2017-07-07 13:36:53 +08:00
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
StringRef getAbbrevSection() const override { return AbbrevSection; }
|
|
|
|
const DWARFSection &getLocSection() const override { return LocSection; }
|
2018-10-22 19:30:54 +08:00
|
|
|
const DWARFSection &getLoclistsSection() const override { return LocListsSection; }
|
2017-07-20 06:27:28 +08:00
|
|
|
StringRef getARangeSection() const override { return ARangeSection; }
|
|
|
|
StringRef getDebugFrameSection() const override { return DebugFrameSection; }
|
|
|
|
StringRef getEHFrameSection() const override { return EHFrameSection; }
|
|
|
|
const DWARFSection &getLineSection() const override { return LineSection; }
|
|
|
|
StringRef getStringSection() const override { return StringSection; }
|
|
|
|
const DWARFSection &getRangeSection() const override { return RangeSection; }
|
2018-02-02 20:35:52 +08:00
|
|
|
const DWARFSection &getRnglistsSection() const override {
|
|
|
|
return RnglistsSection;
|
|
|
|
}
|
2017-07-20 06:27:28 +08:00
|
|
|
StringRef getMacinfoSection() const override { return MacinfoSection; }
|
2018-11-12 02:57:28 +08:00
|
|
|
const DWARFSection &getPubNamesSection() const override { return PubNamesSection; }
|
|
|
|
const DWARFSection &getPubTypesSection() const override { return PubTypesSection; }
|
|
|
|
const DWARFSection &getGnuPubNamesSection() const override {
|
2017-07-20 06:27:28 +08:00
|
|
|
return GnuPubNamesSection;
|
|
|
|
}
|
2018-11-12 02:57:28 +08:00
|
|
|
const DWARFSection &getGnuPubTypesSection() const override {
|
2017-07-20 06:27:28 +08:00
|
|
|
return GnuPubTypesSection;
|
|
|
|
}
|
|
|
|
const DWARFSection &getAppleNamesSection() const override {
|
|
|
|
return AppleNamesSection;
|
|
|
|
}
|
|
|
|
const DWARFSection &getAppleTypesSection() const override {
|
|
|
|
return AppleTypesSection;
|
|
|
|
}
|
|
|
|
const DWARFSection &getAppleNamespacesSection() const override {
|
|
|
|
return AppleNamespacesSection;
|
|
|
|
}
|
|
|
|
const DWARFSection &getAppleObjCSection() const override {
|
|
|
|
return AppleObjCSection;
|
|
|
|
}
|
[DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.
Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).
I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).
In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.
Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42297
llvm-svn: 323638
2018-01-29 19:08:32 +08:00
|
|
|
const DWARFSection &getDebugNamesSection() const override {
|
|
|
|
return DebugNamesSection;
|
|
|
|
}
|
2017-07-20 06:27:28 +08:00
|
|
|
|
|
|
|
StringRef getFileName() const override { return FileName; }
|
|
|
|
uint8_t getAddressSize() const override { return AddressSize; }
|
2018-11-08 05:39:09 +08:00
|
|
|
void forEachInfoSections(
|
|
|
|
function_ref<void(const DWARFSection &)> F) const override {
|
|
|
|
for (auto &P : InfoSections)
|
|
|
|
F(P.second);
|
|
|
|
}
|
2017-07-20 06:27:28 +08:00
|
|
|
void forEachTypesSections(
|
|
|
|
function_ref<void(const DWARFSection &)> F) const override {
|
|
|
|
for (auto &P : TypesSections)
|
|
|
|
F(P.second);
|
|
|
|
}
|
|
|
|
};
|
2017-08-20 21:03:48 +08:00
|
|
|
} // namespace
|
2017-07-20 06:27:28 +08:00
|
|
|
|
|
|
|
std::unique_ptr<DWARFContext>
|
|
|
|
DWARFContext::create(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
|
2017-07-30 09:34:08 +08:00
|
|
|
function_ref<ErrorPolicy(Error)> HandleError,
|
|
|
|
std::string DWPName) {
|
2017-07-20 07:42:53 +08:00
|
|
|
auto DObj = llvm::make_unique<DWARFObjInMemory>(Obj, L, HandleError);
|
2018-11-24 01:13:06 +08:00
|
|
|
return llvm::make_unique<DWARFContext>(std::move(DObj), std::move(DWPName));
|
2017-01-21 03:03:14 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:27:28 +08:00
|
|
|
std::unique_ptr<DWARFContext>
|
|
|
|
DWARFContext::create(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
|
|
|
|
uint8_t AddrSize, bool isLittleEndian) {
|
2017-07-20 07:42:53 +08:00
|
|
|
auto DObj =
|
|
|
|
llvm::make_unique<DWARFObjInMemory>(Sections, AddrSize, isLittleEndian);
|
2017-07-30 09:34:08 +08:00
|
|
|
return llvm::make_unique<DWARFContext>(std::move(DObj), "");
|
2017-07-20 06:27:28 +08:00
|
|
|
}
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-30 05:41:21 +08:00
|
|
|
|
2018-11-24 01:13:06 +08:00
|
|
|
Error DWARFContext::loadRegisterInfo(const object::ObjectFile &Obj) {
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-30 05:41:21 +08:00
|
|
|
// Detect the architecture from the object file. We usually don't need OS
|
|
|
|
// info to lookup a target and create register info.
|
|
|
|
Triple TT;
|
|
|
|
TT.setArch(Triple::ArchType(Obj.getArch()));
|
|
|
|
TT.setVendor(Triple::UnknownVendor);
|
|
|
|
TT.setOS(Triple::UnknownOS);
|
|
|
|
std::string TargetLookupError;
|
|
|
|
const Target *TheTarget =
|
|
|
|
TargetRegistry::lookupTarget(TT.str(), TargetLookupError);
|
|
|
|
if (!TargetLookupError.empty())
|
[DWARF] Refactor DWARF classes to use unified error reporting. NFC.
DWARF-related classes in lib/DebugInfo/DWARF contained
duplicating code for creating StringError instances, like:
template <typename... Ts>
static Error createError(char const *Fmt, const Ts &... Vals) {
std::string Buffer;
raw_string_ostream Stream(Buffer);
Stream << format(Fmt, Vals...);
return make_error<StringError>(Stream.str(), inconvertibleErrorCode());
}
Similar function was placed in Support lib in https://reviews.llvm.org/D49824
This revision makes DWARF classes use this function
instead of their local implementation of it.
Reviewers: aprantl, dblaikie, probinson, wolfgangp, JDevlieghere, jhenderson
Reviewed By: JDevlieghere, jhenderson
Differential Revision: https://reviews.llvm.org/D49964
llvm-svn: 340163
2018-08-20 17:59:08 +08:00
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
TargetLookupError.c_str());
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-30 05:41:21 +08:00
|
|
|
RegInfo.reset(TheTarget->createMCRegInfo(TT.str()));
|
|
|
|
return Error::success();
|
|
|
|
}
|
2018-08-01 06:19:19 +08:00
|
|
|
|
|
|
|
uint8_t DWARFContext::getCUAddrSize() {
|
|
|
|
// In theory, different compile units may have different address byte
|
|
|
|
// sizes, but for simplicity we just use the address byte size of the
|
|
|
|
// last compile unit. In practice the address size field is repeated across
|
|
|
|
// various DWARF headers (at least in version 5) to make it easier to dump
|
|
|
|
// them independently, not to enable varying the address size.
|
|
|
|
uint8_t Addr = 0;
|
|
|
|
for (const auto &CU : compile_units()) {
|
|
|
|
Addr = CU->getAddressByteSize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Addr;
|
|
|
|
}
|
2018-08-23 20:43:33 +08:00
|
|
|
|
|
|
|
void DWARFContext::dumpWarning(Error Warning) {
|
|
|
|
handleAllErrors(std::move(Warning), [](ErrorInfoBase &Info) {
|
|
|
|
WithColor::warning() << Info.message() << '\n';
|
|
|
|
});
|
|
|
|
}
|