blarsen / rpms / gdb

Forked from rpms/gdb 2 years ago
Clone
Jan Kratochvil dedd61b
http://sourceware.org/ml/gdb-cvs/2010-08/msg00101.html
Jan Kratochvil dedd61b
Jan Kratochvil dedd61b
### src/gdb/ChangeLog	2010/08/18 12:24:08	1.12093
Jan Kratochvil dedd61b
### src/gdb/ChangeLog	2010/08/18 12:25:48	1.12094
Jan Kratochvil dedd61b
## -2,6 +2,27 @@
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
 	PR corefile/8210
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
+	* linux-thread-db.c (add_thread_db_info): Skip glibc/BZ5983
Jan Kratochvil dedd61b
+	workaround on core files.
Jan Kratochvil dedd61b
+	(try_thread_db_load_1): Don't try enabling thread event reporting
Jan Kratochvil dedd61b
+	on core files.
Jan Kratochvil dedd61b
+	(thread_db_load): Allow thread_db on core files.
Jan Kratochvil dedd61b
+	(attach_thread): Don't check thread signals on core files, nor try
Jan Kratochvil dedd61b
+	really attaching to the thread, nor enabling thread event event
Jan Kratochvil dedd61b
+	reporting.
Jan Kratochvil dedd61b
+	(thread_db_detach): Don't try disabing thread event reporting or
Jan Kratochvil dedd61b
+	removing thread event breakpoints when debugging a core file.
Jan Kratochvil dedd61b
+	(find_new_threads_callback): Don't try enabling thread event
Jan Kratochvil dedd61b
+	reporting on core files.
Jan Kratochvil dedd61b
+	(thread_db_find_new_threads_2): Don't look for a stopped lwp when
Jan Kratochvil dedd61b
+	debugging a core file.
Jan Kratochvil dedd61b
+	(thread_db_find_new_threads): Don't update thread
Jan Kratochvil dedd61b
+	cores (processors) when debugging a core (dump).
Jan Kratochvil dedd61b
+
Jan Kratochvil dedd61b
+2010-08-18  Pedro Alves  <pedro@codesourcery.com>
Jan Kratochvil dedd61b
+
Jan Kratochvil dedd61b
+	PR corefile/8210
Jan Kratochvil dedd61b
+
Jan Kratochvil dedd61b
 	* corelow.c (add_to_thread_list): Don't use
Jan Kratochvil dedd61b
 	gdbarch_core_reg_section_encodes_pid.  Use bfd_core_file_pid.
Jan Kratochvil dedd61b
 	(get_core_register_section): Don't use
Jan Kratochvil dedd61b
--- src/gdb/linux-thread-db.c	2010/07/31 15:34:41	1.76
Jan Kratochvil dedd61b
+++ src/gdb/linux-thread-db.c	2010/08/18 12:25:49	1.77
Jan Kratochvil dedd61b
@@ -189,7 +189,11 @@
Jan Kratochvil dedd61b
   info = xcalloc (1, sizeof (*info));
Jan Kratochvil dedd61b
   info->pid = ptid_get_pid (inferior_ptid);
Jan Kratochvil dedd61b
   info->handle = handle;
Jan Kratochvil dedd61b
-  info->need_stale_parent_threads_check = 1;
Jan Kratochvil dedd61b
+
Jan Kratochvil dedd61b
+  /* The workaround works by reading from /proc/pid/status, so it is
Jan Kratochvil dedd61b
+     disabled for core files.  */
Jan Kratochvil dedd61b
+  if (target_has_execution)
Jan Kratochvil dedd61b
+    info->need_stale_parent_threads_check = 1;
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   info->next = thread_db_list;
Jan Kratochvil dedd61b
   thread_db_list = info;
Jan Kratochvil dedd61b
@@ -737,7 +741,9 @@
Jan Kratochvil dedd61b
   if (thread_db_list->next == NULL)
