8.3. 运行 GNU Debugger
要在您要调试的程序上运行 GNU Debugger :
$ scl enable devtoolset-11 'gdb file_name'
这会在交互模式中启动 gdb debugger,并显示默认提示 (gdb)。要退出调试会话并返回到 shell 提示符,请随时运行以下命令:
(gdb) quit
请注意,您可以使用 scl 工具执行任何命令,从而导致它使用等效的 Red Hat Developer Toolset 二进制文件来运行它。这可让您使用 Red Hat Developer Toolset gdb 作为默认运行 shell 会话:
$ scl enable devtoolset-11 'bash'
注意
验证您在任何时间点上使用的 gdb 版本:
$ which gdb
Red Hat Developer Toolset 的 gdb 可执行路径以 /opt 开头。另外,您可以使用以下命令确认版本号与 Red Hat Developer Toolset gdb 的版本号匹配:
$ gdb -v
例 8.3. 在 fibonacci Binary 文件中运行 gdb 实用程序
这个示例假设您已成功编译了 fibonacci 二进制文件,如 例 8.1 “使用调试信息编译 C 程序” 所示。
使用 gdb 开始调试 fibonacci :
$ scl enable devtoolset-11 'gdb fibonacci'
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-2.el7
Copyright (C) 2017 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:
<http://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"...
Reading symbols from fibonacci...done.
(gdb)