go-delve/delve · error

bad address size

Error message

bad address size

What it means

The DWARF2 loclist reader (pkg/dwarf/loclist/dwarf2_loclist.go) panics with "bad address size" when the address size used to read a loclist entry's low/high PC is neither 4 nor 8 bytes. Address sizes must match the target architecture (32- or 64-bit); any other value means the DWARF metadata (address_size in the CU header / ptrSz) is wrong or corrupted. This is a fail-fast guard against nonsensical metadata.

Source

Thrown at pkg/dwarf/loclist/dwarf2_loclist.go:93

func (rdr *Dwarf2Reader) read(sz int) []byte {
	r := rdr.data[rdr.cur : rdr.cur+sz]
	rdr.cur += sz
	return r
}

func (rdr *Dwarf2Reader) oneAddr() uint64 {
	switch rdr.ptrSz {
	case 4:
		addr := binary.LittleEndian.Uint32(rdr.read(rdr.ptrSz))
		if addr == ^uint32(0) {
			return ^uint64(0)
		}
		return uint64(addr)
	case 8:
		addr := binary.LittleEndian.Uint64(rdr.read(rdr.ptrSz))
		return addr
	default:
		panic("bad address size")
	}
}

// Entry represents a single entry in the loclist section.
type Entry struct {
	LowPC, HighPC uint64
	Instr         []byte
}

// BaseAddressSelection returns true if entry.highpc should
// be used as the base address for subsequent entries.
func (e *Entry) BaseAddressSelection() bool {
	return e.LowPC == ^uint64(0)
}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Confirm the ELF header's architecture matches the DWARF address_size in the compile unit; debug the correct target binary.
  2. Inspect the CU header's address_size field for corruption; re-obtain or rebuild the binary with debug info.
  3. Check where rdr.ptrSz/addrSize is initialized in Delve's bininfo and that the correct architecture is detected.
  4. If reading untrusted files, wrap loclist parsing in recover() and return a descriptive error.

Example fix

// before
default:
	panic("bad address size")
// after
default:
	return 0, fmt.Errorf("unsupported DWARF address size %d", size) // propagate instead of panic
Defensive patterns

Strategy: validation

Validate before calling

// Go: validate address size before reading loclist entries
if addrSize != 4 && addrSize != 8 {
	return fmt.Errorf("unsupported address size %d", addrSize)
}

Prevention

When it happens

Trigger: Calling loclist Next() (via oneAddr) when rdr.addrSize (derived from CU address_size or ptrSz) has a value other than 4 or 8 — e.g. corrupted address_size field, wrong binaryinfo setup, or foreign/arch-mismatched DWARF.

Common situations: Debugging a binary compiled for a different architecture than assumed; corrupted DWARF sections in core dumps; toolchains emitting nonstandard address_size values.

Related errors


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