From ad9cdfbcfdf9c7a679393d35adaf95e2b3cb6fd0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 16 May 2023 09:51:51 -0600 Subject: Add "stop at main" extension to DAP launch request Co-workers who work on a program that uses DAP asked for the ability to have gdb stop at the main subprogram when launching. This patch implements this extension. Reviewed-By: Eli Zaretskii --- gdb/python/lib/gdb/dap/launch.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gdb/python') diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 2fec326..aee8c2f 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -20,7 +20,7 @@ from typing import Mapping, Optional, Sequence from .events import ExecutionInvoker from .server import request, capability -from .startup import send_gdb, send_gdb_with_response, in_gdb_thread +from .startup import send_gdb, send_gdb_with_response, in_gdb_thread, exec_and_log _program = None @@ -36,6 +36,14 @@ 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. @@ -45,12 +53,15 @@ def launch( program: 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(f"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)) -- cgit v1.1