[RFA,3/3] Document 'set|show exec-file-mismatch (reload|warn|off)'

Message ID 20191221143632.15990-4-philippe.waroquiers@skynet.be
State New, archived
Headers

Commit Message

Philippe Waroquiers Dec. 21, 2019, 2:36 p.m. UTC
  Mention in NEWS the new option and the set/show commands.

Document in gdb.texinfo the new option and the set/show commands.

gdb/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Mention the new option and the set/show commands.

gdb/doc/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Attach): Document the new option and the
	set/show commands.
	(Connecting): Reference the exec-file-mismatch option.
---
 gdb/NEWS            | 12 ++++++++++++
 gdb/doc/gdb.texinfo | 31 +++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
  

Comments

Eli Zaretskii Dec. 21, 2019, 5:44 p.m. UTC | #1
> From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> Date: Sat, 21 Dec 2019 15:36:32 +0100
> 
> +  Set or show the option 'exec-file-mismatch'.  When GDB attaches to
> +  a running program and can determine the running program, this new option

"attached to a running program and can determine the running program"
sounds strange and confusing (if GDB has attached to a program, it
should not have any trouble determining it, right?).  I guess you
meant something like

  When GDB attaches to a running process, and can determine the
  executable program file the process runs, this new option ...

> +  indicates how to handle a mismatch between the current exec-file and
> +  the automatically detected file.

Here, instead of "current exec-file" I'd use "the program file on
disk", and instead of "automatically detected" I'd use "the program
file used to start the process".  The main point is not to introduce
terminology not referenced in previous text, otherwise you risk losing
or confusing the reader.

> +  and reload the automatically determined file after user confirmation.

Well, the "automatically determined file" can no longer be reloaded,
since it was updated on disk, right?

> +@anchor{set exec-file-mismatch}
> +If the debugger can determine the program running in the process
> +and this program does not match the current exec-file, the option
> +@code{exec-file-mismatch} specifies how to handle the mismatch.

Suggest to explain how the mismatch is determined, because otherwise
this text sounds unclear and maybe confusing.

> +@table @code
> +@kindex exec-file-mismatch
> +@cindex set exec-file-mismatch
> +@item set exec-file-mismatch @samp{reload|warn|off}
> +In case of mismatch between the current exec-file and the automatically
> +determined exec-file of the PID the debugger is attaching to,
> +@samp{reload} indicates to give a warning to the user and reload
> +the automatically determined exec-file.  The user will be asked to
> +confirm the loading of the automatically determined file.
> +With @samp{warn}, @value{GDBN} just gives a warning to the user to
> +signal the mismatch.  @samp{off} indicates to not check for mismatch.
> +The default value is @samp{reload}.

I'd reword this text as follows:

  Whether to detect mismatch between the program file used to start
  the process and the current executable file of that program on disk.
  If @samp{reload}, the default, display a warning and ask the user
  whether to reload the program's file; if @samp{warn}, just display a
  warning; if @samp{off}, don't attempt to detect a mismatch.

> +Some remote targets allow @value{GDBN} to determine the program running
> +in the process the debugger is attaching to.  In such a case, @value{GDBN}
> +uses the value of @code{exec-file-mismatch} to handle a possible mismatch
> +between the program running in the process and the current exec-file.
> +(@pxref{set exec-file-mismatch}).

The period before @pxref in parentheses is redundant and should be
removed.

Thanks.
  
Philippe Waroquiers Dec. 21, 2019, 8:15 p.m. UTC | #2
Thanks for the detailed comments, I will fix/improve
according to your suggestions.

However, your comments make me think that the words used
in the command itself might have to be improved, as the
word "reload" seems confusing.

I will try to clarify what "reload" currently does using an example.

Imagine you have 2 running processes:
  process PID 123 running program xxxxx
  process PID 345 running program yyyyy

When GDB attaches to 123, it determines that the program
is xxxxx.  When detaching, and then attaching to 345,
GDB git master version *silently keeps* xxxxx as exec-file
for PID 345.

When the below new option is reload or warn, when attaching
to 345, GDB will determine that the exec-file of 345 
is yyyyy.
It then compares the file name yyyyy with the current exec file xxxxx,
and because file differs, it will warn the user and (for reload option)
ask the user if the exec-file yyyyy must be reloaded.

