https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/142684
Fixes #142581 >From 7e940dcb0cfde1bc9be73c7cf2a40ba7f08d12e5 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <yerimy...@gmail.com> Date: Mon, 2 Jun 2025 17:07:50 +0100 Subject: [PATCH 1/4] [lldb-dap] Forward any error from stepping. --- lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp | 9 ++++++--- lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp | 11 +++++++---- lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp index 3fa167686d2f9..02fd77470fa08 100644 --- a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp @@ -8,6 +8,7 @@ #include "DAP.h" #include "EventHelper.h" +#include "LLDBUtils.h" #include "Protocol/ProtocolTypes.h" #include "RequestHandler.h" #include "llvm/Support/Error.h" @@ -33,13 +34,15 @@ Error NextRequestHandler::Run(const NextArguments &args) const { // Remember the thread ID that caused the resume so we can set the // "threadCausedFocus" boolean value in the "stopped" events. dap.focus_tid = thread.GetThreadID(); + lldb::SBError error; if (args.granularity == eSteppingGranularityInstruction) { - thread.StepInstruction(/*step_over=*/true); + thread.StepInstruction(/*step_over=*/true, error); } else { - thread.StepOver(args.singleThread ? eOnlyThisThread : eOnlyDuringStepping); + thread.StepOver(args.singleThread ? eOnlyThisThread : eOnlyDuringStepping, + error); } - return Error::success(); + return ToError(error); } } // namespace lldb_dap diff --git a/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp index 15f242a9e18ff..1a70be7d220c5 100644 --- a/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp @@ -8,6 +8,7 @@ #include "DAP.h" #include "EventHelper.h" +#include "LLDBUtils.h" #include "Protocol/ProtocolRequests.h" #include "Protocol/ProtocolTypes.h" #include "RequestHandler.h" @@ -39,9 +40,10 @@ Error StepInRequestHandler::Run(const StepInArguments &args) const { // "threadCausedFocus" boolean value in the "stopped" events. dap.focus_tid = thread.GetThreadID(); + lldb::SBError error; if (args.granularity == eSteppingGranularityInstruction) { - thread.StepInstruction(/*step_over=*/false); - return Error::success(); + thread.StepInstruction(/*step_over=*/false, error); + return ToError(error); } std::string step_in_target; @@ -50,8 +52,9 @@ Error StepInRequestHandler::Run(const StepInArguments &args) const { step_in_target = it->second; RunMode run_mode = args.singleThread ? eOnlyThisThread : eOnlyDuringStepping; - thread.StepInto(step_in_target.c_str(), run_mode); - return Error::success(); + thread.StepInto(step_in_target.c_str(), LLDB_INVALID_LINE_NUMBER, error, + run_mode); + return ToError(error); } } // namespace lldb_dap diff --git a/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp index 6b98582262a68..e31b38cb68bfd 100644 --- a/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp @@ -8,6 +8,7 @@ #include "DAP.h" #include "EventHelper.h" +#include "LLDBUtils.h" #include "Protocol/ProtocolRequests.h" #include "RequestHandler.h" #include "llvm/Support/Error.h" @@ -35,9 +36,10 @@ Error StepOutRequestHandler::Run(const StepOutArguments &arguments) const { // Remember the thread ID that caused the resume so we can set the // "threadCausedFocus" boolean value in the "stopped" events. dap.focus_tid = thread.GetThreadID(); - thread.StepOut(); + lldb::SBError error; + thread.StepOut(error); - return Error::success(); + return ToError(error); } } // namespace lldb_dap >From 89d2bb588e2f880d6818fe45061a0f9db0a3fdd1 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <yerimy...@gmail.com> Date: Tue, 3 Jun 2025 19:34:59 +0100 Subject: [PATCH 2/4] [lldb][lldb-dap] add review changes --- lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp | 3 +++ lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp | 3 +++ lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp index 02fd77470fa08..2b48350dfba1b 100644 --- a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp @@ -31,6 +31,9 @@ Error NextRequestHandler::Run(const NextArguments &args) const { if (!thread.IsValid()) return make_error<DAPError>("invalid thread"); + if (!SBDebugger::StateIsStoppedState(dap.target.GetProcess().GetState())) + return make_error<NotStoppedError>(); + // Remember the thread ID that caused the resume so we can set the // "threadCausedFocus" boolean value in the "stopped" events. dap.focus_tid = thread.GetThreadID(); diff --git a/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp index 1a70be7d220c5..6742c791a5486 100644 --- a/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp @@ -40,6 +40,9 @@ Error StepInRequestHandler::Run(const StepInArguments &args) const { // "threadCausedFocus" boolean value in the "stopped" events. dap.focus_tid = thread.GetThreadID(); + if (!SBDebugger::StateIsStoppedState(dap.target.GetProcess().GetState())) + return make_error<NotStoppedError>(); + lldb::SBError error; if (args.granularity == eSteppingGranularityInstruction) { thread.StepInstruction(/*step_over=*/false, error); diff --git a/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp index e31b38cb68bfd..e896e03720b6b 100644 --- a/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp @@ -33,6 +33,10 @@ Error StepOutRequestHandler::Run(const StepOutArguments &arguments) const { if (!thread.IsValid()) return make_error<DAPError>("invalid thread"); + if (!lldb::SBDebugger::StateIsStoppedState( + dap.target.GetProcess().GetState())) + return make_error<NotStoppedError>(); + // Remember the thread ID that caused the resume so we can set the // "threadCausedFocus" boolean value in the "stopped" events. dap.focus_tid = thread.GetThreadID(); >From 38f73ce39a05198ba3500539b14a75ed393ff35e Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <yerimy...@gmail.com> Date: Tue, 3 Jun 2025 23:22:30 +0100 Subject: [PATCH 3/4] [lldb] Return an error when if process save-core plugin is invalid Fixes #142581 --- lldb/source/Commands/CommandObjectProcess.cpp | 2 +- lldb/source/Symbol/SaveCoreOptions.cpp | 1 - .../command-process-save-core-not-a-plugin.test | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 lldb/test/Shell/Commands/command-process-save-core-not-a-plugin.test diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index d0f5eaf2dfd9a..b1f243c9e2777 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -1303,7 +1303,7 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed { llvm_unreachable("Unimplemented option"); } - return {}; + return error; } void OptionParsingStarting(ExecutionContext *execution_context) override { diff --git a/lldb/source/Symbol/SaveCoreOptions.cpp b/lldb/source/Symbol/SaveCoreOptions.cpp index e51ae27954934..d884b00a47b00 100644 --- a/lldb/source/Symbol/SaveCoreOptions.cpp +++ b/lldb/source/Symbol/SaveCoreOptions.cpp @@ -24,7 +24,6 @@ Status SaveCoreOptions::SetPluginName(const char *name) { if (!PluginManager::IsRegisteredObjectFilePluginName(name)) { return Status::FromErrorStringWithFormat( "plugin name '%s' is not a valid ObjectFile plugin name", name); - return error; } m_plugin_name = name; diff --git a/lldb/test/Shell/Commands/command-process-save-core-not-a-plugin.test b/lldb/test/Shell/Commands/command-process-save-core-not-a-plugin.test new file mode 100644 index 0000000000000..bd23777998a40 --- /dev/null +++ b/lldb/test/Shell/Commands/command-process-save-core-not-a-plugin.test @@ -0,0 +1,16 @@ +# RUN: %clang_host -g %S/Inputs/main.c -o %t +# RUN: %lldb %t -s %s -o exit 2>&1 | FileCheck %s + +b main +# CHECK-LABEL: b main +# CHECK: Breakpoint 1: where = {{.*}}`main + +run +# CHECK-LABEL: run +# CHECK: Process {{.*}} stopped +# CHECK: stop reason = breakpoint 1 +# CHECK: frame #0: {{.*}}`main at main.c + +process save-core --plugin-name=notaplugin dump +# CHECK-LABEL: process save-core --plugin-name=notaplugin dump +# CHECK: error: plugin name 'notaplugin' is not a valid ObjectFile plugin name >From 4ecdda7af64f4579d87c23470753970a959abbdf Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <yerimy...@gmail.com> Date: Tue, 3 Jun 2025 23:27:22 +0100 Subject: [PATCH 4/4] [lldb] Add test note --- .../Shell/Commands/command-process-save-core-not-a-plugin.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lldb/test/Shell/Commands/command-process-save-core-not-a-plugin.test b/lldb/test/Shell/Commands/command-process-save-core-not-a-plugin.test index bd23777998a40..c034c8ebbf87d 100644 --- a/lldb/test/Shell/Commands/command-process-save-core-not-a-plugin.test +++ b/lldb/test/Shell/Commands/command-process-save-core-not-a-plugin.test @@ -1,3 +1,6 @@ +# This checks that lldb returns an error if process save-core is called +# with a plugin that does not exist. + # RUN: %clang_host -g %S/Inputs/main.c -o %t # RUN: %lldb %t -s %s -o exit 2>&1 | FileCheck %s _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits