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

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