]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.3-gstack-20050411.patch
- updated to 14.1 + rebased Fedora buildid patches set
[packages/gdb.git] / gdb-6.3-gstack-20050411.patch
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
5
6 ;; Add a wrapper script to GDB that implements pstack using the
7 ;; --readnever option.
8 ;;=push
9
10 2004-11-23  Andrew Cagney  <cagney@redhat.com>
11
12         * Makefile.in (uninstall-gstack, install-gstack): New rules, add
13         to install and uninstall.
14         * gstack.sh, gstack.1: New files.
15
16 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
17 --- a/gdb/Makefile.in
18 +++ b/gdb/Makefile.in
19 @@ -1767,7 +1767,7 @@ info install-info clean-info dvi pdf install-pdf html install-html: force
20  install: all
21         @$(MAKE) $(FLAGS_TO_PASS) install-only
22  
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 @@ -1816,7 +1816,25 @@ install-guile:
29  install-python:
30         $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_DATADIR)/python/gdb
31  
32 -uninstall: force $(CONFIG_UNINSTALL)
33 +GSTACK=gstack
34 +.PHONY: install-gstack
35 +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) ; \
40 +               else \
41 +                 true ; \
42 +               fi ; \
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
50 +
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 @@ -1847,6 +1865,18 @@ uninstall: force $(CONFIG_UNINSTALL)
56         rm -f $(DESTDIR)$(bindir)/$$transformed_name
57         @$(MAKE) DO=uninstall "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do
58  
59 +.PHONY: uninstall-gstack
60 +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) ; \
65 +               else \
66 +                 true ; \
67 +               fi ; \
68 +               rm -f $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) \
69 +                     $(DESTDIR)$(man1dir)/$$transformed_name.1
70 +
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
75 new file mode 100644
76 --- /dev/null
77 +++ b/gdb/gstack.sh
78 @@ -0,0 +1,43 @@
79 +#!/bin/sh
80 +
81 +if test $# -ne 1; then
82 +    echo "Usage: `basename $0 .sh` <process-id>" 1>&2
83 +    exit 1
84 +fi
85 +
86 +if test ! -r /proc/$1; then
87 +    echo "Process $1 not found." 1>&2
88 +    exit 1
89 +fi
90 +
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.
94 +
95 +backtrace="bt"
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"
100 +    fi
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"
105 +    fi
106 +fi
107 +
108 +GDB=${GDB:-gdb}
109 +
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 |
113 +set width 0
114 +set height 0
115 +set pagination no
116 +$backtrace
117 +EOF
118 +/bin/sed -n \
119 +    -e 's/^\((gdb) \)*//' \
120 +    -e '/^#/p' \
121 +    -e '/^Thread/p'
122 diff --git a/gdb/testsuite/gdb.base/gstack.c b/gdb/testsuite/gdb.base/gstack.c
123 new file mode 100644
124 --- /dev/null
125 +++ b/gdb/testsuite/gdb.base/gstack.c
126 @@ -0,0 +1,43 @@
127 +/* This testcase is part of GDB, the GNU debugger.
128 +
129 +   Copyright 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
130 +
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.
135 +
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.
140 +
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/>.  */
143 +
144 +#include <stdio.h>
145 +#include <unistd.h>
146 +#include <string.h>
147 +
148 +void
149 +func (void)
150 +{
151 +  const char msg[] = "looping\n";
152 +
153 +  /* Use the most simple notification not to get caught by attach on exiting
154 +     the function.  */
155 +  write (1, msg, strlen (msg));
156 +
157 +  for (;;);
158 +}
159 +
160 +int
161 +main (void)
162 +{
163 +  alarm (60);
164 +  nice (100);
165 +
166 +  func ();
167 +
168 +  return 0;
169 +}
170 diff --git a/gdb/testsuite/gdb.base/gstack.exp b/gdb/testsuite/gdb.base/gstack.exp
171 new file mode 100644
172 --- /dev/null
173 +++ b/gdb/testsuite/gdb.base/gstack.exp
174 @@ -0,0 +1,84 @@
175 +# Copyright (C) 2012 Free Software Foundation, Inc.
176 +
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.
181 +#
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.
186 +#
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/>.
189 +
190 +set testfile gstack
191 +set executable ${testfile}
192 +set binfile [standard_output_file $executable]
193 +if {[build_executable ${testfile} ${executable} "" {debug}] == -1} {
194 +    return -1
195 +}
196 +
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."
202 +    fail $test
203 +    return
204 +}
205 +
206 +# The spawn id of the test inferior.
207 +set test_spawn_id $res
208 +
209 +set use_gdb_stub 1
210 +set pid [exp_pid -i $res]
211 +gdb_expect {
212 +    -re "looping\r\n" {
213 +       pass $test
214 +    }
215 +    eof {
216 +       fail "$test (eof)"
217 +       return
218 +    }
219 +    timeout {
220 +       fail "$test (timeout)"
221 +       return
222 +    }
223 +}
224 +
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.
227 +
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."
233 +    fail $test
234 +}
235 +
236 +set gdb_spawn_id $res
237 +
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\$" {
240 +       pass $test
241 +    }
242 +}
243 +
244 +gdb_test_multiple "" "gstack exits" {
245 +    eof {
246 +       set result [wait -i $gdb_spawn_id]
247 +       verbose $result
248 +
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"
251 +
252 +       remote_close host
253 +       clear_gdb_spawn_id
254 +    }
255 +}
256 +
257 +# Kill the test inferior.
258 +kill_wait_spawned_process $test_spawn_id
This page took 0.066653 seconds and 3 git commands to generate.