]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: make all_inferiors_safe actually work
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 14 Jul 2021 16:31:36 +0000 (12:31 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 17 Jul 2021 12:54:40 +0000 (08:54 -0400)
The test gdb.threads/fork-plus-threads.exp fails since 08bdefb58b78
("gdb: make inferior_list use intrusive_list"):

    FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left

Looking at the log, we see that we are left with a bunch of inferiors in
the detach-on-fork=off case:

    info inferiors^M
      Num  Description       Connection           Executable        ^M
    * 1    <null>                                 <snip>/fork-plus-threads ^M
      2    <null>                                 <snip>/fork-plus-threads ^M
      3    <null>                                 <snip>/fork-plus-threads ^M
      4    <null>                                 <snip>/fork-plus-threads ^M
      5    <null>                                 <snip>/fork-plus-threads ^M
      6    <null>                                 <snip>/fork-plus-threads ^M
      7    <null>                                 <snip>/fork-plus-threads ^M
      8    <null>                                 <snip>/fork-plus-threads ^M
      9    <null>                                 <snip>/fork-plus-threads ^M
      10   <null>                                 <snip>/fork-plus-threads ^M
      11   <null>                                 <snip>/fork-plus-threads ^M
    (gdb) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left

when we expect to have just one.  The problem is prune_inferiors not
pruning inferiors.  And this is caused by all_inferiors_safe not
actually iterating on inferiors.  The current implementation:

  inline all_inferiors_safe_range
  all_inferiors_safe ()
  {
    return {};
  }

default-constructs an all_inferiors_safe_range, which default-constructs
an all_inferiors_safe_iterator as its m_begin field, which
default-constructs a all_inferiors_iterator.  A default-constructed
all_inferiors_iterator is an end iterator, which means we have
constructed an (end,end) all_inferiors_safe_range.

We actually need to pass down the list on which we want to iterator
(that is the inferior_list global), so that all_inferiors_iterator's
first constructor is chosen.  We also pass nullptr as the proc_target
filter.  In this case, we don't do any filtering, but if in the future
all_inferiors_safe needed to allow filtering on process target (like
all_inferiors does), we could pass down a process target pointer.

basic_safe_iterator's constructor needs to be changed to allow
constructing the wrapped iterator with multiple arguments, not just one.

With this, gdb.threads/fork-plus-threads.exp is passing once again for
me.

Change-Id: I650552ede596e3590c4b7606ce403690a0278a01

gdb/inferior.h
gdbsupport/safe-iterator.h

index 6662a3bde4635190e19360c1d83beecdeee04948..94fbac0fc5711365f72c47fe882753cd06552cdf 100644 (file)
@@ -676,7 +676,7 @@ extern intrusive_list<inferior> inferior_list;
 inline all_inferiors_safe_range
 all_inferiors_safe ()
 {
-  return {};
+  return all_inferiors_safe_range (nullptr, inferior_list);
 }
 
 /* Returns a range representing all inferiors, suitable to use with
index 5cfc5b6ee692ec4776ea8c6dfc42a56ce85b7e41..53868d3b3eecfc1987cdaf871c3508289610b29a 100644 (file)
@@ -48,11 +48,11 @@ public:
   typedef typename Iterator::iterator_category iterator_category;
   typedef typename Iterator::difference_type difference_type;
 
-  /* Construct using the given argument; the end iterator is default
-     constructed.  */
-  template<typename Arg>
-  explicit basic_safe_iterator (Arg &&arg)
-    : m_it (std::forward<Arg> (arg)),
+  /* Construct the begin iterator using the given arguments; the end iterator is
+     default constructed.  */
+  template<typename... Args>
+  explicit basic_safe_iterator (Args &&...args)
+    : m_it (std::forward<Args> (args)...),
       m_next (m_it)
   {
     if (m_it != m_end)