[Github-comments] [geany/geany-plugins] How to debug a multithread application (#1069)

avafinger notifications at xxxxx
Wed Mar 3 04:54:23 UTC 2021


I am not sure where I should open this issue, here or in geany-plugins.

I need to debug a multithreaded app with Geany with debugger plugin (gdb) but Geany hangs inside the thread.
I have been using Geany for a long time but I can't find a way to debug a thread.

To reproduce the problem, build and debug the sample thread.c, setting a break-point at the line *22* and *34* and then **run**
* Build
        
       gcc -g -O0 -o thread thread.c -lpthread  

* thread.c

```
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>

/*
 * Build with:
 *
 * gcc -g -O0 -o thread thread.c -lpthread
 *
*/

pthread_t tid[2];

void* doSomeThing(void *arg)
{
    unsigned long x = 0;
    int j = 0;
    int i = (int)arg;

    pthread_t id = pthread_self();

    printf("Thread %d processing...\n", i);
    if(pthread_equal(id,tid[0])) {
        printf("Inside First thread\n");
    } else  {
        printf("Inside Second thread\n");
    }

    for(x=0; x<(0xFFFFFFFF);x++) {
        j++;
    }
    printf("Thread %d: 0x%lx [ x = 0x%X ]\n",i, id, j);

    return NULL;
}

int main(void)
{
    int i = 0;
    int err;

    while (i < 2) {
        err = pthread_create(&(tid[i]), NULL, &doSomeThing, (void*)i);
        if (err != 0)
            printf("can't create thread :[%s]", strerror(err));
        else
            printf("Thread %d created successfully\n", i);
        i++;
    }

    sleep(10);
    return 0;
}

```

Geany correctly stops at the first break-point, but If i click "Step over", Geany switches to the second thread, hitting "Step over" again hangs Geany. And eventually, a crash occurs if you try to close Geany.

The correct behavior should be to stay in the same thread and walk through the code while "Step over" is hit, line by line.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/issues/1069
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20210302/39a8e0c1/attachment.htm>


More information about the Github-comments mailing list