前言
gdb - The GNU Debugger(GNU 调试器)
官方文档 | 官方手册 | 在线中文手册
帮助
详情如下:
This is the GNU debugger. Usage: 这是 GNU 调试器。用法:
gdb [options] [executable-file [core-file or process-id]]
gdb [options] --args executable-file [inferior-arguments ...]
Selection of debuggee and its files: 调试对象及其文件的选择:
--args Arguments after executable-file are passed to inferior 可执行文件后的参数传递给 inferior
--core=COREFILE Analyze the core dump COREFILE. 分析核心转储 COREFILE。
--exec=EXECFILE Use EXECFILE as the executable. 使用 EXECFILE 作为可执行文件。
--pid=PID Attach to running process PID. 附加到正在运行的进程 PID。
--directory=DIR Search for source files in DIR. 在 DIR 中搜索源文件。
--se=FILE Use FILE as symbol file and executable file. 使用 FILE 作为符号文件和可执行文件。
--symbols=SYMFILE Read symbols from SYMFILE. 从 SYMFILE 读取符号。
--readnow Fully read symbol files on first access. 首次访问时完全读取符号文件。
--readnever Do not read symbol files. 不读取符号文件。
--write Set writing into executable and core files. 设置写入可执行文件和核心文件。
Initial commands and command files: 初始命令和命令文件:
--command=FILE, -x Execute GDB commands from FILE. 从 FILE 执行 GDB 命令。
--init-command=FILE, -ix
Like -x but execute commands before loading inferior. 类似于 -x 但在加载inferior之前执行命令。
--eval-command=COMMAND, -ex
Execute a single GDB command. 执行单个 GDB 命令。
May be used multiple times and in conjunction with --command. 可以多次使用并与 --command 结合使用。
--init-eval-command=COMMAND, -iex
Like -ex but before loading inferior. 像 -ex 但在加载inferior之前。
--nh Do not read ~/.gdbinit. 不读取 ~/.gdbinit。
--nx Do not read any .gdbinit files in any directory. 不要读取任何目录中的任何 .gdbinit 文件。
Output and user interface control: 输出和用户界面控制:
--fullname Output information used by emacs-GDB interface. 输出 emacs-GDB 接口使用的信息。
--interpreter=INTERP
Select a specific interpreter / user interface 选择特定的解释器/用户界面
--tty=TTY Use TTY for input/output by the program being debugged. 将 TTY 用于正在调试的程序的输入/输出。
-w Use the GUI interface. 使用 GUI 界面。
--nw Do not use the GUI interface. 不要使用 GUI 界面。
--tui Use a terminal user interface. 使用终端用户界面。
--dbx DBX compatibility mode.
-q, --quiet, --silent
Do not print version number on startup. 不要在启动时打印版本号。
Operating modes: 操作模式:
--batch Exit after processing options. 处理选项后退出。
--batch-silent Like --batch, but suppress all gdb stdout output. 与 --batch 类似,但禁止所有 gdb stdout 输出。
--return-child-result
GDB exit code will be the child's exit code. GDB 退出代码将是孩子的退出代码。
--configuration Print details about GDB configuration and then exit. 打印有关 GDB 配置的详细信息,然后退出。
--help Print this message and then exit. 打印此消息然后退出。
--version Print version information and then exit. 打印版本信息然后退出。
Remote debugging options: 远程调试选项:
-b BAUDRATE Set serial port baud rate used for remote debugging. 设置用于远程调试的串口波特率。
-l TIMEOUT Set timeout in seconds for remote debugging. 设置远程调试的超时时间(以秒为单位)。
Other options: 其他选项:
--cd=DIR Change current directory to DIR. 将当前目录更改为 DIR。
--data-directory=DIR, -D
Set GDB's data-directory to DIR. 将 GDB 的数据目录设置为 DIR。
At startup, GDB reads the following init files and executes their commands:
在启动时,GDB 读取以下 init 文件并执行它们的命令:
* system-wide init files: /etc/gdbinit 系统范围的初始化文件:/etc/gdbinit
For more information, type "help" from within GDB, or consult the 有关更多信息,请在 GDB 中键入“帮助”,或查阅
GDB manual (available as on-line info or a printed manual). GDB 手册(可作为在线信息或印刷手册获得)。
Report bugs to <https://www.gnu.org/software/gdb/bugs/>.
You can ask GDB-related questions on the GDB users mailing list
(gdb@sourceware.org) or on GDB's IRC channel (#gdb on Freenode).
3.1. help
maminjie@fedora ~/work> gdb
GNU gdb (GDB) Fedora 10.1-13.fc34
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help". 如需帮助,请键入“帮助”。
Type "apropos word" to search for commands related to "word". 输入“apropos word”以搜索与“word”相关的命令。
(gdb) help
List of classes of commands: 命令类列表:
aliases -- User-defined aliases of other commands. 其他命令的用户定义别名。
breakpoints -- Making program stop at certain points. 使程序在某些点停止。
data -- Examining data. 检查数据。
files -- Specifying and examining files. 指定和检查文件。
internals -- Maintenance commands. 维护命令。
obscure -- Obscure features. 晦涩的特征。
running -- Running the program. 运行程序。
stack -- Examining the stack. 检查堆栈。
status -- Status inquiries. 状态查询。
support -- Support facilities. 支持设施。
text-user-interface -- TUI is the GDB text based interface. TUI 是基于 GDB 文本的界面。
tracepoints -- Tracing of program execution without stopping the program. 在不停止程序的情况下跟踪程序执行。
user-defined -- User-defined commands. 用户定义的命令。
Type "help" followed by a class name for a list of commands in that class. 键入“help”,后跟类名以获取该类中的命令列表。
Type "help all" for the list of all commands. 为所有命令的列表键入“help all”。
Type "help" followed by command name for full documentation. 键入“help”后跟命令名称以获取完整文档。
Type "apropos word" to search for commands related to "word". 输入“apropos word”以搜索与“word”相关的命令。
Type "apropos -v word" for full documentation of commands related to "word". 键入“apropos -v word”以获取与“word”相关的命令的完整文档。
Command name abbreviations are allowed if unambiguous. 如果没有歧义,则允许使用命令名称缩写。
(gdb)
3.2. help class
查看breakpoints类的命令:
(gdb) help breakpoints
Making program stop at certain points.
List of commands:
awatch -- Set a watchpoint for an expression.
break, brea, bre, br, b -- Set breakpoint at specified location.
break-range -- Set a breakpoint for an address range.
catch -- Set catchpoints to catch events.
catch assert -- Catch failed Ada assertions, when raised.
catch catch -- Catch an exception, when caught.
catch exception -- Catch Ada exceptions, when raised.
catch exec -- Catch calls to exec.
catch fork -- Catch calls to fork.
catch handlers -- Catch Ada exceptions, when handled.
catch load -- Catch loads of shared libraries.
catch rethrow -- Catch an exception, when rethrown.
catch signal -- Catch signals by their names and/or numbers.
catch syscall -- Catch system calls by their names, groups and/or numbers.
catch throw -- Catch an exception, when thrown.
catch unload -- Catch unloads of shared libraries.
catch vfork -- Catch calls to vfork.
clear, cl -- Clear breakpoint at specified location.
commands -- Set commands to be executed when the given breakpoints are hit.
condition -- Specify breakpoint number N to break only if COND is true.
delete, del, d -- Delete all or some breakpoints.
delete bookmark -- Delete a bookmark from the bookmark list.
delete breakpoints -- Delete all or some breakpoints or auto-display expressions.
delete checkpoint -- Delete a checkpoint (experimental).
delete display -- Cancel some expressions to be displayed when program stops.
delete mem -- Delete memory region.
delete tracepoints, delete tr -- Delete specified tracepoints.
delete tvariable -- Delete one or more trace state variables.
disable, disa, dis -- Disable all or some breakpoints.
disable breakpoints -- Disable all or some breakpoints.
disable display -- Disable some expressions to be displayed when program stops.
disable frame-filter -- GDB command to disable the specified frame-filter.
disable mem -- Disable memory region.
disable pretty-printer -- GDB command to disable the specified pretty-printer.
disable probes -- Disable probes.
disable type-printer -- GDB command to disable the specified type-printer.
disable unwinder -- GDB command to disable the specified unwinder.
disable xmethod -- GDB command to disable a specified (group of) xmethod(s).
dprintf -- Set a dynamic printf at specified location.
enable, en -- Enable all or some breakpoints.
enable breakpoints -- Enable all or some breakpoints.
enable breakpoints count -- Enable some breakpoints for COUNT hits.
enable breakpoints delete -- Enable some breakpoints and delete when hit.
enable breakpoints once -- Enable some breakpoints for one hit.
enable count -- Enable some breakpoints for COUNT hits.
enable delete -- Enable some breakpoints and delete when hit.
enable display -- Enable some expressions to be displayed when program stops.
enable frame-filter -- GDB command to enable the specified frame-filter.
enable mem -- Enable memory region.
enable once -- Enable some breakpoints for one hit.
enable pretty-printer -- GDB command to enable the specified pretty-printer.
enable probes -- Enable probes.
enable type-printer -- GDB command to enable the specified type printer.
enable unwinder -- GDB command to enable unwinders.
enable xmethod -- GDB command to enable a specified (group of) xmethod(s).
ftrace -- Set a fast tracepoint at specified location.
hbreak -- Set a hardware assisted breakpoint.
--Type <RET> for more, q to quit, c to continue without paging--
3.3. help command
查看break命令的帮助信息:
(gdb) h b
break, brea, bre, br, b
Set breakpoint at specified location.
break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]
PROBE_MODIFIER shall be present if the command is to be placed in a
probe point. Accepted values are `-probe' (for a generic, automatically
guessed probe type), `-probe-stap' (for a SystemTap probe) or
`-probe-dtrace' (for a DTrace probe).
LOCATION may be a linespec, address, or explicit location as described
below.
With no LOCATION, uses current execution address of the selected
stack frame. This is useful for breaking on return to a stack frame.
THREADNUM is the number from "info threads".
CONDITION is a boolean expression.
Linespecs are colon-separated lists of location parameters, such as
source filename, function name, label name, and line number.
Example: To specify the start of a label named "the_top" in the
function "fact" in the file "factorial.c", use
"factorial.c:fact:the_top".
Address locations begin with "*" and specify an exact address in the
program. Example: To specify the fourth byte past the start function
"main", use "*main + 4".
Explicit locations are similar to linespecs but use an option/argument
syntax to specify location parameters.
Example: To specify the start of the label named "the_top" in the
function "fact" in the file "factorial.c", use "-source factorial.c
-function fact -label the_top".
By default, a specified function is matched against the program's
functions in all scopes. For C++, this means in all namespaces and
classes. For Ada, this means in all packages. E.g., in C++,
"func()" matches "A::func()", "A::B::func()", etc. The
"-qualified" flag overrides this behavior, making GDB interpret the
specified name as a complete fully-qualified name instead.
Multiple breakpoints at one place are permitted, and useful if their
conditions are different.
Do "help breakpoints" for info on other commands dealing with breakpoints.
(gdb)
3.4. apropos word
apropos – Search for commands matching a REGEXP. 搜索与 REGEXP 匹配的命令
搜索breakpoints匹配的命令如下:
(gdb) apropos breakpoints
break, brea, bre, br, b -- Set breakpoint at specified location.
breakpoints -- Making program stop at certain points.
clear, cl -- Clear breakpoint at specified location.
commands -- Set commands to be executed when the given breakpoints are hit.
delete, del, d -- Delete all or some breakpoints.
delete breakpoints -- Delete all or some breakpoints or auto-display expressions.
disable, disa, dis -- Disable all or some breakpoints.
disable breakpoints -- Disable all or some breakpoints.
enable, en -- Enable all or some breakpoints.
enable breakpoints -- Enable all or some breakpoints.
enable breakpoints count -- Enable some breakpoints for COUNT hits.
enable breakpoints delete -- Enable some breakpoints and delete when hit.
enable breakpoints once -- Enable some breakpoints for one hit.
enable count -- Enable some breakpoints for COUNT hits.
enable delete -- Enable some breakpoints and delete when hit.
enable once -- Enable some breakpoints for one hit.
ftrace -- Set a fast tracepoint at specified location.
hbreak -- Set a hardware assisted breakpoint.
info breakpoints, info b -- Status of specified breakpoints (all user-settable breakpoints if no argument).
maintenance info breakpoints -- Status of all breakpoints, or breakpoint number NUMBER.
save breakpoints -- Save current breakpoint definitions as a script.
set breakpoint always-inserted -- Set mode for inserting breakpoints.
set breakpoint auto-hw -- Set automatic usage of hardware breakpoints.
set breakpoint pending -- Set debugger's behavior regarding pending breakpoints.
set displaced-stepping -- Set debugger's willingness to use displaced stepping.
set may-insert-breakpoints -- Set permission to insert breakpoints in the target.
set observer -- Set whether gdb controls the inferior in observer mode.
set remote conditional-breakpoints-packet -- Set use of remote protocol `ConditionalBreakpoints' (conditional-breakpoints) packet.
set remote hardware-breakpoint-limit -- Set the maximum number of target hardware breakpoints.
show breakpoint always-inserted -- Show mode for inserting breakpoints.
show breakpoint auto-hw -- Show automatic usage of hardware breakpoints.
show breakpoint pending -- Show debugger's behavior regarding pending breakpoints.
show displaced-stepping -- Show debugger's willingness to use displaced stepping.
show may-insert-breakpoints -- Show permission to insert breakpoints in the target.
show observer -- Show whether gdb controls the inferior in observer mode.
show remote conditional-breakpoints-packet -- Show current use of remote protocol `ConditionalBreakpoints' (conditional-breakpoints) packet.
show remote hardware-breakpoint-limit -- Show the maximum number of target hardware breakpoints.
strace -- Set a static tracepoint at location or marker.
tbreak -- Set a temporary breakpoint.
thbreak -- Set a temporary hardware assisted breakpoint.
trace, trac, tra, tr, tp -- Set a tracepoint at specified location.
(gdb)
详解
拓展
后语
|