bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gdb+pthreads+strtod=nan


From: Alexander Enchevich
Subject: gdb+pthreads+strtod=nan
Date: Wed, 04 Jul 2001 17:28:14 -0700

Hi

This is a bug report for GDB version:    GNU gdb 5.0mdk-11mdk
Linux-Mandrake 8.0

Description of problem:
------------------
Problem occurs when a program using pthreads and stdlib's strtod()
function is being debugged in gdb.
When the strtod(char*, char**) f-n is called from a program even w/
correct input, it does not return a correct number but rather 'nan'.
Whatever that is... A sample program is included below.

System Config
---------------
    RAM: 128MB
    Linux:  2.4.3-20mdk
    gcc version 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)
    pthreads:
        1492240 May  2 11:22 libpthread.a
          555792 May  2 11:22 libpthread-0.9.so
    libc:
      26499142 May  2 11:21 libc.a
        1222404 May  2 11:39 libc-2.2.2.so
    glib:
          152768 Mar 22 05:30 libglib-1.2.so.0.0.10
          221748 Mar 22 05:30 libglib.a

    /proc/cpuinfo:
processor : 0
vendor_id : AuthenticAMD
cpu family : 6
model  : 2
model name : AMD Athlon(tm) Processor
stepping : 2
cpu MHz  : 755.288
cache size : 512 KB
fdiv_bug : no
hlt_bug  : no
f00f_bug : no
coma_bug : no
fpu  : yes
fpu_exception : yes
cpuid level : 1
wp  : yes
flags  : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat
pse36 mmx fxsr syscall mmxext 3dnowext 3dnow
bogomips : 1507.32


The Example and Testing Procedure:
-------------------------------
Compile with:
g++ -c  -g -fPIC -Wall -D_REENTRANT -DDEBUG main.cpp -o main_dbg.o
g++ -static -o t main_dbg.o  -lpthread

When started with any command line arguments will run threaded, i.e.
will create one dummy thread and wait for it to start before calling
strtod for the second time. Without arguments just calls strtod twice.
Compiling without -static yields even more amazing results...

The table below shows in which calls to strtod (there's 2 in my example)
the bug happens depending on how the example is built and run.

                     threads         no threads
-----------------------------
-static      I  call 2                  no bug
no -static I calls 1 & 2           call 1


Example Source:
-------------------
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

int threadCreated=0;

void*
TestThread(void *p)
{
    printf("TestThread created, pid = %d\n", getpid());
    threadCreated=1;
    for(;;)
        ;
    return NULL;
}

int
main(int argc, char** argv)
{
    printf("in main(), pid = %d\n", getpid());

    pthread_t   ptTest;
    char        szNum[20]="123.456", *ptrBadCh;
    double      bla;

    bla = strtod(szNum, &ptrBadCh);
    printf("\"%s\" converted to double by strtod = %lf (garbage: %s)\n",
szNum,
              bla, ((*ptrBadCh)?ptrBadCh:"NO GARBAGE") );

    if(argc>1)
        pthread_create(&ptTest, NULL, &TestThread, NULL);
    else
        threadCreated = 1;

    while(!threadCreated)
        ; // a lazy cond_wait   :)

    bla = strtod(szNum, &ptrBadCh);
    printf("\"%s\" converted to double by strtod = %lf (garbage: %s)\n",
szNum,
              bla, ((*ptrBadCh)?ptrBadCh:"NO GARBAGE") );

    return 0;
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]