Bug 72982

Summary: breakpoint in thread causes SIGTRAP
Product: [Retired] Red Hat Linux Reporter: com
Component: gdbAssignee: Trond Eivind Glomsrxd <teg>
Status: CLOSED NOTABUG QA Contact: Jay Turner <jturner>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.3CC: srevivo
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-09-02 11:22:05 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description com 2002-08-29 18:08:34 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc1) Gecko/20020417

Description of problem:
When setting a breakpoint in a thread other than main the main thread receives a
SIGTRAP instead of gdb stopping in the thread, This is very simmilar to old gdb
bug reports.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
Run the attahced prg in gdb. Set a breakpoint in  b 'thread_fnc(void *)' and run
the prg.

/*
 * To compile this program(gcc 2.95.2 was used):
 * 	g++ -o thr_test_debug thr_test_debug.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);

}


Actual Results:   gdb thr_test_debug
GNU gdb Red Hat Linux (5.2-2)
Copyright 2002 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 "i386-redhat-linux"...
(gdb) b 'thread_fnc
thread_fnc(void*)  thread_fnc__FPv     
(gdb) b 'thread_fnc
thread_fnc(void *)  thread_fnc__FPv     
(gdb) b 'thread_fnc(void *)' 
Breakpoint 1 at 0x804899a: file thr_test_debug.cpp, line 81.
(gdb) c
The program is not being run.
(gdb) r
Starting program: /data/HotCache/Compiler/Test/thr_test_debug 
pthread_create successful

Program received signal SIGTRAP, Trace/breakpoint trap.
0x400dd425 in sigsuspend () from /lib/libc.so.6


Additional info:

Linux thunderbird.localdomain 2.4.18-5 #1 Mon Jun 10 15:37:14 EDT 2002 i686 unknown

gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-112)

Comment 1 com 2002-09-02 11:21:58 UTC
I can make this problem disappear by not running an extra shell. My xterm starts
a  bash shell and I then start tcsh and then gdb. If I run gdb directly from the
bash shell everything works fine?

Comment 2 com 2002-09-02 12:04:59 UTC
Unsetting LD_ASSUME_KERNEL before running gdb made things work.