2.1 调用GDB
gdb program
gdb program core
gdb program pid
gdb -args test 111
gdb传递参数给被调试的可执行程序
gdb -help
2.1.1 选择文件
--args
Arguments after executable-file are passed to inferior
--core=COREFILE
Analyze the core dump COREFILE.
--exec=EXECFILE
Use EXECFILE as the executable.
--pid=PID
Attach to running process PID.
--directory=DIR
Search for source files in DIR. 加入路径directory作为源代码的搜索路径
--se=FILE
Use FILE as symbol file and executable file. 从file读入符号表,将文件作为可执行程序
--symbols=SYMFILE
Read symbols from SYMFILE. 从file读入符号表
--readnow
Fully read symbol files on first access.
--write
Set writing into executable and core files.以可读可写的方式打开文件
--command=FILE, -x Execute GDB commands from FILE.
--init-command=FILE, -ix
Like -x but execute commands before loading inferior.
--eval-command=COMMAND, -ex
Execute a single GDB command.May be used multiple times and in conjunction with --command.
2.1.2 选择模式
例如批处理模式和安静模式
-q, --quiet, --silent
Do not print version number on startup.
--batch
Exit after processing options.以批处理模式运行,处理完所有命令文件(-x)后以0状态退出
gdb初始化文件.gdbinit
2.2 退出GDB
q | ctrl+d 退出GDB
ctrl+c 结束正在处理的GDB命令
detach 释放GDB attach过的进程
2.3 shell命令
shell command string
shell ls -lh
2.4 日志输出
show logging 显示当前log设置
set logging on 默认log是off的
set logging off
set logging overwrite on|off 覆盖|追加