https://github.com/da-viper created 
https://github.com/llvm/llvm-project/pull/180056

>From https://github.com/llvm/llvm-project/pull/179202#discussion_r2757981118

>From 6d3f678ae70630714d900dcd50576d8945784552 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <[email protected]>
Date: Thu, 5 Feb 2026 22:48:30 +0000
Subject: [PATCH] [lldb-dap][NFC] Create helper function
 DAP::ProcessIsNotStopped

---
 lldb/tools/lldb-dap/DAP.cpp                                 | 5 +++++
 lldb/tools/lldb-dap/DAP.h                                   | 2 ++
 lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp      | 3 +--
 lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp          | 2 +-
 lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp    | 3 +--
 lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp    | 3 +--
 lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp        | 2 +-
 lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp | 3 +--
 lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp       | 2 +-
 lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp   | 3 +--
 10 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 5ef384706aab0..2eee318237d49 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -208,6 +208,11 @@ void DAP::PopulateExceptionBreakpoints() {
   }
 }
 
+bool DAP::ProcessIsNotStopped() {
+  const lldb::StateType process_state = target.GetProcess().GetState();
+  return !lldb::SBDebugger::StateIsStoppedState(process_state);
+}
+
 ExceptionBreakpoint *DAP::GetExceptionBreakpoint(llvm::StringRef filter) {
   for (auto &bp : exception_breakpoints) {
     if (bp.GetFilter() == filter)
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 657105c8dd6b9..34d6a29b3c110 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -255,6 +255,8 @@ struct DAP final : public DAPTransport::MessageHandler {
 
   void PopulateExceptionBreakpoints();
 
+  bool ProcessIsNotStopped();
+
   /// Attempt to determine if an expression is a variable expression or
   /// lldb command using a heuristic based on the first term of the
   /// expression.
diff --git a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
index 0eb5c57732350..82a011b8088df 100644
--- a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
@@ -97,8 +97,7 @@ EvaluateRequestHandler::Run(const EvaluateArguments 
&arguments) const {
     return body;
   }
 
-  const lldb::StateType process_state = dap.target.GetProcess().GetState();
-  if (!lldb::SBDebugger::StateIsStoppedState(process_state))
+  if (dap.ProcessIsNotStopped())
     return llvm::make_error<DAPError>(
         "Cannot evaluate expressions while the process is running. Pause "
         "the process and try again.",
diff --git a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
index ecb086b36c817..59df5498943f2 100644
--- a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
@@ -27,7 +27,7 @@ namespace lldb_dap {
 /// adapter first sends the response and then a `stopped` event (with reason
 /// `step`) after the step has completed.
 Error NextRequestHandler::Run(const NextArguments &args) const {
-  if (!SBDebugger::StateIsStoppedState(dap.target.GetProcess().GetState()))
+  if (dap.ProcessIsNotStopped())
     return make_error<NotStoppedError>();
 
   lldb::SBThread thread = dap.GetLLDBThread(args.threadId);
diff --git a/lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp
index 374dc4516aa2d..32752f51284ec 100644
--- a/lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp
@@ -21,8 +21,7 @@ llvm::Expected<protocol::ReadMemoryResponseBody>
 ReadMemoryRequestHandler::Run(const protocol::ReadMemoryArguments &args) const 
{
   const lldb::addr_t raw_address = args.memoryReference + args.offset;
 
-  lldb::SBProcess process = dap.target.GetProcess();
-  if (!lldb::SBDebugger::StateIsStoppedState(process.GetState()))
+  if (dap.ProcessIsNotStopped())
     return llvm::make_error<NotStoppedError>();
 
   const uint64_t count_read = std::max<uint64_t>(args.count, 1);
diff --git a/lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp
index 9dc9b3735734d..6e6f9b0e5b285 100644
--- a/lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp
@@ -190,8 +190,7 @@ static bool FillStackFrames(DAP &dap, lldb::SBThread 
&thread,
 
 llvm::Expected<protocol::StackTraceResponseBody>
 StackTraceRequestHandler::Run(const protocol::StackTraceArguments &args) const 
{
-  const lldb::StateType process_state = dap.target.GetProcess().GetState();
-  if (!lldb::SBDebugger::StateIsStoppedState(process_state))
+  if (dap.ProcessIsNotStopped())
     return llvm::make_error<NotStoppedError>();
 
   lldb::SBThread thread = dap.GetLLDBThread(args.threadId);
diff --git a/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp
index 8f11d10389b1c..ba4457e62731c 100644
--- a/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp
@@ -32,7 +32,7 @@ namespace lldb_dap {
 // possible targets for a given source line can be retrieved via the
 // `stepInTargets` request.
 Error StepInRequestHandler::Run(const StepInArguments &args) const {
-  if (!SBDebugger::StateIsStoppedState(dap.target.GetProcess().GetState()))
+  if (dap.ProcessIsNotStopped())
     return make_error<NotStoppedError>();
 
   SBThread thread = dap.GetLLDBThread(args.threadId);
diff --git a/lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp
index 6aaa59af9e4d9..2b41626bb74fb 100644
--- a/lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp
@@ -24,8 +24,7 @@ namespace lldb_dap {
 // `supportsStepInTargetsRequest` is true.
 llvm::Expected<StepInTargetsResponseBody>
 StepInTargetsRequestHandler::Run(const StepInTargetsArguments &args) const {
-  const lldb::StateType process_state = dap.target.GetProcess().GetState();
-  if (!lldb::SBDebugger::StateIsStoppedState(process_state))
+  if (dap.ProcessIsNotStopped())
     return llvm::make_error<NotStoppedError>();
 
   dap.step_in_targets.clear();
diff --git a/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp
index baf790a5f27f0..61bde76e08a3d 100644
--- a/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp
@@ -30,7 +30,7 @@ namespace lldb_dap {
 /// The debug adapter first sends the response and then a `stopped` event (with
 /// reason `step`) after the step has completed."
 Error StepOutRequestHandler::Run(const StepOutArguments &arguments) const {
-  if (!SBDebugger::StateIsStoppedState(dap.target.GetProcess().GetState()))
+  if (dap.ProcessIsNotStopped())
     return make_error<NotStoppedError>();
 
   lldb::SBThread thread = dap.GetLLDBThread(arguments.threadId);
diff --git a/lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp
index 3e34e488d1158..17406ce1426e6 100644
--- a/lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp
@@ -27,8 +27,7 @@ llvm::Expected<WriteMemoryResponseBody>
 WriteMemoryRequestHandler::Run(const WriteMemoryArguments &args) const {
   const lldb::addr_t address = args.memoryReference + args.offset;
 
-  lldb::SBProcess process = dap.target.GetProcess();
-  if (!lldb::SBDebugger::StateIsStoppedState(process.GetState()))
+  if (dap.ProcessIsNotStopped())
     return llvm::make_error<NotStoppedError>();
 
   if (args.data.empty()) {

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to