Skip to content
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

When assert is called from C code, dlv is not able to decode the core dump. #3322

Open
MariappanBalraj opened this issue Apr 3, 2023 · 4 comments

Comments

@MariappanBalraj
Copy link

MariappanBalraj commented Apr 3, 2023

Please answer the following before submitting your issue:

Note: Please include any substantial examples (debug session output,
stacktraces, etc) as linked gists.

If this is about source listing not showing up (or breakpoints not being
accepted) while running in a container please read our
FAQ
first.

  1. What version of Delve are you using (dlv version)? 1.20.1
  2. What version of Go are you using? (go version)? 1.20.2
  3. What operating system and processor architecture are you using? linux/amd64
  4. What did you do?

CGO_CFLAGS="-g" go build -gcflags=all="-N -l" hello.go
hello.go

package main

/*
#include <stdio.h>
#include <assert.h>

void test1(void) {
    assert(0);
}

void test2(void) {
    int val = 2;
    test1();
}

void test3(void) {
    int val = 3;
    test2();
}

*/
import "C"

func main() {
    C.test3()
}
  1. What did you expect to see?
    gdb is able to decode to some extent.
(gdb) thread 5
[Switching to thread 5 (Thread 0x150e8f7a5740 (LWP 1006394))]
#0  runtime.usleep () at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:135
135             RET
(gdb) bt
#0  runtime.usleep () at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:135
#1  0x00000000004494aa in runtime.sighandler (sig=6, info=<optimized out>, ctxt=<optimized out>, gp=0xc0000061a0)
    at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:791
#2  0x0000000000448965 in runtime.sigtrampgo (sig=6, info=0xc00000f4b0, ctx=0xc00000f380)
    at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:479
#3  0x00000000004611a6 in runtime.sigtramp () at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:352
#4  <signal handler called>
#5  __pthread_kill_implementation (no_tid=0, signo=6, threadid=23152280885056) at ./nptl/pthread_kill.c:44
#6  __pthread_kill_internal (signo=6, threadid=23152280885056) at ./nptl/pthread_kill.c:78
#7  __GI___pthread_kill (threadid=23152280885056, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#8  0x0000150e8f7ea476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#9  0x0000150e8f7d07f3 in __GI_abort () at ./stdlib/abort.c:79
#10 0x0000150e8f7d071b in __assert_fail_base (fmt=0x150e8f985150 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x47f334 "0",
    file=0x47f308 "/home/soomohan/mbalraj/test_assert/hello.go", line=8, function=<optimized out>) at ./assert/assert.c:92
#11 0x0000150e8f7e1e96 in __GI___assert_fail (assertion=0x47f334 "0", file=0x47f308 "/home/soomohan/mbalraj/test_assert/hello.go", line=8,
    function=0x47f336 <__PRETTY_FUNCTION__.0> "test1") at ./assert/assert.c:101
#12 0x0000000000464475 in test1 () at /home/soomohan/mbalraj/test_assert/hello.go:8
#13 0x000000000046448d in test2 () at /home/soomohan/mbalraj/test_assert/hello.go:13
#14 0x00000000004644a8 in test3 () at /home/soomohan/mbalraj/test_assert/hello.go:18
#15 0x00000000004644c8 in _cgo_55ddea9956f0_Cfunc_test3 (v=0xc000048f70) at /tmp/go-build/cgo-gcc-prolog:49
#16 0x000000000045f304 in runtime.asmcgocall () at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:848
#17 0x00000000004e3480 in ?? ()
#18 0x0000000000000001 in ?? ()
#19 0x000000c000102100 in ?? ()
#20 0x0a007fff922734b8 in ?? ()
#21 0x0000000000000001 in ?? ()
#22 0x00000000000000f8 in ?? ()
#23 0x000000c0000061a0 in ?? ()
#24 0x000000c000048af8 in ?? ()
#25 0x000000000045f149 in runtime.systemstack () at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:496
#26 0x0000000000461dc5 in runtime.newproc (fn=0x1) at <autogenerated>:1
#27 0x00000000004cc740 in runtime[scavenger] ()
#28 0x0000000000000001 in ?? ()
#29 0x000000000045f045 in runtime.mstart () at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:394
#30 0x000000000045efcf in runtime.rt0_go () at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s:358
#31 0x0000000000000001 in ?? ()
#32 0x00007fff92273638 in ?? ()
#33 0x0000000000000000 in ?? ()
(gdb) frame 12
#12 0x0000000000464475 in test1 () at /home/soomohan/mbalraj/test_assert/hello.go:8
8           assert(0);
(gdb) info reg
rbp            0x7fff92273400      0x7fff92273400
rip            0x464475            0x464475 <test2>
  1. What did you see instead?
