fdeazeve created this revision. Herald added a subscriber: arphaman. Herald added a project: All. fdeazeve requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
LLDB's implementation of DWARFDataExtractor has a method that returns a llvm::DWARFDataExtractor. In some cases, like DebugNamesDWARFIndex::Create, we were passing an LLVM::DWARFDataExtractor to a function that expects a LLVM:DataExtractor by value. This is causing slicing of the derived class. While slicing is not inherently bad, it can be dangerous if the constructor of the derived class mutates the base class in a way that leaves it in an invalid state after slicing. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D153913 Files: lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -142,7 +142,7 @@ dw_offset_t unit_offset) { Log *log = GetLog(DWARFLog::DebugInfo); - llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVM(); + llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVMDWARF(); llvm::DWARFContext &ctx = context.GetAsLLVM(); llvm::Expected<const llvm::DWARFDebugLine::LineTable *> line_table = line.getOrParseLineTable( @@ -166,7 +166,7 @@ dw_offset_t unit_offset) { Log *log = GetLog(DWARFLog::DebugInfo); bool success = true; - llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVM(); + llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVMDWARF(); llvm::DWARFContext &ctx = context.GetAsLLVM(); uint64_t offset = line_offset; llvm::Error error = prologue.parse( @@ -1058,7 +1058,8 @@ FileSpecList &list = iter_bool.first->second; if (iter_bool.second) { uint64_t line_table_offset = offset; - llvm::DWARFDataExtractor data = m_context.getOrLoadLineData().GetAsLLVM(); + llvm::DWARFDataExtractor data = + m_context.getOrLoadLineData().GetAsLLVMDWARF(); llvm::DWARFContext &ctx = m_context.GetAsLLVM(); llvm::DWARFDebugLine::Prologue prologue; auto report = [](llvm::Error error) { Index: lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -23,8 +23,8 @@ DebugNamesDWARFIndex::Create(Module &module, DWARFDataExtractor debug_names, DWARFDataExtractor debug_str, SymbolFileDWARF &dwarf) { - auto index_up = std::make_unique<DebugNames>(debug_names.GetAsLLVM(), - debug_str.GetAsLLVM()); + auto index_up = std::make_unique<DebugNames>(debug_names.GetAsLLVMDWARF(), + debug_str.GetAsLLVM()); if (llvm::Error E = index_up->extract()) return std::move(E); Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -501,7 +501,7 @@ m_loclist_table_header.emplace(".debug_loclists", "locations"); offset += loclists_base - header_size; if (llvm::Error E = m_loclist_table_header->extract( - m_dwarf.GetDWARFContext().getOrLoadLocListsData().GetAsLLVM(), + m_dwarf.GetDWARFContext().getOrLoadLocListsData().GetAsLLVMDWARF(), &offset)) { GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError( "Failed to extract location list table at offset {0:x16} (location " @@ -564,7 +564,7 @@ m_rnglist_table_done = true; if (auto table_or_error = ParseListTableHeader<llvm::DWARFDebugRnglistTable>( - GetRnglistData().GetAsLLVM(), m_ranges_base, DWARF32)) + GetRnglistData().GetAsLLVMDWARF(), m_ranges_base, DWARF32)) m_rnglist_table = std::move(table_or_error.get()); else GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError( @@ -1040,7 +1040,7 @@ return llvm::createStringError(std::errc::invalid_argument, "missing or invalid range list table"); - llvm::DWARFDataExtractor data = GetRnglistData().GetAsLLVM(); + llvm::DWARFDataExtractor data = GetRnglistData().GetAsLLVMDWARF(); // As DW_AT_rnglists_base may be missing we need to call setAddressSize. data.setAddressSize(m_header.GetAddressByteSize()); Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp @@ -16,7 +16,7 @@ void DWARFDebugRanges::Extract(DWARFContext &context) { llvm::DWARFDataExtractor extractor = - context.getOrLoadRangesData().GetAsLLVM(); + context.getOrLoadRangesData().GetAsLLVMDWARF(); llvm::DWARFDebugRangeList extracted_list; uint64_t current_offset = 0; auto extract_next_list = [&] { Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h @@ -30,7 +30,8 @@ size_t GetDWARFSizeofInitialLength() const { return 4; } size_t GetDWARFSizeOfOffset() const { return 4; } - llvm::DWARFDataExtractor GetAsLLVM() const; + llvm::DWARFDataExtractor GetAsLLVMDWARF() const; + llvm::DataExtractor GetAsLLVM() const; }; } Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp @@ -21,9 +21,14 @@ return GetMaxU64(offset_ptr, GetDWARFSizeOfOffset()); } -llvm::DWARFDataExtractor DWARFDataExtractor::GetAsLLVM() const { +llvm::DWARFDataExtractor DWARFDataExtractor::GetAsLLVMDWARF() const { return llvm::DWARFDataExtractor(llvm::ArrayRef(GetDataStart(), GetByteSize()), GetByteOrder() == lldb::eByteOrderLittle, GetAddressByteSize()); } +llvm::DataExtractor DWARFDataExtractor::GetAsLLVM() const { + return llvm::DataExtractor(llvm::ArrayRef(GetDataStart(), GetByteSize()), + GetByteOrder() == lldb::eByteOrderLittle, + GetAddressByteSize()); +} } // namespace lldb_private
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits