Debugger Agent は、GitHub Copilot Chatを介して動作する AI を利用したデバッグ アシスタントで、実行を制御し、ライブ ランタイム状態に対して作業を検証することで、バグを再現、分離、修正するのに役立ちます。 エージェントは、明確な目標を与え、デバッグ ワークフローをエンドツーエンドで管理できるようにする場合に最も強力です。
デバッガー エージェントは、バグの存在を証明し、修正プログラムが機能することを確認し、ブレークポイントとトレースポイントを使用してコードをインストルメント化し、複雑な呼び出し履歴を分析する必要があるシナリオに優れています。 自然言語要求とデバッガー制御を組み合わせることにより、手動デバッグだけで実行するよりも効率的に、再現/インストルメント/分離/修正ワークフロー間を移動できます。
デバッガー エージェントにアクセスする方法
Copilot Chat ウィンドウ (View>GitHub Copilot Chat) を開きます。
チャット ウィンドウの左下隅にあるモード ドロップダウンから [デバッガー ] を選択するか、エージェント モードでチャット入力に
@debuggerを入力します。プレースホルダー テキストをシナリオの詳細に置き換えて、デバッグ タスクを説明するプロンプトを入力します。
バグの再現と診断
デバッガー エージェントは、問題の説明からバグを再現し、ランタイム環境にバグが存在することを確認できます。 まず、バグの説明、GitHub の issue リンク、または Azure DevOps のバグをエージェントに指定し、一連の流れ全体を実行させます。
プロンプトの例:
Investigate/fix/debug the bug described in <issue link>. Reproduce the failure, find the root cause with the debugger, and propose a fix.
When I <do these steps>, I expect <expected result> but instead I see <actual result>. Debug the problem, find where the code goes wrong, and suggest a fix.
Create a minimal repro for the following issue, then run it under the debugger to confirm the failure and show me the runtime state that causes it: <bug description>.
ベリフィケーションとバリデーションを修正
エージェントが作成した修正でも自分で作成した修正でも、修正が問題を解決し、すべての重要なコードパスが実行されることを確認するために、Debugger Agent を使用してください。
プロンプトの例:
エージェントに、修正が機能することを証明できる自己完結した手段(単体テストまたは小さなコンソール再現コード)を与え、そのうえで特定のランタイム動作を検証させます。
Set breakpoints at <specific locations>, debug, and verify that <variable> has the value <expected value> and that <behavior> happens as expected.
I'm working on a change to make my code handle <new feature>. As part of that, I broke the following scenario: <repro steps>. Debug the problem and find where my code went wrong. Here are my changes: <paste diff here>
インストルメンテーションとランタイムの検査
デバッガー エージェントは、条件付きブレークポイントとトレースポイントを必要な場所に正確に設定し、プロジェクトを実行して必要なデータを収集できます。 この方法では、コードを手動で編集しなくても、可視性が向上します。
プロンプトの例:
Set a breakpoint at the start of ProcessFile that breaks only when the file name starts with "data12345", then launch my project.
I need more visibility into <area of code>. Add tracepoints that log <the values you care about> at the key points in this flow, then run my project and show me the trace output.
呼び出し履歴の分析と制御フロー
ブレークポイントまたは例外で一時停止し、実行パスを理解する必要がある場合、デバッガー エージェントは呼び出し履歴を分析し、非同期フローを含む現在のスレッドの動作を説明できます。
プロンプトの例:
Analyze the current call stack and explain what this thread is doing and how it got here, including the async flow. Point out the frame most likely responsible for <the problem>.
Why is my code taking the wrong branch and not reaching <this line>? Set a breakpoint there and run the app. If it isn't hit, set breakpoints at the upstream decision points and inspect the actual condition values to find where control flow diverges.
Tip
1 回のクリックで呼び出し履歴の分析を取得することもできます。[呼び出し履歴] ウィンドウで [Copilotで分析] を選択するか、[並列スタック / ] ビューでCopilotで分析を使用してマルチスレッド シナリオを実行できます。
単体テストのデバッグ
デバッガー エージェントは、最初にデバッガーを起動しなくても、失敗したテストをチャットから直接デバッグできます。
サンプル プロンプト:
The test <TestName> is failing. Debug it, find the root cause of the failure, and suggest a fix.
Tip
テスト エクスプローラーまたはエディターで テスト の上にある CodeLens インジケーターから失敗したテストのデバッグを開始し、そこからデバッガー エージェントとの会話を続けることもできます。 これは、失敗したテストのコンテキストをCopilotに渡す簡単な方法です。
デバッガー エージェントのベスト プラクティス
コマンドではなく、データを指定します。 デバッガー エージェントにはシェルまたは PowerShell アクセスがないため、
git.exeなどのツールを実行できません。 代わりに、実際の出力を貼り付けます。 たとえば、diff コマンドを実行するようにエージェントに指示するのではなく、差分のテキストを貼り付けます。エージェントがコードをインストルメント化する際に実行を制御します。 Copilot は、実行を制御している場合にのみ、条件付きブレークポイントおよびトレースポイントの誤りを修正できます。 「条件付きブレークポイントを設定する」単独よりも、「条件付きブレークポイントを設定して、プロジェクトを実行する」を優先してください。
エージェントが休憩状態に入ったときに終了させます。 エージェントが実行を制御していて、チャットにCopilot動作が表示される場合は、何もする必要はありません。 制御を取り戻すには、チャットの 停止 ボタンを選択します。