Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-block.exp
CommitLineData
88b9d363 1# Copyright (C) 2010-2022 Free Software Foundation, Inc.
f3e9a817
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 values to Python.
18
a2c09bd0
DE
19load_lib gdb-python.exp
20
b4a58790
TT
21standard_testfile
22
5b362f04 23if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
f3e9a817
PM
24 return -1
25}
26
f3e9a817
PM
27# Skip all tests if Python scripting is not enabled.
28if { [skip_python_tests] } { continue }
29
30if ![runto_main] then {
bc6c7af4 31 fail "can't run to main"
f3e9a817
PM
32 return 0
33}
34
35global hex decimal
36gdb_breakpoint [gdb_get_line_number "Block break here."]
37gdb_continue_to_breakpoint "Block break here."
38
39# Test initial innermost block.
40gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
2cb60e74
AB
41gdb_py_test_silent_cmd "python block = frame.block()" \
42 "Get block, initial innermost block" 0
cdc7edd7
LM
43gdb_test "python print (block)" "<gdb.Block object at $hex>" "check block not None"
44gdb_test "python print (block.function)" "None" "first anonymous block"
45gdb_test "python print (block.start)" "${decimal}" "check start not None"
46gdb_test "python print (block.end)" "${decimal}" "check end not None"
0b27c27d
CB
47gdb_test "python print (block\['f'\].name == 'f')" "True" "check variable access"
48gdb_test "python print (block\['nonexistent'\])" ".*KeyError: 'nonexistent'.*" \
49 "check nonexistent variable"
50gdb_test "python print (block\[42\])" ".*TypeError: Expected a string.*" \
51 "check non-string key"
f3e9a817 52
9df2fbc4
PM
53# Test global/static blocks
54gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
2cb60e74
AB
55gdb_py_test_silent_cmd "python block = frame.block()" \
56 "Get block, frame.block" 0
cdc7edd7
LM
57gdb_test "python print (block.is_global)" "False" "not a global block"
58gdb_test "python print (block.is_static)" "False" "not a static block"
2cb60e74
AB
59gdb_py_test_silent_cmd "python gblock = block.global_block" \
60 "Get block, global_block" 1
61gdb_py_test_silent_cmd "python sblock = block.static_block" \
62 "Get block, static_block" 1
cdc7edd7
LM
63gdb_test "python print (gblock.is_global)" "True" "is the global block"
64gdb_test "python print (sblock.is_static)" "True" "is the static block"
9df2fbc4 65
f3e9a817 66# Move up superblock(s) until we reach function block_func.
9f058c10 67gdb_test_no_output "python block = block.superblock" "get superblock"
cdc7edd7 68gdb_test "python print (block.function)" "None" "second anonymous block"
9f058c10 69gdb_test_no_output "python block = block.superblock" "get superblock 2"
9325cb04 70gdb_test "python print (block.function)" "block_func" \
c45f3c54 71 "Print superblock 2 function"
f3e9a817
PM
72
73# Switch frames, then test for main block.
f6978de9 74gdb_test "up" ".*"
c45f3c54
JB
75gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame 2" 0
76gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0
9325cb04 77gdb_test "python print (block)" "<gdb.Block object at $hex>" \
c45f3c54 78 "Check Frame 2's block not None"
9325cb04 79gdb_test "python print (block.function)" "main" "main block"
29703da4
PM
80
81
82# Test Block is_valid. This must always be the last test in this
83# testcase as it unloads the object file.
84delete_breakpoints
85gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
86gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame block" 0
87gdb_py_test_silent_cmd "python block_iter = iter (block)" "Get Frame block" 0
9325cb04 88gdb_test "python print (block.is_valid())" "True" \
29703da4 89 "Check block validity"
9325cb04 90gdb_test "python print (block_iter.is_valid())" "True" \
2cb60e74 91 "Check block_iter validity"
29703da4 92gdb_unload
9325cb04 93gdb_test "python print (block.is_valid())" "False" \
2cb60e74 94 "Check block validity after unload"
9325cb04 95gdb_test "python print (block_iter.is_valid())" "False" \
2cb60e74 96 "Check block_iter validity after unload"
This page took 1.565672 seconds and 4 git commands to generate.