2011-07-26 Pedro Alves <pedro@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sect-cmd.exp
CommitLineData
7b6bb8da 1# Copyright 1997, 1998, 1999, 2003, 2007, 2008, 2009, 2010, 2011
0fb0cc75 2# Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 16
c906108c
SS
17if $tracelevel then {
18 strace $tracelevel
19 }
20
21global usestubs
22
23#
24# test running programs
25#
c906108c
SS
26
27# This test exists solely to exercise the "section" command for
28# code-coverage on HP-UX. (So far as I can tell, the "section"
29# command isn't needed on HP-UX, but probably is for embedded
30# apps.)
31#
32if ![istarget "hppa*-*-hpux*"] then {
33 return
34}
35
aa81e255
JK
36set testfile "sect-cmd"
37set srcfile break.c
38set srcfile1 break1.c
c906108c 39set binfile ${objdir}/${subdir}/${testfile}
850742db 40
fc91c6c2 41if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
b60f0898
JB
42 untested sect-cmd.exp
43 return -1
850742db
MC
44}
45
fc91c6c2 46if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
b60f0898
JB
47 untested sect-cmd.exp
48 return -1
850742db
MC
49}
50
fc91c6c2 51if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
52 untested sect-cmd.exp
53 return -1
c906108c
SS
54}
55
56gdb_exit
57gdb_start
58gdb_reinitialize_dir $srcdir/$subdir
59gdb_load ${binfile}
60
61if ![runto_main] then { fail "section command tests suppressed" }
62
63# Get the $CODE$ section's starting address.
64#
65# (Note that this works for PA32 programs, which use the SOM file
66# format. PA64 uses ELF, and when support for that is added, it's
67# not clear that there'll be a section named "$CODE$" in such
68# programs.)
69#
085dd6e6
JM
70
71set address1 ""
72set address2 ""
c906108c
SS
73send_gdb "info files\n"
74gdb_expect {
085dd6e6
JM
75 -re ".*(0x\[0-9a-fA-F\]*) - (0x\[0-9a-fA-F\]*) is .(CODE|text).*$gdb_prompt $"\
76 {pass "info files"
77 set address1 $expect_out(1,string)
78 set address2 $expect_out(2,string)}
c906108c
SS
79 -re "$gdb_prompt $"\
80 {fail "info files"}
81 timeout {fail "(timeout) info files"}
82}
83
84# Reset the section to that same starting address, which should be
85# harmless (i.e., we just want to exercise the section command).
86#
085dd6e6
JM
87if [istarget "hppa2.0w-*-*"] then {
88 send_gdb "section \.text $address1\n"
89 gdb_expect {
90 -re ".*$address1 \- $address2 is .text.*$gdb_prompt $"\
91 {pass "set section command"}
92 -re "$gdb_prompt $"\
93 {fail "set section command"}
94 timeout {fail "(timeout) set section command"}
95 }
96} else {
97 send_gdb "section \$CODE\$ $address1\n"
98 gdb_expect {
99 -re ".*$address1 \- $address2 is .CODE..*$gdb_prompt $"\
100 {pass "set section command"}
101 -re "$gdb_prompt $"\
102 {fail "set section command"}
103 timeout {fail "(timeout) set section command"}
104 }
c906108c
SS
105}
106
107# Verify that GDB responds gracefully to a non-existent section name.
108#
109send_gdb "section FOOBARBAZ 0x1234\n"
110gdb_expect {
111 -re "Section FOOBARBAZ not found\r\n$gdb_prompt $"\
112 {pass "non-existent section disallowed"}
113 -re "$gdb_prompt $"\
114 {fail "non-existent section disallowed"}
115 timeout {fail "(timeout) non-existent section disallowed"}
116}
117
118# We "happen to know" that GDB uses a fixed size character buffer to
119# parse the section name into, and the buffer is declared to be 100
120# characters in length. Verify that GDB gracefully handles section
121# names longer than that. (The section is also non-existent.)
122#
123send_gdb "section A234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123 0x1234\n"
124gdb_expect {
125 -re "Section A23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 not found\r\n$gdb_prompt $"\
126 {pass "non-existent too-long section disallowed"}
127 -re "$gdb_prompt $"\
128 {fail "non-existent too-long section disallowed"}
129 timeout {fail "(timeout) non-existent too-long section disallowed"}
130}
131
132gdb_exit
133return 0
This page took 1.254056 seconds and 4 git commands to generate.