Skip to content

Commit 3efbc3c

Browse files
committed
[lldb][NFCI] Remove ObjectFile::GetReflectionSectionIdentifier
ObjectFile doesn't need to know what swift is. The only place this method got used was in SwiftLanguageRuntime, which already has functionality to replace this entirely (which I just moved up).
1 parent 38a8c52 commit 3efbc3c

File tree

9 files changed

+43
-95
lines changed

9 files changed

+43
-95
lines changed

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
#include "llvm/Support/VersionTuple.h"
2525
#include <optional>
2626

27-
namespace swift {
28-
enum ReflectionSectionKind : uint8_t;
29-
}
3027
namespace lldb_private {
3128

3229
/// \class ObjectFile ObjectFile.h "lldb/Symbol/ObjectFile.h"
@@ -721,9 +718,6 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
721718
/// Creates a plugin-specific call frame info
722719
virtual std::unique_ptr<CallFrameInfo> CreateCallFrameInfo();
723720

724-
virtual llvm::StringRef
725-
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section);
726-
727721
/// Load binaries listed in a corefile
728722
///
729723
/// A corefile may have metadata listing binaries that can be loaded,

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

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,32 @@ class SwiftLanguageRuntimeStub {
419419
operator=(const SwiftLanguageRuntimeStub &) = delete;
420420
};
421421

422+
static std::unique_ptr<swift::SwiftObjectFileFormat>
423+
GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
424+
std::unique_ptr<swift::SwiftObjectFileFormat> obj_file_format;
425+
switch (obj_format_type) {
426+
case llvm::Triple::MachO:
427+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatMachO>();
428+
break;
429+
case llvm::Triple::ELF:
430+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatELF>();
431+
break;
432+
case llvm::Triple::COFF:
433+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatCOFF>();
434+
break;
435+
default:
436+
if (Log *log = GetLog(LLDBLog::Types))
437+
log->Printf("%s: Could not find out swift reflection section names for "
438+
"object format type.",
439+
__FUNCTION__);
440+
}
441+
return obj_file_format;
442+
}
443+
422444
static bool HasReflectionInfo(ObjectFile *obj_file) {
445+
if (!obj_file)
446+
return false;
447+
423448
auto findSectionInObject = [&](StringRef name) {
424449
ConstString section_name(name);
425450
SectionSP section_sp =
@@ -429,18 +454,24 @@ static bool HasReflectionInfo(ObjectFile *obj_file) {
429454
return false;
430455
};
431456

432-
StringRef field_md = obj_file->GetReflectionSectionIdentifier(
433-
swift::ReflectionSectionKind::fieldmd);
434-
StringRef assocty = obj_file->GetReflectionSectionIdentifier(
435-
swift::ReflectionSectionKind::assocty);
436-
StringRef builtin = obj_file->GetReflectionSectionIdentifier(
437-
swift::ReflectionSectionKind::builtin);
438-
StringRef capture = obj_file->GetReflectionSectionIdentifier(
439-
swift::ReflectionSectionKind::capture);
440-
StringRef typeref = obj_file->GetReflectionSectionIdentifier(
441-
swift::ReflectionSectionKind::typeref);
442-
StringRef reflstr = obj_file->GetReflectionSectionIdentifier(
443-
swift::ReflectionSectionKind::reflstr);
457+
const auto obj_format_type =
458+
obj_file->GetArchitecture().GetTriple().getObjectFormat();
459+
auto obj_file_format_up = GetObjectFileFormat(obj_format_type);
460+
if (!obj_file_format_up)
461+
return false;
462+
463+
StringRef field_md =
464+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::fieldmd);
465+
StringRef assocty =
466+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::assocty);
467+
StringRef builtin =
468+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::builtin);
469+
StringRef capture =
470+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::capture);
471+
StringRef typeref =
472+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::typeref);
473+
StringRef reflstr =
474+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::reflstr);
444475

445476
bool hasReflectionSection = false;
446477
hasReflectionSection |= findSectionInObject(field_md);
@@ -629,28 +660,6 @@ void SwiftLanguageRuntime::ModulesDidLoad(const ModuleList &module_list) {
629660
}
630661
}
631662

