Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 223533 | Differences between
and this patch

Collapse All | Expand All

(-)gdb-6.8.orig/gdb/testsuite/configure (-1 / +2 lines)
Lines 3104-3110 Link Here
3104
3104
3105
3105
3106
3106
3107
                                                                                                                                                                                              ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.fortran/Makefile gdb.server/Makefile gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
3107
                                                                                                                                                                                              ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.fortran/Makefile gdb.server/Makefile gdb.pie/Makefile gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
3108
cat >confcache <<\_ACEOF
3108
cat >confcache <<\_ACEOF
3109
# This file is a shell script that caches the results of configure
3109
# This file is a shell script that caches the results of configure
3110
# tests run on this system so they can be shared between configure
3110
# tests run on this system so they can be shared between configure
Lines 3665-3670 Link Here
3665
  "gdb.dwarf2/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.dwarf2/Makefile" ;;
3665
  "gdb.dwarf2/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.dwarf2/Makefile" ;;
3666
  "gdb.fortran/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.fortran/Makefile" ;;
3666
  "gdb.fortran/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.fortran/Makefile" ;;
3667
  "gdb.server/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.server/Makefile" ;;
3667
  "gdb.server/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.server/Makefile" ;;
3668
  "gdb.pie/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.pie/Makefile" ;;
3668
  "gdb.java/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.java/Makefile" ;;
3669
  "gdb.java/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.java/Makefile" ;;
3669
  "gdb.mi/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.mi/Makefile" ;;
3670
  "gdb.mi/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.mi/Makefile" ;;
3670
  "gdb.modula2/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.modula2/Makefile" ;;
3671
  "gdb.modula2/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.modula2/Makefile" ;;
(-)gdb-6.8.orig/gdb/testsuite/configure.ac (-1 / +1 lines)
Lines 114-120 Link Here
114
  gdb.ada/Makefile \
114
  gdb.ada/Makefile \
115
  gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile \
115
  gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile \
116
  gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile \
116
  gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile \
117
  gdb.fortran/Makefile gdb.server/Makefile \
117
  gdb.fortran/Makefile gdb.server/Makefile gdb.pie/Makefile \
118
  gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile \
118
  gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile \
119
  gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile \
119
  gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile \
120
  gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile])
120
  gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile])
(-)gdb-6.8/gdb/testsuite/gdb.pie/Makefile.in (+19 lines)
Added Link Here
1
VPATH = @srcdir@
2
srcdir = @srcdir@
3
4
EXECUTABLES =
5
MISCELLANEOUS = arch.inc
6
7
all info install-info dvi install uninstall installcheck check:
8
	@echo "Nothing to be done for $@..."
9
10
clean mostlyclean:
11
	-rm -f *~ *.o a.out *.x *.ci *.tmp
12
	-rm -f core core.coremaker coremaker.core corefile $(EXECUTABLES)
13
	-rm -f $(MISCELLANEOUS)
14
15
distclean maintainer-clean realclean: clean
16
	-rm -f *~ core
17
	-rm -f Makefile config.status config.log
18
	-rm -f *-init.exp
19
	-rm -fr *.log summary detail *.plog *.sum *.psum site.*
(-)gdb-6.8/gdb/testsuite/gdb.pie/attach.c (+20 lines)
Added Link Here
1
/* This program is intended to be started outside of gdb, and then
2
   attached to by gdb.  Thus, it simply spins in a loop.  The loop
3
   is exited when & if the variable 'should_exit' is non-zero.  (It
4
   is initialized to zero in this program, so the loop will never
5
   exit unless/until gdb sets the variable to non-zero.)
6
   */
7
#include <stdio.h>
8
9
int  should_exit = 0;
10
11
int main ()
12
{
13
  int  local_i = 0;
14
15
  while (! should_exit)
16
    {
17
      local_i++;
18
    }
19
  return 0;
20
}
(-)gdb-6.8/gdb/testsuite/gdb.pie/attach.exp (+432 lines)
Added Link Here
1
#   Copyright 1997, 1999, 2002 Free Software Foundation, Inc.
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
# 
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
# 
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
16
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-gdb@prep.ai.mit.edu
19
20
if $tracelevel then {
21
	strace $tracelevel
22
	}
