GO的GDB調試

來源:互聯網
上載者:User

標籤:

GoLang語言,學了很久,一直覺得它單步調試有較多問題,最近才知道自已對它瞭解得太少了。
原來GO語言對GDB的版本是至少為gdb7以上,才能比較好的列印任意變數,如果低於這個版本,則才會出一些問題。
網上說GDB版本為7.1,本人使用GDB7.8版本測試,確實很不錯。以下是記錄單步調試使用的幾個列印變數。
info frame,列印當前棧參數。
info locals列印局部變數
info args列印參數。
bt顯示當前堆棧
x/3xw &r查看記憶體

刪除偵錯符號:go build -ldflags “-s -w” filename.go

-s: 去掉符號資訊。
-w: 去掉DWARF調試資訊。
關閉內聯最佳化:go build -gcflags “-N -l” filename.go

—————–
在centos6.6裡利用原生的GDB調試時,發現如下特點。
1.直接使用list命令,會進入到一個如下狀態。
(gdb) l
/usr/local/go/src/runtime/rt0_linux_amd64.s: No such file or directory.
in /usr/local/go/src/runtime/rt0_linux_amd64.s

2.可以使用l main.main命令定位到主函數。
(gdb) l main.main
warning: Source file is more recent than executable.
4
5type point struct {
6x, y int
7}
8
9func main() {
10i:=32
11p := point{1, 2}
12f := 3.3434
13txt := "sdfsdfdsfsfds"

http://www.kxtry.com/archives/737

GO的GDB調試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.