|
| 1 | +--- |
| 2 | +name: Breakpoint Debugging |
| 3 | +description: Use the Chrome DevTools Debugger to find root causes of bugs by setting breakpoints, inspecting state, and stepping through code. |
| 4 | +--- |
| 5 | + |
| 6 | +# Breakpoint Debugging Skill |
| 7 | + |
| 8 | +This skill allows you to perform in-depth Root Cause Analysis (RCA) by controlling the Chrome DevTools Debugger. You can pause execution, inspect variables, and step through code to understand exactly why a bug is occurring. |
| 9 | + |
| 10 | +## Tools |
| 11 | + |
| 12 | +- `debugger_enable`: Enable the debugger for the page. **Must be called first.** |
| 13 | +- `debugger_set_breakpoint`: Set a breakpoint at a specific URL and line number. |
| 14 | +- `debugger_get_paused_state`: Check if the debugger is paused and get the call stack. |
| 15 | +- `debugger_get_scope_variables`: Inspect variables in a specific scope when paused. |
| 16 | +- `debugger_step_over` / `debugger_step_into` / `debugger_step_out`: Control execution. |
| 17 | +- `debugger_resume`: Resume execution. |
| 18 | +- `debugger_evaluate_on_call_frame`: Evaluate expressions in the current context. |
| 19 | +- `debugger_get_code_lines`: Read code around a specific line. |
| 20 | + |
| 21 | +## Root Cause Analysis Workflow |
| 22 | + |
| 23 | +Your objective is to find the **root cause** of an error or bug. Do not stop at the surface level. |
| 24 | + |
| 25 | +1. **Enable Debugger**: Always start by ensuring the debugger is enabled. |
| 26 | + ```javascript |
| 27 | + // Example |
| 28 | + debugger_enable({}) |
| 29 | + ``` |
| 30 | + |
| 31 | +2. **Hypothesize & Set Trap**: |
| 32 | + - Read the code using `debugger_get_code_lines` (or `read_file` if local) to understand the logic. |
| 33 | + - Identify the critical line where state corruption likely occurred. |
| 34 | + - Set a breakpoint on that line. |
| 35 | + ```javascript |
| 36 | + debugger_set_breakpoint({ url: 'http://localhost:8080/app.js', lineNumber: 42 }) |
| 37 | + ``` |
| 38 | + |
| 39 | +3. **Trigger & Wait**: |
| 40 | + - Perform the action that triggers the bug (e.g., clicking a button using `click`). |
| 41 | + - Check if the debugger is paused using `debugger_get_paused_state`. |
| 42 | + - **Note**: If `debugger_get_paused_state` returns "Debugger is not paused", wait a moment and try again, or ask the user to trigger the action if you cannot. |
| 43 | + |
| 44 | +4. **Inspect State (Runtime Mode)**: |
| 45 | + - Once paused, examine the `callStack` returned by `debugger_get_paused_state`. |
| 46 | + - Use `debugger_get_scope_variables` to see values of local variables. |
| 47 | + - Use `debugger_evaluate_on_call_frame` to check specific expressions or deep objects. |
| 48 | + ```javascript |
| 49 | + // Check local variables (scopeIndex 0 is usually Local) |
| 50 | + debugger_get_scope_variables({ callFrameId: '...', scopeIndex: 0 }) |
| 51 | + ``` |
| 52 | + |
| 53 | +5. **Step & Trace**: |
| 54 | + - Use `debugger_step_into` to enter function calls. |
| 55 | + - Use `debugger_step_over` to advance line-by-line. |
| 56 | + - Use `debugger_step_out` to return to the caller. |
| 57 | + - **Always** check `debugger_get_paused_state` and variable values after stepping to see how state changed. |
| 58 | + |
| 59 | +6. **Verify Root Cause**: |
| 60 | + - Explain exactly how the runtime state contradicts the expected logic. |
| 61 | + - Point to the specific line of code that is the root cause. |
| 62 | + |
| 63 | +7. **Apply Fix & Verify**: |
| 64 | + - Once the issue is found, you can try to fix it (e.g., by editing the file). |
| 65 | + - Remove breakpoints using `debugger_remove_breakpoint` or `debugger_remove_all_breakpoints`. |
| 66 | + - Resume execution with `debugger_resume`. |
| 67 | + - Verify the fix by reproducing the steps. |
| 68 | + |
| 69 | +## Tips |
| 70 | + |
| 71 | +- **STATIC MODE** (Reading code) vs **RUNTIME MODE** (Paused): Switch between them. If you need to see a variable, switch to Runtime Mode by setting a breakpoint. |
| 72 | +- **Already Paused?**: If you are already paused, start inspecting immediately. |
| 73 | +- **Step Into**: Essential for investigating function calls on the current line. |
| 74 | +- **Check Location**: Always confirm where you are with `debugger_get_paused_state` after stepping. |
0 commit comments