Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Pedro Alves <pedro@palves.net>, gdb-patches@sourceware.org
Subject: Re: [PATCH 3/3] Make scoped_restore_current_thread's cdtors exception free (RFC)
Date: Wed, 8 Jul 2020 23:49:30 -0400	[thread overview]
Message-ID: <58a4020f-fbbb-611f-eb23-c1b3fa25d4f2@simark.ca> (raw)
In-Reply-To: <20200708233125.1030-4-pedro@palves.net>

On 2020-07-08 7:31 p.m., Pedro Alves wrote:
> If the remote target closes while we're reading registers/memory for
> restoring the selected frame in scoped_restore_current_thread's dtor,
> the corresponding TARGET_CLOSE_ERROR error is swallowed by the
> scoped_restore_current_thread's dtor, because letting exceptions
> escape from a dtor is bad.  It isn't great to lose that errors like
> that, though.  I've been thinking about how to avoid it, and I came up
> with this patch.
> 
> The idea here is to make scoped_restore_current_thread's dtor do as
> little as possible, to avoid any work that might throw in the first
> place.  And to do that, instead of having the dtor call
> restore_selected_frame, which re-finds the previously selected frame,
> just record the frame_id/level of the desired selected frame, and have
> get_selected_frame find the frame the next time it is called.  In
> effect, this implements most of Cagney's suggestion, here:
> 
>   /* On demand, create the selected frame and then return it.  If the
>      selected frame can not be created, this function prints then throws
>      an error.  When MESSAGE is non-NULL, use it for the error message,
>      otherwize use a generic error message.  */
>   /* FIXME: cagney/2002-11-28: At present, when there is no selected
>      frame, this function always returns the current (inner most) frame.
>      It should instead, when a thread has previously had its frame
>      selected (but not resumed) and the frame cache invalidated, find
>      and then return that thread's previously selected frame.  */
>   extern struct frame_info *get_selected_frame (const char *message);
> 
> The only thing missing to fully implement that would be to make
> reinit_frame_cache just clear selected_frame instead of calling
> select_frame(NULL), and the call select_frame(NULL) explicitly in the
> places where we really wanted reinit_frame_cache to go back to the
> current frame too.  That can done separately, though, I'm not
> proposing to do that in this patch.
> 
> restore_selected_frame should really move from thread.c to frame.c,
> but I didn't do that here, just to avoid churn in the patch while it
> collects comments.  I will do that as a preparatory patch if people
> agree with this approach.
> 
> Incidentally, this patch alone would fix the crashes fixed by the
> previous patches in the series, because with this,
> scoped_restore_current_thread's constructor doesn't throw either.

I don't understand all the code changes, the but the idea sounds fine
to me.

> -/* Select frame FI (or NULL - to invalidate the current frame).  */
> +/* Select frame FI (or NULL - to invalidate the selected frame).  */
>  
>  void
>  select_frame (struct frame_info *fi)
>  {
>    selected_frame = fi;
> +  selected_frame_level = frame_relative_level (fi);
> +  if (selected_frame_level == 0)
> +    {
> +      /* Treat the current frame especially -- we want to always
> +	 save/restore it without warning, even if the frame ID changes
> +	 (see restore_selected_frame).  Also get_frame_id may access
> +	 the target's registers/memory, and thus skipping get_frame_id
> +	 optimizes the common case.  */
> +      selected_frame_level = -1;
> +      selected_frame_id = null_frame_id;
> +    }
> +  else
> +    selected_frame_id = get_frame_id (fi);
> +

I don't really understand this part, why don't we want to set selected_frame_level
and selected_frame_id when the level is 0.  I'm more interested by why it wouldn't
be correct or how it would break things, rather than the optimization aspect.

Simon


  reply	other threads:[~2020-07-09  3:49 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-08 23:31 [PATCH 0/3] Fix crash if connection drops in scoped_restore_current_thread's ctor Pedro Alves
2020-07-08 23:31 ` [PATCH 1/3] Fix crash if connection drops in scoped_restore_current_thread's ctor, part 1 Pedro Alves
2020-07-09  3:17   ` Simon Marchi
2020-07-09 10:51     ` Pedro Alves
2020-07-09 14:13       ` Simon Marchi
2020-07-08 23:31 ` [PATCH 2/3] Fix crash if connection drops in scoped_restore_current_thread's ctor, part 2 Pedro Alves
2020-07-09  3:31   ` Simon Marchi
2020-07-09 11:12     ` Pedro Alves
2020-07-09 14:16       ` Simon Marchi
2020-07-09 17:23         ` Pedro Alves
2020-07-09 17:28           ` Simon Marchi
2020-07-08 23:31 ` [PATCH 3/3] Make scoped_restore_current_thread's cdtors exception free (RFC) Pedro Alves
2020-07-09  3:49   ` Simon Marchi [this message]
2020-07-09 11:56     ` Pedro Alves
2020-07-09 12:09       ` Pedro Alves
2020-07-09 15:40       ` Simon Marchi
2020-07-09 22:22         ` Pedro Alves
2020-07-10  2:55           ` Simon Marchi
2020-10-30  1:13             ` Pedro Alves
2020-10-30  1:37               ` [pushed] Move lookup_selected_frame to frame.c Pedro Alves
2020-10-30  7:44               ` [PATCH 3/3] Make scoped_restore_current_thread's cdtors exception free (RFC) Aktemur, Tankut Baris via Gdb-patches
2020-10-30 11:32                 ` Pedro Alves
2020-10-31 14:35                   ` [PATCH] Fix frame cycle detection (Re: [PATCH 3/3] Make scoped_restore_current_thread's cdtors exception free (RFC)) Pedro Alves
2020-11-09 14:05                     ` Aktemur, Tankut Baris via Gdb-patches
2020-11-16 13:48                       ` Tom de Vries
2020-11-16 14:57                         ` Pedro Alves
2020-07-10 23:02 ` [PATCH 0/3] Fix crash if connection drops in scoped_restore_current_thread's ctor Pedro Alves
2020-07-22 19:37   ` Simon Marchi
2020-07-22 20:37     ` Pedro Alves
2020-07-22 20:47       ` Simon Marchi
2020-07-23 15:28         ` [pushed] Don't touch frame_info objects if frame cache was reinitialized (was: Re: [PATCH 0/3] Fix crash if connection drops in scoped_restore_current_thread's ctor) Pedro Alves

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=58a4020f-fbbb-611f-eb23-c1b3fa25d4f2@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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