{"record":{"id":"2be84f4070cfdfd7","repo":"go-delve/delve","slug":"could-not-read-d-bytes-from-address-x-v","errorCode":null,"errorMessage":"could not read %d bytes from address %#x: %v","messagePattern":"could not read (.+?) bytes from address %#x: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/mem.go","lineNumber":152,"sourceCode":"\tfor i := range pieces {\n\t\tpiece := &pieces[i]\n\t\tswitch piece.Kind {\n\t\tcase op.RegPiece:\n\t\t\treg := regs.Bytes(piece.Val)\n\t\t\tif piece.Size == 0 && i == len(pieces)-1 {\n\t\t\t\tpiece.Size = len(reg)\n\t\t\t}\n\t\t\tif piece.Size > len(reg) {\n\t\t\t\tif regs.FloatLoadError != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"could not read %d bytes from register %d (size: %d), also error loading floating point registers: %v\", piece.Size, piece.Val, len(reg), regs.FloatLoadError)\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"could not read %d bytes from register %d (size: %d)\", piece.Size, piece.Val, len(reg))\n\t\t\t}\n\t\t\tcmem.data = append(cmem.data, reg[:piece.Size]...)\n\t\tcase op.AddrPiece:\n\t\t\tbuf := make([]byte, piece.Size)\n\t\t\tif _, err := mem.ReadMemory(buf, piece.Val); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"could not read %d bytes from address %#x: %v\", piece.Size, piece.Val, err)\n\t\t\t}\n\t\t\tcmem.data = append(cmem.data, buf...)\n\t\tcase op.ImmPiece:\n\t\t\tbuf := piece.Bytes\n\t\t\tif buf == nil {\n\t\t\t\tsz := max(piece.Size, 8)\n\t\t\t\tif piece.Size == 0 && i == len(pieces)-1 {\n\t\t\t\t\tpiece.Size = arch.PtrSize() // DWARF doesn't say what this should be\n\t\t\t\t}\n\t\t\t\tbuf = make([]byte, sz)\n\t\t\t\tbinary.LittleEndian.PutUint64(buf, piece.Val)\n\t\t\t}\n\t\t\tcmem.data = append(cmem.data, buf[:piece.Size]...)\n\t\tdefault:\n\t\t\tpanic(\"unsupported piece kind\")\n\t\t}\n\t}\n\tpaddingBytes := int(size) - len(cmem.data)","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/mem.go#L134-L170","documentation":"newCompositeMemory failed while reading the address-based piece of a DWARF location expression (op.AddrPiece): Reading piece.Size bytes at address piece.Val from the target memory failed. The wrapped error (from MemoryRead) carries the real cause, typically an unreadable/unmapped address.","triggerScenarios":"CreateCompositeMemory on a location expression containing DW_OP_addr pieces pointing to memory that cannot be read — unmapped pages, freed heap, invalid stack address, or a detached/dead process.","commonSituations":"Evaluating a variable after its stack frame returned (address invalid); inspecting memory of a process that exited; address-space layout differences between core dump and live process; corrupt optimized code locations.","solutions":["Read the wrapped %v cause — if it is an out-of-bounds/unmapped read, the variable's address is stale; move to a frame where the variable is live.","Stop the process at a breakpoint before evaluating variables that live in memory.","For core dumps, ensure the core covers the region (full core, not truncated).","Re-check the binary matches the process/core (PIE base mismatch yields bogus addresses)."],"exampleFix":"// before: evaluating after function returned\nstate := <-continueCh\ngo eval(\"localVar\")   // AddrPiece points to dead frame\n// after: evaluate while stopped inside the frame\ngo eval(\"localVar\")   // while breakpoint in the same frame is hit","handlingStrategy":"try-catch","validationCode":"// Validate the piece address is in a mapped region before reading\nfor _, m := range procMemMap {\n    if piece.Val >= m.Start && piece.Val+uint64(piece.Size) <= m.End { return nil }\n}\nreturn fmt.Errorf(\"address %#x not mapped\", piece.Val)","typeGuard":"func addressMapped(addr uint64, size int, regions []MemoryRegion) bool {\n    for _, r := range regions { if addr >= r.Start && addr+uint64(size) <= r.End { return true } }\n    return false\n}","tryCatchPattern":"v, err := scope.EvalVariable(name)\nif err != nil && strings.Contains(err.Error(), \"could not read \") && strings.Contains(err.Error(), \"address 0x\") {\n    return fmt.Errorf(\"variable %s points to unreadable memory (stale frame?), stopped frame required: %w\", name, err)\n}","preventionTips":["Evaluate variables only while the target is stopped in a frame where they are live.","Ensure core dumps are full cores covering the relevant regions.","Verify the binary under debug matches the running process or core (PIE load addresses).","Check the wrapped cause (%v) — it distinguishes unmapped pages from detached processes."],"tags":["dwarf","memory-read","debugging","delve"],"backgroundTag":"unreadable-memory-address","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}