Skip to content

cmd/ld: gdb information is wrong when using cgo #5719

@gopherbot

Description

@gopherbot

by huangmipi:

What is the expected output?
Right variable's value in GDB breakpoint.

What do you see instead?
Wrong variable's value in GDB breakpoint.

Which compiler are you using (5g, 6g, 8g, gccgo)?
go build test.go

Which operating system are you using?
ubuntu 11.04 i386
gdb 7.6

Which version are you using?  (run 'go version')
go 1.1

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);
}
================================
go build -gcflags "-N -l" test.go
gdb ./test
b 10
r
info locals  // <- every variable's value is wrong!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions