From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7869bcee569so208553539f.0 for ; Tue, 25 Jul 2023 06:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1690292981; x=1690897781; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OyaliUezp7QBgzRaNuBpSIdFn7jIaoea0a8lklcedHk=; b=JXs+XgNwpqGcdxq09k8OfWJVgk56GU6LqC1O2hZ4A91HdQ2xv2hmVdE373vkTgdnFs lbKfYt+ACEsA7hjybIcSFj2GTJmFoyZzqSmpFUUU+AnLm8dTiHiTkNpq7OiFJwf0YPYh SvrYp9TBUSGlun/y8Z5tXjmzHuugbqp2U7E10chy421jhHgZpXJKldnrUDDCZ1Q3Ws9O qma4N+Rr1XiHQFlY6J73PKncdE1Ie04jw48OtlnRpqlY1njdVpYdIWrmIs1BpXY9Gqw7 QYeXSVQGka6KTC8xpQOfHY8jfudZPJ9hSS30KRLUcisQuOIJK35A314jD0Q7e+KFeS0V zQ/A== 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) From: Tom Tromey Date: Tue, 25 Jul 2023 07:49:39 -0600 Subject: [PATCH 2/6] Refactor dap_launch MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 List-Id: 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] -- 2.40.1