-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[lldb-dap] Refactoring lldb-dap port listening mode to allow multiple connections. #116392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
420153f
[lldb-dap] Refactoring lldb-dap port listening mode to allow multiple…
ashgti bf10b15
Applying review comments.
ashgti 088ddfb
Ensuring the server mode tracks active DAP sessions and adding an int…
ashgti ef62918
Using a std::condition_variable to notify the main thread after all D…
ashgti 1ccd9ff
Refactoring to TestDAP_server tests to not create an extra client con…
ashgti 43097eb
Moving connection handling to its own helper to simplify main and app…
ashgti 709da7d
Rewording an error message.
ashgti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
C_SOURCES := main.c | ||
|
||
include Makefile.rules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
""" | ||
Test lldb-dap server integration. | ||
""" | ||
|
||
import os | ||
import signal | ||
import tempfile | ||
|
||
import dap_server | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
import lldbdap_testcase | ||
|
||
|
||
class TestDAP_server(lldbdap_testcase.DAPTestCaseBase): | ||
def start_server(self, connection): | ||
log_file_path = self.getBuildArtifact("dap.txt") | ||
(process, connection) = dap_server.DebugAdaptorServer.launch( | ||
executable=self.lldbDAPExec, | ||
connection=connection, | ||
log_file=log_file_path, | ||
) | ||
|
||
def cleanup(): | ||
process.terminate() | ||
|
||
self.addTearDownHook(cleanup) | ||
|
||
return (process, connection) | ||
|
||
def run_debug_session(self, connection, name): | ||
self.dap_server = dap_server.DebugAdaptorServer( | ||
connection=connection, | ||
) | ||
program = self.getBuildArtifact("a.out") | ||
source = "main.c" | ||
breakpoint_line = line_number(source, "// breakpoint") | ||
|
||
self.launch( | ||
program, | ||
args=[name], | ||
disconnectAutomatically=False, | ||
) | ||
self.set_source_breakpoints(source, [breakpoint_line]) | ||
self.continue_to_next_stop() | ||
self.continue_to_exit() | ||
output = self.get_stdout() | ||
self.assertEqual(output, f"Hello {name}!\r\n") | ||
self.dap_server.request_disconnect() | ||
|
||
def test_server_port(self): | ||
""" | ||
Test launching a binary with a lldb-dap in server mode on a specific port. | ||
""" | ||
self.build() | ||
(_, connection) = self.start_server(connection="tcp://localhost:0") | ||
self.run_debug_session(connection, "Alice") | ||
self.run_debug_session(connection, "Bob") | ||
|
||
@skipIfWindows | ||
def test_server_unix_socket(self): | ||
""" | ||
Test launching a binary with a lldb-dap in server mode on a unix socket. | ||
""" | ||
dir = tempfile.gettempdir() | ||
ashgti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
name = dir + "/dap-connection-" + str(os.getpid()) | ||
|
||
def cleanup(): | ||
os.unlink(name) | ||
|
||
self.addTearDownHook(cleanup) | ||
|
||
self.build() | ||
(_, connection) = self.start_server(connection="unix://" + name) | ||
self.run_debug_session(connection, "Alice") | ||
self.run_debug_session(connection, "Bob") | ||
|
||
@skipIfWindows | ||
def test_server_interrupt(self): | ||
""" | ||
Test launching a binary with lldb-dap in server mode and shutting down the server while the debug session is still active. | ||
""" | ||
self.build() | ||
(process, connection) = self.start_server(connection="tcp://localhost:0") | ||
self.dap_server = dap_server.DebugAdaptorServer( | ||
connection=connection, | ||
) | ||
program = self.getBuildArtifact("a.out") | ||
source = "main.c" | ||
breakpoint_line = line_number(source, "// breakpoint") | ||
|
||
self.launch( | ||
program, | ||
args=["Alice"], | ||
disconnectAutomatically=False, | ||
) | ||
self.set_source_breakpoints(source, [breakpoint_line]) | ||
self.continue_to_next_stop() | ||
|
||
# Interrupt the server which should disconnect all clients. | ||
process.send_signal(signal.SIGINT) | ||
|
||
self.dap_server.wait_for_terminated() | ||
self.assertIsNone( | ||
self.dap_server.exit_status, | ||
"Process exited before interrupting lldb-dap server", | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char const *argv[]) { | ||
if (argc == 2) { // breakpoint 1 | ||
printf("Hello %s!\n", argv[1]); | ||
} else { | ||
printf("Hello World!\n"); | ||
} | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# RUN: lldb-dap --help | FileCheck %s | ||
# CHECK: --connection | ||
# CHECK: -g | ||
# CHECK: --help | ||
# CHECK: -h | ||
# CHECK: --port | ||
# CHECK: -p | ||
# CHECK: --repl-mode | ||
# CHECK: --wait-for-debugger | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.