次に、イベントハンドラの設定例をあげます。
array[99] でデータ変更ブレークポイントを設定するには、次のように入力します。
(dbx) stop access w &array[99] (2) stop access w &array[99], 4 (dbx) run Running: watch.x2 watchpoint array[99] (0x2ca88[4]) at line 22 in file "watch.c" 22 array[i] = i; |
(dbx) when step { echo at line $lineno; } |
たとえば、
<dbx> trace step -in foo |
は、次のようなスクリプトと等価です。
# create handler in disabled state when step -disable { echo Stepped to $line; } t=$newhandlerid # remember handler id when in foo { # when entered foo enable the trace handler -enable "$t" # arrange so that upon returning from foo, # the trace is disabled. when returns { handler -disable "$t"; }; } |
小規模なプログラムで何行実行されたかを調べます。
(dbx) stop step -count infinity # step and stop when count=inf (2) stop step -count 0/infinity (dbx) run ... (dbx) status (2) stop step -count 133/infinity |
ここでは、プログラムを停止させているのではなく、明らかにプログラムが終了しています。実行された行の数は 133 です。このプロセスは非常に低速です。この方法が有効なのは、何度も呼び出される関数にブレークポイントを設定している場合です。
特定の行で実行された命令の数を数えます。
(dbx) ... # get to the line in question (dbx) stop step -instr -count infinity (dbx) step ... (dbx) status (3) stop step -count 48/infinity # 48 instructions were executed |
ステップ実行している行で関数呼び出しが行われる場合、最終的にそれらの呼び出しもカウントされます。step イベントの代わりに next イベントを使用すれば、そのような呼び出しはカウントされません。
別のイベントが発生した場合のみ、ブレークポイントを有効にします。たとえば、プログラムで関数 hash が 1300 番目のシンボル検索以後に正しく動作しなくなるとします。次のように入力します。
(dbx) when in lookup -count 1300 { stop in hash hash_bpt=$newhandlerid when proc_gone -temp { delete $hash_bpt; } } |
$newhandlerid が、実行された直後の stop in コマンドを参照している点に注意してください。
アプリケーションが処理するファイルを replay 中にリセットする必要がある場合、プログラムを実行するたびに自動的にリセットを行うハンドラを書くことができます。
(dbx) when sync { sh regen ./database; } (dbx) run < ./database... # during which database gets clobbered (dbx) save ... # implies a RUN, which implies the SYNC event which (dbx) restore # causes regen to run |
プログラムの実行中にその状態をすばやく調べます。
(dbx) ignore sigint (dbx) when sig sigint { where; cancel; } |
プログラムを停止しないでそのスタックトレースを調べるためには、ここで ^C を押します。
コレクタはこれ以外のことも実行できますが、基本的にコレクタの手動標本収集モードが実行する機能は、このように状態を調べます。ここではすでに ^C を使用したため、プログラムに割り込むには SIGQUIT (^\) を使用します。
特定の浮動小数点例外を捕捉します。ここでは、IEEE オーバーフローだけを捕捉しています。
(dbx) ignore FPE # turn off default handler (dbx) help signals | grep FPE # can’t remember the subcode name ... (dbx) stop sig fpe FPE_FLTUND ... |