go-delve/delve · error

bad arguments: %w

Error message

bad arguments: %w

What it means

examineMemory in the DAP session wraps any error returned by api.ParseExamineMemoryArg with the prefix 'bad arguments:'. It indicates the -x/-fmt/-count option string supplied to the examineMemory DAP command failed parsing; the underlying cause (e.g. invalid format or unknown option) follows the prefix.

Source

Thrown at service/dap/command.go:163

		if idx := strings.Index(h, "\n"); idx >= 0 {
			h = h[:idx]
		}
		if len(cmd.aliases) > 1 {
			fmt.Fprintf(&buf, "    dlv %s (alias: %s) \t %s\n", cmd.aliases[0], strings.Join(cmd.aliases[1:], " | "), h)
		} else {
			fmt.Fprintf(&buf, "    dlv %s \t %s\n", cmd.aliases[0], h)
		}
	}

	fmt.Fprintln(&buf)
	fmt.Fprintln(&buf, "Type 'dlv help' followed by a command for full documentation.")
	return buf.String(), nil
}

func (s *Session) examineMemory(goid, frame int, argstr string) (string, error) {
	args, err := api.ParseExamineMemoryArg(argstr)
	if err != nil {
		return fmt.Errorf("bad arguments: %w", err).Error(), nil
	}

	var address uint64

	if args.IsExpr {
		val, err := s.debugger.EvalVariableInScope(int64(goid), frame, 0, args.Operand, s.loadConfig())
		if err != nil {
			return "", err
		}

		switch val.Kind {
		case reflect.Pointer: // "-x &myVar" or "-x myPtrVar"
			if len(val.Children) < 1 {
				return fmt.Errorf("bug? invalid pointer: %#v", val).Error(), nil
			}
			address = val.Children[0].Addr

		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: // "-x 0xc000079f20 + 8" or -x 824634220320 + 8

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Read the wrapped cause after 'bad arguments:' and fix that specific option (format name, flag spelling, count value).
  2. Use documented options only: -fmt/-format, -count/-len, -x.
  3. Validate the option string client-side before sending the DAP request.

Example fix

// before
await session.customRequest("examineMemory", {argstr: "-fmt float 0xc000010000"})
// after
await session.customRequest("examineMemory", {argstr: "-fmt hex 0xc000010000"})
Defensive patterns

Strategy: validation

Validate before calling

var validOpts = map[string]bool{"-fmt": true, "-format": true, "-count": true, "-len": true, "-x": true}
func argsLookValid(argstr string) bool {
	for _, f := range strings.Fields(argstr) {
		if strings.HasPrefix(f, "-") && !validOpts[f] { return false }
	}
	return true
}

Try / catch

out, err := s.examineMemory(goid, frame, argstr)
if err != nil || strings.HasPrefix(out, "bad arguments:") {
	log.Printf("examine-memory args rejected: %s", out)
}

Prevention

When it happens

Trigger: Sending a DAP REPL or custom 'examineMemory' request whose argstr contains a malformed option string, e.g. argstr="-fmt float 0xc000010000" or an empty/-only option string.

Common situations: IDE clients constructing the option string programmatically with wrong flags; user typos in a debug console; API version changes to accepted option names.

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/2aa54cff079b1a07. Report an issue: GitHub.