Jan Kratochvil dedd61b
     push_target (&thread_db_ops);
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-  enable_thread_event_reporting ();
Jan Kratochvil dedd61b
+  /* Enable event reporting, but not when debugging a core file.  */
Jan Kratochvil dedd61b
+  if (target_has_execution)
Jan Kratochvil dedd61b
+    enable_thread_event_reporting ();
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   /* There appears to be a bug in glibc-2.3.6: calls to td_thr_get_info fail
Jan Kratochvil dedd61b
      with TD_ERR for statically linked executables if td_thr_get_info is
Jan Kratochvil dedd61b
@@ -869,13 +875,13 @@
Jan Kratochvil dedd61b
   if (info != NULL)
Jan Kratochvil dedd61b
     return 1;
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-  /* Don't attempt to use thread_db on targets which can not run
Jan Kratochvil dedd61b
-     (executables not running yet, core files) for now.  */
Jan Kratochvil dedd61b
-  if (!target_has_execution)
Jan Kratochvil dedd61b
+  /* Don't attempt to use thread_db on executables not running
Jan Kratochvil dedd61b
+     yet.  */
Jan Kratochvil dedd61b
+  if (!target_has_registers)
Jan Kratochvil dedd61b
     return 0;
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   /* Don't attempt to use thread_db for remote targets.  */
Jan Kratochvil dedd61b
-  if (!target_can_run (&current_target))
Jan Kratochvil dedd61b
+  if (!(target_can_run (&current_target) || core_bfd))
Jan Kratochvil dedd61b
     return 0;
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   if (thread_db_load_search ())
Jan Kratochvil dedd61b
@@ -1030,13 +1036,15 @@
Jan Kratochvil dedd61b
 	}
Jan Kratochvil dedd61b
     }
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-  check_thread_signals ();
Jan Kratochvil dedd61b
+  if (target_has_execution)
Jan Kratochvil dedd61b
+    check_thread_signals ();
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   if (ti_p->ti_state == TD_THR_UNKNOWN || ti_p->ti_state == TD_THR_ZOMBIE)
Jan Kratochvil dedd61b
     return 0;			/* A zombie thread -- do not attach.  */
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   /* Under GNU/Linux, we have to attach to each and every thread.  */
Jan Kratochvil dedd61b
-  if (tp == NULL
Jan Kratochvil dedd61b
+  if (target_has_execution
Jan Kratochvil dedd61b
+      && tp == NULL
Jan Kratochvil dedd61b
       && lin_lwp_attach_lwp (BUILD_LWP (ti_p->ti_lid, GET_PID (ptid))) < 0)
Jan Kratochvil dedd61b
     return 0;
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
@@ -1061,11 +1069,16 @@
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   info = get_thread_db_info (GET_PID (ptid));
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-  /* Enable thread event reporting for this thread.  */
Jan Kratochvil dedd61b
-  err = info->td_thr_event_enable_p (th_p, 1);
Jan Kratochvil dedd61b
-  if (err != TD_OK)
Jan Kratochvil dedd61b
-    error (_("Cannot enable thread event reporting for %s: %s"),
Jan Kratochvil dedd61b
-	   target_pid_to_str (ptid), thread_db_err_str (err));
Jan Kratochvil dedd61b
+  /* Enable thread event reporting for this thread, except when
Jan Kratochvil dedd61b
+     debugging a core file.  */
Jan Kratochvil dedd61b
+  if (target_has_execution)
Jan Kratochvil dedd61b
+    {
Jan Kratochvil dedd61b
+      err = info->td_thr_event_enable_p (th_p, 1);
Jan Kratochvil dedd61b
+      if (err != TD_OK)
Jan Kratochvil dedd61b
+	error (_("Cannot enable thread event reporting for %s: %s"),
Jan Kratochvil dedd61b
+	       target_pid_to_str (ptid), thread_db_err_str (err));
Jan Kratochvil dedd61b
+    }
Jan Kratochvil dedd61b
+
Jan Kratochvil dedd61b
   return 1;
Jan Kratochvil dedd61b
 }
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
@@ -1097,14 +1110,17 @@
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   if (info)
Jan Kratochvil dedd61b
     {
Jan Kratochvil dedd61b
-      disable_thread_event_reporting (info);
Jan Kratochvil dedd61b
+      if (target_has_execution)
Jan Kratochvil dedd61b
+	{
Jan Kratochvil dedd61b
+	  disable_thread_event_reporting (info);
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-      /* Delete the old thread event breakpoints.  Note that unlike
Jan Kratochvil dedd61b
-	 when mourning, we can remove them here because there's still
Jan Kratochvil dedd61b
-	 a live inferior to poke at.  In any case, GDB will not try to
Jan Kratochvil dedd61b
-	 insert anything in the inferior when removing a
Jan Kratochvil dedd61b
-	 breakpoint.  */
Jan Kratochvil dedd61b
-      remove_thread_event_breakpoints ();
Jan Kratochvil dedd61b
+	  /* Delete the old thread event breakpoints.  Note that
Jan Kratochvil dedd61b
+	     unlike when mourning, we can remove them here because
Jan Kratochvil dedd61b
+	     there's still a live inferior to poke at.  In any case,
Jan Kratochvil dedd61b
+	     GDB will not try to insert anything in the inferior when
Jan Kratochvil dedd61b
+	     removing a breakpoint.  */
Jan Kratochvil dedd61b
+	  remove_thread_event_breakpoints ();
Jan Kratochvil dedd61b
+	}
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
       delete_thread_db_info (GET_PID (inferior_ptid));
Jan Kratochvil dedd61b
     }
