Skip to content

gdb: Wrong values for local variables #8256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gopherbot opened this issue Jun 20, 2014 · 12 comments
Closed

gdb: Wrong values for local variables #8256

gopherbot opened this issue Jun 20, 2014 · 12 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@gopherbot
Copy link
Contributor

by andreas.nusser:

What does 'go version' print?
Tried with 
.)go version go1.3 linux/amd64
and
.)go version devel +e0ad7e329637 Thu Jun 19 22:19:56 2014 -0700 linux/amd64

As gdb I'm using "GNU gdb (GDB) 7.6.2 (Debian 7.6.2-1.1+b1)"

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Write a short test program similar to the one attached. (You can find it here too:
http://play.golang.org./p/Y5b-t2iobd)
2. Compile it with go build -gcflags "-N -l" to prevent inlining
3. Run the resulting binary with gdb and observe as gdb reports wrong values for the
local variables. It even doesn't report the changed value of "z" in line 13.

What happened?
 - Instead of the values of the variables, gdb shows garbage.

What should have happened instead?
 - gdb should show the correct values.

Thanks for your help!
Andreas

Attachments:

  1. gdb_fail.go (276 bytes)
@ianlancetaylor
Copy link
Member

Comment 1:

Labels changed: added repo-main, release-go1.4.

@mholt
Copy link

mholt commented Sep 4, 2014

Comment 2:

Not sure if it matters, but I'm able to reproduce this on Mac OS 10.9.4 with GNU gdb
(GDB) 7.7.1 and Go 1.3.1. I used the same build command with the same flags.
My Go program and garbage output are both attached for reference.

Attachments:

  1. gdbtest.go (76 bytes)
  2. gdb_garbage_out.txt (821 bytes)

@rsc
Copy link
Contributor

rsc commented Sep 15, 2014

Comment 3:

Probably not for 1.4.

Labels changed: added release-go1.5, removed release-go1.4.

Status changed to Accepted.

@gopherbot
Copy link
Contributor Author

Comment 4 by jeromelaurens:

Same here with :
go version go1.3.1 darwin/amd64
GNU gdb (GDB) 7.8
I also have the flags : -gcflags "-N -l"
I'm using LiteIDE
local variable showing odd values
Very annoying when you want to inspect your variables
Thanks for your help

@gopherbot
Copy link
Contributor Author

Comment 5 by holgerfinger:

Same problem with go version go1.3 linux/amd64.
I tried gdb 7.4 and gdb 7.8.
go 1.2.2 seems to be working fine.

@gopherbot
Copy link
Contributor Author

Comment 6 by ludmiloff:

When to expect a bug fix

@ianlancetaylor
Copy link
Member

Comment 7:

See http://golang.org/doc/gdb .  As it says there, making Go work well with gdb is not a
priority for the Go project.  Of course Go is an open source project and we are always
happy to accept patches.  But at the moment I'm not aware of anybody working on this
issue, so I can not predict when it will be fixed.

@gopherbot
Copy link
Contributor Author

Comment 8 by lars.oppermann:

If gdb is not a priority, what is the recommended way for debugging go programs?

@gopherbot
Copy link
Contributor Author

Comment 9 by eidmanna:

Even if debugging with command line is possible, it is much easier to find bugs with a
good debugger (such as the Google Chrome Javascript Debugger). Why has this issue as low
priority?

@mholt
Copy link

mholt commented Nov 28, 2014

Comment 10:

Using the fmt and log packages is a pretty common way of debugging Go programs, and the
log package especially is safe for concurrent execution. gdb... not so much.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@rsc rsc removed accepted labels Apr 14, 2015
@rsc rsc modified the milestones: Unplanned, Go1.5 Jun 29, 2015
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 13, 2024
@linsite
Copy link
Contributor

linsite commented Feb 25, 2025

Newly tests show gdb work fines.
$ go version
go version go1.23.4 linux/amd64

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.2) 9.2

Thread 1 "gdb" hit Breakpoint 1, main.main () at /home/ulin/data/code/lean/compile/gdb.go:18
18 func main() {
(gdb) n
19 flag.Parse()
(gdb) n
20 x := iterations
(gdb) n
21 y := *x
(gdb) n
22 z := abc(y)
(gdb) n
23 fmt.Printf("%v %v\n", z, *x)
(gdb) p z
$1 = 2

@ianlancetaylor
Copy link
Member

Thanks.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants