其他:remove-inferiors infno, detach inferior
2. GDB默认支持调试多线程,跟主线程,子线程block在create thread。 查询线程:info threads 切换调试线程:thread <thread number>
程序代码:
#include <stdio.h> #include <pthread.h> void child() { int i = 0; printf("child; %d\n", i); } void father() { int i = 1; printf("father: %d\n", i); } void *thread_run(void *arg) { int count = 0; while(count++ < 5) { sleep(1); printf("T am new thread,tid:%lu, pid:%d\n", pthread_self(), getpid()); } pthread_exit((void *)123); } int main() { pid_t pid = fork(); if(pid == 0) child(); else father(); pthread_t id; pthread_create(&id, NULL, thread_run, NULL); while(1) { sleep(1); printf("I am main thread,tid:%lu, pid:%d\n", pthread_self(), getpid()); } sleep(4); int ret2 = pthread_cancel(id); void *val = NULL; int ret = pthread_join(id, &val); printf("The new thread is quit.val:%d\n", (int)val); printf("%lu\n",id); return 0; }
调试:
1. 调试主进程,block子进程。
2.切换到子进程
3.调试主进程中的子线程
4.切换线程