Blame SOURCES/gdb-gnat-dwarf-crash-3of3.patch

6240d7
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
6240d7
From: Fedora GDB patches <invalid@email.com>
6240d7
Date: Fri, 27 Oct 2017 21:07:50 +0200
6240d7
Subject: gdb-gnat-dwarf-crash-3of3.patch
6240d7
6240d7
;; Fix crash of -readnow /usr/lib/debug/usr/bin/gnatbind.debug (BZ 1069211).
6240d7
;;=push+jan
6240d7
6240d7
http://sourceware.org/ml/gdb-patches/2014-02/msg00731.html
6240d7
6240d7
--6TrnltStXW4iwmi0
6240d7
Content-Type: text/plain; charset=us-ascii
6240d7
Content-Disposition: inline
6240d7
6240d7
Hi,
6240d7
6240d7
PR 16581:
6240d7
	GDB crash on inherit_abstract_dies infinite recursion
6240d7
	https://sourceware.org/bugzilla/show_bug.cgi?id=16581
6240d7
6240d7
fixed crash from an infinite recursion.  But in rare cases the new code can
6240d7
now gdb_assert() due to weird DWARF file.
6240d7
6240d7
I do not yet fully understand why the DWARF is as it is but just GDB should
6240d7
never crash due to invalid DWARF anyway.  The "invalid" DWARF I see only in
6240d7
Fedora GCC build, not in FSF GCC build, more info at:
6240d7
	https://bugzilla.redhat.com/show_bug.cgi?id=1069382
6240d7
	http://people.redhat.com/jkratoch/gcc-debuginfo-4.8.2-7.fc20.x86_64-gnatbind.debug
6240d7
6240d7
Thanks,
6240d7
Jan
6240d7
6240d7
--6TrnltStXW4iwmi0
6240d7
Content-Type: text/plain; charset=us-ascii
6240d7
Content-Disposition: inline; filename="complaint.patch"
6240d7
6240d7
gdb/
6240d7
2014-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
6240d7
6240d7
	* dwarf2read.c (process_die): Change gdb_assert to complaint.
6240d7
6240d7
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
6240d7
--- a/gdb/dwarf2read.c
6240d7
+++ b/gdb/dwarf2read.c
6240d7
@@ -10588,6 +10588,13 @@ private:
6240d7
 static void
6240d7
 process_die (struct die_info *die, struct dwarf2_cu *cu)
6240d7
 {
6240d7
+  if (die->in_process)
6240d7
+    {
6240d7
+      complaint (_("DIE at 0x%s attempted to be processed twice"),
6240d7
+		 sect_offset_str (die->sect_off));
6240d7
+      return;
6240d7
+    }
6240d7
+
6240d7
   process_die_scope scope (die, cu);
6240d7
 
6240d7
   switch (die->tag)
6240d7
diff --git a/gdb/infrun.c b/gdb/infrun.c
6240d7
--- a/gdb/infrun.c
6240d7
+++ b/gdb/infrun.c
6240d7
@@ -609,6 +609,13 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
6240d7
 				target_pid_to_str (process_ptid));
6240d7
 	    }
6240d7
 
6240d7
+#ifdef NEED_DETACH_SIGSTOP
6240d7
+	  /* We should check PID_WAS_STOPPED and detach it stopped accordingly.
6240d7
+	     In this point of code it cannot be 1 as we would not get FORK
6240d7
+	     executed without CONTINUE first which resets PID_WAS_STOPPED.
6240d7
+	     We would have to first TARGET_STOP and WAITPID it as with running
6240d7
+	     inferior PTRACE_DETACH, SIGSTOP will ignore the signal.  */
6240d7
+#endif
6240d7
 	  target_detach (parent_inf, 0);
6240d7
 	}
6240d7
 
6240d7
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
6240d7
--- a/gdb/linux-nat.c
6240d7
+++ b/gdb/linux-nat.c
6240d7
@@ -192,6 +192,12 @@ struct linux_nat_target *linux_target;
6240d7
 /* Does the current host support PTRACE_GETREGSET?  */
6240d7
 enum tribool have_ptrace_getregset = TRIBOOL_UNKNOWN;
6240d7
 
6240d7
+#ifdef NEED_DETACH_SIGSTOP
6240d7
+/* PID of the inferior stopped by SIGSTOP before attaching (or zero).  */
6240d7
+static pid_t pid_was_stopped;
6240d7
+
6240d7
+#endif
6240d7
+
6240d7
 static unsigned int debug_linux_nat;
6240d7
 static void
6240d7
 show_debug_linux_nat (struct ui_file *file, int from_tty,
6240d7
@@ -1037,6 +1043,9 @@ linux_nat_post_attach_wait (ptid_t ptid, int *signalled)
6240d7
       if (debug_linux_nat)
6240d7
 	fprintf_unfiltered (gdb_stdlog,
6240d7
 			    "LNPAW: Attaching to a stopped process\n");
6240d7
+#ifdef NEED_DETACH_SIGSTOP
6240d7
+      pid_was_stopped = ptid.pid ();
6240d7
+#endif
6240d7
 
6240d7
       /* The process is definitely stopped.  It is in a job control
6240d7
 	 stop, unless the kernel predates the TASK_STOPPED /
6240d7
@@ -1369,6 +1378,25 @@ get_detach_signal (struct lwp_info *lp)
6240d7
       return gdb_signal_to_host (signo);
6240d7
     }
6240d7
 
6240d7
+#ifdef NEED_DETACH_SIGSTOP
6240d7
+  /* Workaround RHEL-5 kernel which has unreliable PTRACE_DETACH, SIGSTOP (that
6240d7
+     many TIDs are left unstopped).  See RH Bug 496732.  */
6240d7
+  if (lp->ptid.pid () == pid_was_stopped)
6240d7
+    {
6240d7
+      int err;
6240d7
+
6240d7
+      errno = 0;
6240d7
+      err = kill_lwp (lp->ptid.lwp (), SIGSTOP);
6240d7
+      if (debug_linux_nat)
6240d7
+	{
6240d7
+	  fprintf_unfiltered (gdb_stdlog,
6240d7
+			      "SC:  lwp kill %d %s\n",
6240d7
+			      err,
6240d7
+			      errno ? safe_strerror (errno) : "ERRNO-OK");
6240d7
+	}
6240d7
+    }
6240d7
+
6240d7
+#endif
6240d7
   return 0;
6240d7
 }
