CBL_DEBUGBREAK および CBL_DEBUG_START ライブラリ・ルーチンを使用すると、コード内の特定のポイントでデバッグをトリガさせることができます。これは、他のプログラムから呼び出される Windows ダイナミック・リンク・ライブラリをデバッグする場合に特に役立ちます。
多くの場合、これらの文は、指令の設定によって有効または無効にできるように条件付きコンパイルで組み込まれます。次の例では、アプリケーションをビルドする前にユーザが CONSTANT DEBUG(1) をコンパイラ指令として設定した場合にのみ、CBL_DEBUGBREAK が呼び出されます。
CBL_DEBUGBREAK を使用して、デバッガ (Windows) または アニメータ (UNIX) を呼び出します。
別の方法としては、CBL_DEBUG_START と CBL_DEBUG_STOP を使用して、アプリケーションへのデバッガの接続とアプリケーションからのデバッガの切り離しを行います。これらのルーチンには、デバッグをさらに制御できるパラメータが含まれています (開始すべきデバッガ・プロセスの識別やその開始を待つ時間など)。
CBL_DEBUGBREAK または CBL_DEBUG_START が実行されるまでは、デバッガは待機状態のままになります。CBL_DEBUG_START を使用した場合は、CBL_DEBUG_STOP を使用してデバッガをアプリケーションから切り離すことができます。そのアプリケーションは、デバッグ機能なしで実行を再開します。
perform with test after
until char not = "Y" and char not = "y"
call clear-screen
display
"To select a square type a number between 1 and 9"
upon crt
perform init
move "Shall I start ? " to question
perform get-reply
$if DEBUG defined
call "CBL_DEBUGBREAK"
$end
if char = "Y" or char = "y"
move 10 to check(5)
perform put-move
end-if
perform new-move
until game not = spaces
move "Play again ? " to question
perform get-reply
end-perform.
working-storage section.
copy 'cbltypes.cpy'.
01 dbg.
02 flgs cblt-os-flags.
02 tmout cblt-os-ssize.
02 identifier pic x(80) value "XsessID ".
02 st-code pic x(2) COMP-5.
01 transaction pic x(80).
01 stop-flags cblt-os-flags.
01 argument pic x(80).
procedure division.
move "transaction" to argument
*> Set CBL_DEBUG_START flags to :-
*> Start debugging via a waiting debugger,
*> when a debuggable program is entered.
*> Error if no debugger is available.
*>
move h"03" to flgs
move 0 to tmout
*> Set CBL_DEBUG_STOP flags to :-
*> Stop debugging and return the debugger to
*> a waiting state
*>
move h"01" to stop-flags
*> Run the transaction
perform run-transaction
call "CBL_THREAD_SLEEP" using by value 5000 size 4
*> Run the transaction
perform run-transaction
stop run.
run-transaction section.
call "CBL_DEBUG_START" using by value flgs
tmout
by reference identifier
returning st-code
if st-code not = 0
display "No waiting debugger"
goback
end-if
call argument
call "CBL_DEBUG_STOP" using by value stop-flags
returning st-code
if st-code not = 0
display "Failed to stop debugger"
end-if
.