23
24
set prms_id 0
25
set bug_id 0
26
27
# On HP-UX 11.0, this test is causing a process running the program
28
# "attach" to be left around spinning.  Until we figure out why, I am
29
# commenting out the test to avoid polluting tiamat (our 11.0 nightly
30
# test machine) with these processes. RT
31
#
32
# Setting the magic bit in the target app should work.  I added a
33
# "kill", and also a test for the R3 register warning.  JB
34
if { [istarget "hppa*-*-hpux*"] } {
35
    return 0
36
}
37
38
# are we on a target board
39
if [is_remote target] then {
40
    return 0
41
}
42
43
set testfile "attach"
44
set srcfile  ${testfile}.c
45
set srcfile2 ${testfile}2.c
46
set binfile  ${objdir}/${subdir}/${testfile}
47
set binfile2 ${objdir}/${subdir}/${testfile}2
48
set escapedbinfile  [string_to_regexp ${objdir}/${subdir}/${testfile}]
49
set cleanupfile ${objdir}/${subdir}/${testfile}.awk
50
51
#execute_anywhere "rm -f ${binfile} ${binfile2}"
52
remote_exec build "rm -f ${binfile} ${binfile2}"
53
# For debugging this test
54
#
55
#log_user 1
56
57
# Clean out any old files from past runs.
58
#
59
remote_exec build "${cleanupfile}"
60
61
# build the first test case
62
#
63
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags= -fpie -pie"}] != "" } {
64
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
65
}
66
67
# Build the in-system-call test
68
69
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug "additional_flags= -fpie -pie"}] != "" } {
70
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
71
}
72
73
if [get_compiler_info ${binfile}] {
74
    return -1
75
}
76
77
proc do_attach_tests {} {
78
   global gdb_prompt
79
   global binfile
80
   global escapedbinfile
81
   global srcfile
82
   global testfile
83
   global objdir
84
   global subdir
85
   global timeout
86
87
   # Start the program running and then wait for a bit, to be sure
88
   # that it can be attached to.
89
   #
90
   set testpid [eval exec $binfile &]
91
   exec sleep 2
92
93
   # Verify that we cannot attach to nonsense.
94
   #
95
   send_gdb "attach abc\n"
96
   gdb_expect {
97
      -re ".*Illegal process-id: abc.*$gdb_prompt $"\
98
                      {pass "attach to nonsense is prohibited"}
99
      -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
100
                      {
101
                        # Response expected from /proc-based systems.
102
                        pass "attach to nonsense is prohibited" 
103
                      }
104
      -re "Attaching to.*$gdb_prompt $"\
105
                      {fail "attach to nonsense is prohibited (bogus pid allowed)"}
106
      -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
107
      timeout         {fail "(timeout) attach to nonsense is prohibited"}
108
   }
109
110
   # Verify that we cannot attach to what appears to be a valid
111
   # process ID, but is a process that doesn't exist.  Traditionally,
112
   # most systems didn't have a process with ID 0, so we take that as
113
   # the default.  However, there are a few exceptions.
114
   #
115
   set boguspid 0
116
   if { [istarget "*-*-*bsd*"] } {
117
       # In FreeBSD 5.0, PID 0 is used for "swapper".  Use -1 instead
118
       # (which should have the desired effect on any version of
119
       # FreeBSD, and probably other *BSD's too).
120
       set boguspid -1
121
   }
122
   send_gdb "attach $boguspid\n"
123
   gdb_expect {
124
       -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $"\
125
	       {
126
	   # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
127
	   pass "attach to nonexistent process is prohibited"
128
       }
129
       -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $"\
130
	       {
131
	   # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
132
	   pass "attach to nonexistent process is prohibited"
133
       }
134
       -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $"\
135
	       {pass "attach to nonexistent process is prohibited"}
136
       -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $"\
137
	       {pass "attach to nonexistent process is prohibited"}
138
       -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
139
	       {
140
	   # Response expected from /proc-based systems.
141
	   pass "attach to nonexistent process is prohibited"
142
       }
143
       -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
144
       timeout {
145
	   fail "(timeout) attach to nonexistent process is prohibited"
146
       }
147
   }
148
149
   # Verify that we can attach to the process by first giving its
150
   # executable name via the file command, and using attach with
151
   # the process ID.
152
   #
153
   # (Actually, the test system appears to do this automatically
154
   # for us.  So, we must also be prepared to be asked if we want
155
   # to discard an existing set of symbols.)
156
   #
157
   send_gdb "file $binfile\n"
158
   gdb_expect {
159
      -re "Load new symbol table from.*y or n.*$" {
160
         send_gdb "y\n"
161
         gdb_expect {
162
            -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
163
                            {pass "(re)set file, before attach1"}
164
            -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
165
            timeout         {fail "(timeout) (re)set file, before attach1"}
166
         }
167
      }
168
      -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
169
                      {pass "set file, before attach1"}
170
      -re "$gdb_prompt $" {fail "set file, before attach1"}
171
      timeout         {fail "(timeout) set file, before attach1"}
172
   }
173
174
   send_gdb "attach $testpid\n"
175
   gdb_expect {
176
      -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
177
                      {pass "attach1, after setting file"}
178
      -re "$gdb_prompt $" {fail "attach1, after setting file"}
179
      timeout         {fail "(timeout) attach1, after setting file"}
180
   }
181
182
   # Verify that we can "see" the variable "should_exit" in the
183
   # program, and that it is zero.
184
   #
185
   send_gdb "print should_exit\n"
186
   gdb_expect {
187
      -re ".* = 0.*$gdb_prompt $"\
188
                      {pass "after attach1, print should_exit"}
189
      -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
190
      timeout         {fail "(timeout) after attach1, print should_exit"}
191
   }
192
193
   # Detach the process.
194
   #
195
   send_gdb "detach\n"
196
   gdb_expect {
197
      -re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $"\
198
                      {pass "attach1 detach"}
199
      -re "$gdb_prompt $" {fail "attach1 detach"}
200
      timeout         {fail "(timeout) attach1 detach"}
201
   }
202
203
   # Wait a bit for gdb to finish detaching
204
   #
205
   exec sleep 5
206
207
   # Purge the symbols from gdb's brain.  (We want to be certain
208
   # the next attach, which won't be preceded by a "file" command,
209
   # is really getting the executable file without our help.)
210
   #
211
   set old_timeout $timeout
212
   set timeout 15 
213
   send_gdb "file\n"
214
   gdb_expect {
215
      -re ".*gdb internal error.*$" { 
216
          fail "Internal error, prob. Memory corruption" 
217
      }
218
      -re "No executable file now.*Discard symbol table.*y or n.*$" {
219
         send_gdb "y\n"
220
         gdb_expect {
221
            -re "No symbol file now.*$gdb_prompt $"\
222
                            {pass "attach1, purging symbols after detach"}
223
            -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
224
            timeout         {fail "(timeout) attach1, purging symbols after detach"}
225
         }
226
      }
227
      -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
228
      timeout         {
229
          fail "(timeout) attach1, purging file after detach"
230
      }
231
   }
232
   set timeout $old_timeout
233
234
   # Verify that we can attach to the process just by giving the
235
   # process ID.
236
   #
237
   send_gdb "attach $testpid\n"
238
   gdb_expect {
239
      -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
240
                      {pass "attach2"}
241
      -re "$gdb_prompt $" {fail "attach2"}
242
      timeout         {fail "(timeout) attach2"}
243
   }
244
245
   # Verify that we can modify the variable "should_exit" in the
246
   # program.
247
   #
248
   send_gdb "set should_exit=1\n"
249
   gdb_expect {
250
      -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
251
      timeout         {fail "(timeout) after attach2, set should_exit"}
252
   }
253
254
   # Verify that the modification really happened.
255
   #
256
   send_gdb "tbreak 19\n"
257
   gdb_expect {
258
      -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
259
                      {pass "after attach2, set tbreak postloop"}
260
      -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
261
      timeout         {fail "(timeout) after attach2, set tbreak postloop"}
262
   }
263
   send_gdb "continue\n"
264
   gdb_expect {
265
      -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
266
                      {pass "after attach2, reach tbreak postloop"}
267
      -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
268
      timeout         {fail "(timeout) after attach2, reach tbreak postloop"}
269
   }
270
271
   # Allow the test process to exit, to cleanup after ourselves.
272
   #
273
   send_gdb "continue\n"
274
   gdb_expect {
275
      -re "Program exited normally.*$gdb_prompt $"\
276
                      {pass "after attach2, exit"}
277
      -re "$gdb_prompt $" {fail "after attach2, exit"}
278
      timeout         {fail "(timeout) after attach2, exit"}
279
   }
280
281
   # Make sure we don't leave a process around to confuse
282
   # the next test run (and prevent the compile by keeping
283
   # the text file busy), in case the "set should_exit" didn't
284
   # work.
285
   #
286
   remote_exec build "kill -9 ${testpid}"
287
   # Start the program running and then wait for a bit, to be sure
288
   # that it can be attached to.
289
   #
290
   set testpid [eval exec $binfile &]
291
   exec sleep 2
292
293
   # Verify that we can attach to the process, and find its a.out
294
   # when we're cd'd to some directory that doesn't contain the
295
   # a.out.  (We use the source path set by the "dir" command.)
296
   #
297
   send_gdb "dir ${objdir}/${subdir}\n"
298
   gdb_expect {
299
      -re ".*Source directories searched: .*$gdb_prompt $"\
300
                      {pass "set source path"}
301
      -re "$gdb_prompt $" {fail "set source path"}
302
      timeout         {fail "(timeout) set source path"}
303
   }
304
305
   send_gdb "cd /tmp\n"
306
   gdb_expect {
307
      -re ".*Working directory /tmp.*$gdb_prompt $"\
308
                      {pass "cd away from process' a.out"}
309
      -re "$gdb_prompt $" {fail "cd away from process' a.out"}
310
      timeout         {fail "(timeout) cd away from process' a.out"}
311
   }
312
313
   # Explicitly flush out any knowledge of the previous attachment.
314
   send_gdb "symbol\n"
315
   gdb_expect {
316
      -re ".*Discard symbol table from.*y or n. $"\
317
                      {send_gdb "y\n"
318
                       gdb_expect {
319
                          -re ".*No symbol file now.*$gdb_prompt $"\
320
                                          {pass "before attach3, flush symbols"}
321
                          -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
322
                          timeout         {fail "(timeout) before attach3, flush symbols"}
323
                       }
324
                      }
325
      -re ".*No symbol file now.*$gdb_prompt $"\
326
                      {pass "before attach3, flush symbols"}
327
      -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
328
      timeout         {fail "(timeout) before attach3, flush symbols"}
329
   }
330
   send_gdb "exec\n"
331
   gdb_expect {
332
      -re ".*No executable file now.*$gdb_prompt $"\
333
                      {pass "before attach3, flush exec"}
334
      -re "$gdb_prompt $" {fail "before attach3, flush exec"}
335
      timeout         {fail "(timeout) before attach3, flush exec"}
336
   }
337
338
   send_gdb "attach $testpid\n"
339
   gdb_expect {
340
      -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
341
                      {pass "attach when process' a.out not in cwd"}
342
      -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
343
      timeout         {fail "(timeout) attach when process' a.out not in cwd"}
344
   }
345
346
   send_gdb "kill\n"
347
   gdb_expect {
348
      -re ".*Kill the program being debugged.*y or n. $"\
349
                      {send_gdb "y\n"
350
                       gdb_expect {
351
                          -re "$gdb_prompt $" {pass "after attach3, exit"}
352
                          timeout {fail "(timeout) after attach3, exit"}
353
                       }
354
                      }
355
      -re "$gdb_prompt $" {fail "after attach3, exit"}
356
      timeout         {fail "(timeout) after attach3, exit"}
357
   }
358
359
   # Another "don't leave a process around"
360
   remote_exec build "kill -9 ${testpid}"
361
}
362
363
proc do_call_attach_tests {} {
364
   global gdb_prompt
365
   global binfile2
366
367
   # Start the program running and then wait for a bit, to be sure
368
   # that it can be attached to.
369
   #
370
   set testpid [eval exec $binfile2 &]
371
   exec sleep 2
372
373
   # Attach
374
   #
375
   gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
376
   send_gdb "attach $testpid\n"
377
   gdb_expect {
378
      -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
379
         fail "attach call, read register 3 error"
380
     }
381
     -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
382
         pass "attach call"
383
     }
384
      -re "$gdb_prompt $" {fail "attach call"}
385
      timeout         {fail "(timeout) attach call"}
386
   }
387
388
   # See if other registers are problems
389
   #
390
   send_gdb "i r r3\n"
