go-delve/delve · error

Malformed breakpoint location, no line offset specified

Error message

Malformed breakpoint location, no line offset specified

What it means

When a breakpoint location spec reduces to exactly one file (e.g. b file.go: form or a bare file name), Find needs a line number (loc.LineOffset). A negative LineOffset means no line offset was supplied, so Delve cannot compute an address and returns this malformed-location error.

Source

Thrown at pkg/locspec/locations.go:427

		// expression that the user forgot to prefix with '*', try treating it as
		// such.
		addrSpec := &AddrLocationSpec{AddrExpr: locStr}
		locs, subst, err := addrSpec.Find(t, processArgs, scope, locStr, includeNonExecutableLines, nil)
		if err != nil {
			return nil, "", &ErrLocationNotFound{Spec: locStr}
		}
		return locs, subst, nil
	} else if matching > 1 {
		return nil, "", AmbiguousLocationError{Location: locStr, CandidatesString: append(candidateFiles, candidateFuncs...)}
	}

	// len(candidateFiles) + len(candidateFuncs) == 1
	var addrs []uint64
	var err error
	if len(candidateFiles) == 1 {
		if loc.LineOffset < 0 {
			//lint:ignore ST1005 backwards compatibility
			return nil, "", errors.New("Malformed breakpoint location, no line offset specified")
		}
		addrs, err = proc.FindFileLocation(t, candidateFiles[0], loc.LineOffset)
		if includeNonExecutableLines {
			if _, isCouldNotFindLine := err.(*proc.ErrCouldNotFindLine); isCouldNotFindLine {
				return []api.Location{{File: candidateFiles[0], Line: loc.LineOffset}}, "", nil
			}
		}
	} else { // len(candidateFuncs) == 1
		addrs, err = proc.FindFunctionLocation(t, candidateFuncs[0], loc.LineOffset)
	}

	if err != nil {
		return nil, "", err
	}
	return []api.Location{addressesToLocation(addrs)}, "", nil
}

func (loc *NormalLocationSpec) findFuncCandidates(bi *proc.BinaryInfo, limit int) []string {

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Include a line number in the location string, e.g. b main.go:42
  2. If using the API, set LineOffset to a valid line (>= 0) on the location spec before calling Find
  3. Use a function-name breakpoint (e.g. b main.main) if you want the entry point instead of a line

Example fix

// before
dlv> b main.go
// after
dlv> b main.go:42
Defensive patterns

Strategy: validation

Validate before calling

if loc.LineOffset < 0 {
    return errors.New("file-only breakpoint requires a line number: use file.go:<line>")
}
locs, subst, err := loc.Find(t, funcs, scope, locStr, inclNonExec, dirs)

Try / catch

locs, _, err := loc.Find(t, funcs, scope, locStr, false, nil)
if err != nil && strings.Contains(err.Error(), "no line offset") {
    return fmt.Errorf("add a line number to the breakpoint location: %w", err)
}

Prevention

When it happens

Trigger: Calling Find with a location spec that resolved to a single candidate file but with LineOffset < 0 — i.e. a spec like "main.go" or ":" without an explicit line number.

Common situations: Typing b main.go without a line number in the CLI; constructing a location spec programmatically and forgetting to set LineOffset (default -1).

Understand the failure class

Related errors


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