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

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