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