/* Thread iterators and ranges for GDB, the GNU debugger.
- Copyright (C) 2018-2019 Free Software Foundation, Inc.
+ Copyright (C) 2018-2020 Free Software Foundation, Inc.
This file is part of GDB.
#include "gdbsupport/filtered-iterator.h"
#include "gdbsupport/next-iterator.h"
#include "gdbsupport/safe-iterator.h"
+#include "thread-map.h"
/* A forward iterator that iterates over a given inferior's
threads. */
/* Create a one-past-end iterator. */
all_threads_iterator ()
- : m_thr (nullptr)
+ : m_inf (nullptr)
{}
- thread_info *operator* () const { return m_thr; }
+ thread_info *operator* () const;
all_threads_iterator &operator++ ()
{
}
bool operator== (const all_threads_iterator &other) const
- { return m_thr == other.m_thr; }
+ {
+ if (m_inf != other.m_inf)
+ return false;
+
+ /* Inferiors of both iterators are equal. */
+ if (m_inf == NULL) {
+ /* They are both ended iterators. */
+ return true;
+ } else {
+ /* Do they both point to the same thread? */
+ return m_thr_iter == other.m_thr_iter;
+ }
+ }
bool operator!= (const all_threads_iterator &other) const
- { return m_thr != other.m_thr; }
+ {
+ return !(*this == other);
+ }
private:
/* Advance to the next thread. */
void advance ();
private:
- /* The current inferior and thread. M_THR is NULL if we reached the
+ /* The current inferior and thread. M_INF is NULL if we reached the
end of the threads list of the last inferior. */
inferior *m_inf;
- thread_info *m_thr;
+ ptid_thread_map::const_iterator m_thr_iter;
};
/* Iterate over all threads that match a given PTID. */
/* Creates an iterator that iterates over all threads that match
FILTER_PTID. */
- explicit all_matching_threads_iterator (ptid_t filter_ptid);
+ all_matching_threads_iterator (process_stratum_target *filter_target,
+ ptid_t filter_ptid);
/* Create a one-past-end iterator. */
all_matching_threads_iterator ()
: m_inf (nullptr),
- m_thr (nullptr),
+ m_filter_target (nullptr),
m_filter_ptid (minus_one_ptid)
{}
- thread_info *operator* () const { return m_thr; }
+ thread_info *operator* () const;
all_matching_threads_iterator &operator++ ()
{
}
bool operator== (const all_matching_threads_iterator &other) const
- { return m_thr == other.m_thr; }
+ {
+ if (m_inf != other.m_inf)
+ return false;
+
+ /* Inferiors of both iterators are equal. */
+ if (m_inf == NULL) {
+ /* They are both ended iterators. */
+ return true;
+ } else {
+ /* Do they both point to the same thread? */
+ return m_thr_iter == other.m_thr_iter;
+ }
+ }
bool operator!= (const all_matching_threads_iterator &other) const
- { return m_thr != other.m_thr; }
+ {
+ return !(* this == other);
+ }
private:
/* Advance to next thread, skipping filtered threads. */
inferior *m_inf;
/* The current thread. */
- thread_info *m_thr;
+ ptid_thread_map::const_iterator m_thr_iter;
/* The filter. */
+ process_stratum_target *m_filter_target;
ptid_t m_filter_ptid;
};
struct all_matching_threads_range
{
public:
- explicit all_matching_threads_range (ptid_t filter_ptid)
- : m_filter_ptid (filter_ptid)
+ all_matching_threads_range (process_stratum_target *filter_target,
+ ptid_t filter_ptid)
+ : m_filter_target (filter_target), m_filter_ptid (filter_ptid)
{}
all_matching_threads_range ()
- : m_filter_ptid (minus_one_ptid)
+ : m_filter_target (nullptr), m_filter_ptid (minus_one_ptid)
{}
all_matching_threads_iterator begin () const
- { return all_matching_threads_iterator (m_filter_ptid); }
+ { return all_matching_threads_iterator (m_filter_target, m_filter_ptid); }
all_matching_threads_iterator end () const
{ return all_matching_threads_iterator (); }
private:
/* The filter. */
+ process_stratum_target *m_filter_target;
ptid_t m_filter_ptid;
};
class all_non_exited_threads_range
{
public:
- explicit all_non_exited_threads_range (ptid_t filter_ptid)
- : m_filter_ptid (filter_ptid)
+ all_non_exited_threads_range (process_stratum_target *filter_target,
+ ptid_t filter_ptid)
+ : m_filter_target (filter_target), m_filter_ptid (filter_ptid)
{}
all_non_exited_threads_range ()
- : m_filter_ptid (minus_one_ptid)
+ : m_filter_target (nullptr), m_filter_ptid (minus_one_ptid)
{}
all_non_exited_threads_iterator begin () const
- { return all_non_exited_threads_iterator (m_filter_ptid); }
+ { return all_non_exited_threads_iterator (m_filter_target, m_filter_ptid); }
all_non_exited_threads_iterator end () const
{ return all_non_exited_threads_iterator (); }
private:
+ process_stratum_target *m_filter_target;
ptid_t m_filter_ptid;
};