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