[gdb/testsuite] Fix FAIL in gdb.tui/basic.exp
authorTom de Vries <tdevries@suse.de>
Tue, 7 Dec 2021 07:16:42 +0000 (08:16 +0100)
committerTom de Vries <tdevries@suse.de>
Tue, 7 Dec 2021 07:16:42 +0000 (08:16 +0100)
commitc178f2a133740e64344da6484f71807f236a3c00
tree2605501bc4be4f352fbcb4bd812513fc6a5131e8
parent545e49f5ee911bbcf55dc3dbeb49b62103b205d4
[gdb/testsuite] Fix FAIL in gdb.tui/basic.exp

On openSUSE Leap 15.2 aarch64 I ran into:
...
FAIL: gdb.tui/basic.exp: check main is where we expect on the screen
...
while this is passing on x86_64.

On x86_64-linux we have at the initial screen dump for "list -q main":
...
 0 +-/home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.tui/tui-layout.c--+
 1 |       15     You should have received a copy of the GNU General Public |
 2 |       16     along with this program.  If not, see <http://www.gnu.org/|
 3 |       17                                                               |
 4 |       18  int                                                          |
 5 |       19  main ()                                                      |
 6 |       20  {                                                            |
 7 |       21    return 0;                                                  |
 8 |       22  }                                                            |
 9 |       23                                                               |
...
but on aarch64:
...
 0 +-/home/tdevries/gdb/src/gdb/testsuite/gdb.tui/tui-layout.c--------------+
 1 |       16     along with this program.  If not, see <http://www.gnu.org/|
 2 |       17                                                               |
 3 |       18  int                                                          |
 4 |       19  main ()                                                      |
 5 |       20  {                                                            |
 6 |       21    return 0;                                                  |
 7 |       22  }                                                            |
 8 |       23                                                               |
 9 |       24                                                               |
...

The cause of the diffferent placement is that we have as line number for main
on x86_64:
...
$ gdb -q -batch outputs/gdb.tui/basic/basic -ex "info line main"
Line 20 of "tui-layout.c" starts at address 0x4004a7 <main> \
  and ends at 0x4004ab <main+4>.
...
and on aarch64 instead:
...
$ gdb -q -batch outputs/gdb.tui/basic/basic -ex "info line main"
Line 21 of "tui-layout.c" starts at address 0x4005f4 <main> \
  and ends at 0x4005f8 <main+4>.
...

Fix this by using a new source file main-one-line.c, that implements the
entire main function on a single line, in order to force the compiler to use
that line number.

Also try to do less hard-coding in the test-case.

Tested on x86_64-linux and aarch64-linux.
gdb/testsuite/gdb.tui/basic.exp
gdb/testsuite/gdb.tui/main-one-line.c [new file with mode: 0644]