391
   gdb_expect {
392
       -re ".*warning: reading register.*$gdb_prompt $" {
393
           pass "CHFts23490: known bug"
394
       }
395
       -re ".*r3.*$gdb_prompt $" {
396
           pass "Bug fixed, Yayyy!"
397
       }
398
       timeout { fail "timeout on info reg" }
399
   }
400
401
   # Get rid of the process
402
   #
403
   gdb_test "p should_exit = 1" ".*"
404
   gdb_test "c" ".*Program exited normally.*"
405
   
406
   # Be paranoid
407
   #
408
    remote_exec build "kill -9 ${testpid}"
409
410
}
411
412
413
# Start with a fresh gdb
414
#
415
gdb_exit
416
gdb_start
417
gdb_reinitialize_dir $srcdir/$subdir
418
gdb_load ${binfile}
419
420
# This is a test of gdb's ability to attach to a running process.
421
#
422
do_attach_tests
423
424
# Test attaching when the target is inside a system call
425
#
426
gdb_exit
427
gdb_start
428
429
gdb_reinitialize_dir $srcdir/$subdir
430
do_call_attach_tests
431
432
return 0
(-)gdb-6.8/gdb/testsuite/gdb.pie/attach2.c (+24 lines)
Added Link Here
1
/* This program is intended to be started outside of gdb, and then
2
   attached to by gdb.  Thus, it simply spins in a loop.  The loop
3
   is exited when & if the variable 'should_exit' is non-zero.  (It
4
   is initialized to zero in this program, so the loop will never
5
   exit unless/until gdb sets the variable to non-zero.)
6
   */
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <unistd.h>
10
11
int  should_exit = 0;
12
13
int main ()
14
{
15
  int  local_i = 0;
16
17
  sleep( 10 ); /* System call causes register fetch to fail */
18
               /* This is a known HPUX "feature"            */
19
  while (! should_exit)
20
    {
21
      local_i++;
22
    }
23
  return (0);
24
}
(-)gdb-6.8/gdb/testsuite/gdb.pie/break.c (+146 lines)
Added Link Here
1
/* This testcase is part of GDB, the GNU debugger.
2
3
   Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003 Free Software
4
   Foundation, Inc.
5
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20
   Please email any bugs, comments, and/or additions to this file to:
21
   bug-gdb@prep.ai.mit.edu  */
22
23
#ifdef vxworks
24
25
#  include <stdio.h>
26
27
/* VxWorks does not supply atoi.  */
28
static int
29
atoi (z)
30
     char *z;
31
{
32
  int i = 0;
33
34
  while (*z >= '0' && *z <= '9')
35
    i = i * 10 + (*z++ - '0');
36
  return i;
37
}
38
39
/* I don't know of any way to pass an array to VxWorks.  This function
40
   can be called directly from gdb.  */
41
42
vxmain (arg)
43
char *arg;
44
{
45
  char *argv[2];
46
47
  argv[0] = "";
48
  argv[1] = arg;
49
  main (2, argv, (char **) 0);
50
}
51
52
#else /* ! vxworks */
53
#  include <stdio.h>
54
#  include <stdlib.h>
55
#endif /* ! vxworks */
56
57
#ifdef PROTOTYPES
58
extern int marker1 (void);
59
extern int marker2 (int a);
60
extern void marker3 (char *a, char *b);
61
extern void marker4 (long d);
62
#else
63
extern int marker1 ();
64
extern int marker2 ();
65
extern void marker3 ();
66
extern void marker4 ();
67
#endif
68
69
/*
70
 *	This simple classical example of recursion is useful for
71
 *	testing stack backtraces and such.
72
 */
73
74
#ifdef PROTOTYPES
75
int factorial(int);
76
77
int
78
main (int argc, char **argv, char **envp)
79
#else
80
int
81
main (argc, argv, envp)
82
int argc;
83
char *argv[], **envp;
84
#endif
85
{
86
#ifdef usestubs
87
    set_debug_traps();  /* set breakpoint 5 here */
88
    breakpoint();
89
#endif
90
    if (argc == 12345) {  /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
91
	fprintf (stderr, "usage:  factorial <number>\n");
92
	return 1;
93
    }
94
    printf ("%d\n", factorial (atoi ("6")));  /* set breakpoint 1 here */
95
    /* set breakpoint 12 here */
96
    marker1 ();  /* set breakpoint 11 here */
97
    marker2 (43); /* set breakpoint 20 here */
98
    marker3 ("stack", "trace"); /* set breakpoint 21 here */
99
    marker4 (177601976L);
100
    argc = (argc == 12345); /* This is silly, but we can step off of it */ /* set breakpoint 2 here */
101
    return argc;  /* set breakpoint 10 here */
102
}
103
104
#ifdef PROTOTYPES
105
int factorial (int value)
106
#else
107
int factorial (value)
108
int value;
109
#endif
110
{
111
  if (value > 1) {  /* set breakpoint 7 here */
112
	value *= factorial (value - 1);
113
    }
114
    return (value); /* set breakpoint 19 here */
115
}
116
117
#ifdef PROTOTYPES
118
int multi_line_if_conditional (int a, int b, int c)
119
#else
120
int multi_line_if_conditional (a, b, c)
121
  int a, b, c;
122
#endif
123
{
124
  if (a    /* set breakpoint 3 here */
125
      && b
126
      && c)
127
    return 0;
128
  else
129
    return 1;
130
}
131
132
#ifdef PROTOTYPES
133
int multi_line_while_conditional (int a, int b, int c)
134
#else
135
int multi_line_while_conditional (a, b, c)
136
  int a, b, c;
