Linux GDB的简单使用——多线程

Linux GDB的简单使用——多线程

GDB多线程调试

测试代码

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

void* thread1()
{
    
    
        printf("This is thread1, tid = %ld\n",pthread_self());
}

void* thread2()
{
    
    
        printf("This is thread2, tid = %ld\n",pthread_self());
}

int main()
{
    
    
        pthread_t tid1,tid2;
        pthread_create(&tid1, NULL, thread1, NULL);
        pthread_create(&tid1, NULL, thread2, NULL);

        pthread_join(tid1, NULL);
        pthread_join(tid2, NULL);

        return 0;
}

调试

在这里插入图片描述
在这里插入图片描述
选择跟进指定线程的方法就是直接将断点打在指定线程所实现的函数
如:要跟进线程1,就直接

b thread1

如:要跟进线程2,就直接

b thread2

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_50438937/article/details/114711908