Skip to content

Commit ff9b426

Browse files
committedMay 17, 2019
Make DWARFContext dwo-aware and port debug_info sections over
Summary: The previous attempt and moving section handling over to DWARFContext (D59611) failed because it did not take into account the dwo sections correctly. All DWARFContexts (even those in SymbolFileDWARFDwo) used the main module for loading the sections, but in the dwo scenario some sections should come from the dwo file. This patch fixes that by making the DWARFContext aware of whether it a dwo context or a regular one. A dwo context gets two sections lists, and it knows where to look for a particular type of a section. This isn't fully consistent with how the llvm DWARFContext behaves, because that one leaves it up to the user to know whether it should ask for a dwo section or not. However, for the time being, it seems useful to have a single entity which knows how to peice together the debug info in dwo and non-dwo scenarios. The rough roadmap for the future is: - port over the rest of the sections to DWARFContext - find a way to get rid of SymbolFileDWARFDwo/Dwp/DwpDwo. This will likely involve adding the ability for the DWARFContext to spawn dwo sub-contexts, similarly to how it's done in llvm. - get rid of the special handling of the "dwo" contexts by making sure everything knows whether it should ask for the .dwo version of the section or not (similarly to how llvm's DWARFUnits do that) To demonstrate how the DWARFContext should behave in this new world, I port the debug_info section (which is debug_info.dwo in the dwo file) handling to DWARFContext. The rest of the sections will come in subsequent patches. Reviewers: aprantl, clayborg, JDevlieghere Subscribers: zturner, lldb-commits Differential Revision: https://reviews.llvm.org/D62012 llvm-svn: 361000
1 parent eb4cbf8 commit ff9b426

9 files changed

+46
-34
lines changed
 

‎lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@ uint32_t DWARFCompileUnit::GetHeaderByteSize() const {
106106
}
107107

108108
const lldb_private::DWARFDataExtractor &DWARFCompileUnit::GetData() const {
109-
return m_dwarf->get_debug_info_data();
109+
return m_dwarf->GetDWARFContext().getOrLoadDebugInfoData();
110110
}

‎lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
using namespace lldb;
1414
using namespace lldb_private;
1515

16-
static DWARFDataExtractor LoadSection(Module &module,
16+
static DWARFDataExtractor LoadSection(SectionList *section_list,
1717
SectionType section_type) {
18-
SectionList *section_list = module.GetSectionList();
1918
if (!section_list)
2019
return DWARFDataExtractor();
2120

@@ -29,16 +28,22 @@ static DWARFDataExtractor LoadSection(Module &module,
2928
}
3029

3130
static const DWARFDataExtractor &
32-
LoadOrGetSection(Module &module, SectionType section_type,
31+
LoadOrGetSection(SectionList *section_list, SectionType section_type,
3332
llvm::Optional<DWARFDataExtractor> &extractor) {
3433
if (!extractor)
35-
extractor = LoadSection(module, section_type);
34+
extractor = LoadSection(section_list, section_type);
3635
return *extractor;
3736
}
3837

39-
DWARFContext::DWARFContext(Module &module) : m_module(module) {}
40-
4138
const DWARFDataExtractor &DWARFContext::getOrLoadArangesData() {
42-
return LoadOrGetSection(m_module, eSectionTypeDWARFDebugAranges,
39+
return LoadOrGetSection(m_main_section_list, eSectionTypeDWARFDebugAranges,
4340
m_data_debug_aranges);
4441
}
42+
43+
const DWARFDataExtractor &DWARFContext::getOrLoadDebugInfoData() {
44+
if (isDwo())
45+
return LoadOrGetSection(m_dwo_section_list, eSectionTypeDWARFDebugInfoDwo,
46+
m_data_debug_info);
47+
return LoadOrGetSection(m_main_section_list, eSectionTypeDWARFDebugInfo,
48+
m_data_debug_info);
49+
}

‎lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@
1010
#define LLDB_PLUGINS_SYMBOLFILE_DWARF_DWARFCONTEXT_H
1111

1212
#include "DWARFDataExtractor.h"
13-
#include "lldb/Core/Module.h"
13+
#include "lldb/Core/Section.h"
1414
#include "llvm/ADT/Optional.h"
1515
#include <memory>
1616

1717
namespace lldb_private {
1818
class DWARFContext {
1919
private:
20-
Module &m_module;
20+
SectionList *m_main_section_list;
21+
SectionList *m_dwo_section_list;
22+
2123
llvm::Optional<DWARFDataExtractor> m_data_debug_aranges;
24+
llvm::Optional<DWARFDataExtractor> m_data_debug_info;
25+
26+
bool isDwo() { return m_dwo_section_list != nullptr; }
2227

2328
public:
24-
explicit DWARFContext(Module &module);
29+
explicit DWARFContext(SectionList *main_section_list,
30+
SectionList *dwo_section_list)
31+
: m_main_section_list(main_section_list),
32+
m_dwo_section_list(dwo_section_list) {}
2533

2634
const DWARFDataExtractor &getOrLoadArangesData();
35+
const DWARFDataExtractor &getOrLoadDebugInfoData();
2736
};
2837
} // namespace lldb_private
2938

‎lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void DWARFDebugInfo::ParseUnitHeadersIfNeeded() {
8080
return;
8181

8282
lldb::offset_t offset = 0;
83-
const auto &debug_info_data = m_dwarf2Data->get_debug_info_data();
83+
const auto &debug_info_data = m_context.getOrLoadDebugInfoData();
8484

8585
while (debug_info_data.ValidOffset(offset)) {
8686
llvm::Expected<DWARFUnitSP> cu_sp = DWARFCompileUnit::extract(

‎lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
#include <assert.h>
1010

11+
#include "lldb/Core/Module.h"
1112
#include "lldb/Core/dwarf.h"
13+
#include "lldb/Symbol/ObjectFile.h"
1214
#include "lldb/Utility/Stream.h"
1315

1416
#include "DWARFDebugInfo.h"

‎lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

+11-13
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ const char *SymbolFileDWARF::GetPluginDescriptionStatic() {
200200
}
201201

202202
SymbolFile *SymbolFileDWARF::CreateInstance(ObjectFile *obj_file) {
203-
return new SymbolFileDWARF(obj_file);
203+
return new SymbolFileDWARF(obj_file,
204+
/*dwo_section_list*/ nullptr);
204205
}
205206

206207
TypeList *SymbolFileDWARF::GetTypeList() {
@@ -348,18 +349,19 @@ SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die) {
348349
return DWARFDIE();
349350
}
350351

351-
SymbolFileDWARF::SymbolFileDWARF(ObjectFile *objfile)
352+
SymbolFileDWARF::SymbolFileDWARF(ObjectFile *objfile,
353+
SectionList *dwo_section_list)
352354
: SymbolFile(objfile),
353355
UserID(0x7fffffff00000000), // Used by SymbolFileDWARFDebugMap to
354356
// when this class parses .o files to
355357
// contain the .o file index/ID
356358
m_debug_map_module_wp(), m_debug_map_symfile(NULL),
357-
m_context(*objfile->GetModule()), m_data_debug_abbrev(),
358-
m_data_debug_frame(), m_data_debug_info(), m_data_debug_line(),
359-
m_data_debug_macro(), m_data_debug_loc(), m_data_debug_ranges(),
360-
m_data_debug_rnglists(), m_data_debug_str(), m_data_apple_names(),
361-
m_data_apple_types(), m_data_apple_namespaces(), m_abbr(), m_info(),
362-
m_line(), m_fetched_external_modules(false),
359+
m_context(objfile->GetModule()->GetSectionList(), dwo_section_list),
360+
m_data_debug_abbrev(), m_data_debug_frame(), m_data_debug_info(),
361+
m_data_debug_line(), m_data_debug_macro(), m_data_debug_loc(),
362+
m_data_debug_ranges(), m_data_debug_rnglists(), m_data_debug_str(),
363+
m_data_apple_names(), m_data_apple_types(), m_data_apple_namespaces(),
364+
m_abbr(), m_info(), m_line(), m_fetched_external_modules(false),
363365
m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
364366
m_unique_ast_type_map() {}
365367

@@ -563,10 +565,6 @@ const DWARFDataExtractor &SymbolFileDWARF::get_debug_frame_data() {
563565
return GetCachedSectionData(eSectionTypeDWARFDebugFrame, m_data_debug_frame);
564566
}
565567

566-
const DWARFDataExtractor &SymbolFileDWARF::get_debug_info_data() {
567-
return GetCachedSectionData(eSectionTypeDWARFDebugInfo, m_data_debug_info);
568-
}
569-
570568
const DWARFDataExtractor &SymbolFileDWARF::get_debug_line_data() {
571569
return GetCachedSectionData(eSectionTypeDWARFDebugLine, m_data_debug_line);
572570
}
@@ -670,7 +668,7 @@ DWARFDebugInfo *SymbolFileDWARF::DebugInfo() {
670668
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
671669
Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
672670
static_cast<void *>(this));
673-
if (get_debug_info_data().GetByteSize() > 0) {
671+
if (m_context.getOrLoadDebugInfoData().GetByteSize() > 0) {
674672
m_info = llvm::make_unique<DWARFDebugInfo>(m_context);
675673
m_info->SetDwarfData(this);
676674
}

‎lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
8484

8585
// Constructors and Destructors
8686

87-
SymbolFileDWARF(lldb_private::ObjectFile *ofile);
87+
SymbolFileDWARF(lldb_private::ObjectFile *ofile,
88+
lldb_private::SectionList *dwo_section_list);
8889

8990
~SymbolFileDWARF() override;
9091

@@ -214,7 +215,6 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
214215
virtual const lldb_private::DWARFDataExtractor &get_debug_abbrev_data();
215216
virtual const lldb_private::DWARFDataExtractor &get_debug_addr_data();
216217
const lldb_private::DWARFDataExtractor &get_debug_frame_data();
217-
virtual const lldb_private::DWARFDataExtractor &get_debug_info_data();
218218
const lldb_private::DWARFDataExtractor &get_debug_line_data();
219219
const lldb_private::DWARFDataExtractor &get_debug_line_str_data();
220220
const lldb_private::DWARFDataExtractor &get_debug_macro_data();
@@ -315,6 +315,8 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
315315

316316
void DumpClangAST(lldb_private::Stream &s) override;
317317

318+
lldb_private::DWARFContext &GetDWARFContext() { return m_context; }
319+
318320
protected:
319321
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
320322
DIEToTypePtr;

‎lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ using namespace lldb_private;
2121

2222
SymbolFileDWARFDwo::SymbolFileDWARFDwo(ObjectFileSP objfile,
2323
DWARFUnit *dwarf_cu)
24-
: SymbolFileDWARF(objfile.get()), m_obj_file_sp(objfile),
25-
m_base_dwarf_cu(dwarf_cu) {
24+
: SymbolFileDWARF(objfile.get(), objfile->GetSectionList(
25+
/*update_module_section_list*/ false)),
26+
m_obj_file_sp(objfile), m_base_dwarf_cu(dwarf_cu) {
2627
SetID(((lldb::user_id_t)dwarf_cu->GetID()) << 32);
2728
}
2829

@@ -129,10 +130,6 @@ const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_addr_data() {
129130
return m_data_debug_addr.m_data;
130131
}
131132

132-
const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_info_data() {
133-
return GetCachedSectionData(eSectionTypeDWARFDebugInfoDwo, m_data_debug_info);
134-
}
135-
136133
const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_str_data() {
137134
return GetCachedSectionData(eSectionTypeDWARFDebugStrDwo, m_data_debug_str);
138135
}

‎lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF {
4747

4848
const lldb_private::DWARFDataExtractor &get_debug_abbrev_data() override;
4949
const lldb_private::DWARFDataExtractor &get_debug_addr_data() override;
50-
const lldb_private::DWARFDataExtractor &get_debug_info_data() override;
5150
const lldb_private::DWARFDataExtractor &get_debug_str_data() override;
5251
const lldb_private::DWARFDataExtractor &get_debug_str_offsets_data() override;
5352

0 commit comments

Comments
 (0)