kopia lustrzana https://github.com/micropython/micropython-lib
2.5 KiB
2.5 KiB
Debugging MicroPython debugpy with VS Code
Method 1: Direct Connection with Enhanced Logging
-
Start MicroPython with enhanced logging:
~/micropython2/ports/unix/build-standard/micropython test_vscode.py
This will now show detailed DAP protocol messages like:
[DAP] RECV: request initialize (seq=1) [DAP] args: {...} [DAP] SEND: response initialize (req_seq=1, success=True)
-
Connect VS Code debugger:
- Use the launch configuration in
.vscode/launch.json
- Or manually attach to
127.0.0.1:5678
- Use the launch configuration in
-
Look for issues in the terminal output - you'll see all DAP message exchanges
Method 2: Using DAP Monitor (Recommended for detailed analysis)
-
Start MicroPython debugpy server:
~/micropython2/ports/unix/build-standard/micropython test_vscode.py
-
In another terminal, start the DAP monitor:
python3 dap_monitor.py
The monitor listens on port 5679 and forwards to port 5678
-
Connect VS Code to the monitor:
- Modify your VS Code launch config to connect to port
5679
instead of5678
- Or create a new launch config:
{ "name": "Debug via Monitor", "type": "python", "request": "attach", "connect": { "host": "127.0.0.1", "port": 5679 } }
- Modify your VS Code launch config to connect to port
-
Analyze the complete DAP conversation in the monitor terminal
VS Code Debug Logging
Enable VS Code's built-in DAP logging:
- Open VS Code settings (Ctrl+,)
- Search for:
debug.console.verbosity
- Set to:
verbose
- Also set:
debug.allowBreakpointsEverywhere
totrue
Common Issues to Look For
- Missing required DAP capabilities - check the
initialize
response - Breakpoint verification failures - look for
setBreakpoints
exchanges - Thread/stack frame issues - check
stackTrace
andscopes
responses - Evaluation problems - monitor
evaluate
request/response pairs
Expected DAP Sequence
A successful debug session should show this sequence:
initialize
request → response with capabilitiesinitialized
eventsetBreakpoints
request → response with verified breakpointsconfigurationDone
request → responseattach
request → response- When execution hits breakpoint:
stopped
event stackTrace
request → response with framesscopes
request → response with local/global scopescontinue
request → response to resume
If any step fails or is missing, that's where the issue lies.