go-delve/delve · error
ErrStackIndexOutOfBounds
ErrStackIndexOutOfBounds
Error message
DWARF stack index out of bounds
What it means
ErrStackIndexOutOfBounds is a sentinel error returned when a DWARF expression opcode references a stack slot that does not exist, e.g. the pick opcode addressing beyond the current stack depth. Like ErrStackUnderflow it is defined as a public sentinel in pkg/dwarf/op and propagated by ExecuteStackProgram.
Source
Thrown at pkg/dwarf/op/op.go:54
type Piece struct {
Size int
Kind PieceKind
Val uint64
Bytes []byte
}
// PieceKind describes the kind of a piece.
type PieceKind uint8
const (
AddrPiece PieceKind = iota // The piece is stored in memory, Val is the address
RegPiece // The piece is stored in a register, Val is the register number
ImmPiece // The piece is an immediate value, Val or Bytes is the value
)
var (
ErrStackUnderflow = errors.New("DWARF stack underflow")
ErrStackIndexOutOfBounds = errors.New("DWARF stack index out of bounds")
ErrMemoryReadUnavailable = errors.New("memory read unavailable")
)
const arbitraryExecutionLimitFactor = 10
// ExecuteStackProgram executes a DWARF location expression and returns
// either an address (int64), or a slice of Pieces for location expressions
// that don't evaluate to an address (such as register and composite expressions).
func ExecuteStackProgram(regs DwarfRegisters, instructions []byte, ptrSize int, readMemory ReadMemoryFunc) (int64, []Piece, error) {
ctxt := &context{
buf: bytes.NewBuffer(instructions),
prog: instructions,
stack: make([]int64, 0, 3),
DwarfRegisters: regs,
ptrSize: ptrSize,
readMemory: readMemory,
}
View on GitHub (pinned to a23773e6c3)
Solutions
- Recompile the target binary with a current toolchain to regenerate valid DWARF
- Validate that the pick index in the expression is < current stack depth before executing custom expressions
- Treat the variable/expression as unreadable when errors.Is(err, op.ErrStackIndexOutOfBounds)
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check pick depth if you generate expressions yourself
if pickIndex >= currentStackDepth { return errors.New("pick index exceeds stack depth") } Try / catch
if errors.Is(err, op.ErrStackIndexOutOfBounds) { /* treat as unreadable expression */ } Prevention
- Validate generated DWARF expression streams against a linter/dumper
- Rebuild binaries when DWARF parse errors appear
- Avoid patching expression bytes in place
When it happens
Trigger: Executing a DWARF expression containing a pick opcode with an index equal to or greater than the number of values currently on the expression stack.
Common situations: Badly generated DWARF (compiler bug), corrupted debug sections, or reusing/patching expressions that no longer match the emitted stack layout.
Related errors
- ErrStackUnderflow
- ErrMemoryReadUnavailable
- empty OP stack
- could not retrieve CFA for current PC
- type assertion failed
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/8c3c1c40f2bd1ec0.
Report an issue: GitHub.