137
#endif
138
{
139
  while (a /* set breakpoint 4 here */
140
      && b
141
      && c)
142
    {
143
      a--, b--, c--;
144
    }
145
  return 0;
146
}
(-)gdb-6.8/gdb/testsuite/gdb.pie/break.exp (+973 lines)
Added Link Here
1
#   Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2
#   2000, 2002, 2003, 2004
3
#   Free Software Foundation, Inc.
4
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
# 
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
# 
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
18
19
# Please email any bugs, comments, and/or additions to this file to:
20
# bug-gdb@prep.ai.mit.edu
21
22
# This file was written by Rob Savoye. (rob@cygnus.com)
23
24
# Test the same stuff but with PIE executables
25
26
if $tracelevel then {
27
    strace $tracelevel
28
}
29
30
31
#
32
# test running programs
33
#
34
set prms_id 0
35
set bug_id 0
36
37
set testfile "break"
38
set srcfile ${testfile}.c
39
set srcfile1 ${testfile}1.c
40
set binfile ${objdir}/${subdir}/${testfile}
41
42
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug "additional_flags=-w -fpie -pie"}] != "" } {
43
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44
}
45
46
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug "additional_flags=-w -fpie -pie"}] != "" } {
47
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
48
}
49
50
if  { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug "additional_flags=-w -fpie -pie"}] != "" } {
51
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
52
}
53
54
if [get_compiler_info ${binfile}] {
55
    return -1
56
}
57
58
gdb_exit
59
gdb_start
60
gdb_reinitialize_dir $srcdir/$subdir
61
gdb_load ${binfile}
62
63
if [target_info exists gdb_stub] {
64
    gdb_step_for_stub;
65
}
66
#
67
# test simple breakpoint setting commands
68
#
69
70
# Test deleting all breakpoints when there are none installed,
71
# GDB should not prompt for confirmation.
72
# Note that gdb-init.exp provides a "delete_breakpoints" proc
73
# for general use elsewhere.
74
75
send_gdb "delete breakpoints\n"
76
gdb_expect {
77
     -re "Delete all breakpoints.*$" {
78
	    send_gdb "y\n"
79
	    gdb_expect {
80
		-re "$gdb_prompt $" {
81
		    fail "Delete all breakpoints when none (unexpected prompt)"
82
		}
83
		timeout	{ fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
84
	    }
85
	}
86
     -re ".*$gdb_prompt $"       { pass "Delete all breakpoints when none" }
87
    timeout	            { fail "Delete all breakpoints when none (timeout)" }
88
}
89
90
#
91
# test break at function
92
#
93
gdb_test "break main" \
94
    "Breakpoint.*at.* file .*$srcfile, line.*" \
95
    "breakpoint function"
96
97
#
98
# test break at quoted function
99
#
100
gdb_test "break \"marker2\"" \
101
    "Breakpoint.*at.* file .*$srcfile1, line.*" \
102
    "breakpoint quoted function"
103
104
#
105
# test break at function in file
106
#
107
gdb_test "break $srcfile:factorial" \
108
    "Breakpoint.*at.* file .*$srcfile, line.*" \
109
    "breakpoint function in file"
110
111
set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
112
113
#
114
# test break at line number
115
#
116
# Note that the default source file is the last one whose source text
117
# was printed.  For native debugging, before we've executed the
118
# program, this is the file containing main, but for remote debugging,
119
# it's wherever the processor was stopped when we connected to the
120
# board.  So, to be sure, we do a list command.
121
#
122
gdb_test "list main" \
123
    ".*main \\(argc, argv, envp\\).*" \
124
    "use `list' to establish default source file"
125
gdb_test "break $bp_location1" \
126
    "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
127
    "breakpoint line number"
128
129
#
130
# test duplicate breakpoint
131
#
132
gdb_test "break $bp_location1" \
133
    "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
134
    "breakpoint duplicate"
135
136
set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
137
138
#
139
# test break at line number in file
140
#
141
gdb_test "break $srcfile:$bp_location2" \
142
    "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
143
    "breakpoint line number in file"
144
145
set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
146
set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
147
148
#
149
# Test putting a break at the start of a multi-line if conditional.
150
# Verify the breakpoint was put at the start of the conditional.
151
#
152
gdb_test "break multi_line_if_conditional" \
153
    "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
154
    "breakpoint at start of multi line if conditional"
155
156
gdb_test "break multi_line_while_conditional" \
157
    "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
158
    "breakpoint at start of multi line while conditional"
159
160
set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
161
set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
162
163
#
164
# check to see what breakpoints are set
165
#
166
if [target_info exists gdb_stub] {
167
    set main_line $bp_location5
168
} else {
169
    set main_line $bp_location6
170
}
171
172
if {$hp_aCC_compiler} {
173
    set proto "\\(int\\)"
174
} else {
175
    set proto ""
176
}
177
178
set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
179
set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
180
set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
181
182
gdb_test "info break" \
183
    "Num Type\[ \]+Disp Enb Address\[ \]+What.*
184
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$main_line.*
185
\[0-9\]+\[\t \]+breakpoint     keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
186
\[0-9\]+\[\t \]+breakpoint     keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
187
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location1.*
188
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location1.*
189
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location2.*
190
\[0-9\]+\[\t \]+breakpoint     keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
191
\[0-9\]+\[\t \]+breakpoint     keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
192
    "breakpoint info"
193
194
# FIXME: The rest of this test doesn't work with anything that can't
195
# handle arguments.
196
# Huh? There doesn't *appear* to be anything that passes arguments
197
# below.
198
if [istarget "mips-idt-*"] then {
199
    return
200
}
201
202
#
203
# run until the breakpoint at main is hit. For non-stubs-using targets.
204
#
205
if ![target_info exists use_gdb_stub] {
206
  if [istarget "*-*-vxworks*"] then {
207
    send_gdb "run vxmain \"2\"\n"
208
    set timeout 120
209
    verbose "Timeout is now $timeout seconds" 2
210
  } else {
211
	send_gdb "run\n"
212
  }
213
  gdb_expect {
214
    -re "The program .* has been started already.*y or n. $" {
215
	send_gdb "y\n"
216
	exp_continue
217
    }
218
    -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
219
	                    { pass "run until function breakpoint" }
220
    -re ".*$gdb_prompt $"       { fail "run until function breakpoint" }
221
    timeout	            { fail "run until function breakpoint (timeout)" }
222
  }
223
} else {
224
    if ![target_info exists gdb_stub] {
225
	gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
226
    }
227
}
228
229
#
230
# run until the breakpoint at a line number
231
#
232
gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
233
			"run until breakpoint set at a line number"
234
235
#
236
# Run until the breakpoint set in a function in a file
237
#
238
for {set i 6} {$i >= 1} {incr i -1} {
239
	gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
240
			"run until file:function($i) breakpoint"
241
}
242
243
#
244
# Run until the breakpoint set at a quoted function
245
#
246
gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
247
		"run until quoted breakpoint"
248
#
249
# run until the file:function breakpoint at a line number in a file
250
#
251
gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
252
		"run until file:linenum breakpoint"
253
254
# Test break at offset +1
255
set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
256
257
gdb_test "break +1" \
258
    "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
259
    "breakpoint offset +1"
260
261
# Check to see if breakpoint is hit when stepped onto
262
263
gdb_test "step" \
264
    ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
265
    "step onto breakpoint"
266
267
#
268
# delete all breakpoints so we can start over, course this can be a test too
269
#
270
delete_breakpoints
271
272
#
273
# test temporary breakpoint at function
274
#
275
276
gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
277
278
#
279
# test break at function in file
280
#
281
282
gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
283
	"Temporary breakpoint function in file"
284
285
#
286
# test break at line number
287
#
288
send_gdb "tbreak $bp_location1\n"
289
gdb_expect {
290
    -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
291
	-re ".*$gdb_prompt $"   { pass "Temporary breakpoint line number #1" }
292
	timeout	    { fail "breakpoint line number #1 (timeout)" }
293
}
294
295
gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
296
297
#
298
# test break at line number in file
299
#
300
send_gdb "tbreak $srcfile:$bp_location2\n"
301
gdb_expect {
302
    -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
303
	-re ".*$gdb_prompt $"   { pass "Temporary breakpoint line number in file #1" }
304
	timeout	    { fail "Temporary breakpoint line number in file #1 (timeout)" }
305
}
306
307
set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
308
gdb_test  "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
309
310
#
311
# check to see what breakpoints are set (temporary this time)
312
#
313
gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
314
\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
315
\[0-9\]+\[\t \]+breakpoint     del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
316
\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
317
\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
318
\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
319
\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location11.*" \
320
    "Temporary breakpoint info"
321
322
323
#***********
324
325
# Verify that catchpoints for fork, vfork and exec don't trigger
326
# inappropriately.  (There are no calls to those system functions
327
# in this test program.)
328
#
329
if ![runto_main] then { fail "break tests suppressed" }
330
331
send_gdb "catch\n"
332
gdb_expect {
333
  -re "Catch requires an event name.*$gdb_prompt $"\
334
          {pass "catch requires an event name"}
335
  -re "$gdb_prompt $"\
336
          {fail "catch requires an event name"}
337
  timeout {fail "(timeout) catch requires an event name"}
338
}
339
340
341
set name "set catch fork, never expected to trigger"
342
send_gdb "catch fork\n"
343
gdb_expect {
344
  -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
345
          {pass $name}
346
  -re "Catch of fork not yet implemented.*$gdb_prompt $"
347
	  {pass $name}
348
  -re "$gdb_prompt $"
349
          {fail $name}
350
  timeout {fail "(timeout) $name"}
351
}
352
353
354
set name "set catch vfork, never expected to trigger"
355
send_gdb "catch vfork\n"
356
357
# If we are on HP-UX 10.20, we expect an error message to be
358
# printed if we type "catch vfork" at the gdb gdb_prompt.  This is
359
# because on HP-UX 10.20, we cannot catch vfork events.
360
361
if [istarget "hppa*-hp-hpux10.20"] then {
362
    gdb_expect {
363
	-re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
364
		{pass $name}
365
	-re "$gdb_prompt $"
366
		{fail $name}
367
	timeout {fail "(timeout) $name"}
368
    }
369
} else {
370
    gdb_expect {
371
	-re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
372
		{pass $name}
373
	-re "Catch of vfork not yet implemented.*$gdb_prompt $"
374
		{pass $name}
375
	-re "$gdb_prompt $"
376
		{fail $name}
377
	timeout {fail "(timeout) $name"}
378
    }
379
}
380
381
set name "set catch exec, never expected to trigger"
382
send_gdb "catch exec\n"
383
gdb_expect {
384
  -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
385
          {pass $name}
386
  -re "Catch of exec not yet implemented.*$gdb_prompt $"
387
	  {pass $name}
388
  -re "$gdb_prompt $" {fail $name}
389
  timeout {fail "(timeout) $name"}
390
}
391
392
# Verify that GDB responds gracefully when asked to set a breakpoint
393
# on a nonexistent source line.
394
#
395
send_gdb "break 999\n"
396
gdb_expect {
397
  -re "No line 999 in file .*$gdb_prompt $"\
398
          {pass "break on non-existent source line"}
399
  -re "$gdb_prompt $"\
400
          {fail "break on non-existent source line"}
401
  timeout {fail "(timeout) break on non-existent source line"}
402
}
403
404
# Run to the desired default location. If not positioned here, the
405
# tests below don't work.
406
#
407
gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
408
409
410
# Verify that GDB allows one to just say "break", which is treated
411
# as the "default" breakpoint.  Note that GDB gets cute when printing
412
# the informational message about other breakpoints at the same
413
# location.  We'll hit that bird with this stone too.
414
#
415
send_gdb "break\n"
416
gdb_expect {
417
  -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
418
          {pass "break on default location, 1st time"}
419
  -re "$gdb_prompt $"\
420
          {fail "break on default location, 1st time"}
421
  timeout {fail "(timeout) break on default location, 1st time"}
422
}
423
424
send_gdb "break\n"
425
gdb_expect {
426
  -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
427
          {pass "break on default location, 2nd time"}
428
  -re "$gdb_prompt $"\
429
          {fail "break on default location, 2nd time"}
430
  timeout {fail "(timeout) break on default location, 2nd time"}
431
}
432
433
send_gdb "break\n"
434
gdb_expect {
435
  -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
436
          {pass "break on default location, 3rd time"}
437
  -re "$gdb_prompt $"\
438
          {fail "break on default location, 3rd time"}
439
  timeout {fail "(timeout) break on default location, 3rd time"}
440
}
441
442
send_gdb "break\n"
443
gdb_expect {
444
  -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
445
          {pass "break on default location, 4th time"}
446
  -re "$gdb_prompt $"\
447
          {fail "break on default location, 4th time"}
448
  timeout {fail "(timeout) break on default location, 4th time"}
449
}
450
451
# Verify that a "silent" breakpoint can be set, and that GDB is indeed
452
# "silent" about its triggering.
453
#
454
if ![runto_main] then { fail "break tests suppressed" }
455
456
send_gdb "break $bp_location1\n"
457
gdb_expect {
458
  -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
459
          {pass "set to-be-silent break bp_location1"}
460
  -re "$gdb_prompt $"\
461
          {fail "set to-be-silent break bp_location1"}
462
  timeout {fail "(timeout) set to-be-silent break bp_location1"}
463
}
464
465
send_gdb "commands $expect_out(1,string)\n"
466
send_gdb "silent\n"
467
send_gdb "end\n"
468
gdb_expect {
469
  -re ".*$gdb_prompt $"\
470
          {pass "set silent break bp_location1"}
471
  timeout {fail "(timeout) set silent break bp_location1"}
472
}
473
474
send_gdb "info break $expect_out(1,string)\n"
475
gdb_expect {
476
  -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
477
          {pass "info silent break bp_location1"}
478
  -re "$gdb_prompt $"\
479
          {fail "info silent break bp_location1"}
480
  timeout {fail "(timeout) info silent break bp_location1"}
481
}
482
send_gdb "continue\n"
483
gdb_expect {
484
  -re "Continuing.\r\n$gdb_prompt $"\
485
          {pass "hit silent break bp_location1"}
486
  -re "$gdb_prompt $"\
487
          {fail "hit silent break bp_location1"}
488
  timeout {fail "(timeout) hit silent break bp_location1"}
489
}
490
send_gdb "bt\n"
491
gdb_expect {
492
  -re "#0  main .* at .*:$bp_location1.*$gdb_prompt $"\
493
          {pass "stopped for silent break bp_location1"}
494
  -re "$gdb_prompt $"\
495
          {fail "stopped for silent break bp_location1"}
496
  timeout {fail "(timeout) stopped for silent break bp_location1"}
497
}
498
499
# Verify that GDB can at least parse a breakpoint with the
500
# "thread" keyword.  (We won't attempt to test here that a
501
# thread-specific breakpoint really triggers appropriately.
502
# The gdb.threads subdirectory contains tests for that.)
503
#
504
set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
505
send_gdb "break $bp_location12 thread 999\n"
506
gdb_expect {
507
  -re "Unknown thread 999.*$gdb_prompt $"\
508
          {pass "thread-specific breakpoint on non-existent thread disallowed"}
509
  -re "$gdb_prompt $"\
510
          {fail "thread-specific breakpoint on non-existent thread disallowed"}
511
  timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
512
}
513
send_gdb "break $bp_location12 thread foo\n"
514
gdb_expect {
515
  -re "Junk after thread keyword..*$gdb_prompt $"\
516
          {pass "thread-specific breakpoint on bogus thread ID disallowed"}
517
  -re "$gdb_prompt $"\
518
          {fail "thread-specific breakpoint on bogus thread ID disallowed"}
519
  timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
520
}
521
522
# Verify that GDB responds gracefully to a breakpoint command with
523
# trailing garbage.
524
#
525
send_gdb "break $bp_location12 foo\n"
526
gdb_expect {
527
  -re "Junk at end of arguments..*$gdb_prompt $"\
528
          {pass "breakpoint with trailing garbage disallowed"}
529
  -re "$gdb_prompt $"\
530
          {fail "breakpoint with trailing garbage disallowed"}
531
  timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
532
}
533
534
# Verify that GDB responds gracefully to a "clear" command that has
535
# no matching breakpoint.  (First, get us off the current source line,
536
# which we know has a breakpoint.)
537
#
538
send_gdb "next\n"
539
gdb_expect {
540
  -re ".*$gdb_prompt $"\
541
          {pass "step over breakpoint"}
542
  timeout {fail "(timeout) step over breakpoint"}
543
}
544
send_gdb "clear 81\n"
545
gdb_expect {
546
  -re "No breakpoint at 81..*$gdb_prompt $"\
547
          {pass "clear line has no breakpoint disallowed"}
548
  -re "$gdb_prompt $"\
549
          {fail "clear line has no breakpoint disallowed"}
550
  timeout {fail "(timeout) clear line has no breakpoint disallowed"}
551
}
552
send_gdb "clear\n"
553
gdb_expect {
554
  -re "No breakpoint at this line..*$gdb_prompt $"\
555
          {pass "clear current line has no breakpoint disallowed"}
556
  -re "$gdb_prompt $"\
557
          {fail "clear current line has no breakpoint disallowed"}
558
  timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
559
}
560
561
# Verify that we can set and clear multiple breakpoints.
562
#
563
# We don't test that it deletes the correct breakpoints.  We do at
564
# least test that it deletes more than one breakpoint.
565
#
566
gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
567
gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
568
gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
569
570
# Verify that a breakpoint can be set via a convenience variable.
571
#
572
send_gdb "set \$foo=$bp_location11\n"
573
gdb_expect {
574
  -re "$gdb_prompt $"\
575
          {pass "set convenience variable \$foo to bp_location11"}
576
  timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
577
}
578
send_gdb "break \$foo\n"
579
gdb_expect {
580
  -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
581
          {pass "set breakpoint via convenience variable"}
582
  -re "$gdb_prompt $"\
583
          {fail "set breakpoint via convenience variable"}
584
  timeout {fail "(timeout) set breakpoint via convenience variable"}
585
}
586
587
# Verify that GDB responds gracefully to an attempt to set a
588
# breakpoint via a convenience variable whose type is not integer.
589
#
590
send_gdb "set \$foo=81.5\n"
591
gdb_expect {
592
  -re "$gdb_prompt $"\
593
          {pass "set convenience variable \$foo to 81.5"}
594
  timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
595
}
596
send_gdb "break \$foo\n"
597
gdb_expect {
598
  -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
599
          {pass "set breakpoint via non-integer convenience variable disallowed"}
600
  -re "$gdb_prompt $"\
601
          {fail "set breakpoint via non-integer convenience variable disallowed"}
602
  timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
603
}
604
605
# Verify that we can set and trigger a breakpoint in a user-called function.
606
#
607
send_gdb "break marker2\n"
608
gdb_expect {
609
    -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
610
          {pass "set breakpoint on to-be-called function"}
611
  -re "$gdb_prompt $"\
612
          {fail "set breakpoint on to-be-called function"}
613
  timeout {fail "(timeout) set breakpoint on to-be-called function"}
614
}
615
send_gdb "print marker2(99)\n"
616
gdb_expect {
617
  -re "The program being debugged stopped while in a function called from GDB.\r\nWhen the function .marker2$proto. is done executing, GDB will silently\r\nstop .instead of continuing to evaluate the expression containing\r\nthe function call...*$gdb_prompt $"\
618
          {pass "hit breakpoint on called function"}
619
  -re "$gdb_prompt $"\
620
          {fail "hit breakpoint on called function"}
621
  timeout {fail "(timeout) hit breakpoint on called function"}
622
}
623
624
# As long as we're stopped (breakpointed) in a called function,
625
# verify that we can successfully backtrace & such from here.
626
#
627
# In this and the following test, the _sr4export check apparently is needed
628
# for hppa*-*-hpux.
629
#
630
send_gdb "bt\n"
631
gdb_expect {
632
    -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
633
            {pass "backtrace while in called function"}
634
    -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
635
	    {pass "backtrace while in called function"}
636
    -re "$gdb_prompt $"\
637
            {fail "backtrace while in called function"}
638
    timeout {fail "(timeout) backtrace while in called function"}
639
}
640
641
# Return from the called function.  For remote targets, it's important to do
642
# this before runto_main, which otherwise may silently stop on the dummy
643
# breakpoint inserted by GDB at the program's entry point.
644
#
645
send_gdb "finish\n"
646
gdb_expect {
647
    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
648
            {pass "finish from called function"}
649
    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
650
            {pass "finish from called function"}
651
    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
652
            {pass "finish from called function"}
653
    -re "$gdb_prompt $"\
654
            {fail "finish from called function"}
655
    timeout {fail "(timeout) finish from called function"}
656
}
657
658
# Verify that GDB responds gracefully to a "finish" command with
659
# arguments.
660
#
661
if ![runto_main] then { fail "break tests suppressed" }
662
663
send_gdb "finish 123\n"
664
gdb_expect {
665
  -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
666
          {pass "finish with arguments disallowed"}
667
  -re "$gdb_prompt $"\
668
          {fail "finish with arguments disallowed"}
669
  timeout {fail "(timeout) finish with arguments disallowed"}
670
}
671
672
# Verify that GDB responds gracefully to a request to "finish" from
673
# the outermost frame.  On a stub that never exits, this will just
674
# run to the stubs routine, so we don't get this error...  Thus the 
675
# second condition.
676
#
677
678
send_gdb "finish\n"
679
gdb_expect {
680
  -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
681
          {pass "finish from outermost frame disallowed"}
682
  -re "Run till exit from.*\r\n$gdb_prompt $" {
683
     pass "finish from outermost frame disallowed"
684
  }
685
  -re "$gdb_prompt $"\
686
          {fail "finish from outermost frame disallowed"}
687
  timeout {fail "(timeout) finish from outermost frame disallowed"}
688
}
689
690
# Verify that we can explicitly ask GDB to stop on all shared library
691
# events, and that it does so.
692
#
693
if [istarget "hppa*-*-hpux*"] then {
694
  if ![runto_main] then { fail "break tests suppressed" }
695
696
  send_gdb "set stop-on-solib-events 1\n"
697
  gdb_expect {
698
    -re "$gdb_prompt $"\
699
            {pass "set stop-on-solib-events"}
700
    timeout {fail "(timeout) set stop-on-solib-events"}
701
  }
702
703
  send_gdb "run\n"
704
  gdb_expect {
705
    -re ".*Start it from the beginning.*y or n. $"\
706
            {send_gdb "y\n"
707
             gdb_expect {
708
               -re ".*Stopped due to shared library event.*$gdb_prompt $"\
709
                       {pass "triggered stop-on-solib-events"}
710
               -re "$gdb_prompt $"\
711
                       {fail "triggered stop-on-solib-events"}
712
               timeout {fail "(timeout) triggered stop-on-solib-events"}
713
             }
714
            }
715
    -re "$gdb_prompt $"\
716
            {fail "rerun for stop-on-solib-events"}
717
    timeout {fail "(timeout) rerun for stop-on-solib-events"}
718
  }
719
720
  send_gdb "set stop-on-solib-events 0\n"
721
  gdb_expect {
722
    -re "$gdb_prompt $"\
723
            {pass "reset stop-on-solib-events"}
724
    timeout {fail "(timeout) reset stop-on-solib-events"}
725
  }
726
}
727
728
# Hardware breakpoints are unsupported on HP-UX.  Verify that GDB
729
# gracefully responds to requests to create them.
730
#
731
if [istarget "hppa*-*-hpux*"] then {
732
  if ![runto_main] then { fail "break tests suppressed" }
733
734
  send_gdb "hbreak\n"
735
  gdb_expect {
736
    -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
737
            {pass "hw breaks disallowed"}
738
    -re "$gdb_prompt $"\
739
            {fail "hw breaks disallowed"}
740
    timeout {fail "(timeout) hw breaks disallowed"}
741
  }
742
743
  send_gdb "thbreak\n"
744
  gdb_expect {
745
    -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
746
            {pass "temporary hw breaks disallowed"}
747
    -re "$gdb_prompt $"\
748
            {fail "temporary hw breaks disallowed"}
749
    timeout {fail "(timeout) temporary hw breaks disallowed"}
750
  }
751
}
752
753
#********
754
755
756
#
757
# Test "next" over recursive function call.
758
#
759
760
proc test_next_with_recursion {} { 
761
    global gdb_prompt
762
    global decimal
763
    global binfile
764
765
    if [target_info exists use_gdb_stub] {
766
	# Reload the program.
767
	delete_breakpoints
768
	gdb_load ${binfile};
769
    } else {
770
	# FIXME: should be using runto
771
	gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
772
773
	delete_breakpoints
774
    }
775
776
    gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
777
778
    # Run until we call factorial with 6
779
780
    if [istarget "*-*-vxworks*"] then {
781
	send_gdb "run vxmain \"6\"\n"
782
    } else {
783
	gdb_run_cmd
784
    }
785
    gdb_expect {
786
	-re "Break.* factorial .value=6. .*$gdb_prompt $" {}
787
	-re ".*$gdb_prompt $" {
788
	    fail "run to factorial(6)";
789
	    gdb_suppress_tests;
790
	}
791
	timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
792
    }
793
794
    # Continue until we call factorial recursively with 5.
795
796
    if [gdb_test "continue" \
797
	"Continuing.*Break.* factorial .value=5. .*" \
798
	"continue to factorial(5)"] then { gdb_suppress_tests }
799
800
    # Do a backtrace just to confirm how many levels deep we are.
801
802
    if [gdb_test "backtrace" \
803
	"#0\[ \t\]+ factorial .value=5..*" \
804
	"backtrace from factorial(5)"] then { gdb_suppress_tests }
805
806
    # Now a "next" should position us at the recursive call, which
807
    # we will be performing with 4.
808
809
    if [gdb_test "next" \
810
	".* factorial .value - 1.;.*" \
811
	"next to recursive call"] then { gdb_suppress_tests }
812
813
    # Disable the breakpoint at the entry to factorial by deleting them all.
814
    # The "next" should run until we return to the next line from this
815
    # recursive call to factorial with 4.
816
    # Buggy versions of gdb will stop instead at the innermost frame on
817
    # the line where we are trying to "next" to.
818
819
    delete_breakpoints
820
821
    if [istarget "mips*tx39-*"] {
822
	set timeout 60
823
    }
824
    # We used to set timeout here for all other targets as well.  This
825
    # is almost certainly wrong.  The proper timeout depends on the
826
    # target system in use, and how we communicate with it, so there
827
    # is no single value appropriate for all targets.  The timeout
828
    # should be established by the Dejagnu config file(s) for the
829
    # board, and respected by the test suite.
830
    #
831
    # For example, if I'm running GDB over an SSH tunnel talking to a
832
    # portmaster in California talking to an ancient 68k board running
833
    # a crummy ROM monitor (a situation I can only wish were
834
    # hypothetical), then I need a large timeout.  But that's not the
835
    # kind of knowledge that belongs in this file.
836
837
    gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
838
	    "next over recursive call"
839
840
    # OK, we should be back in the same stack frame we started from.
841
    # Do a backtrace just to confirm.
842
843
    set result [gdb_test "backtrace" \
844
	    "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
845
	    "backtrace from factorial(5.1)"]
846
    if { $result != 0 } { gdb_suppress_tests }
847
848
    if [target_info exists gdb,noresults] { gdb_suppress_tests }
849
  gdb_continue_to_end "recursive next test"
850
   gdb_stop_suppressing_tests;
851
}
852
853
test_next_with_recursion
854
855
856
#********
857
858
# build a new file with optimization enabled so that we can try breakpoints
859
# on targets with optimized prologues
860
861
set binfileo2 ${objdir}/${subdir}/${testfile}o2
862
863
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug "additional_flags=-w -O2 -fpie -pie"}] != "" } {
864
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
865
}
866
867
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug "additional_flags=-w -O2 -fpie -pie"}] != "" } {
868
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
869
}
870
871
if  { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug "additional_flags=-w -fpie -pie"}] != "" } {
872
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
873
}
874
875
if [get_compiler_info ${binfileo2}] {
876
    return -1
877
}
878
879
gdb_exit
880
gdb_start
881
gdb_reinitialize_dir $srcdir/$subdir
882
gdb_load ${binfileo2}
883
884
if [target_info exists gdb_stub] {
885
    gdb_step_for_stub;
886
}
887
888
#
889
# test break at function
890
#
891
gdb_test "break main" \
892
    "Breakpoint.*at.* file .*$srcfile, line.*" \
