Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* when can find_thread_pid (inferior_ptid) return NULL?
@ 2009-03-26 21:36 Doug Evans
  2009-03-26 22:35 ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Doug Evans @ 2009-03-26 21:36 UTC (permalink / raw)
  To: gdb

Hi.  Some places in gdb assert that find_thread_pid (inferior_ptid)
is never NULL.

e.g.

struct thread_info*
inferior_thread (void)
{
  struct thread_info *tp = find_thread_pid (inferior_ptid);
  gdb_assert (tp);
  return tp;
}

Other places check.  E.g.

make_cleanup_restore_current_thread:

      tp = find_thread_pid (inferior_ptid);
      if (tp)
	tp->refcount++;

Since delete_thread_1 has this:

  /* If this is the current thread, or there's code out there that
     relies on it existing (refcount > 0) we can't delete yet.  Mark
     it as exited, and notify it.  */
  if (tp->refcount > 0
      || ptid_equal (tp->ptid, inferior_ptid))
    {

I would expect that one can always assert
find_thread_pid (inferior_ptid) != NULL.

Is that true?
Or are there situations where it's not true?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: when can find_thread_pid (inferior_ptid) return NULL?
  2009-03-26 21:36 when can find_thread_pid (inferior_ptid) return NULL? Doug Evans
@ 2009-03-26 22:35 ` Pedro Alves
  2009-03-27  0:54   ` Doug Evans
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2009-03-26 22:35 UTC (permalink / raw)
  To: gdb; +Cc: Doug Evans

On Thursday 26 March 2009 21:36:42, Doug Evans wrote:
> Hi.  Some places in gdb assert that find_thread_pid (inferior_ptid)
> is never NULL.

> make_cleanup_restore_current_thread:
> 
>       tp = find_thread_pid (inferior_ptid);
>       if (tp)
> 	tp->refcount++;

I think that in this particular case, it will always be true.

> 
> Since delete_thread_1 has this:
> 
>   /* If this is the current thread, or there's code out there that
>      relies on it existing (refcount > 0) we can't delete yet.  Mark
>      it as exited, and notify it.  */
>   if (tp->refcount > 0
>       || ptid_equal (tp->ptid, inferior_ptid))
>     {
> 
> I would expect that one can always assert
> find_thread_pid (inferior_ptid) != NULL.
> 
> Is that true?
> Or are there situations where it's not true?

When inferior_ptid is null_ptid.  You'll also not
find the old ptid if running the cleanup after something
clears the thread list, e.g., after killing or poping the target.

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: when can find_thread_pid (inferior_ptid) return NULL?
  2009-03-26 22:35 ` Pedro Alves
@ 2009-03-27  0:54   ` Doug Evans
  0 siblings, 0 replies; 3+ messages in thread
From: Doug Evans @ 2009-03-27  0:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb

On Thu, Mar 26, 2009 at 3:35 PM, Pedro Alves <pedro@codesourcery.com> wrote:
> On Thursday 26 March 2009 21:36:42, Doug Evans wrote:
>> Hi.  Some places in gdb assert that find_thread_pid (inferior_ptid)
>> is never NULL.
>
>> make_cleanup_restore_current_thread:
>>
>>       tp = find_thread_pid (inferior_ptid);
>>       if (tp)
>>       tp->refcount++;
>
> I think that in this particular case, it will always be true.
>
>>
>> Since delete_thread_1 has this:
>>
>>   /* If this is the current thread, or there's code out there that
>>      relies on it existing (refcount > 0) we can't delete yet.  Mark
>>      it as exited, and notify it.  */
>>   if (tp->refcount > 0
>>       || ptid_equal (tp->ptid, inferior_ptid))
>>     {
>>
>> I would expect that one can always assert
>> find_thread_pid (inferior_ptid) != NULL.
>>
>> Is that true?
>> Or are there situations where it's not true?
>
> When inferior_ptid is null_ptid.  You'll also not
> find the old ptid if running the cleanup after something
> clears the thread list, e.g., after killing or poping the target.

Ya, I found that out shortly after ^c^c.  What a surprise.  :-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-27  0:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-26 21:36 when can find_thread_pid (inferior_ptid) return NULL? Doug Evans
2009-03-26 22:35 ` Pedro Alves
2009-03-27  0:54   ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox