This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 3/3] Replace home-grown linked-lists in FreeBSD's native target with STL lists.


On Wednesday, August 09, 2017 08:16:29 PM Simon Marchi wrote:
> On 2017-08-09 19:47, John Baldwin wrote:
> > diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
> > index 721e72b85c..c89343a24f 100644
> > --- a/gdb/fbsd-nat.c
> > +++ b/gdb/fbsd-nat.c
> > @@ -41,6 +41,8 @@
> >  #include "elf-bfd.h"
> >  #include "fbsd-nat.h"
> > 
> > +#include <list>
> > +
> >  /* Return the name of a file that can be opened to get the symbols for
> >     the child process identified by PID.  */
> > 
> > @@ -712,13 +714,7 @@ fbsd_update_thread_list (struct target_ops *ops)
> >    sake.  FreeBSD versions newer than 9.1 contain both fixes.
> >  */
> > 
> > -struct fbsd_fork_info
> > -{
> > -  struct fbsd_fork_info *next;
> > -  ptid_t ptid;
> > -};
> > -
> > -static struct fbsd_fork_info *fbsd_pending_children;
> > +static std::list<ptid_t> fbsd_pending_children;
> 
> Can't this be a forward_list as well?

Not trivially.  fbsd_is_child_pending has to walk the list looking for a
specific PID and remove that specific list entry (not always the first
entry).  Right now this is using the following loop:

   for (auto it = fbsd_pending_children.begin ();
       it != fbsd_pending_children.end (); it++)
     if (it->pid () == pid)
       {
         ptid_t ptid = *it;
         fbsd_pending_children.erase (it);
         return ptid;
       }
   return null_ptid;

I'm not sure if it's legal to do something like this for a forward_list:

   for (auto it = fbsd_pending_children.before_begin ();
        it + 1 != fbsd_pending_children.end (); it++)
    if ((it + 1)->pid () == pid)
       {
         ptid_t ptid = *(it + 1);
         fbsd_pending_childern.erase_after (it);
         return ptid;
       }
   return null_ptid;

Even if it is legal, I'm not sure it is more readable.  These lists should
generally be quite small, so I think readability is more important than
optimization in this case.

-- 
John Baldwin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]