From patchwork Tue Jul 25 13:49:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 73156 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 2D9E6385AF93 for ; Tue, 25 Jul 2023 13:50:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D9E6385AF93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690293008; bh=7qSGsMG+tlXDTeR3dMUqxlMO6dKF5VSwIJZqGAqdjNQ=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=woyNaPkg03MwgtodpSzpf6MUh8Qzh42lZMJ+byBLMdp3PnW24fQ+M8vsFaECPg9jX qSovFHPxsoyHLQRFfPkRFO32Ub86H9Glx2//1KAhH2xqJLqZMSrRZ1ttgWe27j1qR9 JMZ1wIMKM7U7xzGJH1ltZN/WEwH3s3VqgM223JAw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id 767D23857710 for ; Tue, 25 Jul 2023 13:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 767D23857710 Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-78666f06691so235812039f.0 for ; Tue, 25 Jul 2023 06:49:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690292980; x=1690897780; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7qSGsMG+tlXDTeR3dMUqxlMO6dKF5VSwIJZqGAqdjNQ=; b=a4OG+KRVVvuNddRiSHqhiB/Lxq72XSk0tdgbTfHqdt25+L0vIdWIKpMlhmgFd1F2Dt MahoscRlgphmW8AUdhEJIWYyoRfWxOttDhso+/IajREm/5SshoipN6dmg2v5/vQexqWL k6ATz+BIQzbCcV8ZfaOzFWASKSJdXv4qusXdB0zhQe1Bes6YDid4ANKrjsqVA5tuMuZ9 jx9BabLjeY6OyA6+9KlDd2q86cHv1mF+jHjOjhTioolA3Iwfvvbp+klP+FLy0e28bNl6 4Ad4rA+BJeDSzf8C4DzwFCh86bdmdIobvCDx+c2hP3+UW6t8E0D9I6MQogX9JajzLzaR yqWg== X-Gm-Message-State: ABy/qLYoEMp8KD5XOLmiAxhzXnbs8cFmATYKyplF9+0gCPwAd/rqcCB/ P3Jp/pKgDXATkNqFbsov/DwrGU8rAVwVNo4FLaJZWg== X-Google-Smtp-Source: APBJJlFtwGvQ5te7PZfiBavxLtVKt7Xtc0xlFq5QZUUkOHB7U8HM0YcWU2Y97aAyWbgTaD8qsrxs9g== X-Received: by 2002:a6b:7e06:0:b0:785:d06d:7b04 with SMTP id i6-20020a6b7e06000000b00785d06d7b04mr2778448iom.1.1690292980331; Tue, 25 Jul 2023 06:49:40 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id c3-20020a02a403000000b00418a5e0e93esm3595018jal.162.2023.07.25.06.49.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:49:40 -0700 (PDT) Date: Tue, 25 Jul 2023 07:49:38 -0600 Subject: [PATCH 1/6] Rename private member of FrameDecorator MIME-Version: 1.0 Message-Id: <20230725-dap-bt-path-v1-1-bb015b0d8e54@adacore.com> References: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In Python, a member name starting with "__" is specially handled to make it private to the class. This patch ensures that this is done for the private method of FrameDecorator. --- gdb/python/lib/gdb/FrameDecorator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdb/python/lib/gdb/FrameDecorator.py b/gdb/python/lib/gdb/FrameDecorator.py index 050cb934b7c..c4a7806e434 100644 --- a/gdb/python/lib/gdb/FrameDecorator.py +++ b/gdb/python/lib/gdb/FrameDecorator.py @@ -53,7 +53,7 @@ class FrameDecorator(object): self._base = base @staticmethod - def _is_limited_frame(frame): + def __is_limited_frame(frame): """Internal utility to determine if the frame is special or limited.""" sal = frame.find_sal() @@ -148,7 +148,7 @@ class FrameDecorator(object): return self._base.frame_args() frame = self.inferior_frame() - if self._is_limited_frame(frame): + if self.__is_limited_frame(frame): return None args = FrameVars(frame) @@ -164,7 +164,7 @@ class FrameDecorator(object): return self._base.frame_locals() frame = self.inferior_frame() - if self._is_limited_frame(frame): + if self.__is_limited_frame(frame): return None args = FrameVars(frame) @@ -179,7 +179,7 @@ class FrameDecorator(object): return self._base.line() frame = self.inferior_frame() - if self._is_limited_frame(frame): + if self.__is_limited_frame(frame): return None sal = frame.find_sal() From patchwork Tue Jul 25 13:49:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 73158 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 46204385AFAC for ; Tue, 25 Jul 2023 13:50:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46204385AFAC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690293039; bh=OyaliUezp7QBgzRaNuBpSIdFn7jIaoea0a8lklcedHk=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QZ4u0G3FW4gUgYYxeRFUOPzxkaQle3SM7V7B01NMCjnY0VdQkJGdj0nKNz0FtdqWu e1omOS98t7K4y/9xV4nQHUns+TZLzUXhURaFoMJc7bLUpGXYmqAUeMppoPf28aCM+O oztNInn1mQD4enbKTZbpPHMz9Ee7HQ5vRZ/DGWFw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id CBA313857719 for ; Tue, 25 Jul 2023 13:49:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBA313857719 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7869bcee569so208553539f.0 for ; Tue, 25 Jul 2023 06:49:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690292981; x=1690897781; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OyaliUezp7QBgzRaNuBpSIdFn7jIaoea0a8lklcedHk=; b=KLlenUNsjYL3giiNDJokbhgs8WUq5shpCIjen3wsCfcZ3i9cPS5F9+oJ5jU5ceX0TW 6OCZq88F0SrUvFzXPjT4cUP2T6YIKSqBQklpexzGcnX2eXvbsfyDmfweYE/eOWYN2C3Z dTbuOQmWQAN/Z9y5v2mkpuKxUK7LcVqJKAP4SP0LaUMiY45uCyv5OY4cMSh2A0VlMN3b 1JCAqEcCYImTScsou2YKfFZKUSOQ2J7NWgO+w4EpxH0elltMrREk9mGfCBGncRUUjTVT d09cv89owDC+LCsNX+D5uG5JTuIG+P/zlm18XdH4GfXpXOq0HbcGS0GZAIDytk/aFo8O p8Ng== X-Gm-Message-State: ABy/qLa/tpFMp+wY2vFElkKyRDRCKitrXrhJnQ8Got0gGemdiY9+0ImE /GEWTqdkK2n+j51ZAJhLVwZBy8aNQE1sx7JhFcT8pA== X-Google-Smtp-Source: APBJJlGe9bLfVo4Fuvr834t/r7HqVBPvMgBGg56VzjJ2rj+a+gBjh92vK8+PwdSqsB6tvCtgxkF5Pw== X-Received: by 2002:a5d:8997:0:b0:786:fd8e:760b with SMTP id m23-20020a5d8997000000b00786fd8e760bmr3216324iol.11.1690292980885; Tue, 25 Jul 2023 06:49:40 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id c3-20020a02a403000000b00418a5e0e93esm3595018jal.162.2023.07.25.06.49.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:49:40 -0700 (PDT) Date: Tue, 25 Jul 2023 07:49:39 -0600 Subject: [PATCH 2/6] Refactor dap_launch MIME-Version: 1.0 Message-Id: <20230725-dap-bt-path-v1-2-bb015b0d8e54@adacore.com> References: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This patch refactors dap_launch to make it more extensible and also easier to use. --- gdb/testsuite/gdb.dap/args-env.exp | 2 +- gdb/testsuite/gdb.dap/stop-at-main.exp | 2 +- gdb/testsuite/lib/dap-support.exp | 67 +++++++++++++++++++++------------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/gdb/testsuite/gdb.dap/args-env.exp b/gdb/testsuite/gdb.dap/args-env.exp index 96fbb28d9ce..ae6cf2e66a6 100644 --- a/gdb/testsuite/gdb.dap/args-env.exp +++ b/gdb/testsuite/gdb.dap/args-env.exp @@ -25,7 +25,7 @@ if {[build_executable ${testfile}.exp $testfile] == -1} { return } -if {[dap_launch $testfile {a "b c"} {{DEI something}}] == ""} { +if {[dap_launch $testfile arguments {a "b c"} env {{DEI something}}] == ""} { return } diff --git a/gdb/testsuite/gdb.dap/stop-at-main.exp b/gdb/testsuite/gdb.dap/stop-at-main.exp index 80a9b81e152..3f22f4a0154 100644 --- a/gdb/testsuite/gdb.dap/stop-at-main.exp +++ b/gdb/testsuite/gdb.dap/stop-at-main.exp @@ -25,7 +25,7 @@ if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { return } -if {[dap_launch $testfile {} {} 1] == ""} { +if {[dap_launch $testfile stop_at_main 1] == ""} { return } diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index e3750e1d016..4a1a288e7ae 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -239,40 +239,55 @@ proc _dap_initialize {name} { # Start gdb, send a DAP initialize request, and then a launch request # specifying FILE as the program to use for the inferior. Returns the # empty string on failure, or the response object from the launch -# request. If specified, ARGS is a list of command-line arguments, -# and ENV is a list of pairs of the form {VAR VALUE} that is used to -# populate the inferior's environment. After this is called, gdb will -# be ready to accept breakpoint requests. If STOP_AT_MAIN is nonzero, -# pass "stopAtBeginningOfMainSubprogram" to the launch request. -proc dap_launch {file {args {}} {env {}} {stop_at_main 0}} { +# request. If specified, ARGS is a dictionary of key-value pairs, +# each passed to the launch request. Valid keys are: +# * arguments - value is a list of strings passed as command-line +# arguments to the inferior +# * env - value is a list of pairs of the form {VAR VALUE} that is +# used to populate the inferior's environment. +# * stop_at_main - value is ignored, the presence of this means that +# "stopAtBeginningOfMainSubprogram" will be passed to the launch +# request. +# +# After this proc is called, gdb will be ready to accept breakpoint +# requests. +proc dap_launch {file {args {}}} { if {[_dap_initialize "startup - initialize"] == ""} { return "" } set params "o program" append params " [format {[%s]} [list s [standard_output_file $file]]]" - if {[llength $args] > 0} { - append params " args" - set arglist "" - foreach arg $args { - append arglist " \[s [list $arg]\]" - } - append params " \[a $arglist\]" - } + foreach {key value} $args { + switch -exact -- $key { + arguments { + append params " args" + set arglist "" + foreach arg $value { + append arglist " \[s [list $arg]\]" + } + append params " \[a $arglist\]" + } - if {[llength $env] > 0} { - append params " env" - set envlist "" - foreach pair $env { - lassign $pair var value - append envlist " $var" - append envlist " [format {[%s]} [list s $value]]" - } - append params " \[o $envlist\]" - } + env { + append params " env" + set envlist "" + foreach pair $value { + lassign $pair var value + append envlist " $var" + append envlist " [format {[%s]} [list s $value]]" + } + append params " \[o $envlist\]" + } + + stop_at_main { + append params { stopAtBeginningOfMainSubprogram [l true]} + } - if {$stop_at_main} { - append params { stopAtBeginningOfMainSubprogram [l true]} + default { + error "unrecognized parameter $key" + } + } } return [dap_check_request_and_response "startup - launch" launch $params] From patchwork Tue Jul 25 13:49:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 73157 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 1774D3853559 for ; Tue, 25 Jul 2023 13:50:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1774D3853559 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690293020; bh=fS5n8VqkjRUcioSRuJPHQYEAb+OL0L2iC1QKlJUeLyk=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qgQmMLO9njNvdSG9Q4wmrxSupoXcJl2+f4hrilpnDxM4QtkKYbTAqJ+oKX0rdcazd N5oWYrHC5TEOOOlr4vShJPqVXXcQS0wRnSchD/39H8lkNc0jmljX2ad8uiQu3OoO5b AWF5+CqEjR+asiTCGW2Kpj7OJ33XiZPpsibxZNP8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 71D5C3857711 for ; Tue, 25 Jul 2023 13:49:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71D5C3857711 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-783698a37beso307878339f.0 for ; Tue, 25 Jul 2023 06:49:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690292981; x=1690897781; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fS5n8VqkjRUcioSRuJPHQYEAb+OL0L2iC1QKlJUeLyk=; b=Fo6Lim9hZ6lST/ItbWhl6QhrTuLM7kJMI8wj4LJWZ+j7jCHJmcU6srWX78ndiqWtu3 ktE+v2gCVIpf68TdK+rhVhTWweiR3N7Sqh6iFHhuKmD3+I1BoeIWFSHii7VYiGU15mHc 05KJK6G5Irm/L21qaV0M+Uyo5nbLhuzKPJTkNSC3OnzYBm8KsP2ucrSgV1Rxfzlnu5y7 JONeCEudtArPsiSd+HeP773/E0mFjFvpn5jWuIGAhYV36mvaFsou6Aa9eOE7sfsAG8Kr GUmrBa6E4W/3pU23CbrYyjTBD1LxiLThDD/cNXZ91KmT7Cu1XFub4d0/8AYFTO37igas OWDQ== X-Gm-Message-State: ABy/qLYBMmzDjHGip07nMTj/XGgL1FS8VxQCG5oMfzRVO32KVJW7G/hK VTJiaoKLplzruf+phCVugotsVP/87cZbchbTuUB4Gw== X-Google-Smtp-Source: APBJJlGm2WW0rJE+nFgvE6r6awOt2624XBipwOP9IaNc38Bds8ZD/YPOZwKRzbFetb1DlFCLCnx3HQ== X-Received: by 2002:a5d:870b:0:b0:787:4b5f:b5ef with SMTP id u11-20020a5d870b000000b007874b5fb5efmr2933287iom.4.1690292981592; Tue, 25 Jul 2023 06:49:41 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id c3-20020a02a403000000b00418a5e0e93esm3595018jal.162.2023.07.25.06.49.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:49:41 -0700 (PDT) Date: Tue, 25 Jul 2023 07:49:40 -0600 Subject: [PATCH 3/6] Add "cwd" parameter to DAP launch request MIME-Version: 1.0 Message-Id: <20230725-dap-bt-path-v1-3-bb015b0d8e54@adacore.com> References: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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 --- gdb/doc/gdb.texinfo | 8 ++++++++ gdb/python/lib/gdb/dap/launch.py | 34 ++++++++++++++++----------------- gdb/testsuite/gdb.dap/cwd.exp | 40 +++++++++++++++++++++++++++++++++++++++ gdb/testsuite/lib/dap-support.exp | 5 +++++ 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 1463f501768..bd11f0a4475 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -39069,6 +39069,14 @@ If provided, this should be an array of strings. These strings are provided as command-line arguments to the inferior, as if by @code{set args}. @xref{Arguments}. +@item cwd +If provided, this should be a string. @value{GDBN} will change its +working directory to this directory, as if by the @code{cd} command +(@pxref{Working Directory}). The launched program will inherit this +as its working directory. Note that change of directory happens +before the @code{program} parameter is processed. This will affect +the result if @code{program} is a relative filename. + @item env If provided, this should be an object. Each key of the object will be used as the name of an environment variable; each value must be a diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index c3c09bc3dd0..d13037fa476 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -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") diff --git a/gdb/testsuite/gdb.dap/cwd.exp b/gdb/testsuite/gdb.dap/cwd.exp new file mode 100644 index 00000000000..394fe5ada83 --- /dev/null +++ b/gdb/testsuite/gdb.dap/cwd.exp @@ -0,0 +1,40 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test the cwd extension. + +require allow_dap_tests {!is_remote host} + +load_lib dap-support.exp + +standard_testfile attach.c + +if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { + return +} + +# Starting the inferior will fail if the change of cwd does not work. +set the_dir [file dirname $testfile] +set the_file [file tail $testfile] +if {[dap_launch $the_file cwd $the_dir stop_at_main 1] == ""} { + return +} + +dap_check_request_and_response "start inferior" configurationDone +# We didn't explicitly set a breakpoint, so if we hit one, it worked. +dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ + "body reason" breakpoint + +dap_shutdown diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index 4a1a288e7ae..657ad7b29bc 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -248,6 +248,7 @@ proc _dap_initialize {name} { # * stop_at_main - value is ignored, the presence of this means that # "stopAtBeginningOfMainSubprogram" will be passed to the launch # request. +# * cwd - value is the working directory to use. # # After this proc is called, gdb will be ready to accept breakpoint # requests. @@ -284,6 +285,10 @@ proc dap_launch {file {args {}}} { append params { stopAtBeginningOfMainSubprogram [l true]} } + cwd { + append envlist " cwd [format {[%s]} [list s $value]]" + } + default { error "unrecognized parameter $key" } From patchwork Tue Jul 25 13:49:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 73161 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 156CC385C6DF for ; Tue, 25 Jul 2023 13:51:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 156CC385C6DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690293075; bh=ioaRpsRRTqZkgTjNqBqG+Kl/Iv9vMK04n7UwsWy6lF8=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qcath/w/VKnp375kmZG0XLrEmmc1sMh4OvJSpMjTrAweF5eiuS+ptaInVeigbQu9S c/5W9zArkOMKNJODSkV9ihWgDiNShSB3OGhLBkOFHrvOvF6Ynpt6GBapMRxGXoeqE/ T+Cl8FslGIRocg7N+FUJV3gmHqcbHEpRilc/9Pfo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id 1F3FB385771D for ; Tue, 25 Jul 2023 13:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F3FB385771D Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7835971026fso234786639f.3 for ; Tue, 25 Jul 2023 06:49:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690292982; x=1690897782; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ioaRpsRRTqZkgTjNqBqG+Kl/Iv9vMK04n7UwsWy6lF8=; b=J0KVypbrgHIBiz09T87OruOmWJASGhAAPD6LG1Zx7OAR7+59aYAuM5E3s/jCIpJp1V qxK9A79tOm09Ljr2WBR4JdiReqo8V4uWi6qKxUTy5Xd2Q3bpmMA8jiEXJAeYxnW25ziu E4I3cDslsc/7VWWtbSdrz4MGswM0tRqX4SdVEfikybLwlReXbkUxQmFSZBetqhEzI1du 9H4bYViRf8zjTXzOnUjtUfcbLZyaRJIA7iLGfjiU0Cw2opeWRmXrpu6wLQEFiZ/WOqb9 w62cVEIuarePhQYVm7mR92thZL5fbIWBKJi1kRZaPAt5akcSYxzztrUTnl/eX32NlS8N POoQ== X-Gm-Message-State: ABy/qLYI/vB4LJGjDcxG7P0cWkvukBcffVQ9UJGBghBoX8oDrVKWOQOZ bqNK4Sbvev4t82iqAjc1Pvj/oo/JLHxONVMlr4BMpQ== X-Google-Smtp-Source: APBJJlHvxNkWyjDyqy1vDFdT1BgAiBIpj9UcAla1LBBmT9ExizbD2SWDO1oX6b5x8kFuqqCVeU6C9g== X-Received: by 2002:a5e:a60c:0:b0:787:f94:5133 with SMTP id q12-20020a5ea60c000000b007870f945133mr2493160ioi.2.1690292982171; Tue, 25 Jul 2023 06:49:42 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id c3-20020a02a403000000b00418a5e0e93esm3595018jal.162.2023.07.25.06.49.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:49:41 -0700 (PDT) Date: Tue, 25 Jul 2023 07:49:41 -0600 Subject: [PATCH 4/6] Full paths in DAP stackTrace responses MIME-Version: 1.0 Message-Id: <20230725-dap-bt-path-v1-4-bb015b0d8e54@adacore.com> References: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.6 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Vladimir Makaev noticed that, in some cases, a DAP stackTrace response would include a relative path name for the "path" component. This patch changes the frame decorator code to add a new DAP-specific decorator, and changes the DAP entry point to frame filters to use it. This decorator prefers the symtab's full name, and does not fall back to the solib's name. I'm not entirely happy with this patch, because if a user frame filter uses FrameDecorator, it may still do the wrong thing. It would be better to have frame filters return symtab-like objects instead, or to have a separate method to return the full path to the source file. I also tend to think that the solib fallback behavior of FrameDecorator is a mistake. If this is ever needed, it seems to me that it should be a separate method. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30665 --- gdb/python/lib/gdb/FrameDecorator.py | 111 +++++++++++++++++++++-------------- gdb/python/lib/gdb/frames.py | 14 ++++- 2 files changed, 78 insertions(+), 47 deletions(-) diff --git a/gdb/python/lib/gdb/FrameDecorator.py b/gdb/python/lib/gdb/FrameDecorator.py index c4a7806e434..22d5fa4d0a9 100644 --- a/gdb/python/lib/gdb/FrameDecorator.py +++ b/gdb/python/lib/gdb/FrameDecorator.py @@ -16,34 +16,8 @@ import gdb -class FrameDecorator(object): - """Basic implementation of a Frame Decorator""" - - """ This base frame decorator decorates a frame or another frame - decorator, and provides convenience methods. If this object is - wrapping a frame decorator, defer to that wrapped object's method - if it has one. This allows for frame decorators that have - sub-classed FrameDecorator object, but also wrap other frame - decorators on the same frame to correctly execute. - - E.g - - If the result of frame filters running means we have one gdb.Frame - wrapped by multiple frame decorators, all sub-classed from - FrameDecorator, the resulting hierarchy will be: - - Decorator1 - -- (wraps) Decorator2 - -- (wraps) FrameDecorator - -- (wraps) gdb.Frame - - In this case we have two frame decorators, both of which are - sub-classed from FrameDecorator. If Decorator1 just overrides the - 'function' method, then all of the other methods are carried out - by the super-class FrameDecorator. But Decorator2 may have - overriden other methods, so FrameDecorator will look at the - 'base' parameter and defer to that class's methods. And so on, - down the chain.""" +class _FrameDecoratorBase(object): + """Base class of frame decorators.""" # 'base' can refer to a gdb.Frame or another frame decorator. In # the latter case, the child class will have called the super @@ -122,22 +96,6 @@ class FrameDecorator(object): frame = self.inferior_frame() return frame.pc() - def filename(self): - """Return the filename associated with this frame, detecting - and returning the appropriate library name is this is a shared - library.""" - - if hasattr(self._base, "filename"): - return self._base.filename() - - frame = self.inferior_frame() - sal = frame.find_sal() - if not sal.symtab or not sal.symtab.filename: - pc = frame.pc() - return gdb.solib_name(pc) - else: - return sal.symtab.filename - def frame_args(self): """Return an iterable of frame arguments for this frame, if any. The iterable object contains objects conforming with the @@ -198,6 +156,71 @@ class FrameDecorator(object): return self._base +class FrameDecorator(_FrameDecoratorBase): + """Basic implementation of a Frame Decorator""" + + """ This base frame decorator decorates a frame or another frame + decorator, and provides convenience methods. If this object is + wrapping a frame decorator, defer to that wrapped object's method + if it has one. This allows for frame decorators that have + sub-classed FrameDecorator object, but also wrap other frame + decorators on the same frame to correctly execute. + + E.g + + If the result of frame filters running means we have one gdb.Frame + wrapped by multiple frame decorators, all sub-classed from + FrameDecorator, the resulting hierarchy will be: + + Decorator1 + -- (wraps) Decorator2 + -- (wraps) FrameDecorator + -- (wraps) gdb.Frame + + In this case we have two frame decorators, both of which are + sub-classed from FrameDecorator. If Decorator1 just overrides the + 'function' method, then all of the other methods are carried out + by the super-class FrameDecorator. But Decorator2 may have + overriden other methods, so FrameDecorator will look at the + 'base' parameter and defer to that class's methods. And so on, + down the chain.""" + + def filename(self): + """Return the filename associated with this frame, detecting + and returning the appropriate library name is this is a shared + library.""" + + if hasattr(self._base, "filename"): + return self._base.filename() + + frame = self.inferior_frame() + sal = frame.find_sal() + if not sal.symtab or not sal.symtab.filename: + pc = frame.pc() + return gdb.solib_name(pc) + else: + return sal.symtab.filename + + +class DAPFrameDecorator(_FrameDecoratorBase): + """Like FrameDecorator, but has slightly different results + for the "filename" method.""" + + def filename(self): + """Return the filename associated with this frame, detecting + and returning the appropriate library name is this is a shared + library.""" + + if hasattr(self._base, "filename"): + return self._base.filename() + + frame = self.inferior_frame() + sal = frame.find_sal() + if sal.symtab is not None: + return sal.symtab.fullname() + return None + + class SymValueWrapper(object): """A container class conforming to the Symbol/Value interface which holds frame locals or frame arguments.""" diff --git a/gdb/python/lib/gdb/frames.py b/gdb/python/lib/gdb/frames.py index cff3ba07704..104ff4bb203 100644 --- a/gdb/python/lib/gdb/frames.py +++ b/gdb/python/lib/gdb/frames.py @@ -18,7 +18,7 @@ import gdb from gdb.FrameIterator import FrameIterator -from gdb.FrameDecorator import FrameDecorator +from gdb.FrameDecorator import FrameDecorator, DAPFrameDecorator import itertools import collections @@ -172,7 +172,11 @@ def _frame_iterator(frame, frame_low, frame_high, always): # Apply a basic frame decorator to all gdb.Frames. This unifies # the interface. - frame_iterator = map(FrameDecorator, frame_iterator) + if always: + decorator = DAPFrameDecorator + else: + decorator = FrameDecorator + frame_iterator = map(decorator, frame_iterator) for ff in sorted_list: frame_iterator = ff.filter(frame_iterator) @@ -214,7 +218,11 @@ def frame_iterator(frame, frame_low, frame_high): """Helper function that will execute the chain of frame filters. Each filter is executed in priority order. After the execution completes, slice the iterator to frame_low - frame_high range. An - iterator is always returned. + iterator is always returned. The iterator will always yield + frame decorator objects, but note that these decorators have + slightly different semantics from the ordinary ones: they will + always return a fully-qualified 'filename' (if possible) and will + never substitute the objfile name. Arguments: frame: The initial frame. From patchwork Tue Jul 25 13:49:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 73160 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 1248E38708BF for ; Tue, 25 Jul 2023 13:50:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1248E38708BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690293050; bh=1daIOuKxH+zMHg4+ctPJ5fVGmHm29E6mixuqB/RmoaM=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=eJeNW9lc2VFVbeD//wkHxt7Z8gfVHy25s3E2Mod7RXzgz52dm1qGERtdPhKO5u4GB W8O8Bl4Ft4yEbPfxiEqADTAfUcQ+JHqSnZ95v77lYg9U0rRkxIvwS0S5BTwHZFLELG MRSrsFFiFv7E75ZJeUvGcN2Vko2fOXsLJPNDPMZA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 73B90385773F for ; Tue, 25 Jul 2023 13:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73B90385773F Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-77a62a84855so235653239f.1 for ; Tue, 25 Jul 2023 06:49:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690292982; x=1690897782; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1daIOuKxH+zMHg4+ctPJ5fVGmHm29E6mixuqB/RmoaM=; b=NmuCxeK07vs4hG17se1qtU1sICrUd72+93jypP/esO5uRhwg6i890VvrPhKemk9UqC 4+AC/vzk9rMWr3nvbXW0N8Kk/b80jlO9eJ3jv6okgVMKFVNczlLgW3sY40Oh4Z7dh90C uCvdEzfInhgQ1VsiKZlNSkRgHXX3oa//3zo2zPzU4JfJM2aSqAKqsbiWeHzO1KthSn7A JuMxppeElGL3mibhYkBNc+/w47uEXfwNeIF5yWYsbDLwZvE4bibJfffjjwDLmbSAGFch C/L12kv+oDjVrP5lD9d6OW2VXD2EtnQmJpFyyHOkORn8z/MTDBvtjecdIgIXJTA48c7/ Zu8g== X-Gm-Message-State: ABy/qLZUTN2ei5TLuMo2G28shKHcCJGJp1GqeAxWQjm2IgGkqwHMEwAJ ejdeavLWTh7lPUtYfZCzZd2uAkPFWymbJIwH0uWXZQ== X-Google-Smtp-Source: APBJJlFD4fkzCOqqJI3xKQ0u+M7xFG1tdQ1m2HhPMQQXXMPP5hO3W49NuY5UHTLLLlofZGyfVTslgA== X-Received: by 2002:a05:6602:190:b0:786:e612:72f8 with SMTP id m16-20020a056602019000b00786e61272f8mr2451809ioo.21.1690292982749; Tue, 25 Jul 2023 06:49:42 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id c3-20020a02a403000000b00418a5e0e93esm3595018jal.162.2023.07.25.06.49.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:49:42 -0700 (PDT) Date: Tue, 25 Jul 2023 07:49:42 -0600 Subject: [PATCH 5/6] Move DAP breakpoint event code to breakpoint.py MIME-Version: 1.0 Message-Id: <20230725-dap-bt-path-v1-5-bb015b0d8e54@adacore.com> References: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" A subsequent patch will add the ability to suppress breakpoint events to DAP. My first attempt at this ended up with recurse imports, cause Python failures. So, this patch moves all the DAP breakpoint event code to breakpoint.py in preparation for the change. I've renamed breakpoint_descriptor here as well, because it can now be private to breakpoint.py. --- gdb/python/lib/gdb/dap/breakpoint.py | 42 ++++++++++++++++++++++++++++++++++-- gdb/python/lib/gdb/dap/events.py | 37 ------------------------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index 27745ebfd2c..4a1c98efd87 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -25,6 +25,44 @@ from .startup import send_gdb_with_response, in_gdb_thread, log_stack from .typecheck import type_check +@in_gdb_thread +def _bp_modified(event): + send_event( + "breakpoint", + { + "reason": "changed", + "breakpoint": _breakpoint_descriptor(event), + }, + ) + + +@in_gdb_thread +def _bp_created(event): + send_event( + "breakpoint", + { + "reason": "new", + "breakpoint": _breakpoint_descriptor(event), + }, + ) + + +@in_gdb_thread +def _bp_deleted(event): + send_event( + "breakpoint", + { + "reason": "removed", + "breakpoint": _breakpoint_descriptor(event), + }, + ) + + +gdb.events.breakpoint_created.connect(_bp_created) +gdb.events.breakpoint_modified.connect(_bp_modified) +gdb.events.breakpoint_deleted.connect(_bp_deleted) + + # Map from the breakpoint "kind" (like "function") to a second map, of # breakpoints of that type. The second map uses the breakpoint spec # as a key, and the gdb.Breakpoint itself as a value. This is used to @@ -34,7 +72,7 @@ breakpoint_map = {} @in_gdb_thread -def breakpoint_descriptor(bp): +def _breakpoint_descriptor(bp): "Return the Breakpoint object descriptor given a gdb Breakpoint." result = { "id": bp.number, @@ -115,7 +153,7 @@ def _set_breakpoints_callback(kind, specs, creator): # Reaching this spot means success. breakpoint_map[kind][keyspec] = bp - result.append(breakpoint_descriptor(bp)) + result.append(_breakpoint_descriptor(bp)) # Exceptions other than gdb.error are possible here. except Exception as e: log_stack() diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index c1631442746..50ab038e91d 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -18,7 +18,6 @@ import gdb from .server import send_event from .startup import in_gdb_thread, Invoker, log -from .breakpoint import breakpoint_descriptor from .modules import is_module, make_module @@ -35,39 +34,6 @@ def _on_exit(event): ) -@in_gdb_thread -def _bp_modified(event): - send_event( - "breakpoint", - { - "reason": "changed", - "breakpoint": breakpoint_descriptor(event), - }, - ) - - -@in_gdb_thread -def _bp_created(event): - send_event( - "breakpoint", - { - "reason": "new", - "breakpoint": breakpoint_descriptor(event), - }, - ) - - -@in_gdb_thread -def _bp_deleted(event): - send_event( - "breakpoint", - { - "reason": "removed", - "breakpoint": breakpoint_descriptor(event), - }, - ) - - @in_gdb_thread def _new_thread(event): send_event( @@ -169,9 +135,6 @@ def _on_stop(event): gdb.events.stop.connect(_on_stop) gdb.events.exited.connect(_on_exit) -gdb.events.breakpoint_created.connect(_bp_created) -gdb.events.breakpoint_modified.connect(_bp_modified) -gdb.events.breakpoint_deleted.connect(_bp_deleted) gdb.events.new_thread.connect(_new_thread) gdb.events.cont.connect(_cont) gdb.events.new_objfile.connect(_new_objfile) From patchwork Tue Jul 25 13:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 73159 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 3DC87385AFB2 for ; Tue, 25 Jul 2023 13:50:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DC87385AFB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690293041; bh=t5sEn7yk8fQPJNEZGTgykqqWrONJwiyxhgA3KxjDPBw=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=w7koJ7lvgkzLzmfCt7ws4aM7PzhCwgI4AM6t73mk9DK1MQJ0VrVMHesrqtqmF9Y1t kIafNhh+PttHgn8U4m4SuLHvSfEqIot00ANUWPyDla6zUWbSOqJsW/GPF3rrH0kqgv ivB9Z4o7W/GHoS+OXlNgHoJ2KoX0IJ+fxnukVVew= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 0A2343857340 for ; Tue, 25 Jul 2023 13:49:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A2343857340 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-785cbc5bfd2so280757639f.2 for ; Tue, 25 Jul 2023 06:49:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690292983; x=1690897783; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t5sEn7yk8fQPJNEZGTgykqqWrONJwiyxhgA3KxjDPBw=; b=bnbjE3z2n8tHjMXie9aGUgDcyP1SzRLCc22FpTnR5JlTU0e0/ss+vXMnGdg7aLn2LZ 0RXWJFddjcLYZu6jMQtbMQ716QdhrunpF4nzTglKfy1LFa7LZQsydQ5dFd7SpdxsPRAy dXSmlO7HoCdJ7Q2vRdbIm4gTfbcNh6FA2Af70OYv2Dw/t4GXL4deshb0emqayTGyG6hb 2h1fhPi4mAtcLTLiWYpBHM/QpiBeAbbf5rM/6+/ozjboWoVMshJcE+jgbUfPAlUuZbiT /L7srWvcIBo6+Pvy7rLJY+445kfLiHYcwef9IVLJZpcP0t87JvtMgdi+gVUjjsicYWdd vP0w== X-Gm-Message-State: ABy/qLaRDq81IwbGWY16szOsGg1RZZQNtbaifiG/s9YJ9EiF4wB/GMVu g3scrRgNC6vJZx00YuuAbZ63JpPibel837Q9Jw2lJg== X-Google-Smtp-Source: APBJJlGWBTGdCe3jN+TAn7EumrXmzDm10T8TO5pOVNmgmOtLNs8PX3WzB+yzEzx7qxdBnkGMbvFtgw== X-Received: by 2002:a5d:9b8f:0:b0:783:5e20:768d with SMTP id r15-20020a5d9b8f000000b007835e20768dmr2954587iom.18.1690292983328; Tue, 25 Jul 2023 06:49:43 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id c3-20020a02a403000000b00418a5e0e93esm3595018jal.162.2023.07.25.06.49.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:49:43 -0700 (PDT) Date: Tue, 25 Jul 2023 07:49:43 -0600 Subject: [PATCH 6/6] Do not send "new breakpoint" event when breakpoint is set MIME-Version: 1.0 Message-Id: <20230725-dap-bt-path-v1-6-bb015b0d8e54@adacore.com> References: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When the DAP client sets a breakpoint, gdb currently sends a "new breakpoint" event. However, Vladimir Makaev discovered that this causes VSCode to think there are two breakpoints. This patch changes gdb to suppress the event in this case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30678 --- gdb/python/lib/gdb/dap/breakpoint.py | 36 ++++++++++++++++++++++++++++-------- gdb/testsuite/gdb.dap/basic-dap.exp | 11 ++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index 4a1c98efd87..e612c512a89 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -17,6 +17,8 @@ import gdb import os import re +from contextlib import contextmanager + # These are deprecated in 3.9, but required in older versions. from typing import Optional, Sequence @@ -36,15 +38,32 @@ def _bp_modified(event): ) +# True when suppressing new breakpoint events. +_suppress_bp = False + + +@contextmanager +def suppress_new_breakpoint_event(): + """Return a new context manager that suppresses new breakpoint events.""" + global _suppress_bp + _suppress_bp = True + try: + yield None + finally: + _suppress_bp = False + + @in_gdb_thread def _bp_created(event): - send_event( - "breakpoint", - { - "reason": "new", - "breakpoint": _breakpoint_descriptor(event), - }, - ) + global _suppress_bp + if not _suppress_bp: + send_event( + "breakpoint", + { + "reason": "new", + "breakpoint": _breakpoint_descriptor(event), + }, + ) @in_gdb_thread @@ -141,7 +160,8 @@ def _set_breakpoints_callback(kind, specs, creator): if keyspec in saved_map: bp = saved_map.pop(keyspec) else: - bp = creator(**spec) + with suppress_new_breakpoint_event(): + bp = creator(**spec) bp.condition = condition if hit_condition is None: diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index ef3c535f6a2..c4a1698beda 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -54,7 +54,7 @@ set obj [dap_check_request_and_response "set breakpoint by line number" \ set line_bpno [dap_get_breakpoint_number $obj] # Check the new breakpoint event. -set ok 0 +set ok 1 foreach d [lindex $obj 1] { if {[dict get $d type] != "event" || [dict get $d event] != "breakpoint"} { @@ -62,13 +62,14 @@ foreach d [lindex $obj 1] { } if {[dict get $d body reason] == "new" && [dict get $d body breakpoint verified] == "true"} { - set ok 1 - pass "check new breakpoint event" + set ok 0 break } } -if {!$ok} { - fail "check new breakpoint event" +if {$ok} { + pass "check lack of new breakpoint event" +} else { + fail "check lack of new breakpoint event" } # Check that there are breakpoint locations on each line between FIRST