893
    "breakpoint function, optimized file"
894
895
#
896
# test break at function
897
#
898
gdb_test "break marker4" \
899
    "Breakpoint.*at.* file .*$srcfile1, line.*" \
900
    "breakpoint small function, optimized file"
901
902
#
903
# run until the breakpoint at main is hit. For non-stubs-using targets.
904
#
905
if ![target_info exists use_gdb_stub] {
906
  if [istarget "*-*-vxworks*"] then {
907
    send_gdb "run vxmain \"2\"\n"
908
    set timeout 120
909
    verbose "Timeout is now $timeout seconds" 2
910
  } else {
911
	send_gdb "run\n"
912
  }
913
  gdb_expect {
914
    -re "The program .* has been started already.*y or n. $" {
915
	send_gdb "y\n"
916
	exp_continue
917
    }
918
    -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
919
	                    { pass "run until function breakpoint, optimized file" }
920
    -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
921
	                    { pass "run until function breakpoint, optimized file (code motion)" }
922
    -re ".*$gdb_prompt $"       { fail "run until function breakpoint, optimized file" }
923
    timeout	            { fail "run until function breakpoint, optimized file (timeout)" }
924
  }
925
} else {
926
    if ![target_info exists gdb_stub] {
927
	gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
928
    }
929
}
930
931
#
932
# run until the breakpoint at a small function
933
#
934
935
#
936
# Add a second pass pattern.  The behavior differs here between stabs
937
# and dwarf for one-line functions.  Stabs preserves two line symbols
938
# (one before the prologue and one after) with the same line number, 
939
# but dwarf regards these as duplicates and discards one of them.
940
# Therefore the address after the prologue (where the breakpoint is)
941
# has no exactly matching line symbol, and GDB reports the breakpoint
942
# as if it were in the middle of a line rather than at the beginning.
943
944
set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
945
set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
946
send_gdb "continue\n"
947
gdb_expect {
948
    -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
949
	pass "run until breakpoint set at small function, optimized file"
950
    }
