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

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