第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

golang gdb - 打印變量

golang gdb - 打印變量

Go
慕哥6287543 2021-08-16 19:25:08
我有 gdb 無法正確打印變量的問題。簡單的程序是通過以下方式構建的:chmurson-osx:helloworld chmurson$ go build -gcflags '-N' start.go 然后 gdb 執(zhí)行:chmurson-osx:helloworld chmurson$ gdb start -d $GOROOTGNU gdb (GDB) 7.8Copyright (C) 2014 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.  Type "show copying"and "show warranty" for details.This GDB was configured as "x86_64-apple-darwin14.0.0".Type "show configuration" for configuration details.For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>.Find the GDB manual and other documentation resources online at:<http://www.gnu.org/software/gdb/documentation/>.For help, type "help".Type "apropos word" to search for commands related to "word"...Reading symbols from start...done.warning: Missing auto-load scripts referenced in section .debug_gdb_scriptsof file /Users/chmurson/Dev/goprojects/misc/src/helloworld/startUse `info auto-load python-scripts [REGEXP]' to list them.(gdb) (gdb) source /usr/local/go/src/pkg/runtime/runtime-gdb.pyLoading Go Runtime support.這是我接下來要做的:(gdb) list1   package main2   3   import "fmt"4   5   func main() {6       x := "abc"7       i := 38       fmt.Println(i)9       fmt.Println(x)10  }(gdb) b 9Breakpoint 1 at 0x2106: file /Users/chmurson/Dev/goprojects/misc/src/helloworld/start.go, line 9.(gdb) runStarting program: /Users/chmurson/Dev/goprojects/misc/src/helloworld/start 3[New Thread 0x1113 of process 14039]Breakpoint 1, main.main () at /Users/chmurson/Dev/goprojects/misc/src/helloworld/start.go:99       fmt.Println(x)(gdb) p xPython Exception <type 'exceptions.OverflowError'> signed integer is greater than maximum: $1 = (gdb) p i$2 = 8725692800(gdb) 您可以看到在檢查 'p' 變量時存在 Python 異常,而在顯示 'i' 的值時完全不是 3。怎么了 ?
查看完整描述

2 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

添加到@AlexAtNet 的答案中,Go 1.2.x 之后的所有內容都破壞了 GDB 支持,因此要么使用 go 1.2.x 進行調試,要么使用 gccgo(請記住,gcc 4.8.x 支持 go 1.1,gcc 4.9.x 最高為 1.2) .


另一種選擇是使用您自己的跟蹤功能,雖然不漂亮,但它是目前 go 1.3+ 唯一真正的調試選項。


我個人使用這樣的東西進行調試:


var traceLock sync.Mutex


func trace(a ...interface{}) {

    traceLock.Lock()

    pc, f, ln, ok := runtime.Caller(1)

    fn := ""

    if ok {

        fn = runtime.FuncForPC(pc).Name()

    }

    fmt.Printf("trace: %s %s:%d", fn, filepath.Base(f), ln)

    if len(a) > 0 {

        fmt.Println(append([]interface{}{": "}, a...)...)

    }

    traceLock.Unlock()

}


查看完整回答
反對 回復 2021-08-16
  • 2 回答
  • 0 關注
  • 316 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號