I have encountered what looks like a bug under gdb 5.0.

The bug appears when debugging a multi-threaded program under
Linux RedHat 6.2 (x86).  It looks as if gdb does not know how to
continue
out of a thread that has finished(terminated/exited).  This particular
problem
did not occur with an old 4.17.x version of gdb.

The configuration as printed out by gdb on startup is:

GNU gdb 5.0
Copyright 2000 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 "i686-pc-linux-gnu".

Basically, I set a break point inside a function that gets called in a
thread other
than the main thread.  GDB hits the breakpoint fine.  However, when I
hit continue
GDB gives the following message:

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0 in ?? ()
(gdb)  continue
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x0 in ?? ()
(gdb)

I typed in continue after the SIGTRAP message and GDB printed out the
second message above.

I have a simple C++ program that can reproduce this problem.  This
program runs fine outside
of GDB.  It is only when runned from GDB that I get the errror messages
and I can no longer debug.

Other configuration information:

glibc  2.1.3
binutils-2.10

The program is attached as an ASCII file for reference with instructions
on how it was compiled.

Thanks



--Jubey Garza



/*
 * To compile this program(gcc 2.95.2 was used):
 *      g++ -o thread_test thread_test.cpp -lpthread
 *
 */

#define _REENTRANT

#include <pthread.h>
#include <iostream>


//-----

void *thread_fnc (void *data);

//-----

struct Thread_Type
{
    pthread_mutex_t _mutex;
    int             _value;
} thread_data1, thread_data2;

//-----

int
main()
{
    pthread_t thread_1, thread_2;
    thread_data1._value = 0;
    thread_data2._value = 1;


    int result1 = pthread_create (&thread_1, 0, thread_fnc, &thread_data1);
    int result2 = pthread_create (&thread_2, 0, thread_fnc, &thread_data2);

    if (result1 == 0 && result2 == 0)
    {
        cout << "pthread_create successful" << endl;
        int *thread_return_ptr1; 
        int *thread_return_ptr2;
        result1 = pthread_join (thread_1, (void **) &thread_return_ptr1);
        result2 = pthread_join (thread_2, (void **) &thread_return_ptr2);
        if (result1 == 0 && result2 == 0)
        {
            cout << "pthread_join() of thread 1 and thread 2 succeeded" << endl;
            if (thread_return_ptr1 == 0)
            {
                cout << "Thread 1 terminated successfully\n";
            }
            else
            {
                cerr << "Thread 1 returned failure: " << thread_return_ptr1 << "\n";
            }
            if (thread_return_ptr2 == 0)
            {
                cout << "Thread 2 terminated successfully\n";
            }
            else
            {
                cerr << "Thread 2 returned failure: " << thread_return_ptr2 << "\n";
            }
        }
        else
        {
            cerr << "pthread_join() failed!" << endl;
        }
    }
    else
    {
        cerr << "pthread_create() failed!\n";
    }
}

//-----

void *
thread_fnc (void * data)
{
    Thread_Type * thread_type = (Thread_Type *)data; 
    cout << "In thread and value is: " << thread_type->_value << endl;

    //return (void *) 0;

    pthread_exit ((void *) 1);

}

//-----

Reply via email to