Skip to content

[lldb] Adapt lldb to new swift::remote::RemoteAbsolutePointer interface #10865

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
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
26 changes: 16 additions & 10 deletions lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ LLDBMemoryReader::resolvePointerAsSymbol(swift::remote::RemoteAddress address) {
// aware of local symbols, so avoid returning those.
using namespace swift::Demangle;
if (isSwiftSymbol(mangledName) && !isOldFunctionTypeMangling(mangledName))
return {{mangledName, 0}};
return swift::remote::RemoteAbsolutePointer{mangledName, 0, address};
}

return {};
Expand All @@ -228,15 +228,16 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
// We may have gotten a pointer to a process address, try to map it back
// to a tagged address so further memory reads originating from it benefit
// from the file-cache optimization.
swift::remote::RemoteAbsolutePointer process_pointer("", readValue);
swift::remote::RemoteAbsolutePointer process_pointer{
swift::remote::RemoteAddress{readValue}};

if (!readMetadataFromFileCacheEnabled())
return process_pointer;

// Try to strip the pointer before checking if we have it mapped.
auto strippedPointer = signedPointerStripper(process_pointer);
if (strippedPointer.isResolved())
readValue = strippedPointer.getOffset();
if (auto resolved = strippedPointer.getResolvedAddress())
readValue = resolved.getAddressData();

auto &target = m_process.GetTarget();
Address addr;
Expand Down Expand Up @@ -293,9 +294,12 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
return process_pointer;
}

swift::remote::RemoteAbsolutePointer tagged_pointer("", tagged_address);
if (tagged_address !=
(uint64_t)signedPointerStripper(tagged_pointer).getOffset()) {
swift::remote::RemoteAbsolutePointer tagged_pointer{
swift::remote::RemoteAddress{tagged_address}};

if (tagged_address != (uint64_t)signedPointerStripper(tagged_pointer)
.getResolvedAddress()
.getAddressData()) {
lldbassert(false &&
"Tagged pointer runs into pointer authentication mask!");
return process_pointer;
Expand Down Expand Up @@ -534,9 +538,11 @@ LLDBMemoryReader::addModuleToAddressMap(ModuleSP module,
auto module_end_address = module_start_address + size;

if (module_end_address !=
(uint64_t)signedPointerStripper(
swift::remote::RemoteAbsolutePointer("", module_end_address))
.getOffset()) {
signedPointerStripper(
swift::remote::RemoteAbsolutePointer{
swift::remote::RemoteAddress{module_end_address}})
.getResolvedAddress()
.getAddressData()) {
LLDB_LOG(GetLog(LLDBLog::Types),
"[MemoryReader] module to address map ran into pointer "
"authentication mask!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2033,10 +2033,11 @@ CompilerType SwiftLanguageRuntime::GetDynamicTypeAndAddress_EmbeddedClass(
if (!pointer)
return {};
llvm::StringRef symbol_name;
if (pointer->isResolved()) {
if (pointer->getSymbol().empty() || pointer->getOffset()) {
// Find the symbol name at this address.
Address address;
address.SetLoadAddress(pointer->getOffset(), &GetProcess().GetTarget());
address.SetLoadAddress(pointer->getResolvedAddress().getAddressData(),
&GetProcess().GetTarget());
Symbol *symbol = address.CalculateSymbolContextSymbol();
if (!symbol)
return {};
Expand Down Expand Up @@ -2337,8 +2338,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Existential(
return false;

uint64_t address = 0;
if (maybe_addr_or_symbol->isResolved()) {
address = maybe_addr_or_symbol->getOffset();
if (maybe_addr_or_symbol->getSymbol().empty() &&
maybe_addr_or_symbol->getOffset() == 0) {
address = maybe_addr_or_symbol->getResolvedAddress().getAddressData();
} else {
SymbolContextList sc_list;
auto &module_list = GetProcess().GetTarget().GetImages();
Expand All @@ -2357,7 +2359,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Existential(
GetDynamicTypeAndAddress_EmbeddedClass(address, existential_type);
if (!dynamic_type)
return false;
dynamic_address = maybe_addr_or_symbol->getOffset();
dynamic_address = maybe_addr_or_symbol->getResolvedAddress().getAddressData();
}
class_type_or_name.SetCompilerType(dynamic_type);
address.SetRawAddress(dynamic_address);
Expand Down