So, "reload" does not mean:  "reload the same file if it was changed on disk",
it means "reload a new exec-file, because the PID we attach to
runs another exec-file".

Note that with the above 2 processes, GDB git master similarly uses the wrong
file if you do:  
   gdb xxxxx
   (gdb) attach 345
      => GDB now silently uses the (wrong) file xxxxx to debug 345.
That is equally solved (or warned) with the new option.

So, maybe "reload" in 'set exec-file-mismatch reload|warn|off' should be replaced
by a less confusing word?

Maybe 'set exec-file-mismatch ask-to-load|warn|off' ?


Feedback ? Any other suggestion ?


Thanks

Philippe


On Sat, 2019-12-21 at 19:44 +0200, Eli Zaretskii wrote:
> > From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> > Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> > Date: Sat, 21 Dec 2019 15:36:32 +0100
> > 
> > +  Set or show the option 'exec-file-mismatch'.  When GDB attaches to
> > +  a running program and can determine the running program, this new option
> 
> "attached to a running program and can determine the running program"
> sounds strange and confusing (if GDB has attached to a program, it
> should not have any trouble determining it, right?).  I guess you
> meant something like
> 
>   When GDB attaches to a running process, and can determine the
>   executable program file the process runs, this new option ...
> 
> > +  indicates how to handle a mismatch between the current exec-file and
> > +  the automatically detected file.
> 
> Here, instead of "current exec-file" I'd use "the program file on
> disk", and instead of "automatically detected" I'd use "the program
> file used to start the process".  The main point is not to introduce
> terminology not referenced in previous text, otherwise you risk losing
> or confusing the reader.
> 
> > +  and reload the automatically determined file after user confirmation.
> 
> Well, the "automatically determined file" can no longer be reloaded,
> since it was updated on disk, right?
> 
> > +@anchor{set exec-file-mismatch}
> > +If the debugger can determine the program running in the process
> > +and this program does not match the current exec-file, the option
> > +@code{exec-file-mismatch} specifies how to handle the mismatch.
> 
> Suggest to explain how the mismatch is determined, because otherwise
> this text sounds unclear and maybe confusing.
> 
> > +@table @code
> > +@kindex exec-file-mismatch
> > +@cindex set exec-file-mismatch
> > +@item set exec-file-mismatch @samp{reload|warn|off}
> > +In case of mismatch between the current exec-file and the automatically
> > +determined exec-file of the PID the debugger is attaching to,
> > +@samp{reload} indicates to give a warning to the user and reload
> > +the automatically determined exec-file.  The user will be asked to
> > +confirm the loading of the automatically determined file.
> > +With @samp{warn}, @value{GDBN} just gives a warning to the user to
> > +signal the mismatch.  @samp{off} indicates to not check for mismatch.
> > +The default value is @samp{reload}.
> 
> I'd reword this text as follows:
> 
>   Whether to detect mismatch between the program file used to start
>   the process and the current executable file of that program on disk.
>   If @samp{reload}, the default, display a warning and ask the user
>   whether to reload the program's file; if @samp{warn}, just display a
>   warning; if @samp{off}, don't attempt to detect a mismatch.
> 
> > +Some remote targets allow @value{GDBN} to determine the program running
> > +in the process the debugger is attaching to.  In such a case, @value{GDBN}
> > +uses the value of @code{exec-file-mismatch} to handle a possible mismatch
> > +between the program running in the process and the current exec-file.
> > +(@pxref{set exec-file-mismatch}).
> 
> The period before @pxref in parentheses is redundant and should be
> removed.
> 
> Thanks.
  
Terekhov, Mikhail via Gdb-patches Dec. 22, 2019, 2:46 a.m. UTC | #3
On Sat, Dec 21, 2019, 09:37 Philippe Waroquiers <
philippe.waroquiers@skynet.be> wrote:

> Mention in NEWS the new option and the set/show commands.
>
> Document in gdb.texinfo the new option and the set/show commands.
>

When would someone set this to off, or even warn? I'm wondering is it makes
sense to add this setting vs always having the reload behavior?


