go-delve/delve · warning

bug? invalid pointer: %#v

Error message

bug? invalid pointer: %#v

What it means

When the -x expression form of examineMemory evaluates to a pointer-kind variable, examineMemory expects the evaluated Variable to carry at least one child (the pointed-to value whose Addr is the target address). An empty Children slice means the debugger could not resolve the pointer to a concrete address, and the session reports it as a probable bug since well-formed pointer evaluations always have a child.

Source

Thrown at service/dap/command.go:177

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
			n, _ := constant.Int64Val(val.Value)
			address = uint64(n)
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: // "-x 0xc000079f20 + 8" or -x 824634220320 + 8
			address, _ = constant.Uint64Val(val.Value)
		default:
			return fmt.Errorf("unsupported expression type: %s", val.Kind).Error(), nil
		}
	} else {
		address, err = strconv.ParseUint(args.Operand, 0, 64)
		if err != nil {
			return fmt.Errorf("convert address into uintptr type failed, %s", err).Error(), nil
		}
	}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Verify the pointer expression is non-nil at the breakpoint before examining memory through it.
  2. Pass the concrete address directly (without -x) if you already know it.
  3. Increase the evaluation load config depth so pointer children are loaded, or dereference explicitly in the expression (e.g. -x *p).

Example fix

// before
examineMemory -x p            // p is nil
// after
examineMemory 0xc000010000    // concrete address, or guard: if p != nil
Defensive patterns

Strategy: try-catch

Validate before calling

// guard nil pointers before examineMemory -x
// e.g. evaluate 'p == nil' first via an Evaluate request and skip if true
if val.Kind == reflect.Pointer && len(val.Children) < 1 {
	// fall back to passing a concrete address without -x
}

Type guard

func isResolvedPointer(val api.Variable) bool {
	return val.Kind == reflect.Pointer && len(val.Children) >= 1 && val.Children[0].Addr != 0
}

Try / catch

out, err := s.examineMemory(goid, frame, argstr)
if err != nil {
	log.Printf("pointer expression unresolved (%v); pass a concrete address instead", err)
	return ""
}

Prevention

When it happens

Trigger: Calling examineMemory with -x pointing at a nil pointer, an unresolved/opaque pointer variable, or a pointer whose children were elided by the load configuration (e.g. deep load limits), e.g. '-x myNilPtr'.

Common situations: Dereferencing a nil pointer variable; evaluating a pointer whose target memory is unreadable; using a load config that skips children; stale expressions after the program moved.

Related errors


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