Skip to content
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

misc/gdb: gdb picks wrong i from two variables both named i #6913

Open
glycerine opened this issue Dec 7, 2013 · 8 comments

Comments

@glycerine
Copy link

commented Dec 7, 2013

In the demonstration below, when stopped at line 11, gdb reports i being 0 rather than
the correct local value of 32.

package main
  import (
      "os"
      "fmt"
  )

  func main() {
      i := int64(0)
      if os.Args[0] != "blah" {
          i := 32
B =>      fmt.Printf("i = %v\n", i) // line 11
      }
      i++
  }


GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 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-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>;...
Reading symbols from /home/jaten/gdblies2...done.
Loading Go Runtime support.
(gdb) break gdblies2.go:11
Breakpoint 1 at 0x400ca6: file /home/jaten/gdblies2.go, line 11.
(gdb) run
Starting program: /home/jaten/gdblies2
warning: no loadable sections found in added symbol-file system-supplied DSO at
0x7ffff7ffd000
[Inferior 1 (process 23017) exited normally]
(gdb) run
`/home/jaten/gdblies2' has changed; re-reading symbols.
Starting program: /home/jaten/gdblies2

Breakpoint 1, main.main () at /home/jaten/gdblies2.go:11
(gdb) p i
$1 = 0
(gdb) n
[New LWP 23035]
i = 32
[LWP 23035 exited]
[Inferior 1 (process 23033) exited normally]
(gdb) 

ubuntu 12.04 amd64
go 1.2rc3
built with: go build -gcflags "-N -l" gdblies2.go
@minux

This comment has been minimized.

Copy link
Member

commented Dec 7, 2013

Comment 1:

Labels changed: added release-go1.3maybe, repo-main.

Status changed to Accepted.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Mar 5, 2014

Comment 2:

Labels changed: added gdb.

@rsc

This comment has been minimized.

Copy link
Contributor

commented May 12, 2014

Comment 4:

Labels changed: added release-none, suggested, removed release-go1.3maybe.

@glycerine

This comment has been minimized.

Copy link
Author

commented Aug 25, 2014

Comment 5:

Addendum: I still regularly run into gdb printing out incorrect values for the contents
of structs in golang 1.3. Presumably the dwarf debug info is still quite off, as in this
bug's example above with two i variables.
If somebody would orient me towards where the problem lies (if known), I would take a
stab at fixing it. It's really, really annoying to have gdb tell you very wrong
information about a variable when debugging.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Aug 25, 2014

Comment 6:

All the DWARF information is generated by cmd/ld/dwarf.c.  I don't know what the
specific problem is, though.
@gopherbot

This comment has been minimized.

Copy link

commented Sep 22, 2016

CL https://golang.org/cl/29591 mentions this issue.

@gopherbot

This comment has been minimized.

Copy link

commented Feb 13, 2017

CL https://golang.org/cl/36879 mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 7, 2017
cmd/compile: output DWARF lexical blocks for local variables
Change compiler and linker to emit DWARF lexical blocks in debug_info.
Version of debug_info is updated from DWARF v.2 to DWARF v.3 since version 2
does not allow lexical blocks with discontinuous ranges.

Second attempt at https://go-review.googlesource.com/#/c/29591/

Remaining open problems:
- scope information is removed from inlined functions
- variables in debug_info do not have DW_AT_start_scope attributes so a
variable will shadow other variables with the same name as soon as its
containing scope begins, before its declaration.

Updates #12899, #6913

Change-Id: I0e260a45b564d14a87b88974eb16c5387cb410a5
Reviewed-on: https://go-review.googlesource.com/36879
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
@gopherbot

This comment has been minimized.

Copy link

commented Apr 10, 2017

CL https://golang.org/cl/40095 mentions this issue.

lparth added a commit to lparth/go that referenced this issue Apr 13, 2017
cmd/compile: output DWARF lexical blocks for local variables
Change compiler and linker to emit DWARF lexical blocks in debug_info.
Version of debug_info is updated from DWARF v.2 to DWARF v.3 since version 2
does not allow lexical blocks with discontinuous ranges.

Second attempt at https://go-review.googlesource.com/#/c/29591/

Remaining open problems:
- scope information is removed from inlined functions
- variables in debug_info do not have DW_AT_start_scope attributes so a
variable will shadow other variables with the same name as soon as its
containing scope begins, before its declaration.

Updates golang#12899, golang#6913

Change-Id: I0e260a45b564d14a87b88974eb16c5387cb410a5
Reviewed-on: https://go-review.googlesource.com/36879
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
gopherbot pushed a commit that referenced this issue May 18, 2017
cmd/compile: output DWARF lexical blocks for local variables
Change compiler and linker to emit DWARF lexical blocks in .debug_info
section when compiling with -N -l.

Version of debug_info is updated from DWARF v2 to DWARF v3 since
version 2 does not allow lexical blocks with discontinuous PC ranges.

Remaining open problems:
- scope information is removed from inlined functions
- variables records do not have DW_AT_start_scope attributes so a
variable will shadow other variables with the same name as soon as its
containing scope begins, even before its declaration.

Updates #6913.
Updates #12899.

Change-Id: Idc6808788512ea20e7e45bcf782453acb416fb49
Reviewed-on: https://go-review.googlesource.com/40095
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.