2016-12-07 22:47:28 +01:00
|
|
|
//===------ dwarf2yaml.cpp - obj2yaml conversion tool -----------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01: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
|
2016-12-07 22:47:28 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-06-13 16:04:51 +02:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2016-12-07 22:47:28 +01:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
2016-12-09 01:26:44 +01:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
|
2020-08-19 15:13:46 +02:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
|
2020-04-24 04:25:12 +02:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
|
2016-12-22 23:44:27 +01:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
|
2020-05-29 13:56:32 +02:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
|
2016-12-07 22:47:28 +01:00
|
|
|
#include "llvm/ObjectYAML/DWARFYAML.h"
|
|
|
|
|
2016-12-22 23:44:27 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
2016-12-07 22:47:28 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2017-07-20 00:27:28 +02:00
|
|
|
void dumpDebugAbbrev(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
2016-12-07 22:47:28 +01:00
|
|
|
auto AbbrevSetPtr = DCtx.getDebugAbbrev();
|
|
|
|
if (AbbrevSetPtr) {
|
2020-08-21 13:01:35 +02:00
|
|
|
uint64_t AbbrevTableID = 0;
|
2016-12-07 22:47:28 +01:00
|
|
|
for (auto AbbrvDeclSet : *AbbrevSetPtr) {
|
2020-08-21 04:11:33 +02:00
|
|
|
Y.DebugAbbrev.emplace_back();
|
2016-12-07 22:47:28 +01:00
|
|
|
for (auto AbbrvDecl : AbbrvDeclSet.second) {
|
2016-12-08 18:46:57 +01:00
|
|
|
DWARFYAML::Abbrev Abbrv;
|
2016-12-07 22:47:28 +01:00
|
|
|
Abbrv.Code = AbbrvDecl.getCode();
|
|
|
|
Abbrv.Tag = AbbrvDecl.getTag();
|
|
|
|
Abbrv.Children = AbbrvDecl.hasChildren() ? dwarf::DW_CHILDREN_yes
|
|
|
|
: dwarf::DW_CHILDREN_no;
|
|
|
|
for (auto Attribute : AbbrvDecl.attributes()) {
|
2016-12-08 18:46:57 +01:00
|
|
|
DWARFYAML::AttributeAbbrev AttAbrv;
|
2016-12-07 22:47:28 +01:00
|
|
|
AttAbrv.Attribute = Attribute.Attr;
|
|
|
|
AttAbrv.Form = Attribute.Form;
|
2017-03-07 00:22:49 +01:00
|
|
|
if (AttAbrv.Form == dwarf::DW_FORM_implicit_const)
|
2017-09-21 17:32:05 +02:00
|
|
|
AttAbrv.Value = Attribute.getImplicitConstValue();
|
2016-12-07 22:47:28 +01:00
|
|
|
Abbrv.Attributes.push_back(AttAbrv);
|
|
|
|
}
|
2020-08-21 13:01:35 +02:00
|
|
|
Y.DebugAbbrev.back().ID = AbbrevTableID++;
|
2020-08-21 04:11:33 +02:00
|
|
|
Y.DebugAbbrev.back().Table.push_back(Abbrv);
|
2016-12-07 22:47:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 10:08:42 +02:00
|
|
|
Error dumpDebugStrings(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
|
|
|
DataExtractor StrData = DCtx.getStringExtractor();
|
|
|
|
uint64_t Offset = 0;
|
|
|
|
std::vector<StringRef> DebugStr;
|
|
|
|
Error Err = Error::success();
|
|
|
|
while (StrData.isValidOffset(Offset)) {
|
|
|
|
const char *CStr = StrData.getCStr(&Offset, &Err);
|
|
|
|
if (Err)
|
|
|
|
return Err;
|
|
|
|
DebugStr.push_back(CStr);
|
2016-12-07 22:47:28 +01:00
|
|
|
}
|
2020-09-08 10:08:42 +02:00
|
|
|
|
|
|
|
Y.DebugStrings = DebugStr;
|
|
|
|
return Err;
|
2016-12-07 22:47:28 +01:00
|
|
|
}
|
|
|
|
|
2019-12-25 08:05:56 +01:00
|
|
|
Error dumpDebugARanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
2020-03-02 12:48:59 +01:00
|
|
|
DWARFDataExtractor ArangesData(DCtx.getDWARFObj().getArangesSection(),
|
|
|
|
DCtx.isLittleEndian(), 0);
|
2019-08-06 12:49:40 +02:00
|
|
|
uint64_t Offset = 0;
|
2016-12-09 01:26:44 +01:00
|
|
|
DWARFDebugArangeSet Set;
|
2020-07-31 06:56:10 +02:00
|
|
|
std::vector<DWARFYAML::ARange> DebugAranges;
|
2020-08-10 14:36:44 +02:00
|
|
|
|
|
|
|
// We ignore any errors that don't prevent parsing the section, since we can
|
|
|
|
// still represent such sections. These errors are recorded via the
|
|
|
|
// WarningHandler parameter of Set.extract().
|
|
|
|
auto DiscardError = [](Error Err) { consumeError(std::move(Err)); };
|
|
|
|
|
2019-12-25 08:05:56 +01:00
|
|
|
while (ArangesData.isValidOffset(Offset)) {
|
2020-08-10 14:36:44 +02:00
|
|
|
if (Error E = Set.extract(ArangesData, &Offset, DiscardError))
|
2019-12-25 08:05:56 +01:00
|
|
|
return E;
|
2016-12-09 01:26:44 +01:00
|
|
|
DWARFYAML::ARange Range;
|
2020-06-05 06:15:34 +02:00
|
|
|
Range.Format = Set.getHeader().Format;
|
|
|
|
Range.Length = Set.getHeader().Length;
|
2016-12-09 01:26:44 +01:00
|
|
|
Range.Version = Set.getHeader().Version;
|
|
|
|
Range.CuOffset = Set.getHeader().CuOffset;
|
|
|
|
Range.AddrSize = Set.getHeader().AddrSize;
|
|
|
|
Range.SegSize = Set.getHeader().SegSize;
|
|
|
|
for (auto Descriptor : Set.descriptors()) {
|
|
|
|
DWARFYAML::ARangeDescriptor Desc;
|
|
|
|
Desc.Address = Descriptor.Address;
|
|
|
|
Desc.Length = Descriptor.Length;
|
|
|
|
Range.Descriptors.push_back(Desc);
|
|
|
|
}
|
2020-07-31 06:56:10 +02:00
|
|
|
DebugAranges.push_back(Range);
|
2016-12-09 01:26:44 +01:00
|
|
|
}
|
2020-07-31 06:56:10 +02:00
|
|
|
|
|
|
|
Y.DebugAranges = DebugAranges;
|
2019-12-25 08:05:56 +01:00
|
|
|
return ErrorSuccess();
|
2016-12-09 01:26:44 +01:00
|
|
|
}
|
|
|
|
|
2020-04-24 04:25:12 +02:00
|
|
|
Error dumpDebugRanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
|
|
|
// We are assuming all address byte sizes will be consistent across all
|
|
|
|
// compile units.
|
|
|
|
uint8_t AddrSize = 0;
|
|
|
|
for (const auto &CU : DCtx.compile_units()) {
|
|
|
|
const uint8_t CUAddrSize = CU->getAddressByteSize();
|
|
|
|
if (AddrSize == 0)
|
|
|
|
AddrSize = CUAddrSize;
|
|
|
|
else if (CUAddrSize != AddrSize)
|
|
|
|
return createStringError(std::errc::invalid_argument,
|
|
|
|
"address sizes vary in different compile units");
|
|
|
|
}
|
|
|
|
|
|
|
|
DWARFDataExtractor Data(DCtx.getDWARFObj().getRangesSection().Data,
|
|
|
|
DCtx.isLittleEndian(), AddrSize);
|
|
|
|
uint64_t Offset = 0;
|
|
|
|
DWARFDebugRangeList DwarfRanges;
|
|
|
|
|
|
|
|
while (Data.isValidOffset(Offset)) {
|
|
|
|
DWARFYAML::Ranges YamlRanges;
|
|
|
|
YamlRanges.Offset = Offset;
|
|
|
|
YamlRanges.AddrSize = AddrSize;
|
|
|
|
if (Error E = DwarfRanges.extract(Data, &Offset))
|
|
|
|
return E;
|
|
|
|
for (const auto &RLE : DwarfRanges.getEntries())
|
|
|
|
YamlRanges.Entries.push_back({RLE.StartAddress, RLE.EndAddress});
|
2020-05-14 07:01:57 +02:00
|
|
|
Y.DebugRanges.push_back(std::move(YamlRanges));
|
2020-04-24 04:25:12 +02:00
|
|
|
}
|
|
|
|
return ErrorSuccess();
|
|
|
|
}
|
|
|
|
|
2020-08-19 15:13:46 +02:00
|
|
|
static Optional<DWARFYAML::PubSection>
|
|
|
|
dumpPubSection(const DWARFContext &DCtx, const DWARFSection &Section,
|
|
|
|
bool IsGNUStyle) {
|
|
|
|
DWARFYAML::PubSection Y;
|
2018-11-11 19:57:28 +01:00
|
|
|
DWARFDataExtractor PubSectionData(DCtx.getDWARFObj(), Section,
|
|
|
|
DCtx.isLittleEndian(), 0);
|
2020-08-19 15:13:46 +02:00
|
|
|
DWARFDebugPubTable Table;
|
|
|
|
// We ignore any errors that don't prevent parsing the section, since we can
|
|
|
|
// still represent such sections.
|
|
|
|
Table.extract(PubSectionData, IsGNUStyle,
|
|
|
|
[](Error Err) { consumeError(std::move(Err)); });
|
|
|
|
ArrayRef<DWARFDebugPubTable::Set> Sets = Table.getData();
|
|
|
|
if (Sets.empty())
|
|
|
|
return None;
|
|
|
|
|
|
|
|
// FIXME: Currently, obj2yaml only supports dumping the first pubtable.
|
|
|
|
Y.Format = Sets[0].Format;
|
|
|
|
Y.Length = Sets[0].Length;
|
|
|
|
Y.Version = Sets[0].Version;
|
|
|
|
Y.UnitOffset = Sets[0].Offset;
|
|
|
|
Y.UnitSize = Sets[0].Size;
|
|
|
|
|
|
|
|
for (const DWARFDebugPubTable::Entry &E : Sets[0].Entries)
|
2020-08-19 15:41:40 +02:00
|
|
|
Y.Entries.push_back(DWARFYAML::PubEntry{(uint32_t)E.SecOffset,
|
|
|
|
E.Descriptor.toBits(), E.Name});
|
2020-06-02 08:38:15 +02:00
|
|
|
|
|
|
|
return Y;
|
2016-12-19 23:22:12 +01:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:27:28 +02:00
|
|
|
void dumpDebugPubSections(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
|
|
|
const DWARFObject &D = DCtx.getDWARFObj();
|
2016-12-19 23:22:12 +01:00
|
|
|
|
2020-08-19 15:13:46 +02:00
|
|
|
Y.PubNames =
|
|
|
|
dumpPubSection(DCtx, D.getPubnamesSection(), /*IsGNUStyle=*/false);
|
|
|
|
Y.PubTypes =
|
|
|
|
dumpPubSection(DCtx, D.getPubtypesSection(), /*IsGNUStyle=*/false);
|
|
|
|
// TODO: Test dumping .debug_gnu_pubnames section.
|
|
|
|
Y.GNUPubNames =
|
|
|
|
dumpPubSection(DCtx, D.getGnuPubnamesSection(), /*IsGNUStyle=*/true);
|
|
|
|
// TODO: Test dumping .debug_gnu_pubtypes section.
|
|
|
|
Y.GNUPubTypes =
|
|
|
|
dumpPubSection(DCtx, D.getGnuPubtypesSection(), /*IsGNUStyle=*/true);
|
2016-12-19 23:22:12 +01:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:27:28 +02:00
|
|
|
void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
2016-12-22 23:44:27 +01:00
|
|
|
for (const auto &CU : DCtx.compile_units()) {
|
|
|
|
DWARFYAML::Unit NewUnit;
|
2020-08-06 10:37:52 +02:00
|
|
|
NewUnit.Format = CU->getFormat();
|
2020-06-30 09:07:45 +02:00
|
|
|
NewUnit.Length = CU->getLength();
|
2020-08-06 10:37:52 +02:00
|
|
|
NewUnit.Version = CU->getVersion();
|
|
|
|
if (NewUnit.Version >= 5)
|
2017-03-07 19:50:58 +01:00
|
|
|
NewUnit.Type = (dwarf::UnitType)CU->getUnitType();
|
2020-08-21 13:01:35 +02:00
|
|
|
const DWARFDebugAbbrev *DebugAbbrev = DCtx.getDebugAbbrev();
|
|
|
|
NewUnit.AbbrevTableID = std::distance(
|
|
|
|
DebugAbbrev->begin(),
|
|
|
|
std::find_if(
|
|
|
|
DebugAbbrev->begin(), DebugAbbrev->end(),
|
|
|
|
[&](const std::pair<uint64_t, DWARFAbbreviationDeclarationSet> &P) {
|
|
|
|
return P.first == CU->getAbbreviations()->getOffset();
|
|
|
|
}));
|
2016-12-22 23:44:27 +01:00
|
|
|
NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
|
2020-08-06 10:37:52 +02:00
|
|
|
NewUnit.AddrSize = CU->getAddressByteSize();
|
2016-12-22 23:44:27 +01:00
|
|
|
for (auto DIE : CU->dies()) {
|
|
|
|
DWARFYAML::Entry NewEntry;
|
|
|
|
DataExtractor EntryData = CU->getDebugInfoExtractor();
|
2019-08-06 12:49:40 +02:00
|
|
|
uint64_t offset = DIE.getOffset();
|
2016-12-22 23:44:27 +01:00
|
|
|
|
|
|
|
assert(EntryData.isValidOffset(offset) && "Invalid DIE Offset");
|
|
|
|
if (!EntryData.isValidOffset(offset))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
NewEntry.AbbrCode = EntryData.getULEB128(&offset);
|
|
|
|
|
|
|
|
auto AbbrevDecl = DIE.getAbbreviationDeclarationPtr();
|
|
|
|
if (AbbrevDecl) {
|
|
|
|
for (const auto &AttrSpec : AbbrevDecl->attributes()) {
|
|
|
|
DWARFYAML::FormValue NewValue;
|
|
|
|
NewValue.Value = 0xDEADBEEFDEADBEEF;
|
|
|
|
DWARFDie DIEWrapper(CU.get(), &DIE);
|
2017-01-13 22:08:18 +01:00
|
|
|
auto FormValue = DIEWrapper.find(AttrSpec.Attr);
|
2017-01-10 07:22:49 +01:00
|
|
|
if (!FormValue)
|
2016-12-22 23:44:27 +01:00
|
|
|
return;
|
|
|
|
auto Form = FormValue.getValue().getForm();
|
|
|
|
bool indirect = false;
|
|
|
|
do {
|
|
|
|
indirect = false;
|
|
|
|
switch (Form) {
|
|
|
|
case dwarf::DW_FORM_addr:
|
|
|
|
case dwarf::DW_FORM_GNU_addr_index:
|
|
|
|
if (auto Val = FormValue.getValue().getAsAddress())
|
|
|
|
NewValue.Value = Val.getValue();
|
|
|
|
break;
|
|
|
|
case dwarf::DW_FORM_ref_addr:
|
|
|
|
case dwarf::DW_FORM_ref1:
|
|
|
|
case dwarf::DW_FORM_ref2:
|
|
|
|
case dwarf::DW_FORM_ref4:
|
|
|
|
case dwarf::DW_FORM_ref8:
|
|
|
|
case dwarf::DW_FORM_ref_udata:
|
|
|
|
case dwarf::DW_FORM_ref_sig8:
|
|
|
|
if (auto Val = FormValue.getValue().getAsReferenceUVal())
|
|
|
|
NewValue.Value = Val.getValue();
|
|
|
|
break;
|
|
|
|
case dwarf::DW_FORM_exprloc:
|
|
|
|
case dwarf::DW_FORM_block:
|
|
|
|
case dwarf::DW_FORM_block1:
|
|
|
|
case dwarf::DW_FORM_block2:
|
|
|
|
case dwarf::DW_FORM_block4:
|
|
|
|
if (auto Val = FormValue.getValue().getAsBlock()) {
|
|
|
|
auto BlockData = Val.getValue();
|
|
|
|
std::copy(BlockData.begin(), BlockData.end(),
|
|
|
|
std::back_inserter(NewValue.BlockData));
|
|
|
|
}
|
|
|
|
NewValue.Value = NewValue.BlockData.size();
|
|
|
|
break;
|
|
|
|
case dwarf::DW_FORM_data1:
|
|
|
|
case dwarf::DW_FORM_flag:
|
|
|
|
case dwarf::DW_FORM_data2:
|
|
|
|
case dwarf::DW_FORM_data4:
|
|
|
|
case dwarf::DW_FORM_data8:
|
|
|
|
case dwarf::DW_FORM_sdata:
|
|
|
|
case dwarf::DW_FORM_udata:
|
2017-03-06 23:20:03 +01:00
|
|
|
case dwarf::DW_FORM_ref_sup4:
|
|
|
|
case dwarf::DW_FORM_ref_sup8:
|
2016-12-22 23:44:27 +01:00
|
|
|
if (auto Val = FormValue.getValue().getAsUnsignedConstant())
|
|
|
|
NewValue.Value = Val.getValue();
|
|
|
|
break;
|
|
|
|
case dwarf::DW_FORM_string:
|
|
|
|
if (auto Val = FormValue.getValue().getAsCString())
|
|
|
|
NewValue.CStr = Val.getValue();
|
|
|
|
break;
|
|
|
|
case dwarf::DW_FORM_indirect:
|
|
|
|
indirect = true;
|
|
|
|
if (auto Val = FormValue.getValue().getAsUnsignedConstant()) {
|
|
|
|
NewValue.Value = Val.getValue();
|
|
|
|
NewEntry.Values.push_back(NewValue);
|
|
|
|
Form = static_cast<dwarf::Form>(Val.getValue());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_FORM_strp:
|
|
|
|
case dwarf::DW_FORM_sec_offset:
|
|
|
|
case dwarf::DW_FORM_GNU_ref_alt:
|
|
|
|
case dwarf::DW_FORM_GNU_strp_alt:
|
|
|
|
case dwarf::DW_FORM_line_strp:
|
|
|
|
case dwarf::DW_FORM_strp_sup:
|
|
|
|
case dwarf::DW_FORM_GNU_str_index:
|
2017-06-06 03:22:34 +02:00
|
|
|
case dwarf::DW_FORM_strx:
|
2016-12-22 23:44:27 +01:00
|
|
|
if (auto Val = FormValue.getValue().getAsCStringOffset())
|
|
|
|
NewValue.Value = Val.getValue();
|
|
|
|
break;
|
|
|
|
case dwarf::DW_FORM_flag_present:
|
|
|
|
NewValue.Value = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (indirect);
|
|
|
|
NewEntry.Values.push_back(NewValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NewUnit.Entries.push_back(NewEntry);
|
|
|
|
}
|
|
|
|
Y.CompileUnits.push_back(NewUnit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 12:49:40 +02:00
|
|
|
bool dumpFileEntry(DataExtractor &Data, uint64_t &Offset,
|
2017-01-10 07:22:49 +01:00
|
|
|
DWARFYAML::File &File) {
|
|
|
|
File.Name = Data.getCStr(&Offset);
|
|
|
|
if (File.Name.empty())
|
|
|
|
return false;
|
|
|
|
File.DirIdx = Data.getULEB128(&Offset);
|
|
|
|
File.ModTime = Data.getULEB128(&Offset);
|
|
|
|
File.Length = Data.getULEB128(&Offset);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-20 00:27:28 +02:00
|
|
|
void dumpDebugLines(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
2017-01-10 07:22:49 +01:00
|
|
|
for (const auto &CU : DCtx.compile_units()) {
|
|
|
|
auto CUDIE = CU->getUnitDIE();
|
|
|
|
if (!CUDIE)
|
|
|
|
continue;
|
|
|
|
if (auto StmtOffset =
|
2017-01-13 22:08:18 +01:00
|
|
|
dwarf::toSectionOffset(CUDIE.find(dwarf::DW_AT_stmt_list))) {
|
2017-01-10 07:22:49 +01:00
|
|
|
DWARFYAML::LineTable DebugLines;
|
2017-07-20 00:27:28 +02:00
|
|
|
DataExtractor LineData(DCtx.getDWARFObj().getLineSection().Data,
|
|
|
|
DCtx.isLittleEndian(), CU->getAddressByteSize());
|
2019-08-06 12:49:40 +02:00
|
|
|
uint64_t Offset = *StmtOffset;
|
2020-06-13 16:04:51 +02:00
|
|
|
uint64_t LengthOrDWARF64Prefix = LineData.getU32(&Offset);
|
|
|
|
if (LengthOrDWARF64Prefix == dwarf::DW_LENGTH_DWARF64) {
|
|
|
|
DebugLines.Format = dwarf::DWARF64;
|
|
|
|
DebugLines.Length = LineData.getU64(&Offset);
|
|
|
|
} else {
|
|
|
|
DebugLines.Format = dwarf::DWARF32;
|
|
|
|
DebugLines.Length = LengthOrDWARF64Prefix;
|
|
|
|
}
|
2020-08-26 14:34:36 +02:00
|
|
|
assert(DebugLines.Length);
|
|
|
|
uint64_t LineTableLength = *DebugLines.Length;
|
2020-06-13 16:04:51 +02:00
|
|
|
uint64_t SizeOfPrologueLength =
|
|
|
|
DebugLines.Format == dwarf::DWARF64 ? 8 : 4;
|
2017-01-10 07:22:49 +01:00
|
|
|
DebugLines.Version = LineData.getU16(&Offset);
|
|
|
|
DebugLines.PrologueLength =
|
|
|
|
LineData.getUnsigned(&Offset, SizeOfPrologueLength);
|
2020-08-26 14:34:36 +02:00
|
|
|
assert(DebugLines.PrologueLength);
|
|
|
|
const uint64_t EndPrologue = *DebugLines.PrologueLength + Offset;
|
2017-01-10 07:22:49 +01:00
|
|
|
|
|
|
|
DebugLines.MinInstLength = LineData.getU8(&Offset);
|
|
|
|
if (DebugLines.Version >= 4)
|
|
|
|
DebugLines.MaxOpsPerInst = LineData.getU8(&Offset);
|
|
|
|
DebugLines.DefaultIsStmt = LineData.getU8(&Offset);
|
|
|
|
DebugLines.LineBase = LineData.getU8(&Offset);
|
|
|
|
DebugLines.LineRange = LineData.getU8(&Offset);
|
|
|
|
DebugLines.OpcodeBase = LineData.getU8(&Offset);
|
|
|
|
|
|
|
|
DebugLines.StandardOpcodeLengths.reserve(DebugLines.OpcodeBase - 1);
|
|
|
|
for (uint8_t i = 1; i < DebugLines.OpcodeBase; ++i)
|
|
|
|
DebugLines.StandardOpcodeLengths.push_back(LineData.getU8(&Offset));
|
|
|
|
|
|
|
|
while (Offset < EndPrologue) {
|
|
|
|
StringRef Dir = LineData.getCStr(&Offset);
|
|
|
|
if (!Dir.empty())
|
|
|
|
DebugLines.IncludeDirs.push_back(Dir);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (Offset < EndPrologue) {
|
|
|
|
DWARFYAML::File TmpFile;
|
|
|
|
if (dumpFileEntry(LineData, Offset, TmpFile))
|
|
|
|
DebugLines.Files.push_back(TmpFile);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t LineEnd =
|
|
|
|
LineTableLength + *StmtOffset + SizeOfPrologueLength;
|
|
|
|
while (Offset < LineEnd) {
|
2019-08-29 04:36:48 +02:00
|
|
|
DWARFYAML::LineTableOpcode NewOp = {};
|
2017-01-10 07:22:49 +01:00
|
|
|
NewOp.Opcode = (dwarf::LineNumberOps)LineData.getU8(&Offset);
|
|
|
|
if (NewOp.Opcode == 0) {
|
|
|
|
auto StartExt = Offset;
|
|
|
|
NewOp.ExtLen = LineData.getULEB128(&Offset);
|
|
|
|
NewOp.SubOpcode =
|
|
|
|
(dwarf::LineNumberExtendedOps)LineData.getU8(&Offset);
|
|
|
|
switch (NewOp.SubOpcode) {
|
|
|
|
case dwarf::DW_LNE_set_address:
|
|
|
|
case dwarf::DW_LNE_set_discriminator:
|
|
|
|
NewOp.Data = LineData.getAddress(&Offset);
|
|
|
|
break;
|
|
|
|
case dwarf::DW_LNE_define_file:
|
|
|
|
dumpFileEntry(LineData, Offset, NewOp.FileEntry);
|
|
|
|
break;
|
|
|
|
case dwarf::DW_LNE_end_sequence:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
while (Offset < StartExt + NewOp.ExtLen)
|
|
|
|
NewOp.UnknownOpcodeData.push_back(LineData.getU8(&Offset));
|
|
|
|
}
|
|
|
|
} else if (NewOp.Opcode < DebugLines.OpcodeBase) {
|
|
|
|
switch (NewOp.Opcode) {
|
|
|
|
case dwarf::DW_LNS_copy:
|
|
|
|
case dwarf::DW_LNS_negate_stmt:
|
|
|
|
case dwarf::DW_LNS_set_basic_block:
|
|
|
|
case dwarf::DW_LNS_const_add_pc:
|
|
|
|
case dwarf::DW_LNS_set_prologue_end:
|
|
|
|
case dwarf::DW_LNS_set_epilogue_begin:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dwarf::DW_LNS_advance_pc:
|
|
|
|
case dwarf::DW_LNS_set_file:
|
|
|
|
case dwarf::DW_LNS_set_column:
|
|
|
|
case dwarf::DW_LNS_set_isa:
|
|
|
|
NewOp.Data = LineData.getULEB128(&Offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dwarf::DW_LNS_advance_line:
|
|
|
|
NewOp.SData = LineData.getSLEB128(&Offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dwarf::DW_LNS_fixed_advance_pc:
|
|
|
|
NewOp.Data = LineData.getU16(&Offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
for (uint8_t i = 0;
|
|
|
|
i < DebugLines.StandardOpcodeLengths[NewOp.Opcode - 1]; ++i)
|
|
|
|
NewOp.StandardOpcodeData.push_back(LineData.getULEB128(&Offset));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DebugLines.Opcodes.push_back(NewOp);
|
|
|
|
}
|
|
|
|
Y.DebugLines.push_back(DebugLines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|