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

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