@@ -53,6 +53,7 @@ enum class ThunkAction {
5353 Unknown = 0 ,
5454 GetThunkTarget,
5555 StepIntoConformance,
56+ StepIntoAllocatingInit,
5657 StepThrough,
5758};
5859
@@ -336,7 +337,7 @@ static const char *GetThunkKindName(ThunkKind kind) {
336337 case ThunkKind::Unknown:
337338 return " Unknown" ;
338339 case ThunkKind::AllocatingInit:
339- return " StepThrough " ;
340+ return " StepIntoAllocatingInit " ;
340341 case ThunkKind::PartialApply:
341342 return " GetThunkTarget" ;
342343 case ThunkKind::ObjCAttribute:
@@ -353,7 +354,7 @@ static ThunkAction GetThunkAction(ThunkKind kind) {
353354 case ThunkKind::Unknown:
354355 return ThunkAction::Unknown;
355356 case ThunkKind::AllocatingInit:
356- return ThunkAction::StepThrough ;
357+ return ThunkAction::StepIntoAllocatingInit ;
357358 case ThunkKind::PartialApply:
358359 return ThunkAction::GetThunkTarget;
359360 case ThunkKind::ObjCAttribute:
@@ -589,18 +590,50 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
589590 thread, sym_addr_range, sc, function_name.c_str (), eOnlyDuringStepping,
590591 eLazyBoolNo, eLazyBoolNo);
591592 }
593+ case ThunkAction::StepIntoAllocatingInit: {
594+ LLDB_LOGF (log, " Stepping into allocating init: \" %s\" " , symbol_name);
595+ swift::Demangle::Context ctx;
596+ NodePointer demangled_node =
597+ SwiftLanguageRuntime::DemangleSymbolAsNode (symbol_name, ctx);
598+
599+ using Kind = Node::Kind;
600+ NodePointer class_node = childAtPath (
601+ demangled_node, {Kind::Allocator, Kind::Class, Kind::Identifier});
602+ if (!class_node || !class_node->hasText ()) {
603+ std::string node_str = getNodeTreeAsString (demangled_node);
604+ LLDB_LOGF (log,
605+ " Failed to extract constructor name from demangle node: %s" ,
606+ node_str.c_str ());
607+ return nullptr ;
608+ }
609+
610+ ModuleFunctionSearchOptions options{/* include_symbols*/ true ,
611+ /* include_inlines*/ true };
612+ std::string ctor_name = llvm::formatv (" {0}.init" , class_node->getText ());
613+ SymbolContextList sc_list;
614+ sc.module_sp ->FindFunctions (RegularExpression (ctor_name), options, sc_list);
615+ std::vector<addr_t > load_addresses;
616+ Target &target = thread.GetProcess ()->GetTarget ();
617+ for (const SymbolContext &ctor_sc : sc_list) {
618+ const Symbol *ctor_symbol = ctor_sc.symbol ;
619+ if (ctor_symbol)
620+ load_addresses.push_back (ctor_symbol->GetLoadAddress (&target));
621+ }
622+ if (load_addresses.empty ())
623+ return nullptr ;
624+ return std::make_shared<ThreadPlanRunToAddress>(thread, load_addresses,
625+ stop_others);
626+ }
592627 case ThunkAction::StepThrough: {
593628 if (log)
594629 log->Printf (" Stepping through thunk: %s kind: %s" , symbol_name,
595630 GetThunkKindName (thunk_kind));
596631 AddressRange sym_addr_range (sc.symbol ->GetAddress (),
597632 sc.symbol ->GetByteSize ());
598- ThreadPlanSP new_plan_sp = std::make_shared<ThreadPlanStepInRange>(thread, sym_addr_range, sc,
599- nullptr , eOnlyDuringStepping,
600- eLazyBoolNo, eLazyBoolNo);
601- static_cast <ThreadPlanStepInRange *>(new_plan_sp.get ())
602- ->GetFlags ().Clear (ThreadPlanShouldStopHere::eStepOutPastThunks);
603- return new_plan_sp;
633+ ThreadPlanSP new_plan_sp = std::make_shared<ThreadPlanStepInRange>(
634+ thread, sym_addr_range, sc, nullptr , eOnlyDuringStepping, eLazyBoolNo,
635+ eLazyBoolNo);
636+ return new_plan_sp;
604637 }
605638 }
606639
@@ -613,7 +646,15 @@ bool SwiftLanguageRuntime::IsSymbolARuntimeThunk(const Symbol &symbol) {
613646 if (symbol_name.empty ())
614647 return false ;
615648 swift::Demangle::Context demangle_ctx;
616- return demangle_ctx.isThunkSymbol (symbol_name);
649+ if (demangle_ctx.isThunkSymbol (symbol_name))
650+ return true ;
651+
652+ // These are not Thunks in the sense that they don't jump to *user* code.
653+ // But they are language symbols that should be identified as something to act
654+ // on; here, the default action of stepping out is appropriate.
655+ Node *node = demangle_ctx.demangleSymbolAsNode (symbol_name);
656+ return node && node->getKind () == Node::Kind::Global &&
657+ hasChild (node, Node::Kind::TypeMetadataAccessFunction);
617658}
618659
619660bool SwiftLanguageRuntime::IsSwiftMangledName (llvm::StringRef name) {
0 commit comments