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

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