Skip to content

Commit

Permalink
General cleanup to minimize the .debug_types patch
Browse files Browse the repository at this point in the history
This cleanup is designed to make the https://reviews.llvm.org/D32167 patch smaller and easier to read.

Cleanup in this patch:

Allow DWARFUnit subclasses to hand out the data that should be used when decoding data for a DIE. The information might be in .debug_info or could be in .debug_types. There is a new virtual function on DWARFUnit that each subclass must override:

virtual const lldb_private::DWARFDataExtractor &DWARFUnit::GetData() const;
This allows DWARFCompileUnit and eventually DWARFTypeUnit to hand out different data to be used when decoding the DIE information.

Add a new pure virtual function to get the size of the DWARF unit header:

virtual uint32_t DWARFUnit::GetHeaderByteSize() const = 0;
This allows DWARFCompileUnit and eventually DWARFTypeUnit to hand out different offsets where the first DIE starts when decoding DIE information from the unit.

Added a new function to DWARFDataExtractor to get the size of an offset:

size_t DWARFDataExtractor::GetDWARFSizeOfOffset() const;
Removed dead dumping and parsing code in the DWARFDebugInfo class.
Inlined a bunch of calls in DWARFUnit for accessors that were just returning integer member variables.
Renamed DWARFUnit::Size() to DWARFUnit::GetHeaderByteSize() as it clearly states what it is doing and makes more sense.

Differential Revision: https://reviews.llvm.org/D46606

llvm-svn: 331892
  • Loading branch information
