Skip to content

Commit 166d032

Browse files
[lldb][nfc] Add customization flags for ThreadPlanStepOut
ThreadPlanStepOut always skips over Hidden/Artificial frames when computing its destination frame, without providing any customization of this behavior. This is problematic for some plans like StepThrough, which may need to step out of a frame _without_ stepping out of a Hidden/Artificial frame. Any first step towards fixing this requires the ability to customize ThreadPlanStepOut, which is what this NFC patch addresses. Since the computation of which frames to skip is done by the constructor, this patch adds a Flags parameter to `ThreadPlanStepOut::ThreadPlanStepOut`.
1 parent 98534ee commit 166d032

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

lldb/include/lldb/Target/ThreadPlanShouldStopHere.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ class ThreadPlanShouldStopHere {
6060
eAvoidInlines = (1 << 0),
6161
eStepInAvoidNoDebug = (1 << 1),
6262
eStepOutAvoidNoDebug = (1 << 2),
63-
eStepOutPastThunks = (1 << 3)
63+
eStepOutPastThunks = (1 << 3),
64+
eStepOutPastHiddenFunctions = (1 << 4),
65+
eStepOutPastArtificialFunctions = (1 << 5),
6466
};
6567

6668
// Constructors and Destructors

lldb/include/lldb/Target/ThreadPlanStepOut.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ namespace lldb_private {
1717

1818
class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
1919
public:
20-
ThreadPlanStepOut(Thread &thread, SymbolContext *addr_context,
21-
bool first_insn, bool stop_others, Vote report_stop_vote,
22-
Vote report_run_vote, uint32_t frame_idx,
23-
LazyBool step_out_avoids_code_without_debug_info,
24-
bool continue_to_next_branch = false,
25-
bool gather_return_value = true);
20+
ThreadPlanStepOut(
21+
Thread &thread, SymbolContext *addr_context, bool first_insn,
22+
bool stop_others, Vote report_stop_vote, Vote report_run_vote,
23+
uint32_t frame_idx, LazyBool step_out_avoids_code_without_debug_info,
24+
bool continue_to_next_branch = false, bool gather_return_value = true,
25+
lldb_private::Flags flags = ThreadPlanStepOut::s_default_flag_values);
2626

2727
~ThreadPlanStepOut() override;
2828

@@ -87,6 +87,9 @@ class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
8787

8888
void CalculateReturnValue();
8989

90+
lldb::StackFrameSP
91+
ComputeReturnToFrame(Thread &thread, uint32_t start_frame_idx, Flags flags);
92+
9093
ThreadPlanStepOut(const ThreadPlanStepOut &) = delete;
9194
const ThreadPlanStepOut &operator=(const ThreadPlanStepOut &) = delete;
9295
};

lldb/source/Target/ThreadPlanStepOut.cpp

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,63 @@
2929
using namespace lldb;
3030
using namespace lldb_private;
3131

32-
uint32_t ThreadPlanStepOut::s_default_flag_values = 0;
32+
uint32_t ThreadPlanStepOut::s_default_flag_values =
33+
eStepOutPastArtificialFunctions | eStepOutPastHiddenFunctions;
34+
35+
StackFrameSP ThreadPlanStepOut::ComputeReturnToFrame(Thread &thread,
36+
uint32_t start_frame_idx,
37+
Flags flags) {
38+
uint32_t frame_idx = start_frame_idx + 1;
39+
StackFrameSP return_frame_sp = thread.GetStackFrameAtIndex(frame_idx);
40+
if (!return_frame_sp)
41+
return nullptr;
42+
43+
// If asked to, step out past artificial/hidden frames.
44+
while ((flags.Test(eStepOutPastArtificialFunctions) &&
45+
return_frame_sp->IsArtificial()) ||
46+
(flags.Test(eStepOutPastHiddenFunctions) &&
47+
return_frame_sp->IsHidden())) {
48+
m_stepped_past_frames.push_back(return_frame_sp);
49+
50+
frame_idx++;
51+
return_frame_sp = thread.GetStackFrameAtIndex(frame_idx);
52+
53+
// We never expect to see an artificial frame without a regular ancestor.
54+
// Defensively refuse to step out.
55+
if (!return_frame_sp) {
56+
LLDB_LOG(GetLog(LLDBLog::Step),
57+
"Can't step out of frame with artificial ancestors");
58+
return nullptr;
59+
}
60+
}
61+
return return_frame_sp;
62+
}
3363

3464
// ThreadPlanStepOut: Step out of the current frame
3565
ThreadPlanStepOut::ThreadPlanStepOut(
3666
Thread &thread, SymbolContext *context, bool first_insn, bool stop_others,
3767
Vote report_stop_vote, Vote report_run_vote, uint32_t frame_idx,
3868
LazyBool step_out_avoids_code_without_debug_info,
39-
bool continue_to_next_branch, bool gather_return_value)
69+
bool continue_to_next_branch, bool gather_return_value, Flags flags)
4070
: ThreadPlan(ThreadPlan::eKindStepOut, "Step out", thread, report_stop_vote,
4171
report_run_vote),
4272
ThreadPlanShouldStopHere(this), m_step_from_insn(LLDB_INVALID_ADDRESS),
4373
m_return_bp_id(LLDB_INVALID_BREAK_ID),
4474
m_return_addr(LLDB_INVALID_ADDRESS), m_stop_others(stop_others),
4575
m_immediate_step_from_function(nullptr),
4676
m_calculate_return_value(gather_return_value) {
47-
Log *log = GetLog(LLDBLog::Step);
48-
SetFlagsToDefault();
77+
m_flags = flags;
4978
SetupAvoidNoDebug(step_out_avoids_code_without_debug_info);
5079

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

53-
uint32_t return_frame_index = frame_idx + 1;
54-
StackFrameSP return_frame_sp(thread.GetStackFrameAtIndex(return_frame_index));
82+
StackFrameSP return_frame_sp =
83+
ComputeReturnToFrame(thread, frame_idx, m_flags);
5584
StackFrameSP immediate_return_from_sp(thread.GetStackFrameAtIndex(frame_idx));
5685

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

60-
// While stepping out, behave as-if artificial frames are not present.
61-
while (return_frame_sp->IsArtificial() || return_frame_sp->IsHidden()) {
62-
m_stepped_past_frames.push_back(return_frame_sp);
63-
64-
++return_frame_index;
65-
return_frame_sp = thread.GetStackFrameAtIndex(return_frame_index);
66-
67-
// We never expect to see an artificial frame without a regular ancestor.
68-
// If this happens, log the issue and defensively refuse to step out.
69-
if (!return_frame_sp) {
70-
LLDB_LOG(log, "Can't step out of frame with artificial ancestors");
71-
return;
72-
}
73-
}
74-
7589
m_step_out_to_id = return_frame_sp->GetStackID();
7690
m_immediate_step_from_id = immediate_return_from_sp->GetStackID();
7791

@@ -125,6 +139,7 @@ ThreadPlanStepOut::ThreadPlanStepOut(
125139

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

0 commit comments

Comments
 (0)