632-
static std::unique_ptr<swift::SwiftObjectFileFormat>
633-
GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
634-
std::unique_ptr<swift::SwiftObjectFileFormat> obj_file_format;
635-
switch (obj_format_type) {
636-
case llvm::Triple::MachO:
637-
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatMachO>();
638-
break;
639-
case llvm::Triple::ELF:
640-
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatELF>();
641-
break;
642-
case llvm::Triple::COFF:
643-
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatCOFF>();
644-
break;
645-
default:
646-
if (Log *log = GetLog(LLDBLog::Types))
647-
log->Printf("%s: Could not find out swift reflection section names for "
648-
"object format type.",
649-
__FUNCTION__);
650-
}
651-
return obj_file_format;
652-
}
653-
654663
static llvm::SmallVector<llvm::StringRef, 1>
655664
GetLikelySwiftImageNamesForModule(ModuleSP module) {
656665
if (!module || !module->GetFileSpec())

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
#include "llvm/Support/MemoryBuffer.h"
4646
#include "llvm/Support/MipsABIFlags.h"
4747

48-
#ifdef LLDB_ENABLE_SWIFT
49-
#include "swift/ABI/ObjectFile.h"
50-
#endif //LLDB_ENABLE_SWIFT
51-
5248
#define CASE_AND_STREAM(s, def, width) \
5349
case def: \
5450
s->Printf("%-*s", width, #def); \
@@ -3588,13 +3584,3 @@ ObjectFileELF::MapFileDataWritable(const FileSpec &file, uint64_t Size,
35883584
return FileSystem::Instance().CreateWritableDataBuffer(file.GetPath(), Size,
35893585
Offset);
35903586
}
3591-
3592-
llvm::StringRef ObjectFileELF::GetReflectionSectionIdentifier(
3593-
swift::ReflectionSectionKind section) {
3594-
#ifdef LLDB_ENABLE_SWIFT
3595-
swift::SwiftObjectFileFormatELF file_format_elf;
3596-
return file_format_elf.getSectionName(section);
3597-
#else
3598-
llvm_unreachable("Swift support disabled");
3599-
#endif //LLDB_ENABLE_SWIFT
3600-
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ class ObjectFileELF : public lldb_private::ObjectFile {
398398
/// .gnu_debugdata section or \c nullptr if an error occured or if there's no
399399
/// section with that name.
400400
std::shared_ptr<ObjectFileELF> GetGnuDebugDataObjectFile();
401-
402-
llvm::StringRef
403-
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
404401
};
405402

406403
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
#include "ObjectFileMachO.h"
5555
#ifdef LLDB_ENABLE_SWIFT
56-
#include "swift/ABI/ObjectFile.h"
5756
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
5857
#endif //LLDB_ENABLE_SWIFT
5958

@@ -6946,16 +6945,6 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
69466945
return false;
69476946
}
69486947

6949-
llvm::StringRef ObjectFileMachO::GetReflectionSectionIdentifier(
6950-
swift::ReflectionSectionKind section) {
6951-
#ifdef LLDB_ENABLE_SWIFT
6952-
swift::SwiftObjectFileFormatMachO file_format_mach_o;
6953-
return file_format_mach_o.getSectionName(section);
6954-
#else
6955-
llvm_unreachable("Swift support disabled");
6956-
#endif //LLDB_ENABLE_SWIFT
6957-
}
6958-
69596948
ObjectFileMachO::MachOCorefileAllImageInfos
69606949
ObjectFileMachO::GetCorefileAllImageInfos() {
69616950
MachOCorefileAllImageInfos image_infos;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,6 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
228228

229229
bool SectionIsLoadable(const lldb_private::Section *section);
230230

231-
llvm::StringRef
232-
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
233-
234231
/// A corefile may include metadata about all of the binaries that were
235232
/// present in the process when the corefile was taken. This is only
236233
/// implemented for Mach-O files for now; we'll generalize it when we

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
#include "llvm/TargetParser/Host.h"
4141
#include <optional>
4242

43-
#ifdef LLDB_ENABLE_SWIFT
44-
#include "swift/ABI/ObjectFile.h"
45-
#endif //LLDB_ENABLE_SWIFT
46-
4743
#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
4844
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
4945
#define OPT_HEADER_MAGIC_PE32 0x010b
@@ -1434,13 +1430,3 @@ ObjectFile::Type ObjectFilePECOFF::CalculateType() {
14341430
}
14351431

14361432
ObjectFile::Strata ObjectFilePECOFF::CalculateStrata() { return eStrataUser; }
1437-
1438-
llvm::StringRef ObjectFilePECOFF::GetReflectionSectionIdentifier(
1439-
swift::ReflectionSectionKind section) {
1440-
#ifdef LLDB_ENABLE_SWIFT
1441-
swift::SwiftObjectFileFormatCOFF file_format_coff;
1442-
return file_format_coff.getSectionName(section);
1443-
#else
1444-
llvm_unreachable("Swift support disabled");
1445-
#endif //LLDB_ENABLE_SWIFT
1446-
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,6 @@ class ObjectFilePECOFF : public lldb_private::ObjectFile {
265265
const section_header_t &sect);
266266
size_t GetSectionDataSize(lldb_private::Section *section) override;
267267

268-
llvm::StringRef
269-
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
270-
271268
typedef std::vector<section_header_t> SectionHeaderColl;
272269
typedef SectionHeaderColl::iterator SectionHeaderCollIter;
273270
typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;

lldb/source/Symbol/ObjectFile.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,6 @@ void llvm::format_provider<ObjectFile::Strata>::format(
732732
}
733733
}
734734

735-
llvm::StringRef ObjectFile::GetReflectionSectionIdentifier(
736-
swift::ReflectionSectionKind section) {
737-
assert(false &&
738-
"Base class's GetReflectionSectionIdentifier should not be called");
739-
return "";
740-
}
741-
742735
Symtab *ObjectFile::GetSymtab() {
743736
ModuleSP module_sp(GetModule());
744737
if (module_sp) {

0 commit comments

Comments
 (0)