public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 3/5] gdb: make set/show cwd work with $_gdb_setting_str
Date: Tue,  4 Apr 2023 13:45:29 +0100	[thread overview]
Message-ID: <db14b6ac1bc28968fdfce4432a875d3ca275bddb.1680608960.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1680608960.git.aburgess@redhat.com>

The previous commit fixed set/show args when used with
$_gdb_setting_str, this commit fixes set/show cwd.

Instead of using a scratch variable which is then pushed into the
current inferior from a set callback, move to the API that allows for
getters and setters, and store the value directly within the current
inferior.

Update the existing test to check the cwd setting.
---
 gdb/infcmd.c                             | 15 +++++----------
 gdb/testsuite/gdb.multi/gdb-settings.exp | 23 +++++++++++++++++++++++
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 2f0d4f38c85..2e26ae9b934 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -66,10 +66,6 @@ static void step_1 (int, int, const char *);
 #define ERROR_NO_INFERIOR \
    if (!target_has_execution ()) error (_("The program is not being run."));
 
-/* Scratch area where the new cwd will be stored by 'set cwd'.  */
-
-static std::string inferior_cwd_scratch;
-
 /* Scratch area where 'set inferior-tty' will store user-provided value.
    We'll immediate copy it into per-inferior storage.  */
 
@@ -165,12 +161,12 @@ get_inferior_cwd ()
   return current_inferior ()->cwd ();
 }
 
-/* Handle the 'set cwd' command.  */
+/* Store the new value passed to 'set cwd'.  */
 
 static void
-set_cwd_command (const char *args, int from_tty, struct cmd_list_element *c)
+set_cwd_value (const std::string &args)
 {
-  current_inferior ()->set_cwd (inferior_cwd_scratch);
+  current_inferior ()->set_cwd (args);
 }
 
 /* Handle the 'show cwd' command.  */
@@ -3164,8 +3160,7 @@ Follow this command with any number of args, to be passed to the program."),
   set_cmd_completer (args_set_show.set, filename_completer);
 
   auto cwd_set_show =
-    add_setshow_string_noescape_cmd ("cwd", class_run,
-				     &inferior_cwd_scratch, _("\
+    add_setshow_string_noescape_cmd ("cwd", class_run, _("\
 Set the current working directory to be used when the inferior is started.\n\
 Changing this setting does not have any effect on inferiors that are\n\
 already running."),
@@ -3175,7 +3170,7 @@ Show the current working directory that is used when the inferior is started."),
 Use this command to change the current working directory that will be used\n\
 when the inferior is started.  This setting does not affect GDB's current\n\
 working directory."),
-				     set_cwd_command,
+				     set_cwd_value, get_inferior_cwd,
 				     show_cwd_command,
 				     &setlist, &showlist);
   set_cmd_completer (cwd_set_show.set, filename_completer);
diff --git a/gdb/testsuite/gdb.multi/gdb-settings.exp b/gdb/testsuite/gdb.multi/gdb-settings.exp
index d2741d16157..70e0752a5bb 100644
--- a/gdb/testsuite/gdb.multi/gdb-settings.exp
+++ b/gdb/testsuite/gdb.multi/gdb-settings.exp
@@ -33,6 +33,10 @@ proc inferior_args {num} {
     return "a_${num}_1 a_${num}_2 a_${num}_3"
 }
 
+proc inferior_cwd {num} {
+    return [standard_output_file inf_${num}_dir]
+}
+
 # Start inferior NUM.
 
 proc start_inferior {num} {
@@ -41,6 +45,9 @@ proc start_inferior {num} {
 
 	set args [inferior_args ${num}]
 
+	set dir [inferior_cwd ${num}]
+	remote_exec host "mkdir -p $dir"
+
 	if {$num != 1} {
 	    gdb_test "add-inferior" "Added inferior $num.*" \
 		"add empty inferior"
@@ -50,10 +57,17 @@ proc start_inferior {num} {
 	    gdb_test_no_output "set args $args"
 	}
 
+	gdb_test_no_output "set cwd $dir" \
+	    "set cwd for inferior ${num}"
+
 	gdb_test {print $_gdb_setting_str("args")} \
 	    " = \"$args\"" \
 	    "check args before loading a file"
 
+	gdb_test {print $_gdb_setting_str("cwd")} \
+	    " = \"$dir\"" \
+	    "check cwd before loading a file"
+
 	gdb_load $binfile
 
 	if {[gdb_start_cmd] < 0} {
@@ -65,6 +79,10 @@ proc start_inferior {num} {
 	gdb_test {print $_gdb_setting_str("args")} \
 	    " = \"$args\"" \
 	    "check after after starting"
+
+	gdb_test {print $_gdb_setting_str("cwd")} \
+	    " = \"$dir\"" \
+	    "check cwd after starting"
     }
 
     return 0
@@ -95,4 +113,9 @@ for {set i 1} {$i <= $NUM_INFS} {incr i} {
     gdb_test {print $_gdb_setting_str("args")} \
 	" = \"$args\"" \
 	"check args after after switching to inferior $i"
+
+    set dir [inferior_cwd $i]
+    gdb_test {print $_gdb_setting_str("cwd")} \
+	" = \"$dir\"" \
+	"check cwd after after switching to inferior $i"
 }
-- 
2.25.4


  parent reply	other threads:[~2023-04-04 12:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04 12:45 [PATCH 0/5] Fixes for per-inferior settings and $_gdb_setting_str() Andrew Burgess
2023-04-04 12:45 ` [PATCH 1/5] gdb: cleanup command creation in infcmd.c Andrew Burgess
2023-04-17 16:27   ` Tom Tromey
2023-04-04 12:45 ` [PATCH 2/5] gdb: make set/show args work with $_gdb_setting_str Andrew Burgess
2023-04-17 16:37   ` Tom Tromey
2023-04-17 18:04     ` Simon Marchi
2023-04-04 12:45 ` Andrew Burgess [this message]
2023-04-04 12:45 ` [PATCH 4/5] gdb: make set/show inferior-tty " Andrew Burgess
2023-04-04 12:45 ` [PATCH 5/5] gdb: make deprecated_show_value_hack static Andrew Burgess
2023-04-17 16:41   ` Tom Tromey
2023-04-28 14:57     ` Andrew Burgess
2023-07-10 17:25       ` Tom Tromey
2023-04-17 16:42 ` [PATCH 0/5] Fixes for per-inferior settings and $_gdb_setting_str() Tom Tromey
2023-04-17 18:09 ` Simon Marchi
2023-04-17 18:21   ` Simon Marchi
2023-04-28 21:53     ` Andrew Burgess
2023-04-28 16:43   ` Andrew Burgess

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=db14b6ac1bc28968fdfce4432a875d3ca275bddb.1680608960.git.aburgess@redhat.com \
    --to=aburgess@redhat.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).