go-delve/delve · error
couldn't read pointer: %w
Error message
couldn't read pointer: %w
What it means
Thrown by evalPointerDeref after xev.loadPtr() fails to read the pointed-to memory from the debuggee: the variable's Unreadable field is set and the pointer's constant value is 0, so the failure is a nil-pointer dereference reported with the underlying read error wrapped via %w. Delve wraps the memory-read error so both the cause (nil address) and the original read failure are visible.
Source
Thrown at pkg/proc/eval.go:2327
return
}
if xev == nilVariable {
stack.err = errors.New("nil can not be dereferenced")
return
}
if len(xev.Children) == 1 {
// this branch is here to support pointers constructed with typecasts from ints
xev.Children[0].OnlyAddr = false
stack.push(&(xev.Children[0]))
return
}
xev.loadPtr()
if xev.Unreadable != nil {
val, ok := constant.Uint64Val(xev.Value)
if ok && val == 0 {
stack.err = fmt.Errorf("couldn't read pointer: %w", xev.Unreadable)
return
}
}
rv := &xev.Children[0]
if rv.Addr == 0 {
stack.err = errors.New("nil pointer dereference")
return
}
stack.push(rv)
}
// Evaluates expressions &<subexpr>
func (scope *EvalScope) evalAddrOf(op *evalop.AddrOf, stack *evalStack) {
xev := stack.pop()
if xev.Addr == 0 || xev.DwarfType == nil {
stack.err = fmt.Errorf("can not take address of %q", astutil.ExprToString(op.Node.X))
return
}View on GitHub (pinned to a23773e6c3)
Solutions
- Print the pointer itself (`print p`) to confirm it is nil before dereferencing.
- Step forward in execution until the pointer is assigned a valid address, then evaluate `*p`.
- Use conditional breakpoints or `if p != nil` checks in the inspected code to avoid reaching a state with nil pointers.
- If the pointer is non-nil but still unreadable, verify the memory region is valid and the binary/debug info match the running process.
Example fix
// before (dlv) print *p couldn't read pointer: invalid address 0x0 // after: check first (dlv) print p // nil (dlv) break main.go:42 // stop after p = &x (dlv) continue (dlv) print *p
Defensive patterns
Strategy: validation
Validate before calling
// Check the pointer before dereferencing:
(dlv) print p // nil -> do not evaluate *p
(dlv) print p != nil // use as a breakpoint condition guard
// In program code: if p != nil { use(*p) } Type guard
func validPointer[T any](p *T) bool { return p != nil } Prevention
- Print the pointer before dereferencing it.
- Place breakpoints after pointer assignment.
- Guard breakpoint conditions with `p != nil &&`.
When it happens
Trigger: Evaluating `*p` where p is a nil pointer (address 0): loadPtr attempts to read at address 0, the read fails, and since the constant value of the pointer is 0 the error is reported as `couldn't read pointer: <read error>` rather than continuing to inspect children.
Common situations: Inspecting a pointer field before it was assigned, a function returned nil, an optional field was not populated, or a struct pointer from a map/interface is nil during a panic investigation.
Related errors
- parent pointer unreadable: %w
- nil can not be dereferenced
- nil pointer dereference
- nil pointer dereference
- expression %q (%s) does not support indexing
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/47298b69b3bd270e.
Report an issue: GitHub.