New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: in core dump generated for a signal while executing C code, gdb reports a corrupt stack #57698
Comments
CC @golang/runtime Looks like gdb can't unwind past the call to |
Hi Ian,
When I simulated the crash by adding assert, from core dump, I am getting
the complete stack.
package main
/*
#include <stdio.h>
#include <assert.h>
void test1(void) {
assert(1 == 2);
}
void test2(void) {
int val = 2;
test1();
}
void test3(void) {
int val = 3;
test2();
}
*/
import "C"
func main() {
C.test3()
}
(gdb) bt
#0 runtime.usleep () at /usr/local/go/src/runtime/sys_linux_amd64.s:140
#1 0x0000000000442e2f in runtime.sighandler (sig=<optimized out>,
info=<optimized out>, ctxt=<optimized out>, gp=0xc000006340)
at /usr/local/go/src/runtime/signal_unix.go:789
#2 0x00000000004421d4 in runtime.sigtrampgo (sig=6, info=0xc00000fbf0,
ctx=0xc00000fac0) at /usr/local/go/src/runtime/signal_unix.go:479
#3 0x00000000004586c6 in runtime.sigtramp () at
/usr/local/go/src/runtime/sys_linux_amd64.s:359
#4 <signal handler called>
#5 0x00007f78b7524a7c in pthread_kill () from
/lib/x86_64-linux-gnu/libc.so.6
#6 0x00007f78b74d0476 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#7 0x00007f78b74b67f3 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#8 0x00007f78b74b671b in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#9 0x00007f78b74c7e96 in __assert_fail () from
/lib/x86_64-linux-gnu/libc.so.6
#10 0x000000000045ac22 in test1 () at
/home/ubuntu/mbalraj/GO/TEST/TEST3/test.go:8
#11 0x000000000045ac3a in test2 () at
/home/ubuntu/mbalraj/GO/TEST/TEST3/test.go:13
#12 0x000000000045ac55 in test3 () at
/home/ubuntu/mbalraj/GO/TEST/TEST3/test.go:18
#13 0x000000000045ac75 in _cgo_601fe3e3f98a_Cfunc_test3 (v=0xc00005bf70) at
/tmp/go-build/cgo-gcc-prolog:49
#14 0x0000000000456804 in runtime.asmcgocall () at
/usr/local/go/src/runtime/asm_amd64.s:844
#15 0x00000000004e15e0 in ?? ()
#16 0x0000000000000001 in ?? ()
#17 0x000000c000040a00 in ?? ()
#18 0x00007ffe126b9c08 in ?? ()
#19 0x0000000000439fc5 in runtime.malg.func1 () at
/usr/local/go/src/runtime/proc.go:4080
#20 0x0000000000456649 in runtime.systemstack () at
/usr/local/go/src/runtime/asm_amd64.s:492
#21 0x0000000000459005 in runtime.newproc (fn=0x1) at <autogenerated>:1
#22 0x00000000004c9780 in runtime[scavenger] ()
#23 0x0000000000000001 in ?? ()
#24 0x0000000000456545 in runtime.mstart () at
/usr/local/go/src/runtime/asm_amd64.s:390
#25 0x00000000004564cf in runtime.rt0_go () at
/usr/local/go/src/runtime/asm_amd64.s:354
#26 0x0000000000000001 in ?? ()
#27 0x00007ffe126b9d88 in ?? ()
#28 0x0000000000000000 in ?? ()
Best Regards
Mariappan
…On Tue, Jan 10, 2023 at 3:31 AM Ian Lance Taylor ***@***.***> wrote:
CC @golang/runtime <https://github.com/orgs/golang/teams/runtime>
Looks like gdb can't unwind past the call to sigpanic. It gets to test1
but can't get any farther. This might be difficult to solve, as the call to
sigpanic is dynamically generated.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZXH57VPVZHRMPDIBZ3WRSDDTANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I'm suggesting that the problem is that gdb can't unwind past a call to |
Hi Ian,
Is there any way to bypass sigpanic?
Best Regards
Mariappan
…On Wed, 11 Jan, 2023, 12:03 am Ian Lance Taylor, ***@***.***> wrote:
I'm suggesting that the problem is that gdb can't unwind past a call to
sigpanic. When you call the C function assert, no call to sigpanic is
involved.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZXHHIGE5E4X2NXGGV3WRWTPNANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Maybe we could consider not injecting a |
My understanding is when there is a segmentation fault in the C code,
sigpanic handler is GO code. So, we have GO stack and C stack and signal
handler stack which is another GO stack.
I am trying to understand what is done by injecting sigpanic. What kind of
recovery is done? I am able to think about handling defer calls till the
main function. In C, there is no such kind of mechanism available. But we
are ok with that. I am able to understand that some people may need it and
it is also one of the best feature of GO. But, when we start using CGO,
if there is any issue then we should be able to debug it. Debugging
support is very very important. Otherwise, the end customer will not be
happy about it. Is there any API currently available to bypass injecting
sigpanic? If there is no such API then could you please provide an API? We
can call the API in the beginning of the program. Or can it be a build
option?
Best Regards
Mariappan
…On Wed, Jan 11, 2023 at 9:21 PM cherrymui ***@***.***> wrote:
Maybe we could consider not injecting a sigpanic if a faulting signal
lands on a non-user G. It would be that either we're in the runtime, or
we're running some C code. Either way I think we cannot recover.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZXJMC6DUQNDTY3OHE3WR3JITANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
There is no API to avoid calling @cherrymui has pointed out that it is currently impossible to recover a panic that occurs while executing C code, so it may be reasonable to avoid injecting a However, making that change is not going to be a high priority for us. I don't know of anybody else who has reported problems getting a stack backtrace in a core dump generated while executing C code called by Go code. Go is an open source project, and anybody is welcome to contribute. See https://go.dev/doc/contribute. |
Hi Ian,
I have more than 18 years of industrial experience in C. So, please believe
me, this one is really a very serious problem. Now only, people started to
think very seriously about GO and taking actions. In our product, the
infrastructure is completely in C. I am evaluating using GO with existing C
infrastructure for new applications. Till now I have not seen any blockage
except this one. If we are not able to get the C stack then we may decide
to stop going with GO.
Yes. If possible, I can contribute to this. But, please provide your
continuous support.
There are two ways to solve this problem.
1) Avoid injecting the sigpanic call in C code - How to do it?
2) Reraise the signal, like how it is done for other signals. I have to
check this one.
But, which is the best solution in this two? Which one is easy to fix?
Best Regards
Mariappan
…On Thu, Jan 12, 2023 at 10:02 AM Ian Lance Taylor ***@***.***> wrote:
There is no API to avoid calling sigpanic, and we are not going to add
one.
@cherrymui <https://github.com/cherrymui> has pointed out that it is
currently impossible to recover a panic that occurs while executing C code,
so it may be reasonable to avoid injecting a sigpanic call in C code. We
could, instead, simply reraise the signal, as we do for other signals that
occur while executing C code. See the badsignal function.
However, making that change is not going to be a high priority for us. I
don't know of anybody else who has reported problems getting a stack
backtrace in a core dump generated while executing C code called by Go
code. Go is an open source project, and anybody is welcome to contribute.
See https://go.dev/doc/contribute.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZRFS2HH3IR3Q5CPNE3WR6COBANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi Ian,
I have removed _SigPanic flag for SIGSEGV from the table sigtable.
var sigtable = [...]sigTabT{
runtime/sigtab_linux_generic.go: /* 11 */ {_SigPanic + _SigUnblock,
"SIGSEGV: segmentation violation"},
===>
runtime/sigtab_linux_generic.go: /* 11 */ {_SigUnblock, "SIGSEGV:
segmentation violation"},
After doing this change, I am getting the full C stack. Is it ok?
Best Regards
Mariappan
On Thu, Jan 12, 2023 at 11:48 AM mariappan balraj <
***@***.***> wrote:
… Hi Ian,
I have more than 18 years of industrial experience in C. So, please
believe me, this one is really a very serious problem. Now only, people
started to think very seriously about GO and taking actions. In our
product, the infrastructure is completely in C. I am evaluating using GO
with existing C infrastructure for new applications. Till now I have not
seen any blockage except this one. If we are not able to get the C stack
then we may decide to stop going with GO.
Yes. If possible, I can contribute to this. But, please provide your
continuous support.
There are two ways to solve this problem.
1) Avoid injecting the sigpanic call in C code - How to do it?
2) Reraise the signal, like how it is done for other signals. I have to
check this one.
But, which is the best solution in this two? Which one is easy to fix?
Best Regards
Mariappan
On Thu, Jan 12, 2023 at 10:02 AM Ian Lance Taylor <
***@***.***> wrote:
> There is no API to avoid calling sigpanic, and we are not going to add
> one.
>
> @cherrymui <https://github.com/cherrymui> has pointed out that it is
> currently impossible to recover a panic that occurs while executing C code,
> so it may be reasonable to avoid injecting a sigpanic call in C code. We
> could, instead, simply reraise the signal, as we do for other signals that
> occur while executing C code. See the badsignal function.
>
> However, making that change is not going to be a high priority for us. I
> don't know of anybody else who has reported problems getting a stack
> backtrace in a core dump generated while executing C code called by Go
> code. Go is an open source project, and anybody is welcome to contribute.
> See https://go.dev/doc/contribute.
>
> —
> Reply to this email directly, view it on GitHub
> <#57698 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A25ROZRFS2HH3IR3Q5CPNE3WR6COBANCNFSM6AAAAAATVHEFR4>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Just removing the |
Hi Ian,
Thanks for your comments.
I have tried 2 solutions. Both worked fine. But which one is best? Or Do I
need to think differently?
1) Solution 1: In sighandler(), When _SigPanic is sent in CGO, Just mask
it and add _SigThrow.
runtime/signal_unix.go
608 func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g)
{
659 flags := int32(_SigThrow)
660 if sig < uint32(len(sigtable)) {
661 flags = sigtable[sig].flags
662 if _g_.m.incgo && flags&_SigPanic != 0 {
663 print("Inside sighandler flags ", hex(flags), "sig
", sig, " SigPanic ", hex(_SigPanic), "\n")
664 flags &= ^_SigPanic
665 flags |= _SigThrow
666 print("Inside sighandler flags ", hex(flags), "sig
", sig, " SigPanic ", hex(_SigPanic), "\n")
667
668 }
669 }
2) Solution 2: In sighandler(), When _SigPanic is set in CGO, reset the
flags to _SigThrow.
668 if c.sigcode() != _SI_USER && flags&_SigPanic != 0 &&
_g_.m.incgo {
669 // We can't safely sigpanic because it may grow the
670 // stack. Abort in the signal handler instead.
671 flags = _SigThrow
672 }
Best Regards
Mariappan
…On Thu, Jan 12, 2023 at 10:09 PM Ian Lance Taylor ***@***.***> wrote:
Just removing the _Sigpanic flag will mean that dereferencing a nil
pointer in Go will not cause a panic as it should. I expect that if you do
that some tests will fail. You can run "all.bash" to build the entire tree
and run all the tests, as documented at
https://go.dev/doc/contribute#testing .
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZS4WNH3UMW4E2IRGRDWSAXUNANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
My thinking is to set it to _SigThrow if the signal is not arrived on a user Go stack. I plan to send a CL, but I need to check a few things to make sure it works as expected. Thanks. |
Hi Cherrymui,
What is CL? Shall I go with the following code change? or Do I need to
consider something more?
668 if c.sigcode() != _SI_USER && flags&_SigPanic != 0 &&
_g_.m.incgo {
669 // We can't safely sigpanic because it may grow the
670 // stack. Abort in the signal handler instead.
671 flags = _SigThrow
672 }
Best Regards
Mariappan
…On Fri, Jan 13, 2023 at 11:58 PM cherrymui ***@***.***> wrote:
My thinking is to set it to _SigThrow if the signal is not arrived on a
user Go stack. I plan to send a CL, but I need to check a few things to
make sure it works as expected. Thanks.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZRNRTLJCH5KWEGLZXDWSGNDHANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Change https://go.dev/cl/462437 mentions this issue: |
https://go.dev/cl/462437 is the CL. I'd still need to do more testing. You're welcome to try if the CL fixes your case. Thanks. |
Hi Cherrymui,
I have tested your changes.The fix works fine. Thanks. Please let me know
when the changes will be available.
(gdb) bt
#0 runtime.usleep () at /usr/local/go/src/runtime/sys_linux_amd64.s:140
#1 0x0000000000442e45 in runtime.sighandler (sig=<optimized out>,
info=<optimized out>, ctxt=<optimized out>, gp=0xc000006340)
at /usr/local/go/src/runtime/signal_unix.go:790
#2 0x00000000004421b4 in runtime.sigtrampgo (sig=11, info=0xc00000fbf0,
ctx=0xc00000fac0) at /usr/local/go/src/runtime/signal_unix.go:479
#3 0x00000000004586e6 in runtime.sigtramp () at
/usr/local/go/src/runtime/sys_linux_amd64.s:359
#4 <signal handler called>
#5 0x000000000045ac26 in test1 () at
/home/ubuntu/mbalraj/GO/TEST/TEST1/test.go:8
#6 0x000000000045ac47 in test2 () at
/home/ubuntu/mbalraj/GO/TEST/TEST1/test.go:13
#7 0x000000000045ac62 in test3 () at
/home/ubuntu/mbalraj/GO/TEST/TEST1/test.go:18
#8 0x000000000045ac82 in _cgo_6ac9acc88c92_Cfunc_test3 (v=0xc00005bf70) at
/tmp/go-build/cgo-gcc-prolog:49
#9 0x0000000000456824 in runtime.asmcgocall () at
/usr/local/go/src/runtime/asm_amd64.s:844
#10 0x00000000004e15e0 in ?? ()
#11 0x0000000000000001 in ?? ()
#12 0x000000c000040a00 in ?? ()
#13 0x00007fffcfc97888 in ?? ()
#14 0x0000000000439fa5 in runtime.malg.func1 () at
/usr/local/go/src/runtime/proc.go:4080
#15 0x0000000000456669 in runtime.systemstack () at
/usr/local/go/src/runtime/asm_amd64.s:492
#16 0x0000000000459025 in runtime.newproc (fn=0x1) at <autogenerated>:1
#17 0x00000000004c9780 in runtime[scavenger] ()
#18 0x0000000000000001 in ?? ()
#19 0x0000000000456565 in runtime.mstart () at
/usr/local/go/src/runtime/asm_amd64.s:390
#20 0x00000000004564ef in runtime.rt0_go () at
/usr/local/go/src/runtime/asm_amd64.s:354
#21 0x0000000000000001 in ?? ()
#22 0x00007fffcfc97a08 in ?? ()
#23 0x0000000000000000 in ?? ()
(gdb)
Best Regards
Mariappan
…On Wed, Jan 18, 2023 at 6:20 AM cherrymui ***@***.***> wrote:
https://go.dev/cl/462437 is the CL. I'd still need to do more testing.
You're welcome to try if the CL fixes your case. Thanks.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZSS3PS7JB6NXMVVENDWS447DANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi Cherrymui,
In the following program, the GO program calls C function test3() and
test3() calls test2() and test2 calls test1(). test1() calls exported GO
function Test4(). Test4() does panic when it is called. In this case,
initially go stack and after that C stack and again GO stack. In this case,
I am not seeing the C stack from gdb.Is it possible to handle this case
also to get the complete C stack?
//test.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();
}
*/
import "C"
func main() {
C.test3()
}
//export.go
package main
import "C"
//export Test4
func Test4() {
panic("Panic inside Test4")
}
panic: Panic inside Test4
goroutine 1 [running]:
panic({0x460a80, 0x481770})
/usr/local/go/src/runtime/panic.go:987 +0x3ba fp=0xc000056d38
sp=0xc000056c78 pc=0x42f09a
main.Test4(...)
/home/ubuntu/mbalraj/GO/TEST/TEST4/export.go:7
_cgoexp_040b784f82f8_Test4(0x0?)
_cgo_gotypes.go:51 +0x27 fp=0xc000056d58 sp=0xc000056d38 pc=0x45ac27
runtime.cgocallbackg1(0x45ac00, 0x4c83e0?, 0x0)
/usr/local/go/src/runtime/cgocall.go:316 +0x2c2 fp=0xc000056e28
sp=0xc000056d58 pc=0x404aa2
runtime.cgocallbackg(0xc000006340?, 0x300000002?, 0xc000006340?)
/usr/local/go/src/runtime/cgocall.go:235 +0x109 fp=0xc000056eb8
sp=0xc000056e28 pc=0x404729
runtime.cgocallbackg(0x45ac00, 0x7ffcba5f807f, 0x0)
<autogenerated>:1 +0x2f fp=0xc000056ee0 sp=0xc000056eb8 pc=0x458daf
runtime.cgocallback(0x4045a5, 0x45ad64, 0xc000056f70)
/usr/local/go/src/runtime/asm_amd64.s:994 +0xb4 fp=0xc000056f08
sp=0xc000056ee0 pc=0x456954
runtime.systemstack_switch()
/usr/local/go/src/runtime/asm_amd64.s:459 fp=0xc000056f10 sp=0xc000056f08
pc=0x456620
runtime.cgocall(0x45ad64, 0xc000056f70)
/usr/local/go/src/runtime/cgocall.go:168 +0x85 fp=0xc000056f48
sp=0xc000056f10 pc=0x4045a5
main._Cfunc_test3()
_cgo_gotypes.go:41 +0x45 fp=0xc000056f70 sp=0xc000056f48 pc=0x45aba5
main.main()
/home/ubuntu/mbalraj/GO/TEST/TEST4/test.go:25 +0x17 fp=0xc000056f80
sp=0xc000056f70 pc=0x45abd7
runtime.main()
/usr/local/go/src/runtime/proc.go:250 +0x212 fp=0xc000056fe0
sp=0xc000056f80 pc=0x431d32
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000056fe8
sp=0xc000056fe0 pc=0x456b41
(gdb) bt
#0 runtime.raise () at /usr/local/go/src/runtime/sys_linux_amd64.s:159
#1 0x00000000004433a5 in runtime.dieFromSignal (sig=6) at
/usr/local/go/src/runtime/signal_unix.go:871
#2 0x000000000044393e in runtime.sigfwdgo (sig=6, info=<optimized out>,
ctx=<optimized out>, ~r0=<optimized out>) at
/usr/local/go/src/runtime/signal_unix.go:1087
#3 0x0000000000442047 in runtime.sigtrampgo (sig=0, info=0x0, ctx=0x458421
<runtime.raise+33>) at /usr/local/go/src/runtime/signal_unix.go:432
#4 0x0000000000458706 in runtime.sigtramp () at
/usr/local/go/src/runtime/sys_linux_amd64.s:359
#5 <signal handler called>
#6 runtime.raise () at /usr/local/go/src/runtime/sys_linux_amd64.s:159
#7 0x00000000004433a5 in runtime.dieFromSignal (sig=6) at
/usr/local/go/src/runtime/signal_unix.go:871
#8 0x000000000042f9c9 in runtime.crash () at
/usr/local/go/src/runtime/signal_unix.go:963
#9 runtime.fatalpanic (msgs=<optimized out>) at
/usr/local/go/src/runtime/panic.go:1170
#10 0x000000000042f09a in runtime.gopanic (e=...) at
/usr/local/go/src/runtime/panic.go:987
#11 0x000000000045ac27 in main.Test4 () at
/home/ubuntu/mbalraj/GO/TEST/TEST4/export.go:7
#12 _cgoexp_040b784f82f8_Test4 (a=<optimized out>) at _cgo_gotypes.go:51
#13 0x0000000000404aa2 in runtime.cgocallbackg1 (fn=0x45ac00
<_cgoexp_040b784f82f8_Test4>, frame=0x7ffcba5f807f, ctxt=0) at
/usr/local/go/src/runtime/cgocall.go:316
#14 0x0000000000404729 in runtime.cgocallbackg (fn=0x45ac00
<_cgoexp_040b784f82f8_Test4>, frame=0x7ffcba5f807f, ctxt=0) at
/usr/local/go/src/runtime/cgocall.go:235
#15 0x0000000000458daf in runtime.cgocallbackg (fn=0x45ac00
<_cgoexp_040b784f82f8_Test4>, frame=0x7ffcba5f807f, ctxt=0) at
<autogenerated>:1
#16 0x0000000000456954 in runtime.cgocallback () at
/usr/local/go/src/runtime/asm_amd64.s:994
#17 0x0000000000456620 in ?? ()
#18 0x00000000004045a5 in runtime.cgocall (fn=0x45ad64
<_cgo_040b784f82f8_Cfunc_test3>, arg=0xc000056f70, ~r0=<optimized out>) at
/usr/local/go/src/runtime/cgocall.go:168
#19 0x000000000045aba5 in main._Cfunc_test3 (r1=...) at _cgo_gotypes.go:41
#20 0x000000000045abd7 in main.main () at
/home/ubuntu/mbalraj/GO/TEST/TEST4/test.go:25
Best Regards
Mariappan
On Wed, Jan 18, 2023 at 11:07 AM mariappan balraj <
***@***.***> wrote:
… Hi Cherrymui,
I have tested your changes.The fix works fine. Thanks. Please let me know
when the changes will be available.
(gdb) bt
#0 runtime.usleep () at /usr/local/go/src/runtime/sys_linux_amd64.s:140
#1 0x0000000000442e45 in runtime.sighandler (sig=<optimized out>,
info=<optimized out>, ctxt=<optimized out>, gp=0xc000006340)
at /usr/local/go/src/runtime/signal_unix.go:790
#2 0x00000000004421b4 in runtime.sigtrampgo (sig=11, info=0xc00000fbf0,
ctx=0xc00000fac0) at /usr/local/go/src/runtime/signal_unix.go:479
#3 0x00000000004586e6 in runtime.sigtramp () at
/usr/local/go/src/runtime/sys_linux_amd64.s:359
#4 <signal handler called>
#5 0x000000000045ac26 in test1 () at
/home/ubuntu/mbalraj/GO/TEST/TEST1/test.go:8
#6 0x000000000045ac47 in test2 () at
/home/ubuntu/mbalraj/GO/TEST/TEST1/test.go:13
#7 0x000000000045ac62 in test3 () at
/home/ubuntu/mbalraj/GO/TEST/TEST1/test.go:18
#8 0x000000000045ac82 in _cgo_6ac9acc88c92_Cfunc_test3 (v=0xc00005bf70)
at /tmp/go-build/cgo-gcc-prolog:49
#9 0x0000000000456824 in runtime.asmcgocall () at
/usr/local/go/src/runtime/asm_amd64.s:844
#10 0x00000000004e15e0 in ?? ()
#11 0x0000000000000001 in ?? ()
#12 0x000000c000040a00 in ?? ()
#13 0x00007fffcfc97888 in ?? ()
#14 0x0000000000439fa5 in runtime.malg.func1 () at
/usr/local/go/src/runtime/proc.go:4080
#15 0x0000000000456669 in runtime.systemstack () at
/usr/local/go/src/runtime/asm_amd64.s:492
#16 0x0000000000459025 in runtime.newproc (fn=0x1) at <autogenerated>:1
#17 0x00000000004c9780 in runtime[scavenger] ()
#18 0x0000000000000001 in ?? ()
#19 0x0000000000456565 in runtime.mstart () at
/usr/local/go/src/runtime/asm_amd64.s:390
#20 0x00000000004564ef in runtime.rt0_go () at
/usr/local/go/src/runtime/asm_amd64.s:354
#21 0x0000000000000001 in ?? ()
#22 0x00007fffcfc97a08 in ?? ()
#23 0x0000000000000000 in ?? ()
(gdb)
Best Regards
Mariappan
On Wed, Jan 18, 2023 at 6:20 AM cherrymui ***@***.***>
wrote:
> https://go.dev/cl/462437 is the CL. I'd still need to do more testing.
> You're welcome to try if the CL fixes your case. Thanks.
>
> —
> Reply to this email directly, view it on GitHub
> <#57698 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A25ROZSS3PS7JB6NXMVVENDWS447DANCNFSM6AAAAAATVHEFR4>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
The Go functions and C functions run on different stacks. When test3 calls Test4, internally there is a stack switch, and GDB cannot unwind through that. You may want to try Delve (https://github.com/go-delve/delve), which knows Go's stack switch convention and probably handles this better. |
Hi cherrymui,
I have tried with delve. But delve does not understand C stack. It shows
only the top level GO stack. There is no visibility to Middle C stack and
bottom GO stack.
(dlv) bt
0 0x0000000000458421 in runtime.raise
at /usr/local/go/src/runtime/sys_linux_amd64.s:159
1 0x00000000004433a5 in runtime.dieFromSignal
at /usr/local/go/src/runtime/signal_unix.go:871
2 0x000000000044393e in runtime.sigfwdgo
at /usr/local/go/src/runtime/signal_unix.go:1087
3 0x0000000000442047 in runtime.sigtrampgo
at /usr/local/go/src/runtime/signal_unix.go:432
4 0x0000000000458706 in runtime.sigtramp
at /usr/local/go/src/runtime/sys_linux_amd64.s:359
5 0x00007f64167aa520 in ???
at ?:-1
6 0x000000000042f9c9 in runtime.crash
at /usr/local/go/src/runtime/signal_unix.go:963
7 0x000000000042f9c9 in runtime.fatalpanic
at /usr/local/go/src/runtime/panic.go:1170
8 0x000000000042f09a in runtime.gopanic
at /usr/local/go/src/runtime/panic.go:987
9 0x000000000045ac27 in main.Test4
at ./export.go:7
10 0x000000000045ac27 in _cgoexp_040b784f82f8_Test4
at _cgo_gotypes.go:51
11 0x0000000000404aa2 in runtime.cgocallbackg1
at /usr/local/go/src/runtime/cgocall.go:316
12 0x0000000000404729 in runtime.cgocallbackg
at /usr/local/go/src/runtime/cgocall.go:235
13 0x0000000000458daf in runtime.cgocallbackg
at <autogenerated>:1
14 0x0000000000456954 in runtime.cgocallback
at /usr/local/go/src/runtime/asm_amd64.s:994
15 0x0000000000000001 in ???
at ?:-1
error: error while reading spliced memory at 0xc: EOF
(truncated)
Best regards
Mariappan
…On Thu, 19 Jan, 2023, 12:11 am cherrymui, ***@***.***> wrote:
The Go functions and C functions run on different stacks. When test3 calls
Test4, internally there is a stack switch, and GDB cannot unwind through
that. You may want to try Delve (https://github.com/go-delve/delve),
which knows Go's stack switch convention and probably handles this better.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZVADMSHHCGYTHOWEZDWTA2NZANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hello Go experts,
Can someone please help with this? How to proceed further? This issue is
very common when we go with CGO. GO can call CGO and CGO can call GO
functions. Kindly please help.
Best Regards
Mariappan
On Thu, Jan 19, 2023 at 10:52 AM mariappan balraj <
***@***.***> wrote:
… Hi cherrymui,
I have tried with delve. But delve does not understand C stack. It shows
only the top level GO stack. There is no visibility to Middle C stack and
bottom GO stack.
(dlv) bt
0 0x0000000000458421 in runtime.raise
at /usr/local/go/src/runtime/sys_linux_amd64.s:159
1 0x00000000004433a5 in runtime.dieFromSignal
at /usr/local/go/src/runtime/signal_unix.go:871
2 0x000000000044393e in runtime.sigfwdgo
at /usr/local/go/src/runtime/signal_unix.go:1087
3 0x0000000000442047 in runtime.sigtrampgo
at /usr/local/go/src/runtime/signal_unix.go:432
4 0x0000000000458706 in runtime.sigtramp
at /usr/local/go/src/runtime/sys_linux_amd64.s:359
5 0x00007f64167aa520 in ???
at ?:-1
6 0x000000000042f9c9 in runtime.crash
at /usr/local/go/src/runtime/signal_unix.go:963
7 0x000000000042f9c9 in runtime.fatalpanic
at /usr/local/go/src/runtime/panic.go:1170
8 0x000000000042f09a in runtime.gopanic
at /usr/local/go/src/runtime/panic.go:987
9 0x000000000045ac27 in main.Test4
at ./export.go:7
10 0x000000000045ac27 in _cgoexp_040b784f82f8_Test4
at _cgo_gotypes.go:51
11 0x0000000000404aa2 in runtime.cgocallbackg1
at /usr/local/go/src/runtime/cgocall.go:316
12 0x0000000000404729 in runtime.cgocallbackg
at /usr/local/go/src/runtime/cgocall.go:235
13 0x0000000000458daf in runtime.cgocallbackg
at <autogenerated>:1
14 0x0000000000456954 in runtime.cgocallback
at /usr/local/go/src/runtime/asm_amd64.s:994
15 0x0000000000000001 in ???
at ?:-1
error: error while reading spliced memory at 0xc: EOF
(truncated)
Best regards
Mariappan
On Thu, 19 Jan, 2023, 12:11 am cherrymui, ***@***.***>
wrote:
> The Go functions and C functions run on different stacks. When test3
> calls Test4, internally there is a stack switch, and GDB cannot unwind
> through that. You may want to try Delve (
> https://github.com/go-delve/delve), which knows Go's stack switch
> convention and probably handles this better.
>
> —
> Reply to this email directly, view it on GitHub
> <#57698 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A25ROZVADMSHHCGYTHOWEZDWTA2NZANCNFSM6AAAAAATVHEFR4>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Following is the working source code of GO which uses CGO. From GO code, the c function test3() is called, which calls test2(), which calls test1(). In test1(), there is a NULL pointer assignment, which will cause segmentation fault. To get the core dump, "ulimit -c unlimited" and "echo "core" > /proc/sys/kernel/core_pattern" are run. The code is compiled without optimization by setting env variable CGO_CFLAGS to -g. The program is run by "GOTRACEBACK=crash ./test", which produced core dump. From the core dump, I am not getting complete C stack and it reports corrupt stack. Please note that when I run the program by using gdb, I am getting the complete stack.
package main
/*
#include <stdio.h>
void test1(void) {
int p = (int)NULL;
*p = 30;
}
void test2(void) {
int val = 2;
test1();
}
void test3(void) {
int val = 3;
test2();
}
*/
import "C"
func main() {
C.test3()
}
What did you expect to see?
I am expecting the same C stack which is displayed when the program is run directly by gdb.
gdb ./test
GNU gdb (GDB) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
https://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
warning: Unsupported auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/ubuntu/mbalraj/GO/TEST/test.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) run
Starting program: /home/ubuntu/mbalraj/GO/TEST/test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffd08f7640 (LWP 193717)]
[New Thread 0x7fffcbfff640 (LWP 193718)]
[New Thread 0x7fffcb7fe640 (LWP 193719)]
[New Thread 0x7fffcaffd640 (LWP 193720)]
[New Thread 0x7fffca7fc640 (LWP 193721)]
Thread 1 "test" received signal SIGSEGV, Segmentation fault.
0x000000000045abe6 in test1 () at /home/ubuntu/GO/TEST/test.go:8
8 *p = 30;
(gdb) bt
#0 0x000000000045abe6 in test1 () at /home/ubuntu/GO/TEST/test.go:8
#1 0x000000000045ac07 in test2 () at /home/ubuntu/GO/TEST/test.go:13
#2 0x000000000045ac22 in test3 () at /home/ubuntu/GO/TEST/test.go:18
#3 0x000000000045ac42 in _cgo_6ac9acc88c92_Cfunc_test3 (v=0xc000056f70) at /tmp/go-build/cgo-gcc-prolog:49
#4 0x00000000004567e4 in runtime.asmcgocall () at /usr/local/go/src/runtime/asm_amd64.s:844
#5 0x00000000004e15e0 in ?? ()
#6 0x0000000000000001 in ?? ()
#7 0x000000c000100a00 in ?? ()
#8 0x00007fffffffe2d8 in ?? ()
#9 0x0000000000439fa5 in runtime.malg.func1 () at /usr/local/go/src/runtime/proc.go:4080
#10 0x0000000000456629 in runtime.systemstack () at /usr/local/go/src/runtime/asm_amd64.s:492
#11 0x0000000000458fe5 in runtime.newproc (fn=0x1) at :1
#12 0x00000000004c9780 in runtime[scavenger] ()
#13 0x0000000000000001 in ?? ()
#14 0x0000000000456525 in runtime.mstart () at /usr/local/go/src/runtime/asm_amd64.s:390
#15 0x00000000004564af in runtime.rt0_go () at /usr/local/go/src/runtime/asm_amd64.s:354
#16 0x0000000000000001 in ?? ()
#17 0x00007fffffffe458 in ?? ()
#18 0x0000000000000000 in ?? ()
What did you see instead?
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
[New LWP 193685]
[New LWP 193687]
[New LWP 193686]
[New LWP 193689]
[New LWP 193688]
[New LWP 193690]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by
./test'. Program terminated with signal SIGABRT, Aborted. #0 runtime.raise () at /usr/local/go/src/runtime/sys_linux_amd64.s:159 159 RET [Current thread is 1 (Thread 0x7fdf0cfb7740 (LWP 193685))] warning: Unsupported auto-load script at offset 0 in section .debug_gdb_scripts of file /home/ubuntu/mbalraj/GO/TEST/test. Use
info auto-load python-scripts [REGEXP]' to list them.(gdb) bt
#0 runtime.raise () at /usr/local/go/src/runtime/sys_linux_amd64.s:159
#1 0x0000000000443345 in runtime.dieFromSignal (sig=6) at /usr/local/go/src/runtime/signal_unix.go:870
#2 0x00000000004438de in runtime.sigfwdgo (sig=6, info=, ctx=, ~r0=)
at /usr/local/go/src/runtime/signal_unix.go:1086
#3 0x0000000000442027 in runtime.sigtrampgo (sig=0, info=0x0, ctx=0x4583c1 <runtime.raise+33>) at /usr/local/go/src/runtime/signal_unix.go:432
#4 0x00000000004586a6 in runtime.sigtramp () at /usr/local/go/src/runtime/sys_linux_amd64.s:359
#5
#6 runtime.raise () at /usr/local/go/src/runtime/sys_linux_amd64.s:159
#7 0x0000000000443345 in runtime.dieFromSignal (sig=6) at /usr/local/go/src/runtime/signal_unix.go:870
#8 0x0000000000443558 in runtime.crash () at /usr/local/go/src/runtime/signal_unix.go:962
#9 0x000000000042f891 in runtime.fatalthrow.func1 () at /usr/local/go/src/runtime/panic.go:1129
#10 0x000000000042f80c in runtime.fatalthrow (t=) at /usr/local/go/src/runtime/panic.go:1122
#11 0x000000000042f4bd in runtime.throw (s=...) at /usr/local/go/src/runtime/panic.go:1047
#12 0x0000000000443289 in runtime.sigpanic () at /usr/local/go/src/runtime/signal_unix.go:819
#13 0x000000000045abe6 in test1 () at /home/ubuntu/GO/TEST/test.go:8
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
The text was updated successfully, but these errors were encountered: