ライブラリ ルーチンを使用したデバッガーの自動起動

制約事項: 本トピックは、ネイティブ COBOL にのみ該当します。

CBL_DEBUGBREAK および CBL_DEBUG_START ライブラリ ルーチンを使用すると、コード内の特定のポイントでデバッグをトリガーさせることができます。これは特に、他のプログラムから呼び出される ダイナミック リンク ライブラリをデバッグする際に役に立ちます。

多くの場合、これらの文は、指令の設定によって有効または無効にできるように条件付きコンパイルで組み込まれます。次の例では、アプリケーションをビルドする前にユーザーが CONSTANT DEBUG(1) をコンパイラ指令として設定した場合にのみ、CBL_DEBUGBREAK が呼び出されます。

CBL_DEBUGBREAK を使用して、デバッガー を呼び出します。

別の方法としては、CBL_DEBUG_START と CBL_DEBUG_STOP を使用して、アプリケーションへのデバッガーの接続とアプリケーションからのデバッガーの切り離しを行います。これらのルーチンには、デバッグをさらに制御できるパラメーターが含まれています (開始すべきデバッガー プロセスの識別やその開始を待つ時間など)。

  1. ルーチンの呼び出しをプログラム内の適切なポイントに追加し、アプリケーションをリビルドします。以下のコード例を参照してください。
  2. プロジェクトのプロパティで、[Wait for debuggable attachment] 起動オプションを有効にし、プログラムで呼び出したライブラリ ルーチンに応じて [Wait for any program] または [Wait for ID] のいずれかのサブオプションを選択します。詳細については、「[Wait for debuggable attachment] を使用してデバッグ プロセスを起動するには」を参照してください。
  3. その他のデバッグ オプションを必要に応じて設定します。
  4. デバッガーを起動します。

CBL_DEBUGBREAK または CBL_DEBUG_START が実行されるまでは、デバッガーは待機状態のままになります。CBL_DEBUG_START を使用した場合は、CBL_DEBUG_STOP を使用してデバッガーをアプリケーションから切り離すことができます。そのアプリケーションは、デバッグ機能なしで実行を再開します。

CBL_DEBUGBREAK の例

            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.

CBL_DEBUG_START/STOP の例

       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
           .