diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp index 98a9c1dfd2c9a..d7c938e4d1b81 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp @@ -53,6 +53,7 @@ enum class ThunkAction { Unknown = 0, GetThunkTarget, StepIntoConformance, + StepIntoAllocatingInit, StepThrough, }; @@ -336,7 +337,7 @@ static const char *GetThunkKindName(ThunkKind kind) { case ThunkKind::Unknown: return "Unknown"; case ThunkKind::AllocatingInit: - return "StepThrough"; + return "StepIntoAllocatingInit"; case ThunkKind::PartialApply: return "GetThunkTarget"; case ThunkKind::ObjCAttribute: @@ -353,7 +354,7 @@ static ThunkAction GetThunkAction(ThunkKind kind) { case ThunkKind::Unknown: return ThunkAction::Unknown; case ThunkKind::AllocatingInit: - return ThunkAction::StepThrough; + return ThunkAction::StepIntoAllocatingInit; case ThunkKind::PartialApply: return ThunkAction::GetThunkTarget; case ThunkKind::ObjCAttribute: @@ -589,17 +590,40 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, thread, sym_addr_range, sc, function_name.c_str(), eOnlyDuringStepping, eLazyBoolNo, eLazyBoolNo); } + case ThunkAction::StepIntoAllocatingInit: { + LLDB_LOGF(log, "Stepping into allocating init: \"%s\"", symbol_name); + swift::Demangle::Context ctx; + NodePointer demangled_node = + SwiftLanguageRuntime::DemangleSymbolAsNode(symbol_name, ctx); + + using Kind = Node::Kind; + NodePointer function_node = childAtPath( + demangled_node, {Kind::Allocator, Kind::Class, Kind::Identifier}); + if (!function_node || !function_node->hasText()) { + std::string node_str = getNodeTreeAsString(demangled_node); + LLDB_LOGF(log, + "Failed to extract constructor name from demangle node: %s", + node_str.c_str()); + return nullptr; + } + StringRef class_name = function_node->getText(); + std::string ctor_name = (class_name + ".init").str(); + AddressRange sym_addr_range(sc.symbol->GetAddress(), + sc.symbol->GetByteSize()); + ThreadPlanSP new_plan_sp = std::make_shared( + thread, sym_addr_range, sc, ctor_name.c_str(), eOnlyDuringStepping, + eLazyBoolNo, eLazyBoolNo); + return new_plan_sp; + } case ThunkAction::StepThrough: { if (log) log->Printf("Stepping through thunk: %s kind: %s", symbol_name, GetThunkKindName(thunk_kind)); AddressRange sym_addr_range(sc.symbol->GetAddress(), sc.symbol->GetByteSize()); - ThreadPlanSP new_plan_sp = std::make_shared(thread, sym_addr_range, sc, - nullptr, eOnlyDuringStepping, - eLazyBoolNo, eLazyBoolNo); - static_cast(new_plan_sp.get()) - ->GetFlags().Clear(ThreadPlanShouldStopHere::eStepOutPastThunks); + ThreadPlanSP new_plan_sp = std::make_shared( + thread, sym_addr_range, sc, nullptr, eOnlyDuringStepping, eLazyBoolNo, + eLazyBoolNo); return new_plan_sp; } } diff --git a/lldb/test/API/lang/swift/cxx_interop/backward/stepping/TestSwiftBackwardInteropStepping.py b/lldb/test/API/lang/swift/cxx_interop/backward/stepping/TestSwiftBackwardInteropStepping.py index 29f4eed6269af..8ebc198781d9e 100644 --- a/lldb/test/API/lang/swift/cxx_interop/backward/stepping/TestSwiftBackwardInteropStepping.py +++ b/lldb/test/API/lang/swift/cxx_interop/backward/stepping/TestSwiftBackwardInteropStepping.py @@ -53,7 +53,6 @@ def test_method_step_over_class(self): thread = self.setup('Break here for method - class') self.check_step_over(thread, 'testMethod') - @expectedFailureAll(bugnumber="rdar://106670255") @swiftTest def test_init_step_in_class(self): thread = self.setup('Break here for constructor - class') @@ -115,7 +114,6 @@ def test_method_step_over_struct_class(self): thread = self.setup('Break here for method - struct') self.check_step_over(thread, 'testMethod') - @expectedFailureAll(bugnumber="rdar://106670255") @swiftTest def test_init_step_in_struct_class(self): thread = self.setup('Break here for constructor - struct') diff --git a/lldb/test/API/lang/swift/step_through_allocating_init/TestStepThroughAllocatingInit.py b/lldb/test/API/lang/swift/step_through_allocating_init/TestStepThroughAllocatingInit.py index 5911f1da164b6..897e6bc2b114a 100644 --- a/lldb/test/API/lang/swift/step_through_allocating_init/TestStepThroughAllocatingInit.py +++ b/lldb/test/API/lang/swift/step_through_allocating_init/TestStepThroughAllocatingInit.py @@ -25,18 +25,6 @@ def setUp(self): lldbtest.TestBase.setUp(self) self.main_source = "main.swift" self.main_source_spec = lldb.SBFileSpec(self.main_source) - # If you are running against a debug swift you are going to - # end up stepping into the stdlib and that will make stepping - # tests impossible to write. So avoid that. - - if platform.system() == 'Darwin': - lib_name = "libswiftCore.dylib" - else: - lib_name = "libswiftCore.so" - - self.dbg.HandleCommand( - "settings set " - "target.process.thread.step-avoid-libraries {}".format(lib_name)) def do_test(self, use_api): """Tests that we can step reliably in swift code."""