public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andrew Burgess <andrew.burgess@embecosm.com>, gdb-patches@sourceware.org
Subject: Re: [PATCHv2] gdb: avoid premature dummy frame garbage collection
Date: Fri, 28 May 2021 22:03:27 -0400	[thread overview]
Message-ID: <37becdeb-57ac-7895-9056-bb7b03b6e691@polymtl.ca> (raw)
In-Reply-To: <20210525104905.2234888-1-andrew.burgess@embecosm.com>



On 2021-05-25 6:49 a.m., Andrew Burgess wrote:
> From: Richard Bunt <richard.bunt@arm.com>
> 
> Consider the following chain of events:
> 
>   * GDB is performing an inferior call, and
> 
>   * the inferior calls longjmp, and
> 
>   * GDB detects that the longjmp has completed, stops, and enters
>     check_longjmp_breakpoint_for_call_dummy (in breakpoint.c), and
> 
>   * GDB tries to unwind the stack in order to check that the dummy
>     frame (setup for the inferior call) is still on the stack, but
> 
>   * The unwind fails, possibly due to missing debug information, so
> 
>   * GDB incorrectly concludes that the inferior has longjmp'd past the
>     dummy frame, and so deletes the dummy frame, including the dummy
>     frame breakpoint, but then
> 
>   * The inferior continues, and eventually returns to the dummy frame,
>     which is usually (always?) on the stack, the inferior starts
>     trying to execute the random contents of the stack, this results
>     in undefined behaviour.
> 
> This situation is already warned about in the comment on the function
> check_longjmp_breakpoint_for_call_dummy where we say:
> 
>    You should call this function only at places where it is safe to currently
>    unwind the whole stack.  Failed stack unwind would discard live dummy
>    frames.
> 
> The warning here is fine, the problem is that, even though we call the
> function from a location within GDB where we hope to be able to
> unwind, sometime the state of the inferior means that the unwind will
> not succeed.
> 
> This commit tries to improve the situation by adding the following
> additional check; when GDB fails to find the dummy frame on the stack,
> instead of just assuming that the dummy frame can be garbage
> collected, first find the stop_reason for the last frame on the stack.
> If this stop_reason indicates that the stack unwinding may have failed
> then we assume that the dummy frame is still in use.  However, if the
> last frame's stop_reason indicates that the stack unwind completed
> successfully then we can be confident that the dummy frame is no
> longer in use, and we garbage collect it.
> 
> Tested on x86-64 GNU/Linux.

LGTM, thanks!

Simon

      reply	other threads:[~2021-05-29  2:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19 12:29 [PATCH] " Andrew Burgess
2021-05-20 14:30 ` Simon Marchi
2021-05-21  8:42   ` Andrew Burgess
2021-05-25 10:49 ` [PATCHv2] " Andrew Burgess
2021-05-29  2:03   ` Simon Marchi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37becdeb-57ac-7895-9056-bb7b03b6e691@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).