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