@@ -53,6 +53,7 @@ enum class ThunkAction {
53
53
Unknown = 0 ,
54
54
GetThunkTarget,
55
55
StepIntoConformance,
56
+ StepIntoAllocatingInit,
56
57
StepThrough,
57
58
};
58
59
@@ -336,7 +337,7 @@ static const char *GetThunkKindName(ThunkKind kind) {
336
337
case ThunkKind::Unknown:
337
338
return " Unknown" ;
338
339
case ThunkKind::AllocatingInit:
339
- return " StepThrough " ;
340
+ return " StepIntoAllocatingInit " ;
340
341
case ThunkKind::PartialApply:
341
342
return " GetThunkTarget" ;
342
343
case ThunkKind::ObjCAttribute:
@@ -353,7 +354,7 @@ static ThunkAction GetThunkAction(ThunkKind kind) {
353
354
case ThunkKind::Unknown:
354
355
return ThunkAction::Unknown;
355
356
case ThunkKind::AllocatingInit:
356
- return ThunkAction::StepThrough ;
357
+ return ThunkAction::StepIntoAllocatingInit ;
357
358
case ThunkKind::PartialApply:
358
359
return ThunkAction::GetThunkTarget;
359
360
case ThunkKind::ObjCAttribute:
@@ -589,18 +590,50 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
589
590
thread, sym_addr_range, sc, function_name.c_str (), eOnlyDuringStepping,
590
591
eLazyBoolNo, eLazyBoolNo);
591
592
}
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
+ }
592
627
case ThunkAction::StepThrough: {
593
628
if (log )
594
629
log ->Printf (" Stepping through thunk: %s kind: %s" , symbol_name,
595
630
GetThunkKindName (thunk_kind));
596
631
AddressRange sym_addr_range (sc.symbol ->GetAddress (),
597
632
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;
604
637
}
605
638
}
606
639
@@ -613,7 +646,15 @@ bool SwiftLanguageRuntime::IsSymbolARuntimeThunk(const Symbol &symbol) {
613
646
if (symbol_name.empty ())
614
647
return false ;
615
648
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);
617
658
}
618
659
619
660
bool SwiftLanguageRuntime::IsSwiftMangledName (llvm::StringRef name) {
0 commit comments