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

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