6240d7
 
6240d7
@@ -1517,6 +1545,10 @@ linux_nat_target::detach (inferior *inf, int from_tty)
6240d7
       detach_one_lwp (main_lwp, &signo);
6240d7
 
6240d7
       detach_success (inf);
6240d7
+
6240d7
+#ifdef NEED_DETACH_SIGSTOP
6240d7
+      pid_was_stopped = 0;
6240d7
+#endif
6240d7
     }
6240d7
 }
6240d7
 
6240d7
@@ -1775,6 +1807,16 @@ linux_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
6240d7
       return;
6240d7
     }
6240d7
 
6240d7
+#ifdef NEED_DETACH_SIGSTOP
6240d7
+  /* At this point, we are going to resume the inferior and if we
6240d7
+     have attached to a stopped process, we no longer should leave
6240d7
+     it as stopped if the user detaches.  PTID variable has PID set to LWP
6240d7
+     while we need to check the real PID here.  */
6240d7
+
6240d7
+  if (!step && lp && pid_was_stopped == lp->ptid.pid ())
6240d7
+    pid_was_stopped = 0;
6240d7
+
6240d7
+#endif
6240d7
   if (resume_many)
6240d7
     iterate_over_lwps (ptid, linux_nat_resume_callback, lp);
6240d7
 
6240d7
@@ -3763,6 +3805,10 @@ linux_nat_target::mourn_inferior ()
6240d7
 
6240d7
   /* Let the arch-specific native code know this process is gone.  */
6240d7
   linux_target->low_forget_process (pid);
6240d7
+#ifdef NEED_DETACH_SIGSTOP
6240d7
+
6240d7
+  pid_was_stopped = 0;
6240d7
+#endif
6240d7
 }
6240d7
 
6240d7
 /* Convert a native/host siginfo object, into/from the siginfo in the
6240d7
diff --git a/gdb/testsuite/gdb.threads/attach-stopped.exp b/gdb/testsuite/gdb.threads/attach-stopped.exp
6240d7
--- a/gdb/testsuite/gdb.threads/attach-stopped.exp
6240d7
+++ b/gdb/testsuite/gdb.threads/attach-stopped.exp
6240d7
@@ -56,7 +56,65 @@ proc corefunc { threadtype } {
6240d7
     gdb_reinitialize_dir $srcdir/$subdir
6240d7
     gdb_load ${binfile}
6240d7
 
6240d7
-    # Verify that we can attach to the stopped process.
6240d7
+    # Verify that we can attach to the process by first giving its
6240d7
+    # executable name via the file command, and using attach with the
6240d7
+    # process ID.
6240d7
+
6240d7
+    set test "$threadtype: set file, before attach1 to stopped process"
6240d7
+    gdb_test_multiple "file $binfile" "$test" {
6240d7
+       -re "Load new symbol table from.*y or n. $" {
6240d7
+	    gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
6240d7
+		    "$test (re-read)"
6240d7
+	}
6240d7
+	-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
6240d7
+	    pass "$test"
6240d7
+	}
6240d7
+    }
6240d7
+
6240d7
+    set test "$threadtype: attach1 to stopped, after setting file"
6240d7
+    gdb_test_multiple "attach $testpid" "$test" {
6240d7
+	-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
6240d7
+	    pass "$test"
6240d7
+	}
6240d7
+    }
6240d7
+
6240d7
+    # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
6240d7
+    if {[string equal $threadtype threaded]} {
6240d7
+	gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach1 to stopped bt"
6240d7
+    } else {
6240d7
+	gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach1 to stopped bt"
6240d7
+    }
6240d7
+
6240d7
+    # Exit and detach the process.
6240d7
+       
6240d7
+    gdb_exit
6240d7
+
6240d7
+    # Avoid some race:
6240d7
+    sleep 2
6240d7
+
6240d7
+    if [catch {open /proc/${testpid}/status r} fileid] {
6240d7
+	set line2 "NOTFOUND"
6240d7
+    } else {
6240d7
+	gets $fileid line1;
6240d7
+	gets $fileid line2;
6240d7
+	close $fileid;
6240d7
+    }
6240d7
+
6240d7
+    set test "$threadtype: attach1, exit leaves process stopped"
6240d7
+    if {[string match "*(stopped)*" $line2]} {
6240d7
+      pass $test
6240d7
+    } else {
6240d7
+      fail $test
6240d7
+    }
6240d7
+
6240d7
+    # At this point, the process should still be stopped
6240d7
+
6240d7
+    gdb_start
6240d7
+    gdb_reinitialize_dir $srcdir/$subdir
6240d7
+    gdb_load ${binfile}
6240d7
+
6240d7
+    # Verify that we can attach to the process just by giving the
6240d7
+    # process ID.
6240d7
        
6240d7
     set test "$threadtype: attach2 to stopped, after setting file"
6240d7
     gdb_test_multiple "attach $testpid" "$test" {