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
35 lines
1.3 KiB
C++
35 lines
1.3 KiB
C++
//===-- DWARFDataExtractor.cpp --------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "DWARFDataExtractor.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
namespace lldb_private {
|
|
|
|
uint64_t
|
|
DWARFDataExtractor::GetDWARFInitialLength(lldb::offset_t *offset_ptr) const {
|
|
return GetU32(offset_ptr);
|
|
}
|
|
|
|
dw_offset_t
|
|
DWARFDataExtractor::GetDWARFOffset(lldb::offset_t *offset_ptr) const {
|
|
return GetMaxU64(offset_ptr, GetDWARFSizeOfOffset());
|
|
}
|
|
|
|
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
|