public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: make set/show cwd work with $_gdb_setting_str
@ 2023-04-28 21:51 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2023-04-28 21:51 UTC (permalink / raw)
  To: gdb-cvs

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"
     }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-28 21:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28 21:51 [binutils-gdb] gdb: make set/show cwd work with $_gdb_setting_str Andrew Burgess

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).