指定した式にウォッチポイントを設定します。
次の例は、変数 glob にウォッチポイントを設定し、デバッグ対象が変数を書き込んだ場合の動作を示しています。
hello_simple.c: のコードの行 16-25 を例に考えます。
16 printf("Hello world!\n");
17
18 glob = 1;
19 glob = 11;
20 glob = 111;
21 glob = 1111;
22
23 readGlob(glob);
24 readGlob(glob);
25 readGlob(glob);
例の最初では、glob=1 です。
(idb) break 19 Breakpoint 1 at 0x1f75: file /site/c_code/hello_simple.c, line 19. (idb) run Starting program: /site/c_code/hello_simple.darwin.9.exe.dSYM/Contents/Resources/DWARF/hello_simple.darwin.9.exe Hello world! Breakpoint 1, main () at /site/c_code/hello_simple.c:19 19 glob = 11;(idb) next 20 glob = 111; (idb) print glob $1 = 11
ここでは、glob=11 です。行 19 は実行されましたが行 20 は実行されていません。
ウォッチポイントを作成します。
(idb) awatch glob Watchpoint 2: Access memory (any) 0x00002048 to 0x0000204b (idb) continue Continuing. Old value = 11 New value = 111 Watchpoint 2, main () at /site/c_code/hello_simple.c:21 21 glob = 1111;
行 20 の割り当ての結果としてウォッチポイントにヒットしますが、変数が行 20 でアクセスされるため、デバッガーは行 21 を実行する前に行 21 で停止します。
(idb)
continue
Continuing.
Old value = 111
New value = 1111
Watchpoint 2, main () at /site/c_code/hello_simple.c:23
23 readGlob(glob);行 21 の割り当ての結果としてウォッチポイントにヒットします。行 22 にコードがないため、デバッガーは行 23 で停止します。