[lldb][NFC] Prevent slicing when converting DataExtractors
authorFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Tue, 27 Jun 2023 20:10:05 +0000 (16:10 -0400)
committerFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Tue, 27 Jun 2023 22:09:40 +0000 (18:09 -0400)
commitab674234c440ed27302f58eeccc612c83b32c43f
treea83e51969d42c19fcb418c21b26e40a5247d809f
parentf3ebd88064d7f1c36a8272b3e5f7d53501c3f53b
[lldb][NFC] Prevent slicing when converting DataExtractors

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.

Differential Revision: https://reviews.llvm.org/D153913
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