951
    -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
952
	pass "run until breakpoint set at small function, optimized file"
953
    }
954
    -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
955
        # marker4() is defined at line 46 when compiled with -DPROTOTYPES
956
	pass "run until breakpoint set at small function, optimized file (line bp_location14)"
957
    }
958
    -re ".*$gdb_prompt " {
959
	fail "run until breakpoint set at small function, optimized file"
960
    }
961
    timeout {
962
	fail "run until breakpoint set at small function, optimized file (timeout)"
963
    }
964
}
965
966
967
# Reset the default arguments for VxWorks
968
if [istarget "*-*-vxworks*"] {
969
    set timeout 10
970
    verbose "Timeout is now $timeout seconds" 2
971
    send_gdb "set args main\n"
972
    gdb_expect -re ".*$gdb_prompt $" {}
973
}
(-)gdb-6.8/gdb/testsuite/gdb.pie/break1.c (+44 lines)
Added Link Here
1
/* This testcase is part of GDB, the GNU debugger.
2
3
   Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003 Free Software
4
   Foundation, Inc.
5
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20
   Please email any bugs, comments, and/or additions to this file to:
21
   bug-gdb@prep.ai.mit.edu  */
22
23
/* The code for this file was extracted from the gdb testsuite
24
   testcase "break.c". */
