From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 822113858CDB; Fri, 28 Apr 2023 21:51:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 822113858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682718679; bh=eWmhwxq4vuEBn6onE+IJTJ6zsQW5ZCejIQqmIP3Dqmg=; h=From:To:Subject:Date:From; b=mEKJmupRn68GKUR3NHwP1QEqorbd06Vvn9NTr2/u2hzl/8+iivtMN/Mq3V53CFRMI awlfhHCE+g2nipx3+62On3YVpWgWNF9eSUGlFBwNfs3DSiVZpUbxPaUHMl1zaDjHiA IgmkTnG/1ivGXJJsT4PW56w/iHt/kBK8Nw1Xwm2s= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: make set/show cwd work with $_gdb_setting_str X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: cc09d372f664410aea226bfaa246aeb74fee8126 X-Git-Newrev: 94e6c5641234c4ced9cb3fa0ccc2aaaa6b7b62ea Message-Id: <20230428215119.822113858CDB@sourceware.org> Date: Fri, 28 Apr 2023 21:51:19 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D94e6c5641234= c4ced9cb3fa0ccc2aaaa6b7b62ea commit 94e6c5641234c4ced9cb3fa0ccc2aaaa6b7b62ea Author: Andrew Burgess Date: Fri Apr 28 22:14:53 2023 +0100 gdb: make set/show cwd work with $_gdb_setting_str =20 The previous commit fixed set/show args when used with $_gdb_setting_str, this commit fixes set/show cwd. =20 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. =20 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.")= ); =20 -/* 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. */ =20 @@ -165,12 +161,12 @@ get_inferior_cwd () return current_inferior ()->cwd (); } =20 -/* Handle the 'set cwd' command. */ +/* Store the new value passed to 'set cwd'. */ =20 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); } =20 /* Handle the 'show cwd' command. */ @@ -3164,8 +3160,7 @@ Follow this command with any number of args, to be pa= ssed to the program."), set_cmd_completer (args_set_show.set, filename_completer); =20 auto cwd_set_show - =3D add_setshow_string_noescape_cmd ("cwd", class_run, - &inferior_cwd_scratch, _("\ + =3D 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.m= ulti/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" } =20 # 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" " =3D 1" gdb_test "show args" "inf${inf}-args.*" =20 + gdb_test "with cwd tmp-value -- print 1" " =3D 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\"" } =20 # 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" } =20 # 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" } }