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