]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame_incremental - gdb/testsuite/gdb.python/py-block.exp
gdb/alpha: Redefine fpcr with fpcr_flags type
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-block.exp
... / ...
CommitLineData
1# Copyright (C) 2010-2025 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 mechanism
17# exposing values to Python.
18
19load_lib gdb-python.exp
20
21require allow_python_tests
22
23standard_testfile
24
25if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
26 return -1
27}
28
29if {![runto_main]} {
30 return 0
31}
32
33global hex decimal
34gdb_breakpoint [gdb_get_line_number "Block break here."]
35gdb_continue_to_breakpoint "Block break here."
36
37# Test initial innermost block.
38gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
39gdb_py_test_silent_cmd "python block = frame.block()" \
40 "Get block, initial innermost block" 0
41gdb_test "python print (block)" "<gdb.Block <anonymous> \{i, f, b\}>" \
42 "check block not None"
43gdb_test "python print (block.function)" "None" "first anonymous block"
44gdb_test "python print (block.start)" "${decimal}" "check start not None"
45gdb_test "python print (block.end)" "${decimal}" "check end not None"
46gdb_test "python print (block\['f'\].name == 'f')" "True" "check variable access"
47gdb_test "python print (block\['nonexistent'\])" ".*KeyError.*: 'nonexistent'.*" \
48 "check nonexistent variable"
49gdb_test "python print (block\[42\])" ".*TypeError.*: Expected a string.*" \
50 "check non-string key"
51
52# Test global/static blocks
53gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
54gdb_py_test_silent_cmd "python block = frame.block()" \
55 "Get block, frame.block" 0
56gdb_test "python print (block.is_global)" "False" "not a global block"
57gdb_test "python print (block.is_static)" "False" "not a static block"
58gdb_py_test_silent_cmd "python gblock = block.global_block" \
59 "Get block, global_block" 1
60gdb_py_test_silent_cmd "python sblock = block.static_block" \
61 "Get block, static_block" 1
62gdb_test "python print (gblock.is_global)" "True" "is the global block"
63gdb_test "python print (sblock.is_static)" "True" "is the static block"
64gdb_test "python print (len(gblock.subblocks) > 0)" "True" \
65 "global block contains at least one block"
66gdb_test "python print (sblock in gblock.subblocks)" "True" \
67 "global block contains at static block"
68
69# Move up superblock(s) until we reach function block_func.
70gdb_test_no_output "python block = block.superblock" "get superblock"
71gdb_test "python print (block.function)" "None" "second anonymous block"
72gdb_test_no_output "python block = block.superblock" "get superblock 2"
73gdb_test "python print (block.function)" "block_func" \
74 "Print superblock 2 function"
75
76# Switch frames, then test block for no_locals_func.
77gdb_test "continue" ".*" "continue to no_locals_func breakpoint"
78gdb_test "up" ".*" "up to no_locals_func"
79gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame 2" 0
80gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0
81gdb_test "python print (repr (block))" "<gdb.Block no_locals_func \{\}>" \
82 "Check block in no_locals_func"
83gdb_test "python print (block.function)" "no_locals_func" \
84 "no_locals_func block"
85
86# Switch frames, then test block for few_locals_func.
87gdb_test "continue" ".*" "continue to few_locals_func breakpoint"
88gdb_test "up" ".*" "up to few_locals_func"
89gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame 2" 0
90gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0
91gdb_test "python print (repr (block))" \
92 "<gdb.Block few_locals_func \{i, j, k, x, y\}>" \
93 "Check block in few_locals_func"
94gdb_test "python print (block.function)" "few_locals_func" \
95 "few_locals_func block"
96
97# Switch frames, then test block for many_locals_func.
98gdb_test "continue" ".*" "continue to many_locals_func breakpoint"
99gdb_test "up" ".*" "up to many_locals_func"
100gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame 2" 0
101gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0
102gdb_test "python print (repr (block))" \
103 "<gdb.Block many_locals_func \{i, j, k, x, y, \\.\\.\\. \\(1 more symbol\\)\}>" \
104 "Check block in many_locals_func"
105gdb_test "python print (block.function)" "many_locals_func" \
106 "many_locals_func block"
107
108# Switch frames, then test for main block.
109gdb_test "up" ".*"
110gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame 2" 0
111gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0
112gdb_test "python print (repr (block))" "<gdb.Block main \{.*\}>" \
113 "Check Frame 2's block not None"
114gdb_test "python print (block.function)" "main" "main block"
115
116# Test Block is_valid. This must always be the last test in this
117# testcase as it unloads the object file.
118delete_breakpoints
119gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
120gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame block" 0
121gdb_py_test_silent_cmd "python block_iter = iter (block)" "Get Frame block" 0
122gdb_test "python print (block.is_valid())" "True" \
123 "Check block validity"
124gdb_test "python print (block_iter.is_valid())" "True" \
125 "Check block_iter validity"
126gdb_test_no_output "python x = hash(block)" "block is hashable"
127gdb_test "python print (type (x))" "<class 'int'>" "block hash is integer"
128gdb_unload
129gdb_test "python print (block.is_valid())" "False" \
130 "Check block validity after unload"
131gdb_test "python print (block_iter.is_valid())" "False" \
132 "Check block_iter validity after unload"
133gdb_test "python print (hash (block) == x)" "True" \
134 "block hash did not change"