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