Skip to content

Commit 8eef4a0

Browse files
committed
[lldb][NFCI] Remove Section::CanContainSwiftReflectionData
Instead of giving Section swift-specific knowledge, I think it would make more sense for the Swift plugins that need this knowledge to compute it.
1 parent 829efb1 commit 8eef4a0

File tree

10 files changed

+33
-58
lines changed

10 files changed

+33
-58
lines changed

lldb/include/lldb/Core/Section.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ class Section : public std::enable_shared_from_this<Section>,
209209
ObjectFile *GetObjectFile() { return m_obj_file; }
210210
const ObjectFile *GetObjectFile() const { return m_obj_file; }
211211

212-
bool CanContainSwiftReflectionData() const;
213-
214212
/// Read the section data from the object file that the section
215213
/// resides in.
216214
///

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <optional>
2626

2727
namespace swift {
28-
class SwiftObjectFileFormat;
2928
enum ReflectionSectionKind : uint8_t;
3029
}
3130
namespace lldb_private {
@@ -725,12 +724,6 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
725724
virtual llvm::StringRef
726725
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section);
727726

728-
#ifdef LLDB_ENABLE_SWIFT
729-
virtual bool CanContainSwiftReflectionData(const Section &section) {
730-
return false;
731-
}
732-
#endif // LLDB_ENABLE_SWIFT
733-
734727
/// Load binaries listed in a corefile
735728
///
736729
/// A corefile may have metadata listing binaries that can be loaded,

lldb/source/Core/Section.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,6 @@ void Section::SetPermissions(uint32_t permissions) {
378378
m_executable = (permissions & ePermissionsExecutable) != 0;
379379
}
380380

381-
bool Section::CanContainSwiftReflectionData() const {
382-
#ifdef LLDB_ENABLE_SWIFT
383-
return m_obj_file->CanContainSwiftReflectionData(*this);
384-
#else
385-
return false;
386-
#endif // LLDB_ENABLE_SWIFT
387-
}
388-
389381
lldb::offset_t Section::GetSectionData(void *dst, lldb::offset_t dst_len,
390382
lldb::offset_t offset) {
391383
if (m_obj_file)

lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,27 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
134134
return swift::remote::RemoteAddress(load_addr);
135135
}
136136

