Fix debug program args after -- - #18
Conversation
Cobra was validating arguments after the `--` separator as positional args for `dap debug`, so commands like `dap debug script.py -- -i espoo` failed before the debug session started. Handle validation and script selection using only the arguments before `--`, and forward the remaining arguments to the debugged program as `ProgramArgs`. Add an end-to-end regression test covering a Python script that requires a forwarded program argument so this parsing path stays exercised.
Review Summary by QodoFix debug command to properly handle program arguments after --
WalkthroughsDescription• Fix argument parsing to handle program args after -- separator • Validate only pre-separator args, forward post-separator args to debugged program • Add end-to-end regression test for Python script with forwarded arguments Diagramflowchart LR
A["CLI args with --"] --> B["Split at -- separator"]
B --> C["Validate pre-separator args"]
B --> D["Forward post-separator args"]
C --> E["Set script path"]
D --> F["Set ProgramArgs"]
E --> G["Start debug session"]
F --> G
File Changes1. cli.go
|
Code Review by Qodo
1. Breakpoint before assignment
|
| cmd := exec.Command(env.binary, | ||
| "--socket", env.socketPath, | ||
| "debug", scriptPath, | ||
| "--break", scriptPath+":6", | ||
| "--", | ||
| "example-value", | ||
| ) | ||
| cmd.Dir = projectRoot(t) | ||
| out, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| t.Fatalf("debug with program args failed: %v\n%s", err, out) | ||
| } | ||
|
|
||
| if !strings.Contains(string(out), "Stopped: breakpoint") { | ||
| t.Errorf("expected breakpoint stop, got:\n%s", out) | ||
| } | ||
| if !strings.Contains(string(out), "value (str) = 'example-value'") { | ||
| t.Errorf("expected parsed CLI arg in locals, got:\n%s", out) | ||
| } |
There was a problem hiding this comment.
1. Breakpoint before assignment 🐞 Bug ✓ Correctness
TestE2E_DebugPython_WithProgramArgs sets a breakpoint on the same line where value is assigned, but then asserts value is present in locals at the breakpoint stop; locals are collected at the stop location before executing the current line, so value will not exist yet.
Agent Prompt
### Issue description
`TestE2E_DebugPython_WithProgramArgs` breaks on the `value = args.value` line and then asserts `value` exists in locals. At a line breakpoint, execution typically stops before that assignment runs, so `value` won’t be in locals.
### Issue Context
The test intends to verify that arguments after `--` are forwarded to the debugged program and observable in debugger context.
### Fix Focus Areas
- e2e_test.go[200-239]
### Suggested fix
Change the breakpoint to the next line (the `print(value)` line) so `value` is assigned before locals are collected, e.g. change `--break scriptPath+":6"` to `--break scriptPath+":7"`. Alternatively, keep the breakpoint at `:6` but add a subsequent `step` command and assert on that output instead.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Independent confirmation, verified 2026-08-03 on both Root cause is exactly what this PR describes: This PR is still unmerged as of today, so Args: func(cmd *cobra.Command, args []string) error {
if dashIdx := cmd.ArgsLenAtDash(); dashIdx >= 0 {
args = args[:dashIdx]
}
if len(args) > 1 {
return fmt.Errorf("accepts at most 1 arg(s), received %d", len(args))
}
return nil
},Verified end-to-end: with that patch I ran a full lldb-dap session against a Rust test binary ( |
Summary
This fixes
dap debugwhen the debugged program needs its own CLI arguments.Before this change, Cobra treated arguments after
--as extra positional arguments fordap debugitself. That caused commands like:dap debug script.py --break script.py:10 -- valueto fail during CLI argument validation instead of starting a debug session and forwarding
valueto the target script.Root Cause
debugusedcobra.MaximumNArgs(1), which counted arguments after--toward the command's positional arg limit.The command also reconstructed forwarded program args from a different slice than the one used for validation, which made the parsing logic brittle around the separator.
Fix
--ProgramArgsTests
go test ./...passes locallydebugpyis installed