> gdb/ChangeLog
> YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
>
>         * NEWS: Mention the new option and the set/show commands.
>
> gdb/doc/ChangeLog
> YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
>
>         * gdb.texinfo (Attach): Document the new option and the
>         set/show commands.
>         (Connecting): Reference the exec-file-mismatch option.
> ---
>  gdb/NEWS            | 12 ++++++++++++
>  gdb/doc/gdb.texinfo | 31 +++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index ee10914fd8..1a90862b0d 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,18 @@
>
>  *** Changes since GDB 9
>
> +* New commands
> +
> +set exec-file-mismatch -- Set exec-file-mismatch handling
> (reload|warn|off).
> +show exec-file-mismatch -- Show exec-file-mismatch handling
> (reload|warn|off).
> +  Set or show the option 'exec-file-mismatch'.  When GDB attaches to
> +  a running program and can determine the running program, this new option
> +  indicates how to handle a mismatch between the current exec-file and
> +  the automatically detected file.
> +  'reload' is the default value: in case of mismatch, GDB will warn the
> user
> +  and reload the automatically determined file after user confirmation.
> +
> +
>  *** Changes in GDB 9
>
>  * 'thread-exited' event is now available in the annotations interface.
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 4d25f755d7..a246ba0bf5 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -2904,6 +2904,31 @@ the program is not found) by using the source file
> search path
>  the @code{file} command to load the program.  @xref{Files, ,Commands to
>  Specify Files}.
>
> +@anchor{set exec-file-mismatch}
> +If the debugger can determine the program running in the process
> +and this program does not match the current exec-file, the option
> +@code{exec-file-mismatch} specifies how to handle the mismatch.
> +
> +@table @code
> +@kindex exec-file-mismatch
> +@cindex set exec-file-mismatch
> +@item set exec-file-mismatch @samp{reload|warn|off}
> +In case of mismatch between the current exec-file and the automatically
> +determined exec-file of the PID the debugger is attaching to,
> +@samp{reload} indicates to give a warning to the user and reload
> +the automatically determined exec-file.  The user will be asked to
> +confirm the loading of the automatically determined file.
> +With @samp{warn}, @value{GDBN} just gives a warning to the user to
> +signal the mismatch.  @samp{off} indicates to not check for mismatch.
> +The default value is @samp{reload}.
> +
> +
> +@cindex show exec-file-mismatch
> +@item show exec-file-mismatch
> +Show the current value of @code{exec-file-mismatch}.
> +
> +@end table
> +
>  The first thing @value{GDBN} does after arranging to debug the specified
>  process is to stop it.  You can examine and modify an attached process
>  with all the @value{GDBN} commands that are ordinarily available when
> @@ -21780,6 +21805,12 @@ established.  If you are using @code{gdbserver},
> you may also invoke
>  @code{gdbserver} using the @option{--attach} option
>  (@pxref{Running gdbserver}).
>
> +Some remote targets allow @value{GDBN} to determine the program running
> +in the process the debugger is attaching to.  In such a case, @value{GDBN}
> +uses the value of @code{exec-file-mismatch} to handle a possible mismatch
> +between the program running in the process and the current exec-file.
> +(@pxref{set exec-file-mismatch}).
> +
>  @end table
>
>  @anchor{Host and target files}
> --
> 2.20.1
>
>
  
Philippe Waroquiers Dec. 22, 2019, 9:09 a.m. UTC | #4
On Sat, 2019-12-21 at 21:46 -0500, Christian Biesinger via gdb-patches wrote:
> On Sat, Dec 21, 2019, 09:37 Philippe Waroquiers <
> philippe.waroquiers@skynet.be> wrote:
> 
> > Mention in NEWS the new option and the set/show commands.
> > 
> > Document in gdb.texinfo the new option and the set/show commands.
> > 
> 
> When would someone set this to off, or even warn? I'm wondering is it makes
> sense to add this setting vs always having the reload behavior?
Effectively, I think that in a large majority of the cases, the reload
behavior is the correct thing to do, which is why it is the default value.

However, I have added the option for the following reasons:
* There are today already several features to choose
  flexibly the exec-file and symbol-file (see GDB manual
  "18.1 Commands to Specify Files").  The new option allows to retain
  the flexible manual control, which I assume is needed for some
  use cases.
