您的位置:首页 > 博客中心 > 数据库 >

gdb调试多线程

时间:2022-03-15 04:21

二、编译运行

 

2.1 编译

        gcc -g test.c -lpthread -o test

2.2 运行

        ./test 

2.3 输出结果

技术分享

三、调试 -- 方法1

3.1 查看 test进程号

        ps aux|grep test

3.2 查看进程中的所有线程

        pstree -p 13006

3.3 gdb调试定位bug位置

        gdb

        attach 进程号

        bt 【thread apply all bt】

如下图:

技术分享

        thread apply all bt

技术分享

四、调试 --  方法2

4.1 查看 test进程号

        ps -e|grep test

4.2 gdb调试定位bug位置

        gdb test 进程号   启动gdb attach 进程

        info threads         显示所有线程信息

        thread 2               调到第2个线程

        bt                           查看第2个线程的堆栈,即可可以看到线程死锁的地方

技术分享

 

 

参考资料:

      使用gdb调试死锁线程:

 

热门排行

今日推荐

热门手游