Blame SOURCES/gdb-6.3-gstack-20050411.patch

4c2ad1
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
4c2ad1
From: Andrew Cagney <cagney@gnu.org>
4c2ad1
Date: Fri, 27 Oct 2017 21:07:50 +0200
4c2ad1
Subject: gdb-6.3-gstack-20050411.patch
4c2ad1
4c2ad1
;; Add a wrapper script to GDB that implements pstack using the
4c2ad1
;; --readnever option.
4c2ad1
;;=push
4c2ad1
4c2ad1
2004-11-23  Andrew Cagney  <cagney@redhat.com>
4c2ad1
4c2ad1
	* Makefile.in (uninstall-gstack, install-gstack): New rules, add
4c2ad1
	to install and uninstall.
4c2ad1
	* gstack.sh, gstack.1: New files.
4c2ad1
4c2ad1
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
4c2ad1
--- a/gdb/Makefile.in
4c2ad1
+++ b/gdb/Makefile.in
4c2ad1
@@ -1735,7 +1735,7 @@ info install-info clean-info dvi pdf install-pdf html install-html: force
4c2ad1
 install: all
4c2ad1
 	@$(MAKE) $(FLAGS_TO_PASS) install-only
4c2ad1
 
4c2ad1
-install-only: $(CONFIG_INSTALL)
4c2ad1
+install-only: install-gstack $(CONFIG_INSTALL)
4c2ad1
 	transformed_name=`t='$(program_transform_name)'; \
4c2ad1
 			  echo gdb | sed -e "$$t"` ; \
4c2ad1
 		if test "x$$transformed_name" = x; then \
4c2ad1
@@ -1784,7 +1784,25 @@ install-guile:
4c2ad1
 install-python:
4c2ad1
 	$(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_DATADIR)/python/gdb
4c2ad1
 
4c2ad1
-uninstall: force $(CONFIG_UNINSTALL)
4c2ad1
+GSTACK=gstack
4c2ad1
+.PHONY: install-gstack
4c2ad1
+install-gstack:
4c2ad1
+	transformed_name=`t='$(program_transform_name)'; \
4c2ad1
+			  echo $(GSTACK) | sed -e "$$t"` ; \
4c2ad1
+		if test "x$$transformed_name" = x; then \
4c2ad1
+		  transformed_name=$(GSTACK) ; \
4c2ad1
+		else \
4c2ad1
+		  true ; \
4c2ad1
+		fi ; \
4c2ad1
+		$(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(bindir) ; \
4c2ad1
+		$(INSTALL_PROGRAM) $(srcdir)/$(GSTACK).sh \
4c2ad1
+			$(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) ; \
4c2ad1
+		: $(SHELL) $(srcdir)/../mkinstalldirs \
4c2ad1
+			$(DESTDIR)$(man1dir) ; \
4c2ad1
+		: $(INSTALL_DATA) $(srcdir)/gstack.1 \
4c2ad1
+			$(DESTDIR)$(man1dir)/$$transformed_name.1
4c2ad1
+
4c2ad1
+uninstall: force uninstall-gstack $(CONFIG_UNINSTALL)
4c2ad1
 	transformed_name=`t='$(program_transform_name)'; \
4c2ad1
 			  echo gdb | sed -e $$t` ; \
4c2ad1
 		if test "x$$transformed_name" = x; then \
4c2ad1
@@ -1807,6 +1825,18 @@ uninstall: force $(CONFIG_UNINSTALL)
4c2ad1
 	fi
4c2ad1
 	@$(MAKE) DO=uninstall "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do
4c2ad1
 
4c2ad1
+.PHONY: uninstall-gstack
4c2ad1
+uninstall-gstack:
4c2ad1
+	transformed_name=`t='$(program_transform_name)'; \
4c2ad1
+			  echo $(GSTACK) | sed -e $$t` ; \
4c2ad1
+		if test "x$$transformed_name" = x; then \
4c2ad1
+		  transformed_name=$(GSTACK) ; \
4c2ad1
+		else \
4c2ad1
+		  true ; \
4c2ad1
+		fi ; \
4c2ad1
+		rm -f $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) \
4c2ad1
+		      $(DESTDIR)$(man1dir)/$$transformed_name.1
4c2ad1
+ 
4c2ad1
 # The C++ name parser can be built standalone for testing.