* Also, the previous trial to fix this problem was based on the notion
  of "sticky" exec-file: if the exec-file was explicitly given
  by the user, then it was never changed automatically when
  attaching to another process having another exec-file.
  IMO, this was not the best approach, as GDB would still
  silently use the wrong file in some cases (such as typo in the PID,
  or successive attach/detach after having given a program file
  as GDB argument).
  But this fix trial also seems to indicate some desire to let the
  user choose (in unusual circumstances) to keep a specific exec file.

Note that for reload and warn, the message given to the user explicitly
mention the 'exec-file-mismatch' option, so that users that need some
control are informed of the possibility.

Once the function 'validate_exec_file' was implemented and called at
the right places, implementing the option itself was not a big deal,
apart of the difficulty of properly naming and documenting the values :).

Thanks
Philippe


> 
> 
> > gdb/ChangeLog
> > YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
> > 
> >         * NEWS: Mention the new option and the set/show commands.
> > 
> > gdb/doc/ChangeLog
> > YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
> > 
> >         * gdb.texinfo (Attach): Document the new option and the
> >         set/show commands.
> >         (Connecting): Reference the exec-file-mismatch option.
> > ---
> >  gdb/NEWS            | 12 ++++++++++++
> >  gdb/doc/gdb.texinfo | 31 +++++++++++++++++++++++++++++++
> >  2 files changed, 43 insertions(+)
> > 
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index ee10914fd8..1a90862b0d 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -3,6 +3,18 @@
> > 
> >  *** Changes since GDB 9
> > 
> > +* New commands
> > +
> > +set exec-file-mismatch -- Set exec-file-mismatch handling
> > (reload|warn|off).
> > +show exec-file-mismatch -- Show exec-file-mismatch handling
> > (reload|warn|off).
> > +  Set or show the option 'exec-file-mismatch'.  When GDB attaches to
> > +  a running program and can determine the running program, this new option
> > +  indicates how to handle a mismatch between the current exec-file and
> > +  the automatically detected file.
> > +  'reload' is the default value: in case of mismatch, GDB will warn the
> > user
> > +  and reload the automatically determined file after user confirmation.
> > +
> > +
> >  *** Changes in GDB 9
> > 
> >  * 'thread-exited' event is now available in the annotations interface.
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 4d25f755d7..a246ba0bf5 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -2904,6 +2904,31 @@ the program is not found) by using the source file
> > search path
> >  the @code{file} command to load the program.  @xref{Files, ,Commands to
> >  Specify Files}.
> > 
> > +@anchor{set exec-file-mismatch}
> > +If the debugger can determine the program running in the process
> > +and this program does not match the current exec-file, the option
> > +@code{exec-file-mismatch} specifies how to handle the mismatch.
> > +
> > +@table @code
> > +@kindex exec-file-mismatch
> > +@cindex set exec-file-mismatch
> > +@item set exec-file-mismatch @samp{reload|warn|off}
> > +In case of mismatch between the current exec-file and the automatically
> > +determined exec-file of the PID the debugger is attaching to,
> > +@samp{reload} indicates to give a warning to the user and reload
> > +the automatically determined exec-file.  The user will be asked to
> > +confirm the loading of the automatically determined file.
> > +With @samp{warn}, @value{GDBN} just gives a warning to the user to
> > +signal the mismatch.  @samp{off} indicates to not check for mismatch.
> > +The default value is @samp{reload}.
> > +
> > +
> > +@cindex show exec-file-mismatch
> > +@item show exec-file-mismatch
> > +Show the current value of @code{exec-file-mismatch}.
> > +
> > +@end table
> > +
> >  The first thing @value{GDBN} does after arranging to debug the specified
> >  process is to stop it.  You can examine and modify an attached process
> >  with all the @value{GDBN} commands that are ordinarily available when
> > @@ -21780,6 +21805,12 @@ established.  If you are using @code{gdbserver},
> > you may also invoke
> >  @code{gdbserver} using the @option{--attach} option
> >  (@pxref{Running gdbserver}).
> > 
> > +Some remote targets allow @value{GDBN} to determine the program running
> > +in the process the debugger is attaching to.  In such a case, @value{GDBN}
> > +uses the value of @code{exec-file-mismatch} to handle a possible mismatch
> > +between the program running in the process and the current exec-file.
> > +(@pxref{set exec-file-mismatch}).
> > +
> >  @end table
> > 
> >  @anchor{Host and target files}
> > --
> > 2.20.1
> > 
> >
  
