debug-run 0.1.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,262 @@
1
+ # .NET Debugging Guide
2
+
3
+ This guide covers debugging .NET applications with debug-run using the vsdbg adapter.
4
+
5
+ ## Prerequisites
6
+
7
+ ### vsdbg Adapter
8
+
9
+ The vsdbg adapter is automatically detected if you have the VS Code C# extension installed:
10
+
11
+ ```bash
12
+ npx debug-run list-adapters
13
+ # Should show: vsdbg - Status: installed (path)
14
+ ```
15
+
16
+ If not installed, install the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) in VS Code.
17
+
18
+ ### Alternative: netcoredbg
19
+
20
+ Open-source alternative (less stable on some platforms):
21
+
22
+ ```bash
23
+ npx debug-run install-adapter netcoredbg
24
+ ```
25
+
26
+ ## Build Your Application
27
+
28
+ Before debugging, build your .NET application:
29
+
30
+ ```bash
31
+ dotnet build
32
+ ```
33
+
34
+ ## Launch Mode (Debug New Process)
35
+
36
+ ### Basic Debugging
37
+
38
+ ```bash
39
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
40
+ -a vsdbg \
41
+ -b "src/Services/OrderService.cs:42" \
42
+ --pretty \
43
+ -t 30s
44
+ ```
45
+
46
+ ### With Expression Evaluation
47
+
48
+ ```bash
49
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
50
+ -a vsdbg \
51
+ -b "src/Services/OrderService.cs:42" \
52
+ -e "order.Total" \
53
+ -e "order.Items.Count" \
54
+ -e "this._inventory.Count" \
55
+ --pretty \
56
+ -t 30s
57
+ ```
58
+
59
+ ### With Assertions
60
+
61
+ ```bash
62
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
63
+ -a vsdbg \
64
+ -b "src/Services/OrderService.cs:42" \
65
+ --assert "order.Total >= 0" \
66
+ --assert "order.Items.Count > 0" \
67
+ --assert "this._inventory != null" \
68
+ --pretty \
69
+ -t 30s
70
+ ```
71
+
72
+ ### Exception Handling
73
+
74
+ Break on all exceptions with chain flattening:
75
+
76
+ ```bash
77
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
78
+ -a vsdbg \
79
+ --break-on-exception all \
80
+ --pretty \
81
+ -t 30s
82
+ ```
83
+
84
+ ## Attach Mode (ASP.NET / Long-Running Services)
85
+
86
+ For debugging running ASP.NET applications or services:
87
+
88
+ ### 1. Start Your Application
89
+
90
+ ```bash
91
+ cd MyWebApi
92
+ dotnet run
93
+ # Note the process - find PID with: ps aux | grep dotnet
94
+ ```
95
+
96
+ ### 2. Attach debug-run
97
+
98
+ ```bash
99
+ npx debug-run --attach --pid <PID> \
100
+ -a vsdbg \
101
+ -b "src/Controllers/OrderController.cs:28" \
102
+ -e "request.OrderId" \
103
+ --pretty \
104
+ -t 60s
105
+ ```
106
+
107
+ ### Important Notes for Attach Mode
108
+
109
+ 1. **Timing matters**: After `process_attached` event, wait 10-15 seconds before triggering the code path
110
+ 2. **Breakpoints start unverified**: `verified: false` is normal; they verify when the code path is hit
111
+ 3. **Process survives**: In attach mode, the debuggee keeps running after debug-run exits
112
+
113
+ ### Example: Debug ASP.NET Endpoint
114
+
115
+ ```bash
116
+ # Terminal 1: Start the API
117
+ cd samples/aspnet/SampleApi
118
+ dotnet run # Runs on http://localhost:5009
119
+
120
+ # Terminal 2: Attach debugger
121
+ npx debug-run --attach --pid $(pgrep -f SampleApi) \
122
+ -a vsdbg \
123
+ -b "samples/aspnet/SampleApi/Program.cs:16" \
124
+ --pretty \
125
+ -t 60s
126
+
127
+ # Terminal 3: Trigger the endpoint
128
+ curl http://localhost:5009/orders
129
+ ```
130
+
131
+ ## Test Debugging (NUnit, xUnit, MSTest)
132
+
133
+ debug-run supports debugging .NET unit tests with automatic test runner orchestration:
134
+
135
+ ### Quick Start
136
+
137
+ ```bash
138
+ # Build the test project first
139
+ cd samples/nunit && dotnet build && cd ../..
140
+
141
+ # Debug tests
142
+ npx debug-run --test-project samples/nunit \
143
+ -b "samples/nunit/CalculatorTests.cs:57" \
144
+ --pretty \
145
+ -t 60s
146
+ ```
147
+
148
+ ### Filter Specific Tests
149
+
150
+ ```bash
151
+ npx debug-run --test-project samples/nunit \
152
+ --test-filter "Add_TwoPositiveNumbers_ReturnsSum" \
153
+ -b "samples/nunit/CalculatorTests.cs:57" \
154
+ --pretty
155
+ ```
156
+
157
+ ### With Expression Evaluation
158
+
159
+ ```bash
160
+ npx debug-run --test-project samples/nunit \
161
+ -b "samples/nunit/CalculatorTests.cs:57" \
162
+ -e "a" -e "b" -e "result" \
163
+ --pretty
164
+ ```
165
+
166
+ ### How It Works
167
+
168
+ 1. Launches `dotnet test --no-build` with `VSTEST_HOST_DEBUG=1`
169
+ 2. Parses the testhost PID from the output
170
+ 3. Automatically attaches the debugger to the testhost process
171
+ 4. Sets breakpoints and captures variables
172
+
173
+ ## Trace Mode
174
+
175
+ Follow execution flow after hitting a breakpoint:
176
+
177
+ ```bash
178
+ # Basic trace
179
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
180
+ -a vsdbg \
181
+ -b "src/Services/OrderService.cs:42" \
182
+ --trace \
183
+ --pretty
184
+
185
+ # Trace into function calls
186
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
187
+ -a vsdbg \
188
+ -b "src/Services/OrderService.cs:42" \
189
+ --trace \
190
+ --trace-into \
191
+ --trace-limit 50 \
192
+ --pretty
193
+
194
+ # Trace with variable diffing
195
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
196
+ -a vsdbg \
197
+ -b "src/Services/OrderService.cs:42" \
198
+ --trace \
199
+ --diff-vars \
200
+ --pretty
201
+ ```
202
+
203
+ ## Sample Application
204
+
205
+ A sample .NET console application is included for testing:
206
+
207
+ ```bash
208
+ # Build
209
+ cd samples/dotnet && dotnet build && cd ../..
210
+
211
+ # Debug
212
+ npx debug-run ./samples/dotnet/bin/Debug/net8.0/SampleApp.dll \
213
+ -a vsdbg \
214
+ -b "samples/dotnet/Program.cs:67" \
215
+ --pretty \
216
+ -t 30s
217
+ ```
218
+
219
+ ### Good Breakpoint Locations
220
+
221
+ | Line | Location | Description |
222
+ |------|----------|-------------|
223
+ | 67 | `ProcessOrder` | Inside order processing method |
224
+ | 51 | `Main` | After configuration setup |
225
+ | 78 | `CalculateDiscount` | Discount calculation logic |
226
+
227
+ ## Token Efficiency for .NET
228
+
229
+ ### Blocked Properties (Automatic)
230
+
231
+ debug-run automatically filters verbose .NET reflection metadata:
232
+ - `EqualityContract` - C# record equality (often 4KB+ of noise)
233
+ - `CustomAttributes`, `DeclaredConstructors`, `DeclaredMethods`
234
+ - `[More]`, `Raw View`, `Static members`, `Non-Public members`
235
+
236
+ ### Service Type Compaction
237
+
238
+ Common service patterns are compacted by default:
239
+ ```json
240
+ "_logger": { "type": "ILogger<OrderService>", "value": "{ILogger}" }
241
+ "_repository": { "type": "OrderRepository", "value": "{Repository}" }
242
+ ```
243
+
244
+ Override with `--expand-services` if you need full expansion.
245
+
246
+ ## Troubleshooting
247
+
248
+ | Issue | Solution |
249
+ |-------|----------|
250
+ | vsdbg license warning | Informational only, can be ignored |
251
+ | netcoredbg SIGSEGV | Use vsdbg instead (`-a vsdbg`) |
252
+ | "Adapter not installed" | Install VS Code C# extension |
253
+ | Breakpoint not verified | Wait longer after attach, or check file path |
254
+ | Test not stopping | Ensure `--no-build` and build manually first |
255
+
256
+ ### Debug Adapter Communication
257
+
258
+ Enable verbose DAP logging:
259
+
260
+ ```bash
261
+ DEBUG_DAP=1 npx debug-run ./app.dll -a vsdbg -b "file.cs:10" --pretty
262
+ ```
@@ -0,0 +1,282 @@
1
+ # Python Debugging Guide
2
+
3
+ This guide covers debugging Python applications with debug-run using the debugpy adapter.
4
+
5
+ ## Prerequisites
6
+
7
+ ### debugpy Adapter
8
+
9
+ The debugpy adapter is automatically detected from two sources:
10
+
11
+ 1. **VS Code Python Extension** (recommended) - debugpy is bundled with it
12
+ 2. **pip installation** - `pip install debugpy`
13
+
14
+ Check availability:
15
+
16
+ ```bash
17
+ npx debug-run list-adapters
18
+ # Should show: debugpy - Status: installed (VS Code Python extension or pip)
19
+ ```
20
+
21
+ ### Installing debugpy
22
+
23
+ **Option 1: VS Code Python Extension (Recommended)**
24
+ - Install the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) in VS Code
25
+ - debugpy is bundled automatically
26
+
27
+ **Option 2: pip**
28
+ ```bash
29
+ pip install debugpy
30
+ # or
31
+ pip3 install debugpy
32
+ ```
33
+
34
+ ## Launch Mode (Debug Python Script)
35
+
36
+ ### Basic Debugging
37
+
38
+ ```bash
39
+ npx debug-run ./main.py \
40
+ -a python \
41
+ -b "src/processor.py:25" \
42
+ --pretty \
43
+ -t 30s
44
+ ```
45
+
46
+ ### With Expression Evaluation
47
+
48
+ ```bash
49
+ npx debug-run ./main.py \
50
+ -a python \
51
+ -b "src/processor.py:42" \
52
+ -e "subtotal" \
53
+ -e "tax" \
54
+ -e "order.order_id" \
55
+ -e "len(order.items)" \
56
+ --pretty \
57
+ -t 30s
58
+ ```
59
+
60
+ ### With Assertions
61
+
62
+ ```bash
63
+ npx debug-run ./main.py \
64
+ -a python \
65
+ -b "src/processor.py:42" \
66
+ --assert "subtotal >= 0" \
67
+ --assert "len(order.items) > 0" \
68
+ --assert "customer is not None" \
69
+ --pretty \
70
+ -t 30s
71
+ ```
72
+
73
+ ### Exception Handling
74
+
75
+ Break on raised or uncaught exceptions:
76
+
77
+ ```bash
78
+ # Break on all raised exceptions
79
+ npx debug-run ./main.py \
80
+ -a python \
81
+ --break-on-exception raised \
82
+ --pretty \
83
+ -t 30s
84
+
85
+ # Break on uncaught exceptions only
86
+ npx debug-run ./main.py \
87
+ -a python \
88
+ --break-on-exception uncaught \
89
+ --pretty \
90
+ -t 30s
91
+ ```
92
+
93
+ ## Adapter Aliases
94
+
95
+ Both `-a python` and `-a debugpy` work identically:
96
+
97
+ ```bash
98
+ # These are equivalent
99
+ npx debug-run ./main.py -a python -b "main.py:10" --pretty
100
+ npx debug-run ./main.py -a debugpy -b "main.py:10" --pretty
101
+ ```
102
+
103
+ ## Sample Application
104
+
105
+ A sample Python application is included for testing:
106
+
107
+ ```bash
108
+ # Debug the sample app
109
+ npx debug-run samples/python/sample_app.py \
110
+ -a python \
111
+ -b "samples/python/sample_app.py:185" \
112
+ --pretty \
113
+ -t 30s
114
+ ```
115
+
116
+ ### With Expression Evaluation
117
+
118
+ ```bash
119
+ npx debug-run samples/python/sample_app.py \
120
+ -a python \
121
+ -b "samples/python/sample_app.py:188" \
122
+ -e "subtotal" \
123
+ -e "tax" \
124
+ -e "discount" \
125
+ -e "order.order_id" \
126
+ --pretty \
127
+ -t 30s
128
+ ```
129
+
130
+ ### Good Breakpoint Locations (Sample App)
131
+
132
+ | Line | Location | Description |
133
+ |------|----------|-------------|
134
+ | 185 | `process_order` | After variable setup, before loyalty points |
135
+ | 140 | `calculate_discount` | After discount rate calculation |
136
+ | 298 | `main` | Before processing first order |
137
+ | 178 | `process_order` | Inside inventory loop |
138
+
139
+ ## Trace Mode
140
+
141
+ Follow execution flow after hitting a breakpoint:
142
+
143
+ ```bash
144
+ # Basic trace
145
+ npx debug-run ./main.py \
146
+ -a python \
147
+ -b "src/processor.py:25" \
148
+ --trace \
149
+ --pretty
150
+
151
+ # Trace into function calls
152
+ npx debug-run ./main.py \
153
+ -a python \
154
+ -b "src/processor.py:25" \
155
+ --trace \
156
+ --trace-into \
157
+ --trace-limit 50 \
158
+ --pretty
159
+
160
+ # Trace with variable diffing
161
+ npx debug-run ./main.py \
162
+ -a python \
163
+ -b "src/processor.py:25" \
164
+ --trace \
165
+ --diff-vars \
166
+ --pretty
167
+ ```
168
+
169
+ ## Python-Specific Notes
170
+
171
+ ### Breakpoint Timing
172
+
173
+ Breakpoints are set AFTER launch for Python (debugpy's DAP flow differs from .NET). This is handled automatically by debug-run.
174
+
175
+ ### Dataclass Variables
176
+
177
+ Python dataclasses show a `special variables` section in locals containing class metadata. This is normal debugpy behavior. The actual instance fields are shown alongside.
178
+
179
+ ```json
180
+ {
181
+ "customer": {
182
+ "type": "Customer",
183
+ "value": {
184
+ "special variables": {...}, // Class metadata
185
+ "id": { "type": "str", "value": "CUST-001" },
186
+ "name": { "type": "str", "value": "Alice" },
187
+ "email": { "type": "str", "value": "alice@example.com" }
188
+ }
189
+ }
190
+ }
191
+ ```
192
+
193
+ ### justMyCode
194
+
195
+ By default, debug-run sets `justMyCode: false` to allow stepping into library code. The default Python debugger behavior only stops in user code.
196
+
197
+ ### Expression Syntax
198
+
199
+ Use Python syntax for expressions:
200
+
201
+ ```bash
202
+ # Python expressions
203
+ -e "len(items)"
204
+ -e "order.items[0].price"
205
+ -e "sum(item.quantity for item in order.items)"
206
+ -e "customer.loyalty_tier.value"
207
+ ```
208
+
209
+ ## Working with Virtual Environments
210
+
211
+ If your project uses a virtual environment, activate it before running debug-run:
212
+
213
+ ```bash
214
+ # Activate venv
215
+ source .venv/bin/activate # Linux/macOS
216
+ # or
217
+ .venv\Scripts\activate # Windows
218
+
219
+ # Then debug
220
+ npx debug-run ./main.py -a python -b "main.py:10" --pretty
221
+ ```
222
+
223
+ debug-run uses the active Python interpreter, which will have access to your virtual environment's packages.
224
+
225
+ ## Troubleshooting
226
+
227
+ | Issue | Solution |
228
+ |-------|----------|
229
+ | "debugpy not found" | Install VS Code Python extension or `pip install debugpy` |
230
+ | "python not found" | Ensure Python 3 is in PATH (`python3 --version`) |
231
+ | Variables show as "not defined" | Expression is evaluated BEFORE the line executes |
232
+ | Breakpoint not hitting | Check file path is correct and line has executable code |
233
+ | Timeout before breakpoint | Increase timeout with `-t 60s` or `-t 2m` |
234
+
235
+ ### Debug Adapter Communication
236
+
237
+ Enable verbose DAP logging to troubleshoot:
238
+
239
+ ```bash
240
+ DEBUG_DAP=1 npx debug-run ./main.py -a python -b "main.py:10" --pretty
241
+ ```
242
+
243
+ ### Verify debugpy Installation
244
+
245
+ ```bash
246
+ # Check if debugpy is importable
247
+ python3 -c "import debugpy; print(debugpy.__version__)"
248
+
249
+ # Check adapter detection
250
+ npx debug-run list-adapters
251
+ ```
252
+
253
+ ## Common Patterns
254
+
255
+ ### Debug a Flask/Django App
256
+
257
+ ```bash
258
+ # Flask
259
+ npx debug-run app.py \
260
+ -a python \
261
+ -b "app.py:25" \
262
+ --pretty \
263
+ -t 120s
264
+
265
+ # Django (using manage.py)
266
+ npx debug-run manage.py runserver \
267
+ -a python \
268
+ -b "myapp/views.py:42" \
269
+ --pretty \
270
+ -t 120s
271
+ ```
272
+
273
+ ### Debug with Arguments
274
+
275
+ ```bash
276
+ npx debug-run ./script.py -- --input data.json --verbose \
277
+ -a python \
278
+ -b "script.py:15" \
279
+ --pretty
280
+ ```
281
+
282
+ Arguments after `--` are passed to your Python script.