4c2ad1
 test-cp-name-parser.o: cp-name-parser.c
4c2ad1
 	$(COMPILE) -DTEST_CPNAMES cp-name-parser.c
4c2ad1
diff --git a/gdb/gstack.sh b/gdb/gstack.sh
4c2ad1
new file mode 100644
4c2ad1
--- /dev/null
4c2ad1
+++ b/gdb/gstack.sh
4c2ad1
@@ -0,0 +1,43 @@
4c2ad1
+#!/bin/sh
4c2ad1
+
4c2ad1
+if test $# -ne 1; then
4c2ad1
+    echo "Usage: `basename $0 .sh` <process-id>" 1>&2
4c2ad1
+    exit 1
4c2ad1
+fi
4c2ad1
+
4c2ad1
+if test ! -r /proc/$1; then
4c2ad1
+    echo "Process $1 not found." 1>&2
4c2ad1
+    exit 1
4c2ad1
+fi
4c2ad1
+
4c2ad1
+# GDB doesn't allow "thread apply all bt" when the process isn't
4c2ad1
+# threaded; need to peek at the process to determine if that or the
4c2ad1
+# simpler "bt" should be used.
4c2ad1
+
4c2ad1
+backtrace="bt"
4c2ad1
+if test -d /proc/$1/task ; then
4c2ad1
+    # Newer kernel; has a task/ directory.
4c2ad1
+    if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2>/dev/null ; then
4c2ad1
+	backtrace="thread apply all bt"
4c2ad1
+    fi
4c2ad1
+elif test -f /proc/$1/maps ; then
4c2ad1
+    # Older kernel; go by it loading libpthread.
4c2ad1
+    if /bin/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then
4c2ad1
+	backtrace="thread apply all bt"
4c2ad1
+    fi
4c2ad1
+fi
4c2ad1
+
4c2ad1
+GDB=${GDB:-gdb}
4c2ad1
+
4c2ad1
+# Run GDB, strip out unwanted noise.
4c2ad1
+# --readnever is no longer used since .gdb_index is now in use.
4c2ad1
+$GDB --quiet -nx $GDBARGS /proc/$1/exe $1 <<EOF 2>&1 | 
4c2ad1
+set width 0
4c2ad1
+set height 0
4c2ad1
+set pagination no
4c2ad1
+$backtrace
4c2ad1
+EOF
4c2ad1
+/bin/sed -n \
4c2ad1
+    -e 's/^\((gdb) \)*//' \
4c2ad1
+    -e '/^#/p' \
4c2ad1
+    -e '/^Thread/p'
4c2ad1
diff --git a/gdb/testsuite/gdb.base/gstack.c b/gdb/testsuite/gdb.base/gstack.c
4c2ad1
new file mode 100644
4c2ad1
--- /dev/null
4c2ad1
+++ b/gdb/testsuite/gdb.base/gstack.c
4c2ad1
@@ -0,0 +1,43 @@
4c2ad1
+/* This testcase is part of GDB, the GNU debugger.
4c2ad1
+
4c2ad1
+   Copyright 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
4c2ad1
+
4c2ad1
+   This program is free software; you can redistribute it and/or modify
4c2ad1
+   it under the terms of the GNU General Public License as published by
4c2ad1
+   the Free Software Foundation; either version 3 of the License, or
4c2ad1
+   (at your option) any later version.
4c2ad1
+
4c2ad1
+   This program is distributed in the hope that it will be useful,
4c2ad1
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
4c2ad1
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c2ad1
+   GNU General Public License for more details.
4c2ad1
+
4c2ad1
+   You should have received a copy of the GNU General Public License
4c2ad1
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
4c2ad1
+
4c2ad1
+#include <stdio.h>
4c2ad1
+#include <unistd.h>
4c2ad1
+#include <string.h>
4c2ad1
+
4c2ad1
+void
4c2ad1
+func (void)
4c2ad1
+{
4c2ad1
+  const char msg[] = "looping\n";
4c2ad1
+
4c2ad1
+  /* Use the most simple notification not to get caught by attach on exiting
4c2ad1
+     the function.  */
4c2ad1
+  write (1, msg, strlen (msg));
4c2ad1
+  
4c2ad1
+  for (;;);
4c2ad1
+}
4c2ad1
+
4c2ad1
+int
4c2ad1
+main (void)
4c2ad1
+{
4c2ad1
+  alarm (60);
4c2ad1
+  nice (100);
4c2ad1
+
4c2ad1
+  func ();
4c2ad1
+
4c2ad1
+  return 0;
4c2ad1
+}
4c2ad1
diff --git a/gdb/testsuite/gdb.base/gstack.exp b/gdb/testsuite/gdb.base/gstack.exp
4c2ad1
new file mode 100644
4c2ad1
--- /dev/null
4c2ad1
+++ b/gdb/testsuite/gdb.base/gstack.exp
4c2ad1
@@ -0,0 +1,66 @@
4c2ad1
+# Copyright (C) 2012 Free Software Foundation, Inc.
4c2ad1
+
4c2ad1
+# This program is free software; you can redistribute it and/or modify
4c2ad1
+# it under the terms of the GNU General Public License as published by
4c2ad1
+# the Free Software Foundation; either version 3 of the License, or
4c2ad1
+# (at your option) any later version.
4c2ad1
+#
4c2ad1
+# This program is distributed in the hope that it will be useful,
4c2ad1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c2ad1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c2ad1
+# GNU General Public License for more details.
4c2ad1
+#
4c2ad1
+# You should have received a copy of the GNU General Public License
4c2ad1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
4c2ad1
+
4c2ad1
+set testfile gstack
4c2ad1
+set executable ${testfile}
4c2ad1
+set binfile [standard_output_file $executable]
4c2ad1
+if {[build_executable ${testfile} ${executable} "" {debug}] == -1} {
4c2ad1
+    return -1
4c2ad1
+}
4c2ad1
+
4c2ad1
+set test "spawn inferior"
4c2ad1
+set command "${binfile}"
4c2ad1
+set res [remote_spawn host $command];
4c2ad1
+if { $res < 0 || $res == "" } {
4c2ad1
+    perror "Spawning $command failed."
4c2ad1
+    fail $test
4c2ad1
+    return
4c2ad1
+}
4c2ad1
+set use_gdb_stub 1
4c2ad1
+set pid [exp_pid -i $res]
4c2ad1
+gdb_expect {
4c2ad1
+    -re "looping\r\n" {
4c2ad1
+	pass $test
4c2ad1
+    }
4c2ad1
+    eof {
4c2ad1
+	fail "$test (eof)"
4c2ad1
+	return
4c2ad1
+    }
4c2ad1
+    timeout {
4c2ad1
+	fail "$test (timeout)"
4c2ad1
+	return
4c2ad1
+    }
4c2ad1
+}
4c2ad1
+gdb_exit
4c2ad1
+
4c2ad1
+# Testcase uses the most simple notification not to get caught by attach on
4c2ad1
+# exiting the function.  Still we could retry the gstack command if we fail.
4c2ad1
+
4c2ad1
+set test "spawn gstack"
4c2ad1
+set command "sh -c GDB=$GDB\\ GDBARGS=-data-directory\\\\\\ $BUILD_DATA_DIRECTORY\\ sh\\ ${srcdir}/../gstack.sh\\ $pid\\;echo\\ GSTACK-END"
4c2ad1
+set res [remote_spawn host $command];
4c2ad1
+if { $res < 0 || $res == "" } {
4c2ad1
+    perror "Spawning $command failed."
4c2ad1
+    fail $test
4c2ad1
+}
4c2ad1
+set pid [exp_pid -i $res]
4c2ad1
+gdb_test_multiple "" $test {
4c2ad1
+    -re "^#0 +(0x\[0-9a-f\]+ in )?\\.?func \\(\\) at \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in \\.?main \\(\\) at \[^\r\n\]*\r\nGSTACK-END\r\n\$" {
4c2ad1
+	pass $test
4c2ad1
+    }
4c2ad1
+}
4c2ad1
+gdb_exit
4c2ad1
+
4c2ad1
+remote_exec host "kill -9 $pid"