]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-connection-removed.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-connection-removed.exp
1 # Copyright (C) 2022-2023 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 # Check that the gdb.connect_removed event triggers when we expect it
17 # too.
18 #
19 # Checking this event has wider implications that simply some corner
20 # of the Python API working or not. The connection_removed event
21 # triggers when the reference count of a process_stratum_target
22 # reaches zero. If these events stop triggering when expected then
23 # GDB might be getting the reference counting on target_ops objects
24 # wrong.
25
26 load_lib gdb-python.exp
27
28 standard_testfile py-connection.c
29
30 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
31 return -1
32 }
33
34 # Skip all tests if Python scripting is not enabled.
35 if { [skip_python_tests] } { continue }
36
37 if ![runto_main] then {
38 return 0
39 }
40
41 # Register a callback that will trigger when a connection is removed
42 # (deleted) within GDB.
43 gdb_test_multiline "Add connection_removed event" \
44 "python" "" \
45 "def connection_removed_handler(event):" "" \
46 " num = event.connection.num" "" \
47 " type = event.connection.type" "" \
48 " print('Connection %d (%s) removed' % (num, type))" "" \
49 "gdb.events.connection_removed.connect (connection_removed_handler)" "" \
50 "end" ""
51
52 if { [target_info exists gdb_protocol] } {
53 if { [target_info gdb_protocol] == "extended-remote" } {
54 set connection_type "extended-remote"
55 } else {
56 set connection_type "remote"
57 }
58 } else {
59 set connection_type "native"
60 }
61
62 # Add an inferior that shares a connection with inferior 1.
63 gdb_test "add-inferior" "Added inferior 2 on connection 1 \[^\r\n\]+"
64
65 # Add an inferior with no connection.
66 gdb_test "add-inferior -no-connection" "Added inferior 3"
67
68 # Kill the first inferior. If we are using the plain 'remote' protocol then
69 # it as this point that the remote target connection is removed. For the
70 # 'extended-remote' and 'native' targets the connection is removed later.
71 if { $connection_type == "remote" } {
72 gdb_test "with confirm off -- kill" \
73 "Connection 1 \\(remote\\) removed\r\n.*" "kill inferior"
74 } else {
75 gdb_test "with confirm off -- kill" "" "kill inferior"
76 }
77
78 # Switch to inferior 3 (the one with no connection).
79 gdb_test "inferior 3"
80
81 # Remove inferior 1, not expecting anything interesting at this point.
82 gdb_test_no_output "remove-inferiors 1"
83
84 # Now removed inferior 2. For the 'remote' target the connection has
85 # already been removed (see above), but for 'extended-remote' and 'native'
86 # targets, it is at this point that the connection is removed.
87 if { $connection_type == "remote" } {
88 gdb_test_no_output "remove-inferiors 2"
89 } else {
90 gdb_test "remove-inferiors 2" \
91 "Connection 1 \\(${connection_type}\\) removed"
92 }