質問

example files

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 code

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

Who can help me solve this problem, thank you very much.

My Environment:

  • ubuntu 11.04 i386
  • gdb 7.6
  • go 1.1
役に立ちましたか?

解決

There is currently an open bug regarding this: https://code.google.com/p/go/issues/detail?id=5221

Debugging cgo with gdb worked in 1.0 but is currently broken in 1.1. It's being worked on.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top