pthread_cond_timedwait & gdb

Wong, Ken Ken.Wong at christiedigital.com
Thu Apr 23 20:08:12 UTC 2009


Hi everyone... we're running into a strange situation where we can't
seem to step over any functions that call "pthread_cond_timedwait" when
we're debugging with GDB.  The application itself runs fine outside of
GDB but debugging is particularly cumbersome due to this strange
behavior.

 

I'm looking for any advice on how to narrow down the problem.  Even
better, if someone has a solution, I'm all ears.

 

Our current debug configuration is as follows:

*         Coldfire MCF547x processor

*         Linux 2.6.10

*         Using the 4.3-43 toolchain from the bitshrine.org/gpp website

*         gdbserver v6.6

*         gdb client v6.6 built for windows using mingw

*         Eclipse as a development environment

 

If I try to step over a function that executes "pthread_cond_timedwait",
GDB stops in the "__pthread_timedsuspend_new" function instead of the
following line of the current stack frame.  I've tried this on both the
Coldfire and on an x86 platform... the problem is only showing up on the
Coldfire platform.

 

I've included the sample code for replicating this issue (sorry for the
length of the message).  The code basically creates a thread that
signals once every 2 seconds.  The main function/thread continuously
picks up the signal using different variations of the
"pthread_cond_*wait()" functions.

 

More details past the code...

 

-- begin code --

#include <stdio.h>

#include <pthread.h>

#include <sched.h>

#include <unistd.h>

#include <errno.h>

#include <time.h>

 

struct SSignal {

    pthread_cond_t* mpCond;

    pthread_mutex_t* mpMutex;

};

 

void* thread_run(void* pArg)

{

    struct SSignal* pSignal = (struct SSignal*) pArg;

    while (true) {

        pthread_mutex_lock(pSignal->mpMutex);

 

        printf("Signaling...\n");

        pthread_cond_signal(pSignal->mpCond);

 

        pthread_mutex_unlock(pSignal->mpMutex);

 

        // wait 2 seconds between signals

        sleep(2);

    }

 

    return NULL;

}

 

void WaitForSignal(struct SSignal* pSignal, unsigned int waitTime = 0)

{

    int rc = 0;

    struct timespec resumeTime = {};

 

    pthread_mutex_lock(pSignal->mpMutex);

 

    if( waitTime > 0 ) {

        // Setup the timeout value for the condition variable

        clock_gettime(CLOCK_REALTIME, &resumeTime);

        resumeTime.tv_sec += waitTime;

 

        // Wait for a signal

        rc = pthread_cond_timedwait(pSignal->mpCond, pSignal->mpMutex,
&resumeTime);

 

        // Evaluate the response

        if (rc == 0) {

            printf("Received signal while waiting for %d seconds...\n",
waitTime);

        } else if (rc == ETIMEDOUT) {

            printf("Timeout while waiting for %d seconds\n", waitTime);

        } else {

            printf("ERROR; return code from pthread_cond_timedwait() is
%d\n", rc);

        }

    } else {

        pthread_cond_timedwait(pSignal->mpCond, pSignal->mpMutex,
&resumeTime);

        printf("Received signal...\n");

    }

 

    pthread_mutex_unlock(pSignal->mpMutex);

}

 

int main (int argc, char* argv[])

{

    int returnValue = 0;        // return value for application

 

    pthread_t thread;           // thread that signals continuously

    pthread_cond_t cond;        // condition variable used for
signalling

    pthread_mutex_t mutex;      // mutex for condition variable

    struct SSignal signal = {}; // signal to pass into thread

 

    printf("Starting\n");

 

    // initialize the condition variable

    pthread_cond_init(&cond, NULL);

 

    // initialize the mutex

    pthread_mutex_init(&mutex, NULL);

 

    // start up the signalling thread

    signal.mpCond = &cond;

    signal.mpMutex = &mutex;

    pthread_create(&thread, NULL, thread_run, (void*) &signal);

 

    while (true) {

        // can step over this just fine

        WaitForSignal(&signal);

 

        // fails to step over this one

        WaitForSignal(&signal, 3);

 

        // fails to step over this one

        WaitForSignal(&signal, 1);

 

        sleep(1);

    }

 

    return returnValue;

}

-- end code --

 

Here's what the stack looks like when I try stepping over the second
call to "WaitForSignal(...)"

 

4  __pthread_timedsuspend_new()            0x40021390

3  pthread_cond_timedwait at GLIBC_2.4()      0x4001ef44

2  WaitForSignal()    pthread_debug.cpp:44 0x8000083c

1  main()             pthread_debug.cpp:89 0x80000980

 

Any suggestions or solutions are welcome.

 

Ken Wong

Product Developer, Software, Business Products

CHRISTIE

809 Wellington Street North

Kitchener, Ontario N2G 4Y7

PH: +1 519-744-8005 Ext. 7177

FX: +1 519-749-3164

www.christiedigital.com <http://www.christiedigital.com> 

 

This e-mail message (including attachments, if any) is confidential.

Any unauthorized use, distribution or disclosure is prohibited.

If you have received this e-mail message in error, please notify 

the sender by reply e-mail or telephone and delete it and any 

attachments from your computer system and records.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/coldfire-gnu-discuss/attachments/20090423/bb8ccd99/attachment.html>


More information about the coldfire-gnu-discuss mailing list