bebbo / binutils-gdb

Unofficial mirror of sourceware binutils-gdb repository. Updated daily.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git
GNU General Public License v2.0
3 stars 3 forks source link

gdb: incorrect addresses of source lines #28

Closed cahirwpz closed 5 months ago

cahirwpz commented 1 year ago

Unfortunately https://github.com/bebbo/binutils-gdb/issues/21 did not fix all problems I experience with gdb. Namely there's a mismatch between relocated addresses and source lines. I cannot use list to display source code of many routines nor use breakpoint on symbols.

To better explain the problem let's use an example. Below you can find a piece of .stabs section for wireframe.o. As you can see Load function is defined in at address .text+0x1ca and UnLoad at .text+0x1ec.

# m68k-amigaos-objdump -G wireframe.o
...
169    SLINE  0      23     000001ca 0      
170    SLINE  0      24     000001ca 0      
171    SLINE  0      25     000001d4 0      
172    SLINE  0      26     000001de 0      
173    SLINE  0      27     000001e8 0      
174    FUN    0      23     000001ca 6628   Load:f19
175    SLINE  0      29     000001ec 0      
176    SLINE  0      30     000001ec 0      
177    SLINE  0      31     000001f6 0      
178    FUN    0      29     000001ec 6637   UnLoad:f19
...

This is what https://github.com/bebbo/binutils-gdb/commit/4a73175ec833bf743fa4791a5d3d71f71836e600 displays when asked about line-to-address correspondence:

(gdb) maintenance info line-table
...
INDEX  LINE   ADDRESS            IS-STMT
0      23     0x00c7a4e2         Y
1      24     0x00c7a4e2         Y
2      25     0x00c7a4ec         Y
3      26     0x00c7a4f6         Y
4      27     0x00c7a500         Y
5      29     0x00c7a706         Y
6      30     0x00c7a706         Y
7      31     0x00c7a710         Y

Expected output is:

(gdb) maintenance info line-table
...
INDEX  LINE   ADDRESS            IS-STMT
0      23     0x00c7a4e2         Y
1      24     0x00c7a4e2         Y
2      25     0x00c7a4ec         Y
3      26     0x00c7a4f6         Y
4      27     0x00c7a500         Y
5      29     0x00c7a504         Y
6      30     0x00c7a504         Y
7      31     0x00c7a50e         Y

Please note that Load is the first function in .text section while UnLoad is the second. As one can see current version of gdb assigns address 0x00c7a706 to UnLoad (at line 29 of wireframe.c) instead of 0x00c7a504.

I've managed to patch it locally (works for me), but I don't know how the change can affect other users. Hence I decided to leave it up to you if that should be patched and how. Here's proposed change:

--- binutils-gdb.orig/gdb/dbxread.c
+++ binutils-gdb/gdb/dbxread.c
@@ -2581,7 +2581,7 @@ process_one_symbol (int type, int desc,

       /* Relocate for dynamic loading and for ELF acc
          function-relative symbols.  */
-      valu += function_start_offset;
+      /* valu += function_start_offset; */

       /* GCC 2.95.3 emits the first N_SLINE stab somewhere in the
     middle of the prologue instead of right at the start of the
bebbo commented 1 year ago

Thanks, I will test this and check if it affects my debugging expirience^^