]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/infcmd.c
gdb: make set/show args work with $_gdb_setting_str
authorAndrew Burgess <aburgess@redhat.com>
Tue, 4 Apr 2023 08:56:00 +0000 (09:56 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 28 Apr 2023 21:50:46 +0000 (22:50 +0100)
commitcc09d372f664410aea226bfaa246aeb74fee8126
tree75b1a2f6947e106b076b3a6c95574795b3917538
parent33c054b015b99e92dcfba1b997a25b7ae8e01e0b
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>
gdb/infcmd.c
gdb/testsuite/gdb.multi/gdb-settings.c [new file with mode: 0644]
gdb/testsuite/gdb.multi/gdb-settings.exp [new file with mode: 0644]