libpthread and gdb oddities

libpthread and gdb oddities

Post by Sven Esmar » Wed, 24 Jul 2002 23:35:03



Hi there,

I extracted my problems down to this short program "test.cc":

#include <iostream>

int main()
{
        double d=10.0;
        cout << d << endl;

        return 0;

Quote:}

Compiling it with

g++ -g -o test.o -c test.cc
g++ test.o -o test

and testing it, everything works out fine.
But compiling it with

g++ -g -o test.o -c test.cc
g++ test.o -lpthread -o test

only invoking "./test" from within the shell gives the desired output
"10". Running it with ddd (or gdb), the variable d has value nan.

My question is: what is wrong with linking against libpthread ? I just
intentionally linked against it and dont need this library, but I would
like to know if this is a fault or a feature.

Thanks in advance

Sven

 
 
 

libpthread and gdb oddities

Post by Stephane SOPPER » Wed, 24 Jul 2002 23:43:24


Quote:> My question is: what is wrong with linking against libpthread ? I just
> intentionally linked against it and dont need this library, but I would
> like to know if this is a fault or a feature.

I've just tested you code with gdb and ddd: the value of d displayed by
the de* after the initialization is 10 in both cases.

--
Stephane SOPPERA
http://www.veryComputer.com/ (in (bad) english now!)

 
 
 

libpthread and gdb oddities

Post by Peter Pointne » Thu, 25 Jul 2002 03:50:29



> Hi there,
> I extracted my problems down to this short program "test.cc":
> #include <iostream>
> int main()
> {
>    double d=10.0;
>    cout << d << endl;
>    return 0;
> }
> Compiling it with
> g++ -g -o test.o -c test.cc
> g++ test.o -o test
> and testing it, everything works out fine.
> But compiling it with
> g++ -g -o test.o -c test.cc
> g++ test.o -lpthread -o test
> only invoking "./test" from within the shell gives the desired output
> "10". Running it with ddd (or gdb), the variable d has value nan.

What version of gdb do you use?
IIRC gdb 5.0.something has a bug wrt floating point and threads.

Peter

 
 
 

libpthread and gdb oddities

Post by Sven Esmar » Thu, 25 Jul 2002 04:28:09


 > What version of gdb do you use?
 > IIRC gdb 5.0.something has a bug wrt floating point and threads.

I am using the latest SuSE (8.0) with GNU gdb 5.1.1. on a
Dual-Celeron-Board.

Best regards

Sven

 
 
 

libpthread and gdb oddities

Post by Peter Pointne » Thu, 25 Jul 2002 06:40:40



>  > What version of gdb do you use?
>  > IIRC gdb 5.0.something has a bug wrt floating point and threads.
> I am using the latest SuSE (8.0) with GNU gdb 5.1.1. on a
> Dual-Celeron-Board.

ijust tested it on my Suse 8.0 system with gdb 5.1.1, and I cannot
reproduce your problem. Do you get "nan" as output from the debugged
program or as output from the de*?

If you would really use pthreads, you should use -pthread as
compiler option. This leads to -D_REENTRANT for the compiler and
-lpthread for the linker.

Peter

 
 
 

libpthread and gdb oddities

Post by Sven Esmar » Thu, 25 Jul 2002 17:11:55


Thanks for your response,

Quote:> ijust tested it on my Suse 8.0 system with gdb 5.1.1, and I cannot
> reproduce your problem. Do you get "nan" as output from the debugged
> program or as output from the de*?

if I compile this code...
============================

#include <iostream>

int main()
{
     double d=10.0;

     cout << d << endl;

     return 0;

Quote:}

============================
with

g++ -g -pthread -o test test.cc

then ./test at the command prompt yields:
============================


10

============================
seems to be fine, but when viewed with gdb...
============================


GNU gdb 5.1.1
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-suse-linux"...
(gdb) l
1       #include <iostream>
2
3       int main()
4       {
5           double d=10.0;
6
7           cout << d << endl;
8
9           return 0;
10      }
(gdb) b 7
Breakpoint 1 at 0x804867f: file test.cc, line 7.
(gdb) run
Starting program: /home/sven/Documents/C++/test/test
[New Thread 1024 (LWP 1713)]
[Switching to Thread 1024 (LWP 1713)]

Breakpoint 1, main () at test.cc:7
7           cout << d << endl;
(gdb) print d
$1 = -nan(0x8000000000000)
(gdb) cont
Continuing.
nan

Program exited normally.
(gdb)

=====================================
But if I am compiling the same code without the -pthread option,
everything works out fine...
=====================================



10

GNU gdb 5.1.1
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-suse-linux"...
(gdb) l
1       #include <iostream>
2
3       int main()
4       {
5           double d=10.0;
6
7           cout << d << endl;
8
9           return 0;
10      }
(gdb) b 7
Breakpoint 1 at 0x804866f: file test.cc, line 7.
(gdb) run
Starting program: /home/sven/Documents/C++/test/test

Breakpoint 1, main () at test.cc:7
7           cout << d << endl;
(gdb) print d
$1 = 10
(gdb) cont
Continuing.
10

Program exited normally.
(gdb)

==============================
I have no clue about what is going on here... At least it does not seem
to be a failure of the Linux distribution. Is it my Dual-Celeron-System
that causes troubles when I am linking against libpthread ? But why ?

I have a bad feeling about that strange behaviour and I am thankful to
anybody who can give me some advice.

Regards
Sven

 
 
 

libpthread and gdb oddities

Post by Sven Esmar » Fri, 26 Jul 2002 00:32:13


Hi there,

I just compiled the latest gdb (5.2.1) and the problem vanished.
Thank you for your support.

Have a nice day

Sven

 
 
 

1. ld.so.cache: ../lib/libpthread.so.1 => libpthread.so.1.0.0

I installed libpthreads.
My ldconfig says :
.....
.....
/usr/local/lib:
        ../lib/libpthread.so.1 => libpthread.so.1.0.0
        libqt.so.1 => libqt.so.1.2
        libz.so.1 => libz.so.1.0.4
        libtiff.so.3 => libtiff.so.3.4.036
        libpng.so.0 => libpng.so.0.90
        libmpeg.so.1 => libmpeg.so.1.2
        libjpeg.so.6 => libjpeg.so.6.0.1
....
....
My binaries don't like that ../lib/ before libpthread.
When I create link ../lib/libpthread.so to
/usr/local/lib/libpthread.so... it works.

I don't understand this.

Could someone help me ?

I need pthreads for ObjC and GNUStep.
I use Slackware3.2beta but this happens on 3.1 also.

2. Stay Informed

3. Signal/gdb oddity in 2.5.61

4. RedHat 5.2 won't "workstation"

5. Matrox Mystique ands X.

6. One question about ftp...

7. Interfacing with gdb: How to set a gdb watch point from C++ code?

8. Interpret out put of /usr/ucb/ps -aux

9. gdb problem (gdb 4.8, gcc 2.6.2)

10. please HELP with GDB output redirect to GDB variable !!!

11. binutils, bugs in gdb, & "fixes" to gdb

12. /lib/libpthread-0.9.so: no symbols; /lib/i686/libpthread-0.9.so many symbols. Why?

13. libpthread and ld problem