Skip to content

Commit 5c02b8d

Browse files
Merge pull request #9412 from felipepiovezan/felipe/simplify_trampolineplan
[lldb][nfc] Simplify swift's GetStepThroughTrampolinePlan
2 parents fbf0ce9 + d6747ee commit 5c02b8d

File tree

1 file changed

+29
-41
lines changed

1 file changed

+29
-41
lines changed

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

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -442,42 +442,37 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
442442
// 3) Thunks that retain captured objects in closure invocations.
443443
// 4) Task switches for async functions.
444444

445-
ThreadPlanSP new_thread_plan_sp;
446-
447445
Log *log(GetLog(LLDBLog::Step));
448446
StackFrameSP stack_sp = thread.GetStackFrameAtIndex(0);
449447
if (!stack_sp)
450-
return new_thread_plan_sp;
448+
return nullptr;
451449

452450
SymbolContext sc = stack_sp->GetSymbolContext(eSymbolContextEverything);
453451
Symbol *symbol = sc.symbol;
454452

455453
if (!symbol)
456-
return new_thread_plan_sp;
454+
return nullptr;
457455

458456
// Only do this if you are at the beginning of the thunk function:
459457
lldb::addr_t cur_addr = thread.GetRegisterContext()->GetPC();
460458
lldb::addr_t symbol_addr =
461459
symbol->GetAddress().GetLoadAddress(&thread.GetProcess()->GetTarget());
462460

463461
if (symbol_addr != cur_addr)
464-
return new_thread_plan_sp;
462+
return nullptr;
465463

466-
Address target_address;
467464
const char *symbol_name = symbol->GetMangled().GetMangledName().AsCString();
468465

469466
ThunkKind thunk_kind = GetThunkKind(symbol);
470467
ThunkAction thunk_action = GetThunkAction(thunk_kind);
471468

472469
switch (thunk_action) {
473470
case ThunkAction::Unknown:
474-
return new_thread_plan_sp;
475-
case ThunkAction::AsyncStepIn: {
476-
if (ThreadPlanStepInAsync::NeedsStep(sc)) {
477-
new_thread_plan_sp.reset(new ThreadPlanStepInAsync(thread, sc));
478-
}
479-
return new_thread_plan_sp;
480-
}
471+
return nullptr;
472+
case ThunkAction::AsyncStepIn:
473+
if (ThreadPlanStepInAsync::NeedsStep(sc))
474+
return std::make_shared<ThreadPlanStepInAsync>(thread, sc);
475+
return nullptr;
481476
case ThunkAction::GetThunkTarget: {
482477
swift::Demangle::Context demangle_ctx;
483478
std::string thunk_target = demangle_ctx.getThunkTarget(symbol_name);
@@ -486,7 +481,7 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
486481
log->Printf("Stepped to thunk \"%s\" (kind: %s) but could not "
487482
"find the thunk target. ",
488483
symbol_name, GetThunkKindName(thunk_kind));
489-
return new_thread_plan_sp;
484+
return nullptr;
490485
}
491486
if (log)
492487
log->Printf(
@@ -497,14 +492,15 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
497492
SymbolContextList sc_list;
498493
modules.FindFunctionSymbols(ConstString(thunk_target),
499494
eFunctionNameTypeFull, sc_list);
500-
if (sc_list.GetSize() == 1) {
501-
SymbolContext sc;
502-
sc_list.GetContextAtIndex(0, sc);
503-
504-
if (sc.symbol)
505-
target_address = sc.symbol->GetAddress();
495+
if (sc_list.GetSize() == 1 && sc_list[0].symbol) {
496+
Symbol &thunk_symbol = *sc_list[0].symbol;
497+
Address target_address = thunk_symbol.GetAddress();
498+
if (target_address.IsValid())
499+
return std::make_shared<ThreadPlanRunToAddress>(thread, target_address,
500+
stop_others);
506501
}
507-
} break;
502+
return nullptr;
503+
}
508504
case ThunkAction::StepIntoConformance: {
509505
// The TTW symbols encode the protocol conformance requirements
510506
// and it is possible to go to the AST and get it to replay the
@@ -538,7 +534,7 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
538534
"find the ProtocolWitness node in the demangled "
539535
"nodes.",
540536
symbol_name);
541-
return new_thread_plan_sp;
537+
return nullptr;
542538
}
543539

544540
size_t num_children = witness_node->getNumChildren();
@@ -547,7 +543,7 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
547543
log->Printf("Stepped into witness thunk \"%s\" but the "
548544
"ProtocolWitness node doesn't have enough nodes.",
549545
symbol_name);
550-
return new_thread_plan_sp;
546+
return nullptr;
551547
}
552548

553549
swift::Demangle::NodePointer function_node = witness_node->getChild(1);
@@ -557,7 +553,7 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
557553
log->Printf("Stepped into witness thunk \"%s\" but could not "
558554
"find the function in the ProtocolWitness node.",
559555
symbol_name);
560-
return new_thread_plan_sp;
556+
return nullptr;
561557
}
562558

563559
// Okay, now find the name of this function.
@@ -576,7 +572,7 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
576572
log->Printf("Stepped into witness thunk \"%s\" but could not "
577573
"find the Function name in the function node.",
578574
symbol_name);
579-
return new_thread_plan_sp;
575+
return nullptr;
580576
}
581577

582578
std::string function_name(name_node->getText());
@@ -585,38 +581,30 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
585581
log->Printf("Stepped into witness thunk \"%s\" but the Function "
586582
"name was empty.",
587583
symbol_name);
588-
return new_thread_plan_sp;
584+
return nullptr;
589585
}
590586

591587
// We have to get the address range of the thunk symbol, and make a
592588
// "step through range stepping in"
593589
AddressRange sym_addr_range(sc.symbol->GetAddress(),
594590
sc.symbol->GetByteSize());
595-
new_thread_plan_sp.reset(new ThreadPlanStepInRange(
591+
return std::make_shared<ThreadPlanStepInRange>(
596592
thread, sym_addr_range, sc, function_name.c_str(), eOnlyDuringStepping,
597-
eLazyBoolNo, eLazyBoolNo));
598-
return new_thread_plan_sp;
599-
600-
} break;
593+
eLazyBoolNo, eLazyBoolNo);
594+
}
601595
case ThunkAction::StepThrough: {
602596
if (log)
603597
log->Printf("Stepping through thunk: %s kind: %s", symbol_name,
604598
GetThunkKindName(thunk_kind));
605599
AddressRange sym_addr_range(sc.symbol->GetAddress(),
606600
sc.symbol->GetByteSize());
607-
new_thread_plan_sp.reset(new ThreadPlanStepInRange(
608-
thread, sym_addr_range, sc, nullptr, eOnlyDuringStepping, eLazyBoolNo,
609-
eLazyBoolNo));
610-
return new_thread_plan_sp;
611-
} break;
601+
return std::make_shared<ThreadPlanStepInRange>(thread, sym_addr_range, sc,
602+
nullptr, eOnlyDuringStepping,
603+
eLazyBoolNo, eLazyBoolNo);
612604
}
613-
614-
if (target_address.IsValid()) {
615-
new_thread_plan_sp.reset(
616-
new ThreadPlanRunToAddress(thread, target_address, stop_others));
617605
}
618606

619-
return new_thread_plan_sp;
607+
return nullptr;
620608
}
621609

622610
bool SwiftLanguageRuntime::IsSymbolARuntimeThunk(const Symbol &symbol) {

0 commit comments

Comments
 (0)