Skip to content

Commit ce1c618

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. (cherry picked from commit 0fc719c)
1 parent d8bea71 commit ce1c618

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
@@ -2807,10 +2807,12 @@ std::optional<lldb::addr_t> SwiftLanguageRuntime::TrySkipVirtualParentProlog(
28072807
// Get the PC of the parent frame, i.e. the continuation pointer, which is
28082808
// the second field of the CFA.
28092809
addr_t pc_location = cfa + ptr_size;
2810-
addr_t pc_value = LLDB_INVALID_ADDRESS;
2811-
process.ReadMemory(pc_location, &pc_value, ptr_size, error);
2810+
addr_t pc_value = process.ReadPointerFromMemory(pc_location, error);
28122811
if (error.Fail())
28132812
return {};
2813+
// Clear any high order bits of this code address so that SetLoadAddress works
2814+
// properly.
2815+
pc_value = process.FixCodeAddress(pc_value);
28142816

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

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

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

0 commit comments

Comments
 (0)