]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - 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
1 # Copyright (C) 2010-2024 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 # This file is part of the GDB testsuite. It tests the program space
17 # support in Python.
18
19 load_lib gdb-python.exp
20
21 require allow_python_tests
22
23 standard_testfile
24
25 if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
26 return -1
27 }
28
29 clean_restart
30
31 gdb_test "python print (gdb.current_progspace().filename)" "None" \
32 "current progspace filename (None)"
33 gdb_test "python print (gdb.current_progspace().symbol_file)" "None" \
34 "current progspace symbol_file is None"
35 gdb_test "python print (gdb.progspaces())" "\\\[<gdb.Progspace object at $hex>\\\]"
36
37 gdb_test_no_output "python dir(gdb.current_progspace())"
38
39 gdb_load ${binfile}
40
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" \
45 "current progspace filename (py-progspace)"
46
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
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"
55
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
62 if {![runto_main]} {
63 return
64 }
65
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
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
73 gdb_test "python print (blk.start <= ${pc_val})" "True" \
74 "block start is before \$pc"
75 gdb_test "python print (blk.end >= ${pc_val})" "True" \
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] {
80 gdb_test "python print (gdb.current_progspace ().block_for_pc (0))" "None"
81 }
82
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
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.*"
115
116 gdb_test "python print (progspace2.symbol_file)" \
117 "RuntimeError: Program space no longer exists.*"