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 wrongly relocates line addresses #21

Closed cahirwpz closed 1 year ago

cahirwpz commented 2 years ago

This is a follow up to #20.

If I relocate file using qOffset command of gdbserver there's wrong association between PC positions and code lines. I issued maint info line-table and got following:

...
objfile: system.exe.dbg ((struct objfile *) 0x7fd7c902a640)
compunit_symtab: ((struct compunit_symtab *) 0x7fd7c8827170)
symtab: main.c ((struct symtab *) 0x7fd7c982e3a0)
linetable: ((struct linetable *) 0x7fd7c982e3d0):
INDEX  LINE   ADDRESS            IS-STMT
0      11     0x00c7cacc         Y
1      12     0x00c7cacc         Y
2      13     0x00c7cad4         Y
3      14     0x00c7cada         Y
4      16     0x00c7cae0         Y
5      21     0x018f95be         Y
6      22     0x018f95be         Y
7      23     0x018f95c2         Y
8      24     0x018f95c8         Y
9      25     0x018f95ce         Y
10     26     0x018f95d2         Y
11     39     0x018f95fc         Y
12     47     0x018f95fc         Y
13     49     0x018f9624         Y
14     52     0x018f9628         Y
15     54     0x018f962a         Y
...

As you can see addresses for indices greater than 4 went bad. That would explain why gdb is not able to show me right code with list command.

cahirwpz commented 2 years ago

This patch fixes the issue: https://github.com/cahirwpz/demoscene-toolchain/blob/master/patches/gdb-line-addr-fix.patch

objfile: system.exe.dbg ((struct objfile *) 0x7f801c49dad0)
compunit_symtab: ((struct compunit_symtab *) 0x7f801c892b70)
symtab: main.c ((struct symtab *) 0x7f801d839fa0)
linetable: ((struct linetable *) 0x7f801d839fd0):
INDEX  LINE   ADDRESS            IS-STMT
0      11     0x00c7cacc         Y
1      12     0x00c7cacc         Y
2      13     0x00c7cad4         Y
3      14     0x00c7cada         Y
4      16     0x00c7cae0         Y
5      21     0x00c7caf2         Y
6      22     0x00c7caf2         Y
7      23     0x00c7caf6         Y
8      24     0x00c7cafc         Y
9      25     0x00c7cb02         Y
10     26     0x00c7cb06         Y
11     39     0x00c7cb0a         Y
12     47     0x00c7cb0a         Y
13     49     0x00c7cb1a         Y
14     52     0x00c7cb1e         Y
15     54     0x00c7cb20         Y
16     56     0x00c7cb22         Y
...
bebbo commented 2 years ago

this patch, kills setting breakpoints in https://github.com/bebbo/bgdbserver ...

cahirwpz commented 2 years ago

That's unfortunate! I posted the patch to give you a sense of what could be a solution. I did not expect to be proficient enough with gdb source code to propose a solid fix. Could you at least confirm that I reported a real bug? As I stated in #20 I'm still using STABS instead of DWARF - and I cannot migrate to compiler supporting DWARF yet.

bebbo commented 2 years ago

That's unfortunate! I posted the patch to give you a sense of what could be a solution. I did not expect to be proficient enough with gdb source code to propose a solid fix. Could you at least confirm that I reported a real bug? As I stated in #20 I'm still using STABS instead of DWARF - and I cannot migrate to compiler supporting DWARF yet.

also gcc 6.5 is still using stabs.

what gdbserver do you use?

cahirwpz commented 2 years ago

what gdbserver do you use?

I wrote my own gdbserver that runs on top fs-uae built-in debugger. RSP implementation is in gdb.py, code communicating with fs-uae is in uae.py and a program that launches fs-uae and opens a TCP listening socket is in uaegdb.py.

I assume the software will write a pointer to hunk list into specific location in memory, I fetch it with get_segments and report with qOffsets packet.

bebbo commented 1 year ago

should be working meanwhile

cahirwpz commented 1 year ago

Now maint info line-table output looks ok to me.

Again... thank you for fixing that :)