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

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