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

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