8.3. GNU デバッガーの実行

デバッグするプログラムで GNU デバッガー を実行するには、以下を実行します。

$ scl enable devtoolset-9 'gdb file_name'

これにより、インタラクティブモードで gdb デバッガーが開始され、デフォルトのプロンプト (gdb) が表示されます。デバッグセッションを終了してシェルプロンプトに戻るには、いつでも以下のコマンドを実行します。

(gdb) quit

この scl ユーティリティーを使用してコマンドを実行すると、これを Red Hat Enterprise Linux システムに優先して使用する Red Hat Developer Toolset バイナリーで実行することができることに注意してください。これにより、デフォルトで Red Hat Developer Toolset gdb でシェルセッションを実行できます。

$ scl enable devtoolset-9 'bash'
注記

使用中の gdb のバージョンを確認するには、以下を行います。

$ which gdb

Red Hat Developer Toolset の gdb の実行可能なパスは、/opt で始まります。以下のコマンドを使用して、バージョン番号が Red Hat Developer Toolset gdb と一致することを確認することができます。

$ gdb -v

例8.3 fiacci バイナリーファイルでの gdb ユーティリティーの実行

この例では、例8.1「デバッグ情報を使用した C プログラムのコンパイル」 の説明に従って fibonacci バイナリーファイルを正常にコンパイルしていることを前提としています。

fibonacci を使用して、gdb のデバッグを開始します。

$ scl enable devtoolset-9 '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)