Bug 30369 - [gdb/symtab] False match issue in skip_prologue_using_linetable
Summary: [gdb/symtab] False match issue in skip_prologue_using_linetable
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: 13.1
: P2 normal
Target Milestone: 13.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-18 08:32 UTC by Tom de Vries
Modified: 2023-04-22 07:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Patch with dwarf assembly reproducer (1.78 KB, patch)
2023-04-18 08:34 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2023-04-18 08:32:53 UTC
[ Reported here ( https://sourceware.org/pipermail/gdb-patches/2023-April/198927.html ), without reproducer. ]

Consider mockup functions foo and bar:
...
00000000004004b2 <foo_label>:
  4004b2:       c7 45 f8 02 00 00 00    movl   $0x2,-0x8(%rbp)

00000000004004b9 <bar_label>:
  4004b9:       c7 45 f4 03 00 00 00    movl   $0x3,-0xc(%rbp)

00000000004004c0 <bar_end>:
...
with line info:
...
INDEX  LINE   REL-ADDRESS        UNREL-ADDRESS      IS-STMT PROLOGUE-END 
0      22     0x00000000004004b2 0x00000000004004b2 Y                    
1      26     0x00000000004004b9 0x00000000004004b9 Y       Y            
2      END    0x00000000004004c0 0x00000000004004c0 Y                    
...

When setting a breakpoint on foo, we get:
...
(gdb) break foo
Breakpoint 1 at 0x4004b9: file $src, line 26.
...
In other words, the breakpoint was set in bar instead.

With the fix from aforementioned patch, we have instead:
...
Breakpoint 1 at 0x4004b2: file $src, line 22.
...
Comment 1 Tom de Vries 2023-04-18 08:34:30 UTC
Created attachment 14837 [details]
Patch with dwarf assembly reproducer
Comment 2 Tom de Vries 2023-04-18 10:00:11 UTC
Reproduced with trunk and gdb-13-branch.

Doesn't reproduce with gdb-12-branch (executed manually, test-case doesn't compile that far back):
...
$ gdb -q -batch dw2-prologue-end-2 -ex "b foo" -ex "print &foo_label"
Breakpoint 1 at 0x4004b2: file $src, line 22.
$1 = (void (*)()) 0x4004b2 <foo>
...
which is not surprising because prologue_end support was only added in gdb 13.
Comment 3 Tom de Vries 2023-04-18 12:16:05 UTC
Submitted v3: https://sourceware.org/pipermail/gdb-patches/2023-April/198967.html
Comment 4 Sourceware Commits 2023-04-22 05:50:18 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a88ee931eee4ba7339c481735b9405f66161e2f6

commit a88ee931eee4ba7339c481735b9405f66161e2f6
Author: WANG Rui <r@hev.cc>
Date:   Sat Apr 22 07:50:08 2023 +0200

    gdb: Fix false match issue in skip_prologue_using_linetable
    
    [ Changes in v2:
      - rebase on trunk
      Changes in v3:
      - add test-case ]
    
    We should exclude matches to the ending PC to prevent false matches with the
    next function, as prologue_end is located at the end PC.
    
      <fun1>:
        0x00: ... <-- start_pc
        0x04: ...
        0x08: ... <-- breakpoint
        0x0c: ret
      <fun2>:
        0x10: ret <-- end_pc | prologue_end of fun2
    
    Tested on x86_64-linux.
    
    Co-Authored-By: WANG Rui <r@hev.cc> (fix, tiny change [1])
    Co-Authored-By: Tom de Vries <tdevries@suse.de> (test-case)
    Approved-by: Kevin Buettner <kevinb@redhat.com>
    
    [1] https://www.gnu.org/prep/maintain/html_node/Legally-Significant.html
    
    PR symtab/30369
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30369
Comment 5 Sourceware Commits 2023-04-22 07:33:55 UTC
The gdb-13-branch branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3310ec8b5b6a7578c80a9da81c8357fa9205bba3

commit 3310ec8b5b6a7578c80a9da81c8357fa9205bba3
Author: WANG Rui <r@hev.cc>
Date:   Sat Apr 22 09:33:45 2023 +0200

    gdb: Fix false match issue in skip_prologue_using_linetable
    
    [ Changes in v2:
      - rebase on trunk
      Changes in v3:
      - add test-case ]
    
    We should exclude matches to the ending PC to prevent false matches with the
    next function, as prologue_end is located at the end PC.
    
      <fun1>:
        0x00: ... <-- start_pc
        0x04: ...
        0x08: ... <-- breakpoint
        0x0c: ret
      <fun2>:
        0x10: ret <-- end_pc | prologue_end of fun2
    
    Tested on x86_64-linux.
    
    Co-Authored-By: WANG Rui <r@hev.cc> (fix, tiny change [1])
    Co-Authored-By: Tom de Vries <tdevries@suse.de> (test-case)
    Approved-by: Kevin Buettner <kevinb@redhat.com>
    
    [1] https://www.gnu.org/prep/maintain/html_node/Legally-Significant.html
    
    PR symtab/30369
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30369
Comment 6 Tom de Vries 2023-04-22 07:35:20 UTC
Fixed on master, backported to gdb-13-branch.