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 reports wrong addresses for sections #20

Closed cahirwpz closed 1 year ago

cahirwpz commented 2 years ago

I'm in a process of writing a loader for demo. The demo consists of several parts in AmigaHunk format. Namely system.exe which is resident executable, and one executable file for each effect. You can think of system.exe as if was an operating system which sole purpose is to load effects into memory, run them and unload.

To debug such beast I need gdb to handle two or more AmigaHunk files to be loaded into memory. Let's consider two files system.exe and playahx.exe. First is loaded by bootloader:

[Loader] Executable file segments:
[Loader] * $00c7c604 - $00c7fc6c
[Loader] * $00c7fc74 - $00c7fd98
[Loader] * $00c7fda0 - $00c80000

...and its section addresses are reported through gdbserver using qOffset reply Text=00c7c604;Data=00c7fc74;Bss=00c7fda0.

However when you ask gdb about section addresses it reports:

>>> info files
        ...
        0x00c7c604 - 0x00c7fc6c is .text
        0x00c832dc - 0x00c83400 is .data
        0x00c8352c - 0x00c8378c is .bss

To add to this confusion if I ask gdb to print minimal symbol table it shows following:

>>> maintenance print msymbols

Object file /Users/cahir/workspace/demoscene/system/system.exe.dbg:

[ 0] D 0xc7fc74 CpuModel section .data
[ 1] B 0xc7fda0 __INIT_LIST__ section .bss
[ 2] B 0xc7fda0 _bss section .bss
[ 3] D 0xc7fc74 _data section .data
[ 4] T 0xc7c604 _text section .text
[ 5] T 0xc7c604 start section .text
[ 6] B 0xc7fda4 __EXIT_LIST__ section .bss
[ 7] T 0xc7c60c CallFuncList section .text
[ 8] T 0xc7c668 EffectLoad section .text
[ 9] T 0xc7c6b8 EffectInit section .text
[10] D 0xc7fd64 ExcVecBase section .data
[11] T 0xc7c704 EffectKill section .text
[12] D 0xc7fd80 CurrentTask section .data
[13] D 0xc7fd94 NeedReschedule section .data
...

So it seems that in symbol table .data and .bss sections have right values. If I ask gdb to print values of variables placed in .data and .bss sections it does it correctly.

This is a minor bug, but more will follow in next issues I'll report.

cahirwpz commented 2 years ago

Please note I'm using a fresh build without my patches:

>>> show version
GNU gdb (GDB) 10.0.50.220509-071035-git

Important: I'm still using STABS format (gcc-2.95.3) instead of DWARF.

bebbo commented 2 years ago

info files adds the sizes of the previous sections, which is wrong.

cahirwpz commented 2 years ago

Is there a chance you'll fix it? I understand you may consider it to be a minor bug not worth your precious time...

cahirwpz commented 1 year ago

Works like a charm! I verified the output of info files for a handful of binaries and it's correct.

Thank you for fixing that!