go-delve/delve · error

expected argument after -fmt

Error message

expected argument after -fmt

What it means

ParseExamineMemoryArg parses arguments of the `examinemem`/`x` command. The -fmt flag requires a following format argument; when nextArg() returns an empty string (flag is last or followed by nothing), parsing fails with 'expected argument after -fmt'. The format may be 'raw' or a printf-style code (oct, x, bin, etc.).

Source

Thrown at service/api/command.go:216

			arg := args[0]
			args = args[1:]
			if arg != "" {
				return arg
			}
		}
		return ""
	}

loop:
	for {
		switch cmd := nextArg(); cmd {
		case "":
			// no more arguments
			break loop
		case "-fmt":
			arg := nextArg()
			if arg == "" {
				return nil, errors.New("expected argument after -fmt")
			}
			if arg == "raw" {
				out.RawOut = true
			} else {
				fmtMapToPriFmt := map[string]byte{
					"oct":         'o',
					"octal":       'o',
					"hex":         'x',
					"hexadecimal": 'x',
					"dec":         'd',
					"decimal":     'd',
					"bin":         'b',
					"binary":      'b',
				}
				out.Format, ok = fmtMapToPriFmt[arg]
				if !ok {
					return nil, fmt.Errorf("%q is not a valid format", arg)
				}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Supply a format after -fmt: x -fmt x 0xc00010000 (hex) or x -fmt raw ... for raw output
  2. Valid formats: oct, x, bin, and other printf-style codes; use 'raw' for unformatted bytes
  3. Ensure any variable providing the format is non-empty before composing the command

Example fix

// before
out, err := api.ParseExamineMemoryArg([]string{"-fmt", "0xc000010000"})

// after
out, err := api.ParseExamineMemoryArg([]string{"-fmt", "x", "0xc000010000"})
Defensive patterns

Strategy: validation

Validate before calling

# compose and sanity-check args before calling ParseExamineMemoryArg
args := []string{"-fmt", "x", "0xc000010000"}
for i, a := range args {
    if a == "-fmt" && (i+1 >= len(args) || args[i+1] == "") {
        panic("-fmt requires raw or a printf-style format")
    }
}

Type guard

func flagHasArg(args []string, flag string) bool {
    for i, a := range args {
        if a == flag {
            return i+1 < len(args) && args[i+1] != ""
        }
    }
    return true // flag absent
}

Prevention

When it happens

Trigger: Calling `x -fmt 0x...` where the address follows immediately without a format value, or invoking the API ParseExamineMemoryArg with args ending in "-fmt". Also when an empty variable is expanded after -fmt so nextArg() yields "".

Common situations: Users forgetting the format code (`x -fmt 0xc000010000` instead of `x -fmt x 0xc000010000`); shell scripts with unset format variables; IDE/command builders appending flags conditionally and leaving -fmt dangling.

Related errors


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