Show Table of Contents
5.3.3. 条件付きブレークポイント
現実の多くの場面で、プログラムは最初の数千回はタスクを適切に実行するものの、タスクの反復回数が 8,000 回に達するとクラッシュし始めたり、エラーが検出される場合があります。プログラマーがクラッシュした反復に達するためだけに
continue コマンドを数千回も辛抱強く実行するとは想像し難いため、このようなデバッグプログラムは困難なものです。
このような状況は現実ではよくあります。そのため、GDB はプログラマーが条件をブレークポイントに付加できるようにします。たとえば、以下のプログラムを見てみましょう。
simple.c
#include <stdio.h>
main()
{
int i;
for (i = 0;; i++) {
fprintf (stdout, "i = %d\n", i);
}
}
GDB プロンプトで条件付きブレークポイントを設定するには、以下のようにします。
(gdb) br 8 if i == 8936 Breakpoint 1 at 0x80483f5: file iterations.c, line 8. (gdb) r
この条件により、プログラムは次の出力を表示して停止します。
i = 8931 i = 8932 i = 8933 i = 8934 i = 8935 Breakpoint 1, main () at iterations.c:8 8 fprintf (stdout, "i = %d\n", i);
ブレークポイントの状況を確認するためにブレークポイントの情報を検査します (
info br を使用する)。
(gdb) info br
Num Type Disp Enb Address What
1 breakpoint keep y 0x080483f5 in main at iterations.c:8
stop only if i == 8936
breakpoint already hit 1 time

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.