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

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