go-delve/delve · error
empty OP stack
Error message
empty OP stack
What it means
A non-sentinel error created in ExecuteStackProgram when the DWARF expression finished without leaving any value on the stack, so there is no result to return. The function needs at least one final stack value to produce an address or confirm a piece list.
Source
Thrown at pkg/dwarf/op/op.go:101
if !ok {
return 0, nil, fmt.Errorf("invalid instruction %#v", opcode)
}
err = fn(opcode, ctxt)
if err != nil {
return 0, nil, err
}
}
if ctxt.pieces != nil {
if len(ctxt.pieces) == 1 && ctxt.pieces[0].Kind == RegPiece {
return int64(regs.Uint64Val(ctxt.pieces[0].Val)), ctxt.pieces, nil
}
return 0, ctxt.pieces, nil
}
if len(ctxt.stack) == 0 {
return 0, nil, errors.New("empty OP stack")
}
return ctxt.stack[len(ctxt.stack)-1], nil, nil
}
// PrettyPrint prints the DWARF stack program instructions to `out`.
func PrettyPrint(out io.Writer, instructions []byte, regnumToName func(uint64) string) {
in := bytes.NewBuffer(instructions)
for {
opcode, err := in.ReadByte()
if err != nil {
break
}
op := Opcode(opcode)
if name, hasname := opcodeName[op]; hasname {
io.WriteString(out, name)
if regnumToName != nil {View on GitHub (pinned to a23773e6c3)
Solutions
- Inspect the DWARF attribute that produced the instruction bytes (objdump --dwarf=info) for emptiness or truncation
- Recompile the binary to regenerate correct debug info
- Guard the call site: treat an empty-result error as 'no location available' rather than retrying
Defensive patterns
Strategy: try-catch
Validate before calling
if len(instr) == 0 { return errors.New("no location expression") } Try / catch
_, _, err := op.ExecuteStackProgram(...)
if err != nil && strings.Contains(err.Error(), "empty OP stack") { /* no result value */ } Prevention
- Check that the DWARF attribute is non-empty before executing
- Prefer higher-level variable evaluation APIs that handle empty locations
When it happens
Trigger: op.ExecuteStackProgram executed an expression whose opcode stream consumed all stack values (e.g. ends with drop-like operations) or is effectively empty, leaving len(ctxt.stack)==0 at the end.
Common situations: Empty or truncated location attribute bytes in DWARF entries, expression streams mis-parsed due to wrong offset, or expressions designed for composite location results that the evaluator path does not expect.
Related errors
- ErrStackUnderflow
- ErrStackIndexOutOfBounds
- ErrMemoryReadUnavailable
- 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/aa6031be5af02bbb.
Report an issue: GitHub.