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

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