public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb: make set/show cwd work with $_gdb_setting_str
Date: Fri, 28 Apr 2023 21:51:19 +0000 (GMT)	[thread overview]
Message-ID: <20230428215119.822113858CDB@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=94e6c5641234c4ced9cb3fa0ccc2aaaa6b7b62ea

commit 94e6c5641234c4ced9cb3fa0ccc2aaaa6b7b62ea
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Fri Apr 28 22:14:53 2023 +0100

    gdb: make set/show cwd work with $_gdb_setting_str
    
    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.

Diff:
---
 gdb/infcmd.c                             | 15 +++++----------
 gdb/testsuite/gdb.multi/gdb-settings.exp |  9 +++++++++
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 310ad625676..7b2db17756b 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 407bc55b1f2..f8e9aaf3e26 100644
--- a/gdb/testsuite/gdb.multi/gdb-settings.exp
+++ b/gdb/testsuite/gdb.multi/gdb-settings.exp
@@ -69,6 +69,7 @@ foreach_with_prefix inf $inferiors {
     gdb_test "inferior ${inf}" "Switching to inferior ${inf}.*" \
 	"switch to inferior ${inf} before set"
     gdb_test_no_output "set args inf${inf}-args"
+    gdb_test_no_output "set cwd /inf${inf}-cwd"
 }
 
 # Check settings are still correct for each inferior.
@@ -80,21 +81,29 @@ foreach_with_prefix inf $inferiors {
     gdb_test "with args tmp-value -- print 1" " = 1"
     gdb_test "show args" "inf${inf}-args.*"
 
+    gdb_test "with cwd tmp-value -- print 1" " = 1"
+    gdb_test "show cwd" "/inf${inf}-cwd.*"
+
     # If the inferiors are running check $_gdb_setting_str and
     # $_gdb_setting return the correct values.
     if { $run } {
 	gdb_test {print $_gdb_setting_str("args")} "\"inf${inf}-args\""
 	gdb_test {print $_gdb_setting("args")} "\"inf${inf}-args\""
+	gdb_test {print $_gdb_setting_str("cwd")} "\"/inf${inf}-cwd\""
+	gdb_test {print $_gdb_setting("cwd")} "\"/inf${inf}-cwd\""
     }
 
     # Check the settings can be read from Python.
     if { $run_python_tests } {
 	gdb_test "python print(gdb.parameter('args'))" "inf${inf}-args"
+	gdb_test "python print(gdb.parameter('cwd'))" "/inf${inf}-cwd"
     }
 
     # Check the settings can be read from Guile.
     if { $run_guile_tests } {
 	gdb_test "guile (print (parameter-value \"args\"))" \
 	    "inf${inf}-args"
+	gdb_test "guile (print (parameter-value \"cwd\"))" \
+	    "/inf${inf}-cwd"
     }
 }

                 reply	other threads:[~2023-04-28 21:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230428215119.822113858CDB@sourceware.org \
    --to=aburgess@sourceware.org \
    --cc=gdb-cvs@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).