Skip to content

[lldb][NFCI] Remove ObjectFile::GetReflectionSectionIdentifier #7761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lldb/include/lldb/Symbol/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
#include "llvm/Support/VersionTuple.h"
#include <optional>

namespace swift {
enum ReflectionSectionKind : uint8_t;
}
namespace lldb_private {

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

virtual llvm::StringRef
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section);

/// Load binaries listed in a corefile
///
/// A corefile may have metadata listing binaries that can be loaded,
Expand Down
77 changes: 43 additions & 34 deletions lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,32 @@ class SwiftLanguageRuntimeStub {
operator=(const SwiftLanguageRuntimeStub &) = delete;
};

static std::unique_ptr<swift::SwiftObjectFileFormat>
GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
std::unique_ptr<swift::SwiftObjectFileFormat> obj_file_format;
switch (obj_format_type) {
case llvm::Triple::MachO:
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatMachO>();
break;
case llvm::Triple::ELF:
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatELF>();
break;
case llvm::Triple::COFF:
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatCOFF>();
break;
default:
if (Log *log = GetLog(LLDBLog::Types))
log->Printf("%s: Could not find out swift reflection section names for "
"object format type.",
__FUNCTION__);
}
return obj_file_format;
}

static bool HasReflectionInfo(ObjectFile *obj_file) {
if (!obj_file)
return false;

auto findSectionInObject = [&](StringRef name) {
ConstString section_name(name);
SectionSP section_sp =
Expand All @@ -429,18 +454,24 @@ static bool HasReflectionInfo(ObjectFile *obj_file) {
return false;
};

StringRef field_md = obj_file->GetReflectionSectionIdentifier(
swift::ReflectionSectionKind::fieldmd);
StringRef assocty = obj_file->GetReflectionSectionIdentifier(
swift::ReflectionSectionKind::assocty);
StringRef builtin = obj_file->GetReflectionSectionIdentifier(
swift::ReflectionSectionKind::builtin);
StringRef capture = obj_file->GetReflectionSectionIdentifier(
swift::ReflectionSectionKind::capture);
StringRef typeref = obj_file->GetReflectionSectionIdentifier(
swift::ReflectionSectionKind::typeref);
StringRef reflstr = obj_file->GetReflectionSectionIdentifier(
swift::ReflectionSectionKind::reflstr);
const auto obj_format_type =
obj_file->GetArchitecture().GetTriple().getObjectFormat();
auto obj_file_format_up = GetObjectFileFormat(obj_format_type);
if (!obj_file_format_up)
return false;

StringRef field_md =
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::fieldmd);
StringRef assocty =
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::assocty);
StringRef builtin =
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::builtin);
StringRef capture =
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::capture);
StringRef typeref =
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::typeref);
StringRef reflstr =
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::reflstr);

bool hasReflectionSection = false;
hasReflectionSection |= findSectionInObject(field_md);
Expand Down Expand Up @@ -629,28 +660,6 @@ void SwiftLanguageRuntime::ModulesDidLoad(const ModuleList &module_list) {
}
}

static std::unique_ptr<swift::SwiftObjectFileFormat>
GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
std::unique_ptr<swift::SwiftObjectFileFormat> obj_file_format;
switch (obj_format_type) {
case llvm::Triple::MachO:
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatMachO>();
break;
case llvm::Triple::ELF:
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatELF>();
break;
case llvm::Triple::COFF:
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatCOFF>();
break;
default:
if (Log *log = GetLog(LLDBLog::Types))
log->Printf("%s: Could not find out swift reflection section names for "
"object format type.",
__FUNCTION__);
}
return obj_file_format;
}

