]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2010-2024 Free Software Foundation, Inc. |
fa33c3cd DE |
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 program space | |
17 | # support in Python. | |
18 | ||
02be9a71 DE |
19 | load_lib gdb-python.exp |
20 | ||
d82e5429 | 21 | require allow_python_tests |
79749205 | 22 | |
b4a58790 TT |
23 | standard_testfile |
24 | ||
25 | if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { | |
fa33c3cd DE |
26 | return -1 |
27 | } | |
28 | ||
9b2234b0 | 29 | clean_restart |
fa33c3cd | 30 | |
9325cb04 | 31 | gdb_test "python print (gdb.current_progspace().filename)" "None" \ |
fa33c3cd | 32 | "current progspace filename (None)" |
5ce85461 AB |
33 | gdb_test "python print (gdb.current_progspace().symbol_file)" "None" \ |
34 | "current progspace symbol_file is None" | |
9325cb04 | 35 | gdb_test "python print (gdb.progspaces())" "\\\[<gdb.Progspace object at $hex>\\\]" |
fa33c3cd | 36 | |
0f6ed0e0 TT |
37 | gdb_test_no_output "python dir(gdb.current_progspace())" |
38 | ||
fa33c3cd DE |
39 | gdb_load ${binfile} |
40 | ||
02be9a71 DE |
41 | gdb_py_test_silent_cmd "python progspace = gdb.current_progspace()" \ |
42 | "Get current progspace" 1 | |
43 | ||
44 | gdb_test "python print (progspace.filename)" "py-progspace" \ | |
fa33c3cd | 45 | "current progspace filename (py-progspace)" |
02be9a71 | 46 | |
5ce85461 AB |
47 | gdb_test "python print (gdb.current_progspace().symbol_file)" \ |
48 | "<gdb.Objfile filename=.*/py-progspace>" \ | |
49 | "current progspace symbol_file is set correctly" | |
50 | ||
02be9a71 DE |
51 | gdb_py_test_silent_cmd "python progspace.random_attribute = 42" \ |
52 | "Set random attribute in progspace" 1 | |
53 | gdb_test "python print (progspace.random_attribute)" "42" \ | |
54 | "Verify set of random attribute in progspace" | |
0ae1a321 | 55 | |
2f47f48f AB |
56 | # Check that we can't create new (invalid) gdb.Progspace objects. |
57 | gdb_test "python gdb.Progspace()" \ | |
58 | [multi_line "TypeError: cannot create 'gdb.Progspace' instances" \ | |
59 | "Error while executing Python code\\."] \ | |
60 | "check for error when calling gdb.Progspace() directly" | |
61 | ||
0ae1a321 | 62 | if {![runto_main]} { |
0ae1a321 SM |
63 | return |
64 | } | |
65 | ||
33d569b7 AB |
66 | # Check we can get a block for the current $pc. |
67 | set pc_val [get_integer_valueof "\$pc" 0] | |
68 | gdb_py_test_silent_cmd "python blk = gdb.current_progspace ().block_for_pc (${pc_val})" \ | |
69 | "get block for the current \$pc" 1 | |
d19ca0b3 TT |
70 | gdb_py_test_silent_cmd \ |
71 | "python blk = gdb.current_progspace ().block_for_pc (gdb.Value(${pc_val}))" \ | |
72 | "get block for the current \$pc as value" 1 | |
4f22c3f4 | 73 | gdb_test "python print (blk.start <= ${pc_val})" "True" \ |
33d569b7 | 74 | "block start is before \$pc" |
4f22c3f4 | 75 | gdb_test "python print (blk.end >= ${pc_val})" "True" \ |
33d569b7 AB |
76 | "block end is after \$pc" |
77 | ||
78 | # Check what happens when we ask for a block of an invalid address. | |
79 | if ![is_address_zero_readable] { | |
4f22c3f4 | 80 | gdb_test "python print (gdb.current_progspace ().block_for_pc (0))" "None" |
33d569b7 AB |
81 | } |
82 | ||
27b2eff1 TT |
83 | gdb_test "python print(gdb.current_progspace().objfile_for_address(${pc_val}).username)" \ |
84 | ".*py-progspace" \ | |
85 | "objfile for pc" | |
86 | gdb_test "python print(gdb.current_progspace().objfile_for_address(0))" \ | |
87 | "None" \ | |
88 | "no objfile for 0" | |
89 | ||
0ae1a321 SM |
90 | # With a single inferior, progspace.objfiles () and gdb.objfiles () should |
91 | # be identical. | |
92 | gdb_test "python print (progspace.objfiles () == gdb.objfiles ())" "True" | |
93 | ||
94 | gdb_test "add-inferior" | |
95 | gdb_test "inferior 2" | |
96 | ||
97 | gdb_load ${binfile} | |
98 | ||
99 | # With a second (non-started) inferior, we should have a single objfile - the | |
100 | # main one. | |
101 | gdb_test "python print (len (gdb.objfiles ())) == 1" | |
102 | ||
103 | # And the gdb.objfiles() list should now be different from the objfiles of the | |
104 | # prog space of inferior 1. | |
105 | gdb_test "python print (progspace.objfiles () != gdb.objfiles ())" "True" | |
106 | ||
107 | # Delete inferior 2 (and therefore the second progspace), check that the Python | |
108 | # object reacts sensibly. | |
109 | gdb_py_test_silent_cmd "python progspace2 = gdb.current_progspace()" \ | |
110 | "save progspace 2" 1 | |
111 | gdb_test "inferior 1" "Switching to inferior 1.*" | |
112 | gdb_test_no_output "remove-inferiors 2" | |
113 | gdb_test "python print (progspace2.objfiles ())" \ | |
114 | "RuntimeError: Program space no longer exists.*" | |
5ce85461 AB |
115 | |
116 | gdb_test "python print (progspace2.symbol_file)" \ | |
117 | "RuntimeError: Program space no longer exists.*" |