Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.linespec / keywords.exp
blobbff6424954252e748409151e0cb589677a4f97c4
1 # Copyright 2015-2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test keyword parsing in the linespec parser.
18 standard_testfile
19 set exefile $testfile
21 if {[prepare_for_testing "failed to prepare" $exefile $srcfile {debug}]} {
22     return -1
25 if ![runto_main] {
26     return 0
29 # Turn off pending breakpoints to facilitate testing errors.
30 gdb_test_no_output "set breakpoint pending off"
32 # The linespec lexer ignores the language setting when lexing
33 # keywords.
34 gdb_test "break if" "Function \"if\" not defined."
35 gdb_breakpoint "thread" "message"
36 gdb_breakpoint "task" "message"
38 # The lexer should prune any trailing whitesapce, so the expected
39 # outcome of the following tests should be the same as the previous
40 # tests.
41 with_test_prefix "trailing whitespace" {
42     gdb_test "break if " "Function \"if\" not defined."
43     gdb_breakpoint "thread " "message"
44     gdb_breakpoint "task " "message"
47 # With a single keyword specified first in the location,
48 # we assume we have a NULL location, i.e., the actual location
49 # of the event is the current default location.
51 # break if XX --> okay if XX is a valid expression
52 # (the lexer cannot know whether the expression is valid or not)
53 # break {thread,task} NUMBER --> invalid thread/task
54 # break {thread,task} STUFF --> "junk" after keyword (STUFF is not numeric)
55 gdb_test "break thread 123" "Unknown thread 123\\."
56 gdb_test "break thread foo" "Invalid thread ID: foo"
57 gdb_test "break task 123" "Unknown task 123\\."
58 gdb_test "break task foo" "Junk after task keyword\\."
59 gdb_breakpoint "thread if 0" "message"
61 # These are also NULL locations, but using a subsequent keyword
62 # as the "junk".
63 gdb_test "break thread thread" "Invalid thread ID: thread"
64 gdb_test "break thread task" "Invalid thread ID: task"
65 gdb_test "break thread if" "Invalid thread ID: if"
66 gdb_test "break task task" "Junk after task keyword\\."
67 gdb_test "break task thread" "Junk after task keyword\\."
68 gdb_test "break task if" "Junk after task keyword\\."
70 # Test locations containing keyword followed by keyword.
71 gdb_test "break thread thread 123" "Unknown thread 123\\."
72 gdb_test "break task task 123" "Unknown task 123\\."
74 # Test NULL location with valid conditional containing a keyword.
75 gdb_breakpoint "thread if thread == 0"
76 gdb_breakpoint "task if task == 0"
78 # Test the positional flexibility of the "-force-condition" flag.
79 foreach prefix {"" "thread 1 "} {
80     foreach suffix {"" " " " thread 1"} {
81         foreach cond {"" " if 1"} {
82             with_test_prefix "prefix: '$prefix', suffix: '$suffix', cond: '$cond'" {
83                 gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\
84                     "message"
85             }
86         }
87     }