Add "cwd" parameter to DAP launch request

This adds the "cwd" parameter to the DAP launch request.

This came up here:
    https://github.com/eclipse-cdt-cloud/cdt-gdb-adapter/issues/90
... and seemed like a good idea.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This commit is contained in:
Tom Tromey
2023-07-24 09:14:20 -06:00
parent 7abfd03742
commit f131a57908
4 changed files with 70 additions and 17 deletions
+17 -17
View File
@@ -23,12 +23,22 @@ from .server import request, capability
from .startup import send_gdb, send_gdb_with_response, in_gdb_thread, exec_and_log
# The program being launched, or None. This should only be access
# from the DAP thread.
_program = None
@in_gdb_thread
def _set_args_env(args, env):
def _launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram):
if cwd is not None:
exec_and_log("cd " + cwd)
if program is not None:
exec_and_log("file " + program)
inf = gdb.selected_inferior()
if stopAtBeginningOfMainSubprogram:
main = inf.main_name
if main is not None:
exec_and_log("tbreak " + main)
inf.arguments = args
if env is not None:
inf.clear_env()
@@ -36,14 +46,6 @@ def _set_args_env(args, env):
inf.set_env(name, value)
@in_gdb_thread
def _break_at_main():
inf = gdb.selected_inferior()
main = inf.main_name
if main is not None:
exec_and_log("tbreak " + main)
# Any parameters here are necessarily extensions -- DAP requires this
# from implementations. Any additions or changes here should be
# documented in the gdb manual.
@@ -51,19 +53,17 @@ def _break_at_main():
def launch(
*,
program: Optional[str] = None,
cwd: Optional[str] = None,
args: Sequence[str] = (),
env: Optional[Mapping[str, str]] = None,
stopAtBeginningOfMainSubprogram: bool = False,
**extra,
):
if program is not None:
global _program
_program = program
send_gdb("file " + _program)
if stopAtBeginningOfMainSubprogram:
send_gdb(_break_at_main)
if len(args) > 0 or env is not None:
send_gdb(lambda: _set_args_env(args, env))
global _program
_program = program
send_gdb(
lambda: _launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram)
)
@request("attach")