(dlv) bt
0  0x0000000000460e7d in runtime.usleep
   at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:135
1  0x00000000004494aa in runtime.sighandler
   at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:791
2  0x0000000000448965 in runtime.sigtrampgo
   at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/signal_unix.go:479
3  0x00000000004611a6 in runtime.sigtramp
   at /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/sys_linux_amd64.s:352
4  0x0000150e8f7ea520 in ???
   at ?:-1
   error: error while reading spliced memory at 0xf5b42: EOF

//test.star

def command_goroutine_start_line(args):
    regs = registers(ThreadID=996049).Regs
    #print(regs)
    rip = 0
    for reg in regs:
        if reg.Name == "Rbp":
            rbp = int(reg.Value, 16)
        elif reg.Name == "Rip":
            rip = int(reg.Value, 16)

    rbp = 0x7fff92273400 
    rip = 0x464475 
    #da = disassemble(StartPC=rip, EndPC=rip+1).Disassemble
    #print("RBP 0x%x RIP 0x%x %s %s %s" % (rbp, rip, da[0].Loc.Function.Name_, da[0].Loc.File, da[0].Loc.Line))

    while True:
        mem = examine_memory(rbp, 8).Mem
        val = 0
        for i in range(len(mem)):
            val <<= 8
            val += mem[len(mem) - i - 1]
        prbp = val

        mem = examine_memory(rbp + 8, 8).Mem
        val = 0
        for i in range(len(mem)):
            val <<= 8
            val += mem[len(mem) - i - 1]
        ra = val

        da = disassemble(StartPC=ra, EndPC=ra+1).Disassemble
        if da[0].Loc.Function:
           print("RBP 0x%x RA 0x%x %s %s %s" % (prbp, ra, da[0].Loc.Function.Name_, da[0].Loc.File, da[0].Loc.Line))
        else:
           print("RBP 0x%x RA" % (prbp))
        if prbp == 0:
           break
        rbp = prbp
def main():
        dlv_command("config alias goroutine_start_line gsl")
(dlv) source test.star
(dlv) gsl
RBP 0x7fff92273420 RA 0x46448d C.test2 /home/soomohan/mbalraj/test_assert/hello.go 14
RBP 0x7fff92273440 RA 0x4644a8 C.test3 /home/soomohan/mbalraj/test_assert/hello.go 19
RBP 0x7fff92273470 RA 0x4644c8 C._cgo_55ddea9956f0_Cfunc_test3 /tmp/go-build/cgo-gcc-prolog 51
RBP 0xc000048f38 RA 0x45f304 runtime.asmcgocall /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s 852
RBP 0xc000048f60 RA 0x464265 main._Cfunc_test3 _cgo_gotypes.go 40
RBP 0xc000048f70 RA 0x4642f7 main.main /home/soomohan/mbalraj/test_assert/hello.go 25
RBP 0xc000048fd0 RA 0x437093 runtime.main /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/proc.go 260
RBP 0x0 RA 0x45f601 runtime.goexit /home/soomohan/mbalraj/GO/go1.20.2/go/src/runtime/asm_amd64.s 1599
@candlerb
Copy link

candlerb commented Apr 3, 2023

(Aside: suggestion. Please edit your post and put three backticks ``` on a line of their own, before and after the backtrace, and before and after each block of code. This will make it format properly and be much easier to read)

@MariappanBalraj
Copy link
Author

MariappanBalraj commented Apr 3, 2023 via email

@aarzilli
Copy link
Member

aarzilli commented Apr 3, 2023

Some changes need to happen to go, then delve will be updated to match. If all goes according to plan it will happen in time for 1.21 in july.

@MariappanBalraj
Copy link
Author

MariappanBalraj commented Apr 4, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants