gdb 调试多进程

来源:互联网 发布:linux压缩命令 tar.gz 编辑:程序博客网 时间:2024/06/11 20:02

gdb fork 文档

https://sourceware.org/gdb/onlinedocs/gdb/Forks.html
目前只有linux支持多进程调试;如果是mac, gdb break子进程代码,当子进程启动时,会收到SIGTRAP信号;SIGTRAP一般会kill掉进程。

inferior

一个inferior相当于一个进程。
http://blog.163.com/jiams_wang/blog/static/303391492013593502373/

  1. info inferiors
    打印GDB当前管理的inferiors列表,对每个inferior,GDB以如下顺序打印信息:

    • the inferior number assigned by gdb
    • the target system’s inferior identifier
    • the name of the executable the inferior is running.

      而数字前的*表示当前inferior
      (gdb) info inferiors
      Num Description Executable
      2 process 2307 hello
      1 process 3401 goodbye

  2. inferior infno
    使inferior号infno成为当前inferior,这个inferior号就是上面由GDB赋给的那个(1)
  3. maint info program-spaces
    打印GDB当前管理的所有程序空间列表,按如下顺序打印每个程序空间:
    • the program space number assigned by gdb
    • the name of the executable loaded into the program space, with e.g., the
      file command.
  4. remove-inferiors infno …
    删除inferior。不过不会remove掉执行该命令的inferior,如果想,可使用kill或detach。
    如果想离开当前inferior,可以用detach inferior(允许其独立运行)或使用kill inferiors命令
    detach inferior infno…
    Detach掉inferior或infno指定的inferiors,注意这些inferiors仍会显示在info inferiors条目里面,但是描述会显示’’。

    kill inferiors infno…
    杀死inferior或infno指定的inferiors,注意这些inferiors仍会显示在info inferiors条目里面,但是描述会显示’’。

    在detach、 detach inferiors、kill或kill inferiors或进程执行完后,该inferior仍然可用,显示在info inferiors条目里面

  5. set print inferior-events
    set print inferior-events on
    set print inferior-events off
    在GDB发现新的inferiors启动或inferiors退出或被detach后,是否打印消息。默认不打印。
  6. show print inferior-events
    当GDB发现inferiors启动、退出或被detached后,是否打印信息。
  7. add-inferior [-copies n] [-exec executable]
    在同一个session里增加n个inferiors来运行程序,使用executable来作为可执行文件,n默认值为1。如果没有指定executable,则inferior是
    空的。可以用file executable来分配给inferior可执行文件。
  8. clone-inferior [-copies n] [infno]
    增加n个inferiors来执行inferior号为infno的可执行程序,n默认为1,infno默认为当前inferior。

gdb简易教程

http://blog.csdn.net/liigo/article/details/582231

一般,在支持gdb 多进程的程序中,可以通过
1. set follow-fork-mode child 设置fork后gdb调试针对的是子进程
2. set detach-on-fork off 在fork后不会detach
3. 通过show follow-fork-mode和show detach-on-fork可以查看当前生效的值

0 0
原创粉丝点击