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

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