除錯代理概念

Debugger Agent 是一款由 AI 驅動的除錯助理,透過 GitHub Copilot Chat 協助你重現、隔離並修正錯誤,透過控制執行與驗證工作是否符合即時執行狀態。 當你給代理明確目標,並讓它從端到端管理除錯工作流程時,它最強大。

除錯代理程式在需要證明錯誤存在、驗證修正有效、使用斷點與追蹤點的程式碼,以及分析複雜呼叫堆疊的情境中表現出色。 結合自然語言請求與除錯器控制,你可以比單純手動除錯更有效率地完成重現、工具、隔離、修復的工作流程。

如何存取除錯代理程式

  1. 開啟 Copilot Chat 視窗(查看>GitHub Copilot Chat)。

  2. 在聊天視窗左下角的模式下拉選單中選擇 「除錯器 」,或在代理模式下輸入 @debugger 聊天輸入。

  3. 輸入描述你的除錯任務的提示,並將佔位文字替換為你情境中的具體內容。

昆蟲繁殖與診斷

除錯代理程式可以從問題描述中重現錯誤,並確認它們存在於你的執行環境中。 先把代理程式指向錯誤描述、GitHub 議題連結或 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

你也可以一鍵獲得呼叫堆疊分析:在呼叫堆疊視窗中選擇「用 Copilot 分析」,或在平行堆疊 / 檢視中用「用 Copilot 分析」來處理多執行緒情境。

單元測試除錯

除錯代理程式可以直接從聊天中除錯失敗的測試,無需你先啟動除錯器。

範例提示:

The test <TestName> is failing. Debug it, find the root cause of the failure, and suggest a fix.

Tip

你也可以從 測試總管,或從編輯器中測試上方的 CodeLens 指標開始對失敗的測試進行除錯,然後再從該處繼續與除錯工具代理程式對話。 這是將失敗測試的上下文提供給 Copilot 的簡單方式。

偵錯代理程式的最佳做法

  • 提供資料,而非指令。 除錯代理程式沒有 shell 或 PowerShell 存取權限,所以無法像你那樣執行工具 git.exe 。 相反地,直接貼上實際輸出。 例如,貼上 diff 的內容,而不是告訴代理執行 diff 指令。

  • 讓代理在執行程式碼時控制執行。 Copilot 只有在其主導執行時,才能修正條件式中斷點和追蹤點中的錯誤。 偏好「設定一個條件斷點......並且執行我的專案」,而不是「設定條件斷點」本身。

  • 讓代理進入中斷狀態時完成。 如果代理控制執行,且聊天室仍顯示 Copilot 在運作,那你不需要做任何事。 要重新掌控,請在聊天中選擇 停止 按鈕。