go-delve / delve

Delve is a debugger for the Go programming language.
MIT License
23.02k stars 2.14k forks source link

[Bug] Linux/arm64 dlv debug hangs forever #3598

Closed qiangz63 closed 11 months ago

qiangz63 commented 11 months ago

go version go1.21.5 linux/arm64

Delve Debugger Version: 1.21.2 Build: $Id: 98f8ab2662d926245917ade2f2bb38277315c7fc $

Delve build from go install github.com/go-delve/delve/cmd/dlv@latest The bug in anywhere (including debug command) When using dlv exec speed --log, it hangs forever: 2023-12-15T03:04:34Z info layer=debugger launching process with args: [speed]

strace dlv exec speed --log shows:

pread64(3, "\0.text\0.noptrdata\0.data\0.bss\0.no"..., 263, 755520) = 263
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=260807245}) = 0
futex(0x3000bc4240, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x3000bc4158, FUTEX_WAKE_PRIVATE, 1) = 1                                                                
close(3)                                = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=262894745}) = 0                                       
futex(0x3000bc4240, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x3000bc4158, FUTEX_WAKE_PRIVATE, 1) = 1
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=264414016}) = 0
--- SIGURG {si_signo=SIGURG, si_code=SI_TKILL, si_pid=13172, si_uid=10207} ---
rt_sigreturn({mask=[RTMIN]})            = 0
......
......
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433782, tv_nsec=310946828}) = 0
futex(0x3000bc4158, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x3000bc3a88, FUTEX_WAIT_PRIVATE, 0, NULL) = -1 EAGAIN (Resource temporarily unavailable)
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=288915578}) = 0
futex(0x3000bc3a88, FUTEX_WAIT_PRIVATE, 0, NULL) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=490779641}) = 0
epoll_pwait(4, [], 128, 200, NULL, 0)   = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=693427037}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=694284328}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=695155162}) = 0
futex(0x4000074d48, FUTEX_WAKE_PRIVATE, 1) = 1
wait4(13179, 0x4000279504, WNOHANG|__WALL, NULL) = 0
openat(AT_FDCWD, "/proc/13179/stat", O_RDONLY|O_CLOEXEC) = 3
fcntl(3, F_GETFL)                       = 0x20000 (flags O_RDONLY|O_LARGEFILE)
fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK|O_LARGEFILE) = 0 
epoll_ctl(4, EPOLL_CTL_ADD, 3, {events=EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, data={u32=3149922309, u64=33733861703680005}}) = -1 EPERM (Operation not permitted)
fcntl(3, F_GETFL)                       = 0x20800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE)                     
fcntl(3, F_SETFL, O_RDONLY|O_LARGEFILE) = 0
read(3, "13179 (speed) t 13172 13179 3417"..., 4096) = 289
close(3)                                = 0                                                                   
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=703827558}) = 0
futex(0x3000bc4240, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x3000bc4158, FUTEX_WAKE_PRIVATE, 1) = 1                                                                
clock_gettime(CLOCK_MONOTONIC, {tv_sec=433781, tv_nsec=706472349}) = 0
--- SIGURG {si_signo=SIGURG, si_code=SI_TKILL, si_pid=13172, si_uid=10207} ---
rt_sigreturn({mask=[RTMIN]})            = 0
......
qiangz63 commented 11 months ago

Linux (Ubuntu 22.04) from Termux proot. In Termux patched dlv could into pipe, and debug fine! So in proot only debug remote from Termux' dlv. My source code speed.go:

package main
import "fmt"
import "time"
func main() {
        var a int64 = 0
        begin := time.Now()
        for i := 0; i < 100000001; i++ {
                a += int64(i)
        }
        end := time.Now()
        fmt.Println("Result:", a)
        fmt.Println("Time:  ", end.Sub(begin).Milliseconds(), "ms")
}

go build -gcflags "all=-N -l" -o speed speed.go

aarzilli commented 11 months ago

It's not clear what the bug is here. You are talking about problems with pipes but the only example you show doesn't use a pipe.

qiangz63 commented 11 months ago

It's not clear what the bug is here. You are talking about problems with pipes but the only example you show doesn't use a pipe.

The main problem is that dlv cannot debug in ubuntu/arm64 , strace shows it always in cycle, after log 2023-12-15T03:04:34Z info layer=debugger launching process with args: [speed]. pipe is sysytem call in ubuntu using strace shows pipe2([3, 7], O_CLOEXEC) = 0, then log 2023-12-15T06:53:13Z debug layer=debugger Adding target 29246 "./speed", but ubuntu can't into debug, just always cycle futex(0x3000bc3a88, FUTEX_WAIT_PRIVATE, 0, NULL) = -1 EAGAIN (Resource temporarily unavailable) or hangs onfutex(0x3000bc3a88, FUTEX_WAIT_PRIVATE, 0, NULL.

aarzilli commented 11 months ago

Delve does work on linux/arm64, we have CI to make sure that is the case. It must be something about your environment or how you are using. Are you using termux?

qiangz63 commented 11 months ago

Delve does work on linux/arm64, we have CI to make sure that is the case. It must be something about your environment or how you are using. Are you using termux?

Yes, I'm using termux patched delve (just add "android" case in some files), it work fine and could add breakpoints. Confused in ubuntu/arm64 build from source can't success debug, and my another device Debian/arm64 can't debug too. The environment maybe no problem, since gdb could debug C/C++ and Rust.

aarzilli commented 11 months ago

We don't support termux/android.