Greg Clayton committed May 9, 2018
1 parent e330071 commit f56c30d
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 335 deletions.
1 change: 1 addition & 0 deletions lldb/include/lldb/lldb-forward.h
Expand Up @@ -76,6 +76,7 @@ class ConnectionFileDescriptor;
class ConstString;
class CXXSyntheticChildren;
class DWARFCallFrameInfo;
class DWARFDataExtractor;
class DWARFExpression;
class DataBuffer;
class DataEncoder;
Expand Down
6 changes: 2 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Expand Up @@ -2868,8 +2868,7 @@ bool DWARFASTParserClang::ParseChildMembers(
if (form_value.BlockData()) {
Value initialValue(0);
Value memberOffset(0);
const DWARFDataExtractor &debug_info_data =
die.GetDWARF()->get_debug_info_data();
const DWARFDataExtractor &debug_info_data = die.GetData();
uint32_t block_length = form_value.Unsigned();
uint32_t block_offset =
form_value.BlockData() - debug_info_data.GetDataStart();
Expand Down Expand Up @@ -3330,8 +3329,7 @@ bool DWARFASTParserClang::ParseChildMembers(
if (form_value.BlockData()) {
Value initialValue(0);
Value memberOffset(0);
const DWARFDataExtractor &debug_info_data =
die.GetDWARF()->get_debug_info_data();
const DWARFDataExtractor &debug_info_data = die.GetData();
uint32_t block_length = form_value.Unsigned();
uint32_t block_offset =
form_value.BlockData() - debug_info_data.GetDataStart();
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
Expand Up @@ -655,8 +655,7 @@ size_t DWARFASTParserGo::ParseChildMembers(const SymbolContext &sc,
if (form_value.BlockData()) {
Value initialValue(0);
Value memberOffset(0);
const DWARFDataExtractor &debug_info_data =
die.GetDWARF()->get_debug_info_data();
const DWARFDataExtractor &debug_info_data = die.GetData();
uint32_t block_length = form_value.Unsigned();
uint32_t block_offset =
form_value.BlockData() - debug_info_data.GetDataStart();
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp
Expand Up @@ -52,8 +52,7 @@ bool DWARFAttributes::ExtractFormValueAtIndex(
form_value.SetCompileUnit(cu);
form_value.SetForm(FormAtIndex(i));
lldb::offset_t offset = DIEOffsetAtIndex(i);
return form_value.ExtractValue(
cu->GetSymbolFileDWARF()->get_debug_info_data(), &offset);
return form_value.ExtractValue(cu->GetData(), &offset);
}

uint64_t DWARFAttributes::FormValueAsUnsigned(dw_attr_t attr,
Expand Down
13 changes: 7 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
Expand Up @@ -20,14 +20,10 @@ DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF *dwarf2Data)
: DWARFUnit(dwarf2Data) {}

DWARFUnitSP DWARFCompileUnit::Extract(SymbolFileDWARF *dwarf2Data,
lldb::offset_t *offset_ptr) {
const DWARFDataExtractor &debug_info,
lldb::offset_t *offset_ptr) {
// std::make_shared would require the ctor to be public.
std::shared_ptr<DWARFCompileUnit> cu_sp(new DWARFCompileUnit(dwarf2Data));
// Out of memory?
if (cu_sp.get() == NULL)
return nullptr;

const DWARFDataExtractor &debug_info = dwarf2Data->get_debug_info_data();

cu_sp->m_offset = *offset_ptr;

Expand Down Expand Up @@ -67,3 +63,8 @@ void DWARFCompileUnit::Dump(Stream *s) const {
m_offset, m_length, m_version, GetAbbrevOffset(), m_addr_size,
GetNextCompileUnitOffset());
}


const lldb_private::DWARFDataExtractor &DWARFCompileUnit::GetData() const {
return m_dwarf->get_debug_info_data();
}
23 changes: 22 additions & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
Expand Up @@ -17,9 +17,30 @@ class DWARFCompileUnit : public DWARFUnit {

public:
static DWARFUnitSP Extract(SymbolFileDWARF *dwarf2Data,
lldb::offset_t *offset_ptr);
const lldb_private::DWARFDataExtractor &debug_info,
lldb::offset_t *offset_ptr);
void Dump(lldb_private::Stream *s) const override;

//------------------------------------------------------------------
/// Get the data that contains the DIE information for this unit.
///
/// @return
/// The correct data (.debug_types for DWARF 4 and earlier, and
/// .debug_info for DWARF 5 and later) for the DIE information in
/// this unit.
//------------------------------------------------------------------
const lldb_private::DWARFDataExtractor &GetData() const override;

//------------------------------------------------------------------
/// Get the size in bytes of the header.
///
/// @return
/// Byte size of the compile unit header
//------------------------------------------------------------------
uint32_t GetHeaderByteSize() const override {
return m_is_dwarf64 ? 23 : 11;
}

private:
DWARFCompileUnit(SymbolFileDWARF *dwarf2Data);
DISALLOW_COPY_AND_ASSIGN(DWARFCompileUnit);
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
Expand Up @@ -460,3 +460,9 @@ bool operator==(const DWARFDIE &lhs, const DWARFDIE &rhs) {
bool operator!=(const DWARFDIE &lhs, const DWARFDIE &rhs) {
return !(lhs == rhs);
}

const DWARFDataExtractor &DWARFDIE::GetData() const {
// Clients must check if this DIE is valid before calling this function.
assert(IsValid());
return m_cu->GetData();
}
10 changes: 10 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
Expand Up @@ -86,6 +86,16 @@ class DWARFDIE {
DWARFDIE
GetContainingDWOModuleDIE() const;

//----------------------------------------------------------------------
// Get the data that contains the attribute values for this DIE. Support
// for .debug_types means that any DIE can have its data either in the
// .debug_info or the .debug_types section; this method will return the
// correct section data.
//
// Clients must validate that this object is valid before calling this.
//----------------------------------------------------------------------
const lldb_private::DWARFDataExtractor &GetData() const;

//----------------------------------------------------------------------
// Accessing information about a DIE
//----------------------------------------------------------------------
Expand Down
Expand Up @@ -22,6 +22,6 @@ DWARFDataExtractor::GetDWARFInitialLength(lldb::offset_t *offset_ptr) const {

dw_offset_t
DWARFDataExtractor::GetDWARFOffset(lldb::offset_t *offset_ptr) const {
return GetMaxU64(offset_ptr, m_is_dwarf64 ? 8 : 4);
return GetMaxU64(offset_ptr, GetDWARFSizeOfOffset());
}
}
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h
Expand Up @@ -29,7 +29,7 @@ class DWARFDataExtractor : public DataExtractor {
dw_offset_t GetDWARFOffset(lldb::offset_t *offset_ptr) const;

size_t GetDWARFSizeofInitialLength() const { return m_is_dwarf64 ? 12 : 4; }

size_t GetDWARFSizeOfOffset() const { return m_is_dwarf64 ? 8 : 4; }
bool IsDWARF64() const { return m_is_dwarf64; }

protected:
Expand Down

0 comments on commit f56c30d

Please sign in to comment.