public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug go/29357] New: gdb for golang prints wrong frame info at the ret instruction
@ 2022-07-12  2:37 greyschwinger at gmail dot com
  2022-07-12  2:38 ` [Bug go/29357] " greyschwinger at gmail dot com
  2023-03-31  0:05 ` tromey at sourceware dot org
  0 siblings, 2 replies; 3+ messages in thread
From: greyschwinger at gmail dot com @ 2022-07-12  2:37 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=29357

            Bug ID: 29357
           Summary: gdb for golang prints wrong frame info at the ret
                    instruction
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: go
          Assignee: unassigned at sourceware dot org
          Reporter: greyschwinger at gmail dot com
  Target Milestone: ---

Prepare a hello world golang program:

```
$ cat -n ./main.go 
     1  package main
     2  
     3  import "fmt"
     4  
     5  func main() {
     6          fmt.Println("hello world")
     7  }
```

Compile the code using go1.18.3 linux/amd64:

```
$ go build .
```

Disassemble the main function:

```
$ gdb -ex "disas/mr 'main.main'" -ex q ./go_hello_world

5       func main() {
   0x000000000047dfe0 <+0>:     49 3b 66 10     cmp    0x10(%r14),%rsp
   0x000000000047dfe4 <+4>:     76 56   jbe    0x47e03c <main.main+92>
   0x000000000047dfe6 <+6>:     48 83 ec 40     sub    $0x40,%rsp
   0x000000000047dfea <+10>:    48 89 6c 24 38  mov    %rbp,0x38(%rsp)
   0x000000000047dfef <+15>:    48 8d 6c 24 38  lea    0x38(%rsp),%rbp
   0x000000000047e03c <+92>:    0f 1f 40 00     nopl   0x0(%rax)
   0x000000000047e040 <+96>:    e8 5b a9 fd ff  call   0x4589a0
<runtime.morestack_noctxt>
   0x000000000047e045 <+101>:   eb 99   jmp    0x47dfe0 <main.main>

6               fmt.Println("hello world")
   0x000000000047dff4 <+20>:    44 0f 11 7c 24 28       movups
%xmm15,0x28(%rsp)
   0x000000000047dffa <+26>:    48 8d 15 5f 7e 00 00    lea   
0x7e5f(%rip),%rdx        # 0x485e60
   0x000000000047e001 <+33>:    48 89 54 24 28  mov    %rdx,0x28(%rsp)
   0x000000000047e006 <+38>:    48 8d 15 7b 4b 03 00    lea   
0x34b7b(%rip),%rdx        # 0x4b2b88
   0x000000000047e00d <+45>:    48 89 54 24 30  mov    %rdx,0x30(%rsp)

7       }
   0x000000000047e032 <+82>:    48 8b 6c 24 38  mov    0x38(%rsp),%rbp
   0x000000000047e037 <+87>:    48 83 c4 40     add    $0x40,%rsp
   0x000000000047e03b <+91>:    c3      ret

End of assembler dump.
```

Then I'll add a breakpoint at the ret instruction, <+91>

```
$ gdb ./go_hello_world 

(gdb) b *0x000000000047e03b
Breakpoint 1 at 0x47e03b: file
/home/gray/src/proving_grounds/go_hello_world/main.go, line 7.
(gdb) r

Thread 1 "go_hello_world" hit Breakpoint 1, 0x000000000047e03b in main.main ()
at /home/gray/src/proving_grounds/go_hello_world/main.go:7
7       }
```

Then let's check the frame info and register:

```
(gdb) i f
Stack level 0, frame at 0xc00011cf78:
 rip = 0x47e03b in main.main
(/home/gray/src/proving_grounds/go_hello_world/main.go:7); saved rip = 0x4324d2
 source language unknown.
 Arglist at 0xc00011cf70, args: 
 Locals at 0xc00011cf70, Previous frame's sp is 0xc00011cf80
 Saved registers:
  rip at 0xc00011cf78

(gdb) p/x $rsp
$1 = 0xc00011cf78
```

However the "frame at 0xc00011cf78" is incorrect. As far as I know, "the frame
at" shows the CFA of the current stack frame, and at the ret instruction, the
CFA should be $rsp+8.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug go/29357] gdb for golang prints wrong frame info at the ret instruction
  2022-07-12  2:37 [Bug go/29357] New: gdb for golang prints wrong frame info at the ret instruction greyschwinger at gmail dot com
@ 2022-07-12  2:38 ` greyschwinger at gmail dot com
  2023-03-31  0:05 ` tromey at sourceware dot org
  1 sibling, 0 replies; 3+ messages in thread
From: greyschwinger at gmail dot com @ 2022-07-12  2:38 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=29357

Ooth Gray <greyschwinger at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greyschwinger at gmail dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug go/29357] gdb for golang prints wrong frame info at the ret instruction
  2022-07-12  2:37 [Bug go/29357] New: gdb for golang prints wrong frame info at the ret instruction greyschwinger at gmail dot com
  2022-07-12  2:38 ` [Bug go/29357] " greyschwinger at gmail dot com
@ 2023-03-31  0:05 ` tromey at sourceware dot org
  1 sibling, 0 replies; 3+ messages in thread
From: tromey at sourceware dot org @ 2023-03-31  0:05 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=29357

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
I think this was fixed.  There were some epilogue changes in the recent
past that probably did it.

Here you can see that the CFA at the start of main.main and at the ret
are now the same:

Thread 1 "main" hit Breakpoint 1, main.main () at
/home/tromey/gdb/PRS/go-29357/main.go:5
5       func main() {
(gdb) info frame
Stack level 0, frame at 0xc000106f80:
 rip = 0x480fa6 in main.main (/home/tromey/gdb/PRS/go-29357/main.go:5); saved
rip = 0x433ff2
 source language unknown.
 Arglist at 0xc000106f70, args: 
 Locals at 0xc000106f70, Previous frame's sp is 0xc000106f80
 Saved registers:
  rip at 0xc000106f78
(gdb) c
Continuing.
hello world

Thread 1 "main" hit Breakpoint 3, 0x0000000000480ffb in main.main () at
/home/tromey/gdb/PRS/go-29357/main.go:7
7       }
(gdb) info frame
Stack level 0, frame at 0xc000106f80:
 rip = 0x480ffb in main.main (/home/tromey/gdb/PRS/go-29357/main.go:7); saved
rip = 0x433ff2
 source language unknown.
 Arglist at 0xc000106f70, args: 
 Locals at 0xc000106f70, Previous frame's sp is 0xc000106f80
 Saved registers:
  rip at 0xc000106f78
(gdb) pipe disassemble | grep -e '=>'
=> 0x0000000000480ffb <+91>:    ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-31  0:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12  2:37 [Bug go/29357] New: gdb for golang prints wrong frame info at the ret instruction greyschwinger at gmail dot com
2022-07-12  2:38 ` [Bug go/29357] " greyschwinger at gmail dot com
2023-03-31  0:05 ` tromey at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).