[gdb/testsuite] Fix gdb.dwarf2/dw2-dir-file-name.exp
authorTom de Vries <tdevries@suse.de>
Fri, 12 Aug 2022 09:48:21 +0000 (11:48 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 12 Aug 2022 09:48:21 +0000 (11:48 +0200)
commitcd919f5533cc8aa495acd75a6f059e5fcf2e6af9
tree4f9655b8aa6aa4a0484a5d053b9ec416c907cc81
parent6f419c9825f35182e4284e7f51b3789e79c1d298
[gdb/testsuite] Fix gdb.dwarf2/dw2-dir-file-name.exp

When running test-case gdb.dwarf2/dw2-dir-file-name.exp on x86_64-linux, we
have:
...
(gdb) break compdir_missing__ldir_missing__file_basename^M
Breakpoint 2 at 0x4004c4: file tmp-dw2-dir-file-name.c, line 999.^M
(gdb) continue^M
Continuing.^M
^M
Breakpoint 2, 0x00000000004004c4 in \
  compdir_missing__ldir_missing__file_basename () \
  at tmp-dw2-dir-file-name.c:999^M
(gdb) PASS: gdb.dwarf2/dw2-dir-file-name.exp: \
  compdir_missing__ldir_missing__file_basename: continue to breakpoint: \
  compdir_missing__ldir_missing__file_basename
...

When trying to set a breakpoint on
compdir_missing__ldir_missing__file_basename, the architecture-specific
prologue skipper starts at 0x4004c0 and skips past two insns, to 0x4004c4:
...
00000000004004c0 <compdir_missing__ldir_missing__file_basename>:
  4004c0: 55                      push   %rbp
  4004c1: 48 89 e5                mov    %rsp,%rbp
  4004c4: 8b 05 72 1b 20 00       mov    0x201b72(%rip),%eax        # 60203c <v>
  4004ca: 83 c0 01                add    $0x1,%eax
  4004cd: 89 05 69 1b 20 00       mov    %eax,0x201b69(%rip)        # 60203c <v>
  4004d3: 90                      nop
  4004d4: 5d                      pop    %rbp
  4004d5: c3                      ret
...

And because the line table info is rudamentary:
...
CU: tmp-dw2-dir-file-name.c:
File name                    Line number    Starting address    View    Stmt
tmp-dw2-dir-file-name.c              999            0x4004c0               x
tmp-dw2-dir-file-name.c             1000            0x4004d6               x
tmp-dw2-dir-file-name.c                -            0x4004d6
...
the address does not fall at an actual line, so the breakpoint is shown with
address, both when setting it and hitting it.

when running the test-case with aarch64-linux, we have similarly:
...
(gdb) break compdir_missing__ldir_missing__file_basename^M
Breakpoint 2 at 0x400618: file tmp-dw2-dir-file-name.c, line 999.^M
...
due to the architecture-specific prologue skipper starting at 0x400610 and
skipping past two insns, to 0x400618:
...
0000000000400610 <compdir_missing__ldir_missing__file_basename>:
  400610:       90000100        adrp    x0, 420000 <__libc_start_main@GLIBC_2.17>
  400614:       9100b000        add     x0, x0, #0x2c
  400618:       b9400000        ldr     w0, [x0]
  40061c:       11000401        add     w1, w0, #0x1
  400620:       90000100        adrp    x0, 420000 <__libc_start_main@GLIBC_2.17>
  400624:       9100b000        add     x0, x0, #0x2c
  400628:       b9000001        str     w1, [x0]
  40062c:       d503201f        nop
  400630:       d65f03c0        ret
...

But interestingly, the aarch64 architecture-specific prologue skipper is
wrong.  There is no prologue, and the breakpoint should be set at 0x400610.

By using "break *compdir_missing__ldir_missing__file_basename"
we can get the breakpoint set at 0x400610:
...
(gdb) break *compdir_missing__ldir_missing__file_basename^M
Breakpoint 2 at 0x400610: file tmp-dw2-dir-file-name.c, line 999.^M
...
and make the test-case independent of prologue analysis.

This requires us to update the expected patterns.

The fix ensures that once the aarch64 architecture-specific prologue skipper
will be fixed, this test-case won't start failing.

Tested on x86_64-linux.
gdb/testsuite/gdb.dwarf2/dw2-dir-file-name.exp
gdb/testsuite/lib/gdb.exp