Eli Zaretskii Dec. 22, 2019, 6:19 p.m. UTC | #5
> From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> Cc: gdb-patches@sourceware.org
> Date: Sat, 21 Dec 2019 21:15:48 +0100
> 
> However, your comments make me think that the words used
> in the command itself might have to be improved, as the
> word "reload" seems confusing.

Yes, I've misunderstood what it means.  The text needs to be rewritten
to make clear what this feature tries to detect.  An example you've
shown could be a good idea.

> So, maybe "reload" in 'set exec-file-mismatch reload|warn|off' should be replaced
> by a less confusing word?
> 
> Maybe 'set exec-file-mismatch ask-to-load|warn|off' ?

How about ask|warn|off ?
  
Tom Tromey Jan. 8, 2020, 12:52 a.m. UTC | #6
Christian> When would someone set this to off, or even warn? I'm wondering is it makes
Christian> sense to add this setting vs always having the reload behavior?

Last time this stuff came up, it turned out there are users who point
gdb at the file with debug symbols while debugging a stripped version on
the target.  IIRC, at the time, build-id and separate debuginfo weren't
widely used, so this was the main way to do this kind of thing.

I don't know if this is still important.  I've only run into trouble
with this behavior, so I welcome the new default at least.

Tom
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index ee10914fd8..1a90862b0d 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,18 @@ 
 
 *** Changes since GDB 9
 
+* New commands
+
+set exec-file-mismatch -- Set exec-file-mismatch handling (reload|warn|off).
+show exec-file-mismatch -- Show exec-file-mismatch handling (reload|warn|off).
+  Set or show the option 'exec-file-mismatch'.  When GDB attaches to
+  a running program and can determine the running program, this new option
+  indicates how to handle a mismatch between the current exec-file and
+  the automatically detected file.
+  'reload' is the default value: in case of mismatch, GDB will warn the user
+  and reload the automatically determined file after user confirmation.
+
+
 *** Changes in GDB 9
 
 * 'thread-exited' event is now available in the annotations interface.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4d25f755d7..a246ba0bf5 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -2904,6 +2904,31 @@  the program is not found) by using the source file search path
 the @code{file} command to load the program.  @xref{Files, ,Commands to
 Specify Files}.
 
+@anchor{set exec-file-mismatch}
+If the debugger can determine the program running in the process
+and this program does not match the current exec-file, the option
+@code{exec-file-mismatch} specifies how to handle the mismatch.
+
+@table @code
+@kindex exec-file-mismatch
+@cindex set exec-file-mismatch
+@item set exec-file-mismatch @samp{reload|warn|off}
+In case of mismatch between the current exec-file and the automatically
+determined exec-file of the PID the debugger is attaching to,
+@samp{reload} indicates to give a warning to the user and reload
+the automatically determined exec-file.  The user will be asked to
+confirm the loading of the automatically determined file.
+With @samp{warn}, @value{GDBN} just gives a warning to the user to
+signal the mismatch.  @samp{off} indicates to not check for mismatch.
+The default value is @samp{reload}.
+
+
+@cindex show exec-file-mismatch
+@item show exec-file-mismatch
+Show the current value of @code{exec-file-mismatch}.
+
+@end table
+
 The first thing @value{GDBN} does after arranging to debug the specified
 process is to stop it.  You can examine and modify an attached process
 with all the @value{GDBN} commands that are ordinarily available when
@@ -21780,6 +21805,12 @@  established.  If you are using @code{gdbserver}, you may also invoke
 @code{gdbserver} using the @option{--attach} option
 (@pxref{Running gdbserver}).
 
+Some remote targets allow @value{GDBN} to determine the program running
+in the process the debugger is attaching to.  In such a case, @value{GDBN}
+uses the value of @code{exec-file-mismatch} to handle a possible mismatch
+between the program running in the process and the current exec-file.
+(@pxref{set exec-file-mismatch}).
+
 @end table
 
 @anchor{Host and target files}