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