ports/157342: Problem with running simple pthreads program under gdb-7.2 (Invalid selected thread)

Dmitry V. Krivenok krivenok.dmitry at gmail.com
Thu May 26 10:20:11 UTC 2011

>Number:         157342
>Category:       ports
>Synopsis:       Problem with running simple pthreads program under gdb-7.2 (Invalid selected thread)
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-ports-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 26 10:20:10 UTC 2011
>Originator:     Dmitry V. Krivenok
>Release:        FreeBSD-8.2
FreeBSD csx-spb-freebsd8.sspg.lab.emc.com 8.2-RELEASE FreeBSD 8.2-RELEASE #7: Thu Mar 10 12:24:16 MSK 2011     root at csx-spb-freebsd8.sspg.lab.emc.com:/big/obj/big/src/sys/CUSTOM  amd64
I've already asked on freebsd-hackers and others also reproduced this problem, so I decided to submit PR.

I wrote very simple Pthreads program to demonstrate the problem with
gdb-7.2 installed from ports on my FreeBSD-8.2 (amd64).

#include <pthread.h>
#include <assert.h>
#include <stdlib.h>

void* run(void* arg)
 return 0;

int main(int argc, char** argv)
 pthread_t tid;
 int r;
 r = pthread_create(&tid, NULL, &run, NULL);
 r = pthread_join(tid, NULL);
 return 0;

I compiled it as follows
$ gcc -Wall -g -O0 -pthread -o t t.c

and then run under base gdb-6.1.1

$ gdb --args t
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) r
Starting program: /big/work/coverage/csxroot/src/t/t
[New LWP 100071]
[New Thread 800a041c0 (LWP 100071)]
[New Thread 800a0ae40 (LWP 100170)]
[Thread 800a0ae40 (LWP 100170) exited]

Program exited normally.
(gdb) q

As you can see program exited normally w/o any errors.
Then I run the same program under gdb-7.2

$ /usr/local/bin/gdb72 --args t
GNU gdb (GDB) 7.2 [GDB v7.2 for FreeBSD]
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-portbld-freebsd8.2".
For bug reporting instructions, please see:
Reading symbols from /big/work/coverage/csxroot/src/t/t...done.
(gdb) r
Starting program: /big/work/coverage/csxroot/src/t/t
[New LWP 100162]
[New Thread 800a041c0 (LWP 100162)]
[New Thread 800a0ae40 (LWP 100171)]
[Thread 800a0ae40 (LWP 100171) exited]
Invalid selected thread.
(gdb) q
A debugging session is active.

       Inferior 1 [process 7756] will be killed.

Quit anyway? (y or n) y

In this case I got "Invalid selected thread." right after the thread has exited.
Looks like gdb is unable to switch to another thread.
What's wrong here?
See "full description".


More information about the freebsd-ports-bugs mailing list