首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gdb -打印变量

gdb -打印变量
EN

Stack Overflow用户
提问于 2014-09-20 16:25:00
回答 1查看 1.5K关注 0票数 4

我对gdb有一个问题,没有正确地打印变量。简单程序的构建方式如下:

代码语言:javascript
复制
chmurson-osx:helloworld chmurson$ go build -gcflags '-N' start.go 

然后gdb执行了:

代码语言:javascript
复制
chmurson-osx:helloworld chmurson$ gdb start -d $GOROOT
GNU gdb (GDB) 7.8
Copyright (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_scripts
of file /Users/chmurson/Dev/goprojects/misc/src/helloworld/start
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) 
(gdb) source /usr/local/go/src/pkg/runtime/runtime-gdb.py
Loading Go Runtime support.

下面是我接下来要做的事情:

代码语言:javascript
复制
(gdb) list
1   package main
2   
3   import "fmt"
4   
5   func main() {
6       x := "abc"
7       i := 3
8       fmt.Println(i)
9       fmt.Println(x)
10  }
(gdb) b 9
Breakpoint 1 at 0x2106: file /Users/chmurson/Dev/goprojects/misc/src/helloworld/start.go, line 9.
(gdb) run
Starting 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:9
9       fmt.Println(x)
(gdb) p x
Python Exception <type 'exceptions.OverflowError'> signed integer is greater than maximum: 
$1 = 
(gdb) p i
$2 = 8725692800
(gdb) 

您可以看到,在检查'p‘变量时存在Python异常,而在显示'i’值时则完全不是3个异常。怎么了?

这是我的围棋版本

代码语言:javascript
复制
chmurson-osx:helloworld chmurson$ go version
go version go1.3.1 darwin/amd64

和gdb配置

代码语言:javascript
复制
(gdb) show configuration
This GDB was configured as follows:
   configure --host=x86_64-apple-darwin14.0.0 --target=x86_64-apple-darwin14.0.0
             --with-auto-load-dir=:${prefix}/share/auto-load
             --with-auto-load-safe-path=:${prefix}/share/auto-load
             --with-expat
             --with-gdb-datadir=/usr/local/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/local/lib/gdb (relocatable)
             --without-libunwind-ia64
             --without-lzma
             --with-python=/System/Library/Frameworks/Python.framework/Versions/2.7
             --without-guile
             --with-separate-debug-dir=/usr/local/lib/debug (relocatable)
             --with-zlib
             --without-babeltrace

("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)
EN

回答 1

Stack Overflow用户

发布于 2014-09-20 21:40:30

GDB支持并不是Go团队的优先事项,因此此类问题的数量不太可能很快就确定下来。请考虑以下几点:

https://golang.org/doc/gdb

GDB不太了解Go程序。堆栈管理、线程处理和运行时包含与执行模型有很大不同的方面-- GDB期望它们会混淆调试器,即使程序是用gccgo编译的。因此,尽管GDB在某些情况下可能很有用,但它并不是Go程序的可靠调试器,特别是大量并发的程序。此外,Go项目没有优先处理这些困难的问题。

但是,您可以使用Gccgo工具链并成功地调试go程序。但是,在Mac上安装它有点麻烦。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25950873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档