diff options
author | Andrew Burgess <aburgess@redhat.com> | 2023-04-04 09:56:00 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2023-04-28 22:50:46 +0100 |
commit | cc09d372f664410aea226bfaa246aeb74fee8126 (patch) | |
tree | 75b1a2f6947e106b076b3a6c95574795b3917538 /gdb/infcmd.c | |
parent | 33c054b015b99e92dcfba1b997a25b7ae8e01e0b (diff) | |
download | gdb-cc09d372f664410aea226bfaa246aeb74fee8126.zip gdb-cc09d372f664410aea226bfaa246aeb74fee8126.tar.gz gdb-cc09d372f664410aea226bfaa246aeb74fee8126.tar.bz2 |
gdb: make set/show args work with $_gdb_setting_str
I noticed that $_gdb_setting_str was not working with 'args', e.g.:
$ gdb -q --args /tmp/hello.x arg1 arg2 arg3
Reading symbols from /tmp/hello.x...
(gdb) show args
Argument list to give program being debugged when it is started is "arg1 arg2 arg3".
(gdb) print $_gdb_setting_str("args")
$1 = ""
This is because the 'args' setting is implemented using a scratch
variable ('inferior_args_scratch') which is updated when the user does
'set args ...'. There is then a function 'set_args_command' which is
responsible for copying the scratch area into the current inferior.
However, when the user sets the arguments via the command line the
scratch variable is not updated, instead the arguments are pushed
straight into the current inferior.
There is a second problem, when the current inferior changes the
scratch area is not updated, which means that the value returned will
only ever reflect the last call to 'set args ...' regardless of which
inferior is currently selected.
Luckily, the fix is pretty easy, set/show variables have an
alternative API which requires we provide some getter and setter
functions. With this done the scratch variable can be removed and the
value returned will now always reflect the current inferior.
While working on set/show args I also rewrote show_args_command to
remove the use of deprecated_show_value_hack.
Reviewed-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/infcmd.c')
-rw-r--r-- | gdb/infcmd.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 86555df..310ad62 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -66,14 +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 string containing arguments to give to the - program will be stored by 'set args'. As soon as anything is - stored, notice_args_set will move it into per-inferior storage. - Arguments are separated by spaces. Empty string (pointer to '\0') - means no args. */ - -static std::string inferior_args_scratch; - /* Scratch area where the new cwd will be stored by 'set cwd'. */ static std::string inferior_cwd_scratch; @@ -136,26 +128,33 @@ set_inferior_args_vector (int argc, char **argv) current_inferior ()->set_args (std::move (n)); } -/* Notice when `set args' is run. */ +/* Store the new value passed to 'set args'. */ static void -set_args_command (const char *args, int from_tty, struct cmd_list_element *c) +set_args_value (const std::string &args) { - /* CLI has assigned the user-provided value to inferior_args_scratch. - Now route it to current inferior. */ - current_inferior ()->set_args (inferior_args_scratch); + current_inferior ()->set_args (args); } -/* Notice when `show args' is run. */ +/* Return the value for 'show args' to display. */ + +static const std::string & +get_args_value () +{ + return current_inferior ()->args (); +} + +/* Callback to implement 'show args' command. */ static void show_args_command (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { - /* Note that we ignore the passed-in value in favor of computing it - directly. */ - deprecated_show_value_hack (file, from_tty, c, - current_inferior ()->args ().c_str ()); + /* Ignore the passed in value, pull the argument directly from the + inferior. However, these should always be the same. */ + gdb_printf (_("\ +Argument list to give program being debugged when it is started is \"%s\".\n"), + current_inferior ()->args ().c_str ()); } /* See gdbsupport/common-inferior.h. */ @@ -3154,12 +3153,12 @@ is restored."), add_alias_cmd ("tty", tty_set_show.set, class_run, 0, &cmdlist); auto args_set_show - = add_setshow_string_noescape_cmd ("args", class_run, - &inferior_args_scratch, _("\ + = add_setshow_string_noescape_cmd ("args", class_run, _("\ Set argument list to give program being debugged when it is started."), _("\ Show argument list to give program being debugged when it is started."), _("\ Follow this command with any number of args, to be passed to the program."), - set_args_command, + set_args_value, + get_args_value, show_args_command, &setlist, &showlist); set_cmd_completer (args_set_show.set, filename_completer); |