go-delve/delve · error

type assertion failed

Error message

type assertion failed

What it means

In Reader.AddrFor, the DWARF entry found by name is expected to have a DW_AT_location attribute holding a []byte expression. If the attribute exists but its value is not a byte slice (e.g., it is a block/list form the parser returned as another type, or a location list), the type assertion fails and this generic error is returned.

Source

Thrown at pkg/dwarf/reader/reader.go:44

}

// SeekToEntry moves the reader to an arbitrary entry.
func (reader *Reader) SeekToEntry(entry *dwarf.Entry) error {
	reader.Seek(entry.Offset)
	// Consume the current entry so .Next works as intended
	_, err := reader.Next()
	return err
}

// AddrFor returns the address for the named entry.
func (reader *Reader) AddrFor(name string, staticBase uint64, ptrSize int) (uint64, error) {
	entry, err := reader.FindEntryNamed(name, false)
	if err != nil {
		return 0, err
	}
	instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
	if !ok {
		return 0, errors.New("type assertion failed")
	}
	addr, _, err := op.ExecuteStackProgram(op.DwarfRegisters{StaticBase: staticBase}, instructions, ptrSize, nil)
	if err != nil {
		return 0, err
	}
	return uint64(addr), nil
}

var ErrTypeNotFound = errors.New("no type entry found, use 'types' for a list of valid types")

// SeekToType moves the reader to the type specified by the entry,
// optionally resolving typedefs and pointer types. If the reader is set
// to a struct type the NextMemberVariable call can be used to walk all member data.
func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resolvePointerTypes bool) (*dwarf.Entry, error) {
	offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)
	if !ok {
		return nil, errors.New("entry does not have a type attribute")
	}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Use InstructionsForEntry/InstructionsForEntryNamed only for entries with static expressions
  2. For optimized builds, evaluate locations through proc's variable evaluation which handles location lists
  3. Check the entry's attribute form with the DWARF dumper before calling AddrFor
Defensive patterns

Strategy: type-guard

Type guard

func hasStaticLocation(e *dwarf.Entry) bool {
    _, ok := e.Val(dwarf.AttrLocation).([]byte)
    return ok
}

Prevention

When it happens

Trigger: reader.AddrFor(name) on an entry whose AttrLocation value is not []byte — for instance a location list (loclistptr) rather than a single expression.

Common situations: Variables with dynamic location lists (optimized code), querying a non-variable entry that happens to have a location attribute, or DWARF version differences changing attribute form.

Related errors


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