25
26
/* The following functions do nothing useful.  They are included
27
   simply as places to try setting breakpoints at.  They are
28
   explicitly "one-line functions" to verify that this case works
29
   (some versions of gcc have or have had problems with this).
30
  
31
   These functions are in a separate source file to prevent an
32
   optimizing compiler from inlining them and optimizing them away. */
33
34
#ifdef PROTOTYPES
35
int marker1 (void) { return (0); }	/* set breakpoint 15 here */
36
int marker2 (int a) { return (1); }	/* set breakpoint 8 here */
37
void marker3 (char *a, char *b) {}	/* set breakpoint 17 here */
38
void marker4 (long d) {}		/* set breakpoint 14 here */
39
#else
40
int marker1 () { return (0); }		/* set breakpoint 16 here */
41
int marker2 (a) int a; { return (1); }	/* set breakpoint 9 here */
42
void marker3 (a, b) char *a, *b; {}	/* set breakpoint 18 here */
43
void marker4 (d) long d; {}		/* set breakpoint 13 here */
44
#endif
(-)gdb-6.8/gdb/testsuite/gdb.pie/corefile.exp (+243 lines)
Added Link Here
1
# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
2
# Free Software Foundation, Inc.
3
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
17
18
# Please email any bugs, comments, and/or additions to this file to:
19
# bug-gdb@prep.ai.mit.edu
20
21
# This file was written by Fred Fish. (fnf@cygnus.com)
22
23
if $tracelevel then {
24
	strace $tracelevel
25
}
26
27
set prms_id 0
28
set bug_id 0
29
30
# are we on a target board
31
if ![isnative] then {
32
    return
33
}
34
35
set testfile "coremaker"
36
set srcfile ${testfile}.c
37
set binfile ${objdir}/${subdir}/${testfile}
38
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags=-fpie -pie"}] != "" } {
39
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
40
}
41
42
# Create and source the file that provides information about the compiler
43
# used to compile the test case.
44
if [get_compiler_info ${binfile}] {
45
    return -1;
46
}
47
48
# Create a core file named "corefile" rather than just "core", to
49
# avoid problems with sys admin types that like to regularly prune all
50
# files named "core" from the system.
51
#
52
# Arbitrarily try setting the core size limit to "unlimited" since
53
# this does not hurt on systems where the command does not work and
54
# allows us to generate a core on systems where it does.
55
#
56
# Some systems append "core" to the name of the program; others append
57
# the name of the program to "core"; still others (like Linux, as of
58
# May 2003) create cores named "core.PID".  In the latter case, we
59
# could have many core files lying around, and it may be difficult to
60
# tell which one is ours, so let's run the program in a subdirectory.
61
set found 0
62
set coredir "${objdir}/${subdir}/coredir.[getpid]"
63
file mkdir $coredir
64
catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
65
#      remote_exec host "${binfile}"
66
foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
67
    if [remote_file build exists $i] {
68
	remote_exec build "mv $i ${objdir}/${subdir}/corefile"
69
	set found 1
70
    }
71
}
72
# Check for "core.PID".
73
if { $found == 0 } {
74
    set names [glob -nocomplain -directory $coredir core.*]
75
    if {[llength $names] == 1} {
76
        set corefile [file join $coredir [lindex $names 0]]
77
        remote_exec build "mv $corefile ${objdir}/${subdir}/corefile"
78
        set found 1
79
    }
80
}
81
if { $found == 0 } {
82
    # The braindamaged HPUX shell quits after the ulimit -c above
83
    # without executing ${binfile}.  So we try again without the
84
    # ulimit here if we didn't find a core file above.
85
    # Oh, I should mention that any "braindamaged" non-Unix system has
86
    # the same problem. I like the cd bit too, it's really neat'n stuff.
87
    catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
88
    foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
89
	if [remote_file build exists $i] {
90
	    remote_exec build "mv $i ${objdir}/${subdir}/corefile"
91
	    set found 1
92
	}
93
    }
94
}
95
96
# Try to clean up after ourselves. 
97
remote_file build delete [file join $coredir coremmap.data]
98
remote_exec build "rmdir $coredir"
99
    
