gdbをインストールした後、ターミナルでプログラムをデバッグするためにgdbを使用してみることができます。gdbのインストールに疑問がある場合は、gdbデバッグエントリ(1)を参照してください:Windows / Linux / Ubuntuでgdbをインストールします。
1.デバッグする必要がある.cファイルを作成または検索します
最初にシンプルなものを書きますhelloworld.c
:
#include<stdio.h>
int main()
{
printf("hello world! \n");
return 0;
}
デバッグする必要のある.cプログラムを見つけて、次のステップを開始することもできます。
2.ファイルをコンパイルします
含むhelloworld.c
ディレクトリの入力端子を:
gcc -g helloworld.c -o helloworld
そして、それが命名にこのディレクトリのうねりで見つけることができhelloworld
、実行可能ファイル。
3. gdbデバッグを開始します
前のセクションのターミナルで、gdb +前のセクションで生成されたデバッグ対象のプログラムの実行可能ファイル名を入力し続けます。
gdb helloworld
端末が次のログ情報を出力したことがわかります。
GNU gdb (GDB) 7.12
Copyright (C) 2016 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-pc-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 helloworld...done.
次に、inputなどのデバッグを行うとlist
、次のログを確認できます。
(gdb) list
1 #include<stdio.h>
2 int main()
3 {
4 printf("hello world! \n");
5 return 0;
6 }
好きなだけデバッグを開始してください〜