gdb: fix 'info frame' for tail calls with no debug information

If the inferior stack contains a tail call function.  And if the CU
containing the tail call function doesn't have any debug information.
And if the user uses 'info frame' to examine the tail call frame, then
GDB will report the wrong function name, for example:

  Breakpoint 1, 0x000000000040110a in callee ()
  (gdb) bt
  #0  0x000000000040110a in callee ()
  #1  0x0000000000401116 in caller ()
  #2  0x0000000000401140 in main ()
  (gdb) up
  #1  0x0000000000401116 in caller ()
  (gdb) frame
  #1  0x0000000000401116 in caller ()
  (gdb) info frame
  Stack level 1, frame at 0x7fffffffa440:
   rip = 0x401116 in dummy_func; saved rip = 0x401140
   called by frame at 0x7fffffffa450, caller of frame at 0x7fffffffa430
   Arglist at 0x7fffffffa430, args:
   Locals at 0x7fffffffa430, Previous frame's sp is 0x7fffffffa440
   Saved registers:
    rbp at 0x7fffffffa430, rip at 0x7fffffffa438
  (gdb)

Notice that 'info frame' claims that the current frame is 'dummy_func'
rather than 'caller', as the 'backtrace', 'up', and 'frame' commands
claim.

This is because 'backtrace', 'up', and 'frame' all uses print_frame to
print the frame details, which in turn uses find_frame_funname to get
the frame's function name.

In contrast, 'info_frame_command_core' contains an inlined copy of
'find_frame_funname' with one key difference.  The code in
info_frame_command_core uses get_frame_pc_if_available while
find_frame_funname uses get_frame_address_in_block_if_available.  The
latter function returns '$pc - 1' if the frame in question could be a
tail call function, while get_frame_pc_if_available always returns
$pc.  This difference means that, for a tail call function, GDB will
lookup the wrong msymbol.

Fix this by updating info_frame_command_core to use
find_frame_funname.  We end up still keeping the call to
get_frame_pc_if_available as 'info frame' still needs to print this
address.  There should be no other noticeable changes after this
commit.

There's also a test in which I have tried to create a tail call
function in a (relatively) target agnostic way.  I compile a test
program, pull some addresses from it, then recompile the test to
assembly, and augment the assembler output, changing one symbol size,
and adding an entirely new function symbol.  The modified assembly
file is then compiled, without debug information, to create the actual
test executable.  This gives GDB the impression that the test contains
a tail call function.

Approved-By: Tom Tromey <tom@tromey.com>
3 files changed