[lldb-dap] Send a 'process' event on restart. (#163833)

When we restart a process, send an updated 'process' event describing
the newly launched process.

I also updated the `isLocalProcess` value based on if we're on the
'host' platform or not.
This commit is contained in:
John Harrison
2025-10-21 14:47:12 -07:00
committed by GitHub
parent 5129b37254
commit 841e1e1e17
6 changed files with 41 additions and 17 deletions

View File

@@ -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
}

View File

@@ -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"

View File

@@ -112,6 +112,9 @@ public:
bool IsValid() const;
/// Returns true if this platform is the host platform, otherwise false.
bool IsHost() const;
void Clear();
const char *GetWorkingDirectory();

View File

@@ -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);

View File

@@ -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 <utility>
@@ -78,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" ]
@@ -93,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" ]
@@ -126,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];
@@ -136,7 +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", true);
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:

View File

@@ -124,6 +124,8 @@ void RestartRequestHandler::operator()(
return;
}
SendProcessEvent(dap, Launch);
// 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.