137+
static std::unique_ptr<swift::SwiftObjectFileFormat>
138+
GetSwiftObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
139+
std::unique_ptr<swift::SwiftObjectFileFormat> obj_file_format;
140+
switch (obj_format_type) {
141+
case llvm::Triple::MachO:
142+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatMachO>();
143+
break;
144+
case llvm::Triple::ELF:
145+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatELF>();
146+
break;
147+
case llvm::Triple::COFF:
148+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatCOFF>();
149+
break;
150+
default:
151+
LLDB_LOG(GetLog(LLDBLog::Types), "Could not determine swift reflection "
152+
"section names for object format type");
153+
break;
154+
}
155+
return obj_file_format;
156+
}
157+
137158
llvm::Optional<swift::remote::RemoteAbsolutePointer>
138159
LLDBMemoryReader::resolvePointerAsSymbol(swift::remote::RemoteAddress address) {
139160
// If an address has a symbol, that symbol provides additional useful data to
@@ -161,8 +182,18 @@ LLDBMemoryReader::resolvePointerAsSymbol(swift::remote::RemoteAddress address) {
161182
return {};
162183
}
163184

164-
if (!addr.GetSection()->CanContainSwiftReflectionData())
165-
return {};
185+
if (auto section_sp = addr.GetSection()) {
186+
if (auto *obj_file = section_sp->GetObjectFile()) {
187+
auto obj_file_format_type =
188+
obj_file->GetArchitecture().GetTriple().getObjectFormat();
189+
if (auto swift_obj_file_format =
190+
GetSwiftObjectFileFormat(obj_file_format_type)) {
191+
if (!swift_obj_file_format->sectionContainsReflectionData(
192+
section_sp->GetName().GetStringRef()))
193+
return {};
194+
}
195+
}
196+
}
166197

167198
if (auto *symbol = addr.CalculateSymbolContextSymbol()) {
168199
auto mangledName = symbol->GetMangled().GetMangledName().GetStringRef();

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,11 +3598,3 @@ llvm::StringRef ObjectFileELF::GetReflectionSectionIdentifier(
35983598
llvm_unreachable("Swift support disabled");
35993599
#endif //LLDB_ENABLE_SWIFT
36003600
}
3601-
3602-
#ifdef LLDB_ENABLE_SWIFT
3603-
bool ObjectFileELF::CanContainSwiftReflectionData(const Section &section) {
3604-
swift::SwiftObjectFileFormatELF file_format;
3605-
return file_format.sectionContainsReflectionData(
3606-
section.GetName().GetStringRef());
3607-
}
3608-
#endif // LLDB_ENABLE_SWIFT

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,6 @@ class ObjectFileELF : public lldb_private::ObjectFile {
401401

402402
llvm::StringRef
403403
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
404-
405-
#ifdef LLDB_ENABLE_SWIFT
406-
bool
407-
CanContainSwiftReflectionData(const lldb_private::Section &section) override;
408-
#endif // LLDB_ENABLE_SWIFT
409404
};
410405

411406
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6956,14 +6956,6 @@ llvm::StringRef ObjectFileMachO::GetReflectionSectionIdentifier(
69566956
#endif //LLDB_ENABLE_SWIFT
69576957
}
69586958

6959-
#ifdef LLDB_ENABLE_SWIFT
6960-
bool ObjectFileMachO::CanContainSwiftReflectionData(const Section &section) {
6961-
swift::SwiftObjectFileFormatMachO file_format;
6962-
return file_format.sectionContainsReflectionData(
6963-
section.GetName().GetStringRef());
6964-
}
6965-
#endif // LLDB_ENABLE_SWIFT
6966-
69676959
ObjectFileMachO::MachOCorefileAllImageInfos
69686960
ObjectFileMachO::GetCorefileAllImageInfos() {
69696961
MachOCorefileAllImageInfos image_infos;

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
231231
llvm::StringRef
232232
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
233233

234-
#ifdef LLDB_ENABLE_SWIFT
235-
bool
236-
CanContainSwiftReflectionData(const lldb_private::Section &section) override;
237-
#endif // LLDB_ENABLE_SWIFT
238-
239234
/// A corefile may include metadata about all of the binaries that were
240235
/// present in the process when the corefile was taken. This is only
241236
/// implemented for Mach-O files for now; we'll generalize it when we

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,11 +1444,3 @@ llvm::StringRef ObjectFilePECOFF::GetReflectionSectionIdentifier(
14441444
llvm_unreachable("Swift support disabled");
14451445
#endif //LLDB_ENABLE_SWIFT
14461446
}
1447-
1448-
#ifdef LLDB_ENABLE_SWIFT
1449-
bool ObjectFilePECOFF::CanContainSwiftReflectionData(const Section &section) {
1450-
swift::SwiftObjectFileFormatCOFF file_format;
1451-
return file_format.sectionContainsReflectionData(
1452-
section.GetName().GetStringRef());
1453-
}
1454-
#endif // LLDB_ENABLE_SWIFT

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,6 @@ class ObjectFilePECOFF : public lldb_private::ObjectFile {
268268
llvm::StringRef
269269
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
270270

271-
#ifdef LLDB_ENABLE_SWIFT
272-
bool
273-
CanContainSwiftReflectionData(const lldb_private::Section &section) override;
274-
#endif // LLDB_ENABLE_SWIFT
275-
276271
typedef std::vector<section_header_t> SectionHeaderColl;
277272
typedef SectionHeaderColl::iterator SectionHeaderCollIter;
278273
typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;

0 commit comments

Comments
 (0)