-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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:
> ***@***.***>
>
|
Hello GO Experts,
Is there any plan for the fix of this issue?
Best Regards
Mariappan
On Mon, Jan 23, 2023 at 11:42 AM mariappan balraj <
***@***.***> wrote:
… 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:
>> ***@***.***>
>>
>
|
We don't use frame pointer on all platforms. Long term we probably want to add DWARF directives to express the stack transition (on frame pointer platforms we can make it point to the FP). |
Delve supports less than all platforms anyway, if amd64 and arm64 have them it would only leave out i386, which is ok. |
Thanks for your valuable responses. From your responses, following can be
the solutions
1) Delve's stack switching code can be rewritten
2) Go runtime to keep frame pointers correct all the time
3) Add DWARF directives to express the stack transition (Long term solution)
I can try to contribute to the AMD64 platform. From the above items, which
one can I pick up to make core file decode works for all the cases? I think
it looks like solution 2 will be easy to do. Please give your suggestion.
So that I can try my best.
…On Thu, Mar 2, 2023 at 11:33 PM Alessandro Arzilli ***@***.***> wrote:
We don't use frame pointer on all platforms
Delve supports less than all platforms anyway, if amd64 and arm64 have
them it would only leave out i386, which is ok.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZQ2MC72ZKAEPYHEQALW2DOGNANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
@MariappanBalraj solution 2 is already done as part of #58378. Feel free to review the amd64 assembly code in case I missed any spurious Just last week I was prototyping the solution 3 at CL 471715. I don't plan to continue that work on the near future, just wanted to prove feasibility, and the results were good. You can take that as reference and work on a cleaner implementation. AFAIK it hasn't been decided if Go should switch to emitting FP-based unwind information instead of stack deltas, so it would be good to create an issue to discuss it and track the effort. |
To add onto what @aarzilli mentioned above, it would be great to eventually phase out the custom and complex stack switching code within Delve. Improving frame pointer correctness would be a huge step forward, and thanks to those actively working on that. I'd be happy to work on solution 3 for the long term, building on top of the work @qmuntal started (if he doesn't plan on continuing that work himself). |
Hi Quim,
I want to try your changes for solution 2. How to fetch your changeset and
build?
Best Regards
Mariappan
…On Fri, Mar 3, 2023 at 4:12 PM Quim Muntal ***@***.***> wrote:
@MariappanBalraj <https://github.com/MariappanBalraj> solution 2 is
already done as part of #58378 <#58378>.
Feel free to review the amd64 assembly code in case I missed any spurious
NOFRAME.
Just last week I was prototyping the solution 3 at CL 471715
<https://go-review.googlesource.com/c/go/+/471715>. I don't plan to
continue that work on the near future, just wanted to prove feasibility,
and the results were good. You can take that as reference and work on a
cleaner implementation. AFAIK it hasn't been decided if Go should switch to
emitting FP-based unwind information instead of stack deltas, so it would
be good to create an issue to discuss it and track the effort.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZWDT4JCOBQYRDBILV3W2HDIZANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Run this commands: go install golang.org/dl/gotip@latest
gotip download 472195 Then use |
Hi Quim,
I have tried the steps. But still I am seeing the same behavior. Do I need
to pull 466316 also?
(dlv) bt
0 0x000000000045cc41 in runtime.raise
at /root/sdk/gotip/src/runtime/sys_linux_amd64.s:154
1 0x000000000045af68 in runtime.systemstack_switch
at /root/sdk/gotip/src/runtime/asm_amd64.s:469
2 0x0000000000403c1f in runtime.cgocall
at /root/sdk/gotip/src/runtime/cgocall.go:168
3 0x000000000045fd1f in main._Cfunc_test3
at _cgo_gotypes.go:39
4 0x000000000045fd4f in main.main
at ./test.go:26
5 0x00000000004343de in runtime.main
at /root/sdk/gotip/src/runtime/proc.go:250
6 0x000000000045b4a1 in runtime.goexit
at /root/sdk/gotip/src/runtime/asm_amd64.s:1619
Best Regards
Mariappan
…On Wed, Mar 8, 2023 at 3:33 PM Quim Muntal ***@***.***> wrote:
Hi Quim, I want to try your changes for solution 2. How to fetch your
changeset and build?
Run this commands:
go install ***@***.***
gotip download 472195
Then use gotip instead of go for building, testing, etc.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZTIHKVNCHGETAV63XLW3BKQJANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
That CL (and other before it) make sure that runtime functions store the frame pointer on the stack. That per-se is not enough to enable cgo stack unwinding on gdb, as gdb uses DWARF CFI information contained on the binary to unwind the stack. Go is not currently emitting DWARF CFI information that makes use of the frame pointer, but uses stack deltas instead, which don't work when changing the stack pointer. Implementing this is part of solution 3. |
Thanks. Got it. I tried with dlv(delve) also. It is not showing the stack
trace. Do we need to enhance dlv code to make stack unwinding work
correctly? Somehow I am looking for a solution to decode core dump. I am
not specific to GDB or DLV. But I prefer dlv. Kindly please help with this.
Best Regards
Mariappan
…On Wed, Mar 8, 2023 at 6:18 PM Quim Muntal ***@***.***> wrote:
I have tried the steps. But still I am seeing the same behavior. Do I need
to pull 466316 also?
That CL (and other before it) make sure that runtime functions store the
frame pointer on the stack. That per-se is not enough to enable cgo stack
unwinding on gdb, as gdb uses DWARF CFI information contained on the binary
to unwind the stack.
Go is not currently emitting DWARF CFI information that makes use of the
frame pointer, but uses stack deltas instead, which don't work when
changing the stack pointer. Implementing this is part of solution 3.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZXACDW2NMQAZ6ADHDLW3B52ZANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hello, Delve also uses the DWARF information to unwind the stack, so it would also need the fix outlined in solution 3 as well. @qmuntal do you plan to continue your work on that or would you mind if I picked that up? |
Thanks got it. Then how storing function pointer helps?
…On Wed, 8 Mar, 2023, 10:16 pm Derek Parker, ***@***.***> wrote:
Thanks. Got it. I tried with dlv(delve) also. It is not showing the stack
trace. Do we need to enhance dlv code to make stack unwinding work
correctly? Somehow I am looking for a solution to decode core dump. I am
not specific to GDB or DLV. But I prefer dlv. Kindly please help with this.
Hello,
Delve also uses the DWARF information to unwind the stack, so it would
also need the fix outlined in solution 3 as well.
@qmuntal <https://github.com/qmuntal> do you plan to continue your work
on that or would you mind if I picked that up?
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZS47CPXN3ATFHLW76DW3CZWFANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I somewhat misspoke (mistyped?) in that Delve does use frame pointers in certain circumstances but it isn't the main mode of stack unwinding, we also do rely on the DWARF unwind information when present. Solution 2 and 3 somewhat go hand in hand because if we can keep frame pointers correct then we can utilize them in the DWARF unwind information for easier, less error prone stack unwinding when switching stacks. |
I've looked a bit more at this and what happens with delve is that we see that the current goroutine is g0, executing a runtime function, and we switch to the goroutine stack. There are two problems with this:
|
@derekparker feel free to pick that CL and evolve it. I'll probably update it once https://go-review.googlesource.com/c/go/+/472195 is merged. |
Hi Quim,
The code changes which you have done for proto typing DWARF addition, will
it solve any issue? Can you please share me the test code which I can use
to test your changes?
…On Thu, 9 Mar, 2023, 2:13 am Quim Muntal, ***@***.***> wrote:
@qmuntal <https://github.com/qmuntal> do you plan to continue your work
on that or would you mind if I picked that up?
@derekparker <https://github.com/derekparker> feel free to pick that CL
and evolve it. I'll probably update it once
https://go-review.googlesource.com/c/go/+/472195 is merged.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZUUWYOO5LDCMSZOX6LW3DVOXANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
No worries, I'll hold off for now while you're still working on it, I was just going to work on it if you weren't planning on doing any more work on it yourself. |
I've just updated a couple of things and now I'm 100% done with that prototype. You can take it from here 😄. |
Hi Quim,
Could you please help me to understand what is done as part of CL 471715
<https://go-review.googlesource.com/c/go/+/471715> prototyping?
Best Regards
Mariappan
…On Mon, Mar 13, 2023 at 9:19 PM Quim Muntal ***@***.***> wrote:
No worries, I'll hold off for now while you're still working on it, I was
just going to work on it if you weren't planning on doing any more work on
it yourself.
I've just updated a couple of things and now I'm 100% done with that
prototype. You can take it from here 😄.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZQYWEYSNYTJJOK7RN3W346XBANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi Quim/Derek,
I have gone through the code changes done as part of CL 471715. It looks
like DWARF CFA information is added. But I am not getting full context. I
have pulled the code changes to see exactly what it fixes. I have used the
following test program and checked the BT. I am not seeing any difference.
Am I missing something? It is good if you can share some information.
Kindly please help.
package main
// static int eee() { asm("int $3"); return 1; }
import "C"
//go:noinline
func eee() bool { return C.eee() == 1 }
//go:noinline
func aaa() bool { return bbb() }
//go:noinline
func bbb() bool { return ccc() }
//go:noinline
func ccc() bool { return ddd() }
//go:noinline
func ddd() bool { return f() }
var f = eee
func main() {
_ = aaa()
}
Best Regards
Mariappan
On Thu, Mar 16, 2023 at 9:34 AM mariappan balraj ***@***.***>
wrote:
… Hi Quim,
Could you please help me to understand what is done as part of CL 471715
<https://go-review.googlesource.com/c/go/+/471715> prototyping?
Best Regards
Mariappan
On Mon, Mar 13, 2023 at 9:19 PM Quim Muntal ***@***.***>
wrote:
> No worries, I'll hold off for now while you're still working on it, I was
> just going to work on it if you weren't planning on doing any more work on
> it yourself.
>
> I've just updated a couple of things and now I'm 100% done with that
> prototype. You can take it from here 😄.
>
> —
> Reply to this email directly, view it on GitHub
> <#57698 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A25ROZQYWEYSNYTJJOK7RN3W346XBANCNFSM6AAAAAATVHEFR4>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Hello Go Experts,
It looks like people are so busy. I am not seeing any reply. I am able to
understand that everyone has their own commitments. Sorry for disturbing
you people.
If I am not able to get the solution for this problem then we may drop
using GOLANG. I am ready to contribute. But I need some help to start with
it. It looks like fixing the GO compiler may take some time. Is it possible
to change dlv code to make it work? Is there a way to get complete stack
unwinding information from the core dump? At least if someone can help me
to unwind the stack manually from the core dump then that may help. I am
seeking strong support from you people.
Best Regards
Mariappan
On Mon, Mar 20, 2023 at 11:44 AM mariappan balraj <
***@***.***> wrote:
… Hi Quim/Derek,
I have gone through the code changes done as part of CL 471715. It looks
like DWARF CFA information is added. But I am not getting full context. I
have pulled the code changes to see exactly what it fixes. I have used the
following test program and checked the BT. I am not seeing any difference.
Am I missing something? It is good if you can share some information.
Kindly please help.
package main
// static int eee() { asm("int $3"); return 1; }
import "C"
//go:noinline
func eee() bool { return C.eee() == 1 }
//go:noinline
func aaa() bool { return bbb() }
//go:noinline
func bbb() bool { return ccc() }
//go:noinline
func ccc() bool { return ddd() }
//go:noinline
func ddd() bool { return f() }
var f = eee
func main() {
_ = aaa()
}
Best Regards
Mariappan
On Thu, Mar 16, 2023 at 9:34 AM mariappan balraj <
***@***.***> wrote:
> Hi Quim,
>
> Could you please help me to understand what is done as part of CL 471715
> <https://go-review.googlesource.com/c/go/+/471715> prototyping?
>
> Best Regards
> Mariappan
>
> On Mon, Mar 13, 2023 at 9:19 PM Quim Muntal ***@***.***>
> wrote:
>
>> No worries, I'll hold off for now while you're still working on it, I
>> was just going to work on it if you weren't planning on doing any more work
>> on it yourself.
>>
>> I've just updated a couple of things and now I'm 100% done with that
>> prototype. You can take it from here 😄.
>>
>> —
>> Reply to this email directly, view it on GitHub
>> <#57698 (comment)>, or
>> unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/A25ROZQYWEYSNYTJJOK7RN3W346XBANCNFSM6AAAAAATVHEFR4>
>> .
>> You are receiving this because you were mentioned.Message ID:
>> ***@***.***>
>>
>
|
About the test case I added in CL 471715, it also fails form time to time on my machine, we might be hitting the same issue.
As I mentioned earlier, I don't have the knowledge now the time to fix cgo stack unwinding on gdb. I submitted CL 471715 in case it is useful for someone else. Can't give more support than that. |
Hi Quim,
Thanks for replying. I could able to understand you completely. I am just
trying to understand exactly what you have done for CL 471715. How will it
be helpful for others to proceed? I hope you might have solved some
specific case by adding DWARF information. Also, you might have tested the
specific case. If you can share those knowledge, then it helps a lot. Also
by adding DWARF information, will gdb and delve debugger able to dump the
back trace? Or do we need to enhance gdb and delve debugger code?
Best Regards
Mariappan
…On Tue, Mar 21, 2023 at 7:12 PM Quim Muntal ***@***.***> wrote:
have gone through the code changes done as part of CL 471715. It looks
like DWARF CFA information is added. But I am not getting full context.
About the test case I added in CL 471715, it also fails form time to time
on my machine, we might be hitting the same issue.
I am seeking strong support from you people.
As I mentioned earlier, I don't have the knowledge now the time to fix cgo
stack unwinding on gdb. I submitted CL 471715 in case it is useful for
someone else. Can't give more support than that.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZREIZRHK6UPBYEQIVTW5GV5VANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hello Go Experts,
I have spent some time in debugging this issue. I have manually unwind the
stack by using the RBP register(Frame pointer). From this analysis, it
shows that there is no problem with the debugger DLV. The system
stack(operating system) itself got corrupted. To dig the issue further, I
used DLV to find out exactly where it got corrupted. The corruption is
happening in the function runtime.unwindm() after the following line.
330: sched := &mp.g0.sched
=> 331: sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp +
alignUp(sys.MinFrameSize, sys.StackAlign)))
(dlv) p mp.g0.sched
runtime.gobuf {sp: 140723152360248, pc: 4418654, g: 4970112, ctxt:
unsafe.Pointer(0x0), ret: 0, lr: 0, bp: 0}
140723152360248 ===> 0x7FFCA9821338 This points to the system stack region
which is corrupting.
For me it looks like, when the CGO is used, this code is not working
correctly. This looks like a bug in the GO compiler and not in the DLV
debugger. Please give me some direction to fix this issue. So that, I can
work on the fix.
***@***.***:/home/soomohan/mbalraj/test# go version
go version go1.18.1 linux/amd64
(dlv) bt
0 0x0000000000404d8d in runtime.unwindm
at /usr/lib/go-1.18/src/runtime/cgocall.go:331
1 0x0000000000404cc6 in runtime.cgocallbackg1.func3
at /usr/lib/go-1.18/src/runtime/cgocall.go:303
2 0x00000000004316a2 in runtime.deferCallSave
at /usr/lib/go-1.18/src/runtime/panic.go:750
3 0x0000000000431575 in runtime.runOpenDeferFrame
at /usr/lib/go-1.18/src/runtime/panic.go:723
4 0x0000000000431909 in runtime.gopanic
at /usr/lib/go-1.18/src/runtime/panic.go:838
5 0x000000000045eee7 in main.Test4
at ./export.go:7
6 0x000000000045ef5c in _cgoexp_e908740ad8ca_Test4
at _cgo_gotypes.go:51
7 0x0000000000404bd3 in runtime.cgocallbackg1
at /usr/lib/go-1.18/src/runtime/cgocall.go:314
8 0x0000000000404879 in runtime.cgocallbackg
at /usr/lib/go-1.18/src/runtime/cgocall.go:233
9 0x000000000045c60f in runtime.cgocallbackg
at <autogenerated>:1
10 0x000000000045a194 in runtime.cgocallback
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:971
11 0x000000000045d77d in crosscall2 ===============> Looks fine
at /usr/lib/go-1.18/src/runtime/cgo/asm_amd64.s:30
12 0x000000000045efc6 in C.Test4
at _cgo_export.c:33
13 0x000000000045f072 in C.test1
at cgo-builtin-prolog:9
14 0x000000000045f08d in C.test2
at cgo-builtin-prolog:14
15 0x000000000045f0a8 in C.test3
at cgo-builtin-prolog:19
16 0x000000000045f0c8 in C._cgo_e908740ad8ca_Cfunc_test3
at /tmp/go-build:49
17 0x000000000045a084 in runtime.asmcgocall
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:821
18 0x000000000045f0ab in C._cgo_e908740ad8ca_Cfunc_test3
at /tmp/go-build:44
19 0x000000000040470a in runtime.cgocall
at /usr/lib/go-1.18/src/runtime/cgocall.go:167
20 0x000000000045ee85 in main._Cfunc_test3
at _cgo_gotypes.go:41
21 0x000000000045ef17 in main.main
at ./hello.go:25
22 0x0000000000434578 in runtime.main
at /usr/lib/go-1.18/src/runtime/proc.go:250
23 0x000000000045a381 in runtime.goexit
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:1571
(dlv) list
runtime.unwindm() /usr/lib/go-1.18/src/runtime/cgocall.go:331 (hits
goroutine(1):1 total:1) (PC: 0x404d8d)
Warning: debugging optimized function
326: if *restore {
327: // Restore sp saved by cgocallback during
328: // unwind of g's stack (see comment at top of file).
329: mp := acquirem()
330: sched := &mp.g0.sched
=> 331: sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp +
alignUp(sys.MinFrameSize, sys.StackAlign)))
332:
333: // Do the accounting that cgocall will not have a
chance to do
334: // during an unwind.
335: //
336: // In the case where a Go call originates from C,
ncgo is 0
(dlv) p mp.g0.sched
runtime.gobuf {sp: 140723152360248, pc: 4418654, g: 4970112, ctxt:
unsafe.Pointer(0x0), ret: 0, lr: 0, bp: 0}
(dlv) n
runtime.unwindm() /usr/lib/go-1.18/src/runtime/cgocall.go:338 (PC:
0x404da9)
Warning: debugging optimized function
333: // Do the accounting that cgocall will not have a
chance to do
334: // during an unwind.
335: //
336: // In the case where a Go call originates from C,
ncgo is 0
337: // and there is no matching cgocall to end.
=> 338: if mp.ncgo > 0 {
339: mp.incgo = false
340: mp.ncgo--
341: osPreemptExtExit(mp)
342: }
343:
(dlv) bt
0 0x0000000000404da9 in runtime.unwindm
at /usr/lib/go-1.18/src/runtime/cgocall.go:338
1 0x0000000000404cc6 in runtime.cgocallbackg1.func3
at /usr/lib/go-1.18/src/runtime/cgocall.go:303
2 0x00000000004316a2 in runtime.deferCallSave
at /usr/lib/go-1.18/src/runtime/panic.go:750
3 0x0000000000431575 in runtime.runOpenDeferFrame
at /usr/lib/go-1.18/src/runtime/panic.go:723
4 0x0000000000431909 in runtime.gopanic
at /usr/lib/go-1.18/src/runtime/panic.go:838
5 0x000000000045eee7 in main.Test4
at ./export.go:7
6 0x000000000045ef5c in _cgoexp_e908740ad8ca_Test4
at _cgo_gotypes.go:51
7 0x0000000000404bd3 in runtime.cgocallbackg1
at /usr/lib/go-1.18/src/runtime/cgocall.go:314
8 0x0000000000404879 in runtime.cgocallbackg
at /usr/lib/go-1.18/src/runtime/cgocall.go:233
9 0x000000000045c60f in runtime.cgocallbackg
at <autogenerated>:1
10 0x000000000045a194 in runtime.cgocallback
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:971
11 0x0000000000000001 in ??? ====> Problem started because of stack got
corrupted
at ?:-1
12 0x000000000045efc6 in C.Test4
at _cgo_export.c:33
13 0x000000000045f072 in C.test1
at cgo-builtin-prolog:9
14 0x000000000045f08d in C.test2
at cgo-builtin-prolog:14
15 0x000000000045f0a8 in C.test3
at cgo-builtin-prolog:19
16 0x000000000045f0c8 in C._cgo_e908740ad8ca_Cfunc_test3
at /tmp/go-build:49
17 0x000000000045a084 in runtime.asmcgocall
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:821
18 0x000000000045f0ab in C._cgo_e908740ad8ca_Cfunc_test3
at /tmp/go-build:44
19 0x000000000040470a in runtime.cgocall
at /usr/lib/go-1.18/src/runtime/cgocall.go:167
20 0x000000000045ee85 in main._Cfunc_test3
at _cgo_gotypes.go:41
21 0x000000000045ef17 in main.main
at ./hello.go:25
22 0x0000000000434578 in runtime.main
at /usr/lib/go-1.18/src/runtime/proc.go:250
23 0x000000000045a381 in runtime.goexit
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:1571
(dlv)
Best Regards
Mariappan
On Tue, Mar 21, 2023 at 9:34 PM mariappan balraj ***@***.***>
wrote:
… Hi Quim,
Thanks for replying. I could able to understand you completely. I am just
trying to understand exactly what you have done for CL 471715. How will it
be helpful for others to proceed? I hope you might have solved some
specific case by adding DWARF information. Also, you might have tested the
specific case. If you can share those knowledge, then it helps a lot. Also
by adding DWARF information, will gdb and delve debugger able to dump the
back trace? Or do we need to enhance gdb and delve debugger code?
Best Regards
Mariappan
On Tue, Mar 21, 2023 at 7:12 PM Quim Muntal ***@***.***>
wrote:
> have gone through the code changes done as part of CL 471715. It looks
> like DWARF CFA information is added. But I am not getting full context.
>
> About the test case I added in CL 471715, it also fails form time to time
> on my machine, we might be hitting the same issue.
>
> I am seeking strong support from you people.
>
> As I mentioned earlier, I don't have the knowledge now the time to fix
> cgo stack unwinding on gdb. I submitted CL 471715 in case it is useful for
> someone else. Can't give more support than that.
>
> —
> Reply to this email directly, view it on GitHub
> <#57698 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A25ROZREIZRHK6UPBYEQIVTW5GV5VANCNFSM6AAAAAATVHEFR4>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Hello Go Experts,
It looks like all are busy. Could you please give your support? It is good
if you can give your inputs for my previous email.
Best Regards
Mariappan
On Fri, Mar 24, 2023 at 8:36 PM mariappan balraj ***@***.***>
wrote:
… Hello Go Experts,
I have spent some time in debugging this issue. I have manually unwind the
stack by using the RBP register(Frame pointer). From this analysis, it
shows that there is no problem with the debugger DLV. The system
stack(operating system) itself got corrupted. To dig the issue further, I
used DLV to find out exactly where it got corrupted. The corruption is
happening in the function runtime.unwindm() after the following line.
330: sched := &mp.g0.sched
=> 331: sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp +
alignUp(sys.MinFrameSize, sys.StackAlign)))
(dlv) p mp.g0.sched
runtime.gobuf {sp: 140723152360248, pc: 4418654, g: 4970112, ctxt:
unsafe.Pointer(0x0), ret: 0, lr: 0, bp: 0}
140723152360248 ===> 0x7FFCA9821338 This points to the system stack region
which is corrupting.
For me it looks like, when the CGO is used, this code is not working
correctly. This looks like a bug in the GO compiler and not in the DLV
debugger. Please give me some direction to fix this issue. So that, I can
work on the fix.
***@***.***:/home/soomohan/mbalraj/test# go version
go version go1.18.1 linux/amd64
(dlv) bt
0 0x0000000000404d8d in runtime.unwindm
at /usr/lib/go-1.18/src/runtime/cgocall.go:331
1 0x0000000000404cc6 in runtime.cgocallbackg1.func3
at /usr/lib/go-1.18/src/runtime/cgocall.go:303
2 0x00000000004316a2 in runtime.deferCallSave
at /usr/lib/go-1.18/src/runtime/panic.go:750
3 0x0000000000431575 in runtime.runOpenDeferFrame
at /usr/lib/go-1.18/src/runtime/panic.go:723
4 0x0000000000431909 in runtime.gopanic
at /usr/lib/go-1.18/src/runtime/panic.go:838
5 0x000000000045eee7 in main.Test4
at ./export.go:7
6 0x000000000045ef5c in _cgoexp_e908740ad8ca_Test4
at _cgo_gotypes.go:51
7 0x0000000000404bd3 in runtime.cgocallbackg1
at /usr/lib/go-1.18/src/runtime/cgocall.go:314
8 0x0000000000404879 in runtime.cgocallbackg
at /usr/lib/go-1.18/src/runtime/cgocall.go:233
9 0x000000000045c60f in runtime.cgocallbackg
at <autogenerated>:1
10 0x000000000045a194 in runtime.cgocallback
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:971
11 0x000000000045d77d in crosscall2 ===============> Looks fine
at /usr/lib/go-1.18/src/runtime/cgo/asm_amd64.s:30
12 0x000000000045efc6 in C.Test4
at _cgo_export.c:33
13 0x000000000045f072 in C.test1
at cgo-builtin-prolog:9
14 0x000000000045f08d in C.test2
at cgo-builtin-prolog:14
15 0x000000000045f0a8 in C.test3
at cgo-builtin-prolog:19
16 0x000000000045f0c8 in C._cgo_e908740ad8ca_Cfunc_test3
at /tmp/go-build:49
17 0x000000000045a084 in runtime.asmcgocall
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:821
18 0x000000000045f0ab in C._cgo_e908740ad8ca_Cfunc_test3
at /tmp/go-build:44
19 0x000000000040470a in runtime.cgocall
at /usr/lib/go-1.18/src/runtime/cgocall.go:167
20 0x000000000045ee85 in main._Cfunc_test3
at _cgo_gotypes.go:41
21 0x000000000045ef17 in main.main
at ./hello.go:25
22 0x0000000000434578 in runtime.main
at /usr/lib/go-1.18/src/runtime/proc.go:250
23 0x000000000045a381 in runtime.goexit
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:1571
(dlv) list
> runtime.unwindm() /usr/lib/go-1.18/src/runtime/cgocall.go:331 (hits
goroutine(1):1 total:1) (PC: 0x404d8d)
Warning: debugging optimized function
326: if *restore {
327: // Restore sp saved by cgocallback during
328: // unwind of g's stack (see comment at top of
file).
329: mp := acquirem()
330: sched := &mp.g0.sched
=> 331: sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp +
alignUp(sys.MinFrameSize, sys.StackAlign)))
332:
333: // Do the accounting that cgocall will not have a
chance to do
334: // during an unwind.
335: //
336: // In the case where a Go call originates from C,
ncgo is 0
(dlv) p mp.g0.sched
runtime.gobuf {sp: 140723152360248, pc: 4418654, g: 4970112, ctxt:
unsafe.Pointer(0x0), ret: 0, lr: 0, bp: 0}
(dlv) n
> runtime.unwindm() /usr/lib/go-1.18/src/runtime/cgocall.go:338 (PC:
0x404da9)
Warning: debugging optimized function
333: // Do the accounting that cgocall will not have a
chance to do
334: // during an unwind.
335: //
336: // In the case where a Go call originates from C,
ncgo is 0
337: // and there is no matching cgocall to end.
=> 338: if mp.ncgo > 0 {
339: mp.incgo = false
340: mp.ncgo--
341: osPreemptExtExit(mp)
342: }
343:
(dlv) bt
0 0x0000000000404da9 in runtime.unwindm
at /usr/lib/go-1.18/src/runtime/cgocall.go:338
1 0x0000000000404cc6 in runtime.cgocallbackg1.func3
at /usr/lib/go-1.18/src/runtime/cgocall.go:303
2 0x00000000004316a2 in runtime.deferCallSave
at /usr/lib/go-1.18/src/runtime/panic.go:750
3 0x0000000000431575 in runtime.runOpenDeferFrame
at /usr/lib/go-1.18/src/runtime/panic.go:723
4 0x0000000000431909 in runtime.gopanic
at /usr/lib/go-1.18/src/runtime/panic.go:838
5 0x000000000045eee7 in main.Test4
at ./export.go:7
6 0x000000000045ef5c in _cgoexp_e908740ad8ca_Test4
at _cgo_gotypes.go:51
7 0x0000000000404bd3 in runtime.cgocallbackg1
at /usr/lib/go-1.18/src/runtime/cgocall.go:314
8 0x0000000000404879 in runtime.cgocallbackg
at /usr/lib/go-1.18/src/runtime/cgocall.go:233
9 0x000000000045c60f in runtime.cgocallbackg
at <autogenerated>:1
10 0x000000000045a194 in runtime.cgocallback
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:971
11 0x0000000000000001 in ??? ====> Problem started because of stack got
corrupted
at ?:-1
12 0x000000000045efc6 in C.Test4
at _cgo_export.c:33
13 0x000000000045f072 in C.test1
at cgo-builtin-prolog:9
14 0x000000000045f08d in C.test2
at cgo-builtin-prolog:14
15 0x000000000045f0a8 in C.test3
at cgo-builtin-prolog:19
16 0x000000000045f0c8 in C._cgo_e908740ad8ca_Cfunc_test3
at /tmp/go-build:49
17 0x000000000045a084 in runtime.asmcgocall
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:821
18 0x000000000045f0ab in C._cgo_e908740ad8ca_Cfunc_test3
at /tmp/go-build:44
19 0x000000000040470a in runtime.cgocall
at /usr/lib/go-1.18/src/runtime/cgocall.go:167
20 0x000000000045ee85 in main._Cfunc_test3
at _cgo_gotypes.go:41
21 0x000000000045ef17 in main.main
at ./hello.go:25
22 0x0000000000434578 in runtime.main
at /usr/lib/go-1.18/src/runtime/proc.go:250
23 0x000000000045a381 in runtime.goexit
at /usr/lib/go-1.18/src/runtime/asm_amd64.s:1571
(dlv)
Best Regards
Mariappan
On Tue, Mar 21, 2023 at 9:34 PM mariappan balraj <
***@***.***> wrote:
> Hi Quim,
>
>
> Thanks for replying. I could able to understand you completely. I am just
> trying to understand exactly what you have done for CL 471715. How will it
> be helpful for others to proceed? I hope you might have solved some
> specific case by adding DWARF information. Also, you might have tested the
> specific case. If you can share those knowledge, then it helps a lot. Also
> by adding DWARF information, will gdb and delve debugger able to dump the
> back trace? Or do we need to enhance gdb and delve debugger code?
>
>
> Best Regards
>
> Mariappan
>
> On Tue, Mar 21, 2023 at 7:12 PM Quim Muntal ***@***.***>
> wrote:
>
>> have gone through the code changes done as part of CL 471715. It looks
>> like DWARF CFA information is added. But I am not getting full context.
>>
>> About the test case I added in CL 471715, it also fails form time to
>> time on my machine, we might be hitting the same issue.
>>
>> I am seeking strong support from you people.
>>
>> As I mentioned earlier, I don't have the knowledge now the time to fix
>> cgo stack unwinding on gdb. I submitted CL 471715 in case it is useful for
>> someone else. Can't give more support than that.
>>
>> —
>> Reply to this email directly, view it on GitHub
>> <#57698 (comment)>, or
>> unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/A25ROZREIZRHK6UPBYEQIVTW5GV5VANCNFSM6AAAAAATVHEFR4>
>> .
>> You are receiving this because you were mentioned.Message ID:
>> ***@***.***>
>>
>
|
If a panicking signal (e.g. SIGSEGV) happens on a g0 stack, we're either in the runtime or running C code. Either way we cannot recover and sigpanic will immediately throw. Further, injecting a sigpanic could make the C stack unwinder and the debugger fail to unwind the stack. So don't inject a sigpanic. If we have cgo traceback and symbolizer attached, if it panics in a C function ("CF" for the example below), previously it shows something like fatal error: unexpected signal during runtime execution [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x45f1ef] runtime stack: runtime.throw({0x485460?, 0x0?}) .../runtime/panic.go:1076 +0x5c fp=0x7ffd77f60f58 sp=0x7ffd77f60f28 pc=0x42e39c runtime.sigpanic() .../runtime/signal_unix.go:821 +0x3e9 fp=0x7ffd77f60fb8 sp=0x7ffd77f60f58 pc=0x442229 goroutine 1 [syscall]: CF /tmp/pp/c.c:6 pc=0x45f1ef runtime.asmcgocall .../runtime/asm_amd64.s:869 pc=0x458007 runtime.cgocall(0x45f1d0, 0xc000053f70) .../runtime/cgocall.go:158 +0x51 fp=0xc000053f48 sp=0xc000053f10 pc=0x404551 main._Cfunc_CF() _cgo_gotypes.go:39 +0x3f fp=0xc000053f70 sp=0xc000053f48 pc=0x45f0bf Now it shows SIGSEGV: segmentation violation PC=0x45f1ef m=0 sigcode=1 signal arrived during cgo execution goroutine 1 [syscall]: CF /tmp/pp/c.c:6 pc=0x45f1ef runtime.asmcgocall .../runtime/asm_amd64.s:869 pc=0x458007 runtime.cgocall(0x45f1d0, 0xc00004ef70) .../runtime/cgocall.go:158 +0x51 fp=0xc00004ef48 sp=0xc00004ef10 pc=0x404551 main._Cfunc_CF() _cgo_gotypes.go:39 +0x3f fp=0xc00004ef70 sp=0xc00004ef48 pc=0x45f0bf I think the new one is reasonable. For #57698. Change-Id: I4f7af91761374e9b569dce4c7587499d4799137e Reviewed-on: https://go-review.googlesource.com/c/go/+/462437 Reviewed-by: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Cherry Mui <[email protected]>
The key improvement of CL 471715 is that it emits the Unfortunately, doing so requires more knowledge about the assembly instructions and functions stack layout than available to the Go linker, so I had to move part of the DWARF processing to the Go compiler. That's why CL 471715 has so many changes for just adding a single DWARF instruction. |
Hi Quim,
Thanks for inputs. It really helps. For me it looks like in this particular
case, stack unwinding is not working because of stack corruption in case of
calling runtime.gopanic(). I gave my analysis as part of different email
thread with reason why I am thinking so. Eagerly waiting for the experts
support.
Best Regards
Mariappan
…On Tue, 28 Mar, 2023, 9:05 pm Quim Muntal, ***@***.***> wrote:
I am just
trying to understand exactly what you have done for CL 471715. How will it
be helpful for others to proceed?
The key improvement of CL 471715 is that it emits the
DW_CFA_def_cfa_register instruction when a function prologue sets the
frame pointer. This instruction can be used by debuggers to know in which
register the current frame pointer is stored, making stack unwinding easier
and more robust. Without that CL, the Go toolchain only emits
DW_CFA_def_cfa_offset and DW_CFA_advance_loc instructions, which can't
correctly model the stack switching that happens in cgo calls.
Unfortunately, doing so requires more knowledge about the assembly
instructions and functions stack layout than available to the Go linker, so
I had to move part of the DWARF processing to the Go compiler. That's why
CL 471715 has so many changes for just adding a single DWARF instruction.
—
Reply to this email directly, view it on GitHub
<#57698 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25ROZTX4IDAMYLO53SZFU3W6MANXANCNFSM6AAAAAATVHEFR4>
.
You are receiving this because you were mentioned.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: