Blame SOURCES/gdb-upstream.patch

be09dc
http://sourceware.org/ml/gdb-patches/2016-03/msg00013.html
be09dc
Subject: [PATCH 1/2] Fix PR gdb/19676: Disable displaced stepping if /proc not mounted
be09dc
be09dc
On GNU/Linux archs that support displaced stepping, if /proc is not
be09dc
mounted, GDB gets stuck not able to step past breakpoints:
be09dc
be09dc
 (gdb) c
be09dc
 Continuing.
be09dc
 dl_main (phdr=<optimized out>, phnum=<optimized out>, user_entry=<optimized out>, auxv=<optimized out>) at rtld.c:2163
be09dc
 2163      LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
be09dc
 Cannot find AT_ENTRY auxiliary vector entry.
be09dc
 (gdb) c
be09dc
 Continuing.
be09dc
 dl_main (phdr=<optimized out>, phnum=<optimized out>, user_entry=<optimized out>, auxv=<optimized out>) at rtld.c:2163
be09dc
 2163      LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
be09dc
 Cannot find AT_ENTRY auxiliary vector entry.
be09dc
 (gdb)
be09dc
be09dc
That's because GDB can't figure out where the scratch pad is.
be09dc
be09dc
This is a regression introduced by the earlier changes to make the
be09dc
Linux native target always work in non-stop mode.
be09dc
be09dc
This commit makes GDB detect the case and fallback to stepping over
be09dc
breakpoints in-line.
be09dc
be09dc
gdb/ChangeLog:
be09dc
2016-03-01  Pedro Alves  <pedro@cascais.lan>
be09dc
be09dc
	PR gdb/19676
be09dc
	* infrun.c (displaced_step_prepare): Also disable displaced
be09dc
	stepping on NOT_SUPPORTED_ERROR.
be09dc
	* linux-tdep.c (linux_displaced_step_location): If reading auxv
be09dc
	fails, throw NOT_SUPPORTED_ERROR instead of generic error.
be09dc
---
be09dc
 gdb/infrun.c     | 3 ++-
be09dc
 gdb/linux-tdep.c | 3 ++-
be09dc
 2 files changed, 4 insertions(+), 2 deletions(-)
