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

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