1 # Copyright
(C
) 2021-2022 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
for testing the gdb.TargetConnection API. This API is
17 # already tested in gdb.multi
/multi
-target
-info-inferiors.exp and
18 # gdb.python
/py
-inferior.exp
, this file just covers some edge cases
19 # that are not tested in other places.
21 load_lib gdb
-python.exp
25 if { [prepare_for_testing
"failed to prepare" ${testfile} ${srcfile}] } {
29 # Skip all tests
if Python scripting is not enabled.
30 if { [skip_python_tests
] } { continue }
32 if ![runto_main
] then {
36 if { [target_info
exists gdb_protocol
] } {
37 set connection_type
"RemoteTargetConnection"
39 set connection_type
"TargetConnection"
42 # Create a gdb.TargetConnection object and check it is initially
44 gdb_test_no_output
"python conn = gdb.selected_inferior().connection"
45 gdb_test
"python print(conn)" \
46 "<gdb.${connection_type} num=1, what=\"\[^\"\]+\">" \
47 "print gdb.${connection_type} while it is still valid"
48 gdb_test
"python print(conn.is_valid())" "True" "is_valid returns True"
50 #
Get the connection again
, and ensure we
get the exact same object.
51 gdb_test_no_output
"python conn2 = gdb.selected_inferior().connection"
52 gdb_test
"python print('Same object: %s' % (conn is conn2))" "True"
54 # Now invalidate the connection
, and ensure that the is_valid method
55 # starts to
return False.
56 gdb_test
"info connections" "\r\n\\* 1 .*" \
57 "info connections while the connection is still around"
58 gdb_test
"with confirm off -- kill" "" "kill inferior"
60 gdb_test
"info connections" "No connections\\." \
61 "info connections now all the connections have gone"
62 gdb_test
"python print(conn)" "<gdb.${connection_type} \\(invalid\\)>" \
63 "print gdb.${connection_type} now its invalid"
64 gdb_test
"python print(conn.is_valid())" "False" "is_valid returns False"
66 # Now check that accessing properties of the invalid connection cases
68 gdb_test
"python print(conn.num)" \
69 "RuntimeError: Connection no longer exists\\.\r\n.*"
70 gdb_test
"python print(conn.type)" \
71 "RuntimeError: Connection no longer exists\\.\r\n.*"
72 gdb_test
"python print(conn.description)" \
73 "RuntimeError: Connection no longer exists\\.\r\n.*"
74 gdb_test
"python print(conn.details)" \
75 "RuntimeError: Connection no longer exists\\.\r\n.*"