[Lldb-commits] [lldb] [lldb] Make thread until a step out plan that stops at the until points (PR #230510)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 9 06:52:25 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Felipe de Azevedo Piovezan (felipepiovezan)
<details>
<summary>Changes</summary>
Review only the second commit.
Depends on https://github.com/llvm/llvm-project/pull/230504
---
Patch is 26.66 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/230510.diff
12 Files Affected:
- (modified) lldb/include/lldb/Target/ThreadPlanStepOut.h (+12)
- (modified) lldb/include/lldb/Target/ThreadPlanStepRange.h (+5)
- (modified) lldb/include/lldb/Target/ThreadPlanStepUntil.h (+9-13)
- (modified) lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp (+5-4)
- (modified) lldb/source/Target/ThreadPlanStepOut.cpp (+23-2)
- (modified) lldb/source/Target/ThreadPlanStepRange.cpp (+15-1)
- (modified) lldb/source/Target/ThreadPlanStepUntil.cpp (+58-191)
- (modified) lldb/test/API/functionalities/inline-frame-pc/TestInlineFrameUntil.py (+15)
- (modified) lldb/test/API/functionalities/inline-frame-pc/main.c (+4)
- (added) lldb/test/API/functionalities/thread/step_until_recursive/Makefile (+3)
- (added) lldb/test/API/functionalities/thread/step_until_recursive/TestStepUntilRecursive.py (+27)
- (added) lldb/test/API/functionalities/thread/step_until_recursive/main.c (+14)
``````````diff
diff --git a/lldb/include/lldb/Target/ThreadPlanStepOut.h b/lldb/include/lldb/Target/ThreadPlanStepOut.h
index ad4434be14120a..72670c85e52f9b 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepOut.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepOut.h
@@ -51,6 +51,13 @@ class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
}
protected:
+ ThreadPlanStepOut(ThreadPlanKind kind, const char *name, Thread &thread,
+ SymbolContext *addr_context, bool first_insn,
+ bool stop_others, Vote report_stop_vote,
+ Vote report_run_vote, uint32_t frame_idx,
+ LazyBool step_out_avoids_code_without_debug_info,
+ bool continue_to_next_branch, bool gather_return_value);
+
void SetFlagsToDefault() override {
GetFlags().Set(ThreadPlanStepOut::s_default_flag_values);
}
@@ -59,6 +66,10 @@ class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
bool QueueInlinedStepPlan(bool queue_now);
+ /// If any ThreadPlans StepRange are enqueued by this plan, they won't explain
+ /// stops for `break_ids`, deferring back to this plan.
+ void SetBreakpointsToYieldTo(llvm::ArrayRef<lldb::break_id_t> break_ids);
+
private:
static uint32_t s_default_flag_values; // These are the default flag values
// for the ThreadPlanStepThrough.
@@ -83,6 +94,7 @@ class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
lldb::ValueObjectSP m_return_valobj_sp;
bool m_calculate_return_value;
StreamString m_constructor_errors;
+ std::vector<lldb::break_id_t> m_breakpoints_to_yield_to;
friend lldb::ThreadPlanSP Thread::QueueThreadPlanForStepOut(
bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
diff --git a/lldb/include/lldb/Target/ThreadPlanStepRange.h b/lldb/include/lldb/Target/ThreadPlanStepRange.h
index 001f3d9fa8957c..f27e16aaf0b496 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepRange.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepRange.h
@@ -40,6 +40,10 @@ class ThreadPlanStepRange : public ThreadPlan {
void AddRange(const AddressRange &new_range);
+ /// A stop at a site that holds one of \p break_ids is not explained by this
+ /// plan. They must be IDs of internal breakpoints.
+ void SetBreakpointsToYieldTo(llvm::ArrayRef<lldb::break_id_t> break_ids);
+
protected:
bool InRange();
lldb::FrameComparison CompareCurrentFrameToStartFrame();
@@ -92,6 +96,7 @@ class ThreadPlanStepRange : public ThreadPlan {
private:
std::vector<lldb::DisassemblerSP> m_instruction_ranges;
+ std::vector<lldb::break_id_t> m_breakpoints_to_yield_to;
ThreadPlanStepRange(const ThreadPlanStepRange &) = delete;
const ThreadPlanStepRange &operator=(const ThreadPlanStepRange &) = delete;
diff --git a/lldb/include/lldb/Target/ThreadPlanStepUntil.h b/lldb/include/lldb/Target/ThreadPlanStepUntil.h
index 82f05a50b7c68e..176ea5c331b797 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepUntil.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepUntil.h
@@ -10,11 +10,11 @@
#define LLDB_TARGET_THREADPLANSTEPUNTIL_H
#include "lldb/Target/Thread.h"
-#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
namespace lldb_private {
-class ThreadPlanStepUntil : public ThreadPlan {
+class ThreadPlanStepUntil : public ThreadPlanStepOut {
public:
ThreadPlanStepUntil(Thread &thread, llvm::ArrayRef<lldb::addr_t> address_list,
bool stop_others, uint32_t frame_idx = 0);
@@ -24,30 +24,26 @@ class ThreadPlanStepUntil : public ThreadPlan {
void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
bool ValidatePlan(Stream *error) override;
bool ShouldStop(Event *event_ptr) override;
- bool StopOthers() override;
- lldb::StateType GetPlanRunState() override;
bool WillStop() override;
bool MischiefManaged() override;
+ bool IsPlanStale() override;
protected:
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
bool DoPlanExplainsStop(Event *event_ptr) override;
- void AnalyzeStop();
-
private:
+ /// Returns the site of the stop if it holds an until point.
+ lldb::BreakpointSiteSP GetUntilPointSite();
+ /// Completes the plan if frame zero is the until frame.
+ void CompleteIfInUntilFrame();
+
StackID m_stack_id;
lldb::addr_t m_step_from_insn;
- lldb::break_id_t m_return_bp_id;
- lldb::addr_t m_return_addr;
- bool m_stepped_out;
- bool m_should_stop;
- bool m_ran_analyze;
- bool m_explains_stop;
+ bool m_reached_until_point = false;
typedef std::map<lldb::addr_t, lldb::break_id_t> until_collection;
until_collection m_until_points;
- bool m_stop_others;
void Clear();
void SetUntilPointsEnabled(bool enabled);
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
index c212541c3b1cfc..f9cfd2eb0ee08c 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
@@ -237,12 +237,13 @@ bool AppleThreadPlanStepThroughObjCTrampoline::WillStop() { return true; }
// since we can't just return control to the plan that's controlling us on the
// first step.
-AppleThreadPlanStepThroughDirectDispatch ::
+AppleThreadPlanStepThroughDirectDispatch::
AppleThreadPlanStepThroughDirectDispatch(
Thread &thread, AppleObjCTrampolineHandler &handler)
- : ThreadPlanStepOut(thread, nullptr, true /* first instruction */, false,
- eVoteNoOpinion, eVoteNoOpinion,
- 0 /* Step out of zeroth frame */,
+ : ThreadPlanStepOut(ThreadPlan::eKindStepOut,
+ "Step through ObjC direct dispatch", thread, nullptr,
+ true /* first instruction */, false, eVoteNoOpinion,
+ eVoteNoOpinion, 0 /* Step out of zeroth frame */,
eLazyBoolNo /* Our parent plan will decide this
when we are done */
,
diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp b/lldb/source/Target/ThreadPlanStepOut.cpp
index 34608000f1d4f8..cd5bc456ec8582 100644
--- a/lldb/source/Target/ThreadPlanStepOut.cpp
+++ b/lldb/source/Target/ThreadPlanStepOut.cpp
@@ -64,8 +64,19 @@ ThreadPlanStepOut::ThreadPlanStepOut(
Vote report_stop_vote, Vote report_run_vote, uint32_t frame_idx,
LazyBool step_out_avoids_code_without_debug_info,
bool continue_to_next_branch, bool gather_return_value)
- : ThreadPlan(ThreadPlan::eKindStepOut, "Step out", thread, report_stop_vote,
- report_run_vote),
+ : ThreadPlanStepOut(ThreadPlan::eKindStepOut, "Step out", thread, context,
+ first_insn, stop_others, report_stop_vote,
+ report_run_vote, frame_idx,
+ step_out_avoids_code_without_debug_info,
+ continue_to_next_branch, gather_return_value) {}
+
+ThreadPlanStepOut::ThreadPlanStepOut(
+ ThreadPlanKind kind, const char *name, Thread &thread,
+ SymbolContext *context, bool first_insn, bool stop_others,
+ Vote report_stop_vote, Vote report_run_vote, uint32_t frame_idx,
+ LazyBool step_out_avoids_code_without_debug_info,
+ bool continue_to_next_branch, bool gather_return_value)
+ : ThreadPlan(kind, name, thread, report_stop_vote, report_run_vote),
ThreadPlanShouldStopHere(this), m_step_from_insn(LLDB_INVALID_ADDRESS),
m_return_bp_id(LLDB_INVALID_BREAK_ID),
m_return_addr(LLDB_INVALID_ADDRESS), m_stop_others(stop_others),
@@ -514,6 +525,8 @@ bool ThreadPlanStepOut::QueueInlinedStepPlan(bool queue_now) {
ThreadPlanStepOverRange *step_through_inline_plan_ptr =
static_cast<ThreadPlanStepOverRange *>(
m_step_through_inline_plan_sp.get());
+ step_through_inline_plan_ptr->SetBreakpointsToYieldTo(
+ m_breakpoints_to_yield_to);
m_step_through_inline_plan_sp->SetPrivate(true);
step_through_inline_plan_ptr->SetOkayToDiscard(true);
@@ -539,6 +552,14 @@ bool ThreadPlanStepOut::QueueInlinedStepPlan(bool queue_now) {
return false;
}
+void ThreadPlanStepOut::SetBreakpointsToYieldTo(
+ llvm::ArrayRef<break_id_t> break_ids) {
+ m_breakpoints_to_yield_to = std::move(break_ids);
+ if (m_step_through_inline_plan_sp)
+ static_cast<ThreadPlanStepOverRange *>(m_step_through_inline_plan_sp.get())
+ ->SetBreakpointsToYieldTo(m_breakpoints_to_yield_to);
+}
+
void ThreadPlanStepOut::CalculateReturnValue() {
if (m_return_valobj_sp)
return;
diff --git a/lldb/source/Target/ThreadPlanStepRange.cpp b/lldb/source/Target/ThreadPlanStepRange.cpp
index 92225906b601ef..148cd7e4ba1b31 100644
--- a/lldb/source/Target/ThreadPlanStepRange.cpp
+++ b/lldb/source/Target/ThreadPlanStepRange.cpp
@@ -86,6 +86,16 @@ void ThreadPlanStepRange::AddRange(const AddressRange &new_range) {
m_instruction_ranges.push_back(DisassemblerSP());
}
+void ThreadPlanStepRange::SetBreakpointsToYieldTo(
+ llvm::ArrayRef<lldb::break_id_t> break_ids) {
+ assert(llvm::all_of(break_ids,
+ [](lldb::break_id_t break_id) {
+ return LLDB_BREAK_ID_IS_INTERNAL(break_id);
+ }) &&
+ "only internal breakpoints can be yielded to");
+ m_breakpoints_to_yield_to = break_ids;
+}
+
void ThreadPlanStepRange::DumpRanges(Stream *s) {
size_t num_ranges = m_address_ranges.size();
if (num_ranges == 1) {
@@ -476,7 +486,11 @@ bool ThreadPlanStepRange::NextRangeBreakpointExplainsStop(
// continue. If one is not internal, then we should not explain the stop,
// and let the user breakpoint handle the stop.
for (size_t i = 0; i < num_constituents; i++) {
- if (!bp_site_sp->GetConstituentAtIndex(i)->GetBreakpoint().IsInternal()) {
+ BreakpointLocation &bp_loc = *bp_site_sp->GetConstituentAtIndex(i);
+ Breakpoint &bp = bp_loc.GetBreakpoint();
+ if (!bp.IsInternal() ||
+ (llvm::is_contained(m_breakpoints_to_yield_to, bp.GetID()) &&
+ bp_loc.ValidForThisThread(GetThread()))) {
explains_stop = false;
break;
}
diff --git a/lldb/source/Target/ThreadPlanStepUntil.cpp b/lldb/source/Target/ThreadPlanStepUntil.cpp
index dfb92abc1371eb..e619f020cfa273 100644
--- a/lldb/source/Target/ThreadPlanStepUntil.cpp
+++ b/lldb/source/Target/ThreadPlanStepUntil.cpp
@@ -9,10 +9,7 @@
#include "lldb/Target/ThreadPlanStepUntil.h"
#include "lldb/Breakpoint/Breakpoint.h"
-#include "lldb/Symbol/SymbolContextScope.h"
#include "lldb/Target/Process.h"
-#include "lldb/Target/RegisterContext.h"
-#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
@@ -26,73 +23,52 @@ using namespace lldb_private;
ThreadPlanStepUntil::ThreadPlanStepUntil(Thread &thread,
llvm::ArrayRef<addr_t> address_list,
bool stop_others, uint32_t frame_idx)
- : ThreadPlan(ThreadPlan::eKindStepUntil, "Step until", thread,
- eVoteNoOpinion, eVoteNoOpinion),
- m_step_from_insn(LLDB_INVALID_ADDRESS),
- m_return_bp_id(LLDB_INVALID_BREAK_ID),
- m_return_addr(LLDB_INVALID_ADDRESS), m_stepped_out(false),
- m_should_stop(false), m_ran_analyze(false), m_explains_stop(false),
- m_until_points(), m_stop_others(stop_others) {
+ : ThreadPlanStepOut(ThreadPlan::eKindStepUntil, "Step until", thread,
+ /*addr_context=*/nullptr, /*first_insn=*/false,
+ stop_others, eVoteNoOpinion, eVoteNoOpinion, frame_idx,
+ /*step_out_avoids_code_without_debug_info=*/eLazyBoolNo,
+ /*continue_to_next_branch=*/false,
+ /*gather_return_value=*/false),
+ m_step_from_insn(LLDB_INVALID_ADDRESS) {
+ ClearShouldStopHereCallbacks();
+
StackFrameSP frame_sp(thread.GetStackFrameAtIndex(frame_idx));
if (!frame_sp)
return;
m_step_from_insn = frame_sp->GetStackID().GetPC();
- Target &target = GetTarget();
-
- // Find the return address and set a breakpoint there:
- // FIXME - can we do this more securely if we know first_insn?
-
- StackFrameSP return_frame_sp(thread.GetStackFrameAtIndex(frame_idx + 1));
- if (return_frame_sp) {
- // TODO: add inline functionality
- m_return_addr = return_frame_sp->GetStackID().GetPC();
- Breakpoint *return_bp =
- target.CreateBreakpoint(m_return_addr, true, false).get();
-
- if (return_bp != nullptr) {
- if (return_bp->IsHardware() && !return_bp->HasResolvedLocations())
- m_could_not_resolve_hw_bp = true;
- return_bp->SetThreadID(m_tid);
- m_return_bp_id = return_bp->GetID();
- return_bp->SetBreakpointKind("until-return-backstop");
- }
- }
-
m_stack_id = frame_sp->GetStackID();
+ Target &target = GetTarget();
+ std::vector<break_id_t> until_bp_ids;
for (addr_t address : address_list) {
Breakpoint *until_bp = target.CreateBreakpoint(address, true, false).get();
if (until_bp != nullptr) {
until_bp->SetThreadID(m_tid);
m_until_points[address] = until_bp->GetID();
until_bp->SetBreakpointKind("until-target");
+ until_bp_ids.push_back(until_bp->GetID());
} else {
m_until_points[address] = LLDB_INVALID_BREAK_ID;
}
}
+ SetBreakpointsToYieldTo(std::move(until_bp_ids));
}
ThreadPlanStepUntil::~ThreadPlanStepUntil() { Clear(); }
void ThreadPlanStepUntil::Clear() {
Target &target = GetTarget();
- if (m_return_bp_id != LLDB_INVALID_BREAK_ID) {
- target.RemoveBreakpointByID(m_return_bp_id);
- m_return_bp_id = LLDB_INVALID_BREAK_ID;
- }
-
for (const auto &[address, break_id] : m_until_points)
target.RemoveBreakpointByID(break_id);
m_until_points.clear();
- m_could_not_resolve_hw_bp = false;
}
void ThreadPlanStepUntil::GetDescription(Stream *s,
lldb::DescriptionLevel level) {
if (level == lldb::eDescriptionLevelBrief) {
s->PutCString("step until");
- if (m_stepped_out)
+ if (IsPlanComplete() && !m_reached_until_point)
s->PutCString(" - stepped out");
return;
}
@@ -109,160 +85,60 @@ void ThreadPlanStepUntil::GetDescription(Stream *s,
for (const auto &[address, break_id] : m_until_points)
s->Printf("\n\t0x%" PRIx64 " (bp: %d)", (uint64_t)address, break_id);
}
- s->Printf(" stepped out address is 0x%" PRIx64 ".", (uint64_t)m_return_addr);
+ s->PutCString("\n");
+ ThreadPlanStepOut::GetDescription(s, level);
}
bool ThreadPlanStepUntil::ValidatePlan(Stream *error) {
- if (m_could_not_resolve_hw_bp) {
- if (error)
- error->PutCString(
- "Could not create hardware breakpoint for thread plan.");
- return false;
- }
- if (m_return_bp_id == LLDB_INVALID_BREAK_ID) {
- if (error)
- error->PutCString("Could not create return breakpoint.");
- return false;
- }
for (const auto &[address, break_id] : m_until_points)
if (!LLDB_BREAK_ID_IS_VALID(break_id))
return false;
- return true;
+ return ThreadPlanStepOut::ValidatePlan(error);
}
-void ThreadPlanStepUntil::AnalyzeStop() {
- if (m_ran_analyze)
- return;
-
+BreakpointSiteSP ThreadPlanStepUntil::GetUntilPointSite() {
StopInfoSP stop_info_sp = GetPrivateStopInfo();
- m_should_stop = true;
- m_explains_stop = false;
-
- if (stop_info_sp) {
- StopReason reason = stop_info_sp->GetStopReason();
-
- if (reason == eStopReasonBreakpoint) {
- // If this is OUR breakpoint, we're fine, otherwise we don't know why
- // this happened...
- BreakpointSiteSP this_site =
- m_process.GetBreakpointSiteList().FindByID(stop_info_sp->GetValue());
- if (!this_site) {
- m_explains_stop = false;
- return;
- }
-
- if (this_site->IsBreakpointAtThisSite(m_return_bp_id)) {
- // If we are at our "step out" breakpoint, and the stack depth has
- // shrunk, then this is indeed our stop. If the stack depth has grown,
- // then we've hit our step out breakpoint recursively. If we are the
- // only breakpoint at that location, then we do explain the stop, and
- // we'll just continue. If there was another breakpoint here, then we
- // don't explain the stop, but we won't mark ourselves Completed,
- // because maybe that breakpoint will continue, and then we'll finish
- // the "until".
- bool done;
- StackID cur_frame_zero_id;
-
- done = (m_stack_id.IsYoungerThan(cur_frame_zero_id));
-
- if (done) {
- m_stepped_out = true;
- SetPlanComplete();
- } else
- m_should_stop = false;
-
- if (this_site->GetNumberOfConstituents() == 1)
- m_explains_stop = true;
- else
- m_explains_stop = false;
- return;
- } else {
- // Check if we've hit one of our "until" breakpoints.
- until_collection::iterator pos, end = m_until_points.end();
- for (pos = m_until_points.begin(); pos != end; pos++) {
- if (this_site->IsBreakpointAtThisSite((*pos).second)) {
- // If we're at the right stack depth, then we're done.
- Thread &thread = GetThread();
- bool done;
- StackID frame_zero_id =
- thread.GetStackFrameAtIndex(0)->GetStackID();
+ if (!stop_info_sp || stop_info_sp->GetStopReason() != eStopReasonBreakpoint)
+ return nullptr;
- if (frame_zero_id == m_stack_id)
- done = true;
- else if (frame_zero_id.IsYoungerThan(m_stack_id))
- done = false;
- else {
- StackFrameSP older_frame_sp = thread.GetStackFrameAtIndex(1);
+ BreakpointSiteSP site_sp =
+ m_process.GetBreakpointSiteList().FindByID(stop_info_sp->GetValue());
+ if (!site_sp)
+ return nullptr;
- // But if we can't even unwind one frame we should just get out
- // of here & stop...
- if (older_frame_sp) {
- const SymbolContext &older_context =
- older_frame_sp->GetSymbolContext(eSymbolContextEverything);
- SymbolContext stack_context;
- m_stack_id.GetSymbolContextScope()->CalculateSymbolContext(
- &stack_context);
-
- done = (older_context == stack_context);
- } else
- done = false;
- }
-
- if (done)
- SetPlanComplete();
- else
- m_should_stop = false;
+ for (const auto &[address, break_id] : m_until_points)
+ if (site_sp->IsBreakpointAtThisSite(break_id))
+ return site_sp;
+ return nullptr;
+}
- // Otherwise we've hit this breakpoint recursively. If we're the
- // only breakpoint here, then we do explain the stop, and we'll
- // continue. If not then we should let higher plans handle this
- // stop.
- if (this_site->GetNumberOfConstituents() == 1)
- m_explains_stop = true;
- else {
- m_should_stop = true;
- m_explains_stop = false;
- }
- return;
- }
- }
- }
- // If we get here we haven't hit any of our breakpoints, so let the
- // higher plans take care of the stop.
- m_explains_stop = false;
- return;
- } else if (IsUsuallyUnexplainedStopReason(reason)) {
- m_explains_stop = false;
- } else {
- m_explains_stop = true;
- }
- }
+void ThreadPlanStepUntil::CompleteIfInUntilFrame() {
+ StackID frame_zero_id = GetThread().GetStackFrameAtIndex(0)->GetStackID();
+ // Hits in younger frames, e.g. recursive calls, do not count.
+ if (frame_zero_id.IsYoungerThan(m_stack_id))
+ return;
+ m_reached_until_point = true;
+ SetPlanComplete();
}
bool ThreadPlanStepUntil::DoPlanExplainsStop(Event *event_ptr) {
- // We...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/230510
More information about the lldb-commits
mailing list