Commit | Line | Data |
---|---|---|
0fb0cc75 | 1 | # Copyright 2007, 2008, 2009 Free Software Foundation, Inc. |
4cf31eea JK |
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 | ||
4cf31eea JK |
17 | # Test GDB's internal buffers safety for the GCORE command. |
18 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
23 | set prms_id 0 | |
24 | set bug_id 0 | |
25 | ||
26 | set testfile "gcore-buffer-overflow" | |
27 | set srcfile ${testfile}.c | |
28 | # The ${binfile} basename needs to exceed 80 characters (`sizeof (psargs)') | |
29 | # plus some additional data to overwrite the stack frame. | |
30 | set pattern 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 | |
31 | set binfile ${objdir}/${subdir}/${testfile}-${pattern} | |
32 | ||
33 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
34 | untested gcore.exp | |
35 | return -1 | |
36 | } | |
37 | ||
38 | # Start with a fresh gdb. | |
39 | ||
40 | gdb_exit | |
41 | gdb_start | |
42 | gdb_reinitialize_dir $srcdir/$subdir | |
43 | gdb_load ${binfile} | |
44 | ||
58d69f29 MK |
45 | # Does this gdb support gcore? |
46 | send_gdb "help gcore\n" | |
47 | gdb_expect { | |
48 | -re "Undefined command: .gcore.*$gdb_prompt $" { | |
49 | # gcore command not supported -- nothing to test here. | |
50 | unsupported "gdb does not support gcore on this target" | |
51 | return -1; | |
52 | } | |
53 | -re "Save a core file .*$gdb_prompt $" { | |
54 | pass "help gcore" | |
55 | } | |
56 | -re ".*$gdb_prompt $" { | |
57 | fail "help gcore" | |
58 | } | |
59 | timeout { | |
60 | fail "help gcore (timeout)" | |
61 | } | |
62 | } | |
63 | ||
4cf31eea JK |
64 | gdb_test "set args ${pattern}" \ |
65 | "" \ | |
66 | "Set buffer exceeding arguments" | |
67 | ||
68 | if { ! [ runto_main ] } then { | |
69 | untested gcore-buffer-overflow.exp | |
70 | return -1 | |
71 | } | |
72 | ||
73 | set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore-buffer-overflow.test] | |
74 | ||
75 | set test "save a corefile" | |
76 | gdb_test_multiple "gcore ${objdir}/${subdir}/gcore-buffer-overflow.test" $test { | |
77 | -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" { | |
78 | pass $test | |
79 | } | |
80 | -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { | |
81 | unsupported $test | |
82 | } | |
83 | eof { | |
84 | fail $test | |
85 | } | |
86 | } |