• gdb 调试


    一、gdb 多线程调试

    GDB多线程调试的基本命令。

    1. info threads 显示当前可调试的所有线程,每个线程会有一个GDB为其分配的ID,后面操作线程的时候会用到这个ID。 前面有*的是当前调试的线程。

    (gdb) info threads
      4 Thread 1099119552 (LWP 12940)   0xffffe002 in ?? ()
      3 Thread 1090731072 (LWP 12939)   0xffffe002 in ?? ()
      2 Thread 1082342592 (LWP 12938)   0xffffe002 in ?? ()
    * 1 Thread 1073951360 (LWP 12931)   main (argc=1, argv=0xbfffda04) at thread.c:21

    2. thread ID 切换当前调试的线程为指定ID的线程。

    (gdb) thread 4
    [Switching to thread 4 (Thread 1099119552 (LWP 12940))]#0   0xffffe002 in ?? ()
    (gdb) info threads
    * 4 Thread 1099119552 (LWP 12940)   0xffffe002 in ?? ()
       3 Thread 1090731072 (LWP 12939)   0xffffe002 in ?? ()
       2 Thread 1082342592 (LWP 12938)   0xffffe002 in ?? ()
       1 Thread 1073951360 (LWP 12931)   main (argc=1, argv=0xbfffda04) at thread.c:21

    3.  break thread_test.c:123 thread all 在所有线程中相应的行上设置断点

    4.  thread apply ID1 ID2 command 让一个或者多个线程执行GDB命令command。

    5.  thread apply all command 让所有被调试线程执行GDB命令command。

    6.  set scheduler-locking off|on|step

       实际使用过多线程调试的人都可以发现,在使用step或者continue命令调试当前被调试线程的时候,其他线程也是同时执行的,怎么只让被调试程序执行呢?通过这个命令就可以实现这个需求。

      off 不锁定任何线程,也就是所有线程都执行,这是默认值。

      on 只有当前被调试程序会执行。

      step 在单步的时候,除了next过一个函数的情况(熟悉情况的人可能知道,这其实是一个设置断点然后continue的行为)以外,只有当前线程会执行。

  • 相关阅读:
    Ubunut 安装 Mariadb 数据库
    编译 APISIX
    Watchtower 自动更新 Docker 镜像与容器
    Drone 教程
    异步任务工具类
    Html 转 PDF
    数据中台
    九大数据分析方法:指标拆解法
    用户画像
    Hudi的更新机制
  • 原文地址:https://www.cnblogs.com/yaozhongxiao/p/3833116.html
Copyright © 2020-2023  润新知