]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-block.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-block.exp
CommitLineData
8acc9f48 1# Copyright (C) 2010-2013 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
c45f3c54 23if { [prepare_for_testing ${testfile}.exp ${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 {
31 fail "Can't run to main"
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
41gdb_py_test_silent_cmd "python block = frame.block()" "Get block" 0
9325cb04
PK
42gdb_test "python print (block)" "<gdb.Block object at $hex>" "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"
f3e9a817 46
9df2fbc4
PM
47# Test global/static blocks
48gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
49gdb_py_test_silent_cmd "python block = frame.block()" "Get block" 0
9325cb04
PK
50gdb_test "python print (block.is_global)" "False" "Not a global block"
51gdb_test "python print (block.is_static)" "False" "Not a static block"
9df2fbc4
PM
52gdb_py_test_silent_cmd "python gblock = block.global_block" "Get block" 1
53gdb_py_test_silent_cmd "python sblock = block.static_block" "Get block" 1
9325cb04
PK
54gdb_test "python print (gblock.is_global)" "True" "Is the global block"
55gdb_test "python print (sblock.is_static)" "True" "Is the static block"
9df2fbc4 56
f3e9a817 57# Move up superblock(s) until we reach function block_func.
89493308 58gdb_test_no_output "python block = block.superblock" "Get superblock"
9325cb04 59gdb_test "python print (block.function)" "None" "Second anonymous block"
89493308 60gdb_test_no_output "python block = block.superblock" "Get superblock 2"
9325cb04 61gdb_test "python print (block.function)" "block_func" \
c45f3c54 62 "Print superblock 2 function"
f3e9a817
PM
63
64# Switch frames, then test for main block.
f6978de9 65gdb_test "up" ".*"
c45f3c54
JB
66gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame 2" 0
67gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0
9325cb04 68gdb_test "python print (block)" "<gdb.Block object at $hex>" \
c45f3c54 69 "Check Frame 2's block not None"
9325cb04 70gdb_test "python print (block.function)" "main" "main block"
29703da4
PM
71
72
73# Test Block is_valid. This must always be the last test in this
74# testcase as it unloads the object file.
75delete_breakpoints
76gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
77gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame block" 0
78gdb_py_test_silent_cmd "python block_iter = iter (block)" "Get Frame block" 0
9325cb04 79gdb_test "python print (block.is_valid())" "True" \
29703da4 80 "Check block validity"
9325cb04 81gdb_test "python print (block_iter.is_valid())" "True" \
29703da4
PM
82 "Check block validity"
83gdb_unload
9325cb04 84gdb_test "python print (block.is_valid())" "False" \
29703da4 85 "Check block validity"
9325cb04 86gdb_test "python print (block_iter.is_valid())" "False" \
29703da4 87 "Check block validity"