linuxGDB调试

1.调试多进程服务程序。
2.调试多线程服务程序。

一、进程

调试父进程:set follow-fork-mode parent(缺省)
调试子进程:set follow-fork-mode child

设置调试模式:set detach-on-fork [on/off],
缺省是on
表示调试当前进程的时候,其他进程继续运行,
如果用off,调试当前进程的时候,其他的进程被gdb挂起。

查看调试的进程;info inferiors
切换当前调试的进程:inferior 进程id

二、线程

1。调试多线程服务程序

在shell中执行:
查看当前运行的进程:ps aux | grep book
查看当前运行的轻量级进程:ps aL | grep book
查看主线程和子线程的关系:pstree -p 主线程id

在gdb中执行:
查看线程;info threads
切换线程:thread 线程id
只运行当前线程:set scheduler-locking on
运行全部的线程:set scheduler-locking off
指定某线程执行某gdb命令:thread apply 线程id cmd
全部的线程执行某gdb命令:thread apply all cmd

转载于C语言技术网