Skip to content

Commit 098fb7f

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 098fb7f

File tree

13 files changed

+147
-763
lines changed

13 files changed

+147
-763
lines changed

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

Lines changed: 7 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import shutil
1515
import json
1616
from threading import Thread
17+
import signal
1718

1819

1920
class TestDAP_runInTerminal(lldbdap_testcase.DAPTestCaseBase):
@@ -30,6 +31,7 @@ def readErrorMessage(self, fifo_file):
3031
return file.readline()
3132

3233
def isTestSupported(self):
34+
return True
3335
# For some strange reason, this test fails on python3.6
3436
if not (sys.version_info.major == 3 and sys.version_info.minor >= 7):
3537
return False
@@ -144,97 +146,21 @@ def test_missingArgInRunInTerminalLauncher(self):
144146
)
145147
self.assertNotEqual(proc.returncode, 0)
146148
self.assertIn(
147-
'"--launch-target" requires "--comm-file" to be specified', proc.stderr
149+
'"--launch-target" requires "--debugger-pid" to be specified', proc.stderr
148150
)
149151

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-
225152
@skipIfWindows
226153
@skipIf(oslist=["linux"], archs=no_match(["x86_64"]))
227154
def test_NonAttachedRunInTerminalLauncher(self):
228155
if not self.isTestSupported():
229156
return
230-
comm_file = os.path.join(self.getBuildDir(), "comm-file")
231-
os.mkfifo(comm_file)
157+
signal.signal(signal.SIGUSR1, signal.SIG_IGN)
232158

233159
proc = subprocess.Popen(
234160
[
235161
self.lldbDAPExec,
236-
"--comm-file",
237-
comm_file,
162+
"--debugger-pid",
163+
str(os.getpid()),
238164
"--launch-target",
239165
"echo",
240166
"foo",
@@ -244,7 +170,5 @@ def test_NonAttachedRunInTerminalLauncher(self):
244170
env={**os.environ, "LLDB_DAP_RIT_TIMEOUT_IN_MS": "1000"},
245171
)
246172

247-
self.readPidMessage(comm_file)
248-
249173
_, stderr = proc.communicate()
250-
self.assertIn("Timed out trying to get messages from the debug adapter", stderr)
174+
self.assertIn("runInTerminal target did not resume in time", 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)