| 1 | # Copyright 1997-2016 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 3 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, see <http://www.gnu.org/licenses/>. */ |
| 15 | |
| 16 | # |
| 17 | # test running programs |
| 18 | # |
| 19 | |
| 20 | # This test exists solely to exercise the "section" command for |
| 21 | # code-coverage on HP-UX. (So far as I can tell, the "section" |
| 22 | # command isn't needed on HP-UX, but probably is for embedded |
| 23 | # apps.) |
| 24 | # |
| 25 | if ![istarget "hppa*-*-hpux*"] then { |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | set testfile "sect-cmd" |
| 30 | set srcfile break.c |
| 31 | set srcfile1 break1.c |
| 32 | set binfile ${objdir}/${subdir}/${testfile} |
| 33 | |
| 34 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } { |
| 35 | untested "failed to compile" |
| 36 | return -1 |
| 37 | } |
| 38 | |
| 39 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } { |
| 40 | untested "failed to compile" |
| 41 | return -1 |
| 42 | } |
| 43 | |
| 44 | if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } { |
| 45 | untested "failed to compile" |
| 46 | return -1 |
| 47 | } |
| 48 | |
| 49 | gdb_exit |
| 50 | gdb_start |
| 51 | gdb_reinitialize_dir $srcdir/$subdir |
| 52 | gdb_load ${binfile} |
| 53 | |
| 54 | if ![runto_main] then { fail "section command tests suppressed" } |
| 55 | |
| 56 | # Get the $CODE$ section's starting address. |
| 57 | # |
| 58 | # (Note that this works for PA32 programs, which use the SOM file |
| 59 | # format. PA64 uses ELF, and when support for that is added, it's |
| 60 | # not clear that there'll be a section named "$CODE$" in such |
| 61 | # programs.) |
| 62 | # |
| 63 | |
| 64 | set address1 "" |
| 65 | set address2 "" |
| 66 | send_gdb "info files\n" |
| 67 | gdb_expect { |
| 68 | -re ".*(0x\[0-9a-fA-F\]*) - (0x\[0-9a-fA-F\]*) is .(CODE|text).*$gdb_prompt $"\ |
| 69 | {pass "info files" |
| 70 | set address1 $expect_out(1,string) |
| 71 | set address2 $expect_out(2,string)} |
| 72 | -re "$gdb_prompt $"\ |
| 73 | {fail "info files"} |
| 74 | timeout {fail "(timeout) info files"} |
| 75 | } |
| 76 | |
| 77 | # Reset the section to that same starting address, which should be |
| 78 | # harmless (i.e., we just want to exercise the section command). |
| 79 | # |
| 80 | if [istarget "hppa2.0w-*-*"] then { |
| 81 | send_gdb "section \.text $address1\n" |
| 82 | gdb_expect { |
| 83 | -re ".*$address1 \- $address2 is .text.*$gdb_prompt $"\ |
| 84 | {pass "set section command"} |
| 85 | -re "$gdb_prompt $"\ |
| 86 | {fail "set section command"} |
| 87 | timeout {fail "(timeout) set section command"} |
| 88 | } |
| 89 | } else { |
| 90 | send_gdb "section \$CODE\$ $address1\n" |
| 91 | gdb_expect { |
| 92 | -re ".*$address1 \- $address2 is .CODE..*$gdb_prompt $"\ |
| 93 | {pass "set section command"} |
| 94 | -re "$gdb_prompt $"\ |
| 95 | {fail "set section command"} |
| 96 | timeout {fail "(timeout) set section command"} |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | # Verify that GDB responds gracefully to a non-existent section name. |
| 101 | # |
| 102 | send_gdb "section FOOBARBAZ 0x1234\n" |
| 103 | gdb_expect { |
| 104 | -re "Section FOOBARBAZ not found\r\n$gdb_prompt $"\ |
| 105 | {pass "non-existent section disallowed"} |
| 106 | -re "$gdb_prompt $"\ |
| 107 | {fail "non-existent section disallowed"} |
| 108 | timeout {fail "(timeout) non-existent section disallowed"} |
| 109 | } |
| 110 | |
| 111 | # We "happen to know" that GDB uses a fixed size character buffer to |
| 112 | # parse the section name into, and the buffer is declared to be 100 |
| 113 | # characters in length. Verify that GDB gracefully handles section |
| 114 | # names longer than that. (The section is also non-existent.) |
| 115 | # |
| 116 | send_gdb "section A234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123 0x1234\n" |
| 117 | gdb_expect { |
| 118 | -re "Section A23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 not found\r\n$gdb_prompt $"\ |
| 119 | {pass "non-existent too-long section disallowed"} |
| 120 | -re "$gdb_prompt $"\ |
| 121 | {fail "non-existent too-long section disallowed"} |
| 122 | timeout {fail "(timeout) non-existent too-long section disallowed"} |
| 123 | } |
| 124 | |
| 125 | gdb_exit |
| 126 | return 0 |