1# Copyright 1997, 1998, 1999, 2003, 2007, 2008, 2009, 2010, 2011
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 3 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, see <http://www.gnu.org/licenses/>.  */
16
17if $tracelevel then {
18	strace $tracelevel
19	}
20
21global usestubs
22
23#
24# test running programs
25#
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
36set testfile "sect-cmd"
37set srcfile break.c
38set srcfile1 break1.c
39set binfile ${objdir}/${subdir}/${testfile}
40
41if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
42    untested sect-cmd.exp
43    return -1
44}
45
46if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
47    untested sect-cmd.exp
48    return -1
49}
50
51if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
52    untested sect-cmd.exp
53    return -1
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#
70
71set address1 ""
72set address2 ""
73send_gdb "info files\n"
74gdb_expect {
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)}
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#
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  }
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
134