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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?