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

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