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