1# Copyright 2012-2015 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# Tests for linespec error conditions 17 18standard_testfile 19set exefile $testfile 20 21if {[prepare_for_testing $testfile $exefile $srcfile \ 22 {debug nowarnings}]} { 23 return -1 24} 25 26# Turn off the pending breakpoint queries. 27gdb_test_no_output "set breakpoint pending off" 28 29# Turn off completion limiting 30gdb_test_no_output "set max-completions unlimited" 31 32# We intentionally do not use gdb_breakpoint for these tests. 33 34# Break at 'linespec' and expect the message in ::error_messages indexed by 35# msg_id with the associated args. 36proc test_break {linespec msg_id args} { 37 global error_messages 38 39 gdb_test "break $linespec" [string_to_regexp \ 40 [eval format \$error_messages($msg_id) $args]] 41} 42 43# Common error message format strings. 44array set error_messages { 45 invalid_file "No source file named %s." 46 invalid_function "Function \"%s\" not defined." 47 invalid_var_or_func "Undefined convenience variable or function \"%s\" not defined." 48 invalid_function_f "Function \"%s\" not defined in \"%s\"." 49 invalid_var_or_func_f \ 50 "Undefined convenience variable or function \"%s\" not defined in \"%s\"." 51 invalid_label "No label \"%s\" defined in function \"%s\"." 52 invalid_offset "No line %d in the current file." 53 invalid_offset_f "No line %d in file \"%s\"." 54 unexpected "malformed linespec error: unexpected %s" 55 unexpected_opt "malformed linespec error: unexpected %s, \"%s\"" 56 unmatched_quote "unmatched quote" 57} 58 59# Some commonly used whitespace tests around ':'. 60set spaces [list ":" ": " " :" " : " "\t: " " :\t" "\t:\t" " \t:\t " \ 61 "\t \t:\t \t \t"] 62 63# A list of invalid offsets. 64set invalid_offsets [list -100 +500 1000] 65 66# Try some simple, invalid linespecs involving spaces. 67foreach x $spaces { 68 test_break $x unexpected "colon" 69} 70 71# Test invalid filespecs starting with offset. This is done 72# first so that default offsets are tested. 73foreach x $invalid_offsets { 74 set offset $x 75 76 # Relative offsets are relative to line 16. Adjust 77 # expected offset from error message accordingly. 78 if {[string index $x 0] == "+" || 79 [string index $x 0] == "-"} { 80 incr offset 16 81 } 82 test_break $x invalid_offset $offset 83} 84 85# Test offsets with trailing tokens w/ and w/o spaces. 86foreach x $spaces { 87 test_break "3$x" unexpected "colon" 88 test_break "+10$x" unexpected "colon" 89 test_break "-10$x" unexpected "colon" 90} 91 92foreach x {1 +1 +100 -10} { 93 test_break "3 $x" unexpected_opt "number" $x 94 test_break "+10 $x" unexpected_opt "number" $x 95 test_break "-10 $x" unexpected_opt "number" $x 96} 97 98test_break "3 foo" unexpected_opt "string" "foo" 99test_break "+10 foo" unexpected_opt "string" "foo" 100test_break "-10 foo" unexpected_opt "string" "foo" 101 102# Test invalid linespecs starting with filename. 103foreach x [list "this_file_doesn't_exist.c" \ 104 "this file has spaces.c" \ 105 "\"file::colons.c\"" \ 106 "'file::colons.c'" \ 107 "\"this \"file\" has quotes.c\"" \ 108 "'this \"file\" has quotes.c'" \ 109 "'this 'file' has quotes.c'" \ 110 "\"this 'file' has quotes.c\"" \ 111 "\"spaces: and :colons.c\"" \ 112 "'more: :spaces: :and colons::.c'"] { 113 # Remove any quoting from FILENAME for the error message. 114 test_break "$x:3" invalid_file [string trim $x \"'] 115} 116 117# Test unmatched quotes. 118foreach x {"\"src-file.c'" "'src-file.c"} { 119 test_break "$x:3" unmatched_quote 120} 121 122test_break $srcfile invalid_function $srcfile 123foreach x {"foo" " foo" " foo "} { 124 # Trim any leading/trailing whitespace for error messages. 125 test_break "$srcfile:$x" invalid_function_f [string trim $x] $srcfile 126 test_break "$srcfile:main:$x" invalid_label [string trim $x] "main" 127} 128 129foreach x $spaces { 130 test_break "$srcfile$x" unexpected "end of input" 131 test_break "$srcfile:main$x" unexpected "end of input" 132} 133 134test_break "${srcfile}::" invalid_function "${srcfile}::" 135test_break "$srcfile:3 1" unexpected_opt "number" "1" 136test_break "$srcfile:3 +100" unexpected_opt "number" "+100" 137test_break "$srcfile:3 -100" unexpected_opt "number" "-100" 138test_break "$srcfile:3 foo" unexpected_opt "string" "foo" 139 140foreach x $invalid_offsets { 141 test_break "$srcfile:$x" invalid_offset_f $x $srcfile 142 test_break "\"$srcfile:$x\"" invalid_offset_f $x $srcfile 143 test_break "'$srcfile:$x'" invalid_offset_f $x $srcfile 144} 145 146# Test invalid filespecs starting with function. 147foreach x {"foobar" "foo::bar" "foo.bar" "foo ." "foo bar" "foo 1" \ 148 "foo 0" "foo +10" "foo -10" "foo +100" "foo -100"} { 149 test_break $x invalid_function $x 150} 151 152foreach x $spaces { 153 test_break "main${x}there" invalid_label "there" "main" 154 if {[test_compiler_info {clang-*-*}]} { setup_xfail clang/14500 *-*-* } 155 test_break "main:here${x}" unexpected "end of input" 156} 157 158test_break "main 3" invalid_function "main 3" 159test_break "main +100" invalid_function "main +100" 160test_break "main -100" invalid_function "main -100" 161test_break "main foo" invalid_function "main foo" 162 163foreach x {"3" "+100" "-100" "foo"} { 164 test_break "main:here $x" invalid_label "here $x" "main" 165} 166 167foreach x {"if" "task" "thread"} { 168 test_break $x invalid_function $x 169} 170 171test_break "'main.c'flubber" unexpected_opt "string" "flubber" 172test_break "'main.c',21" invalid_function "main.c" 173test_break "'main.c' " invalid_function "main.c" 174test_break "'main.c'3" unexpected_opt "number" "3" 175test_break "'main.c'+3" unexpected_opt "number" "+3" 176 177# Test undefined convenience variables. 178set x {$zippo} 179test_break $x invalid_var_or_func $x 180test_break "$srcfile:$x" invalid_var_or_func_f $x $srcfile 181