Skip to content

Commit 0734da1

Browse files
authored
Don't create a swift async unwind plan when in a function prologue (#2645)
* Don't create a swift async unwind plan when in a function prologue If a swift async function does a standard ABI function call into a normal function, at the start, we will still have the caller's async register values (e.g. deref frame pointer shows us an AsyncContext address with high-nibble flags set). This patch changes SwiftLanguageRuntime to detect when we are in the middle of a function prologue, and not return an async unwind plan in that case. * If Function found for $pc, don't also look at Symbol
1 parent 1ce17af commit 0734da1

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lldb/source/Target/SwiftLanguageRuntime.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,8 @@ SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
22992299
RegisterContext *regctx,
23002300
bool &behaves_like_zeroth_frame) {
23012301

2302-
ArchSpec arch = process_sp->GetTarget().GetArchitecture();
2302+
Target &target(process_sp->GetTarget());
2303+
ArchSpec arch = target.GetArchitecture();
23032304
uint32_t async_context_regnum;
23042305
uint32_t fp_regnum;
23052306
uint32_t pc_regnum;
@@ -2335,6 +2336,35 @@ SwiftLanguageRuntime::GetRuntimeUnwindPlan(ProcessSP process_sp,
23352336
return UnwindPlanSP();
23362337
}
23372338

2339+
// If we're in the prologue of a function, don't provide a Swift async
2340+
// unwind plan. We can be tricked by unmodified caller-registers that
2341+
// make this look like an async frame when this is a standard ABI function
2342+
// call, and the parent is the async frame.
2343+
// This assumes that the frame pointer register will be modified in the
2344+
// prologue.
2345+
Address pc;
2346+
pc.SetLoadAddress(regctx->GetPC(), &target);
2347+
SymbolContext sc;
2348+
if (pc.IsValid()) {
2349+
pc.CalculateSymbolContext(&sc,
2350+
eSymbolContextFunction | eSymbolContextSymbol);
2351+
if (sc.function) {
2352+
Address func_start_addr = sc.function->GetAddressRange().GetBaseAddress();
2353+
AddressRange prologue_range(func_start_addr,
2354+
sc.function->GetPrologueByteSize());
2355+
if (prologue_range.ContainsLoadAddress(pc, &target)) {
2356+
return UnwindPlanSP();
2357+
}
2358+
} else if (sc.symbol) {
2359+
Address func_start_addr = sc.symbol->GetAddress();
2360+
AddressRange prologue_range(func_start_addr,
2361+
sc.symbol->GetPrologueByteSize());
2362+
if (prologue_range.ContainsLoadAddress(pc, &target)) {
2363+
return UnwindPlanSP();
2364+
}
2365+
}
2366+
}
2367+
23382368
addr_t saved_fp = LLDB_INVALID_ADDRESS;
23392369
Status error;
23402370
if (!process_sp->ReadMemory(fp, &saved_fp, 8, error))

0 commit comments

Comments
 (0)