Hi Kurtis Rader,

Thanks for your response. I am working on it. I will quickly share it.
Before that one more update. I have commented the below two lines. Now from
the core, I am able to see the correct stack trace.

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.sched332                 //sched.sp
= *(*uintptr)(unsafe.Pointer(sched.sp + alignUp(sys.MinFrameSize,
sys.StackAlign)))*
333
334                 // Do the accounting that cgocall will not have a
chance to do
335                 // during an unwind.
336                 //
337                 // In the case where a Go call originates from C, ncgo
is 0
338                 // and there is no matching cgocall to end.
339                 if mp.ncgo > 0 {
340                         mp.incgo = false
341                         mp.ncgo--
342                         osPreemptExtExit(mp)
343                 }
344
345                 releasem(mp)
346         }
347 }

(dlv)bt
 0  0x0000000000460ea1 in runtime.raise
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/sys_linux_amd64.s:154
 1  0x0000000000449845 in runtime.dieFromSignal
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/signal_unix.go:879
 2  0x0000000000449e25 in runtime.sigfwdgo
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/signal_unix.go:1092
 3  0x00000000004487a7 in runtime.sigtrampgo
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/signal_unix.go:432
 4  0x0000000000461186 in runtime.sigtramp
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/sys_linux_amd64.s:354
 5  0x00007f2d5ba16520 in ???
    at ?:-1
 6  0x0000000000449a58 in runtime.crash
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/signal_unix.go:971
 7  0x0000000000434d85 in runtime.fatalpanic
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/panic.go:1168
 8  0x00000000004344cc in runtime.gopanic
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/panic.go:987
 9  0x00000000004642a7 in main.Test4
    at ./export.go:8
10  0x000000000046431c in _cgoexp_209e16473f08_Test4
    at _cgo_gotypes.go:61
11  0x000000000040535b in runtime.cgocallbackg1
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/cgocall.go:315
12  0x0000000000405079 in runtime.cgocallbackg
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/cgocall.go:234
13  0x0000000000461b0f in runtime.cgocallbackg
    at <autogenerated>:1
14  0x000000000045f3d4 in runtime.cgocallback
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/asm_amd64.s:998
15  0x00000000004641bd in crosscall2
15  0x00000000004641bd in crosscall2
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/cgo/asm_amd64.s:30
16  0x0000000000464386 in C.Test4
    at /tmp/go-build/_cgo_export.c:33
17  0x0000000000464432 in C.test1
    at ./hello.go:10
18  0x000000000046444d in C.test2
    at ./hello.go:15
19  0x0000000000464468 in C.test3
    at ./hello.go:20
20  0x00000000004644a7 in C._cgo_209e16473f08_Cfunc_test3
    at /tmp/go-build/cgo-gcc-prolog:49
21  0x000000000045f2c4 in runtime.asmcgocall
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/asm_amd64.s:848
22  0x000000000046448a in C._cgo_209e16473f08_Cfunc_test3
    at /tmp/go-build/cgo-gcc-prolog:44
23  0x0000000000404f0a in runtime.cgocall
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/cgocall.go:167
24  0x0000000000464245 in main._Cfunc_test3
    at _cgo_gotypes.go:39
25  0x00000000004642d7 in main.main
    at ./hello.go:34
26  0x0000000000437053 in runtime.main
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/proc.go:250
27  0x000000000045f5c1 in runtime.goexit
    at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/asm_amd64.s:1598

Best Regards
Mariappan

On Tue, Apr 4, 2023 at 9:02 AM Kurtis Rader <kra...@skepticism.us> wrote:

