From patchwork Tue Dec 12 14:33:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81969 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 863D33858033 for ; Tue, 12 Dec 2023 14:34:21 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by sourceware.org (Postfix) with ESMTPS id 904483857C4B for ; Tue, 12 Dec 2023 14:34:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 904483857C4B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 904483857C4B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702391648; cv=none; b=Ap7Rd9v9D70VgiWpQcYOQzGNaS4BuYPpj3s7cOqfi6ca16Deo+OruiissDRAt2JJS2KONBYvN09dl2C/s8U6mCdUahw57mxJpl1rcGjf4sNuP2ujHf71+i1S5sizIHr08rCEBJEdkLpu8XzFAFsyduiI4H42IsSWKHRhEzSLHIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702391648; c=relaxed/simple; bh=dfqTsUavwxE3mstIM/yuA1JoQ5IdflVl+oW451g/dgw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KhpovfX79Xh+kviI167IIhs3sSw+whtmdemfCKvytZAyDRR4KmNlTBkB2bnoqxlD2R3v43JfeWhbc/4EcTbz8uCMAOgE+MGbVZrvosvqmpwvrLI2Y1zi2yuDzPH1mXuqOXNqyPGdLY+o7qvyGMZCWeFzG+WzSZy9jRTw5RvETvs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7b7039d30acso330675039f.3 for ; Tue, 12 Dec 2023 06:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702391644; x=1702996444; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=c6BdeZjlMKRg8PIvAsNj1WD8AjiuamX+Sq8KeFTEm2A=; b=KwI/4HCwjskFGGE32CK/qfzOowChmkjzWo0cd5vQfTHFGzAIotlvU0DRxUOrab1vVD kO0aFF6I3iWlXeImAiwiaot+oYmCo17IBn51Ej1JykAFmnWOOHpz5XQwsqRKs6cb+Zhz Wug7IUP6SMb8peNYLHNgXZZf/ZaBgCkAc0OvYZglA4NcrRiQ1XsqMPch3FwE4mGfvEvA 4uJNakIYsnbXhdIvPyIrtsq3Wgf2R5070yS7vagYyJY6wfDJahGk21eShhFETQwb9ixF SzqBgh0eZRoaK9cZxm5OGNxXPMcpfFEXMT7qevV2FLIL5kGbwmbayBM7vawaZOYfny7g piFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702391644; x=1702996444; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=c6BdeZjlMKRg8PIvAsNj1WD8AjiuamX+Sq8KeFTEm2A=; b=NyGEpSUfahhOF9r3edfBzJxayn0CTAAikGQny9bFkq/yfiH3btHApzdAR7PDh2USiH 3ZosI/mQjziKSPVnMLy0K5kb1GVxZwiLjdZS2mYs36yazwF4eMH5gmj519pk14gL7cNV tz8riygMHQ2qSAohmiVdWeXwfrgh8cD/t9fJvSzXqPt7kdt38yaF8cEaGCwuUgO0V7pq 0qbankarOxy77eyzcblkhw2puC+WfeSF7ZyNIWGH39Dv4vR1iPALKstyyc60sjVRERXt 9qwbjReHT5w7wU3nwkcgfYmuMSLYiv3C/vvV0AacoNzKrfhNGKO3pkoDoT7sl4uq+2qW PlmA== X-Gm-Message-State: AOJu0YzSyQLkkPuj5zzgfhtpIKtJZip/tLvovb+dT+ShtgymQb2TDZeK u1DYrQR8DFvwrnQCjB5gAeDdSl3I2XxPd1voElo= X-Google-Smtp-Source: AGHT+IEmTshDIaDUOggNCKeOdy1E9WCuRlYazc8itP6VWjqg88X/BVX3zorvreUG93u6VG+guXIbQQ== X-Received: by 2002:a05:6602:21c8:b0:7b0:2027:efda with SMTP id c8-20020a05660221c800b007b02027efdamr7474147ioc.5.1702391644656; Tue, 12 Dec 2023 06:34:04 -0800 (PST) Received: from localhost.localdomain (71-211-161-25.hlrn.qwest.net. [71.211.161.25]) by smtp.gmail.com with ESMTPSA id g14-20020a02cd0e000000b0046455c93317sm2408581jaq.92.2023.12.12.06.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 06:34:04 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Add 'program' to DAP 'attach' request Date: Tue, 12 Dec 2023 07:33:57 -0700 Message-ID: <20231212143357.1314799-1-tromey@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org In many cases, it's not possible for gdb to discover the executable when a DAP 'attach' request is used. This patch lets the IDE supply this information. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 2 ++ gdb/doc/gdb.texinfo | 11 ++++++++++- gdb/python/lib/gdb/dap/launch.py | 25 +++++++++++++++++++++---- gdb/testsuite/gdb.dap/attach.exp | 2 +- gdb/testsuite/lib/dap-support.exp | 11 ++++++++--- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 534e2e7f364..3c17d09203d 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -88,6 +88,8 @@ show remote thread-options-packet ** GDB now supports the "cancel" request. + ** The "attach" request now supports specifying the program. + * New remote packets New stop reason: clone diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 6e4adf512ee..be79b34ad2c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -39579,12 +39579,21 @@ the same approach as the @code{start} command. @xref{Starting}. @end table @value{GDBN} defines some parameters that can be passed to the -@code{attach} request. One of these must be specified. +@code{attach} request. Either @code{pid} or @code{target} must be +specified, but if both are specified then @code{target} will be +ignored. @table @code @item pid The process ID to which @value{GDBN} should attach. @xref{Attach}. +@item program +If provided, this is a string that specifies the program to use. This +corresponds to the @code{file} command. @xref{Files}. In some cases, +@value{GDBN} can automatically determine which program is running. +However, for many remote targets, this is not the case, and so this +should be supplied. + @item target The target to which @value{GDBN} should connect. This is a string and is passed to the @code{target remote} command. @xref{Connecting}. diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 7014047ff51..675542c92d0 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -28,6 +28,11 @@ from .startup import exec_and_log _program = None +# True if the program was attached, False otherwise. This should only +# be accessed from the gdb thread. +_attach = False + + # Any parameters here are necessarily extensions -- DAP requires this # from implementations. Any additions or changes here should be # documented in the gdb manual. @@ -43,6 +48,8 @@ def launch( ): global _program _program = program + global _attach + _attach = False if cwd is not None: exec_and_log("cd " + cwd) if program is not None: @@ -60,10 +67,20 @@ def launch( @request("attach") -def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): +def attach( + *, + program: Optional[str] = None, + pid: Optional[int] = None, + target: Optional[str] = None, + **args, +): # Ensure configurationDone does not try to run. + global _attach + _attach = True global _program - _program = None + _program = program + if program is not None: + exec_and_log("file " + program) if pid is not None: cmd = "attach " + str(pid) elif target is not None: @@ -77,7 +94,7 @@ def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): @capability("supportsConfigurationDoneRequest") @request("configurationDone", response=False) def config_done(**args): - global _program - if _program is not None: + global _attach + if not _attach: expect_process("process") exec_and_expect_stop("run") diff --git a/gdb/testsuite/gdb.dap/attach.exp b/gdb/testsuite/gdb.dap/attach.exp index 5b308f94975..4d562711f09 100644 --- a/gdb/testsuite/gdb.dap/attach.exp +++ b/gdb/testsuite/gdb.dap/attach.exp @@ -29,7 +29,7 @@ set test_spawn_id [spawn_wait_for_attach $binfile] set testpid [spawn_id_get_pid $test_spawn_id] # We just want to test that attaching works at all. -if {[dap_attach $testpid] != ""} { +if {[dap_attach $testpid $binfile] != ""} { dap_shutdown true } diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index b9ac314fee5..8186148ee0a 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -306,12 +306,17 @@ proc dap_launch {file {args {}}} { # Start gdb, send a DAP initialize request, and then an attach request # specifying PID as the inferior process ID. Returns the empty string # on failure, or the response object from the attach request. -proc dap_attach {pid} { +proc dap_attach {pid {prog ""}} { if {[_dap_initialize "startup - initialize"] == ""} { return "" } - return [dap_check_request_and_response "startup - attach" attach \ - [format {o pid [i %s]} $pid]] + + set args [format {o pid [i %s]} $pid] + if {$prog != ""} { + append args [format { program [s %s]} $prog] + } + + return [dap_check_request_and_response "startup - attach" attach $args] } # Start gdb, send a DAP initialize request, and then an attach request