{"record":{"id":"81276ee446f4bf38","repo":"go-delve/delve","slug":"bug-invalid-pointer-v-81276e","errorCode":null,"errorMessage":"bug? invalid pointer: %#v","messagePattern":"bug\\? invalid pointer: %#v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"service/dap/command.go","lineNumber":177,"sourceCode":"\nfunc (s *Session) examineMemory(goid, frame int, argstr string) (string, error) {\n\targs, err := api.ParseExamineMemoryArg(argstr)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"bad arguments: %w\", err).Error(), nil\n\t}\n\n\tvar address uint64\n\n\tif args.IsExpr {\n\t\tval, err := s.debugger.EvalVariableInScope(int64(goid), frame, 0, args.Operand, s.loadConfig())\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\tswitch val.Kind {\n\t\tcase reflect.Pointer: // \"-x &myVar\" or \"-x myPtrVar\"\n\t\t\tif len(val.Children) < 1 {\n\t\t\t\treturn fmt.Errorf(\"bug? invalid pointer: %#v\", val).Error(), nil\n\t\t\t}\n\t\t\taddress = val.Children[0].Addr\n\n\t\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: // \"-x 0xc000079f20 + 8\" or -x 824634220320 + 8\n\t\t\tn, _ := constant.Int64Val(val.Value)\n\t\t\taddress = uint64(n)\n\t\tcase reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: // \"-x 0xc000079f20 + 8\" or -x 824634220320 + 8\n\t\t\taddress, _ = constant.Uint64Val(val.Value)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unsupported expression type: %s\", val.Kind).Error(), nil\n\t\t}\n\t} else {\n\t\taddress, err = strconv.ParseUint(args.Operand, 0, 64)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"convert address into uintptr type failed, %s\", err).Error(), nil\n\t\t}\n\t}\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/dap/command.go#L159-L195","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","solutions":["Verify the pointer expression is non-nil at the breakpoint before examining memory through it.","Pass the concrete address directly (without -x) if you already know it.","Increase the evaluation load config depth so pointer children are loaded, or dereference explicitly in the expression (e.g. -x *p)."],"exampleFix":"// before\nexamineMemory -x p            // p is nil\n// after\nexamineMemory 0xc000010000    // concrete address, or guard: if p != nil","handlingStrategy":"try-catch","validationCode":"// guard nil pointers before examineMemory -x\n// e.g. evaluate 'p == nil' first via an Evaluate request and skip if true\nif val.Kind == reflect.Pointer && len(val.Children) < 1 {\n\t// fall back to passing a concrete address without -x\n}","typeGuard":"func isResolvedPointer(val api.Variable) bool {\n\treturn val.Kind == reflect.Pointer && len(val.Children) >= 1 && val.Children[0].Addr != 0\n}","tryCatchPattern":"out, err := s.examineMemory(goid, frame, argstr)\nif err != nil {\n\tlog.Printf(\"pointer expression unresolved (%v); pass a concrete address instead\", err)\n\treturn \"\"\n}","preventionTips":["Check pointer non-nil before -x dereference","Dereference explicitly (*p) or pass the literal address","Avoid load configs that elide children of pointers"],"tags":["dap","memory-inspection","pointer","delve"],"backgroundTag":"nil-pointer-dereference","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}