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

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