]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2009-2024 Free Software Foundation, Inc. |
595939de PM |
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 | # This file is part of the GDB testsuite. It tests the mechanism | |
17 | # exposing inferior threads to Python. | |
18 | ||
6c162d5e TT |
19 | load_lib gdb-python.exp |
20 | ||
d82e5429 | 21 | require allow_python_tests |
79749205 | 22 | |
b4a58790 TT |
23 | standard_testfile |
24 | ||
5b362f04 | 25 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { |
595939de PM |
26 | return -1 |
27 | } | |
28 | ||
2a17c803 | 29 | gdb_test_multiline "install new_thread event handler" \ |
7c96f8c1 TT |
30 | "python" "" \ |
31 | "seen_a_thread = False" "" \ | |
32 | "def thread_handler(evt):" "" \ | |
72df4c81 HD |
33 | " if (evt.inferior_thread is not None" "" \ |
34 | " and isinstance (evt.inferior_thread, gdb.InferiorThread)):" "" \ | |
7c96f8c1 TT |
35 | " global seen_a_thread" "" \ |
36 | " seen_a_thread = True" "" \ | |
37 | "gdb.events.new_thread.connect(thread_handler)" "" \ | |
38 | "end" "" | |
39 | ||
595939de PM |
40 | # The following tests require execution. |
41 | ||
b0e16ca5 | 42 | if {![runto_main]} { |
595939de PM |
43 | return 0 |
44 | } | |
45 | ||
7c96f8c1 TT |
46 | gdb_test "python print(seen_a_thread)" "True" |
47 | ||
595939de PM |
48 | # Test basic gdb.Inferior attributes and methods. |
49 | ||
484d8d36 MD |
50 | # Make sure that InferiorThread.inferior returns a new reference (see PR 21213). |
51 | ||
52 | gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 1" 1 | |
53 | gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 2" 1 | |
54 | gdb_test_no_output "python import gc; gc.collect()" "call Python garbage collection" | |
55 | gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 3" 1 | |
56 | gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 4" 1 | |
57 | ||
58 | ||
595939de | 59 | gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1 |
1925bba8 AB |
60 | gdb_test "python print (t0)" \ |
61 | "<gdb.InferiorThread id=${decimal}\\.${decimal} target-id=\"\[^\r\n\]*\">" | |
79bc59cb | 62 | gdb_test "python print ('result = %s' % t0.num)" " = 1" "test InferiorThread.num" |
22a02324 | 63 | gdb_test "python print ('result = %s' % t0.global_num)" " = 1" "test InferiorThread.global_num" |
9325cb04 | 64 | gdb_test "python print ('result = %s' % str (t0.ptid))" " = \\(\[0-9\]+, \[0-9\]+, \[0-9\]+\\)" "test InferiorThread.ptid" |
595939de | 65 | |
76118e16 AB |
66 | # Test the InferiorThread.ptid_string attribute. We don't test the |
67 | # actual string contents as they vary based on target, but we check | |
68 | # that we get back a non-empty string. | |
69 | gdb_test "python print(type(t0.ptid_string))" "<class 'str'>" \ | |
70 | "check that InferiorThread.ptid_string is a string" | |
71 | gdb_test "python print(t0.ptid_string)" ".+" \ | |
72 | "check that InferiorThread.ptid_string is non-empty" | |
73 | ||
84654457 PA |
74 | gdb_py_test_silent_cmd "python i0 = t0.inferior" "test InferiorThread.inferior" 1 |
75 | gdb_test "python print ('result = %s' % i0.num)" " = 1" "test Inferior.num" | |
76 | ||
4694da01 TT |
77 | gdb_py_test_silent_cmd "python name = gdb.selected_thread().name" \ |
78 | "get supplied name of current thread" 1 | |
79 | gdb_py_test_silent_cmd "python gdb.selected_thread().name = 'hibob'" \ | |
80 | "set name of current thread" 1 | |
9325cb04 | 81 | gdb_test "python print (gdb.selected_thread().name)" "hibob" \ |
4694da01 TT |
82 | "check name of current thread" |
83 | gdb_py_test_silent_cmd "python gdb.selected_thread().name = None" \ | |
84 | "reset name of current thread" 1 | |
9325cb04 | 85 | gdb_test "python print (gdb.selected_thread().name == name)" "True" \ |
4694da01 TT |
86 | "check name of current thread again" |
87 | ||
659971cb AB |
88 | gdb_test_no_output "python details = gdb.selected_thread().details" \ |
89 | "record the thread details string" | |
90 | gdb_test "python print(details is None or isinstance(details, str))" "True" \ | |
91 | "check that the details has an acceptable type" | |
92 | ||
9325cb04 PK |
93 | gdb_test "python print ('result = %s' % t0.is_stopped ())" " = True" "test InferiorThread.is_stopped" |
94 | gdb_test "python print ('result = %s' % t0.is_running ())" " = False" "test InferiorThread.is_running" | |
95 | gdb_test "python print ('result = %s' % t0.is_exited ())" " = False" "test InferiorThread.is_exited" | |
29703da4 PM |
96 | |
97 | # Test InferiorThread is_valid. This must always be the last test in | |
98 | # this testcase as it kills the inferior. | |
99 | ||
9325cb04 | 100 | gdb_test "python print ('result = %s' % t0.is_valid ())" " = True" "test InferiorThread.is_valid" |
29703da4 | 101 | gdb_test_no_output "kill inferior 1" "kill inferior 1" |
7f99d636 AB |
102 | gdb_test "python print ('result = %s' % t0.is_valid ())" " = False" \ |
103 | "test InferiorThread.is_valid after thread has been killed" |