Bug 28085 - Per-inferior settings are not displayed properly with MI/Python/Guile/$_gdb_setting/with command
Summary: Per-inferior settings are not displayed properly with MI/Python/Guile/$_gdb_s...
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-14 04:44 UTC by Simon Marchi
Modified: 2021-07-14 04:44 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Marchi 2021-07-14 04:44:23 UTC
Some settings, such as the inferior arguments (the "set args" command) are not global, but per-inferior.  When the "set args" command is used, the args are written to a scratch variable, inferior_args_scratch.  The set callback then moves the value from this scratch variable to a field in the inferior structure.  When using the "show args" command, the value is read from that field in the inferior structure.  The scratch variable is not used.

For MI/Python/Guile/$_gdb_setting/the with command though, the value for the "args" setting is always read from the scratch variable.  This means that if you have two inferior, set the args of both and try to get the value of the first one, you'll get the wrong value.  Here's an illustration using Python:

(gdb) add-inferior 
[New inferior 2]
Added inferior 2
(gdb) set args inf1-args
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) set args inf2-args
(gdb) python print(gdb.parameter('args'))
inf2-args
(gdb) inferior 1
[Switching to inferior 1 [<null>] (<noexec>)]
(gdb) python print(gdb.parameter('args'))
inf2-args   <---- wrong
(gdb) show args
Argument list to give program being debugged when it is started is "inf1-args".

I have a patch in the pipeline for this.  It is here, if anybody cares and wants a preview:

https://review.lttng.org/c/binutils-gdb/+/5831

The idea is to get rid of this scratch variable, and instead allow settings to implement some callback to:

 - set the value
 - get the value
 - show the value (for the CLI)

I said "per-inferior" in the subject, but in reality this problem could pop up for any setting where the registered variable isn't the source of truth, where the set command moves the value somewhere else.