GDB无法在cgo代码中调试go程序

时间:2013-06-17 13:09:37

标签: debugging gdb go cgo

示例文件

的src / test.go

package main
import (
  . "clib"
)
func main() {
  a := "123";
  b := "456";
  c := "789";
  println(a,b,c);
  Output("ABC");
}

的src / CLIB / clib.h

#ifndef CLIB
void output(char* str);
#endif

的src / CLIB / clib.c

#include "clib.h"
#include <stdio.h>
void output(char* str)
{
    printf("%s\n", str);
}

的src / CLIB / clib.go

package clib
/*
#cgo CFLAGS:-g
#include "clib.h"
*/
import "C"
func Output(s string) {
  p := C.CString(s);
  C.output(p);
}

exec代码

go build -gcflags "-N -l" test.go
gdb ./test
b 10
r
info locals  // <- every variable's value is wrong!

谁能帮我解决这个问题,非常感谢你。

我的环境:

  • ubuntu 11.04 i386
  • gdb 7.6
  • 去1.1

1 个答案:

答案 0 :(得分:4)

目前有一个关于此问题的公开错误:https://code.google.com/p/go/issues/detail?id=5221

使用gdb调试cgo在1.0中工作,但目前在1.1中被破坏。它正在进行中。