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