1 # Copyright (C) 2023-2024 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 # This file is part of the GDB testsuite. It tests the program space
17 # related events in the Python API.
19 load_lib gdb-python.exp
21 require allow_python_tests
25 if {[prepare_for_testing "preparing" $testfile $srcfile] == -1} {
29 set pyfile [gdb_remote_download host ${srcdir}/${subdir}/py-progspace-events.py]
30 gdb_test_no_output "source ${pyfile}" "load python file"
36 gdb_breakpoint breakpt
38 gdb_continue_to_breakpoint "run to breakpt function"
40 gdb_test_no_output "set detach-on-fork off"
42 # Continue until the parent process forks and a new child is added.
43 # Done this way so we can count the new progspace events; we expect to
45 set new_progspace_event_count 0
46 gdb_test_multiple "continue" "continue until child process appears" {
47 -re "^NewProgspaceEvent: <gdb.Progspace object at $hex>\r\n" {
48 # This is a correctly formed event line.
49 incr new_progspace_event_count
53 -re "^NewProgspaceEvent:\[^\r\n\]+\r\n" {
54 # This is an incorrectly formed event line.
58 -re "^$gdb_prompt $" {
62 -re "^\[^\r\n\]*\r\n" {
67 gdb_assert { $new_progspace_event_count == 1 } \
68 "only a single new progspace event seen"
70 # Switch to inferior 2 and continue until we hit breakpt.
71 gdb_test "inferior 2" "\\\[Switching to inferior 2 .*"
72 gdb_continue_to_breakpoint "run to breakpt in inferior 2"
74 # Let inferior 2 exit. The new program space is not removed at this
79 "\\\[Inferior $decimal \[^\r\n\]+ exited normally\\\]"] \
80 "continue until inferior 2 exits"
82 gdb_test "inferior 1" "\\\[Switching to inferior 1 .*"
84 # Step the inferior. During this process GDB will prune the now
85 # defunct inferior, which deletes its program space, which should
86 # trigger the FreeProgspaceEvent.
88 # However, there is a slight problem. When the target is remote, and
89 # GDB is accessing files using remote fileio, then GDB will attempt to
90 # prune the inferior at a point in time when the remote target is
91 # waiting for a stop reply. Pruning an inferior causes GDB to close
92 # files associated with that inferior.
94 # In non-async mode we can't send fileio packets while waiting for a
95 # stop reply, so the attempts to close files fails, and this shows up
98 # As this error has nothing to do with the feature being tested here,
99 # we just accept the error message, the important part is the
100 # 'FreeProgspaceEvent' string, so long as that appears (just once)
101 # then the test is a success.
104 "warning: cannot close \"\[^\r\n\]+\": Cannot execute this command while the target is running\\." \
105 "Use the \"interrupt\" command to stop the target" \
106 "and then try again\\."]
110 "^FreeProgspaceEvent: <gdb.Progspace object at $hex>(?:\r\n$warning_msg)*" \
111 "do_parent_stuff \\(\\) at \[^\r\n\]+" \
112 "$decimal\\s+\[^\r\n\]+"]
114 # Let this inferior run to completion.
117 # Check the program space events trigger when a new inferior is
118 # manually added and removed.
119 gdb_test "add-inferior" \
121 "^NewProgspaceEvent: <gdb.Progspace object at $hex>" \
122 "\\\[New inferior 3\\\]" \
123 "Added inferior 3\[^\r\n\]*"]
124 gdb_test "remove-inferior 3" \
125 "^FreeProgspaceEvent: <gdb.Progspace object at $hex>"