> You have not done what Robert suggested. That is, "I would start by
> publishing a small reproducible test case on github that fully compiles
> that demonstrates the issue." It may not be practical to do so. However,
> providing the source code for a small reproducible test case will make it
> infinitely easier for others to a) reproduce the problem, and b)
> investigate the problem and provide additional insights and possible fixes.
> Note that option (a) will, itself, provide insights into the nature of the
> problem if it only manifests on some, rather than all, platforms. You have
> provided a lot of useful data but this type of problem really requires
> others to be able to reproduce it. I say this as someone who was a level
> three support engineer for two decades that specialized in solving exactly
> this type of problem for the customers of the companies I worked for.
>
> On Mon, Apr 3, 2023 at 8:16 PM mariappan balraj <
> mariappan.bal...@gmail.com> wrote:
>
>> Hi Robert,
>>
>> Eagerly waiting for your help. Some further update.
>>
>> I have set a break point at line number 332 by using dlv, noted the value
>> of shced.sp. Once line number 332 is executed, reset the value of  sched.sp
>> by using set command in dlv. In this case, I am getting the proper trace.
>>
>> 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)))
>>
>> Actual core file produces following stack trace:
>>
>>  0  0x0000000000460ec1 in runtime.raise
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:154
>>  1  0x0000000000449865 in runtime.dieFromSignal
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:879
>>  2  0x0000000000449e45 in runtime.sigfwdgo
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:1092
>>  3  0x00000000004487c7 in runtime.sigtrampgo
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:432
>>  4  0x0000000000461186 in runtime.sigtramp
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:352
>>  5  0x00007f9ab9b5f520 in ???
>>     at ?:-1
>>  6  0x0000000000449a78 in runtime.crash
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:971
>>  7  0x0000000000434da5 in runtime.fatalpanic
>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:1168
>>  8  0x00000000004344ec in runtime.gopanic
>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:987
>>  9  0x00000000004642a7 in main.Test4
>>     at ./export.go:8
>> 10  0x000000000046431c in _cgoexp_209e16473f08_Test4
>>     at _cgo_gotypes.go:61
>> 11  0x000000000040535b in runtime.cgocallbackg1
>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:315
>> 12  0x0000000000405079 in runtime.cgocallbackg
>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:234
>> 13  0x0000000000461b0f in runtime.cgocallbackg
>>     at <autogenerated>:1
>> 14  0x000000000045f3f4 in runtime.cgocallback
>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:998
>> 15  0x0000000000000001 in ???
>> 15  0x0000000000000001 in ???
>>     at ?:-1
>> 16  0x000000c00003e000 in ???
>>     at ?:-1
>>     error: error while reading spliced memory at 0x8: EOF
>>
>> <<< By using DLV and setting break point
>>
>>  /root/go/bin/dlv exec ./test
>> Type 'help' for list of commands.
>> (dlv) break unwindm
>> Breakpoint 1 set at 0x4054e6 for runtime.unwindm()
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:326
>> (dlv) c
>> > runtime.unwindm()
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:326 (hits
>> goroutine(1):1 total:1) (PC: 0x4054e6)
>> Warning: debugging optimized function
>>    321:         // Do not unwind m->g0->sched.sp.
>>    322:         // Our caller, cgocallback, will do that.
>>    323:         restore = false
>>    324: }
>>    325:
>> => 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
>>
>> (dlv)
>> > runtime.unwindm()
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:332 (PC:
>> 0x40550d)
>> Warning: debugging optimized function
>>    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)))
>>    333:
>>    334:                 // Do the accounting that cgocall will not have a
>> chance to do
>>    335:                 // during an unwind.
>>    336:                 //
>>    337:                 // In the case where a Go call originates from C,
>> ncgo is 0
>>
>> (dlv) p %x mp.g0.sched.sp
>> 7fffab8268a8
>>
>> (dlv) n
>> > runtime.unwindm()
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:339 (PC:
>> 0x405529)
>> Warning: debugging optimized function
>>    334:                 // Do the accounting that cgocall will not have a
>> chance to do
>>    335:                 // during an unwind.
>>    336:                 //
>>    337:                 // In the case where a Go call originates from C,
>> ncgo is 0
>>    338:                 // and there is no matching cgocall to end.
>> => 339:                 if mp.ncgo > 0 {
>>    340:                         mp.incgo = false
>>    341:                         mp.ncgo--
>>    342:                         osPreemptExtExit(mp)
>>    343:                 }
>>    344:
>> (dlv) p %x mp.g0.sched.sp
>> 7fffab826a18
>>
>> (dlv) set mp.g0.sched.sp=0x7fffab8268a8
>> (dlv)  p %x mp.g0.sched.sp
>> 7fffab8268a8
>>
>> (dlv) break  runtime.raise
>> Breakpoint 2 set at 0x460ea0 for runtime.raise()
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:144
>>
>> (dlv) c
>> (dlv) c
>>
>> (dlv)
>> > runtime.raise()
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:153
>> (PC: 0x460ebf)
>> Warning: debugging optimized function
>>    148:         SYSCALL
>>    149:         MOVL    AX, SI  // arg 2 tid
>>    150:         MOVL    R12, DI // arg 1 pid
>>    151:         MOVL    sig+0(FP), DX   // arg 3
>>    152:         MOVL    $SYS_tgkill, AX
>> => 153:         SYSCALL
>>    154:         RET
>>
>> (dlv) bt
>>  0  0x0000000000460ebf in runtime.raise
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:153
>>  1  0x0000000000449865 in runtime.dieFromSignal
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:879
>>  2  0x0000000000449a78 in runtime.crash
>>     at
>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:971
>>  3  0x0000000000434da5 in runtime.fatalpanic
>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:1168
>>  4  0x00000000004344ec in runtime.gopanic
>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:987
>>  5  0x00000000004642a7 in main.Test4
>>     at ./export.go:8
>>  6  0x000000000046431c in _cgoexp_209e16473f08_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:10
>> 14  0x000000000046444d in C.test2
>>     at ./hello.go:15
>> 15  0x0000000000464468 in C.test3
>> 15  0x0000000000464468 in C.test3
>>     at ./hello.go:20
>> 16  0x00000000004644a7 in C._cgo_209e16473f08_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_209e16473f08_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:34
>> 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
>>
>> Stack trace looks fine till this point.
>>
>> Best Regards
>> Mariappan
>>
>> On Mon, Apr 3, 2023 at 9:50 AM Robert Engels <reng...@ix.netcom.com>
>> wrote:
>>
>>> I would start by publishing a small reproducible test case on github
>>> that fully compiles that demonstrates the issue.
>>>
>>> On Apr 2, 2023, at 10:59 PM, mariappan balraj <
>>> mariappan.bal...@gmail.com> wrote:
>>>
>>> 
>>> Hello Go Experts,
>>>
>>> It is good if someone can help on this?
>>>
>>> Best Regards
>>> Mariappan
>>> On Sat, Apr 1, 2023 at 7:45 AM mariappan balraj <
>>> mariappan.bal...@gmail.com> wrote:
>>>
>>>> Hello Go experts,
>>>>
>>>> Could someone please help to resolve this issue?
>>>>
>>>> Best Regards
>>>> Mariappan
>>>>
>>>> On Thu, Mar 30, 2023 at 2:52 PM mariappan balraj <
>>>> mariappan.bal...@gmail.com> wrote:
>>>>
>>>>> 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
>>>>>
>>>>> On Tue, Mar 28, 2023 at 4:14 PM mariappan balraj <
>>>>> mariappan.bal...@gmail.com> wrote:
>>>>>
>>>>>> Hello Go Experts,
>>>>>>
>>>>>> I am observing system stack corruption when panic() is called from go
>>>>>> function. When panic is called from Test4(), as part of
>>>>>> runtime.systemstack_switch(), the RSP and RBP is set in such a way that 
>>>>>> it
>>>>>> will corrupt the stack.
>>>>>>
>>>>>> Rbp = 0x00007ffdb188bd20===> This should be less than 0x7ffdb188bc50.
>>>>>> But it is set to the value which is already used for CGO calls. So it is
>>>>>> making the system stack to corrupt. When the core file is generated, it
>>>>>> makes it unable to debug from the core file using dlv. Can someone please
>>>>>> help on this issue?
>>>>>>
>>>>>> RBP 0x7ffdb188bc50 RA 0x45f3f4 runtime.cgocallback
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s 1003
>>>>>> RBP 0x7ffdb188bca0 RA 0x4641bd crosscall2
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgo/asm_amd64.s 32
>>>>>> RBP 0x7ffdb188bcd0 RA 0x464386 C.Test4 /tmp/go-build/_cgo_export.c 35
>>>>>> RBP 0x7ffdb188bce0 RA 0x464432 C.test1
>>>>>> /home/soomohan/mbalraj/test/hello.go 10
>>>>>> RBP 0x7ffdb188bd00 RA 0x46444d C.test2
>>>>>> /home/soomohan/mbalraj/test/hello.go 15
>>>>>> RBP 0x7ffdb188bd20 RA 0x464468 C.test3
>>>>>> /home/soomohan/mbalraj/test/hello.go 20
>>>>>> RBP 0x7ffdb188bd50 RA 0x4644a7 C._cgo_78b81bbf688e_Cfunc_test3
>>>>>> /tmp/go-build/cgo-gcc-prolog 51
>>>>>>
>>>>>> go version
>>>>>> go version go1.20.2 linux/amd64
>>>>>>
>>>>>> //hello.go
>>>>>> package main
>>>>>>
>>>>>> /*
>>>>>> #include <stdio.h>
>>>>>>
>>>>>> extern void Test4(void);
>>>>>>
>>>>>> void test1(void) {
>>>>>>    Test4();
>>>>>> }
>>>>>>
>>>>>> void test2(void) {
>>>>>>     int val = 2;
>>>>>>     test1();
>>>>>> }
>>>>>>
>>>>>> void test3(void) {
>>>>>>     int val = 3;
>>>>>>     test2();
>>>>>> }
>>>>>>
>>>>>> void test4(void) {
>>>>>>     printf("Test4()");
>>>>>> }
>>>>>> */
>>>>>> import "C"
>>>>>>
>>>>>> func Test5() {
>>>>>>     C.test4()
>>>>>> }
>>>>>>
>>>>>> func main() {
>>>>>>     C.test3()
>>>>>> }
>>>>>>
>>>>>> //export.go
>>>>>> package main
>>>>>>
>>>>>> import "C"
>>>>>>
>>>>>> //export Test4
>>>>>> func Test4() {
>>>>>>     panic("Panic inside Test4")
>>>>>>     //Test5()
>>>>>> }
>>>>>>
>>>>>> I have written the following script test.start to debug this issue
>>>>>> further in DLV.
>>>>>> def command_goroutine_start_line(args):
>>>>>>     regs = registers().Regs
>>>>>>     rip = 0
>>>>>>     for reg in regs:
>>>>>>         if reg.Name == "Rbp":
>>>>>>             rbp = int(reg.Value, 16)
>>>>>>         elif reg.Name == "Rip":
>>>>>>             rip = int(reg.Value, 16)
>>>>>>
>>>>>>     da = disassemble(StartPC=rip, EndPC=rip+1).Disassemble
>>>>>>     print("RBP 0x%x RIP 0x%x %s %s %s" % (rbp, rip,
>>>>>> da[0].Loc.Function.Name_, da[0].Loc.File, da[0].Loc.Line))
>>>>>>
>>>>>>     while True:
>>>>>>         mem = examine_memory(rbp, 8).Mem
>>>>>>         val = 0
>>>>>>         for i in range(len(mem)):
>>>>>>             val <<= 8
>>>>>>             val += mem[len(mem) - i - 1]
>>>>>>         prbp = val
>>>>>>
>>>>>>         mem = examine_memory(rbp + 8, 8).Mem
>>>>>>         val = 0
>>>>>>         for i in range(len(mem)):
>>>>>>             val <<= 8
>>>>>>             val += mem[len(mem) - i - 1]
>>>>>>         ra = val
>>>>>>
>>>>>>         da = disassemble(StartPC=ra, EndPC=ra+1).Disassemble
>>>>>>         print("RBP 0x%x RA 0x%x %s %s %s" % (prbp, ra,
>>>>>> da[0].Loc.Function.Name_, da[0].Loc.File, da[0].Loc.Line))
>>>>>>         if prbp == 0:
>>>>>>            break
>>>>>>         rbp = prbp
>>>>>>
>>>>>> def main():
>>>>>>         dlv_command("config alias goroutine_start_line gsl")
>>>>>>
>>>>>> (dlv)bt
>>>>>> RBP 0x0 RA 0x45f5e1 runtime.goexit
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s 1599
>>>>>>
>>>>>>  0  0x0000000000433b04 in runtime.addOneOpenDeferFrame.func1
>>>>>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:646
>>>>>>  1  0x000000000045f0c0 in runtime.systemstack_switch
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:463
>>>>>>  2  0x0000000000433a89 in runtime.addOneOpenDeferFrame
>>>>>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:644
>>>>>>  3  0x0000000000434357 in runtime.gopanic
>>>>>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:886
>>>>>>  4  0x00000000004642a7 in main.Test4
>>>>>>     at ./export.go:7
>>>>>>  5  0x000000000046431c in _cgoexp_78b81bbf688e_Test4
>>>>>>     at _cgo_gotypes.go:61
>>>>>>  6  0x000000000040535b in runtime.cgocallbackg1
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:315
>>>>>>  7  0x0000000000405079 in runtime.cgocallbackg
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:234
>>>>>>  8  0x0000000000461b0f in runtime.cgocallbackg
>>>>>>     at <autogenerated>:1
>>>>>>  9  0x000000000045f3f4 in runtime.cgocallback
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:998
>>>>>> 10  0x0000000000000001 in ???
>>>>>>     at ?:-1
>>>>>> 11  0x0000000000464386 in C.Test4
>>>>>>     at /tmp/go-build/_cgo_export.c:33
>>>>>> 12  0x0000000000464432 in C.test1
>>>>>>     at ./hello.go:9
>>>>>> 13  0x000000000046444d in C.test2
>>>>>>     at ./hello.go:14
>>>>>> 14  0x0000000000464468 in C.test3
>>>>>>     at ./hello.go:19
>>>>>> 15  0x00000000004644a7 in C._cgo_78b81bbf688e_Cfunc_test3
>>>>>> 15  0x00000000004644a7 in C._cgo_78b81bbf688e_Cfunc_test3
>>>>>>     at /tmp/go-build/cgo-gcc-prolog:49
>>>>>> 16  0x000000000045f2e4 in runtime.asmcgocall
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:848
>>>>>> 17  0x000000000046448a in C._cgo_78b81bbf688e_Cfunc_test3
>>>>>>     at /tmp/go-build/cgo-gcc-prolog:44
>>>>>> 18  0x0000000000404f0a in runtime.cgocall
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:167
>>>>>> 19  0x0000000000464245 in main._Cfunc_test3
>>>>>>     at _cgo_gotypes.go:39
>>>>>> 20  0x00000000004642d7 in main.main
>>>>>>     at ./hello.go:33
>>>>>> 21  0x0000000000437073 in runtime.main
>>>>>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/proc.go:250
>>>>>> 22  0x000000000045f5e1 in runtime.goexit
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:1598
>>>>>>
>>>>>> (dlv)source test.star
>>>>>> (dlv)gsl
>>>>>> (dlv) gsl
>>>>>> RBP 0xc000048c68 RIP 0x433b04 runtime.addOneOpenDeferFrame.func1
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go 646
>>>>>> RBP 0xc000048d28 RA 0x434357 runtime.gopanic
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go 905
>>>>>> RBP 0xc000048d48 RA 0x4642a7 main.Test4
>>>>>> /home/soomohan/mbalraj/test/export.go 7
>>>>>> RBP 0xc000048d58 RA 0x46431c _cgoexp_78b81bbf688e_Test4
>>>>>> _cgo_gotypes.go 62
>>>>>> RBP 0xc000048e18 RA 0x40535b runtime.cgocallbackg1
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go 323
>>>>>> RBP 0xc000048ea8 RA 0x405079 runtime.cgocallbackg
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go 240
>>>>>> RBP 0xc000048ed0 RA 0x461b0f runtime.cgocallbackg <autogenerated> 1
>>>>>> RBP 0x7ffdb188bc50 RA 0x45f3f4 runtime.cgocallback
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s 1003
>>>>>> RBP 0x7ffdb188bca0 RA 0x4641bd crosscall2
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgo/asm_amd64.s 32
>>>>>> RBP 0x7ffdb188bcd0 RA 0x464386 C.Test4 /tmp/go-build/_cgo_export.c 35
>>>>>> RBP 0x7ffdb188bce0 RA 0x464432 C.test1
>>>>>> /home/soomohan/mbalraj/test/hello.go 10
>>>>>> RBP 0x7ffdb188bd00 RA 0x46444d C.test2
>>>>>> /home/soomohan/mbalraj/test/hello.go 15
>>>>>> RBP 0x7ffdb188bd20 RA 0x464468 C.test3
>>>>>> /home/soomohan/mbalraj/test/hello.go 20
>>>>>> RBP 0x7ffdb188bd50 RA 0x4644a7 C._cgo_78b81bbf688e_Cfunc_test3
>>>>>> /tmp/go-build/cgo-gcc-prolog 51
>>>>>> RBP 0xc000048f38 RA 0x45f2e4 runtime.asmcgocall
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s 852
>>>>>> RBP 0xc000048f60 RA 0x464245 main._Cfunc_test3 _cgo_gotypes.go 40
>>>>>> RBP 0xc000048f70 RA 0x4642d7 main.main
>>>>>> /home/soomohan/mbalraj/test/hello.go 33
>>>>>> RBP 0xc000048fd0 RA 0x437073 runtime.main
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/proc.go 260
>>>>>> RBP 0x0 RA 0x45f5e1 runtime.goexit
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s 1599
>>>>>>
>>>>>> (dlv)si
>>>>>>
>>>>>> (dlv)bt
>>>>>>  0  0x000000000045587f in runtime.gentraceback
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/traceback.go:32
>>>>>>  1  0x000000000045f0c0 in runtime.systemstack_switch
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:463
>>>>>>  2  0x0000000000433a89 in runtime.addOneOpenDeferFrame
>>>>>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:644
>>>>>>  3  0x0000000000434357 in runtime.gopanic
>>>>>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:886
>>>>>>  4  0x00000000004642a7 in main.Test4
>>>>>>     at ./export.go:7
>>>>>>  5  0x000000000046431c in _cgoexp_78b81bbf688e_Test4
>>>>>>     at _cgo_gotypes.go:61
>>>>>>  6  0x000000000040535b in runtime.cgocallbackg1
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:315
>>>>>>  7  0x0000000000405079 in runtime.cgocallbackg
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:234
>>>>>>  8  0x0000000000461b0f in runtime.cgocallbackg
>>>>>>     at <autogenerated>:1
>>>>>>  9  0x000000000045f3f4 in runtime.cgocallback
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:998
>>>>>> 10  0x0000000000000001 in ???
>>>>>>     at ?:-1
>>>>>> 11  0x0000000000464386 in C.Test4
>>>>>>     at /tmp/go-build/_cgo_export.c:33
>>>>>> 12  0x0000000000464432 in C.test1
>>>>>>     at ./hello.go:9
>>>>>> 13  0x000000000046444d in C.test2
>>>>>>     at ./hello.go:14
>>>>>> 14  0x0000000000464468 in C.test3
>>>>>>     at ./hello.go:19
>>>>>> 15  0x0000000000433b4b in runtime.addOneOpenDeferFrame.func1
>>>>>> 15  0x0000000000433b4b in runtime.addOneOpenDeferFrame.func1
>>>>>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/panic.go:645
>>>>>> 16  0x000000000045f129 in runtime.systemstack
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:496
>>>>>> 17  0x0000000000461da5 in runtime.newproc
>>>>>>     at <autogenerated>:1
>>>>>> 18  0x00000000004cc720 in ???
>>>>>>     at ?:-1
>>>>>> 19  0x000000000046431c in _cgoexp_78b81bbf688e_Test4
>>>>>>     at _cgo_gotypes.go:61
>>>>>> 20  0x000000000040535b in runtime.cgocallbackg1
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:315
>>>>>> 21  0x0000000000405079 in runtime.cgocallbackg
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:234
>>>>>> 22  0x0000000000461b0f in runtime.cgocallbackg
>>>>>>     at <autogenerated>:1
>>>>>> 23  0x000000000045f3f4 in runtime.cgocallback
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:998
>>>>>> 24  0x000000000045f0c0 in runtime.systemstack_switch
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:463
>>>>>> 25  0x0000000000404f0a in runtime.cgocall
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/cgocall.go:167
>>>>>> 26  0x0000000000464245 in main._Cfunc_test3
>>>>>>     at _cgo_gotypes.go:39
>>>>>> 27  0x00000000004642d7 in main.main
>>>>>>     at ./hello.go:33
>>>>>> 28  0x0000000000437073 in runtime.main
>>>>>>     at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/proc.go:250
>>>>>> 29  0x000000000045f5e1 in runtime.goexit
>>>>>>     at
>>>>>> /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:1598
>>>>>>
>>>>>> (dlv) regs
>>>>>>  (dlv) regs
>>>>>>     Rip = 0x000000000045587f
>>>>>>     Rsp = 0x00007ffdb188ba08
>>>>>>     Rax = 0x000000000040535b
>>>>>>     Rbx = 0x000000c000048d68
>>>>>>     Rcx = 0x0000000000000000
>>>>>>     Rdx = 0x0000000000433b60
>>>>>>     Rsi = 0x0000000000000000
>>>>>>     Rdi = 0x000000c0000061a0
>>>>>>     Rbp = 0x00007ffdb188bd20
>>>>>>      R8 = 0x0000000000000000
>>>>>>      R9 = 0x000000007fffffff
>>>>>>     R10 = 0x00007ffdb188bd80
>>>>>>     R11 = 0x0000000000000000
>>>>>>     R12 = 0x00007ffdb188ba88
>>>>>>     R13 = 0x000000c000048c18
>>>>>>     R14 = 0x00000000004cc720
>>>>>>     R15 = 0x0000000000000000
>>>>>>  Rflags = 0x0000000000000246    [PF ZF IF IOPL=0]
>>>>>>      Es = 0x0000000000000000
>>>>>>      Cs = 0x0000000000000033
>>>>>>      Ss = 0x000000000000002b
>>>>>>      Ds = 0x0000000000000000
>>>>>>      Fs = 0x0000000000000000
>>>>>>      Gs = 0x0000000000000000
>>>>>> Fs_base = 0x000015128ba66740
>>>>>> Gs_base = 0x0000000000000000
>>>>>>
>>>>>> Best Regards
>>>>>> Mariappan
>>>>>>
>>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/CAKKWi6TOAChrRs64UBrNJSPFdFkYHhWiHPsDzu%2BMKPck9BOhVQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/golang-nuts/CAKKWi6TOAChrRs64UBrNJSPFdFkYHhWiHPsDzu%2BMKPck9BOhVQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/CAKKWi6Souf4Cj%3Dcbh6A3mf2MwZGUF_h6rLu3rEqVJZuXOQg-Ow%40mail.gmail.com
>> <https://groups.google.com/d/msgid/golang-nuts/CAKKWi6Souf4Cj%3Dcbh6A3mf2MwZGUF_h6rLu3rEqVJZuXOQg-Ow%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAKKWi6TROvOpf9LyHBfbD8HJxPgWm7aR7KEQ7xv%2BNp8-2KtQvg%40mail.gmail.com.

Reply via email to