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 ;; Add a wrapper script to GDB that implements pstack using the
10 2004-11-23 Andrew Cagney <cagney@redhat.com>
12 * Makefile.in (uninstall-gstack, install-gstack): New rules, add
13 to install and uninstall.
14 * gstack.sh, gstack.1: New files.
16 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
19 @@ -1768,7 +1768,7 @@ info install-info clean-info dvi pdf install-pdf html install-html: force
21 @$(MAKE) $(FLAGS_TO_PASS) install-only
23 -install-only: $(CONFIG_INSTALL)
24 +install-only: install-gstack $(CONFIG_INSTALL)
25 transformed_name=`t='$(program_transform_name)'; \
26 echo gdb | sed -e "$$t"` ; \
27 if test "x$$transformed_name" = x; then \
28 @@ -1817,7 +1817,25 @@ install-guile:
30 $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_DATADIR)/python/gdb
32 -uninstall: force $(CONFIG_UNINSTALL)
34 +.PHONY: install-gstack
36 + transformed_name=`t='$(program_transform_name)'; \
37 + echo $(GSTACK) | sed -e "$$t"` ; \
38 + if test "x$$transformed_name" = x; then \
39 + transformed_name=$(GSTACK) ; \
43 + $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(bindir) ; \
44 + $(INSTALL_PROGRAM) $(srcdir)/$(GSTACK).sh \
45 + $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) ; \
46 + : $(SHELL) $(srcdir)/../mkinstalldirs \
47 + $(DESTDIR)$(man1dir) ; \
48 + : $(INSTALL_DATA) $(srcdir)/gstack.1 \
49 + $(DESTDIR)$(man1dir)/$$transformed_name.1
51 +uninstall: force uninstall-gstack $(CONFIG_UNINSTALL)
52 transformed_name=`t='$(program_transform_name)'; \
53 echo gdb | sed -e $$t` ; \
54 if test "x$$transformed_name" = x; then \
55 @@ -1840,6 +1858,18 @@ uninstall: force $(CONFIG_UNINSTALL)
57 @$(MAKE) DO=uninstall "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do
59 +.PHONY: uninstall-gstack
61 + transformed_name=`t='$(program_transform_name)'; \
62 + echo $(GSTACK) | sed -e $$t` ; \
63 + if test "x$$transformed_name" = x; then \
64 + transformed_name=$(GSTACK) ; \
68 + rm -f $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) \
69 + $(DESTDIR)$(man1dir)/$$transformed_name.1
71 # The C++ name parser can be built standalone for testing.
72 test-cp-name-parser.o: cp-name-parser.c
73 $(COMPILE) -DTEST_CPNAMES cp-name-parser.c
74 diff --git a/gdb/gstack.sh b/gdb/gstack.sh
81 +if test $# -ne 1; then
82 + echo "Usage: `basename $0 .sh` <process-id>" 1>&2
86 +if test ! -r /proc/$1; then
87 + echo "Process $1 not found." 1>&2
91 +# GDB doesn't allow "thread apply all bt" when the process isn't
92 +# threaded; need to peek at the process to determine if that or the
93 +# simpler "bt" should be used.
96 +if test -d /proc/$1/task ; then
97 + # Newer kernel; has a task/ directory.
98 + if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2>/dev/null ; then
99 + backtrace="thread apply all bt"
101 +elif test -f /proc/$1/maps ; then
102 + # Older kernel; go by it loading libpthread.
103 + if /bin/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then
104 + backtrace="thread apply all bt"
110 +# Run GDB, strip out unwanted noise.
111 +# --readnever is no longer used since .gdb_index is now in use.
112 +$GDB --quiet -nx $GDBARGS /proc/$1/exe $1 <<EOF 2>&1 |
119 + -e 's/^\((gdb) \)*//' \
122 diff --git a/gdb/testsuite/gdb.base/gstack.c b/gdb/testsuite/gdb.base/gstack.c
125 +++ b/gdb/testsuite/gdb.base/gstack.c
127 +/* This testcase is part of GDB, the GNU debugger.
129 + Copyright 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
131 + This program is free software; you can redistribute it and/or modify
132 + it under the terms of the GNU General Public License as published by
133 + the Free Software Foundation; either version 3 of the License, or
134 + (at your option) any later version.
136 + This program is distributed in the hope that it will be useful,
137 + but WITHOUT ANY WARRANTY; without even the implied warranty of
138 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139 + GNU General Public License for more details.
141 + You should have received a copy of the GNU General Public License
142 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
151 + const char msg[] = "looping\n";
153 + /* Use the most simple notification not to get caught by attach on exiting
155 + write (1, msg, strlen (msg));
170 diff --git a/gdb/testsuite/gdb.base/gstack.exp b/gdb/testsuite/gdb.base/gstack.exp
173 +++ b/gdb/testsuite/gdb.base/gstack.exp
175 +# Copyright (C) 2012 Free Software Foundation, Inc.
177 +# This program is free software; you can redistribute it and/or modify
178 +# it under the terms of the GNU General Public License as published by
179 +# the Free Software Foundation; either version 3 of the License, or
180 +# (at your option) any later version.
182 +# This program is distributed in the hope that it will be useful,
183 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
184 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185 +# GNU General Public License for more details.
187 +# You should have received a copy of the GNU General Public License
188 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
191 +set executable ${testfile}
192 +set binfile [standard_output_file $executable]
193 +if {[build_executable ${testfile} ${executable} "" {debug}] == -1} {
197 +set test "spawn inferior"
198 +set command "${binfile}"
199 +set res [remote_spawn host $command];
200 +if { $res < 0 || $res == "" } {
201 + perror "Spawning $command failed."
206 +# The spawn id of the test inferior.
207 +set test_spawn_id $res
210 +set pid [exp_pid -i $res]
212 + -re "looping\r\n" {
220 + fail "$test (timeout)"
225 +# Testcase uses the most simple notification not to get caught by attach on
226 +# exiting the function. Still we could retry the gstack command if we fail.
228 +set test "spawn gstack"
229 +set command "sh -c GDB=$GDB\\ GDBARGS=-data-directory\\\\\\ $BUILD_DATA_DIRECTORY\\ sh\\ ${srcdir}/../gstack.sh\\ $pid\\;echo\\ GSTACK-END"
230 +set res [remote_spawn host $command];
231 +if { $res < 0 || $res == "" } {
232 + perror "Spawning $command failed."
236 +set gdb_spawn_id $res
238 +gdb_test_multiple "" $test {
239 + -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\$" {
244 +gdb_test_multiple "" "gstack exits" {
246 + set result [wait -i $gdb_spawn_id]
249 + gdb_assert { [lindex $result 2] == 0 } "gstack exits with no error"
250 + gdb_assert { [lindex $result 3] == 0 } "gstack's exit status is 0"
257 +# Kill the test inferior.
258 +kill_wait_spawned_process $test_spawn_id