Skip to content

[lldb][swift] Create thread plan for stepping through Allocating Init #10576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: swift/release/6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enum class ThunkAction {
Unknown = 0,
GetThunkTarget,
StepIntoConformance,
StepIntoAllocatingInit,
StepThrough,
};

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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<ThreadPlanStepInRange>(
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<ThreadPlanStepInRange>(thread, sym_addr_range, sc,
nullptr, eOnlyDuringStepping,
eLazyBoolNo, eLazyBoolNo);
static_cast<ThreadPlanStepInRange *>(new_plan_sp.get())
->GetFlags().Clear(ThreadPlanShouldStopHere::eStepOutPastThunks);
ThreadPlanSP new_plan_sp = std::make_shared<ThreadPlanStepInRange>(
thread, sym_addr_range, sc, nullptr, eOnlyDuringStepping, eLazyBoolNo,
eLazyBoolNo);
return new_plan_sp;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down