be09dc
be09dc
diff --git a/gdb/infrun.c b/gdb/infrun.c
be09dc
index 3e8c9e0..696105d 100644
be09dc
--- a/gdb/infrun.c
be09dc
+++ b/gdb/infrun.c
be09dc
@@ -1894,7 +1894,8 @@ displaced_step_prepare (ptid_t ptid)
be09dc
     {
be09dc
       struct displaced_step_inferior_state *displaced_state;
be09dc
 
be09dc
-      if (ex.error != MEMORY_ERROR)
be09dc
+      if (ex.error != MEMORY_ERROR
be09dc
+	  && ex.error != NOT_SUPPORTED_ERROR)
be09dc
 	throw_exception (ex);
be09dc
 
be09dc
       if (debug_infrun)
be09dc
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
be09dc
index 555c302..f197aa7 100644
be09dc
--- a/gdb/linux-tdep.c
be09dc
+++ b/gdb/linux-tdep.c
be09dc
@@ -2426,7 +2426,8 @@ linux_displaced_step_location (struct gdbarch *gdbarch)
be09dc
      location.  The auxiliary vector gets us the PowerPC-side entry
be09dc
      point address instead.  */
be09dc
   if (target_auxv_search (&current_target, AT_ENTRY, &addr) <= 0)
be09dc
-    error (_("Cannot find AT_ENTRY auxiliary vector entry."));
be09dc
+    throw_error (NOT_SUPPORTED_ERROR,
be09dc
+		 _("Cannot find AT_ENTRY auxiliary vector entry."));
be09dc
 
be09dc
   /* Make certain that the address points at real code, and not a
be09dc
      function descriptor.  */
be09dc
-- 
be09dc
2.5.0
be09dc
be09dc
be09dc
be09dc
http://sourceware.org/ml/gdb-patches/2016-03/msg00014.html
be09dc
Subject: [PATCH 2/2] Fix PR gdb/19676: Internal error in linux-thread.db.c if /proc not mounted
be09dc
be09dc
If /proc is not mounted, GDB fails an assertion in find_new_threads_once:
be09dc
be09dc
 Continuing.
be09dc
 /home/pedro/gdb/mygit/src/gdb/linux-thread-db.c:1249: internal-error: find_new_threads_once: Assertion `!target_has_execution' failed.
be09dc
 A problem internal to GDB has been detected,
be09dc
 further debugging may prove unreliable.
be09dc
 Quit this debugging session? (y or n)
be09dc
be09dc
That was supposed to catch misuses of td_ta_thr_iter, which is unsafe
be09dc
for live debugging.  However, if /proc is not mounted, we still
be09dc
fallback to using it.
be09dc
be09dc
I didn't bother with a warning, because GDB already prints several
be09dc
others related to failing to open /proc files.
be09dc
be09dc
gdb/ChangeLog:
be09dc
2016-03-01  Pedro Alves  <pedro@cascais.lan>
be09dc
be09dc
	PR gdb/19676
be09dc
	* linux-thread-db.c (try_thread_db_load_1): Leave
be09dc
	info->td_ta_thr_iter_p NULL iff debugging a live process and we
be09dc
	have /proc access.
be09dc
	(find_new_threads_once): Assert that we have a non-NULL
be09dc
	info->td_ta_thr_iter_p instead of checking whether the target has
be09dc
	execution.
be09dc
---
be09dc
 gdb/linux-thread-db.c | 16 ++++++++++------
be09dc
 1 file changed, 10 insertions(+), 6 deletions(-)
be09dc
be09dc
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
be09dc
index 1eb457d..ce60beb 100644
be09dc
--- a/gdb/linux-thread-db.c
be09dc
+++ b/gdb/linux-thread-db.c
be09dc
@@ -564,7 +564,6 @@ try_thread_db_load_1 (struct thread_db_info *info)
be09dc
 
be09dc
   /* These are essential.  */
be09dc
   CHK (TDB_VERBOSE_DLSYM (info, td_ta_map_lwp2thr));
be09dc
-  CHK (TDB_VERBOSE_DLSYM (info, td_ta_thr_iter));
be09dc
   CHK (TDB_VERBOSE_DLSYM (info, td_thr_validate));
be09dc
   CHK (TDB_VERBOSE_DLSYM (info, td_thr_get_info));
be09dc
 
be09dc
@@ -572,10 +571,6 @@ try_thread_db_load_1 (struct thread_db_info *info)
be09dc
   TDB_DLSYM (info, td_thr_tls_get_addr);
be09dc
   TDB_DLSYM (info, td_thr_tlsbase);
be09dc
 
be09dc
-#undef TDB_VERBOSE_DLSYM
be09dc
-#undef TDB_DLSYM
be09dc
-#undef CHK
be09dc
-
be09dc
   /* It's best to avoid td_ta_thr_iter if possible.  That walks data
be09dc
      structures in the inferior's address space that may be corrupted,
be09dc
      or, if the target is running, may change while we walk them.  If
be09dc
@@ -587,6 +582,15 @@ try_thread_db_load_1 (struct thread_db_info *info)
be09dc
      currently on core targets, as it uses ptrace directly.  */
be09dc
   if (target_has_execution
be09dc
       && linux_proc_task_list_dir_exists (ptid_get_pid (inferior_ptid)))
be09dc
+    info->td_ta_thr_iter_p = NULL;
be09dc
+  else
be09dc
+    CHK (TDB_VERBOSE_DLSYM (info, td_ta_thr_iter));
be09dc
+
be09dc
+#undef TDB_VERBOSE_DLSYM
be09dc
+#undef TDB_DLSYM
be09dc
+#undef CHK
be09dc
+
be09dc
+  if (info->td_ta_thr_iter_p == NULL)
be09dc
     {
be09dc
       struct lwp_info *lp;
be09dc
       int pid = ptid_get_pid (inferior_ptid);
be09dc
@@ -1246,7 +1250,7 @@ find_new_threads_once (struct thread_db_info *info, int iteration,
be09dc
   data.new_threads = 0;
be09dc
 
be09dc
   /* See comment in thread_db_update_thread_list.  */
be09dc
-  gdb_assert (!target_has_execution);
be09dc
+  gdb_assert (info->td_ta_thr_iter_p != NULL);
be09dc
 
be09dc
   TRY
be09dc
     {
be09dc
-- 
be09dc
2.5.0
be09dc
be09dc
be09dc
be09dc
http://sourceware.org/ml/gdb-patches/2016-03/msg00246.html
be09dc
Subject: [patch] Suggest running gdbserver for a PID in container
be09dc
be09dc
be09dc
--azLHFNyN32YCQGCU
be09dc
Content-Type: text/plain; charset=us-ascii
be09dc
Content-Disposition: inline
be09dc
be09dc
Hi,
be09dc
be09dc
currently
be09dc
	gdb -p <pid from a container>
be09dc
will print:
be09dc
	warning: Target and debugger are in different PID namespaces; thread lists and other data are likely unreliable
be09dc
be09dc
BTW it is a bit lost in all the other messages.  Full screen output is in:
be09dc
	https://sourceware.org/bugzilla/show_bug.cgi?id=19828
be09dc
be09dc
It correctly states the problem but it does not say how to solve it.
be09dc
be09dc
Is at least this little suggestion OK?
be09dc
be09dc
Originally I wanted to suggest also the Docker "-p 1234:1234" parameter but
be09dc
I see the containers are more general topic than just Docker (even LxC etc.).
be09dc
be09dc
According to Gary future GDBs should be able to work even without gdbserver.
be09dc
But currently gdbserver is still required.
be09dc
be09dc
be09dc
Thanks,
be09dc
Jan
be09dc
be09dc
--azLHFNyN32YCQGCU
be09dc
Content-Type: text/plain; charset=us-ascii
be09dc
Content-Disposition: inline; filename=1
be09dc
be09dc
gdb/ChangeLog
be09dc
2016-03-15  Jan Kratochvil  <jan.kratochvil@redhat.com>
be09dc
be09dc
	* linux-thread-db.c (check_pid_namespace_match): Extend the message.
be09dc
be09dc
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
be09dc
index 1eb457d..21166bf 100644
be09dc
--- a/gdb/linux-thread-db.c
be09dc
+++ b/gdb/linux-thread-db.c
be09dc
@@ -1020,7 +1020,8 @@ check_pid_namespace_match (void)
be09dc
 	{
be09dc
 	  warning (_ ("Target and debugger are in different PID "
be09dc
 		      "namespaces; thread lists and other data are "
be09dc
-		      "likely unreliable"));
be09dc
+		      "likely unreliable.  "
be09dc
+		      "Connect to gdbserver inside the container."));
be09dc
 	}
be09dc
     }
be09dc
 }
be09dc
be09dc
--azLHFNyN32YCQGCU--
be09dc
be09dc
be09dc
be09dc
commit fef3cb9f3aa84018d10866f89228ae3f23e5ca7e
be09dc
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
be09dc
Date:   Wed Apr 6 15:57:08 2016 +0200
be09dc
be09dc
    Print the "file" command suggestion in exec_file_locate_attach
be09dc
    
be09dc
    currently:
be09dc
    	$ gdbserver-7.9 :1234 true &
be09dc
    	$ gdb -q -ex 'target remote :1234' # that -q is not relevant here
be09dc
    	Remote debugging using :1234
be09dc
    	warning: Could not load vsyscall page because no executable was specified
be09dc
    	try using the "file" command first.
be09dc
    	0x00007ffff7ddcc80 in ?? ()
be09dc
    	(gdb) b main
be09dc
    	No symbol table is loaded.  Use the "file" command.
be09dc
    	Make breakpoint pending on future shared library load? (y or [n]) _
be09dc
    
be09dc
    Provide more suggestive message to use the "file" command.
be09dc
    
be09dc
    gdb/ChangeLog
be09dc
    2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
be09dc
    	    Pedro Alves  <palves@redhat.com>
be09dc
    
be09dc
    	* exec.c (exec_file_locate_attach): Print warning for unsupported
be09dc
    	target_pid_to_exec_file.
be09dc
    	* symfile-mem.c (add_vsyscall_page): Remove the "file" command
be09dc
    	message part.
be09dc
be09dc
### a/gdb/ChangeLog
be09dc
### b/gdb/ChangeLog
be09dc
## -1,3 +1,11 @@
be09dc
+2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
be09dc
+	    Pedro Alves  <palves@redhat.com>
be09dc
+
be09dc
+	* exec.c (exec_file_locate_attach): Print warning for unsupported
be09dc
+	target_pid_to_exec_file.
be09dc
+	* symfile-mem.c (add_vsyscall_page): Remove the "file" command
be09dc
+	message part.
be09dc
+
be09dc
 2016-04-04  Simon Marchi  <simon.marchi@ericsson.com>
be09dc
 
be09dc
 	* cli/cli-decode.c (help_cmd_list): Fix function doc and remove
be09dc
--- a/gdb/exec.c
be09dc
+++ b/gdb/exec.c
be09dc
@@ -151,7 +151,13 @@ exec_file_locate_attach (int pid, int from_tty)
be09dc
   /* Try to determine a filename from the process itself.  */
be09dc
   exec_file = target_pid_to_exec_file (pid);
be09dc
   if (exec_file == NULL)
be09dc
-    return;
be09dc
+    {
be09dc
+      warning (_("No executable has been specified and target does not "
be09dc
+		 "support\n"
be09dc
+		 "determining executable automatically.  "
be09dc
+		 "Try using the \"file\" command."));
be09dc
+      return;
be09dc
+    }
be09dc
 
be09dc
   /* If gdb_sysroot is not empty and the discovered filename
be09dc
      is absolute then prefix the filename with gdb_sysroot.  */
be09dc
--- a/gdb/symfile-mem.c
be09dc
+++ b/gdb/symfile-mem.c
be09dc
@@ -214,8 +214,7 @@ add_vsyscall_page (struct target_ops *target, int from_tty)
be09dc
 	  format should fix this.  */
be09dc
 	{
be09dc
 	  warning (_("Could not load vsyscall page "
be09dc
-		     "because no executable was specified\n"
be09dc
-		     "try using the \"file\" command first."));
be09dc
+		     "because no executable was specified"));
be09dc
 	  return;
be09dc
 	}
be09dc
       args.bfd = bfd;
be09dc
be09dc
be09dc
be09dc
commit 2ef34d11f61d79dcb152713aa059051d8cd3295d
be09dc
Author: Markus Metzger <markus.t.metzger@intel.com>
be09dc
Date:   Fri Feb 5 09:32:53 2016 +0100
be09dc
be09dc
    btrace: fix PR gdb/19829
be09dc
    
be09dc
    This is a backport of
be09dc
    
be09dc
    33b4777ca1b7 btrace, frame: fix crash in get_frame_type
be09dc
    a038fa3e14a4 stack: check frame_unwind_caller_id
be09dc
    2f3ef606b912 frame: add skip_tailcall_frames
be09dc
    
be09dc
    In skip_artificial_frames we repeatedly call get_prev_frame_always until we get
be09dc
    a non-inline and non-tailcall frame assuming that there must be such a frame
be09dc
    eventually.
be09dc
    
be09dc
    For record targets, however, we may have a frame chain that consists only of
be09dc
    artificial frames.  This leads to a crash in get_frame_type when dereferencing a
be09dc
    NULL frame pointer.
be09dc
    
be09dc
    Change skip_artificial_frames and skip_tailcall_frames to return NULL in such a
be09dc
    case and modify each caller to cope with a NULL return.
be09dc
    
be09dc
    In frame_unwind_caller_pc and frame_unwind_caller_arch, we simply assert that
be09dc
    the returned value is not NULL.  Their caller was supposed to check
be09dc
    frame_unwind_caller_id before calling those functions.
be09dc
    
be09dc
    In other cases, we thrown an error.
be09dc
    
be09dc
    In infcmd further move the skip_tailcall_frames call to the forward-stepping
be09dc
    case since we don't need a frame for reverse execution and we don't want to fail
be09dc
    because of that.  Reverse-finish does make sense for a tailcall frame.
be09dc
    
be09dc
    gdb/
be09dc
    	* frame.h (skip_tailcall_frames): New.
be09dc
    	* infcmd.c (finish_command): Call skip_tailcall_frames.
be09dc
    	* frame.c (skip_artificial_frames): Return NULL if only artificial frames
be09dc
    	are found.  Update comment.
be09dc
    	(frame_pop): Call skip_tailcall_frames.
be09dc
    	(frame_unwind_caller_id): Handle NULL return.
be09dc
    	(frame_unwind_caller_pc, frame_unwind_caller_arch): Assert that
be09dc
    	skip_artificial_frames does not return NULL.
be09dc
    	(frame_pop): Add an error if only tailcall frames are found.
be09dc
    	* infcmd.c (finish_command): Move skip_tailcall_frames call into forward-
be09dc
    	execution case.  Add an error if only tailcall frames are found.
be09dc
    	* stack.c (frame_info): Check frame_unwind_caller_id.
be09dc
    
be09dc
    testsuite/
be09dc
    	* gdb.btrace/tailcall-only.exp: New.
be09dc
    	* gdb.btrace/tailcall-only.c: New.
be09dc
    	* gdb.btrace/x86_64-tailcall-only.S: New.
be09dc
    	* gdb.btrace/i686-tailcall-only.S: New.
be09dc
be09dc
### a/gdb/ChangeLog
be09dc
### b/gdb/ChangeLog
be09dc
## -1,3 +1,19 @@
be09dc
+2016-03-17  Markus Metzger  <markus.t.metzger@intel.com>
be09dc
+
be09dc
+	PR gdb/19829
be09dc
+	* frame.h (skip_tailcall_frames): New.
be09dc
+	* infcmd.c (finish_command): Call skip_tailcall_frames.
be09dc
+	* frame.c (skip_artificial_frames): Return NULL if only artificial
be09dc
+	frames are found.  Update comment.
be09dc
+	(frame_pop): Call skip_tailcall_frames.
be09dc
+	(frame_unwind_caller_id): Handle NULL return.
be09dc
+	(frame_unwind_caller_pc, frame_unwind_caller_arch): Assert that
be09dc
+	skip_artificial_frames does not return NULL.
be09dc
+	(frame_pop): Add an error if only tailcall frames are found.
be09dc
+	* infcmd.c (finish_command): Move skip_tailcall_frames call into
be09dc
+	forward-execution case.  Add an error if only tailcall frames are found.
be09dc
+	* stack.c (frame_info): Check frame_unwind_caller_id.
be09dc
+
be09dc
 2016-03-15  Pedro Alves  <palves@redhat.com>
be09dc
 
be09dc
 	PR gdb/19676
be09dc
--- a/gdb/frame.c
be09dc
+++ b/gdb/frame.c
be09dc
@@ -420,7 +420,8 @@ fprint_frame (struct ui_file *file, struct frame_info *fi)
be09dc
 
be09dc
 /* Given FRAME, return the enclosing frame as found in real frames read-in from
be09dc
    inferior memory.  Skip any previous frames which were made up by GDB.
be09dc
-   Return the original frame if no immediate previous frames exist.  */
be09dc
+   Return FRAME if FRAME is a non-artificial frame.
be09dc
+   Return NULL if FRAME is the start of an artificial-only chain.  */
be09dc
 
be09dc
 static struct frame_info *
be09dc
 skip_artificial_frames (struct frame_info *frame)
be09dc
@@ -428,12 +429,34 @@ skip_artificial_frames (struct frame_info *frame)
be09dc
   /* Note we use get_prev_frame_always, and not get_prev_frame.  The
be09dc
      latter will truncate the frame chain, leading to this function
be09dc
      unintentionally returning a null_frame_id (e.g., when the user
be09dc
-     sets a backtrace limit).  This is safe, because as these frames
be09dc
-     are made up by GDB, there must be a real frame in the chain
be09dc
-     below.  */
be09dc
+     sets a backtrace limit).
be09dc
+
be09dc
+     Note that for record targets we may get a frame chain that consists
be09dc
+     of artificial frames only.  */
be09dc
   while (get_frame_type (frame) == INLINE_FRAME
be09dc
 	 || get_frame_type (frame) == TAILCALL_FRAME)
be09dc
-    frame = get_prev_frame_always (frame);
be09dc
+    {
be09dc
+      frame = get_prev_frame_always (frame);
be09dc
+      if (frame == NULL)
be09dc
+	break;
be09dc
+    }
be09dc
+
be09dc
+  return frame;
be09dc
+}
be09dc
+
be09dc
+/* See frame.h.  */
be09dc
+
be09dc
+struct frame_info *
be09dc
+skip_tailcall_frames (struct frame_info *frame)
be09dc
+{
be09dc
+  while (get_frame_type (frame) == TAILCALL_FRAME)
be09dc
+    {
be09dc
+      /* Note that for record targets we may get a frame chain that consists of
be09dc
+	 tailcall frames only.  */
be09dc
+      frame = get_prev_frame (frame);
be09dc
+      if (frame == NULL)
be09dc
+	break;
be09dc
+    }
be09dc
 
be09dc
   return frame;
be09dc
 }
be09dc
@@ -496,6 +519,9 @@ frame_unwind_caller_id (struct frame_info *next_frame)
be09dc
      requests the frame ID of "main()"s caller.  */
be09dc
 
be09dc
   next_frame = skip_artificial_frames (next_frame);
be09dc
+  if (next_frame == NULL)
be09dc
+    return null_frame_id;
be09dc
+
be09dc
   this_frame = get_prev_frame_always (next_frame);
be09dc
   if (this_frame)
be09dc
     return get_frame_id (skip_artificial_frames (this_frame));
be09dc
@@ -869,7 +895,14 @@ frame_unwind_pc (struct frame_info *this_frame)
be09dc
 CORE_ADDR
be09dc
 frame_unwind_caller_pc (struct frame_info *this_frame)
be09dc
 {
be09dc
-  return frame_unwind_pc (skip_artificial_frames (this_frame));
be09dc
+  this_frame = skip_artificial_frames (this_frame);
be09dc
+
be09dc
+  /* We must have a non-artificial frame.  The caller is supposed to check
be09dc
+     the result of frame_unwind_caller_id (), which returns NULL_FRAME_ID
be09dc
+     in this case.  */
be09dc
+  gdb_assert (this_frame != NULL);
be09dc
+
be09dc
+  return frame_unwind_pc (this_frame);
be09dc
 }
be09dc
 
be09dc
 int
be09dc
@@ -972,8 +1005,10 @@ frame_pop (struct frame_info *this_frame)
be09dc
 
be09dc
   /* Ignore TAILCALL_FRAME type frames, they were executed already before
be09dc
      entering THISFRAME.  */
be09dc
-  while (get_frame_type (prev_frame) == TAILCALL_FRAME)
be09dc
-    prev_frame = get_prev_frame (prev_frame);
be09dc
+  prev_frame = skip_tailcall_frames (prev_frame);
be09dc
+
be09dc
+  if (prev_frame == NULL)
be09dc
+    error (_("Cannot find the caller frame."));
be09dc
 
be09dc
   /* Make a copy of all the register values unwound from this frame.
be09dc
      Save them in a scratch buffer so that there isn't a race between
be09dc
@@ -2561,7 +2596,14 @@ frame_unwind_arch (struct frame_info *next_frame)
be09dc
 struct gdbarch *
be09dc
 frame_unwind_caller_arch (struct frame_info *next_frame)
be09dc
 {
be09dc
-  return frame_unwind_arch (skip_artificial_frames (next_frame));
be09dc
+  next_frame = skip_artificial_frames (next_frame);
be09dc
+
be09dc
+  /* We must have a non-artificial frame.  The caller is supposed to check
be09dc
+     the result of frame_unwind_caller_id (), which returns NULL_FRAME_ID
be09dc
+     in this case.  */
be09dc
+  gdb_assert (next_frame != NULL);
be09dc
+
be09dc
+  return frame_unwind_arch (next_frame);
be09dc
 }
be09dc
 
be09dc
 /* Gets the language of FRAME.  */
be09dc
--- a/gdb/frame.h
be09dc
+++ b/gdb/frame.h
be09dc
@@ -820,5 +820,10 @@ extern int frame_unwinder_is (struct frame_info *fi,
be09dc
 
be09dc
 extern enum language get_frame_language (struct frame_info *frame);
be09dc
 
be09dc
+/* Return the first non-tailcall frame above FRAME or FRAME if it is not a
be09dc
+   tailcall frame.  Return NULL if FRAME is the start of a tailcall-only
be09dc
+   chain.  */
be09dc
+
be09dc
+extern struct frame_info *skip_tailcall_frames (struct frame_info *frame);
be09dc
 
be09dc
 #endif /* !defined (FRAME_H)  */
be09dc
--- a/gdb/infcmd.c
be09dc
+++ b/gdb/infcmd.c
be09dc
@@ -2000,11 +2000,6 @@ finish_command (char *arg, int from_tty)
be09dc
       return;
be09dc
     }
be09dc
 
be09dc
-  /* Ignore TAILCALL_FRAME type frames, they were executed already before
be09dc
-     entering THISFRAME.  */
be09dc
-  while (get_frame_type (frame) == TAILCALL_FRAME)
be09dc
-    frame = get_prev_frame (frame);
be09dc
-
be09dc
   /* Find the function we will return from.  */
be09dc
 
be09dc
   sm->function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
be09dc
@@ -2031,7 +2026,16 @@ finish_command (char *arg, int from_tty)
be09dc
   if (execution_direction == EXEC_REVERSE)
be09dc
     finish_backward (sm);
be09dc
   else
be09dc
-    finish_forward (sm, frame);
be09dc
+    {
be09dc
+      /* Ignore TAILCALL_FRAME type frames, they were executed already before
be09dc
+	 entering THISFRAME.  */
be09dc
+      frame = skip_tailcall_frames (frame);
be09dc
+
be09dc
+      if (frame == NULL)
be09dc
+	error (_("Cannot find the caller frame."));
be09dc
+
be09dc
+      finish_forward (sm, frame);
be09dc
+    }
be09dc
 }
be09dc
 
be09dc
 
be09dc
--- a/gdb/stack.c
be09dc
+++ b/gdb/stack.c
be09dc
@@ -1509,27 +1509,32 @@ frame_info (char *addr_exp, int from_tty)
be09dc
   wrap_here ("    ");
be09dc
   printf_filtered ("saved %s = ", pc_regname);
be09dc
 
be09dc
-  TRY
be09dc
-    {
be09dc
-      caller_pc = frame_unwind_caller_pc (fi);
be09dc
-      caller_pc_p = 1;
be09dc
-    }
be09dc
-  CATCH (ex, RETURN_MASK_ERROR)
be09dc
+  if (!frame_id_p (frame_unwind_caller_id (fi)))
be09dc
+    val_print_unavailable (gdb_stdout);
be09dc
+  else
be09dc
     {
be09dc
-      switch (ex.error)
be09dc
+      TRY
be09dc
 	{
be09dc
-	case NOT_AVAILABLE_ERROR:
be09dc
-	  val_print_unavailable (gdb_stdout);
be09dc
-	  break;
be09dc
-	case OPTIMIZED_OUT_ERROR:
be09dc
-	  val_print_not_saved (gdb_stdout);
be09dc
-	  break;
be09dc
-	default:
be09dc
-	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
be09dc
-	  break;
be09dc
+	  caller_pc = frame_unwind_caller_pc (fi);
be09dc
+	  caller_pc_p = 1;
be09dc
 	}
be09dc
+      CATCH (ex, RETURN_MASK_ERROR)
be09dc
+	{
be09dc
+	  switch (ex.error)
be09dc
+	    {
be09dc
+	    case NOT_AVAILABLE_ERROR:
be09dc
+	      val_print_unavailable (gdb_stdout);
be09dc
+	      break;
be09dc
+	    case OPTIMIZED_OUT_ERROR:
be09dc
+	      val_print_not_saved (gdb_stdout);
be09dc
+	      break;
be09dc
+	    default:
be09dc
+	      fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
be09dc
+	      break;
be09dc
+	    }
be09dc
+	}
be09dc
+      END_CATCH
be09dc
     }
be09dc
-  END_CATCH
be09dc
 
be09dc
   if (caller_pc_p)
be09dc
     fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
be09dc
### a/gdb/testsuite/ChangeLog
be09dc
### b/gdb/testsuite/ChangeLog
be09dc
## -1,3 +1,11 @@
be09dc
+2016-03-17  Markus Metzger  <markus.t.metzger@intel.com>
be09dc
+
be09dc
+	PR gdb/19829
be09dc
+	* gdb.btrace/tailcall-only.exp: New.
be09dc
+	* gdb.btrace/tailcall-only.c: New.
be09dc
+	* gdb.btrace/x86_64-tailcall-only.S: New.
be09dc
+	* gdb.btrace/i686-tailcall-only.S: New.
be09dc
+
be09dc
 2016-02-16  Don Breazeal  <donb@codesourcery.com>
be09dc
 
be09dc
 	PR remote/19496
be09dc
--- /dev/null
be09dc
+++ b/gdb/testsuite/gdb.btrace/i686-tailcall-only.S
be09dc
@@ -0,0 +1,447 @@
be09dc
+/* This testcase is part of GDB, the GNU debugger.
be09dc
+
be09dc
+   Copyright 2016 Free Software Foundation, Inc.
be09dc
+
be09dc
+   This program is free software; you can redistribute it and/or modify
be09dc
+   it under the terms of the GNU General Public License as published by
be09dc
+   the Free Software Foundation; either version 3 of the License, or
be09dc
+   (at your option) any later version.
be09dc
+
be09dc
+   This program is distributed in the hope that it will be useful,
be09dc
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
be09dc
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
be09dc
+   GNU General Public License for more details.
be09dc
+
be09dc
+   You should have received a copy of the GNU General Public License
be09dc
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
be09dc
+
be09dc
+
be09dc
+   This file has been generated using:
be09dc
+   gcc -m32 -march=i686 -S -O2 -dA -g tailcall-only.c -o i686-tailcall-only.S
be09dc
+ */
be09dc
+
be09dc
+	.file	"tailcall-only.c"
be09dc
+	.text
be09dc
+.Ltext0:
be09dc
+	.p2align 4,,15
be09dc
+	.type	bar_1, @function
be09dc
+bar_1:
be09dc
+.LFB0:
be09dc
+	.file 1 "tailcall-only.c"
be09dc
+	# tailcall-only.c:22
be09dc
+	.loc 1 22 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:24
be09dc
+	.loc 1 24 0
be09dc
+	movl	$42, %eax
be09dc
+# SUCC: EXIT [100.0%]
be09dc
+	ret
be09dc
+	.cfi_endproc
be09dc
+.LFE0:
be09dc
+	.size	bar_1, .-bar_1
be09dc
+	.p2align 4,,15
be09dc
+	.type	bar, @function
be09dc
+bar:
be09dc
+.LFB1:
be09dc
+	# tailcall-only.c:28
be09dc
+	.loc 1 28 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:29
be09dc
+	.loc 1 29 0
be09dc
+	jmp	bar_1
be09dc
+# SUCC: EXIT [100.0%]  (ABNORMAL,SIBCALL)
be09dc
+.LVL0:
be09dc
+	.cfi_endproc
be09dc
+.LFE1:
be09dc
+	.size	bar, .-bar
be09dc
+	.p2align 4,,15
be09dc
+	.type	foo_1, @function
be09dc
+foo_1:
be09dc
+.LFB2:
be09dc
+	# tailcall-only.c:34
be09dc
+	.loc 1 34 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:35
be09dc
+	.loc 1 35 0
be09dc
+	jmp	bar
be09dc
+# SUCC: EXIT [100.0%]  (ABNORMAL,SIBCALL)
be09dc
+.LVL1:
be09dc
+	.cfi_endproc
be09dc
+.LFE2:
be09dc
+	.size	foo_1, .-foo_1
be09dc
+	.p2align 4,,15
be09dc
+	.type	foo, @function
be09dc
+foo:
be09dc
+.LFB3:
be09dc
+	# tailcall-only.c:40
be09dc
+	.loc 1 40 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:41
be09dc
+	.loc 1 41 0
be09dc
+	jmp	foo_1
be09dc
+# SUCC: EXIT [100.0%]  (ABNORMAL,SIBCALL)
be09dc
+.LVL2:
be09dc
+	.cfi_endproc
be09dc
+.LFE3:
be09dc
+	.size	foo, .-foo
be09dc
+	.section	.text.startup,"ax",@progbits
be09dc
+	.p2align 4,,15
be09dc
+	.globl	main
be09dc
+	.type	main, @function
be09dc
+main:
be09dc
+.LFB4:
be09dc
+	# tailcall-only.c:46
be09dc
+	.loc 1 46 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:49
be09dc
+	.loc 1 49 0
be09dc
+	call	foo
be09dc
+.LVL3:
be09dc
+	# tailcall-only.c:50
be09dc
+	.loc 1 50 0
be09dc
+	addl	$1, %eax
be09dc
+.LVL4:
be09dc
+# SUCC: EXIT [100.0%]
be09dc
+	# tailcall-only.c:53
be09dc
+	.loc 1 53 0
be09dc
+	ret
be09dc
+	.cfi_endproc
be09dc
+.LFE4:
be09dc
+	.size	main, .-main
be09dc
+	.text
be09dc
+.Letext0:
be09dc
+	.section	.debug_info,"",@progbits
be09dc
+.Ldebug_info0:
be09dc
+	.long	0xd5	# Length of Compilation Unit Info
be09dc
+	.value	0x4	# DWARF version number
be09dc
+	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
be09dc
+	.byte	0x4	# Pointer Size (in bytes)
be09dc
+	.uleb128 0x1	# (DIE (0xb) DW_TAG_compile_unit)
be09dc
+	.long	.LASF1	# DW_AT_producer: "GNU C 4.8.3 20140911 (Red Hat 4.8.3-9) -m32 -march=i686 -g -O2"
be09dc
+	.byte	0x1	# DW_AT_language
be09dc
+	.long	.LASF2	# DW_AT_name: "tailcall-only.c"
be09dc
+	.long	.LASF3	# DW_AT_comp_dir: ""
be09dc
+	.long	.Ldebug_ranges0+0	# DW_AT_ranges
be09dc
+	.long	0	# DW_AT_low_pc
be09dc
+	.long	.Ldebug_line0	# DW_AT_stmt_list
be09dc
+	.uleb128 0x2	# (DIE (0x25) DW_TAG_subprogram)
be09dc
+	.long	.LASF4	# DW_AT_name: "bar_1"
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x15	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x3a	# DW_AT_type
be09dc
+	.long	.LFB0	# DW_AT_low_pc
be09dc
+	.long	.LFE0-.LFB0	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.uleb128 0x3	# (DIE (0x3a) DW_TAG_base_type)
be09dc
+	.byte	0x4	# DW_AT_byte_size
be09dc
+	.byte	0x5	# DW_AT_encoding
be09dc
+	.ascii "int\0"	# DW_AT_name
be09dc
+	.uleb128 0x4	# (DIE (0x41) DW_TAG_subprogram)
be09dc
+	.ascii "bar\0"	# DW_AT_name
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x1b	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x3a	# DW_AT_type
be09dc
+	.long	.LFB1	# DW_AT_low_pc
be09dc
+	.long	.LFE1-.LFB1	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.long	0x64	# DW_AT_sibling
be09dc
+	.uleb128 0x5	# (DIE (0x5a) DW_TAG_GNU_call_site)
be09dc
+	.long	.LVL0	# DW_AT_low_pc
be09dc
+			# DW_AT_GNU_tail_call
be09dc
+	.long	0x25	# DW_AT_abstract_origin
be09dc
+	.byte	0	# end of children of DIE 0x41
be09dc
+	.uleb128 0x6	# (DIE (0x64) DW_TAG_subprogram)
be09dc
+	.long	.LASF0	# DW_AT_name: "foo_1"
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x21	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x3a	# DW_AT_type
be09dc
+	.long	.LFB2	# DW_AT_low_pc
be09dc
+	.long	.LFE2-.LFB2	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.long	0x87	# DW_AT_sibling
be09dc
+	.uleb128 0x5	# (DIE (0x7d) DW_TAG_GNU_call_site)
be09dc
+	.long	.LVL1	# DW_AT_low_pc
be09dc
+			# DW_AT_GNU_tail_call
be09dc
+	.long	0x41	# DW_AT_abstract_origin
be09dc
+	.byte	0	# end of children of DIE 0x64
be09dc
+	.uleb128 0x4	# (DIE (0x87) DW_TAG_subprogram)
be09dc
+	.ascii "foo\0"	# DW_AT_name
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x27	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x3a	# DW_AT_type
be09dc
+	.long	.LFB3	# DW_AT_low_pc
be09dc
+	.long	.LFE3-.LFB3	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.long	0xaa	# DW_AT_sibling
be09dc
+	.uleb128 0x5	# (DIE (0xa0) DW_TAG_GNU_call_site)
be09dc
+	.long	.LVL2	# DW_AT_low_pc
be09dc
+			# DW_AT_GNU_tail_call
be09dc
+	.long	0x64	# DW_AT_abstract_origin
be09dc
+	.byte	0	# end of children of DIE 0x87
be09dc
+	.uleb128 0x7	# (DIE (0xaa) DW_TAG_subprogram)
be09dc
+			# DW_AT_external
be09dc
+	.long	.LASF5	# DW_AT_name: "main"
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x2d	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x3a	# DW_AT_type
be09dc
+	.long	.LFB4	# DW_AT_low_pc
be09dc
+	.long	.LFE4-.LFB4	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.uleb128 0x8	# (DIE (0xbf) DW_TAG_variable)
be09dc
+	.long	.LASF6	# DW_AT_name: "answer"
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x2f	# DW_AT_decl_line
be09dc
+	.long	0x3a	# DW_AT_type
be09dc
+	.long	.LLST0	# DW_AT_location
be09dc
+	.uleb128 0x9	# (DIE (0xce) DW_TAG_GNU_call_site)
be09dc
+	.long	.LVL3	# DW_AT_low_pc
be09dc
+	.long	0x87	# DW_AT_abstract_origin
be09dc
+	.byte	0	# end of children of DIE 0xaa
be09dc
+	.byte	0	# end of children of DIE 0xb
be09dc
+	.section	.debug_abbrev,"",@progbits
be09dc
+.Ldebug_abbrev0:
be09dc
+	.uleb128 0x1	# (abbrev code)
be09dc
+	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
be09dc
+	.byte	0x1	# DW_children_yes
be09dc
+	.uleb128 0x25	# (DW_AT_producer)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x13	# (DW_AT_language)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x1b	# (DW_AT_comp_dir)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x55	# (DW_AT_ranges)
be09dc
+	.uleb128 0x17	# (DW_FORM_sec_offset)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x10	# (DW_AT_stmt_list)
be09dc
+	.uleb128 0x17	# (DW_FORM_sec_offset)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x2	# (abbrev code)
be09dc
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x27	# (DW_AT_prototyped)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x12	# (DW_AT_high_pc)
be09dc
+	.uleb128 0x6	# (DW_FORM_data4)
be09dc
+	.uleb128 0x40	# (DW_AT_frame_base)
be09dc
+	.uleb128 0x18	# (DW_FORM_exprloc)
be09dc
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x3	# (abbrev code)
be09dc
+	.uleb128 0x24	# (TAG: DW_TAG_base_type)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0xb	# (DW_AT_byte_size)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3e	# (DW_AT_encoding)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0x8	# (DW_FORM_string)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x4	# (abbrev code)
be09dc
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
be09dc
+	.byte	0x1	# DW_children_yes
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0x8	# (DW_FORM_string)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x27	# (DW_AT_prototyped)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x12	# (DW_AT_high_pc)
be09dc
+	.uleb128 0x6	# (DW_FORM_data4)
be09dc
+	.uleb128 0x40	# (DW_AT_frame_base)
be09dc
+	.uleb128 0x18	# (DW_FORM_exprloc)
be09dc
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x1	# (DW_AT_sibling)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x5	# (abbrev code)
be09dc
+	.uleb128 0x4109	# (TAG: DW_TAG_GNU_call_site)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x2115	# (DW_AT_GNU_tail_call)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x31	# (DW_AT_abstract_origin)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x6	# (abbrev code)
be09dc
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
be09dc
+	.byte	0x1	# DW_children_yes
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x27	# (DW_AT_prototyped)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x12	# (DW_AT_high_pc)
be09dc
+	.uleb128 0x6	# (DW_FORM_data4)
be09dc
+	.uleb128 0x40	# (DW_AT_frame_base)
be09dc
+	.uleb128 0x18	# (DW_FORM_exprloc)
be09dc
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x1	# (DW_AT_sibling)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x7	# (abbrev code)
be09dc
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
be09dc
+	.byte	0x1	# DW_children_yes
be09dc
+	.uleb128 0x3f	# (DW_AT_external)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x27	# (DW_AT_prototyped)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x12	# (DW_AT_high_pc)
be09dc
+	.uleb128 0x6	# (DW_FORM_data4)
be09dc
+	.uleb128 0x40	# (DW_AT_frame_base)
be09dc
+	.uleb128 0x18	# (DW_FORM_exprloc)
be09dc
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x8	# (abbrev code)
be09dc
+	.uleb128 0x34	# (TAG: DW_TAG_variable)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x2	# (DW_AT_location)
be09dc
+	.uleb128 0x17	# (DW_FORM_sec_offset)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x9	# (abbrev code)
be09dc
+	.uleb128 0x4109	# (TAG: DW_TAG_GNU_call_site)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x31	# (DW_AT_abstract_origin)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.section	.debug_loc,"",@progbits
be09dc
+.Ldebug_loc0:
be09dc
+.LLST0:
be09dc
+	.long	.LVL3	# Location list begin address (*.LLST0)
be09dc
+	.long	.LVL4	# Location list end address (*.LLST0)
be09dc
+	.value	0x3	# Location expression size
be09dc
+	.byte	0x70	# DW_OP_breg0
be09dc
+	.sleb128 1
be09dc
+	.byte	0x9f	# DW_OP_stack_value
be09dc
+	.long	.LVL4	# Location list begin address (*.LLST0)
be09dc
+	.long	.LFE4	# Location list end address (*.LLST0)
be09dc
+	.value	0x1	# Location expression size
be09dc
+	.byte	0x50	# DW_OP_reg0
be09dc
+	.long	0	# Location list terminator begin (*.LLST0)
be09dc
+	.long	0	# Location list terminator end (*.LLST0)
be09dc
+	.section	.debug_aranges,"",@progbits
be09dc
+	.long	0x24	# Length of Address Ranges Info
be09dc
+	.value	0x2	# DWARF Version
be09dc
+	.long	.Ldebug_info0	# Offset of Compilation Unit Info
be09dc
+	.byte	0x4	# Size of Address
be09dc
+	.byte	0	# Size of Segment Descriptor
be09dc
+	.value	0	# Pad to 8 byte boundary
be09dc
+	.value	0
be09dc
+	.long	.Ltext0	# Address
be09dc
+	.long	.Letext0-.Ltext0	# Length
be09dc
+	.long	.LFB4	# Address
be09dc
+	.long	.LFE4-.LFB4	# Length
be09dc
+	.long	0
be09dc
+	.long	0
be09dc
+	.section	.debug_ranges,"",@progbits
be09dc
+.Ldebug_ranges0:
be09dc
+	.long	.Ltext0	# Offset 0
be09dc
+	.long	.Letext0
be09dc
+	.long	.LFB4	# Offset 0x8
be09dc
+	.long	.LFE4
be09dc
+	.long	0
be09dc
+	.long	0
be09dc
+	.section	.debug_line,"",@progbits
be09dc
+.Ldebug_line0:
be09dc
+	.section	.debug_str,"MS",@progbits,1
be09dc
+.LASF4:
be09dc
+	.string	"bar_1"
be09dc
+.LASF2:
be09dc
+	.string	"tailcall-only.c"
be09dc
+.LASF1:
be09dc
+	.string	"GNU C 4.8.3 20140911 (Red Hat 4.8.3-9) -m32 -march=i686 -g -O2"
be09dc
+.LASF6:
be09dc
+	.string	"answer"
be09dc
+.LASF5:
be09dc
+	.string	"main"
be09dc
+.LASF3:
be09dc
+	.string	""
be09dc
+.LASF0:
be09dc
+	.string	"foo_1"
be09dc
+	.ident	"GCC: (GNU) 4.8.3 20140911 (Red Hat 4.8.3-9)"
be09dc
+	.section	.note.GNU-stack,"",@progbits
be09dc
--- /dev/null
be09dc
+++ b/gdb/testsuite/gdb.btrace/tailcall-only.c
be09dc
@@ -0,0 +1,53 @@
be09dc
+/* This testcase is part of GDB, the GNU debugger.
be09dc
+
be09dc
+   Copyright 2016 Free Software Foundation, Inc.
be09dc
+
be09dc
+   Contributed by Intel Corp. <markus.t.metzger@intel.com>
be09dc
+
be09dc
+   This program is free software; you can redistribute it and/or modify
be09dc
+   it under the terms of the GNU General Public License as published by
be09dc
+   the Free Software Foundation; either version 3 of the License, or
be09dc
+   (at your option) any later version.
be09dc
+
be09dc
+   This program is distributed in the hope that it will be useful,
be09dc
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
be09dc
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
be09dc
+   GNU General Public License for more details.
be09dc
+
be09dc
+   You should have received a copy of the GNU General Public License
be09dc
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
be09dc
+
be09dc
+static __attribute__ ((noinline)) int
be09dc
+bar_1 (void)
be09dc
+{
be09dc
+  return 42;
be09dc
+}
be09dc
+
be09dc
+static __attribute__ ((noinline)) int
be09dc
+bar (void)
be09dc
+{
be09dc
+  return bar_1 ();
be09dc
+}
be09dc
+
be09dc
+static __attribute__ ((noinline)) int
be09dc
+foo_1 (void)
be09dc
+{
be09dc
+  return bar ();
be09dc
+}
be09dc
+
be09dc
+static __attribute__ ((noinline)) int
be09dc
+foo (void)
be09dc
+{
be09dc
+  return foo_1 ();
be09dc
+}
be09dc
+
be09dc
+int
be09dc
+main (void)
be09dc
+{
be09dc
+  int answer;
be09dc
+
be09dc
+  answer = foo ();
be09dc
+  answer += 1;
be09dc
+
be09dc
+  return answer;
be09dc
+}
be09dc
--- /dev/null
be09dc
+++ b/gdb/testsuite/gdb.btrace/tailcall-only.exp
be09dc
@@ -0,0 +1,97 @@
be09dc
+# This testcase is part of GDB, the GNU debugger.
be09dc
+#
be09dc
+# Copyright 2016 Free Software Foundation, Inc.
be09dc
+#
be09dc
+# This program is free software; you can redistribute it and/or modify
be09dc
+# it under the terms of the GNU General Public License as published by
be09dc
+# the Free Software Foundation; either version 3 of the License, or
be09dc
+# (at your option) any later version.
be09dc
+#
be09dc
+# This program is distributed in the hope that it will be useful,
be09dc
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
be09dc
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
be09dc
+# GNU General Public License for more details.
be09dc
+#
be09dc
+# You should have received a copy of the GNU General Public License
be09dc
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
be09dc
+#
be09dc
+#
be09dc
+# This is a variant of tailcall.exp where the entire trace contains only tail
be09dc
+# calls.  This used to cause a crash in get_frame_type.
be09dc
+#
be09dc
+
be09dc
+# check for btrace support
be09dc
+if { [skip_btrace_tests] } { return -1 }
be09dc
+
be09dc
+# This test requires the compiler to generate a tail call.  To guarantee that
be09dc
+# we always get one, we use an assembly source file.
be09dc
+#
be09dc
+# We use different assembly sources based on the target architecture.
be09dc
+#
be09dc
+# Luckily, they are similar enough that a single test script can handle
be09dc
+# both.
be09dc
+set opts {}
be09dc
+if [info exists COMPILE] {
be09dc
+    # make check RUNTESTFLAGS="gdb.btrace/tailcall-only.exp COMPILE=1"
be09dc
+    standard_testfile tailcall-only.c
be09dc
+    lappend opts debug optimize=-O2
be09dc
+} elseif {[istarget "x86_64-*-*"]} {
be09dc
+	standard_testfile x86_64-tailcall-only.S
be09dc
+} elseif {[istarget "i?86-*-*"]} {
be09dc
+	standard_testfile i686-tailcall-only.S
be09dc
+} else {
be09dc
+    verbose "Skipping ${testfile}."
be09dc
+    return
be09dc
+}
be09dc
+
be09dc
+if [prepare_for_testing tailcall-only.exp $testfile $srcfile $opts] {
be09dc
+    return -1
be09dc
+}
be09dc
+if ![runto_main] {
be09dc
+    return -1
be09dc
+}
be09dc
+
be09dc
+# we want to see the full trace for this test
be09dc
+gdb_test_no_output "set record function-call-history-size 0"
be09dc
+
be09dc
+# trace foo
be09dc
+gdb_test "step" ".*" "prepare for recording"
be09dc
+gdb_test_no_output "record btrace"
be09dc
+gdb_test "stepi 4" ".*" "record branch trace"
be09dc
+
be09dc
+# for debugging
be09dc
+gdb_test "info record" ".*"
be09dc
+
be09dc
+# show the branch trace with calls indented
be09dc
+gdb_test "record function-call-history /c 1" [multi_line \
be09dc
+  "1\tfoo" \
be09dc
+  "2\t  foo_1" \
be09dc
+  "3\t    bar" \
be09dc
+  "4\t      bar_1"
be09dc
+  ] "function-call-history"
be09dc
+
be09dc
+# We can step
be09dc
+gdb_test "record goto begin" ".*foo.*"
be09dc
+gdb_test "stepi" ".*foo_1.*" "step into foo_1"
be09dc
+gdb_test "step" ".*bar.*" "step into bar"
be09dc
+gdb_test "stepi" ".*bar_1.*" "step into bar_1"
be09dc
+
be09dc
+# We can neither finish nor return.
be09dc
+gdb_test "finish" "Cannot find the caller frame.*"
be09dc
+gdb_test_multiple "return" "return" {
be09dc
+  -re "Make .* return now.*y or n. $" {
be09dc
+    send_gdb "y\n"
be09dc
+    exp_continue
be09dc
+  }
be09dc
+  -re "Cannot find the caller frame.*$gdb_prompt $" {
be09dc
+    pass "return"
be09dc
+  }
be09dc
+}
be09dc
+
be09dc
+# But we can reverse-finish
be09dc
+gdb_test "reverse-finish" ".*bar.*"
be09dc
+gdb_test "reverse-step" ".*foo_1.*"
be09dc
+
be09dc
+# Info frame isn't useful but doesn't crash as it used to.
be09dc
+gdb_test "up" ".*foo.*"
be09dc
+gdb_test "info frame" ".*"
be09dc
--- /dev/null
be09dc
+++ b/gdb/testsuite/gdb.btrace/x86_64-tailcall-only.S
be09dc
@@ -0,0 +1,446 @@
be09dc
+/* This testcase is part of GDB, the GNU debugger.
be09dc
+
be09dc
+   Copyright 2016 Free Software Foundation, Inc.
be09dc
+
be09dc
+   This program is free software; you can redistribute it and/or modify
be09dc
+   it under the terms of the GNU General Public License as published by
be09dc
+   the Free Software Foundation; either version 3 of the License, or
be09dc
+   (at your option) any later version.
be09dc
+
be09dc
+   This program is distributed in the hope that it will be useful,
be09dc
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
be09dc
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
be09dc
+   GNU General Public License for more details.
be09dc
+
be09dc
+   You should have received a copy of the GNU General Public License
be09dc
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
be09dc
+
be09dc
+
be09dc
+   This file has been generated using:
be09dc
+   gcc -S -O2 -dA -g tailcall-only.c -o x86_64-tailcall-only.S  */
be09dc
+
be09dc
+	.file	"tailcall-only.c"
be09dc
+	.text
be09dc
+.Ltext0:
be09dc
+	.p2align 4,,15
be09dc
+	.type	bar_1, @function
be09dc
+bar_1:
be09dc
+.LFB0:
be09dc
+	.file 1 "tailcall-only.c"
be09dc
+	# tailcall-only.c:22
be09dc
+	.loc 1 22 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:24
be09dc
+	.loc 1 24 0
be09dc
+	movl	$42, %eax
be09dc
+# SUCC: EXIT [100.0%]
be09dc
+	ret
be09dc
+	.cfi_endproc
be09dc
+.LFE0:
be09dc
+	.size	bar_1, .-bar_1
be09dc
+	.p2align 4,,15
be09dc
+	.type	bar, @function
be09dc
+bar:
be09dc
+.LFB1:
be09dc
+	# tailcall-only.c:28
be09dc
+	.loc 1 28 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:29
be09dc
+	.loc 1 29 0
be09dc
+	jmp	bar_1
be09dc
+# SUCC: EXIT [100.0%]  (ABNORMAL,SIBCALL)
be09dc
+.LVL0:
be09dc
+	.cfi_endproc
be09dc
+.LFE1:
be09dc
+	.size	bar, .-bar
be09dc
+	.p2align 4,,15
be09dc
+	.type	foo_1, @function
be09dc
+foo_1:
be09dc
+.LFB2:
be09dc
+	# tailcall-only.c:34
be09dc
+	.loc 1 34 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:35
be09dc
+	.loc 1 35 0
be09dc
+	jmp	bar
be09dc
+# SUCC: EXIT [100.0%]  (ABNORMAL,SIBCALL)
be09dc
+.LVL1:
be09dc
+	.cfi_endproc
be09dc
+.LFE2:
be09dc
+	.size	foo_1, .-foo_1
be09dc
+	.p2align 4,,15
be09dc
+	.type	foo, @function
be09dc
+foo:
be09dc
+.LFB3:
be09dc
+	# tailcall-only.c:40
be09dc
+	.loc 1 40 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:41
be09dc
+	.loc 1 41 0
be09dc
+	jmp	foo_1
be09dc
+# SUCC: EXIT [100.0%]  (ABNORMAL,SIBCALL)
be09dc
+.LVL2:
be09dc
+	.cfi_endproc
be09dc
+.LFE3:
be09dc
+	.size	foo, .-foo
be09dc
+	.section	.text.startup,"ax",@progbits
be09dc
+	.p2align 4,,15
be09dc
+	.globl	main
be09dc
+	.type	main, @function
be09dc
+main:
be09dc
+.LFB4:
be09dc
+	# tailcall-only.c:46
be09dc
+	.loc 1 46 0
be09dc
+	.cfi_startproc
be09dc
+# BLOCK 2 freq:10000 seq:0
be09dc
+# PRED: ENTRY [100.0%]  (FALLTHRU)
be09dc
+	# tailcall-only.c:49
be09dc
+	.loc 1 49 0
be09dc
+	call	foo
be09dc
+.LVL3:
be09dc
+	# tailcall-only.c:50
be09dc
+	.loc 1 50 0
be09dc
+	addl	$1, %eax
be09dc
+.LVL4:
be09dc
+# SUCC: EXIT [100.0%]
be09dc
+	# tailcall-only.c:53
be09dc
+	.loc 1 53 0
be09dc
+	ret
be09dc
+	.cfi_endproc
be09dc
+.LFE4:
be09dc
+	.size	main, .-main
be09dc
+	.text
be09dc
+.Letext0:
be09dc
+	.section	.debug_info,"",@progbits
be09dc
+.Ldebug_info0:
be09dc
+	.long	0x111	# Length of Compilation Unit Info
be09dc
+	.value	0x4	# DWARF version number
be09dc
+	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
be09dc
+	.byte	0x8	# Pointer Size (in bytes)
be09dc
+	.uleb128 0x1	# (DIE (0xb) DW_TAG_compile_unit)
be09dc
+	.long	.LASF1	# DW_AT_producer: "GNU C 4.8.3 20140911 (Red Hat 4.8.3-9) -mtune=generic -march=x86-64 -g -O2"
be09dc
+	.byte	0x1	# DW_AT_language
be09dc
+	.long	.LASF2	# DW_AT_name: "tailcall-only.c"
be09dc
+	.long	.LASF3	# DW_AT_comp_dir: ""
be09dc
+	.long	.Ldebug_ranges0+0	# DW_AT_ranges
be09dc
+	.quad	0	# DW_AT_low_pc
be09dc
+	.long	.Ldebug_line0	# DW_AT_stmt_list
be09dc
+	.uleb128 0x2	# (DIE (0x29) DW_TAG_subprogram)
be09dc
+	.long	.LASF4	# DW_AT_name: "bar_1"
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x15	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x46	# DW_AT_type
be09dc
+	.quad	.LFB0	# DW_AT_low_pc
be09dc
+	.quad	.LFE0-.LFB0	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.uleb128 0x3	# (DIE (0x46) DW_TAG_base_type)
be09dc
+	.byte	0x4	# DW_AT_byte_size
be09dc
+	.byte	0x5	# DW_AT_encoding
be09dc
+	.ascii "int\0"	# DW_AT_name
be09dc
+	.uleb128 0x4	# (DIE (0x4d) DW_TAG_subprogram)
be09dc
+	.ascii "bar\0"	# DW_AT_name
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x1b	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x46	# DW_AT_type
be09dc
+	.quad	.LFB1	# DW_AT_low_pc
be09dc
+	.quad	.LFE1-.LFB1	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.long	0x7c	# DW_AT_sibling
be09dc
+	.uleb128 0x5	# (DIE (0x6e) DW_TAG_GNU_call_site)
be09dc
+	.quad	.LVL0	# DW_AT_low_pc
be09dc
+			# DW_AT_GNU_tail_call
be09dc
+	.long	0x29	# DW_AT_abstract_origin
be09dc
+	.byte	0	# end of children of DIE 0x4d
be09dc
+	.uleb128 0x6	# (DIE (0x7c) DW_TAG_subprogram)
be09dc
+	.long	.LASF0	# DW_AT_name: "foo_1"
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x21	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x46	# DW_AT_type
be09dc
+	.quad	.LFB2	# DW_AT_low_pc
be09dc
+	.quad	.LFE2-.LFB2	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.long	0xab	# DW_AT_sibling
be09dc
+	.uleb128 0x5	# (DIE (0x9d) DW_TAG_GNU_call_site)
be09dc
+	.quad	.LVL1	# DW_AT_low_pc
be09dc
+			# DW_AT_GNU_tail_call
be09dc
+	.long	0x4d	# DW_AT_abstract_origin
be09dc
+	.byte	0	# end of children of DIE 0x7c
be09dc
+	.uleb128 0x4	# (DIE (0xab) DW_TAG_subprogram)
be09dc
+	.ascii "foo\0"	# DW_AT_name
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x27	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x46	# DW_AT_type
be09dc
+	.quad	.LFB3	# DW_AT_low_pc
be09dc
+	.quad	.LFE3-.LFB3	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.long	0xda	# DW_AT_sibling
be09dc
+	.uleb128 0x5	# (DIE (0xcc) DW_TAG_GNU_call_site)
be09dc
+	.quad	.LVL2	# DW_AT_low_pc
be09dc
+			# DW_AT_GNU_tail_call
be09dc
+	.long	0x7c	# DW_AT_abstract_origin
be09dc
+	.byte	0	# end of children of DIE 0xab
be09dc
+	.uleb128 0x7	# (DIE (0xda) DW_TAG_subprogram)
be09dc
+			# DW_AT_external
be09dc
+	.long	.LASF5	# DW_AT_name: "main"
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x2d	# DW_AT_decl_line
be09dc
+			# DW_AT_prototyped
be09dc
+	.long	0x46	# DW_AT_type
be09dc
+	.quad	.LFB4	# DW_AT_low_pc
be09dc
+	.quad	.LFE4-.LFB4	# DW_AT_high_pc
be09dc
+	.uleb128 0x1	# DW_AT_frame_base
be09dc
+	.byte	0x9c	# DW_OP_call_frame_cfa
be09dc
+			# DW_AT_GNU_all_call_sites
be09dc
+	.uleb128 0x8	# (DIE (0xf7) DW_TAG_variable)
be09dc
+	.long	.LASF6	# DW_AT_name: "answer"
be09dc
+	.byte	0x1	# DW_AT_decl_file (tailcall-only.c)
be09dc
+	.byte	0x2f	# DW_AT_decl_line
be09dc
+	.long	0x46	# DW_AT_type
be09dc
+	.long	.LLST0	# DW_AT_location
be09dc
+	.uleb128 0x9	# (DIE (0x106) DW_TAG_GNU_call_site)
be09dc
+	.quad	.LVL3	# DW_AT_low_pc
be09dc
+	.long	0xab	# DW_AT_abstract_origin
be09dc
+	.byte	0	# end of children of DIE 0xda
be09dc
+	.byte	0	# end of children of DIE 0xb
be09dc
+	.section	.debug_abbrev,"",@progbits
be09dc
+.Ldebug_abbrev0:
be09dc
+	.uleb128 0x1	# (abbrev code)
be09dc
+	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
be09dc
+	.byte	0x1	# DW_children_yes
be09dc
+	.uleb128 0x25	# (DW_AT_producer)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x13	# (DW_AT_language)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x1b	# (DW_AT_comp_dir)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x55	# (DW_AT_ranges)
be09dc
+	.uleb128 0x17	# (DW_FORM_sec_offset)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x10	# (DW_AT_stmt_list)
be09dc
+	.uleb128 0x17	# (DW_FORM_sec_offset)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x2	# (abbrev code)
be09dc
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x27	# (DW_AT_prototyped)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x12	# (DW_AT_high_pc)
be09dc
+	.uleb128 0x7	# (DW_FORM_data8)
be09dc
+	.uleb128 0x40	# (DW_AT_frame_base)
be09dc
+	.uleb128 0x18	# (DW_FORM_exprloc)
be09dc
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x3	# (abbrev code)
be09dc
+	.uleb128 0x24	# (TAG: DW_TAG_base_type)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0xb	# (DW_AT_byte_size)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3e	# (DW_AT_encoding)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0x8	# (DW_FORM_string)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x4	# (abbrev code)
be09dc
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
be09dc
+	.byte	0x1	# DW_children_yes
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0x8	# (DW_FORM_string)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x27	# (DW_AT_prototyped)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x12	# (DW_AT_high_pc)
be09dc
+	.uleb128 0x7	# (DW_FORM_data8)
be09dc
+	.uleb128 0x40	# (DW_AT_frame_base)
be09dc
+	.uleb128 0x18	# (DW_FORM_exprloc)
be09dc
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x1	# (DW_AT_sibling)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x5	# (abbrev code)
be09dc
+	.uleb128 0x4109	# (TAG: DW_TAG_GNU_call_site)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x2115	# (DW_AT_GNU_tail_call)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x31	# (DW_AT_abstract_origin)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x6	# (abbrev code)
be09dc
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
be09dc
+	.byte	0x1	# DW_children_yes
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x27	# (DW_AT_prototyped)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x12	# (DW_AT_high_pc)
be09dc
+	.uleb128 0x7	# (DW_FORM_data8)
be09dc
+	.uleb128 0x40	# (DW_AT_frame_base)
be09dc
+	.uleb128 0x18	# (DW_FORM_exprloc)
be09dc
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x1	# (DW_AT_sibling)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x7	# (abbrev code)
be09dc
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
be09dc
+	.byte	0x1	# DW_children_yes
be09dc
+	.uleb128 0x3f	# (DW_AT_external)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x27	# (DW_AT_prototyped)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x12	# (DW_AT_high_pc)
be09dc
+	.uleb128 0x7	# (DW_FORM_data8)
be09dc
+	.uleb128 0x40	# (DW_AT_frame_base)
be09dc
+	.uleb128 0x18	# (DW_FORM_exprloc)
be09dc
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
be09dc
+	.uleb128 0x19	# (DW_FORM_flag_present)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x8	# (abbrev code)
be09dc
+	.uleb128 0x34	# (TAG: DW_TAG_variable)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0x3	# (DW_AT_name)
be09dc
+	.uleb128 0xe	# (DW_FORM_strp)
be09dc
+	.uleb128 0x3a	# (DW_AT_decl_file)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x3b	# (DW_AT_decl_line)
be09dc
+	.uleb128 0xb	# (DW_FORM_data1)
be09dc
+	.uleb128 0x49	# (DW_AT_type)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.uleb128 0x2	# (DW_AT_location)
be09dc
+	.uleb128 0x17	# (DW_FORM_sec_offset)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.uleb128 0x9	# (abbrev code)
be09dc
+	.uleb128 0x4109	# (TAG: DW_TAG_GNU_call_site)
be09dc
+	.byte	0	# DW_children_no
be09dc
+	.uleb128 0x11	# (DW_AT_low_pc)
be09dc
+	.uleb128 0x1	# (DW_FORM_addr)
be09dc
+	.uleb128 0x31	# (DW_AT_abstract_origin)
be09dc
+	.uleb128 0x13	# (DW_FORM_ref4)
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.byte	0
be09dc
+	.section	.debug_loc,"",@progbits
be09dc
+.Ldebug_loc0:
be09dc
+.LLST0:
be09dc
+	.quad	.LVL3	# Location list begin address (*.LLST0)
be09dc
+	.quad	.LVL4	# Location list end address (*.LLST0)
be09dc
+	.value	0x3	# Location expression size
be09dc
+	.byte	0x70	# DW_OP_breg0
be09dc
+	.sleb128 1
be09dc
+	.byte	0x9f	# DW_OP_stack_value
be09dc
+	.quad	.LVL4	# Location list begin address (*.LLST0)
be09dc
+	.quad	.LFE4	# Location list end address (*.LLST0)
be09dc
+	.value	0x1	# Location expression size
be09dc
+	.byte	0x50	# DW_OP_reg0
be09dc
+	.quad	0	# Location list terminator begin (*.LLST0)
be09dc
+	.quad	0	# Location list terminator end (*.LLST0)
be09dc
+	.section	.debug_aranges,"",@progbits
be09dc
+	.long	0x3c	# Length of Address Ranges Info
be09dc
+	.value	0x2	# DWARF Version
be09dc
+	.long	.Ldebug_info0	# Offset of Compilation Unit Info
be09dc
+	.byte	0x8	# Size of Address
be09dc
+	.byte	0	# Size of Segment Descriptor
be09dc
+	.value	0	# Pad to 16 byte boundary
be09dc
+	.value	0
be09dc
+	.quad	.Ltext0	# Address
be09dc
+	.quad	.Letext0-.Ltext0	# Length
be09dc
+	.quad	.LFB4	# Address
be09dc
+	.quad	.LFE4-.LFB4	# Length
be09dc
+	.quad	0
be09dc
+	.quad	0
be09dc
+	.section	.debug_ranges,"",@progbits
be09dc
+.Ldebug_ranges0:
be09dc
+	.quad	.Ltext0	# Offset 0
be09dc
+	.quad	.Letext0
be09dc
+	.quad	.LFB4	# Offset 0x10
be09dc
+	.quad	.LFE4
be09dc
+	.quad	0
be09dc
+	.quad	0
be09dc
+	.section	.debug_line,"",@progbits
be09dc
+.Ldebug_line0:
be09dc
+	.section	.debug_str,"MS",@progbits,1
be09dc
+.LASF4:
be09dc
+	.string	"bar_1"
be09dc
+.LASF2:
be09dc
+	.string	"tailcall-only.c"
be09dc
+.LASF1:
be09dc
+	.string	"GNU C 4.8.3 20140911 (Red Hat 4.8.3-9) -mtune=generic -march=x86-64 -g -O2"
be09dc
+.LASF6:
be09dc
+	.string	"answer"
be09dc
+.LASF5:
be09dc
+	.string	"main"
be09dc
+.LASF3:
be09dc
+	.string	""
be09dc
+.LASF0:
be09dc
+	.string	"foo_1"
be09dc
+	.ident	"GCC: (GNU) 4.8.3 20140911 (Red Hat 4.8.3-9)"
be09dc
+	.section	.note.GNU-stack,"",@progbits
be09dc
be09dc
be09dc
be09dc
commit cd64cabb8c66a5565fc33bf66a07c08bc767e413
be09dc
Author: Yichao Yu <yyc1992@gmail.com>
be09dc
Date:   Thu Mar 31 19:28:47 2016 +0100
be09dc
be09dc
    Fix PR gdb/19858: GDB doesn't register the JIT libraries on attach
be09dc
    
be09dc
    Ref: https://sourceware.org/ml/gdb/2016-03/msg00023.html
be09dc
    
be09dc
    GDB currently fails to fetch the list of already-registered JIT
be09dc
    modules on attach.
be09dc
    
be09dc
    Nothing is calling jit_inferior_init, which is what is responsible for
be09dc
    walking the JIT object list at init time.
be09dc
    
be09dc
    Despite the misleading naming, jit_inferior_created_hook ->
be09dc
    jit_inferior_init is only called when the inferior execs.
be09dc
    
be09dc
    This regressed with the fix for PR gdb/13431 (03bef283c2d3):
be09dc
     https://sourceware.org/ml/gdb-patches/2012-02/msg00023.html which
be09dc
    removed the inferior_created (jit_inferior_created_observer)
be09dc
    observer.
be09dc
    
be09dc
    Adding an inferior_created observer back fixes the issue.
be09dc
    
be09dc
    In turn, this exposes a bug in jit_breakpoint_re_set_internal as well,
be09dc
    which is returning the wrong result when we already have the
be09dc
    breakpoint at the right address.
be09dc
    
be09dc
    gdb/ChangeLog:
be09dc
    2016-03-31  Yichao Yu  <yyc1992@gmail.com>
be09dc
    
be09dc
    	PR gdb/19858
be09dc
    	* jit.c (jit_breakpoint_re_set_internal): Return 0 if we already
be09dc
    	got the breakpoint at the right address.
be09dc
    	(jit_inferior_created): New function.
be09dc
    	(_initialize_jit): Install jit_inferior_created as
be09dc
    	inferior_created observer.
be09dc
    
be09dc
    Signed-off-by: Pedro Alves <palves@redhat.com>
be09dc
be09dc
### a/gdb/ChangeLog
be09dc
### b/gdb/ChangeLog
be09dc
## -1,3 +1,12 @@
be09dc
+2016-03-31  Yichao Yu  <yyc1992@gmail.com>
be09dc
+
be09dc
+	PR gdb/19858
be09dc
+	* jit.c (jit_breakpoint_re_set_internal): Return 0 if we already
be09dc
+	got the breakpoint at the right address.
be09dc
+	(jit_inferior_created): New function.
be09dc
+	(_initialize_jit): Install jit_inferior_created as
be09dc
+	inferior_created observer.
be09dc
+
be09dc
 2016-03-17  Markus Metzger  <markus.t.metzger@intel.com>
be09dc
 
be09dc
 	PR gdb/19829
be09dc
--- a/gdb/jit.c
be09dc
+++ b/gdb/jit.c
be09dc
@@ -1026,7 +1026,7 @@ jit_breakpoint_deleted (struct breakpoint *b)
be09dc
 }
be09dc
 
be09dc
 /* (Re-)Initialize the jit breakpoint if necessary.
be09dc
-   Return 0 on success.  */
be09dc
+   Return 0 if the jit breakpoint has been successfully initialized.  */
be09dc
 
be09dc
 static int
be09dc
 jit_breakpoint_re_set_internal (struct gdbarch *gdbarch,
be09dc
@@ -1070,7 +1070,7 @@ jit_breakpoint_re_set_internal (struct gdbarch *gdbarch,
be09dc
 			paddress (gdbarch, addr));
be09dc
 
be09dc
   if (ps_data->cached_code_address == addr)
be09dc
-    return 1;
be09dc
+    return 0;
be09dc
 
be09dc
   /* Delete the old breakpoint.  */
be09dc
   if (ps_data->jit_breakpoint != NULL)
be09dc
@@ -1367,6 +1367,14 @@ jit_inferior_init (struct gdbarch *gdbarch)
be09dc
     }
be09dc
 }
be09dc
 
be09dc
+/* inferior_created observer.  */
be09dc
+
be09dc
+static void
be09dc
+jit_inferior_created (struct target_ops *ops, int from_tty)
be09dc
+{
be09dc
+  jit_inferior_created_hook ();
be09dc
+}
be09dc
+
be09dc
 /* Exported routine to call when an inferior has been created.  */
be09dc
 
be09dc
 void
be09dc
@@ -1496,6 +1504,7 @@ _initialize_jit (void)
be09dc
 			     show_jit_debug,
be09dc
 			     &setdebuglist, &showdebuglist);
be09dc
 
be09dc
+  observer_attach_inferior_created (jit_inferior_created);
be09dc
   observer_attach_inferior_exit (jit_inferior_exit_hook);
be09dc
   observer_attach_breakpoint_deleted (jit_breakpoint_deleted);
be09dc
 
be09dc
be09dc
be09dc
be09dc
commit 89df5d6cce0e91c4b34c7a62ba4a68756a8ed4e7
be09dc
Author: Pedro Alves <palves@redhat.com>
be09dc
Date:   Thu Mar 31 19:28:47 2016 +0100
be09dc
be09dc
    Make gdb.base/jit.exp binaries unique
be09dc
    
be09dc
    This testcase compiles the same program and library differently
be09dc
    multiple times using the same file names.  Make them unique, to make
be09dc
    it easier to debug test problems.
be09dc
    
be09dc
    gdb/testsuite/ChangeLog:
be09dc
    2016-03-31  Pedro Alves  <palves@redhat.com>
be09dc
    
be09dc
    	PR gdb/19858
be09dc
    	* gdb.base/jit.exp (compile_jit_test): Add intro comment.  Add
be09dc
    	BINSUFFIX parameter, and handle it.
be09dc
    	(top level): Adjust calls compile_jit_test.
be09dc
be09dc
### a/gdb/testsuite/ChangeLog
be09dc
### b/gdb/testsuite/ChangeLog
be09dc
## -1,3 +1,10 @@
be09dc
+2016-03-31  Pedro Alves  <palves@redhat.com>
be09dc
+
be09dc
+	PR gdb/19858
be09dc
+	* gdb.base/jit.exp (compile_jit_test): Add intro comment.  Add
be09dc
+	BINSUFFIX parameter, and handle it.
be09dc
+	(top level): Adjust calls compile_jit_test.
be09dc
+
be09dc
 2016-03-17  Markus Metzger  <markus.t.metzger@intel.com>
be09dc
 
be09dc
 	PR gdb/19829
be09dc
--- a/gdb/testsuite/gdb.base/jit.exp
be09dc
+++ b/gdb/testsuite/gdb.base/jit.exp
be09dc
@@ -24,18 +24,19 @@ if {[get_compiler_info]} {
be09dc
     return 1
be09dc
 }
be09dc
 
be09dc
-#
be09dc
-# test running programs
be09dc
-#
be09dc
+# Compile the testcase program and library.  BINSUFFIX is the suffix
be09dc
+# to append to the program and library filenames, to make them unique
be09dc
+# between invocations.  OPTIONS is passed to gdb_compile when
be09dc
+# compiling the program.
be09dc
 
be09dc
-proc compile_jit_test {testname options} {
be09dc
+proc compile_jit_test {testname binsuffix options} {
be09dc
     global testfile srcfile binfile srcdir subdir
be09dc
     global solib_testfile solib_srcfile solib_binfile solib_binfile_test_msg
be09dc
     global solib_binfile_target
be09dc
 
be09dc
     set testfile jit-main
be09dc
     set srcfile ${testfile}.c
be09dc
-    set binfile [standard_output_file $testfile]
be09dc
+    set binfile [standard_output_file $testfile$binsuffix]
be09dc
     if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
be09dc
 	      executable [concat debug $options]] != "" } {
be09dc
 	untested $testname
be09dc
@@ -44,8 +45,8 @@ proc compile_jit_test {testname options} {
be09dc
 
be09dc
     set solib_testfile "jit-solib"
be09dc
     set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
be09dc
-    set solib_binfile [standard_output_file ${solib_testfile}.so]
be09dc
-    set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}.so"
be09dc
+    set solib_binfile [standard_output_file ${solib_testfile}$binsuffix.so]
be09dc
+    set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}$binsuffix.so"
be09dc
 
be09dc
     # Note: compiling without debug info: the library goes through
be09dc
     # symbol renaming by munging on its symbol table, and that
be09dc
@@ -109,7 +110,7 @@ proc one_jit_test {count match_str} {
be09dc
     }
be09dc
 }
be09dc
 
be09dc
-if {[compile_jit_test jit.exp {}] < 0} {
be09dc
+if {[compile_jit_test jit.exp "" {}] < 0} {
be09dc
     return
be09dc
 }
be09dc
 one_jit_test 1 "${hex}  jit_function_0000"
be09dc
@@ -117,7 +118,7 @@ one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001"
be09dc
 
be09dc
 with_test_prefix PIE {
be09dc
     if {[compile_jit_test "jit.exp PIE tests" \
be09dc
-	     {additional_flags=-fPIE ldflags=-pie}] < 0} {
be09dc
+	     "-pie" {additional_flags=-fPIE ldflags=-pie}] < 0} {
be09dc
 	return
be09dc
     }
be09dc
 
be09dc
be09dc
be09dc
be09dc
commit 85af34ee0211eedf8d30a5c44dfc59dddf8b512a
be09dc
Author: Pedro Alves <palves@redhat.com>
be09dc
Date:   Thu Mar 31 19:28:47 2016 +0100
be09dc
be09dc
    Add regression test for PR gdb/19858 (JIT code registration on attach)
be09dc
    
be09dc
    This test would fail without the previous gdb/jit.c fix:
be09dc
    
be09dc
      (gdb) attach 23031
be09dc
      Attaching to program: .../build/gdb/testsuite/outputs/gdb.base/jit/jit-main, process 23031
be09dc
      [...]
be09dc
      207           WAIT_FOR_GDB; i = 0;  /* gdb break here 1 */
be09dc
      (gdb) PASS: gdb.base/jit.exp: attach: one_jit_test-2: attach
be09dc
      set var wait_for_gdb = 0
be09dc
      (gdb) PASS: gdb.base/jit.exp: attach: one_jit_test-2: set var wait_for_gdb = 0
be09dc
      info function ^jit_function
be09dc
      All functions matching regular expression "^jit_function":
be09dc
      (gdb) FAIL: gdb.base/jit.exp: attach: one_jit_test-2: info function ^jit_function
be09dc
    
be09dc
    gdb/testsuite/ChangeLog:
be09dc
    2016-03-31  Pedro Alves  <palves@redhat.com>
be09dc
    
be09dc
    	PR gdb/19858
be09dc
    	* gdb.base/jit-main.c: Include unistd.h.
be09dc
    	(ATTACH): Define to 0 if not already defined.
be09dc
    	(wait_for_gdb, mypid): New globals.
be09dc
    	(WAIT_FOR_GDB): New macro.
be09dc
    	(MAIN): Set an alarm.  Store the process's pid.  Wait for GDB at
be09dc
    	some breakpoint locations.
be09dc
    	* gdb.base/jit.exp (clean_reattach, continue_to_test_location):
be09dc
    	New procedures.
be09dc
    	(one_jit_test): Add REATTACH parameter, and handle it.  Use
be09dc
    	continue_to_test_location.
be09dc
    	(top level): Test attach, and adjusts calls to one_jit_test.
be09dc
be09dc
### a/gdb/testsuite/ChangeLog
be09dc
### b/gdb/testsuite/ChangeLog
be09dc
## -1,6 +1,21 @@
be09dc
 2016-03-31  Pedro Alves  <palves@redhat.com>
be09dc
 
be09dc
 	PR gdb/19858
be09dc
+	* gdb.base/jit-main.c: Include unistd.h.
be09dc
+	(ATTACH): Define to 0 if not already defined.
be09dc
+	(wait_for_gdb, mypid): New globals.
be09dc
+	(WAIT_FOR_GDB): New macro.
be09dc
+	(MAIN): Set an alarm.  Store the process's pid.  Wait for GDB at
be09dc
+	some breakpoint locations.
be09dc
+	* gdb.base/jit.exp (clean_reattach, continue_to_test_location):
be09dc
+	New procedures.
be09dc
+	(one_jit_test): Add REATTACH parameter, and handle it.  Use
be09dc
+	continue_to_test_location.
be09dc
+	(top level): Test attach, and adjusts calls to one_jit_test.
be09dc
+
be09dc
+2016-03-31  Pedro Alves  <palves@redhat.com>
be09dc
+
be09dc
+	PR gdb/19858
be09dc
 	* gdb.base/jit.exp (compile_jit_test): Add intro comment.  Add
be09dc
 	BINSUFFIX parameter, and handle it.
be09dc
 	(top level): Adjust calls compile_jit_test.
be09dc
--- a/gdb/testsuite/gdb.base/jit-main.c
be09dc
+++ b/gdb/testsuite/gdb.base/jit-main.c
be09dc
@@ -27,6 +27,7 @@
be09dc
 #include <string.h>
be09dc
 #include <sys/mman.h>
be09dc
 #include <sys/stat.h>
be09dc
+#include <unistd.h>
be09dc
 
be09dc
 /* ElfW is coming from linux. On other platforms it does not exist.
be09dc
    Let us define it here. */
be09dc
@@ -116,10 +117,22 @@ update_locations (const void *const addr, int idx)
be09dc
     }
be09dc
 }
be09dc
 
be09dc
+/* Defined by the .exp file if testing attach.  */
be09dc
+#ifndef ATTACH
be09dc
+#define ATTACH 0
be09dc
+#endif
be09dc
+
be09dc
 #ifndef MAIN
be09dc
 #define MAIN main
be09dc
 #endif
be09dc
 
be09dc
+/* Used to spin waiting for GDB.  */
be09dc
+volatile int wait_for_gdb = ATTACH;
be09dc
+#define WAIT_FOR_GDB while (wait_for_gdb)
be09dc
+
be09dc
+/* The current process's PID.  GDB retrieves this.  */
be09dc
+int mypid;
be09dc
+
be09dc
 int
be09dc
 MAIN (int argc, char *argv[])
be09dc
 {
be09dc
@@ -127,6 +140,10 @@ MAIN (int argc, char *argv[])
be09dc
   const char *libname = NULL;
be09dc
   int count = 0;
be09dc
 
be09dc
+  alarm (300);
be09dc
+
be09dc
+  mypid = getpid ();
be09dc
+
be09dc
   count = count;  /* gdb break here 0  */
be09dc
 
be09dc
   if (argc < 2)
be09dc
@@ -190,7 +207,7 @@ MAIN (int argc, char *argv[])
be09dc
           __jit_debug_register_code ();
be09dc
         }
be09dc
 
be09dc
-      i = 0;  /* gdb break here 1 */
be09dc
+      WAIT_FOR_GDB; i = 0;  /* gdb break here 1 */
be09dc
 
be09dc
       /* Now unregister them all in reverse order.  */
be09dc
       while (__jit_debug_descriptor.relevant_entry != NULL)
be09dc
@@ -215,5 +232,5 @@ MAIN (int argc, char *argv[])
be09dc
           free (entry);
be09dc
         }
be09dc
     }
be09dc
-  return 0;  /* gdb break here 2  */
be09dc
+  WAIT_FOR_GDB; return 0;  /* gdb break here 2  */
be09dc
 }
be09dc
--- a/gdb/testsuite/gdb.base/jit.exp
be09dc
+++ b/gdb/testsuite/gdb.base/jit.exp
be09dc
@@ -66,7 +66,49 @@ proc compile_jit_test {testname binsuffix options} {
be09dc
     return 0
be09dc
 }
be09dc
 
be09dc
-proc one_jit_test {count match_str} {
be09dc
+# Detach, restart GDB, and re-attach to the program.
be09dc
+
be09dc
+proc clean_reattach {} {
be09dc
+    global decimal gdb_prompt srcfile testfile
be09dc
+
be09dc
+    # Get PID of test program.
be09dc
+    set testpid -1
be09dc
+    set test "get inferior process ID"
be09dc
+    gdb_test_multiple "p mypid" $test {
be09dc
+	-re ".* = ($decimal).*$gdb_prompt $" {
be09dc
+	    set testpid $expect_out(1,string)
be09dc
+	    pass $test
be09dc
+	}
be09dc
+    }
be09dc
+
be09dc
+    gdb_test_no_output "set var wait_for_gdb = 1"
be09dc
+    gdb_test "detach" "Detaching from .*"
be09dc
+
be09dc
+    clean_restart $testfile
be09dc
+
be09dc
+    set test "attach"
be09dc
+    gdb_test_multiple "attach $testpid" "$test" {
be09dc
+	-re "Attaching to program.*.*main.*at .*$srcfile:.*$gdb_prompt $" {
be09dc
+	    pass "$test"
be09dc
+	}
be09dc
+    }
be09dc
+
be09dc
+    gdb_test_no_output "set var wait_for_gdb = 0"
be09dc
+}
be09dc
+
be09dc
+# Continue to LOCATION in the program.  If REATTACH, detach and
be09dc
+# re-attach to the program from scratch.
be09dc
+proc continue_to_test_location {location reattach} {
be09dc
+    gdb_breakpoint [gdb_get_line_number $location]
be09dc
+    gdb_continue_to_breakpoint $location
be09dc
+    if {$reattach} {
be09dc
+	with_test_prefix "$location" {
be09dc
+	    clean_reattach
be09dc
+	}
be09dc
+    }
be09dc
+}
be09dc
+
be09dc
+proc one_jit_test {count match_str reattach} {
be09dc
     with_test_prefix "one_jit_test-$count" {
be09dc
 	global verbose testfile solib_binfile_target solib_binfile_test_msg
be09dc
 
be09dc
@@ -91,8 +133,7 @@ proc one_jit_test {count match_str} {
be09dc
 	gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
be09dc
 	gdb_test_no_output "set var count = $count"
be09dc
 
be09dc
-	gdb_breakpoint [gdb_get_line_number "break here 1"]
be09dc
-	gdb_continue_to_breakpoint "break here 1"
be09dc
+	continue_to_test_location "break here 1" $reattach
be09dc
 
be09dc
 	gdb_test "info function ^jit_function" "$match_str"
be09dc
 
be09dc
@@ -102,8 +143,8 @@ proc one_jit_test {count match_str} {
be09dc
 	    gdb_test "maintenance info break"
be09dc
 	}
be09dc
 
be09dc
-	gdb_breakpoint [gdb_get_line_number "break here 2"]
be09dc
-	gdb_continue_to_breakpoint "break here 2"
be09dc
+	continue_to_test_location "break here 2" $reattach
be09dc
+
be09dc
 	# All jit librares must have been unregistered
be09dc
 	gdb_test "info function jit_function" \
be09dc
 	    "All functions matching regular expression \"jit_function\":"
be09dc
@@ -113,8 +154,22 @@ proc one_jit_test {count match_str} {
be09dc
 if {[compile_jit_test jit.exp "" {}] < 0} {
be09dc
     return
be09dc
 }
be09dc
-one_jit_test 1 "${hex}  jit_function_0000"
be09dc
-one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001"
be09dc
+one_jit_test 1 "${hex}  jit_function_0000" 0
be09dc
+one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 0
be09dc
+
be09dc
+# Test attaching to an inferior with some JIT libraries already
be09dc
+# registered.  We reuse the normal test, and detach/reattach at
be09dc
+# specific interesting points.
be09dc
+if {[can_spawn_for_attach]} {
be09dc
+    if {[compile_jit_test "jit.exp attach tests" \
be09dc
+	     "-attach" {additional_flags=-DATTACH=1}] < 0} {
be09dc
+	return
be09dc
+    }
be09dc
+
be09dc
+    with_test_prefix attach {
be09dc
+	one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001" 1
be09dc
+    }
be09dc
+}
be09dc
 
be09dc
 with_test_prefix PIE {
be09dc
     if {[compile_jit_test "jit.exp PIE tests" \
be09dc
@@ -122,5 +177,5 @@ with_test_prefix PIE {
be09dc
 	return
be09dc
     }
be09dc
 
be09dc
-    one_jit_test 1 "${hex}  jit_function_0000"
be09dc
+    one_jit_test 1 "${hex}  jit_function_0000" 0
be09dc
 }