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

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