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

Closed
glycerine opened this issue Dec 7, 2013 · 9 comments
Closed

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

glycerine opened this issue Dec 7, 2013 · 9 comments
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@glycerine
Copy link

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
Copy link
Member

minux commented Dec 7, 2013

Comment 1:

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

Status changed to Accepted.

@robpike
Copy link
Contributor

robpike commented Mar 5, 2014

Comment 2:

Labels changed: added gdb.

@rsc
Copy link
Contributor

rsc commented May 12, 2014

Comment 4:

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

@glycerine
Copy link
Author

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
Copy link
Contributor

Comment 6:

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

@glycerine glycerine added accepted Suggested Issues that may be good for new contributors looking for work to do. labels Aug 25, 2014
@rsc rsc removed the gdb label Apr 10, 2015
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@gopherbot
Copy link

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

@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Apr 7, 2017
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
Copy link

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

lparth pushed a commit to lparth/go that referenced this issue Apr 13, 2017
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
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>
@glycerine
Copy link
Author

very old issue and unlikely to be relevant anymore with all the new DWARF rewrites, so closing.

@golang golang locked and limited conversation to collaborators Mar 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

6 participants