[PATCH 5/6] gdb: Remove cleanup from linux-fork.c:inferior_call_waitpid

Andrew Burgess andrew.burgess@embecosm.com
Wed Jan 9 13:33:00 GMT 2019


* Pedro Alves <palves@redhat.com> [2019-01-09 12:54:59 +0000]:

> On 01/01/2019 10:45 PM, Andrew Burgess wrote:
> 
> > +/* Temporarily switch to the infrun state stored on the fork_info
> > +   identified by a given ptid_t.  When this object goes out of scope,
> > +   restore the currently selected infrun state.   */
> > +
> > +class scoped_switch_fork_info
> >  {
> > -  struct fork_info *oldfp = (struct fork_info *) fp;
> > +public:
> > +  /* Switch to the infrun state held on the fork_info identified by
> > +     PPTID.  If PPTID is the current inferior then no switch is done.  */
> > +  scoped_switch_fork_info (ptid_t pptid)
> 
> (Nit, "explicit scoped_switch_fork_info")
> 
> > +    : m_oldfp (nullptr)
> > +  {
> > +    if (pptid != inferior_ptid)
> > +      {
> > +	struct fork_info *newfp = nullptr;
> > +
> > +	/* Switch to pptid.  */
> > +	m_oldfp = find_fork_ptid (inferior_ptid);
> > +	gdb_assert (m_oldfp != nullptr);
> > +	newfp = find_fork_ptid (pptid);
> > +	gdb_assert (newfp != nullptr);
> > +	fork_save_infrun_state (m_oldfp, 1);
> > +	remove_breakpoints ();
> > +	fork_load_infrun_state (newfp);
> > +	insert_breakpoints ();
> > +      }
> > +  }
> >  
> > -  if (oldfp)
> > -    {
> > -      /* Switch back to inferior_ptid.  */
> > -      remove_breakpoints ();
> > -      fork_load_infrun_state (oldfp);
> > -      insert_breakpoints ();
> > -    }
> > -}
> > +  /* Restore the previously selected infrun state.  If the constructor
> > +     didn't need to switch states, then nothing is done here either.  */
> > +  ~scoped_switch_fork_info ()
> > +  {
> > +    if (m_oldfp != nullptr)
> > +      {
> > +	/* Switch back to inferior_ptid.  */
> > +	remove_breakpoints ();
> > +	fork_load_infrun_state (m_oldfp);
> > +	insert_breakpoints ();
> > +      }
> 
> When writing destructors, we need to keep in mind that if an
> exception escapes, gdb is terminated on the spot.
> 
> Things aren't usually correct in the cleanup version either,
> since an exception escaping while running cleanups leaves
> the cleanup chain with dangling cleanups, but I think that
> these conversions are the ideal time to fix it up.
> 
> The solution will usually be to swallow exceptions in the
> dtor with try/catch(...) and try to limp along.

Is it worth using `internal_warning` rather than silently dropping the
exception?

Thanks,
Andrew



More information about the Gdb-patches mailing list