Skip to content

Commit b71032a

Browse files
committed
[lldb-dap] Reimplement runInTerminal with signals
runInTerminal is currently implemented using JSON messages over FIFOs, which feels too clunky for the simple job of passing a PID. Instead, take advantage of si_pid available from sa_sigaction handler, and send a user signal instead. Both synchronisation and timeout are preserved with the protocol below, 1. Debugger waits for SIGUSR1 under timeout with pselect 2. Launcher forks into child, sends SIGUSR1 to debugger and suspends 3. Debugger receives SIGUSR1, captures the sender (launcher child) PID, attaches to and resumes it 4. Launcher child resumes and exec's into target 5. Launcher parent waitpid's and kills irresponsive child after timeout With this, the entirety of FifoFiles and RunInTerminal can be dropped. Refs: #121269 (comment)
1 parent bd3c632 commit b71032a

File tree

12 files changed

+126
-796
lines changed

12 files changed

+126
-796
lines changed

lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -131,120 +131,3 @@ def test_runInTerminalInvalidTarget(self):
131131
"'INVALIDPROGRAM' does not exist",
132132
response["body"]["error"]["format"],
133133
)
134-
135-
@skipIfWindows
136-
@skipIf(oslist=["linux"], archs=no_match(["x86_64"]))
137-
def test_missingArgInRunInTerminalLauncher(self):
138-
if not self.isTestSupported():
139-
return
140-
proc = subprocess.run(
141-
[self.lldbDAPExec, "--launch-target", "INVALIDPROGRAM"],
142-
capture_output=True,
143-
universal_newlines=True,
144-
)
145-
self.assertNotEqual(proc.returncode, 0)
146-
self.assertIn(
147-
'"--launch-target" requires "--comm-file" to be specified', proc.stderr
148-
)
149-
150-
@skipIfWindows
151-
@skipIf(oslist=["linux"], archs=no_match(["x86_64"]))
152-
def test_FakeAttachedRunInTerminalLauncherWithInvalidProgram(self):
153-
if not self.isTestSupported():
154-
return
155-
comm_file = os.path.join(self.getBuildDir(), "comm-file")
156-
os.mkfifo(comm_file)
157-
158-
proc = subprocess.Popen(
159-
[
160-
self.lldbDAPExec,
161-
"--comm-file",
162-
comm_file,
163-
"--launch-target",
164-
"INVALIDPROGRAM",
165-
],
166-
universal_newlines=True,
167-
stderr=subprocess.PIPE,
168-
)
169-
170-
self.readPidMessage(comm_file)
171-
self.sendDidAttachMessage(comm_file)
172-
self.assertIn("No such file or directory", self.readErrorMessage(comm_file))
173-
174-
_, stderr = proc.communicate()
175-
self.assertIn("No such file or directory", stderr)
176-
177-
@skipIfWindows
178-
@skipIf(oslist=["linux"], archs=no_match(["x86_64"]))
179-
def test_FakeAttachedRunInTerminalLauncherWithValidProgram(self):
180-
if not self.isTestSupported():
181-
return
182-
comm_file = os.path.join(self.getBuildDir(), "comm-file")
183-
os.mkfifo(comm_file)
184-
185-
proc = subprocess.Popen(
186-
[
187-
self.lldbDAPExec,
188-
"--comm-file",
189-
comm_file,
190-
"--launch-target",
191-
"echo",
192-
"foo",
193-
],
194-
universal_newlines=True,
195-
stdout=subprocess.PIPE,
196-
)
197-
198-
self.readPidMessage(comm_file)
199-
self.sendDidAttachMessage(comm_file)
200-
201-
stdout, _ = proc.communicate()
202-
self.assertIn("foo", stdout)
203-
204-
@skipIfWindows
205-
@skipIf(oslist=["linux"], archs=no_match(["x86_64"]))
206-
def test_FakeAttachedRunInTerminalLauncherAndCheckEnvironment(self):
207-
if not self.isTestSupported():
208-
return
209-
comm_file = os.path.join(self.getBuildDir(), "comm-file")
210-
os.mkfifo(comm_file)
211-
212-
proc = subprocess.Popen(
213-
[self.lldbDAPExec, "--comm-file", comm_file, "--launch-target", "env"],
214-
universal_newlines=True,
215-
stdout=subprocess.PIPE,
216-
env={**os.environ, "FOO": "BAR"},
217-
)
218-
219-
self.readPidMessage(comm_file)
220-
self.sendDidAttachMessage(comm_file)
221-
222-
stdout, _ = proc.communicate()
223-
self.assertIn("FOO=BAR", stdout)
224-
225-
@skipIfWindows
226-
@skipIf(oslist=["linux"], archs=no_match(["x86_64"]))
227-
def test_NonAttachedRunInTerminalLauncher(self):
228-
if not self.isTestSupported():
229-
return
230-
comm_file = os.path.join(self.getBuildDir(), "comm-file")
231-
os.mkfifo(comm_file)
232-
233-
proc = subprocess.Popen(
234-
[
235-
self.lldbDAPExec,
236-
"--comm-file",
237-
comm_file,
238-
"--launch-target",
239-
"echo",
240-
"foo",
241-
],
242-
universal_newlines=True,
243-
stderr=subprocess.PIPE,
244-
env={**os.environ, "LLDB_DAP_RIT_TIMEOUT_IN_MS": "1000"},
245-
)
246-
247-
self.readPidMessage(comm_file)
248-
249-
_, stderr = proc.communicate()
250-
self.assertIn("Timed out trying to get messages from the debug adapter", stderr)

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ add_lldb_library(lldbDAP
1414
DAPLog.cpp
1515
EventHelper.cpp
1616
ExceptionBreakpoint.cpp
17-
FifoFiles.cpp
1817
FunctionBreakpoint.cpp
1918
InstructionBreakpoint.cpp
2019
JSONUtils.cpp
2120
LLDBUtils.cpp
2221
OutputRedirector.cpp
2322
ProgressEvent.cpp
2423
ProtocolUtils.cpp
25-
RunInTerminal.cpp
2624
SourceBreakpoint.cpp
2725
Transport.cpp
2826
Variables.cpp

lldb/tools/lldb-dap/FifoFiles.cpp

Lines changed: 0 additions & 101 deletions
This file was deleted.

lldb/tools/lldb-dap/FifoFiles.h

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)