PR ld/13287
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-block.exp
CommitLineData
7b6bb8da 1# Copyright (C) 2010, 2011 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
19if $tracelevel then {
20 strace $tracelevel
21}
22
a2c09bd0
DE
23load_lib gdb-python.exp
24
f3e9a817
PM
25set testfile "py-block"
26set srcfile ${testfile}.c
c45f3c54 27if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
f3e9a817
PM
28 return -1
29}
30
f3e9a817
PM
31# Skip all tests if Python scripting is not enabled.
32if { [skip_python_tests] } { continue }
33
34if ![runto_main] then {
35 fail "Can't run to main"
36 return 0
37}
38
39global hex decimal
40gdb_breakpoint [gdb_get_line_number "Block break here."]
41gdb_continue_to_breakpoint "Block break here."
42
43# Test initial innermost block.
44gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
45gdb_py_test_silent_cmd "python block = frame.block()" "Get block" 0
46gdb_test "python print block" "<gdb.Block object at $hex>" "Check block not None"
47gdb_test "python print block.function" "None" "First anonymous block"
48gdb_test "python print block.start" "${decimal}" "Check start not None"
49gdb_test "python print block.end" "${decimal}" "Check end not None"
50
51# Move up superblock(s) until we reach function block_func.
89493308 52gdb_test_no_output "python block = block.superblock" "Get superblock"
f3e9a817 53gdb_test "python print block.function" "None" "Second anonymous block"
89493308 54gdb_test_no_output "python block = block.superblock" "Get superblock 2"
c45f3c54
JB
55gdb_test "python print block.function" "block_func" \
56 "Print superblock 2 function"
f3e9a817
PM
57
58# Switch frames, then test for main block.
f6978de9 59gdb_test "up" ".*"
c45f3c54
JB
60gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame 2" 0
61gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0
62gdb_test "python print block" "<gdb.Block object at $hex>" \
63 "Check Frame 2's block not None"
f3e9a817 64gdb_test "python print block.function" "main" "main block"
29703da4
PM
65
66
67# Test Block is_valid. This must always be the last test in this
68# testcase as it unloads the object file.
69delete_breakpoints
70gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
71gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame block" 0
72gdb_py_test_silent_cmd "python block_iter = iter (block)" "Get Frame block" 0
73gdb_test "python print block.is_valid()" "True" \
74 "Check block validity"
75gdb_test "python print block_iter.is_valid()" "True" \
76 "Check block validity"
77gdb_unload
78gdb_test "python print block.is_valid()" "False" \
79 "Check block validity"
80gdb_test "python print block_iter.is_valid()" "False" \
81 "Check block validity"
This page took 0.20869 seconds and 4 git commands to generate.