]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-progspace.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-progspace.exp
CommitLineData
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
19load_lib gdb-python.exp
20
d82e5429 21require allow_python_tests
79749205 22
b4a58790
TT
23standard_testfile
24
25if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
fa33c3cd
DE
26 return -1
27}
28
9b2234b0 29clean_restart
fa33c3cd 30
9325cb04 31gdb_test "python print (gdb.current_progspace().filename)" "None" \
fa33c3cd 32 "current progspace filename (None)"
5ce85461
AB
33gdb_test "python print (gdb.current_progspace().symbol_file)" "None" \
34 "current progspace symbol_file is None"
9325cb04 35gdb_test "python print (gdb.progspaces())" "\\\[<gdb.Progspace object at $hex>\\\]"
fa33c3cd 36
0f6ed0e0
TT
37gdb_test_no_output "python dir(gdb.current_progspace())"
38
fa33c3cd
DE
39gdb_load ${binfile}
40
02be9a71
DE
41gdb_py_test_silent_cmd "python progspace = gdb.current_progspace()" \
42 "Get current progspace" 1
43
44gdb_test "python print (progspace.filename)" "py-progspace" \
fa33c3cd 45 "current progspace filename (py-progspace)"
02be9a71 46
5ce85461
AB
47gdb_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
51gdb_py_test_silent_cmd "python progspace.random_attribute = 42" \
52 "Set random attribute in progspace" 1
53gdb_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.
57gdb_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 62if {![runto_main]} {
0ae1a321
SM
63 return
64}
65
33d569b7
AB
66# Check we can get a block for the current $pc.
67set pc_val [get_integer_valueof "\$pc" 0]
68gdb_py_test_silent_cmd "python blk = gdb.current_progspace ().block_for_pc (${pc_val})" \
69 "get block for the current \$pc" 1
d19ca0b3
TT
70gdb_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 73gdb_test "python print (blk.start <= ${pc_val})" "True" \
33d569b7 74 "block start is before \$pc"
4f22c3f4 75gdb_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.
79if ![is_address_zero_readable] {
4f22c3f4 80 gdb_test "python print (gdb.current_progspace ().block_for_pc (0))" "None"
33d569b7
AB
81}
82
27b2eff1
TT
83gdb_test "python print(gdb.current_progspace().objfile_for_address(${pc_val}).username)" \
84 ".*py-progspace" \
85 "objfile for pc"
86gdb_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.
92gdb_test "python print (progspace.objfiles () == gdb.objfiles ())" "True"
93
94gdb_test "add-inferior"
95gdb_test "inferior 2"
96
97gdb_load ${binfile}
98
99# With a second (non-started) inferior, we should have a single objfile - the
100# main one.
101gdb_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.
105gdb_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.
109gdb_py_test_silent_cmd "python progspace2 = gdb.current_progspace()" \
110 "save progspace 2" 1
111gdb_test "inferior 1" "Switching to inferior 1.*"
112gdb_test_no_output "remove-inferiors 2"
113gdb_test "python print (progspace2.objfiles ())" \
114 "RuntimeError: Program space no longer exists.*"
5ce85461
AB
115
116gdb_test "python print (progspace2.symbol_file)" \
117 "RuntimeError: Program space no longer exists.*"