1 From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2 From: Andrew Cagney <cagney@gnu.org>
3 Date: Fri, 27 Oct 2017 21:07:50 +0200
4 Subject: gdb-6.3-gstack-20050411.patch
6 FileName: gdb-6.3-gstack-20050411.patch
8 ;; Add a wrapper script to GDB that implements pstack using the
12 2004-11-23 Andrew Cagney <cagney@redhat.com>
14 * Makefile.in (uninstall-gstack, install-gstack): New rules, add
15 to install and uninstall.
16 * gstack.sh, gstack.1: New files.
18 gdb/Makefile.in | 34 ++++++++++++++++++--
19 gdb/gstack.sh | 43 +++++++++++++++++++++++++
20 gdb/testsuite/gdb.base/gstack.c | 43 +++++++++++++++++++++++++
21 gdb/testsuite/gdb.base/gstack.exp | 66 +++++++++++++++++++++++++++++++++++++++
22 4 files changed, 184 insertions(+), 2 deletions(-)
23 create mode 100644 gdb/gstack.sh
24 create mode 100644 gdb/testsuite/gdb.base/gstack.c
25 create mode 100644 gdb/testsuite/gdb.base/gstack.exp
27 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
28 index 17b71c6e7c..e77d6a5c03 100644
31 @@ -1744,7 +1744,7 @@ info install-info clean-info dvi pdf install-pdf html install-html: force
33 @$(MAKE) $(FLAGS_TO_PASS) install-only
35 -install-only: $(CONFIG_INSTALL)
36 +install-only: install-gstack $(CONFIG_INSTALL)
37 transformed_name=`t='$(program_transform_name)'; \
38 echo gdb | sed -e "$$t"` ; \
39 if test "x$$transformed_name" = x; then \
40 @@ -1784,7 +1784,25 @@ install-guile:
42 $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_DATADIR)/python/gdb
44 -uninstall: force $(CONFIG_UNINSTALL)
46 +.PHONY: install-gstack
48 + transformed_name=`t='$(program_transform_name)'; \
49 + echo $(GSTACK) | sed -e "$$t"` ; \
50 + if test "x$$transformed_name" = x; then \
51 + transformed_name=$(GSTACK) ; \
55 + $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(bindir) ; \
56 + $(INSTALL_PROGRAM) $(srcdir)/$(GSTACK).sh \
57 + $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) ; \
58 + : $(SHELL) $(srcdir)/../mkinstalldirs \
59 + $(DESTDIR)$(man1dir) ; \
60 + : $(INSTALL_DATA) $(srcdir)/gstack.1 \
61 + $(DESTDIR)$(man1dir)/$$transformed_name.1
63 +uninstall: force uninstall-gstack $(CONFIG_UNINSTALL)
64 transformed_name=`t='$(program_transform_name)'; \
65 echo gdb | sed -e $$t` ; \
66 if test "x$$transformed_name" = x; then \
67 @@ -1807,6 +1825,18 @@ uninstall: force $(CONFIG_UNINSTALL)
69 @$(MAKE) DO=uninstall "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do
71 +.PHONY: uninstall-gstack
73 + transformed_name=`t='$(program_transform_name)'; \
74 + echo $(GSTACK) | sed -e $$t` ; \
75 + if test "x$$transformed_name" = x; then \
76 + transformed_name=$(GSTACK) ; \
80 + rm -f $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) \
81 + $(DESTDIR)$(man1dir)/$$transformed_name.1
83 # The C++ name parser can be built standalone for testing.
84 test-cp-name-parser.o: cp-name-parser.c
85 $(COMPILE) -DTEST_CPNAMES cp-name-parser.c
86 diff --git a/gdb/gstack.sh b/gdb/gstack.sh
88 index 0000000000..f7f07248f7
94 +if test $# -ne 1; then
95 + echo "Usage: `basename $0 .sh` <process-id>" 1>&2
99 +if test ! -r /proc/$1; then
100 + echo "Process $1 not found." 1>&2
104 +# GDB doesn't allow "thread apply all bt" when the process isn't
105 +# threaded; need to peek at the process to determine if that or the
106 +# simpler "bt" should be used.
109 +if test -d /proc/$1/task ; then
110 + # Newer kernel; has a task/ directory.
111 + if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2>/dev/null ; then
112 + backtrace="thread apply all bt"
114 +elif test -f /proc/$1/maps ; then
115 + # Older kernel; go by it loading libpthread.
116 + if /bin/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then
117 + backtrace="thread apply all bt"
123 +# Run GDB, strip out unwanted noise.
124 +# --readnever is no longer used since .gdb_index is now in use.
125 +$GDB --quiet -nx $GDBARGS /proc/$1/exe $1 <<EOF 2>&1 |
132 + -e 's/^\((gdb) \)*//' \
135 diff --git a/gdb/testsuite/gdb.base/gstack.c b/gdb/testsuite/gdb.base/gstack.c
137 index 0000000000..dc10813f04
139 +++ b/gdb/testsuite/gdb.base/gstack.c
141 +/* This testcase is part of GDB, the GNU debugger.
143 + Copyright 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
145 + This program is free software; you can redistribute it and/or modify
146 + it under the terms of the GNU General Public License as published by
147 + the Free Software Foundation; either version 3 of the License, or
148 + (at your option) any later version.
150 + This program is distributed in the hope that it will be useful,
151 + but WITHOUT ANY WARRANTY; without even the implied warranty of
152 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153 + GNU General Public License for more details.
155 + You should have received a copy of the GNU General Public License
156 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
165 + const char msg[] = "looping\n";
167 + /* Use the most simple notification not to get caught by attach on exiting
169 + write (1, msg, strlen (msg));
184 diff --git a/gdb/testsuite/gdb.base/gstack.exp b/gdb/testsuite/gdb.base/gstack.exp
186 index 0000000000..1186ec57bc
188 +++ b/gdb/testsuite/gdb.base/gstack.exp
190 +# Copyright (C) 2012 Free Software Foundation, Inc.
192 +# This program is free software; you can redistribute it and/or modify
193 +# it under the terms of the GNU General Public License as published by
194 +# the Free Software Foundation; either version 3 of the License, or
195 +# (at your option) any later version.
197 +# This program is distributed in the hope that it will be useful,
198 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
199 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
200 +# GNU General Public License for more details.
202 +# You should have received a copy of the GNU General Public License
203 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
206 +set executable ${testfile}
207 +set binfile [standard_output_file $executable]
208 +if {[build_executable ${testfile} ${executable} "" {debug}] == -1} {
212 +set test "spawn inferior"
213 +set command "${binfile}"
214 +set res [remote_spawn host $command];
215 +if { $res < 0 || $res == "" } {
216 + perror "Spawning $command failed."
221 +set pid [exp_pid -i $res]
223 + -re "looping\r\n" {
231 + fail "$test (timeout)"
237 +# Testcase uses the most simple notification not to get caught by attach on
238 +# exiting the function. Still we could retry the gstack command if we fail.
240 +set test "spawn gstack"
241 +set command "sh -c GDB=$GDB\\ GDBARGS=-data-directory\\\\\\ $BUILD_DATA_DIRECTORY\\ sh\\ ${srcdir}/../gstack.sh\\ $pid\\;echo\\ GSTACK-END"
242 +set res [remote_spawn host $command];
243 +if { $res < 0 || $res == "" } {
244 + perror "Spawning $command failed."
247 +set pid [exp_pid -i $res]
248 +gdb_test_multiple "" $test {
249 + -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\$" {
255 +remote_exec host "kill -9 $pid"