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

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