Skip to content

Commit 841e1e1

Browse files
authored
[lldb-dap] Send a 'process' event on restart. (llvm#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.
1 parent 5129b37 commit 841e1e1

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%extend lldb::SBPlatform {
2+
#ifdef SWIGPYTHON
3+
%pythoncode %{
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.''')
5+
%}
6+
#endif
7+
}

lldb/bindings/interfaces.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
%include "./interface/SBModuleSpecDocstrings.i"
5454
%include "./interface/SBMutexExtensions.i"
5555
%include "./interface/SBPlatformDocstrings.i"
56+
%include "./interface/SBPlatformExtensions.i"
5657
%include "./interface/SBProcessDocstrings.i"
5758
%include "./interface/SBProcessInfoDocstrings.i"
5859
%include "./interface/SBProgressDocstrings.i"

lldb/include/lldb/API/SBPlatform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class LLDB_API SBPlatform {
112112

113113
bool IsValid() const;
114114

115+
/// Returns true if this platform is the host platform, otherwise false.
116+
bool IsHost() const;
117+
115118
void Clear();
116119

117120
const char *GetWorkingDirectory();

lldb/source/API/SBPlatform.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ SBPlatform::operator bool() const {
331331
return m_opaque_sp.get() != nullptr;
332332
}
333333

334+
bool SBPlatform::IsHost() const {
335+
LLDB_INSTRUMENT_VA(this);
336+
return m_opaque_sp.get() != nullptr && m_opaque_sp->IsHost();
337+
}
338+
334339
void SBPlatform::Clear() {
335340
LLDB_INSTRUMENT_VA(this);
336341

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Protocol/ProtocolRequests.h"
1616
#include "Protocol/ProtocolTypes.h"
1717
#include "lldb/API/SBFileSpec.h"
18+
#include "lldb/API/SBPlatform.h"
1819
#include "llvm/Support/Error.h"
1920
#include <utility>
2021

@@ -78,11 +79,9 @@ void SendExtraCapabilities(DAP &dap) {
7879
// { "$ref": "#/definitions/Event" },
7980
// {
8081
// "type": "object",
81-
// "description": "Event message for 'process' event type. The event
82-
// indicates that the debugger has begun debugging a
83-
// new process. Either one that it has launched, or one
84-
// that it has attached to.",
85-
// "properties": {
82+
// "description": "The event indicates that the debugger has begun
83+
// debugging a new process. Either one that it has launched, or one that
84+
// it has attached to.", "properties": {
8685
// "event": {
8786
// "type": "string",
8887
// "enum": [ "process" ]
@@ -93,31 +92,37 @@ void SendExtraCapabilities(DAP &dap) {
9392
// "name": {
9493
// "type": "string",
9594
// "description": "The logical name of the process. This is
96-
// usually the full path to process's executable
97-
// file. Example: /home/myproj/program.js."
95+
// usually the full path to process's executable file. Example:
96+
// /home/example/myproj/program.js."
9897
// },
9998
// "systemProcessId": {
10099
// "type": "integer",
101-
// "description": "The system process id of the debugged process.
102-
// This property will be missing for non-system
103-
// processes."
100+
// "description": "The process ID of the debugged process, as
101+
// assigned by the operating system. This property should be
102+
// omitted for logical processes that do not map to operating
103+
// system processes on the machine."
104104
// },
105105
// "isLocalProcess": {
106106
// "type": "boolean",
107107
// "description": "If true, the process is running on the same
108-
// computer as the debug adapter."
108+
// computer as the debug adapter."
109109
// },
110110
// "startMethod": {
111111
// "type": "string",
112112
// "enum": [ "launch", "attach", "attachForSuspendedLaunch" ],
113113
// "description": "Describes how the debug engine started
114-
// debugging this process.",
115-
// "enumDescriptions": [
114+
// debugging this process.", "enumDescriptions": [
116115
// "Process was launched under the debugger.",
117116
// "Debugger attached to an existing process.",
118-
// "A project launcher component has launched a new process in
119-
// a suspended state and then asked the debugger to attach."
117+
// "A project launcher component has launched a new process in a
118+
// suspended state and then asked the debugger to attach."
120119
// ]
120+
// },
121+
// "pointerSize": {
122+
// "type": "integer",
123+
// "description": "The size of a pointer or address for this
124+
// process, in bits. This value may be used by clients when
125+
// formatting addresses for display."
121126
// }
122127
// },
123128
// "required": [ "name" ]
@@ -126,7 +131,7 @@ void SendExtraCapabilities(DAP &dap) {
126131
// "required": [ "event", "body" ]
127132
// }
128133
// ]
129-
// }
134+
// },
130135
void SendProcessEvent(DAP &dap, LaunchMethod launch_method) {
131136
lldb::SBFileSpec exe_fspec = dap.target.GetExecutable();
132137
char exe_path[PATH_MAX];
@@ -136,7 +141,8 @@ void SendProcessEvent(DAP &dap, LaunchMethod launch_method) {
136141
EmplaceSafeString(body, "name", exe_path);
137142
const auto pid = dap.target.GetProcess().GetProcessID();
138143
body.try_emplace("systemProcessId", (int64_t)pid);
139-
body.try_emplace("isLocalProcess", true);
144+
body.try_emplace("isLocalProcess", dap.target.GetPlatform().IsHost());
145+
body.try_emplace("pointerSize", dap.target.GetAddressByteSize() * 8);
140146
const char *startMethod = nullptr;
141147
switch (launch_method) {
142148
case Launch:

lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ void RestartRequestHandler::operator()(
124124
return;
125125
}
126126

127+
SendProcessEvent(dap, Launch);
128+
127129
// This is normally done after receiving a "configuration done" request.
128130
// Because we're restarting, configuration has already happened so we can
129131
// continue the process right away.

0 commit comments

Comments
 (0)