Skip to content

Commit 0fc719c

Browse files
[lldb][swift] Call FixCodeAddress on code addresses read from memory
In the changed code, we read a code address from memory and then attempt to use that value to create a load address. This fails in targets using high order bits for metadata, as we must first call `FixCodeAddress` so that the appropriate plugin can clean-up the address. Unfortunately, there doesn't seem to be any clean way of testing this, but this patch also adds logging in case we fail to resolve the symbol context again.
1 parent 5556acc commit 0fc719c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,10 +2806,12 @@ std::optional<lldb::addr_t> SwiftLanguageRuntime::TrySkipVirtualParentProlog(
28062806
// Get the PC of the parent frame, i.e. the continuation pointer, which is
28072807
// the second field of the CFA.
28082808
addr_t pc_location = cfa + ptr_size;
2809-
addr_t pc_value = LLDB_INVALID_ADDRESS;
2810-
process.ReadMemory(pc_location, &pc_value, ptr_size, error);
2809+
addr_t pc_value = process.ReadPointerFromMemory(pc_location, error);
28112810
if (error.Fail())
28122811
return {};
2812+
// Clear any high order bits of this code address so that SetLoadAddress works
2813+
// properly.
2814+
pc_value = process.FixCodeAddress(pc_value);
28132815

28142816
Address pc;
28152817
Target &target = process.GetTarget();
@@ -2818,11 +2820,16 @@ std::optional<lldb::addr_t> SwiftLanguageRuntime::TrySkipVirtualParentProlog(
28182820
return {};
28192821

28202822
SymbolContext sc;
2821-
if (!pc.CalculateSymbolContext(&sc,
2822-
eSymbolContextFunction | eSymbolContextSymbol))
2823-
return {};
2824-
if (!sc.symbol && !sc.function)
2823+
bool sc_ok = pc.CalculateSymbolContext(&sc, eSymbolContextFunction |
2824+
eSymbolContextSymbol);
2825+
if (!sc_ok || (!sc.symbol && !sc.function)) {
2826+
Log *log = GetLog(LLDBLog::Unwind);
2827+
LLDB_LOGF(log,
2828+
"SwiftLanguageRuntime::%s Failed to find a symbol context for "
2829+
"address 0x%" PRIx64,
2830+
__FUNCTION__, pc_value);
28252831
return {};
2832+
}
28262833

28272834
auto prologue_size = sc.symbol ? sc.symbol->GetPrologueByteSize()
28282835
: sc.function->GetPrologueByteSize();

0 commit comments

Comments
 (0)