Radare2 and threads

Hi! Does someone know how to work with threads in radare2?
For example I have the following little C program:

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

        void *thread(void *nothing) {
            while (1) {
                printf("Hello\n");
                sleep(1);
            }
            return NULL;
        }

        int main(void) {
            pthread_t t;
            pthread_create(&t, NULL, thread, NULL);
            while (1) {
                printf("World\n");
                sleep(1);
            }
            return 0;
        }

When I start it with radare2 -d a.out and break behind the pthread_create() call. I just get the output of the two threads:

Hello
World
Hello
World

But I was expecting to get a new radare2 prompt and having rip set to the position I breaked at. I cannot find any documentation about the topic. Does anyone know how to debug threads with radare2?

Play around with these flags:

[0x100001060]> e??~follow
           anal.ptrdepth: Maximum number of nested pointers to follow in analysis
           dbg.follow: Follow program counter when pc > core->offset + dbg.follow
           dbg.follow.child: Continue tracing the child process on fork. By default the parent process is traced
           dbg.trace.inrange: While tracing, avoid following calls outside specified range
[0x100001060]> e??~thread
           dbg.clone: Stop execution if new thread is created
           dbg.execs: Stop execution if new thread is created
           dbg.forks: Stop execution if fork() is done (see dbg.threads)
         dbg.threads: Stop all threads when debugger breaks (see dbg.forks)

If auto following child processes in this example are not working you can try stopping the execution when a thread is created and use radare to list them and follow the new thread manually.

This topic was automatically closed after 121 days. New replies are no longer allowed.