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

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