Hello Go Experts,
When panic() is called from Go function, in the below call sequence, runtime.unwindm() [which is defer function of runtime.cgocallbackg1] is called. This function is unwinding the system stack. Later, as part of the function addOneOpenDeferFrame(), systemstack() is called to run a function in the system stack. This will use the stack which is allocated for C function calls. This makes stack unwinding impossible in case of panic() is called. Can someone please help me to fix this issue?
(dlv) bt
0 0x00000000004054e6 in runtime.unwindm
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:326
1 0x0000000000405446 in runtime.cgocallbackg1.func3
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:304
2 0x00000000004340c8 in runtime.deferCallSave
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:796
3 0x0000000000433fa5 in runtime.runOpenDeferFrame
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:769
4 0x0000000000434332 in runtime.gopanic
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:884
5 0x00000000004642a7 in main.Test4
at ./export.go:7
at ./export.go:7
6 0x000000000046431c in _cgoexp_78b81bbf688e_Test4
at _cgo_gotypes.go:61
7 0x000000000040535b in runtime.cgocallbackg1
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:315
8 0x0000000000405079 in runtime.cgocallbackg
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:234
9 0x0000000000461b0f in runtime.cgocallbackg
at <autogenerated>:1
10 0x000000000045f3f4 in runtime.cgocallback
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:998
11 0x00000000004641bd in crosscall2
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgo/asm_amd64.s:30
12 0x0000000000464386 in C.Test4
at /tmp/go-build/_cgo_export.c:33
13 0x0000000000464432 in C.test1
at ./hello.go:9
14 0x000000000046444d in C.test2
at ./hello.go:14
15 0x0000000000464468 in C.test3
15 0x0000000000464468 in C.test3
at ./hello.go:19
16 0x00000000004644a7 in C._cgo_78b81bbf688e_Cfunc_test3
at /tmp/go-build/cgo-gcc-prolog:49
17 0x000000000045f2e4 in runtime.asmcgocall
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:848
18 0x000000000046448a in C._cgo_78b81bbf688e_Cfunc_test3
at /tmp/go-build/cgo-gcc-prolog:44
19 0x0000000000404f0a in runtime.cgocall
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:167
20 0x0000000000464245 in main._Cfunc_test3
at _cgo_gotypes.go:39
21 0x00000000004642d7 in main.main
at ./hello.go:33
22 0x0000000000437073 in runtime.main
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/proc.go:250
23 0x000000000045f5e1 in runtime.goexit
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:1598
254 func cgocallbackg1(fn, frame unsafe.Pointer, ctxt uintptr) {
304 defer unwindm(&restore)
326 func unwindm(restore *bool) {
327 if *restore {
328 // Restore sp saved by cgocallback during
329 // unwind of g's stack (see comment at top of file).
330 mp := acquirem()
331 sched := &mp.g0.sched
332 sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + alignUp(sys.MinFrameSize, sys.StackAlign)))
(dlv)
> runtime.addOneOpenDeferFrame() /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:642 (PC: 0x433a45)
Warning: debugging optimized function
637: func addOneOpenDeferFrame(gp *g, pc uintptr, sp unsafe.Pointer) {
638: var prevDefer *_defer
639: if sp == nil {
640: prevDefer = gp._defer
641: pc = prevDefer.framepc
=> 642: sp = unsafe.Pointer(prevDefer.sp)
643: }
644: systemstack(func() {
645: gentraceback(pc, uintptr(sp), 0, gp, 0, nil, 0x7fffffff,
646: func(frame *stkframe, unused unsafe.Pointer) bool {
647: if prevDefer != nil && prevDefer.sp == frame.sp {
(dlv) bt
0 0x0000000000433a45 in runtime.addOneOpenDeferFrame
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:642
1 0x0000000000434357 in runtime.gopanic
at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:886
2 0x00000000004642a7 in main.Test4
at ./export.go:7