python – golang gdb – 打印变量
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – golang gdb – 打印变量,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3331字,纯文字阅读大概需要5分钟。
内容图文
我有一个问题,gdb没有正确打印变量.
简单程序以下列方式构建:
chmurson-osx:helloworld chmurson$go build -gcflags '-N' start.go
然后gdb执行:
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.
以下是我接下来要做的事情:
(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.怎么了 ?
这是我的版本
chmurson-osx:helloworld chmurson$go version
go version go1.3.1 darwin/amd64
和gdb配置一样
(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.)
解决方法:
添加到@ AlexAtNet的答案后,Go 1.2.x之后的所有内容都会破坏GDB支持,所以要么使用去1.2.x进行调试或使用gccgo(请记住gcc 4.8.x支持go 1.1,gcc 4.9.x高达1.2) .
另一个选择是使用你自己的跟踪功能,不是很漂亮,但它是目前唯一真正的调试选项.
我个人使用这样的东西进行调试:
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()
}
内容总结
以上是互联网集市为您收集整理的python – golang gdb – 打印变量全部内容,希望文章能够帮你解决python – golang gdb – 打印变量所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。