100
if { $found == 0  } {
101
    warning "can't generate a core file - core tests suppressed - check ulimit -c"
102
    return 0
103
}
104
105
#
106
# Test that we can simply startup with a "-core=corefile" command line arg
107
# and recognize that the core file is a valid, usable core file.
108
# To do this, we must shutdown the currently running gdb and restart
109
# with the -core args.  We can't use gdb_start because it looks for
110
# the first gdb prompt, and the message we are looking for occurs
111
# before the first prompt.  Also, we can't include GDBFLAGS because
112
# if it is empty, this confuses gdb with an empty argument that it
113
# grumbles about (said grumbling currently being ignored in gdb_start).
114
# **FIXME**
115
#
116
# Another problem is that on some systems (solaris for example), there
117
# is apparently a limit on the length of a fully specified path to 
118
# the coremaker executable, at about 80 chars.  For this case, consider
119
# it a pass, but note that the program name is bad.
120
121
gdb_exit
122
if $verbose>1 then {
123
    send_user "Spawning $GDB -nw $GDBFLAGS -core=$objdir/$subdir/corefile\n"
124
}
125
126
set oldtimeout $timeout
127
set timeout [expr "$timeout + 60"]
128
verbose "Timeout is now $timeout seconds" 2
129
eval "spawn $GDB -nw $GDBFLAGS -core=$objdir/$subdir/corefile"
130
expect {
131
    -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
132
        fail "args: -core=corefile (couldn't find regs)"
133
    }
134
    -re "Core was generated by .*coremaker.*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
135
	pass "args: -core=corefile"
136
    }
137
    -re "Core was generated by .*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
138
	pass "args: -core=corefile (with bad program name)"
139
    }
140
    -re ".*registers from core file: File in wrong format.* $" {
141
	fail "args: -core=corefile (could not read registers from core file)"
142
    }
143
    -re ".*$gdb_prompt $"	{ fail "args: -core=corefile" }
144
    timeout 		{ fail "(timeout) starting with -core" }
145
}
146
147
148
#
149
# Test that startup with both an executable file and -core argument.
150
# See previous comments above, they are still applicable.
151
#
152
153
close;
154
155
if $verbose>1 then {
156
    send_user "Spawning $GDB -nw $GDBFLAGS $binfile -core=$objdir/$subdir/corefile\n"
157
}
158
159
160
eval "spawn $GDB -nw $GDBFLAGS $binfile -core=$objdir/$subdir/corefile";
161
expect {
162
    -re "Core was generated by .*coremaker.*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
163
	pass "args: execfile -core=corefile"
164
    }
165
    -re "Core was generated by .*\r\n\#0  .*\(\).*\r\n$gdb_prompt $"	 {
166
	pass "args: execfile -core=corefile (with bad program name)"
167
    }
168
    -re ".*registers from core file: File in wrong format.* $" {
169
	fail "args: execfile -core=corefile (could not read registers from core file)"
170
    }
171
    -re ".*$gdb_prompt $"	{ fail "args: execfile -core=corefile" }
172
    timeout 		{ fail "(timeout) starting with -core" }
173
}
174
set timeout $oldtimeout
175
verbose "Timeout is now $timeout seconds" 2
176
177
close;
178
179
# Now restart normally.
180
181
gdb_start
182
gdb_reinitialize_dir $srcdir/$subdir
183
gdb_load ${binfile}
184
185
# Test basic corefile recognition via core-file command.
186
187
send_gdb "core-file $objdir/$subdir/corefile\n"
188
gdb_expect {
189
    -re ".* program is being debugged already.*y or n. $" {
190
	# gdb_load may connect us to a gdbserver.
191
	send_gdb "y\n"
192
	exp_continue;
193
    }
194
    -re "Core was generated by .*coremaker.*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
195
	pass "core-file command"
196
    }
197
    -re "Core was generated by .*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
198
	pass "core-file command (with bad program name)"
199
    }
200
    -re ".*registers from core file: File in wrong format.* $" {
201
	fail "core-file command (could not read registers from core file)"
202
    }
203
    -re ".*$gdb_prompt $"	{ fail "core-file command" }
204
    timeout 		{ fail "(timeout) core-file command" }
205
}
206
207
# Test correct mapping of corefile sections by printing some variables.
208
209
gdb_test "print coremaker_data" "\\\$$decimal = 202"
210
gdb_test "print coremaker_bss" "\\\$$decimal = 10"
211
gdb_test "print coremaker_ro" "\\\$$decimal = 201"
212
213
gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
214
215
# Somehow we better test the ability to read the registers out of the core
216
# file correctly.  I don't think the other tests do this.
217
218
gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
219
gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
220
221
# Test ability to read mmap'd data
222
223
gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
224
setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*"
225
set test "accessing mmapped data in core file"
226
gdb_test_multiple "x/8bd buf2" "$test" {
227
    -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
228
	pass "$test"
229
    }
230
    -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
231
	fail "$test (mapping failed at runtime)"
232
    }
233
    -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
234
	fail "$test (mapping address not found in core file)"
235
    }
236
}
237
238
# test reinit_frame_cache
239
240
gdb_load ${binfile}
241
gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(\\).*" "up in corefile.exp (reinit)"
242
243
gdb_test "core" "No core file now."
(-)gdb-6.8/gdb/testsuite/gdb.pie/coremaker.c (+142 lines)
Added Link Here
1
/* Copyright 1992, 1993, 1994, 1995, 1996, 1999
2
   Free Software Foundation, Inc.
3
4
   This file is part of GDB.
5
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or (at
9
   your option) any later version.
10
11
   This program is distributed in the hope that it will be useful, but
12
   WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
   General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 59 Temple Place - Suite 330,
19
   Boston, MA 02111-1307, USA.  */
20
21
/* Simple little program that just generates a core dump from inside some
22
   nested function calls. */
23
24
#include <stdio.h>
25
#include <sys/types.h>
26
#include <fcntl.h>
27
#include <sys/mman.h>
28
#include <signal.h>
29
#include <stdlib.h>
30
#include <unistd.h>
31
32
#ifndef __STDC__
33
#define	const	/**/
34
#endif
35
36
#define MAPSIZE (8 * 1024)
37
38
/* Don't make these automatic vars or we will have to walk back up the
39
   stack to access them. */
40
41
char *buf1;
42
char *buf2;
43
44
int coremaker_data = 1;	/* In Data section */
45
int coremaker_bss;	/* In BSS section */
46
47
const int coremaker_ro = 201;	/* In Read-Only Data section */
48
49
/* Note that if the mapping fails for any reason, we set buf2
50
   to -1 and the testsuite notices this and reports it as
51
   a failure due to a mapping error.  This way we don't have
52
   to test for specific errors when running the core maker. */
53
54
void
55
mmapdata ()
56
{
57
  int j, fd;
58
59
  /* Allocate and initialize a buffer that will be used to write
60
     the file that is later mapped in. */
61
62
  buf1 = (char *) malloc (MAPSIZE);
63
  for (j = 0; j < MAPSIZE; ++j)
64
    {
65
      buf1[j] = j;
66
    }
67
68
  /* Write the file to map in */
69
70
  fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
71
  if (fd == -1)
72
    {
73
      perror ("coremmap.data open failed");
74
      buf2 = (char *) -1;
75
      return;
76
    }
77
  write (fd, buf1, MAPSIZE);
78
79
  /* Now map the file into our address space as buf2 */
80
81
  buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
82
  if (buf2 == (char *) -1)
83
    {
84
      perror ("mmap failed");
85
      return;
86
    }
87
88
  /* Verify that the original data and the mapped data are identical.
89
     If not, we'd rather fail now than when trying to access the mapped
90
     data from the core file. */
91
92
  for (j = 0; j < MAPSIZE; ++j)
93
    {
94
      if (buf1[j] != buf2[j])
95
	{
96
	  fprintf (stderr, "mapped data is incorrect");
97
	  buf2 = (char *) -1;
98
	  return;
99
	}
100
    }
101
}
102
103
void
104
func2 ()
105
{
106
  int coremaker_local[5];
107
  int i;
108
109
#ifdef SA_FULLDUMP
110
  /* Force a corefile that includes the data section for AIX.  */
111
  {
112
    struct sigaction sa;
113
114
    sigaction (SIGABRT, (struct sigaction *)0, &sa);
115
    sa.sa_flags |= SA_FULLDUMP;
116
    sigaction (SIGABRT, &sa, (struct sigaction *)0);
117
  }
118
#endif
119
120
  /* Make sure that coremaker_local doesn't get optimized away. */
121
  for (i = 0; i < 5; i++)
122
    coremaker_local[i] = i;
123
  coremaker_bss = 0;
124
  for (i = 0; i < 5; i++)
125
    coremaker_bss += coremaker_local[i];
126
  coremaker_data = coremaker_ro + 1;
127
  abort ();
128
}
129
130
void
131
func1 ()
132
{
133
  func2 ();
134
}
135
136
int main ()
137
{
138
  mmapdata ();
139
  func1 ();
140
  return 0;
141
}
142

Return to bug 223533