public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 0/4] Smart pointer wrapper for frame_info
Date: Thu,  7 Apr 2022 17:19:01 -0600	[thread overview]
Message-ID: <20220407231905.541589-1-tom@tromey.com> (raw)

GDB occasionally gets bugs where a frame_info is kept alive across a
call to reinit_frame_cache.  This causes a use-after-free and, if
you're lucky, a crash.

This series aims to make this setup more "reliable", in the sense that
you'll always get a crash if you break the rules.  This is done by
wrapping frame_info in a smart pointer class, and having
reinit_frame_cache invalidate all the pointers.

I looked into a more ambitious approach: having the frame_info
wrappers automatically "reinflate" on demand after invalidation.
However, I couldn't readily make this work.  I am not completely sure,
but I think there are a few issues.

First, sometimes reinit_frame_cache is called after other global state
has been changed.  This means that one can't call get_frame_id from
there.

Second, I think computing the frame_id requires some unwinding.  This
means that it doesn't make sense to eagerly compute the frame_id when
constructing a frame_info.

This brings up another point -- most frame_info_ptr objects will not
really be needed after a reinit.  So, saving them all is an
unnecessary expense.  But accepting this means, essentially, accepting
the status quo.

It's possible to add a "stash" method to the new smart pointer class,
to make selected instances auto-inflate.  However I haven't done so.
That may be more expensive as well, as these objects are often passed
by value in the current series; and again it doesn't seem hugely
better than the status quo.

Regression tested on x86-64 Fedora 34.

Let me know what you think.  I tend to think that at least patch #2
could go in regardless of whether the rest of this series does.

Tom



             reply	other threads:[~2022-04-07 23:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07 23:19 Tom Tromey [this message]
2022-04-07 23:19 ` [PATCH 1/4] Switch order of comparison in some spots Tom Tromey
2022-04-08  0:25   ` John Baldwin
2022-04-08 17:40   ` Pedro Alves
2022-04-07 23:19 ` [PATCH 2/4] Remove frame_id_eq Tom Tromey
2022-04-08  0:27   ` John Baldwin
2022-04-07 23:19 ` [PATCH 3/4] Introduce frame_info_ptr smart pointer class Tom Tromey
2022-04-08 14:06   ` Bruno Larsen
2022-04-08 15:18     ` Tom Tromey
2022-04-08 16:45       ` Bruno Larsen
2022-04-08 15:49   ` Pedro Alves
2022-04-08 19:03     ` Tom Tromey
2022-04-08 19:22       ` Pedro Alves
2022-04-21 12:08 ` [PATCH 0/4] Smart pointer wrapper for frame_info Bruno Larsen
2022-04-22 14:58   ` Tom Tromey

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=20220407231905.541589-1-tom@tromey.com \
    --to=tom@tromey.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).