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

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