public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/6] Refactor dap_launch
Date: Tue, 25 Jul 2023 07:49:39 -0600	[thread overview]
Message-ID: <20230725-dap-bt-path-v1-2-bb015b0d8e54@adacore.com> (raw)
In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com>

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


  parent reply	other threads:[~2023-07-25 13:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 13:49 [PATCH 0/6] Several DAP fixes for VSCode Tom Tromey
2023-07-25 13:49 ` [PATCH 1/6] Rename private member of FrameDecorator Tom Tromey
2023-07-28 14:50   ` Lancelot SIX
2023-07-31 14:30     ` Tom Tromey
2023-07-31 14:36       ` Lancelot SIX
2023-07-25 13:49 ` Tom Tromey [this message]
2023-07-25 13:49 ` [PATCH 3/6] Add "cwd" parameter to DAP launch request Tom Tromey
2023-07-25 14:07   ` Eli Zaretskii
2023-07-25 13:49 ` [PATCH 4/6] Full paths in DAP stackTrace responses Tom Tromey
2023-07-28 15:29   ` Lancelot SIX
2023-07-31 16:26     ` Tom Tromey
2023-07-25 13:49 ` [PATCH 5/6] Move DAP breakpoint event code to breakpoint.py Tom Tromey
2023-07-25 13:49 ` [PATCH 6/6] Do not send "new breakpoint" event when breakpoint is set Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230725-dap-bt-path-v1-2-bb015b0d8e54@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).