Jan Kratochvil dedd61b
@@ -1317,7 +1333,7 @@
Jan Kratochvil dedd61b
   if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE)
Jan Kratochvil dedd61b
     return 0;			/* A zombie -- ignore.  */
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-  if (ti.ti_tid == 0)
Jan Kratochvil dedd61b
+  if (ti.ti_tid == 0 && target_has_execution)
Jan Kratochvil dedd61b
     {
Jan Kratochvil dedd61b
       /* A thread ID of zero means that this is the main thread, but
Jan Kratochvil dedd61b
 	 glibc has not yet initialized thread-local storage and the
Jan Kratochvil dedd61b
@@ -1417,19 +1433,23 @@
Jan Kratochvil dedd61b
 thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new)
Jan Kratochvil dedd61b
 {
Jan Kratochvil dedd61b
   td_err_e err;
Jan Kratochvil dedd61b
-  struct lwp_info *lp;
Jan Kratochvil dedd61b
   struct thread_db_info *info;
Jan Kratochvil dedd61b
   int pid = ptid_get_pid (ptid);
Jan Kratochvil dedd61b
   int i, loop;
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-  /* In linux, we can only read memory through a stopped lwp.  */
Jan Kratochvil dedd61b
-  ALL_LWPS (lp, ptid)
Jan Kratochvil dedd61b
-    if (lp->stopped && ptid_get_pid (lp->ptid) == pid)
Jan Kratochvil dedd61b
-      break;
Jan Kratochvil dedd61b
+  if (target_has_execution)
Jan Kratochvil dedd61b
+    {
Jan Kratochvil dedd61b
+      struct lwp_info *lp;
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-  if (!lp)
Jan Kratochvil dedd61b
-    /* There is no stopped thread.  Bail out.  */
Jan Kratochvil dedd61b
-    return;
Jan Kratochvil dedd61b
+      /* In linux, we can only read memory through a stopped lwp.  */
Jan Kratochvil dedd61b
+      ALL_LWPS (lp, ptid)
Jan Kratochvil dedd61b
+	if (lp->stopped && ptid_get_pid (lp->ptid) == pid)
Jan Kratochvil dedd61b
+	  break;
Jan Kratochvil dedd61b
+
Jan Kratochvil dedd61b
+      if (!lp)
Jan Kratochvil dedd61b
+	/* There is no stopped thread.  Bail out.  */
Jan Kratochvil dedd61b
+	return;
Jan Kratochvil dedd61b
+    }
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   info = get_thread_db_info (GET_PID (ptid));
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
@@ -1480,8 +1500,9 @@
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
   thread_db_find_new_threads_1 (inferior_ptid);
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
-  iterate_over_lwps (minus_one_ptid /* iterate over all */,
Jan Kratochvil dedd61b
-		     update_thread_core, NULL);
Jan Kratochvil dedd61b
+  if (target_has_execution)
Jan Kratochvil dedd61b
+    iterate_over_lwps (minus_one_ptid /* iterate over all */,
Jan Kratochvil dedd61b
+		       update_thread_core, NULL);
Jan Kratochvil dedd61b
 }
Jan Kratochvil dedd61b
 
Jan Kratochvil dedd61b
 static char *