[PATCH 8/8] Fix removing inferiors from within "thread apply" commands
Yao Qi
qiyaoltc@gmail.com
Thu Apr 13 11:33:00 GMT 2017
Pedro Alves <palves@redhat.com> writes:
> @@ -313,9 +319,31 @@ public:
> explicit inferior (int pid);
> ~inferior ();
>
> + /* Returns true if we can delete this inferior. We can't delete it
> + if it is the current inferior, or if there's code out there that
> + relies on it existing (m_refcount > 0). */
> + bool deletable () const
> + {
> + return m_refcount == 0 && this != current_inferior ();
> + }
> +
> /* Pointer to next inferior in singly-linked list of inferiors. */
> struct inferior *next = NULL;
>
> + /* Increase the refcount. */
> + void incref ()
> + {
> + gdb_assert (m_refcount >= 0);
> + m_refcount++;
> + }
> +
> + /* Decrease the refcount. */
> + void decref ()
> + {
> + m_refcount--;
> + gdb_assert (m_refcount >= 0);
> + }
> +
> /* Convenient handle (GDB inferior id). Unique across all
> inferiors. */
> int num = 0;
> @@ -431,6 +459,12 @@ public:
>
> /* Per inferior data-pointers required by other GDB modules. */
> REGISTRY_FIELDS;
> +
> +private:
> + /* If this is > 0, then it means there's code out there that relies
> + on this inferior existing. Don't allow deleting it in that
> + case. */
> + int m_refcount = 0;
> };
Can we move them to a super class, so that both thread and inferior can
extend it?
>
> -/* Switch from one thread to another. */
> +/* Switch to no thread selected. */
>
> -void
> -switch_to_thread (ptid_t ptid)
> +static void
> +switch_to_no_thread ()
> {
> - /* Switch the program space as well, if we can infer it from the now
> - current thread. Otherwise, it's up to the caller to select the
> - space it wants. */
> - if (ptid != null_ptid)
> - {
> - struct inferior *inf;
> + if (inferior_ptid == null_ptid)
> + return;
>
> - inf = find_inferior_ptid (ptid);
> - gdb_assert (inf != NULL);
> - set_current_program_space (inf->pspace);
> - set_current_inferior (inf);
> - }
> + inferior_ptid = null_ptid;
> + reinit_frame_cache ();
> + stop_pc = ~(CORE_ADDR) 0;
> +}
>
> - if (ptid == inferior_ptid)
> +/* Switch from one thread to another. */
> +
> +static void
> +switch_to_thread (thread_info *thr)
> +{
> + gdb_assert (thr != NULL);
> +
> + if (inferior_ptid == thr->ptid)
> return;
>
> - inferior_ptid = ptid;
> + /* Switch the current program space and current inferior as
> + well. */
> + set_current_program_space (thr->inf->pspace);
> + set_current_inferior (thr->inf);
> +
> + inferior_ptid = thr->ptid;
Can these code be replaced by switch_to_thread_no_regs?
--
Yao (齐尧)
More information about the Gdb-patches
mailing list