[Lldb-commits] [lldb] [lldb] Use ArrayRef instead of pointer+size (NFC) (PR #189186)
Sergei Barannikov via lldb-commits
lldb-commits at lists.llvm.org
Sat Mar 28 11:51:56 PDT 2026
https://github.com/s-barannikov created https://github.com/llvm/llvm-project/pull/189186
While here:
* Move the constructor to the public section. Almost all ThreadPlan classes have public constructors.
* Use `std::make_shared()`. It is modern and more efficient.
>From 1ff1f41d95130800aacd84b54006b8f482aacf18 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Sat, 28 Mar 2026 21:48:56 +0300
Subject: [PATCH] [lldb] Use ArrayRef instead of pointer+size (NFC)
While here:
* Move the constructor to the public section. Almost all ThreadPlan
classes have public constructors.
* Use `std::make_shared()`. It is modern and more efficient.
---
lldb/include/lldb/Target/Thread.h | 2 +-
lldb/include/lldb/Target/ThreadPlanStepUntil.h | 11 +++--------
lldb/source/API/SBThread.cpp | 7 +++----
lldb/source/Commands/CommandObjectThread.cpp | 4 ++--
lldb/source/Target/Thread.cpp | 6 +++---
lldb/source/Target/ThreadPlanStepUntil.cpp | 13 ++++++-------
6 files changed, 18 insertions(+), 25 deletions(-)
diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h
index fe6372058c0da..c698dd8015885 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -1005,7 +1005,7 @@ class Thread : public std::enable_shared_from_this<Thread>,
bool stop_other_threads, Status &status);
virtual lldb::ThreadPlanSP QueueThreadPlanForStepUntil(
- bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses,
+ bool abort_other_plans, llvm::ArrayRef<lldb::addr_t> address_list,
bool stop_others, uint32_t frame_idx, Status &status);
virtual lldb::ThreadPlanSP
diff --git a/lldb/include/lldb/Target/ThreadPlanStepUntil.h b/lldb/include/lldb/Target/ThreadPlanStepUntil.h
index 27e1f85e9cb9e..952da55e064f3 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepUntil.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepUntil.h
@@ -16,6 +16,9 @@ namespace lldb_private {
class ThreadPlanStepUntil : public ThreadPlan {
public:
+ ThreadPlanStepUntil(Thread &thread, llvm::ArrayRef<lldb::addr_t> address_list,
+ bool stop_others, uint32_t frame_idx = 0);
+
~ThreadPlanStepUntil() override;
void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
@@ -30,10 +33,6 @@ class ThreadPlanStepUntil : public ThreadPlan {
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
bool DoPlanExplainsStop(Event *event_ptr) override;
- ThreadPlanStepUntil(Thread &thread, lldb::addr_t *address_list,
- size_t num_addresses, bool stop_others,
- uint32_t frame_idx = 0);
-
void AnalyzeStop();
private:
@@ -52,10 +51,6 @@ class ThreadPlanStepUntil : public ThreadPlan {
void Clear();
- friend lldb::ThreadPlanSP Thread::QueueThreadPlanForStepUntil(
- bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses,
- bool stop_others, uint32_t frame_idx, Status &status);
-
// Need an appropriate marker for the current stack so we can tell step out
// from step in.
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index a857a58be7f84..9efc39c70d1a4 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -846,10 +846,9 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame,
"step until target not in current function");
} else {
Status new_plan_status;
- ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil(
- abort_other_plans, &step_over_until_addrs[0],
- step_over_until_addrs.size(), stop_other_threads,
- frame_sp->GetFrameIndex(), new_plan_status));
+ ThreadPlanSP new_plan_sp = thread->QueueThreadPlanForStepUntil(
+ abort_other_plans, step_over_until_addrs, stop_other_threads,
+ frame_sp->GetFrameIndex(), new_plan_status);
if (new_plan_status.Success())
sb_error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index ab01dc59fc6af..fbfd92a578578 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -1026,8 +1026,8 @@ class CommandObjectThreadUntil : public CommandObjectParsed {
}
new_plan_sp = thread->QueueThreadPlanForStepUntil(
- abort_other_plans, &address_list.front(), address_list.size(),
- m_options.m_stop_others, m_options.m_frame_idx, new_plan_status);
+ abort_other_plans, address_list, m_options.m_stop_others,
+ m_options.m_frame_idx, new_plan_status);
if (new_plan_sp) {
// User level plans should be controlling plans so they can be
// interrupted
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index 9e977481546b9..c8e50db2316ad 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -1415,10 +1415,10 @@ ThreadPlanSP Thread::QueueThreadPlanForRunToAddress(bool abort_other_plans,
}
ThreadPlanSP Thread::QueueThreadPlanForStepUntil(
- bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses,
+ bool abort_other_plans, llvm::ArrayRef<addr_t> address_list,
bool stop_other_threads, uint32_t frame_idx, Status &status) {
- ThreadPlanSP thread_plan_sp(new ThreadPlanStepUntil(
- *this, address_list, num_addresses, stop_other_threads, frame_idx));
+ ThreadPlanSP thread_plan_sp = std::make_shared<ThreadPlanStepUntil>(
+ *this, address_list, stop_other_threads, frame_idx);
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
return thread_plan_sp;
diff --git a/lldb/source/Target/ThreadPlanStepUntil.cpp b/lldb/source/Target/ThreadPlanStepUntil.cpp
index ee0f803510e68..db2b930c1085c 100644
--- a/lldb/source/Target/ThreadPlanStepUntil.cpp
+++ b/lldb/source/Target/ThreadPlanStepUntil.cpp
@@ -24,9 +24,8 @@ using namespace lldb_private;
// the current frame
ThreadPlanStepUntil::ThreadPlanStepUntil(Thread &thread,
- lldb::addr_t *address_list,
- size_t num_addresses, bool stop_others,
- uint32_t frame_idx)
+ 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),
@@ -63,15 +62,15 @@ ThreadPlanStepUntil::ThreadPlanStepUntil(Thread &thread,
m_stack_id = frame_sp->GetStackID();
// Now set breakpoints on all our return addresses:
- for (size_t i = 0; i < num_addresses; i++) {
+ for (addr_t address : address_list) {
Breakpoint *until_bp =
- target_sp->CreateBreakpoint(address_list[i], true, false).get();
+ target_sp->CreateBreakpoint(address, true, false).get();
if (until_bp != nullptr) {
until_bp->SetThreadID(m_tid);
- m_until_points[address_list[i]] = until_bp->GetID();
+ m_until_points[address] = until_bp->GetID();
until_bp->SetBreakpointKind("until-target");
} else {
- m_until_points[address_list[i]] = LLDB_INVALID_BREAK_ID;
+ m_until_points[address] = LLDB_INVALID_BREAK_ID;
}
}
}
More information about the lldb-commits
mailing list