Skip to content

Commit eabe333

Browse files
committed
add and use CanContainSwiftReflectionData
1 parent df3589c commit eabe333

File tree

11 files changed

+63
-12
lines changed

11 files changed

+63
-12
lines changed

lldb/include/lldb/Core/Section.h

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

204+
bool CanContainSwiftReflectionData() const;
205+
204206
/// Read the section data from the object file that the section
205207
/// resides in.
206208
///

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "lldb/Utility/FileSpec.h"
2020
#include "lldb/Utility/UUID.h"
2121
#include "lldb/lldb-private.h"
22+
#include "llvm/ADT/StringRef.h"
2223
#include "llvm/Support/VersionTuple.h"
2324

2425
namespace swift {
@@ -689,6 +690,8 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
689690
virtual llvm::StringRef
690691
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section);
691692

693+
virtual bool CanContainSwiftReflectionData(const Section &section);
694+
692695
/// Load binaries listed in a corefile
693696
///
694697
/// A corefile may have metadata listing binaries that can be loaded,

lldb/source/Core/Section.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ void Section::SetPermissions(uint32_t permissions) {
390390
m_executable = (permissions & ePermissionsExecutable) != 0;
391391
}
392392

393+
bool Section::CanContainSwiftReflectionData() const {
394+
return m_obj_file->CanContainSwiftReflectionData(*this);
395+
}
396+
393397
lldb::offset_t Section::GetSectionData(void *dst, lldb::offset_t dst_len,
394398
lldb::offset_t offset) {
395399
if (m_obj_file)

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) {
122122
swift::remote::RemoteAbsolutePointer
123123
LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
124124
uint64_t readValue) {
125-
auto isEffectivelyReadOnly = [](SectionSP section) {
126-
if ((section->GetPermissions() & ePermissionsWritable) == 0)
127-
return true;
128-
if (section->GetName() == "__const")
129-
return true;
130-
if (auto segment = section->GetParent())
131-
if (segment->GetName() == "__DATA_CONST")
132-
return true;
133-
return false;
134-
};
135-
136125
// If an address has a symbol, that symbol provides additional useful data to
137126
// MetadataReader. Without the symbol, MetadataReader can derive the symbol
138127
// by loading other parts of reflection metadata, but that work has a cost.
@@ -141,7 +130,7 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
141130
Address addr;
142131
auto &target = m_process.GetTarget();
143132
if (target.ResolveLoadAddress(address.getAddressData(), addr))
144-
if (isEffectivelyReadOnly(addr.GetSection()))
133+
if (addr.GetSection()->CanContainSwiftReflectionData())
145134
if (auto *symbol = addr.CalculateSymbolContextSymbol()) {
146135
auto mangledName = symbol->GetMangled().GetMangledName().GetStringRef();
147136
// MemoryReader requires any this to be a Swift symbol. LLDB can also be

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,3 +3429,13 @@ llvm::StringRef ObjectFileELF::GetReflectionSectionIdentifier(
34293429
llvm_unreachable("Swift support disabled");
34303430
#endif //LLDB_ENABLE_SWIFT
34313431
}
3432+
3433+
bool ObjectFileELF::CanContainSwiftReflectionData(const Section &section) {
3434+
#ifdef LLDB_ENABLE_SWIFT
3435+
swift::SwiftObjectFileFormatCOFF file_format;
3436+
return file_format.sectionContainsReflectionData(
3437+
section.GetName().GetStringRef());
3438+
#else
3439+
llvm_unreachable("Swift support disabled");
3440+
#endif // LLDB_ENABLE_SWIFT
3441+
}

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

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

396396
llvm::StringRef
397397
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
398+
399+
bool
400+
CanContainSwiftReflectionData(const lldb_private::Section &section) override;
398401
};
399402

400403
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7019,6 +7019,25 @@ llvm::StringRef ObjectFileMachO::GetReflectionSectionIdentifier(
70197019
#endif //LLDB_ENABLE_SWIFT
70207020
}
70217021

7022+
bool ObjectFileMachO::CanContainSwiftReflectionData(const Section &section) {
7023+
#ifdef LLDB_ENABLE_SWIFT
7024+
swift::SwiftObjectFileFormatMachO file_format;
7025+
if (file_format.sectionContainsReflectionData(
7026+
section.GetName().GetStringRef()))
7027+
return true;
7028+
// Some section names are not unique, such as `__const`, which could be in
7029+
// `__TEXT` or `__DATA`. For these, also check the segment,section name.
7030+
if (auto segment = section.GetParent()) {
7031+
std::string segmentSectionName =
7032+
llvm::formatv("{0},{1}", segment->GetName(), section.GetName()).str();
7033+
return file_format.sectionContainsReflectionData(segmentSectionName);
7034+
}
7035+
return false;
7036+
#else
7037+
llvm_unreachable("Swift support disabled");
7038+
#endif // LLDB_ENABLE_SWIFT
7039+
}
7040+
70227041
ObjectFileMachO::MachOCorefileAllImageInfos
70237042
ObjectFileMachO::GetCorefileAllImageInfos() {
70247043
MachOCorefileAllImageInfos image_infos;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
220220
llvm::StringRef
221221
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
222222

223+
bool
224+
CanContainSwiftReflectionData(const lldb_private::Section &section) override;
225+
223226
/// A corefile may include metadata about all of the binaries that were
224227
/// present in the process when the corefile was taken. This is only
225228
/// implemented for Mach-O files for now; we'll generalize it when we

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,3 +1217,12 @@ llvm::StringRef ObjectFilePECOFF::GetReflectionSectionIdentifier(
12171217
#endif //LLDB_ENABLE_SWIFT
12181218
}
12191219

1220+
bool ObjectFilePECOFF::CanContainSwiftReflectionData(const Section &section) {
1221+
#ifdef LLDB_ENABLE_SWIFT
1222+
swift::SwiftObjectFileFormatCOFF file_format;
1223+
return file_format.sectionContainsReflectionData(
1224+
section.GetName().GetStringRef());
1225+
#else
1226+
llvm_unreachable("Swift support disabled");
1227+
#endif // LLDB_ENABLE_SWIFT
1228+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ class ObjectFilePECOFF : public lldb_private::ObjectFile {
288288
llvm::StringRef
289289
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
290290

291+
bool
292+
CanContainSwiftReflectionData(const lldb_private::Section &section) override;
293+
291294
typedef std::vector<section_header_t> SectionHeaderColl;
292295
typedef SectionHeaderColl::iterator SectionHeaderCollIter;
293296
typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;

lldb/source/Symbol/ObjectFile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,3 +725,9 @@ llvm::StringRef ObjectFile::GetReflectionSectionIdentifier(
725725
"Base class's GetReflectionSectionIdentifier should not be called");
726726
return "";
727727
}
728+
729+
bool ObjectFile::CanContainSwiftReflectionData(const Section &section) {
730+
assert(false &&
731+
"Base class's CanContainSwiftReflectionData should not be called");
732+
return false;
733+
}

0 commit comments

Comments
 (0)