drdr123456 2013-07-03 04:02
浏览 118
已采纳

GDB-附加并中断正在运行的Go应用程序

I compiled a simple go application with debug flags:

go build -gcflags "-N -l" -o main main.go

main.go

package main

import (
    "fmt"
    "time"
)

func main() {
    for i := 0; true; i++ {
        fmt.Println("number:", i)
        time.Sleep(time.Second)
    }
}

In gdb, I attached to its pid and executed break and break 11.

gdb --pid=<pid>

Gdb reports that the breakpoints are successfully set, but they don't ever get hit. Is there a way to get this working?

  • 写回答

2条回答 默认 最新

  • douzhi3105 2014-04-03 06:49
    关注

    Note: that same setup (even when adding your runtime-gdb.py to your .gdbrc) risks to not work with Ubuntu 13.10, where you would get a "SyntaxError" message, as illustrated in:

    The problem is that Ubuntu 13.10 links GDB against Python 3.3 while the script golang ships is for Python 2. Someone has already filed an issue, and it appears to be fixed upstream (so expect Go 1.3 to Just Work).

    Luckily backporting the fix is easy. Simply move your exist runtime-gdb.py out of the way and download the upstream version in its place.

    If your $GOROOT is /usr/local/go the following should Just Work:

    sudo mv /usr/local/go/src/pkg/runtime/runtime-gdb.py /usr/local/go/src/pkg/runtime/runtime-gdb.py.orig
    cd /usr/local/go/src/pkg/runtime/
    sudo wget https://go.googlecode.com/hg/src/pkg/runtime/runtime-gdb.py
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料