go-delve/delve · error
invalid typecast for Dwarf instructions
Error message
invalid typecast for Dwarf instructions
What it means
In Reader.InstructionsForEntryNamed, the located entry's location attribute (AttrLocation or AttrDataMemberLoc depending on tag) must be a []byte DWARF expression. Any other value type yields this error, meaning the entry cannot provide executable location instructions.
Source
Thrown at pkg/dwarf/reader/reader.go:190
return entry, nil
}
return nil, fmt.Errorf("could not find symbol value for %s", name)
}
func (reader *Reader) InstructionsForEntryNamed(name string, member bool) ([]byte, error) {
entry, err := reader.FindEntryNamed(name, member)
if err != nil {
return nil, err
}
var attr dwarf.Attr
if member {
attr = dwarf.AttrDataMemberLoc
} else {
attr = dwarf.AttrLocation
}
instr, ok := entry.Val(attr).([]byte)
if !ok {
return nil, errors.New("invalid typecast for Dwarf instructions")
}
return instr, nil
}
func (reader *Reader) InstructionsForEntry(entry *dwarf.Entry) ([]byte, error) {
if entry.Tag == dwarf.TagMember {
instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte)
if !ok {
return nil, errors.New("member data has no data member location attribute")
}
// clone slice to prevent stomping on the dwarf data
return append([]byte{}, instructions...), nil
}
// non-member
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok {
return nil, errors.New("entry has no location attribute")View on GitHub (pinned to a23773e6c3)
Solutions
- Use InstructionsForEntry on an entry known to carry a static expression
- Fall back to full variable evaluation through proc when the attribute is a location list
- Dump the entry's attributes to confirm the form before extracting instructions
Defensive patterns
Strategy: type-guard
Type guard
func hasByteLocation(e *dwarf.Entry) bool {
attr := dwarf.AttrLocation
if e.Tag == dwarf.TagMember { attr = dwarf.AttrDataMemberLoc }
_, ok := e.Val(attr).([]byte)
return ok
} Prevention
- Only call InstructionsForEntryNamed on entries with expression-form attributes
- Prefer InstructionsForEntry with a validated entry
- Handle loclist/constant forms separately
When it happens
Trigger: InstructionsForEntryNamed on an entry whose AttrLocation/AttrDataMemberLoc is nil or a non-[]byte form (e.g., location list, constant), or on an entry lacking the attribute altogether.
Common situations: Querying variables that are in registers via loclists, constant-valued enum members with AttrConstValue instead of member location, or optimized builds where Go emits location lists.
Related errors
- type assertion failed
- ErrStackUnderflow
- ErrStackIndexOutOfBounds
- ErrMemoryReadUnavailable
- empty OP stack
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/afbf6df8acc1dd45.
Report an issue: GitHub.