[Lldb-commits] [lldb] r360874 - DWARFContext: Return empty data extractors instead of null pointers
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu May 16 04:19:02 PDT 2019
Author: labath
Date: Thu May 16 04:19:02 2019
New Revision: 360874
URL: http://llvm.org/viewvc/llvm-project?rev=360874&view=rev
Log:
DWARFContext: Return empty data extractors instead of null pointers
Summary:
There are several reasons for doing this:
- generally, there's no reason to differentiate between a section being
absent and it being present, but empty
- it matches more closely what llvm DWARF parser is doing (which also
doesn't differentiate the two cases)
- SymbolFileDWARF also doesn't differentiate the two cases, which makes
porting the rest of sections easier
- it fixes a bug in how the return-null-if-empty logic was implemented
(it returned nullptr only the second time we tried to get the
debug_aranges section), which meant that we hit an assert when trying
to parse an empty-but-present section
Reviewers: JDevlieghere, clayborg, aprantl
Subscribers: zturner, lldb-commits
Differential Revision: https://reviews.llvm.org/D61942
Added:
lldb/trunk/lit/SymbolFile/DWARF/debug_aranges-empty-section.s
Modified:
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
Added: lldb/trunk/lit/SymbolFile/DWARF/debug_aranges-empty-section.s
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/debug_aranges-empty-section.s?rev=360874&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/DWARF/debug_aranges-empty-section.s (added)
+++ lldb/trunk/lit/SymbolFile/DWARF/debug_aranges-empty-section.s Thu May 16 04:19:02 2019
@@ -0,0 +1,63 @@
+# Test that an empty .debug_aranges section doesn't confuse (or crash) us.
+
+# RUN: llvm-mc %s -triple x86_64-pc-linux -filetype=obj >%t
+# RUN: lldb %t -o "breakpoint set -n f" -b | FileCheck %s
+
+# CHECK: Breakpoint 1: where = {{.*}}`f, address = 0x0000000000000047
+
+ .text
+ .globl f # -- Begin function f
+ .type f, at function
+ .rept 0x47
+ nop
+ .endr
+f: # @f
+.Lfunc_begin0:
+ retq
+.Lfunc_end0:
+ .size f, .Lfunc_end0-f
+ # -- End function
+ .section .debug_str,"MS", at progbits,1
+.Linfo_string3:
+ .asciz "f" # string offset=83
+ .section .debug_abbrev,"", at progbits
+ .byte 1 # Abbreviation Code
+ .byte 17 # DW_TAG_compile_unit
+ .byte 1 # DW_CHILDREN_yes
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 18 # DW_AT_high_pc
+ .byte 6 # DW_FORM_data4
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 2 # Abbreviation Code
+ .byte 46 # DW_TAG_subprogram
+ .byte 0 # DW_CHILDREN_no
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 18 # DW_AT_high_pc
+ .byte 6 # DW_FORM_data4
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 0 # EOM(3)
+ .section .debug_info,"", at progbits
+.Lcu_begin0:
+ .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+ .short 4 # DWARF version number
+ .long .debug_abbrev # Offset Into Abbrev. Section
+ .byte 8 # Address Size (in bytes)
+ .byte 1 # Abbrev [1] 0xb:0x35 DW_TAG_compile_unit
+ .quad .Lfunc_begin0 # DW_AT_low_pc
+ .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
+ .byte 2 # Abbrev [2] 0x2a:0x15 DW_TAG_subprogram
+ .quad .Lfunc_begin0 # DW_AT_low_pc
+ .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
+ .long .Linfo_string3 # DW_AT_name
+ .byte 0 # End Of Children Mark
+.Ldebug_info_end0:
+
+ .section ".note.GNU-stack","", at progbits
+ .section .debug_aranges,"", at progbits
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp?rev=360874&r1=360873&r2=360874&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp Thu May 16 04:19:02 2019
@@ -13,31 +13,32 @@
using namespace lldb;
using namespace lldb_private;
-static const DWARFDataExtractor *
-LoadOrGetSection(Module &module, SectionType section_type,
- llvm::Optional<DWARFDataExtractor> &extractor) {
- if (extractor.hasValue())
- return extractor->GetByteSize() > 0 ? extractor.getPointer() : nullptr;
-
- // Initialize to an empty extractor so that we always take the fast path going
- // forward.
- extractor.emplace();
-
- const SectionList *section_list = module.GetSectionList();
+static DWARFDataExtractor LoadSection(Module &module,
+ SectionType section_type) {
+ SectionList *section_list = module.GetSectionList();
if (!section_list)
- return nullptr;
+ return DWARFDataExtractor();
auto section_sp = section_list->FindSectionByType(section_type, true);
if (!section_sp)
- return nullptr;
+ return DWARFDataExtractor();
- section_sp->GetSectionData(*extractor);
- return extractor.getPointer();
+ DWARFDataExtractor data;
+ section_sp->GetSectionData(data);
+ return data;
+}
+
+static const DWARFDataExtractor &
+LoadOrGetSection(Module &module, SectionType section_type,
+ llvm::Optional<DWARFDataExtractor> &extractor) {
+ if (!extractor)
+ extractor = LoadSection(module, section_type);
+ return *extractor;
}
DWARFContext::DWARFContext(Module &module) : m_module(module) {}
-const DWARFDataExtractor *DWARFContext::getOrLoadArangesData() {
+const DWARFDataExtractor &DWARFContext::getOrLoadArangesData() {
return LoadOrGetSection(m_module, eSectionTypeDWARFDebugAranges,
m_data_debug_aranges);
}
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.h?rev=360874&r1=360873&r2=360874&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.h Thu May 16 04:19:02 2019
@@ -23,7 +23,7 @@ private:
public:
explicit DWARFContext(Module &module);
- const DWARFDataExtractor *getOrLoadArangesData();
+ const DWARFDataExtractor &getOrLoadArangesData();
};
} // namespace lldb_private
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp?rev=360874&r1=360873&r2=360874&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp Thu May 16 04:19:02 2019
@@ -42,8 +42,6 @@ public:
// Extract
llvm::Error
DWARFDebugAranges::extract(const DWARFDataExtractor &debug_aranges_data) {
- assert(debug_aranges_data.ValidOffset(0));
-
lldb::offset_t offset = 0;
DWARFDebugArangeSet set;
@@ -65,8 +63,8 @@ DWARFDebugAranges::extract(const DWARFDa
}
}
set.Clear();
- }
- return llvm::ErrorSuccess();
+ }
+ return llvm::ErrorSuccess();
}
void DWARFDebugAranges::Dump(Log *log) const {
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp?rev=360874&r1=360873&r2=360874&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp Thu May 16 04:19:02 2019
@@ -44,13 +44,10 @@ llvm::Expected<DWARFDebugAranges &> DWAR
assert(m_dwarf2Data);
m_cu_aranges_up = llvm::make_unique<DWARFDebugAranges>();
- const DWARFDataExtractor *debug_aranges_data =
+ const DWARFDataExtractor &debug_aranges_data =
m_context.getOrLoadArangesData();
- if (debug_aranges_data) {
- llvm::Error error = m_cu_aranges_up->extract(*debug_aranges_data);
- if (error)
- return std::move(error);
- }
+ if (llvm::Error error = m_cu_aranges_up->extract(debug_aranges_data))
+ return std::move(error);
// Make a list of all CUs represented by the arange data in the file.
std::set<dw_offset_t> cus_with_data;
More information about the lldb-commits
mailing list