From 94e6c5641234c4ced9cb3fa0ccc2aaaa6b7b62ea Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Fri, 28 Apr 2023 22:14:53 +0100 Subject: [PATCH] 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. --- 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" } } -- 2.30.2