Skip to content

Commit 8f2c0a8

Browse files
authored
Merge pull request #11985 from jasonmolenda/change-objectfile-extractor-to-sharedptr
[lldb][NFC] Change ObjectFile's DataExtractor to a shared ptr (llvm#170066)
2 parents 934bf47 + 6102bbe commit 8f2c0a8

File tree

11 files changed

+231
-202
lines changed

11 files changed

+231
-202
lines changed

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Utility/Endian.h"
1919
#include "lldb/Utility/FileSpec.h"
2020
#include "lldb/Utility/FileSpecList.h"
21+
#include "lldb/Utility/NonNullSharedPtr.h"
2122
#include "lldb/Utility/StructuredData.h"
2223
#include "lldb/Utility/UUID.h"
2324
#include "lldb/lldb-private.h"
@@ -418,7 +419,7 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
418419
/// Attempts to parse the object header.
419420
///
420421
/// This function is used as a test to see if a given plug-in instance can
421-
/// parse the header data already contained in ObjectFile::m_data. If an
422+
/// parse the header data already contained in ObjectFile::m_data_nsp. If an
422423
/// object file parser does not recognize that magic bytes in a header,
423424
/// false should be returned and the next plug-in can attempt to parse an
424425
/// object file.
@@ -780,6 +781,8 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
780781
std::string GetObjectName() const;
781782

782783
protected:
784+
typedef NonNullSharedPtr<lldb_private::DataExtractor> DataExtractorNSP;
785+
783786
// Member variables.
784787
FileSpec m_file;
785788
Type m_type;
@@ -789,8 +792,10 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
789792
lldb::addr_t m_length; ///< The length of this object file if it is known (can
790793
///be zero if length is unknown or can't be
791794
///determined).
792-
DataExtractor
793-
m_data; ///< The data for this object file so things can be parsed lazily.
795+
DataExtractorNSP m_data_nsp; ///< The data for this object file so things
796+
///< can be parsed lazily. This shared pointer
797+
///< will always have a DataExtractor object,
798+
///< although it may only be default-constructed.
794799
lldb::ProcessWP m_process_wp;
795800
/// Set if the object file only exists in memory.
796801
const lldb::addr_t m_memory_addr;

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ typedef std::shared_ptr<lldb_private::CompileUnit> CompUnitSP;
342342
typedef std::shared_ptr<lldb_private::DataBuffer> DataBufferSP;
343343
typedef std::shared_ptr<lldb_private::WritableDataBuffer> WritableDataBufferSP;
344344
typedef std::shared_ptr<lldb_private::DataExtractor> DataExtractorSP;
345+
typedef std::unique_ptr<lldb_private::DataExtractor> DataExtractorUP;
345346
typedef std::shared_ptr<lldb_private::Debugger> DebuggerSP;
346347
typedef std::weak_ptr<lldb_private::Debugger> DebuggerWP;
347348
typedef std::shared_ptr<lldb_private::Disassembler> DisassemblerSP;

