[llvm] r323691 - [DWARFv5] Re-enable dumping a line table with no CU.
Paul Robinson via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 29 12:57:43 PST 2018
Author: probinson
Date: Mon Jan 29 12:57:43 2018
New Revision: 323691
URL: http://llvm.org/viewvc/llvm-project?rev=323691&view=rev
Log:
[DWARFv5] Re-enable dumping a line table with no CU.
r323476 added support for DW_FORM_line_strp, and incorrectly made that
depend on having a DWARFUnit available. We shouldn't be tracking
.debug_line_str in DWARFUnit after all. After this patch, I can do an
NFC follow up and undo a bunch of the "plumbing" part of r323476.
Differential Revision: https://reviews.llvm.org/D42609
Modified:
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
llvm/trunk/test/DebugInfo/X86/dwarfdump-line-only.s
llvm/trunk/tools/dsymutil/DwarfLinker.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=323691&r1=323690&r2=323691&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h Mon Jan 29 12:57:43 2018
@@ -34,6 +34,7 @@
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Host.h"
#include <cstdint>
@@ -43,7 +44,6 @@
namespace llvm {
-class DataExtractor;
class MCRegisterInfo;
class MemoryBuffer;
class raw_ostream;
@@ -261,6 +261,13 @@ public:
/// Get a pointer to a parsed line table corresponding to a compile unit.
const DWARFDebugLine::LineTable *getLineTableForUnit(DWARFUnit *cu);
+ DataExtractor getStringExtractor() const {
+ return DataExtractor(DObj->getStringSection(), false, 0);
+ }
+ DataExtractor getLineStringExtractor() const {
+ return DataExtractor(DObj->getLineStringSection(), false, 0);
+ }
+
/// Wraps the returned DIEs for a given address.
struct DIEsForAddress {
DWARFCompileUnit *CompileUnit = nullptr;
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h?rev=323691&r1=323690&r2=323691&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h Mon Jan 29 12:57:43 2018
@@ -101,7 +101,7 @@ public:
void clear();
void dump(raw_ostream &OS) const;
bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
- const DWARFUnit *U = nullptr);
+ const DWARFContext &Ctx, const DWARFUnit *U = nullptr);
};
/// Standard .debug_line state machine structure.
@@ -224,7 +224,8 @@ public:
/// Parse prologue and all rows.
bool parse(DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
- const DWARFUnit *U, raw_ostream *OS = nullptr);
+ const DWARFContext &Ctx, const DWARFUnit *U,
+ raw_ostream *OS = nullptr);
using RowVector = std::vector<Row>;
using RowIter = RowVector::const_iterator;
@@ -242,7 +243,8 @@ public:
const LineTable *getLineTable(uint32_t Offset) const;
const LineTable *getOrParseLineTable(DWARFDataExtractor &DebugLineData,
- uint32_t Offset, const DWARFUnit *U);
+ uint32_t Offset, const DWARFContext &C,
+ const DWARFUnit *U);
private:
struct ParsingState {
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h?rev=323691&r1=323690&r2=323691&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h Mon Jan 29 12:57:43 2018
@@ -20,6 +20,7 @@
namespace llvm {
+class DWARFContext;
class DWARFUnit;
class raw_ostream;
@@ -85,7 +86,7 @@ private:
dwarf::Form Form; /// Form for this value.
ValueType Value; /// Contains all data for the form.
const DWARFUnit *U = nullptr; /// Remember the DWARFUnit at extract time.
-
+ const DWARFContext *C = nullptr; /// Context for extract time.
public:
DWARFFormValue(dwarf::Form F = dwarf::Form(0)) : Form(F) {}
@@ -108,10 +109,17 @@ public:
/// Extracts a value in \p Data at offset \p *OffsetPtr. The information
/// in \p FormParams is needed to interpret some forms. The optional
- /// \p Unit allows extracting information if the form refers to other
- /// sections (e.g., .debug_str).
+ /// \p Context and \p Unit allows extracting information if the form refers
+ /// to other sections (e.g., .debug_str).
+ bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr,
+ DWARFFormParams FormParams,
+ const DWARFContext *Context = nullptr,
+ const DWARFUnit *Unit = nullptr);
+
bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr,
- DWARFFormParams FormParams, const DWARFUnit *U = nullptr);
+ DWARFFormParams FormParams, const DWARFUnit *U) {
+ return extractValue(Data, OffsetPtr, FormParams, nullptr, U);
+ }
bool isInlinedCStr() const {
return Value.data != nullptr && Value.data == (const uint8_t *)Value.cstr;
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=323691&r1=323690&r2=323691&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Mon Jan 29 12:57:43 2018
@@ -387,7 +387,7 @@ void DWARFContext::dump(
if (DumpOffset && Offset != *DumpOffset) {
// Find the size of this part of the line table section and skip it.
unsigned OldOffset = Offset;
- LineTable.Prologue.parse(LineData, &Offset, U);
+ LineTable.Prologue.parse(LineData, &Offset, *this, U);
Offset = OldOffset + LineTable.Prologue.TotalLength +
LineTable.Prologue.sizeofTotalLength();
continue;
@@ -397,9 +397,9 @@ void DWARFContext::dump(
OS << "debug_line[" << format("0x%8.8x", Offset) << "]\n";
unsigned OldOffset = Offset;
if (DumpOpts.Verbose) {
- LineTable.parse(LineData, &Offset, U, &OS);
+ LineTable.parse(LineData, &Offset, *this, U, &OS);
} else {
- LineTable.parse(LineData, &Offset, U);
+ LineTable.parse(LineData, &Offset, *this, U);
LineTable.dump(OS);
}
// Check for unparseable prologue, to avoid infinite loops.
@@ -422,7 +422,7 @@ void DWARFContext::dump(
U = It->second;
DWARFDebugLine::LineTable LineTable;
unsigned OldOffset = Offset;
- if (!LineTable.Prologue.parse(LineData, &Offset, U))
+ if (!LineTable.Prologue.parse(LineData, &Offset, *this, U))
break;
if (!DumpOffset || OldOffset == *DumpOffset)
LineTable.dump(OS);
@@ -781,7 +781,7 @@ DWARFContext::getLineTableForUnit(DWARFU
// We have to parse it first.
DWARFDataExtractor lineData(*DObj, U->getLineSection(), isLittleEndian(),
U->getAddressByteSize());
- return Line->getOrParseLineTable(lineData, stmtOffset, U);
+ return Line->getOrParseLineTable(lineData, stmtOffset, *this, U);
}
void DWARFContext::parseCompileUnits() {
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp?rev=323691&r1=323690&r2=323691&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp Mon Jan 29 12:57:43 2018
@@ -157,8 +157,9 @@ parseV5EntryFormat(const DWARFDataExtrac
static bool
parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,
uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
- const DWARFFormParams &FormParams, const DWARFUnit *U,
- bool &HasMD5, std::vector<StringRef> &IncludeDirectories,
+ const DWARFFormParams &FormParams, const DWARFContext &Ctx,
+ const DWARFUnit *U, bool &HasMD5,
+ std::vector<StringRef> &IncludeDirectories,
std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
// Get the directory entry description.
ContentDescriptors DirDescriptors =
@@ -175,7 +176,7 @@ parseV5DirFileTables(const DWARFDataExtr
DWARFFormValue Value(Descriptor.Form);
switch (Descriptor.Type) {
case DW_LNCT_path:
- if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, U))
+ if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
return false;
IncludeDirectories.push_back(Value.getAsCString().getValue());
break;
@@ -200,7 +201,7 @@ parseV5DirFileTables(const DWARFDataExtr
DWARFDebugLine::FileNameEntry FileEntry;
for (auto Descriptor : FileDescriptors) {
DWARFFormValue Value(Descriptor.Form);
- if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, U))
+ if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
return false;
switch (Descriptor.Type) {
case DW_LNCT_path:
@@ -230,7 +231,9 @@ parseV5DirFileTables(const DWARFDataExtr
}
bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,
- uint32_t *OffsetPtr, const DWARFUnit *U) {
+ uint32_t *OffsetPtr,
+ const DWARFContext &Ctx,
+ const DWARFUnit *U) {
const uint64_t PrologueOffset = *OffsetPtr;
clear();
@@ -271,7 +274,7 @@ bool DWARFDebugLine::Prologue::parse(con
if (getVersion() >= 5) {
if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
- FormParams, U, HasMD5, IncludeDirectories,
+ FormParams, Ctx, U, HasMD5, IncludeDirectories,
FileNames)) {
fprintf(stderr,
"warning: parsing line table prologue at 0x%8.8" PRIx64
@@ -401,25 +404,27 @@ DWARFDebugLine::getLineTable(uint32_t Of
const DWARFDebugLine::LineTable *
DWARFDebugLine::getOrParseLineTable(DWARFDataExtractor &DebugLineData,
- uint32_t Offset, const DWARFUnit *U) {
+ uint32_t Offset, const DWARFContext &Ctx,
+ const DWARFUnit *U) {
std::pair<LineTableIter, bool> Pos =
LineTableMap.insert(LineTableMapTy::value_type(Offset, LineTable()));
LineTable *LT = &Pos.first->second;
if (Pos.second) {
- if (!LT->parse(DebugLineData, &Offset, U))
+ if (!LT->parse(DebugLineData, &Offset, Ctx, U))
return nullptr;
}
return LT;
}
bool DWARFDebugLine::LineTable::parse(DWARFDataExtractor &DebugLineData,
- uint32_t *OffsetPtr, const DWARFUnit *U,
- raw_ostream *OS) {
+ uint32_t *OffsetPtr,
+ const DWARFContext &Ctx,
+ const DWARFUnit *U, raw_ostream *OS) {
const uint32_t DebugLineOffset = *OffsetPtr;
clear();
- if (!Prologue.parse(DebugLineData, OffsetPtr, U)) {
+ if (!Prologue.parse(DebugLineData, OffsetPtr, Ctx, U)) {
// Restore our offset and return false to indicate failure!
*OffsetPtr = DebugLineOffset;
return false;
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp?rev=323691&r1=323690&r2=323691&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp Mon Jan 29 12:57:43 2018
@@ -293,7 +293,11 @@ bool DWARFFormValue::isFormClass(DWARFFo
bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
uint32_t *OffsetPtr, DWARFFormParams FP,
+ const DWARFContext *Ctx,
const DWARFUnit *CU) {
+ if (!Ctx && CU)
+ Ctx = &CU->getContext();
+ C = Ctx;
U = CU;
bool Indirect = false;
bool IsBlock = false;
@@ -591,11 +595,12 @@ Optional<const char *> DWARFFormValue::g
if (Form == DW_FORM_string)
return Value.cstr;
// FIXME: Add support for DW_FORM_GNU_strp_alt
- if (Form == DW_FORM_GNU_strp_alt || U == nullptr)
+ if (Form == DW_FORM_GNU_strp_alt || C == nullptr)
return None;
uint32_t Offset = Value.uval;
if (Form == DW_FORM_line_strp) {
- if (const char *Str = U->getLineStringExtractor().getCStr(&Offset))
+ // .debug_line_str is tracked in the Context.
+ if (const char *Str = C->getLineStringExtractor().getCStr(&Offset))
return Str;
return None;
}
@@ -603,13 +608,19 @@ Optional<const char *> DWARFFormValue::g
Form == DW_FORM_strx1 || Form == DW_FORM_strx2 || Form == DW_FORM_strx3 ||
Form == DW_FORM_strx4) {
uint64_t StrOffset;
- if (!U->getStringOffsetSectionItem(Offset, StrOffset))
+ if (!U || !U->getStringOffsetSectionItem(Offset, StrOffset))
return None;
Offset = StrOffset;
}
- if (const char *Str = U->getStringExtractor().getCStr(&Offset)) {
- return Str;
+ // Prefer the Unit's string extractor, because for .dwo it will point to
+ // .debug_str.dwo, while the Context's extractor always uses .debug_str.
+ if (U) {
+ if (const char *Str = U->getStringExtractor().getCStr(&Offset))
+ return Str;
+ return None;
}
+ if (const char *Str = C->getStringExtractor().getCStr(&Offset))
+ return Str;
return None;
}
Modified: llvm/trunk/test/DebugInfo/X86/dwarfdump-line-only.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarfdump-line-only.s?rev=323691&r1=323690&r2=323691&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dwarfdump-line-only.s (original)
+++ llvm/trunk/test/DebugInfo/X86/dwarfdump-line-only.s Mon Jan 29 12:57:43 2018
@@ -1,6 +1,5 @@
# Test object to verify dwarfdump handles dumping a DWARF v5 line table
# without an associated unit.
-# FIXME: Support FORM_strp in this situation.
#
# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o - | \
# RUN: llvm-dwarfdump -v - | FileCheck %s
@@ -42,17 +41,17 @@ LH_5_params:
# Directory table format
.byte 1 # One element per directory entry
.byte 1 # DW_LNCT_path
- .byte 0x08 # DW_FORM_string
+ .byte 0x0e # DW_FORM_strp (-> .debug_str)
# Directory table entries
.byte 2 # Two directory entries
- .asciz "Directory1"
- .asciz "Directory2"
+ .long str_D1
+ .long str_D2
# File table format
.byte 4 # Four elements per file entry
.byte 2 # DW_LNCT_directory_index
.byte 0x0b # DW_FORM_data1
.byte 1 # DW_LNCT_path
- .byte 0x08 # DW_FORM_string
+ .byte 0x1f # DW_FORM_line_strp (-> .debug_line_str)
.byte 3 # DW_LNCT_timestamp
.byte 0x0f # DW_FORM_udata
.byte 4 # DW_LNCT_size
@@ -60,11 +59,11 @@ LH_5_params:
# File table entries
.byte 2 # Two file entries
.byte 1
- .asciz "File1"
+ .long ls_F1
.byte 0x51
.byte 0x52
.byte 0
- .asciz "File2"
+ .long ls_F2
.byte 0x53
.byte 0x54
LH_5_header_end:
@@ -79,6 +78,14 @@ LH_5_header_end:
.byte 1 # DW_LNE_end_sequence
LH_5_end:
+ .section .debug_str,"MS", at progbits,1
+str_D1: .asciz "Directory1"
+str_D2: .asciz "Directory2"
+
+ .section .debug_line_str,"MS", at progbits,1
+ls_F1: .asciz "File1"
+ls_F2: .asciz "File2"
+
# CHECK: Line table prologue:
# CHECK: version: 5
# CHECK: address_size: 8
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=323691&r1=323690&r2=323691&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Mon Jan 29 12:57:43 2018
@@ -3344,7 +3344,7 @@ void DwarfLinker::patchLineTableForUnit(
DWARFDataExtractor LineExtractor(
OrigDwarf.getDWARFObj(), OrigDwarf.getDWARFObj().getLineSection(),
OrigDwarf.isLittleEndian(), Unit.getOrigUnit().getAddressByteSize());
- LineTable.parse(LineExtractor, &StmtOffset, &Unit.getOrigUnit());
+ LineTable.parse(LineExtractor, &StmtOffset, OrigDwarf, &Unit.getOrigUnit());
// This vector is the output line table.
std::vector<DWARFDebugLine::Row> NewRows;
More information about the llvm-commits
mailing list