From 49e0b3b886f68c60dbfb737688ae4959d69df130 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Thu, 16 Oct 2025 10:34:48 -0700 Subject: [PATCH 1/5] [lldb-dap] Send a 'process' event on restart. When we restart a process, send an updated 'process' event describing the newly launched process. --- lldb/tools/lldb-dap/EventHelper.cpp | 5 ++++- lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/EventHelper.cpp b/lldb/tools/lldb-dap/EventHelper.cpp index 2b9ed229405a8..ebddb4ec1f502 100644 --- a/lldb/tools/lldb-dap/EventHelper.cpp +++ b/lldb/tools/lldb-dap/EventHelper.cpp @@ -15,6 +15,7 @@ #include "Protocol/ProtocolRequests.h" #include "Protocol/ProtocolTypes.h" #include "lldb/API/SBFileSpec.h" +#include "lldb/API/SBPlatform.h" #include "llvm/Support/Error.h" #include @@ -136,7 +137,9 @@ void SendProcessEvent(DAP &dap, LaunchMethod launch_method) { EmplaceSafeString(body, "name", exe_path); const auto pid = dap.target.GetProcess().GetProcessID(); body.try_emplace("systemProcessId", (int64_t)pid); - body.try_emplace("isLocalProcess", true); + body.try_emplace("isLocalProcess", + dap.target.GetPlatform().GetName() == + lldb::SBPlatform::GetHostPlatform().GetName()); const char *startMethod = nullptr; switch (launch_method) { case Launch: diff --git a/lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp index 45dd7ddce0428..706e66fd643a3 100644 --- a/lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp @@ -124,6 +124,8 @@ void RestartRequestHandler::operator()( return; } + SendProcessEvent(dap, Attach); + // This is normally done after receiving a "configuration done" request. // Because we're restarting, configuration has already happened so we can // continue the process right away. From c8fdc73832c44a6ba873c07dc42001c4eb90a0d9 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Thu, 16 Oct 2025 13:53:49 -0700 Subject: [PATCH 2/5] Restarts should be a 'launch' configuration. --- lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp index 706e66fd643a3..100173bfc3082 100644 --- a/lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp @@ -124,7 +124,7 @@ void RestartRequestHandler::operator()( return; } - SendProcessEvent(dap, Attach); + SendProcessEvent(dap, Launch); // This is normally done after receiving a "configuration done" request. // Because we're restarting, configuration has already happened so we can From b35bc64c604c06de5937dad968a0ee64df983f61 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 17 Oct 2025 09:18:32 -0700 Subject: [PATCH 3/5] Adding `SBPlatform::IsHost` and using it in the lldb-dap event helper. --- lldb/include/lldb/API/SBPlatform.h | 2 ++ lldb/source/API/SBPlatform.cpp | 5 ++++ lldb/tools/lldb-dap/EventHelper.cpp | 41 ++++++++++++++++------------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lldb/include/lldb/API/SBPlatform.h b/lldb/include/lldb/API/SBPlatform.h index d63d2ed1eaba6..d6e768f055858 100644 --- a/lldb/include/lldb/API/SBPlatform.h +++ b/lldb/include/lldb/API/SBPlatform.h @@ -112,6 +112,8 @@ class LLDB_API SBPlatform { bool IsValid() const; + bool IsHost() const; + void Clear(); const char *GetWorkingDirectory(); diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp index ec59e27a08b30..9a0b47ce80336 100644 --- a/lldb/source/API/SBPlatform.cpp +++ b/lldb/source/API/SBPlatform.cpp @@ -331,6 +331,11 @@ SBPlatform::operator bool() const { return m_opaque_sp.get() != nullptr; } +bool SBPlatform::IsHost() const { + LLDB_INSTRUMENT_VA(this); + return m_opaque_sp.get() != nullptr && m_opaque_sp->IsHost(); +} + void SBPlatform::Clear() { LLDB_INSTRUMENT_VA(this); diff --git a/lldb/tools/lldb-dap/EventHelper.cpp b/lldb/tools/lldb-dap/EventHelper.cpp index ebddb4ec1f502..33a65831ba192 100644 --- a/lldb/tools/lldb-dap/EventHelper.cpp +++ b/lldb/tools/lldb-dap/EventHelper.cpp @@ -79,11 +79,9 @@ void SendExtraCapabilities(DAP &dap) { // { "$ref": "#/definitions/Event" }, // { // "type": "object", -// "description": "Event message for 'process' event type. The event -// indicates that the debugger has begun debugging a -// new process. Either one that it has launched, or one -// that it has attached to.", -// "properties": { +// "description": "The event indicates that the debugger has begun +// debugging a new process. Either one that it has launched, or one that +// it has attached to.", "properties": { // "event": { // "type": "string", // "enum": [ "process" ] @@ -94,31 +92,37 @@ void SendExtraCapabilities(DAP &dap) { // "name": { // "type": "string", // "description": "The logical name of the process. This is -// usually the full path to process's executable -// file. Example: /home/myproj/program.js." +// usually the full path to process's executable file. Example: +// /home/example/myproj/program.js." // }, // "systemProcessId": { // "type": "integer", -// "description": "The system process id of the debugged process. -// This property will be missing for non-system -// processes." +// "description": "The process ID of the debugged process, as +// assigned by the operating system. This property should be +// omitted for logical processes that do not map to operating +// system processes on the machine." // }, // "isLocalProcess": { // "type": "boolean", // "description": "If true, the process is running on the same -// computer as the debug adapter." +// computer as the debug adapter." // }, // "startMethod": { // "type": "string", // "enum": [ "launch", "attach", "attachForSuspendedLaunch" ], // "description": "Describes how the debug engine started -// debugging this process.", -// "enumDescriptions": [ +// debugging this process.", "enumDescriptions": [ // "Process was launched under the debugger.", // "Debugger attached to an existing process.", -// "A project launcher component has launched a new process in -// a suspended state and then asked the debugger to attach." +// "A project launcher component has launched a new process in a +// suspended state and then asked the debugger to attach." // ] +// }, +// "pointerSize": { +// "type": "integer", +// "description": "The size of a pointer or address for this +// process, in bits. This value may be used by clients when +// formatting addresses for display." // } // }, // "required": [ "name" ] @@ -127,7 +131,7 @@ void SendExtraCapabilities(DAP &dap) { // "required": [ "event", "body" ] // } // ] -// } +// }, void SendProcessEvent(DAP &dap, LaunchMethod launch_method) { lldb::SBFileSpec exe_fspec = dap.target.GetExecutable(); char exe_path[PATH_MAX]; @@ -137,9 +141,8 @@ void SendProcessEvent(DAP &dap, LaunchMethod launch_method) { EmplaceSafeString(body, "name", exe_path); const auto pid = dap.target.GetProcess().GetProcessID(); body.try_emplace("systemProcessId", (int64_t)pid); - body.try_emplace("isLocalProcess", - dap.target.GetPlatform().GetName() == - lldb::SBPlatform::GetHostPlatform().GetName()); + body.try_emplace("isLocalProcess", dap.target.GetPlatform().IsHost()); + body.try_emplace("pointerSize", dap.target.GetAddressByteSize() * 8); const char *startMethod = nullptr; switch (launch_method) { case Launch: From 9a0b097a338ae8efcdc543b10f443fe2afd73f40 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 17 Oct 2025 10:21:13 -0700 Subject: [PATCH 4/5] Also adding a python helper for a `is_host` property. --- lldb/bindings/interface/SBPlatformExtensions.i | 7 +++++++ lldb/bindings/interfaces.swig | 1 + 2 files changed, 8 insertions(+) create mode 100644 lldb/bindings/interface/SBPlatformExtensions.i diff --git a/lldb/bindings/interface/SBPlatformExtensions.i b/lldb/bindings/interface/SBPlatformExtensions.i new file mode 100644 index 0000000000000..5868a524a6a30 --- /dev/null +++ b/lldb/bindings/interface/SBPlatformExtensions.i @@ -0,0 +1,7 @@ +%extend lldb::SBPlatform { +#ifdef SWIGPYTHON + %pythoncode %{ + is_host = property(IsHost, None, doc='''A read only property that returns a boolean value that indiciates if this platform is the host platform.''') + %} +#endif +} \ No newline at end of file diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig index e71ed136f20e6..b3d44979c916c 100644 --- a/lldb/bindings/interfaces.swig +++ b/lldb/bindings/interfaces.swig @@ -53,6 +53,7 @@ %include "./interface/SBModuleSpecDocstrings.i" %include "./interface/SBMutexExtensions.i" %include "./interface/SBPlatformDocstrings.i" +%include "./interface/SBPlatformExtensions.i" %include "./interface/SBProcessDocstrings.i" %include "./interface/SBProcessInfoDocstrings.i" %include "./interface/SBProgressDocstrings.i" From 66b77f064361d0d857bb3318f2013763a0278f89 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Mon, 20 Oct 2025 11:36:55 -0700 Subject: [PATCH 5/5] Adding a doc string and newline. --- lldb/bindings/interface/SBPlatformExtensions.i | 2 +- lldb/include/lldb/API/SBPlatform.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/bindings/interface/SBPlatformExtensions.i b/lldb/bindings/interface/SBPlatformExtensions.i index 5868a524a6a30..86759bda50630 100644 --- a/lldb/bindings/interface/SBPlatformExtensions.i +++ b/lldb/bindings/interface/SBPlatformExtensions.i @@ -4,4 +4,4 @@ is_host = property(IsHost, None, doc='''A read only property that returns a boolean value that indiciates if this platform is the host platform.''') %} #endif -} \ No newline at end of file +} diff --git a/lldb/include/lldb/API/SBPlatform.h b/lldb/include/lldb/API/SBPlatform.h index d6e768f055858..7cb19b3f7ec46 100644 --- a/lldb/include/lldb/API/SBPlatform.h +++ b/lldb/include/lldb/API/SBPlatform.h @@ -112,6 +112,7 @@ class LLDB_API SBPlatform { bool IsValid() const; + /// Returns true if this platform is the host platform, otherwise false. bool IsHost() const; void Clear();