static llvm::SmallVector<llvm::StringRef, 1>
GetLikelySwiftImageNamesForModule(ModuleSP module) {
if (!module || !module->GetFileSpec())
Expand Down
14 changes: 0 additions & 14 deletions lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/MipsABIFlags.h"

#ifdef LLDB_ENABLE_SWIFT
#include "swift/ABI/ObjectFile.h"
#endif //LLDB_ENABLE_SWIFT

#define CASE_AND_STREAM(s, def, width) \
case def: \
s->Printf("%-*s", width, #def); \
Expand Down Expand Up @@ -3588,13 +3584,3 @@ ObjectFileELF::MapFileDataWritable(const FileSpec &file, uint64_t Size,
return FileSystem::Instance().CreateWritableDataBuffer(file.GetPath(), Size,
Offset);
}

llvm::StringRef ObjectFileELF::GetReflectionSectionIdentifier(
swift::ReflectionSectionKind section) {
#ifdef LLDB_ENABLE_SWIFT
swift::SwiftObjectFileFormatELF file_format_elf;
return file_format_elf.getSectionName(section);
#else
llvm_unreachable("Swift support disabled");
#endif //LLDB_ENABLE_SWIFT
}
3 changes: 0 additions & 3 deletions lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@ class ObjectFileELF : public lldb_private::ObjectFile {
/// .gnu_debugdata section or \c nullptr if an error occured or if there's no
/// section with that name.
std::shared_ptr<ObjectFileELF> GetGnuDebugDataObjectFile();

llvm::StringRef
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
};

#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H
11 changes: 0 additions & 11 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@

#include "ObjectFileMachO.h"
#ifdef LLDB_ENABLE_SWIFT
#include "swift/ABI/ObjectFile.h"
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
#endif //LLDB_ENABLE_SWIFT

Expand Down Expand Up @@ -6946,16 +6945,6 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
return false;
}

llvm::StringRef ObjectFileMachO::GetReflectionSectionIdentifier(
swift::ReflectionSectionKind section) {
#ifdef LLDB_ENABLE_SWIFT
swift::SwiftObjectFileFormatMachO file_format_mach_o;
return file_format_mach_o.getSectionName(section);
#else
llvm_unreachable("Swift support disabled");
#endif //LLDB_ENABLE_SWIFT
}

ObjectFileMachO::MachOCorefileAllImageInfos
ObjectFileMachO::GetCorefileAllImageInfos() {
MachOCorefileAllImageInfos image_infos;
Expand Down
3 changes: 0 additions & 3 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ class ObjectFileMachO : public lldb_private::ObjectFile {

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

llvm::StringRef
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;

/// A corefile may include metadata about all of the binaries that were
/// present in the process when the corefile was taken. This is only
/// implemented for Mach-O files for now; we'll generalize it when we
Expand Down
14 changes: 0 additions & 14 deletions lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
#include "llvm/TargetParser/Host.h"
#include <optional>

#ifdef LLDB_ENABLE_SWIFT
#include "swift/ABI/ObjectFile.h"
#endif //LLDB_ENABLE_SWIFT

#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
#define OPT_HEADER_MAGIC_PE32 0x010b
Expand Down Expand Up @@ -1434,13 +1430,3 @@ ObjectFile::Type ObjectFilePECOFF::CalculateType() {
}

ObjectFile::Strata ObjectFilePECOFF::CalculateStrata() { return eStrataUser; }

llvm::StringRef ObjectFilePECOFF::GetReflectionSectionIdentifier(
swift::ReflectionSectionKind section) {
#ifdef LLDB_ENABLE_SWIFT
swift::SwiftObjectFileFormatCOFF file_format_coff;
return file_format_coff.getSectionName(section);
#else
llvm_unreachable("Swift support disabled");
#endif //LLDB_ENABLE_SWIFT
}
3 changes: 0 additions & 3 deletions lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ class ObjectFilePECOFF : public lldb_private::ObjectFile {
const section_header_t &sect);
size_t GetSectionDataSize(lldb_private::Section *section) override;

llvm::StringRef
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;

typedef std::vector<section_header_t> SectionHeaderColl;
typedef SectionHeaderColl::iterator SectionHeaderCollIter;
typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;
Expand Down
7 changes: 0 additions & 7 deletions lldb/source/Symbol/ObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,13 +732,6 @@ void llvm::format_provider<ObjectFile::Strata>::format(
}
}

llvm::StringRef ObjectFile::GetReflectionSectionIdentifier(
swift::ReflectionSectionKind section) {
assert(false &&
"Base class's GetReflectionSectionIdentifier should not be called");
return "";
}

Symtab *ObjectFile::GetSymtab() {
ModuleSP module_sp(GetModule());
if (module_sp) {
Expand Down