lldb/source/Expression/ObjectFileJIT.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ ObjectFileJIT::ObjectFileJIT(const lldb::ModuleSP &module_sp,
7373
: ObjectFile(module_sp, nullptr, 0, 0, DataBufferSP(), 0), m_delegate_wp() {
7474
if (delegate_sp) {
7575
m_delegate_wp = delegate_sp;
76-
m_data.SetByteOrder(delegate_sp->GetByteOrder());
77-
m_data.SetAddressByteSize(delegate_sp->GetAddressByteSize());
76+
m_data_nsp->SetByteOrder(delegate_sp->GetByteOrder());
77+
m_data_nsp->SetAddressByteSize(delegate_sp->GetAddressByteSize());
7878
}
7979
}
8080

@@ -85,12 +85,14 @@ bool ObjectFileJIT::ParseHeader() {
8585
return false;
8686
}
8787

88-
ByteOrder ObjectFileJIT::GetByteOrder() const { return m_data.GetByteOrder(); }
88+
ByteOrder ObjectFileJIT::GetByteOrder() const {
89+
return m_data_nsp->GetByteOrder();
90+
}
8991

9092
bool ObjectFileJIT::IsExecutable() const { return false; }
9193

9294
uint32_t ObjectFileJIT::GetAddressByteSize() const {
93-
return m_data.GetAddressByteSize();
95+
return m_data_nsp->GetAddressByteSize();
9496
}
9597

9698
void ObjectFileJIT::ParseSymtab(Symtab &symtab) {

lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ void ObjectFileBreakpad::CreateSections(SectionList &unified_section_list) {
130130

131131
std::optional<Record::Kind> current_section;
132132
offset_t section_start;
133-
llvm::StringRef text = toStringRef(m_data.GetData());
133+
llvm::StringRef text = toStringRef(m_data_nsp->GetData());
134134
uint32_t next_section_id = 1;
135135
auto maybe_add_section = [&](const uint8_t *end_ptr) {
136136
if (!current_section)
137137
return; // We have been called before parsing the first line.
138138

139-
offset_t end_offset = end_ptr - m_data.GetDataStart();
139+
offset_t end_offset = end_ptr - m_data_nsp->GetDataStart();
140140
auto section_sp = std::make_shared<Section>(
141141
GetModule(), this, next_section_id++,
142142
ConstString(toString(*current_section)), eSectionTypeOther,
@@ -162,8 +162,8 @@ void ObjectFileBreakpad::CreateSections(SectionList &unified_section_list) {
162162
maybe_add_section(line.bytes_begin());
163163
// And start a new one.
164164
current_section = next_section;
165-
section_start = line.bytes_begin() - m_data.GetDataStart();
165+
section_start = line.bytes_begin() - m_data_nsp->GetDataStart();
166166
}
167167
// Finally, add the last section.
168-
maybe_add_section(m_data.GetDataEnd());
168+
maybe_add_section(m_data_nsp->GetDataEnd());
169169
}

lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ bool ObjectFileCOFF::ParseHeader() {
300300

301301
std::lock_guard<std::recursive_mutex> guard(module->GetMutex());
302302

303-
m_data.SetByteOrder(eByteOrderLittle);
304-
m_data.SetAddressByteSize(GetAddressByteSize());
303+
m_data_nsp->SetByteOrder(eByteOrderLittle);
304+
m_data_nsp->SetAddressByteSize(GetAddressByteSize());
305305

306306
return true;
307307
}

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ ByteOrder ObjectFileELF::GetByteOrder() const {
781781
}
782782

783783
uint32_t ObjectFileELF::GetAddressByteSize() const {
784-
return m_data.GetAddressByteSize();
784+
return m_data_nsp->GetAddressByteSize();
785785
}
786786

787787
AddressClass ObjectFileELF::GetAddressClass(addr_t file_addr) {
@@ -822,7 +822,7 @@ size_t ObjectFileELF::SectionIndex(const SectionHeaderCollConstIter &I) const {
822822

823823
bool ObjectFileELF::ParseHeader() {
824824
lldb::offset_t offset = 0;
825-
return m_header.Parse(m_data, &offset);
825+
return m_header.Parse(*m_data_nsp.get(), &offset);
826826
}
827827

828828
UUID ObjectFileELF::GetUUID() {
@@ -840,7 +840,7 @@ UUID ObjectFileELF::GetUUID() {
840840
return UUID();
841841

842842
core_notes_crc =
843-
CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
843+
CalculateELFNotesSegmentsCRC32(m_program_headers, *m_data_nsp.get());
844844

845845
if (core_notes_crc) {
846846
// Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make it
@@ -851,7 +851,7 @@ UUID ObjectFileELF::GetUUID() {
851851
}
852852
} else {
853853
if (!m_gnu_debuglink_crc)
854-
m_gnu_debuglink_crc = calc_crc32(0, m_data);
854+
m_gnu_debuglink_crc = calc_crc32(0, *m_data_nsp.get());
855855
if (m_gnu_debuglink_crc) {
856856
// Use 4 bytes of crc from the .gnu_debuglink section.
857857
u32le data(m_gnu_debuglink_crc);
@@ -1037,7 +1037,8 @@ size_t ObjectFileELF::GetProgramHeaderInfo(ProgramHeaderColl &program_headers,
10371037

10381038
// ParseProgramHeaders
10391039
bool ObjectFileELF::ParseProgramHeaders() {
1040-
return GetProgramHeaderInfo(m_program_headers, m_data, m_header) != 0;
1040+
return GetProgramHeaderInfo(m_program_headers, *m_data_nsp.get(), m_header) !=
1041+
0;
10411042
}
10421043

10431044
lldb_private::Status
@@ -1627,8 +1628,8 @@ ObjectFileELF::StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
16271628

16281629
// ParseSectionHeaders
16291630
size_t ObjectFileELF::ParseSectionHeaders() {
1630-
return GetSectionHeaderInfo(m_section_headers, m_data, m_header, m_uuid,
1631-
m_gnu_debuglink_file, m_gnu_debuglink_crc,
1631+
return GetSectionHeaderInfo(m_section_headers, *m_data_nsp.get(), m_header,
1632+
m_uuid, m_gnu_debuglink_file, m_gnu_debuglink_crc,
16321633
m_arch_spec);
16331634
}
16341635

@@ -3600,7 +3601,8 @@ ArchSpec ObjectFileELF::GetArchitecture() {
36003601
if (H.p_type != PT_NOTE || H.p_offset == 0 || H.p_filesz == 0)
36013602
continue;
36023603
DataExtractor data;
3603-
if (data.SetData(m_data, H.p_offset, H.p_filesz) == H.p_filesz) {
3604+
if (data.SetData(*m_data_nsp.get(), H.p_offset, H.p_filesz) ==
3605+
H.p_filesz) {
36043606
UUID uuid;
36053607
RefineModuleDetailsFromNote(data, m_arch_spec, uuid);
36063608
}
@@ -3755,10 +3757,10 @@ llvm::ArrayRef<ELFProgramHeader> ObjectFileELF::ProgramHeaders() {
37553757
}
37563758

37573759
DataExtractor ObjectFileELF::GetSegmentData(const ELFProgramHeader &H) {
3758-
// Try and read the program header from our cached m_data which can come from
3759-
// the file on disk being mmap'ed or from the initial part of the ELF file we
3760-
// read from memory and cached.
3761-
DataExtractor data = DataExtractor(m_data, H.p_offset, H.p_filesz);
3760+
// Try and read the program header from our cached m_data_nsp which can come
3761+
// from the file on disk being mmap'ed or from the initial part of the ELF
3762+
// file we read from memory and cached.
3763+
DataExtractor data = DataExtractor(*m_data_nsp.get(), H.p_offset, H.p_filesz);
37623764
if (data.GetByteSize() == H.p_filesz)
37633765
return data;
37643766
if (IsInMemory()) {

0 commit comments

Comments
 (0)