Skip to content

Commit 05a8344

Browse files
committed
Merge pull request #3848 from apple/lldb-Implement-LLDBMemoryReader-resolvePointer
[lldb] Implement LLDBMemoryReader::resolvePointer (cherry picked from commit bb7505d) (cherry picked from commit 201ddc5)
1 parent 3c8b1f7 commit 05a8344

File tree

10 files changed

+64
-8
lines changed

10 files changed

+64
-8
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,12 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
708708
virtual llvm::StringRef
709709
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section);
710710

711+
#ifdef LLDB_ENABLE_SWIFT
712+
virtual bool CanContainSwiftReflectionData(const Section &section) {
713+
return false;
714+
}
715+
#endif // LLDB_ENABLE_SWIFT
716+
711717
/// Load binaries listed in a corefile
712718
///
713719
/// A corefile may have metadata listing binaries that can be loaded,

lldb/source/Core/Section.cpp

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

379+
bool Section::CanContainSwiftReflectionData() const {
380+
#ifdef LLDB_ENABLE_SWIFT
381+
return m_obj_file->CanContainSwiftReflectionData(*this);
382+
#else
383+
return false;
384+
#endif // LLDB_ENABLE_SWIFT
385+
}
386+
379387
lldb::offset_t Section::GetSectionData(void *dst, lldb::offset_t dst_len,
380388
lldb::offset_t offset) {
381389
if (m_obj_file)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "LLDBMemoryReader.h"
2+
#include "lldb/Core/Address.h"
23
#include "lldb/Core/Section.h"
34
#include "lldb/Utility/LLDBLog.h"
45
#include "lldb/Utility/Log.h"
6+
#include "lldb/Utility/Logging.h"
57

68
#include "llvm/Support/MathExtras.h"
9+
#include "swift/Demangling/Demangle.h"
710

811
using namespace lldb;
912
using namespace lldb_private;

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

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

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

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

397397
llvm::StringRef
398398
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
399+
400+
#ifdef LLDB_ENABLE_SWIFT
401+
bool
402+
CanContainSwiftReflectionData(const lldb_private::Section &section) override;
403+
#endif // LLDB_ENABLE_SWIFT
399404
};
400405

401406
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6900,6 +6900,23 @@ llvm::StringRef ObjectFileMachO::GetReflectionSectionIdentifier(
69006900
#endif //LLDB_ENABLE_SWIFT
69016901
}
69026902

6903+
#ifdef LLDB_ENABLE_SWIFT
6904+
bool ObjectFileMachO::CanContainSwiftReflectionData(const Section &section) {
6905+
swift::SwiftObjectFileFormatMachO file_format;
6906+
if (file_format.sectionContainsReflectionData(
6907+
section.GetName().GetStringRef()))
6908+
return true;
6909+
// Some section names are not unique, such as `__const`, which could be in
6910+
// `__TEXT` or `__DATA`. For these, also check the segment,section name.
6911+
if (auto segment = section.GetParent()) {
6912+
std::string segmentSectionName =
6913+
llvm::formatv("{0},{1}", segment->GetName(), section.GetName()).str();
6914+
return file_format.sectionContainsReflectionData(segmentSectionName);
6915+
}
6916+
return false;
6917+
}
6918+
#endif // LLDB_ENABLE_SWIFT
6919+
69036920
ObjectFileMachO::MachOCorefileAllImageInfos
69046921
ObjectFileMachO::GetCorefileAllImageInfos() {
69056922
MachOCorefileAllImageInfos image_infos;

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

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

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

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,13 +1194,10 @@ ObjectFile::Type ObjectFilePECOFF::CalculateType() {
11941194

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

1197-
llvm::StringRef ObjectFilePECOFF::GetReflectionSectionIdentifier(
1198-
swift::ReflectionSectionKind section) {
11991197
#ifdef LLDB_ENABLE_SWIFT
1200-
swift::SwiftObjectFileFormatCOFF file_format_coff;
1201-
return file_format_coff.getSectionName(section);
1202-
#else
1203-
llvm_unreachable("Swift support disabled");
1204-
#endif //LLDB_ENABLE_SWIFT
1198+
bool ObjectFilePECOFF::CanContainSwiftReflectionData(const Section &section) {
1199+
swift::SwiftObjectFileFormatCOFF file_format;
1200+
return file_format.sectionContainsReflectionData(
1201+
section.GetName().GetStringRef());
12051202
}
1206-
1203+
#endif // LLDB_ENABLE_SWIFT

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

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

291+
#ifdef LLDB_ENABLE_SWIFT
292+
bool
293+
CanContainSwiftReflectionData(const lldb_private::Section &section) override;
294+
#endif // LLDB_ENABLE_SWIFT
295+
291296
typedef std::vector<section_header_t> SectionHeaderColl;
292297
typedef SectionHeaderColl::iterator SectionHeaderCollIter;
293298
typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;

0 commit comments

Comments
 (0)