Repository: go-delve/delve

Issue:
proc: telemetry report: index error in fncallPeek while resuming execution of a call injection
```
#!stacks
"goPanicIndex" && "proc.(*evalStack).fncallPeek"
```
Issue created by [stacks](https://pkg.go.dev/golang.org/x/telemetry/cmd/stacks).

This stack `5cV75w` was [reported by telemetry](https://telemetry.go.dev/data/2025-08-03):

- `delve/bug`
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp.func1:+3`](https://github.com/go-delve/delve/blob/v1.25.0/pkg/proc/eval.go#L1054)
- [`runtime.gopanic:+50`](https://cs.opensource.google/go/go/+/go1.24.5:src/runtime/panic.go;l=792)
- [`runtime.goPanicIndex:+2`](https://cs.opensource.google/go/go/+/go1.24.5:src/runtime/panic.go;l=115)
- `github.com/go-delve/delve/pkg/proc.(*evalStack).fncallPeek:=873`
- [`github.com/go-delve/delve/pkg/proc.(*EvalScope).evalCallInjectionSetTarget:+1`](https://github.com/go-delve/delve/blob/v1.25.0/pkg/proc/fncall.go#L983)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp:+151`](https://github.com/go-delve/delve/blob/v1.25.0/pkg/proc/eval.go#L1200)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).run:+4`](https://github.com/go-delve/delve/blob/v1.25.0/pkg/proc/eval.go#L973)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).resume:+56`](https://github.com/go-delve/delve/blob/v1.25.0/pkg/proc/eval.go#L966)
- [`github.com/go-delve/delve/pkg/proc.callInjectionProtocol:+36`](https://github.com/go-delve/delve/blob/v1.25.0/pkg/proc/fncall.go#L1180)
- [`github.com/go-delve/delve/pkg/proc.(*TargetGroup).Continue:+112`](https://github.com/go-delve/delve/blob/v1.25.0/pkg/proc/target_exec.go#L168)
- [`github.com/go-delve/delve/service/debugger.(*Debugger).Command:+38`](https://github.com/go-delve/delve/blob/v1.25.0/service/debugger/debugger.go#L1100)
- [`github.com/go-delve/delve/service/dap.(*Session).resumeOnce:+20`](https://github.com/go-delve/delve/blob/v1.25.0/service/dap/server.go#L3703)
- [`github.com/go-delve/delve/service/dap.(*Session).resumeOnceAndCheckStop:+1`](https://github.com/go-delve/delve/blob/v1.25.0/service/dap/server.go#L3851)
- [`github.com/go-delve/delve/service/dap.init.func1:+1`](https://github.com/go-delve/delve/blob/v1.25.0/service/dap/server.go#L3847)
- [`github.com/go-delve/delve/service/dap.(*Session).runUntilStop:+10`](https://github.com/go-delve/delve/blob/v1.25.0/service/dap/server.go#L3839)
- [`github.com/go-delve/delve/service/dap.(*Session).runUntilStopAndNotify:+1`](https://github.com/go-delve/delve/blob/v1.25.0/service/dap/server.go#L3714)
```
github.com/go-delve/delve/cmd/dlv@v1.25.0 go1.24.5 linux/amd64 (3)
```
Dups: QUnKEw ScKaUA yjGumQ fqHTcQ

Discussion:
@aarzilli: This stack `QUnKEw` was [reported by telemetry](https://telemetry.go.dev/data/2025-10-04):

- `delve/bug`
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp.func1:+3`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1095)
- [`runtime.gopanic:+50`](https://cs.opensource.google/go/go/+/go1.25.0:src/runtime/panic.go;l=783)
- [`runtime.goPanicIndex:+2`](https://cs.opensource.google/go/go/+/go1.25.0:src/runtime/panic.go;l=115)
- `github.com/go-delve/delve/pkg/proc.(*evalStack).fncallPeek:=914`
- [`github.com/go-delve/delve/pkg/proc.(*EvalScope).evalCallInjectionSetTarget:+1`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/fncall.go#L983)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp:+151`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1241)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).run:+4`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1014)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).resume:+56`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1007)
- [`github.com/go-delve/delve/pkg/proc.callInjectionProtocol:+36`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/fncall.go#L1180)
- [`github.com/go-delve/delve/pkg/proc.(*TargetGroup).Continue:+112`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/target_exec.go#L168)
- [`github.com/go-delve/delve/service/debugger.(*Debugger).Command:+38`](https://github.com/go-delve/delve/blob/v1.25.1/service/debugger/debugger.go#L1100)
- [`github.com/go-delve/delve/service/dap.(*Session).resumeOnce:+20`](https://github.com/go-delve/delve/blob/v1.25.1/service/dap/server.go#L3766)
- [`github.com/go-delve/delve/service/dap.(*Session).resumeOnceAndCheckStop:+1`](https://github.com/go-delve/delve/blob/v1.25.1/service/dap/server.go#L3914)
- [`github.com/go-delve/delve/service/dap.init.func1:+1`](https://github.com/go-delve/delve/blob/v1.25.1/service/dap/server.go#L3910)
- [`github.com/go-delve/delve/service/dap.(*Session).runUntilStop:+10`](https://github.com/go-delve/delve/blob/v1.25.1/service/dap/server.go#L3902)
- [`github.com/go-delve/delve/service/dap.(*Session).runUntilStopAndNotify:+1`](https://github.com/go-delve/delve/blob/v1.25.1/service/dap/server.go#L3777)
```
github.com/go-delve/delve/cmd/dlv@v1.25.1 go1.25.0 darwin/arm64 (1)
```

@aarzilli: This stack `ScKaUA` was [reported by telemetry](https://telemetry.go.dev/data/2025-10-12):

- `delve/bug`
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp.func1:+3`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1095)
- [`runtime.gopanic:+50`](https://cs.opensource.google/go/go/+/go1.25rc2:src/runtime/panic.go;l=783)
- [`runtime.goPanicIndex:+2`](https://cs.opensource.google/go/go/+/go1.25rc2:src/runtime/panic.go;l=115)
- `github.com/go-delve/delve/pkg/proc.(*evalStack).fncallPeek:=914`
- [`github.com/go-delve/delve/pkg/proc.(*EvalScope).evalCallInjectionSetTarget:+1`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/fncall.go#L983)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp:+151`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1241)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).run:+4`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1014)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).resume:+56`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1007)
- [`github.com/go-delve/delve/pkg/proc.callInjectionProtocol:+36`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/fncall.go#L1180)
- [`github.com/go-delve/delve/pkg/proc.(*TargetGroup).Continue:+112`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/target_exec.go#L168)
- [`github.com/go-delve/delve/pkg/proc.EvalExpressionWithCalls:+62`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/fncall.go#L207)
- [`github.com/go-delve/delve/service/debugger.(*Debugger).Command:+57`](https://github.com/go-delve/delve/blob/v1.25.1/service/debugger/debugger.go#L1119)
- [`github.com/go-delve/delve/service/rpc2.(*RPCServer).Command:+1`](https://github.com/go-delve/delve/blob/v1.25.1/service/rpc2/server.go#L130)
- [`reflect.Value.call:+196`](https://cs.opensource.google/go/go/+/go1.25rc2:src/reflect/value.go;l=581)
- [`reflect.Value.Call:+3`](https://cs.opensource.google/go/go/+/go1.25rc2:src/reflect/value.go;l=365)
- [`github.com/go-delve/delve/service/rpccommon.(*ServerImpl).serveJSONCodec.func3:+6`](https://github.com/go-delve/delve/blob/v1.25.1/service/rpccommon/server.go#L293)
```
github.com/go-delve/delve/cmd/dlv@v1.25.1 go1.25rc2 darwin/amd64 (1)
```

@aarzilli: This stack `yjGumQ` was [reported by telemetry](https://telemetry.go.dev/data/2025-11-15):

- `delve/bug`
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp.func1:+3`](https://github.com/go-delve/delve/blob/v1.25.2/pkg/proc/eval.go#L1100)
- [`runtime.gopanic:+50`](https://cs.opensource.google/go/go/+/go1.24.3:src/runtime/panic.go;l=792)
- [`runtime.goPanicIndex:+2`](https://cs.opensource.google/go/go/+/go1.24.3:src/runtime/panic.go;l=115)
- `github.com/go-delve/delve/pkg/proc.(*evalStack).fncallPeek:=914`
- [`github.com/go-delve/delve/pkg/proc.(*EvalScope).evalCallInjectionSetTarget:+1`](https://github.com/go-delve/delve/blob/v1.25.2/pkg/proc/fncall.go#L983)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp:+151`](https://github.com/go-delve/delve/blob/v1.25.2/pkg/proc/eval.go#L1246)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).run:+4`](https://github.com/go-delve/delve/blob/v1.25.2/pkg/proc/eval.go#L1019)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).resume:+61`](https://github.com/go-delve/delve/blob/v1.25.2/pkg/proc/eval.go#L1012)
- [`github.com/go-delve/delve/pkg/proc.callInjectionProtocol:+36`](https://github.com/go-delve/delve/blob/v1.25.2/pkg/proc/fncall.go#L1180)
- [`github.com/go-delve/delve/pkg/proc.(*TargetGroup).Continue:+112`](https://github.com/go-delve/delve/blob/v1.25.2/pkg/proc/target_exec.go#L168)
- [`github.com/go-delve/delve/pkg/proc.(*TargetGroup).Next:+13`](https://github.com/go-delve/delve/blob/v1.25.2/pkg/proc/target_exec.go#L50)
- [`github.com/go-delve/delve/service/debugger.(*Debugger).Command:+77`](https://github.com/go-delve/delve/blob/v1.25.2/service/debugger/debugger.go#L1139)
- [`github.com/go-delve/delve/service/dap.(*Session).resumeOnce:+20`](https://github.com/go-delve/delve/blob/v1.25.2/service/dap/server.go#L3788)
- [`github.com/go-delve/delve/service/dap.(*Session).resumeOnceAndCheckStop:+1`](https://github.com/go-delve/delve/blob/v1.25.2/service/dap/server.go#L3936)
- [`github.com/go-delve/delve/service/dap.init.func1:+1`](https://github.com/go-delve/delve/blob/v1.25.2/service/dap/server.go#L3932)
- [`github.com/go-delve/delve/service/dap.(*Session).runUntilStop:+10`](https://github.com/go-delve/delve/blob/v1.25.2/service/dap/server.go#L3924)
```
github.com/go-delve/delve/cmd/dlv@v1.25.2 go1.24.3 darwin/arm64 (1)
```

Use this command to reproduce the executable:
`(HOME=$(mktemp -d); GOOS=darwin GOARCH=arm64 GOTOOLCHAIN=go1.24.3 go install github.com/go-delve/delve/cmd/dlv@v1.25.2 && find $HOME/go/bin -type f)`
To disassemble: `go tool objdump exe | less`

@aarzilli: This stack `fqHTcQ` was [reported by telemetry](https://telemetry.go.dev/data/2025-11-24):

- `delve/bug`
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp.func1:+3`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1095)
- [`runtime.gopanic:+50`](https://cs.opensource.google/go/go/+/go1.25rc2:src/runtime/panic.go;l=783)
- [`runtime.goPanicIndex:+2`](https://cs.opensource.google/go/go/+/go1.25rc2:src/runtime/panic.go;l=115)
- `github.com/go-delve/delve/pkg/proc.(*evalStack).fncallPeek:=914`
- [`github.com/go-delve/delve/pkg/proc.(*EvalScope).evalCallInjectionSetTarget:+1`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/fncall.go#L983)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).executeOp:+151`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1241)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).run:+4`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1014)
- [`github.com/go-delve/delve/pkg/proc.(*evalStack).resume:+56`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/eval.go#L1007)
- [`github.com/go-delve/delve/pkg/proc.callInjectionProtocol:+36`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/fncall.go#L1180)
- [`github.com/go-delve/delve/pkg/proc.(*TargetGroup).Continue:+112`](https://github.com/go-delve/delve/blob/v1.25.1/pkg/proc/target_exec.go#L168)
- [`github.com/go-delve/delve/service/debugger.(*Debugger).Command:+38`](https://github.com/go-delve/delve/blob/v1.25.1/service/debugger/debugger.go#L1100)
- [`github.com/go-delve/delve/service/rpc2.(*RPCServer).Command:+1`](https://github.com/go-delve/delve/blob/v1.25.1/service/rpc2/server.go#L130)
- [`reflect.Value.call:+196`](https://cs.opensource.google/go/go/+/go1.25rc2:src/reflect/value.go;l=581)
- [`reflect.Value.Call:+3`](https://cs.opensource.google/go/go/+/go1.25rc2:src/reflect/value.go;l=365)
- [`github.com/go-delve/delve/service/rpccommon.(*ServerImpl).serveJSONCodec.func3:+6`](https://github.com/go-delve/delve/blob/v1.25.1/service/rpccommon/server.go#L293)
- `runtime.goexit:+0`
```
github.com/go-delve/delve/cmd/dlv@v1.25.1 go1.25rc2 darwin/arm64 (2)
```

Use this command to reproduce the executable:
`(HOME=$(mktemp -d); GOOS=darwin GOARCH=arm64 GOTOOLCHAIN=go1.25rc2 go install github.com/go-delve/delve/cmd/dlv@v1.25.1 && find $HOME/go/bin -type f)`
To disassemble: `go tool objdump exe | less`



Solution patch:
diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go
index 346741fe..0bf32962 100644
--- a/pkg/proc/eval.go
+++ b/pkg/proc/eval.go
@@ -982,6 +982,11 @@ func (stack *evalStack) resume(g *G) {
 	if finished {
 		funcCallFinish(scope, stack)
 	}
+	if stack.err == nil && len(stack.fncalls) > 0 {
+		if fncall := stack.fncallPeek(); fncall.err != nil {
+			stack.err = fncall.err
+		}
+	}
 
 	if stack.callInjectionContinue {
 		// not done with call injection, stay in this mode
diff --git a/pkg/proc/fncall.go b/pkg/proc/fncall.go
index 0b00839f..10a6a4c9 100644
--- a/pkg/proc/fncall.go
+++ b/pkg/proc/fncall.go
@@ -809,7 +809,7 @@ func funcCallStep(callScope *EvalScope, stack *evalStack, thread Thread) bool {
 	regs, err := thread.Registers()
 	if err != nil {
 		fncall.err = err
-		return true
+		return false
 	}
 
 	regval := bi.Arch.RegistersToDwarfRegisters(0, regs).Uint64Val(fncall.protocolReg)
diff --git a/pkg/proc/loong64_arch.go b/pkg/proc/loong64_arch.go
index 5d1cad6f..dc2e5699 100644
--- a/pkg/proc/loong64_arch.go
+++ b/pkg/proc/loong64_arch.go
@@ -34,6 +34,7 @@ func LOONG64Arch(goos string) *Arch {
 		usesLR:                           true,
 		PCRegNum:                         regnum.LOONG64_PC,
 		SPRegNum:                         regnum.LOONG64_SP,
+		ContextRegNum:                    regnum.LOONG64_R0 + 29,
 		asmRegisters:                     loong64AsmRegisters,
 		RegisterNameToDwarf:              nameToDwarfFunc(regnum.LOONG64NameToDwarf),
 		RegnumToString:                   regnum.LOONG64ToName,
diff --git a/pkg/proc/stack_sigtramp.go b/pkg/proc/stack_sigtramp.go
index dd7a074c..7fb05d0f 100644
--- a/pkg/proc/stack_sigtramp.go
+++ b/pkg/proc/stack_sigtramp.go
@@ -82,6 +82,8 @@ func (it *stackIterator) readSigtrampgoContext() (*op.DwarfRegisters, error) {
 			return sigtrampContextLinuxAMD64(it.mem, addr)
 		case "arm64":
 			return sigtrampContextLinuxARM64(it.mem, addr)
+		case "loong64":
+			return sigtrampContextLinuxLOONG64(it.mem, addr)
 		default:
 			return nil, errors.New("not implemented")
 		}
@@ -321,6 +323,50 @@ func sigtrampContextLinuxARM64(mem MemoryReader, addr uint64) (*op.DwarfRegister
 	dregs[regnum.ARM64_PC] = op.DwarfRegisterFromUint64(regs.pc)
 	return op.NewDwarfRegisters(0, dregs, binary.LittleEndian, regnum.ARM64_PC, regnum.ARM64_SP, regnum.ARM64_BP, regnum.ARM64_LR), nil
 }
+func sigtrampContextLinuxLOONG64(mem MemoryReader, addr uint64) (*op.DwarfRegisters, error) {
+	//The struct get from src/runtime/defs_linux_loong64.go
+	type usigset struct {
+		val [16]uint64
+	}
+
+	type stackt struct {
+		ss_sp     *byte
+		ss_flags  int32
+		pad_cgo_0 [4]byte
+		ss_size   uintptr
+	}
+
+	type sigcontext struct {
+		sc_pc         uint64
+		sc_regs       [32]uint64
+		sc_flags      uint32
+		sc_pad0       [1]uint32
+		sc_extcontext [0]uint64
+	}
+
+	type ucontext struct {
+		uc_flags     uint64
+		uc_link      *ucontext
+		uc_stack     stackt
+		uc_sigmask   usigset
+		uc_x_unused  [0]uint8
+		uc_pad_cgo_0 [8]byte
+		uc_mcontext  sigcontext
+	}
+
+	buf := make([]byte, unsafe.Sizeof(ucontext{}))
+	_, err := mem.ReadMemory(buf, addr)
+	if err != nil {
+		return nil, err
+	}
+	regs := &(((*ucontext)(unsafe.Pointer(&buf[0]))).uc_mcontext)
+	dregs := make([]*op.DwarfRegister, regnum.LOONG64MaxRegNum()+1)
+	for i := regnum.LOONG64_R0; i <= regnum.LOONG64_R31; i++ {
+		dregs[regnum.LOONG64_R0+i] = op.DwarfRegisterFromUint64(regs.sc_regs[i])
+	}
+	dregs[regnum.LOONG64_PC] = op.DwarfRegisterFromUint64(regs.sc_pc)
+	return op.NewDwarfRegisters(0, dregs, binary.LittleEndian, regnum.LOONG64_PC, regnum.LOONG64_SP, regnum.LOONG64_FP, regnum.LOONG64_LR), nil
+}
 
 func sigtrampContextFreebsdAMD64(mem MemoryReader, addr uint64) (*op.DwarfRegisters, error) {
 	type mcontext struct {



Test patch:
diff --git a/pkg/proc/core/core_test.go b/pkg/proc/core/core_test.go
index 52b210b6..e2292750 100644
--- a/pkg/proc/core/core_test.go
+++ b/pkg/proc/core/core_test.go
@@ -533,8 +533,6 @@ func mustSupportCore(t *testing.T) {
 	switch runtime.GOARCH {
 	case "386", "ppc64le":
 		t.Skip("unsupported")
-	case "loong64":
-		t.Skip("could not read runtime.sigtrampgo context")
 	}
 
 	if os.Getenv("CI") == "true" && buildMode == "pie" {