Skip to content

[lldb][nfc] Factor out code from ThreadPlanStepOut ctor #136159

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

Merged
merged 1 commit into from
Apr 17, 2025
Merged
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
47 changes: 29 additions & 18 deletions lldb/source/Target/ThreadPlanStepOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ using namespace lldb_private;

uint32_t ThreadPlanStepOut::s_default_flag_values = 0;

/// Computes the target frame this plan should step out to.
static StackFrameSP
ComputeTargetFrame(Thread &thread, uint32_t start_frame_idx,
std::vector<StackFrameSP> &skipped_frames) {
uint32_t frame_idx = start_frame_idx + 1;
StackFrameSP return_frame_sp = thread.GetStackFrameAtIndex(frame_idx);
if (!return_frame_sp)
return nullptr;

while (return_frame_sp->IsArtificial() || return_frame_sp->IsHidden()) {
skipped_frames.push_back(return_frame_sp);

frame_idx++;
return_frame_sp = thread.GetStackFrameAtIndex(frame_idx);

// We never expect to see an artificial frame without a regular ancestor.
// Defensively refuse to step out.
if (!return_frame_sp) {
LLDB_LOG(GetLog(LLDBLog::Step),
"Can't step out of frame with artificial ancestors");
return nullptr;
}
}
return return_frame_sp;
}

// ThreadPlanStepOut: Step out of the current frame
ThreadPlanStepOut::ThreadPlanStepOut(
Thread &thread, SymbolContext *context, bool first_insn, bool stop_others,
Expand All @@ -44,34 +70,18 @@ ThreadPlanStepOut::ThreadPlanStepOut(
m_return_addr(LLDB_INVALID_ADDRESS), m_stop_others(stop_others),
m_immediate_step_from_function(nullptr),
m_calculate_return_value(gather_return_value) {
Log *log = GetLog(LLDBLog::Step);
SetFlagsToDefault();
SetupAvoidNoDebug(step_out_avoids_code_without_debug_info);

m_step_from_insn = thread.GetRegisterContext()->GetPC(0);

uint32_t return_frame_index = frame_idx + 1;
StackFrameSP return_frame_sp(thread.GetStackFrameAtIndex(return_frame_index));
StackFrameSP return_frame_sp =
ComputeTargetFrame(thread, frame_idx, m_stepped_past_frames);
StackFrameSP immediate_return_from_sp(thread.GetStackFrameAtIndex(frame_idx));

if (!return_frame_sp || !immediate_return_from_sp)
return; // we can't do anything here. ValidatePlan() will return false.

// While stepping out, behave as-if artificial frames are not present.
while (return_frame_sp->IsArtificial() || return_frame_sp->IsHidden()) {
m_stepped_past_frames.push_back(return_frame_sp);

++return_frame_index;
return_frame_sp = thread.GetStackFrameAtIndex(return_frame_index);

// We never expect to see an artificial frame without a regular ancestor.
// If this happens, log the issue and defensively refuse to step out.
if (!return_frame_sp) {
LLDB_LOG(log, "Can't step out of frame with artificial ancestors");
return;
}
}

m_step_out_to_id = return_frame_sp->GetStackID();
m_immediate_step_from_id = immediate_return_from_sp->GetStackID();

Expand Down Expand Up @@ -125,6 +135,7 @@ ThreadPlanStepOut::ThreadPlanStepOut(

// Perform some additional validation on the return address.
uint32_t permissions = 0;
Log *log = GetLog(LLDBLog::Step);
if (!m_process.GetLoadAddressPermissions(m_return_addr, permissions)) {
LLDB_LOGF(log, "ThreadPlanStepOut(%p): Return address (0x%" PRIx64
") permissions not found.", static_cast<void *>(this),
Expand Down
Loading