]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.ada/tasks.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.ada / tasks.exp
CommitLineData
1d506c26 1# Copyright 2009-2024 Free Software Foundation, Inc.
02d9a9ce
JB
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
02d9a9ce 16load_lib "ada.exp"
0a9ccb9d
AB
17load_lib "gdb-guile.exp"
18load_lib "gdb-python.exp"
02d9a9ce 19
74dcf082 20require allow_ada_tests
7a82e903 21
8223e12c 22standard_ada_testfile foo
02d9a9ce 23
02d9a9ce
JB
24if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
25 return -1
26}
27
09050809 28clean_restart ${testfile}
02d9a9ce
JB
29
30set bp_location [gdb_get_line_number "STOP_HERE" ${testdir}/foo.adb]
31runto "foo.adb:$bp_location"
32
33# Make sure that all tasks appear in the "info tasks" listing, and
34# that the active task is the environment task.
35gdb_test "info tasks" \
a8123151
JB
36 [join {" +ID +TID P-ID Pri State +Name" \
37 "\\* +1 .* main_task" \
38 " +2 .* task_list\\(1\\)" \
39 " +3 .* task_list\\(2\\)" \
40 " +4 .* task_list\\(3\\)"} \
02d9a9ce
JB
41 "\r\n"] \
42 "info tasks before inserting breakpoint"
43
0a9ccb9d
AB
44# Confirm that the "info threads" output lines up with the tasks list.
45gdb_test "info threads" \
46 [multi_line \
47 "\\*\\s+1\\s+\[^\r\n\]+\\s\"foo\"\\s\[^\r\n\]+" \
48 "\\s+2\\s+\[^\r\n\]+\\s\"task_list\\(1\\)\"\\s\[^\r\n\]+" \
49 "\\s+3\\s+\[^\r\n\]+\\s\"task_list\\(2\\)\"\\s\[^\r\n\]+" \
50 "\\s+4\\s+\[^\r\n\]+\\s\"task_list\\(3\\)\"\\s\[^\r\n\]+"]
51
980dbf36
AB
52# Check that multiple uses of the 'task' keyword will give an error.
53gdb_test "break break_me task 1 task 3" "You can specify only one task\\."
54gdb_test "watch j task 1 task 3" "You can specify only one task\\."
55
0a9ccb9d
AB
56# Check that attempting to combine 'task' and 'thread' gives an error.
57gdb_test "break break_me task 1 thread 1" \
58 "You can specify only one of thread or task\\."
59gdb_test "break break_me thread 1 task 1" \
60 "You can specify only one of thread or task\\."
b080fe54
AB
61gdb_test "break break_me inferior 1 task 1" \
62 "You can specify only one of inferior or task\\."
0a9ccb9d
AB
63gdb_test "watch j task 1 thread 1" \
64 "You can specify only one of thread or task\\."
65gdb_test "watch j thread 1 task 1" \
66 "You can specify only one of thread or task\\."
67
12ab52e9
PA
68# Insert a breakpoint that should stop only if task 1 stops. Since
69# task 1 never calls break_me, this shouldn't actually ever trigger.
70# The fact that this breakpoint is created _before_ the next one
71# matters. GDB used to have a bug where it would report the first
72# breakpoint in the list that matched the triggered-breakpoint's
73# address, no matter which task it was specific to.
74gdb_test "break break_me task 1" "Breakpoint .* at .*"
f1f517e8
AB
75set bp_number [get_integer_valueof "\$bpnum" "INVALID" \
76 "get number of breakpoint for task 1"]
944b1b18
AB
77gdb_test "info breakpoints" "foo.adb:${decimal}\r\n\\s+stop only in task 1" \
78 "check info breakpoints for task 1 breakpoint"
12ab52e9
PA
79
80# Now, insert a breakpoint that should stop only if task 3 stops, and
f1f517e8
AB
81# extract its number. Use gdb_test here so that we can validate that
82# the 'Breakpoint ... also set at' line correctly includes the task
83# number of the previous breakpoint.
84gdb_test "break break_me task 3" \
85 [multi_line \
86 "Note: breakpoint $bp_number \\(task 1\\) also set at pc $hex\\." \
87 "Breakpoint $decimal at $hex: \[^\r\n\]+"]
88set bp_number [get_integer_valueof "\$bpnum" "INVALID" \
89 "get number of breakpoint for task 3"]
944b1b18
AB
90gdb_test "info breakpoints" "foo.adb:${decimal}\r\n\\s+stop only in task 3" \
91 "check info breakpoints for task 3 breakpoint"
02d9a9ce 92
0a9ccb9d
AB
93# Test the Python API for the breakpoint task attribute.
94if {[allow_python_tests]} {
95 gdb_test_no_output "python bp = gdb.breakpoints()\[$bp_number - 1\]" \
96 "get gdb.Breakpoint from list"
97 gdb_test "python print(bp.task)" "3"
98 gdb_test "python print(bp.thread)" "None"
99 gdb_test "python bp.thread = 1" \
100 [multi_line \
101 "RuntimeError: Cannot set both task and thread attributes\\." \
102 "Error while executing Python code\\."] \
103 "try setting the thread, but expect an error"
104 gdb_test_no_output "python bp.task = None"
105 gdb_test_no_output "python bp.thread = 1"
106 gdb_test "python bp.task = 3" \
107 [multi_line \
108 "RuntimeError: Cannot set both task and thread attributes\\." \
109 "Error while executing Python code\\."] \
110 "try setting the task, but expect an error"
111
112 # Reset the breakpoint to the state required for the rest of this
113 # test.
114 gdb_test_no_output "python bp.thread = None"
115 gdb_test_no_output "python bp.task = 3"
116}
117
118# Test the Guile API for the breakpoint task attribute.
119if {[allow_guile_tests]} {
120 gdb_install_guile_utils
121 gdb_install_guile_module
122
123 gdb_scm_test_silent_cmd "guile (define blist (breakpoints))" \
124 "get breakpoint list"
125 gdb_scm_test_silent_cmd "guile (define bp (list-ref blist (- $bp_number 1)))" \
126 "get <gdb:breakpoint> from list"
127 gdb_test "guile (print (breakpoint-task bp))" "= 3"
128 gdb_test "guile (print (breakpoint-thread bp))" "= #f"
129 gdb_test "guile (set-breakpoint-thread! bp 1)" \
130 [multi_line \
131 "ERROR: In procedure set-breakpoint-thread!:" \
97c19519
AB
132 "(ERROR: )?In procedure gdbscm_set_breakpoint_thread_x:\
133 cannot set both task and thread attributes" \
0a9ccb9d
AB
134 "Error while executing Scheme code."] \
135 "attempt to set thread, but expect an error"
136
137 gdb_scm_test_silent_cmd "guile (set-breakpoint-task! bp #f)" \
138 "clear breakpoint task attribute"
139 gdb_scm_test_silent_cmd "guile (set-breakpoint-thread! bp 1)" \
140 "set breakpoint thread now task is unset"
141 gdb_test "guile (set-breakpoint-task! bp 1)" \
142 [multi_line \
143 "ERROR: In procedure set-breakpoint-task!:" \
97c19519
AB
144 "(ERROR: )?In procedure gdbscm_set_breakpoint_task_x:\
145 cannot set both task and thread attributes" \
0a9ccb9d
AB
146 "Error while executing Scheme code."] \
147 "attempt to set task, but expect an error"
148
149 # Reset the breakpoint to the state required for the rest of this
150 # test.
151 gdb_scm_test_silent_cmd "guile (set-breakpoint-thread! bp #f)" \
152 "clear breakpoint thread attribute"
153 gdb_scm_test_silent_cmd "guile (set-breakpoint-task! bp 3)" \
154 "restore breakpoint task attribute"
155}
156
02d9a9ce
JB
157# Continue to that breakpoint. Task 2 should hit it first, and GDB
158# is expected to ignore that hit and resume the execution. Only then
159# task 3 will hit our breakpoint, and GDB is expected to stop at that
12ab52e9 160# point. Also make sure that GDB reports the correct breakpoint number.
02d9a9ce 161gdb_test "continue" \
12ab52e9 162 ".*Breakpoint $bp_number, foo.break_me \\(\\).*" \
02d9a9ce
JB
163 "continue to breakpoint"
164
165# Check that it is indeed task 3 that hit the breakpoint by checking
166# which is the active task.
167gdb_test "info tasks" \
a8123151
JB
168 [join {" +ID +TID P-ID Pri State +Name" \
169 " +1 .* main_task" \
170 " +2 .* task_list\\(1\\)" \
171 "\\* +3 .* task_list\\(2\\)" \
172 " +4 .* task_list\\(3\\)"} \
02d9a9ce
JB
173 "\r\n"] \
174 "info tasks after hitting breakpoint"
175
176# Now, resume the execution and make sure that GDB does not stop when
177# task 4 hits the breakpoint. Continuing thus results in our program
178# running to completion.
c83d8d32
TT
179set bp_location [gdb_get_line_number "STOP_HERE_2" ${testdir}/foo.adb]
180gdb_breakpoint foo.adb:$bp_location
181gdb_continue_to_breakpoint second ".*foo.adb:$bp_location.*null; -- STOP_HERE_2"
182
183# A regression test for a crash caused by trying to find the thread
184# for a terminated task.
185gdb_test "interpreter-exec mi \"-ada-task-info\"" ".*"