Fix resolving GNU ifunc bp locations when inferior runs resolver
authorPedro Alves <palves@redhat.com>
Thu, 26 Apr 2018 12:01:27 +0000 (13:01 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 26 Apr 2018 12:12:09 +0000 (13:12 +0100)
commit79188d8d27a8885aee2ca4ff55238219a6aa7228
treec788f1f13d5e7d51ef9f402cc4f3a92678113824
parentc7075ad5030c4c2e79a04f3517689b751ff41860
Fix resolving GNU ifunc bp locations when inferior runs resolver

I noticed that if you set a breakpoint on an ifunc before the ifunc is
resolved, and then let the program call the ifunc, thus resolving it,
GDB end up with a location for that original breakpoint that is
pointing to the ifunc target, but it is left pointing to the first
address of the function, instead of after its prologue.  After
prologue is what you get if you create a new breakpoint at that point.

1) With no debug info for the target function:

  1.a) Set before resolving, and then program continued passed resolving:

    Num     Type           Disp Enb Address            What
    1       breakpoint     keep y   0x0000000000400753 <final>

  1.b) Breakpoint set after inferior resolved ifunc:

    Num     Type           Disp Enb Address            What
    2       breakpoint     keep y   0x0000000000400757 <final+4>

2) With debug info for the target function:

   1.a) Set before resolving, and then program continued passed resolving:

     Num     Type           Disp Enb Address            What
     1       breakpoint     keep y   0x0000000000400753 in final at gdb/testsuite/gdb.base/gnu-ifunc-final.c:20

   1.b) Breakpoint set after inferior resolved ifunc:

     Num     Type           Disp Enb Address            What
     2       breakpoint     keep y   0x000000000040075a in final at gdb/testsuite/gdb.base/gnu-ifunc-final.c:21

The problem is that elf_gnu_ifunc_resolver_return_stop (called by the
internal breakpoint that traps the resolver returning) does not agree
with linespec.c:minsym_found.  It does not skip to the function's
start line (i.e., past the prologue).  We can now use the
find_function_start_sal overload added by the previous commmit to fix
this.

New tests included, which fail before the patch, and pass afterwards.

gdb/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

* elfread.c (elf_gnu_ifunc_resolver_return_stop): Use
find_function_start_sal instead of find_pc_line.

gdb/testsuite/ChangeLog:
2018-04-26  Pedro Alves  <palves@redhat.com>

* gdb.base/gnu-ifunc.exp (set-break): Test that GDB resolves
ifunc breakpoint locations correctly of ifunc breakpoints set
while the program resolves the ifunc.
gdb/ChangeLog
gdb/elfread.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/gnu-ifunc.exp