2010-06-08 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-frame.exp
CommitLineData
4c38e0a4 1# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
f8f6f20b
TJB
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
5172aecb 23set testfile "py-frame"
f8f6f20b
TJB
24set srcfile ${testfile}.c
25set binfile ${objdir}/${subdir}/${testfile}
26if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
27 untested "Couldn't compile ${srcfile}"
28 return -1
29}
30
31# Run a command in GDB, and report a failure if a Python exception is thrown.
32# If report_pass is true, report a pass if no exception is thrown.
33proc gdb_py_test_silent_cmd {cmd name report_pass} {
34 global gdb_prompt
35
36 gdb_test_multiple $cmd $name {
37 -re "Traceback.*$gdb_prompt $" { fail $name }
38 -re "$gdb_prompt $" { if $report_pass { pass $name } }
39 }
40}
41
42# Start with a fresh gdb.
43
44gdb_exit
45gdb_start
46gdb_reinitialize_dir $srcdir/$subdir
47gdb_load ${binfile}
48
f6bbabf0
PM
49# Skip all tests if Python scripting is not enabled.
50if { [skip_python_tests] } { continue }
f8f6f20b
TJB
51
52# The following tests require execution.
53
54if ![runto_main] then {
55 fail "Can't run to main"
56 return 0
57}
58
dc00d89f
PM
59gdb_breakpoint [gdb_get_line_number "Block break here."]
60gdb_continue_to_breakpoint "Block break here."
61gdb_py_test_silent_cmd "python bf1 = gdb.selected_frame ()" "get frame" 0
62
63# First test that read_var is unaffected by PR 11036 changes.
64gdb_test "python print bf1.read_var(\"i\")" "\"stuff\"" "test i"
65gdb_test "python print bf1.read_var(\"f\")" "\"foo\"" "test f"
66gdb_test "python print bf1.read_var(\"b\")" "\"bar\"" "test b"
67
68# Test the read_var function in another block other than the current
69# block (in this case, the super block). Test thar read_var is reading
70# the correct variables of i and f but they are the correct value and type.
71gdb_py_test_silent_cmd "python sb = bf1.block().superblock" "get superblock" 0
72gdb_test "python print bf1.read_var(\"i\", sb)" "1.1.*" "test i = 1.1"
73gdb_test "python print bf1.read_var(\"i\", sb).type" "double" "test double i"
74gdb_test "python print bf1.read_var(\"f\", sb)" "2.2.*" "test f = 2.2"
75gdb_test "python print bf1.read_var(\"f\", sb).type" "double" "test double f"
76
77# And again test another outerblock, this time testing "i" is the
78# correct value and type.
79gdb_py_test_silent_cmd "python sb = sb.superblock" "get superblock" 0
80gdb_test "python print bf1.read_var(\"i\", sb)" "99" "test i = 99"
81gdb_test "python print bf1.read_var(\"i\", sb).type" "int" "test int i"
82
f8f6f20b
TJB
83gdb_breakpoint "f2"
84gdb_continue_to_breakpoint "breakpoint at f2"
de7ff789 85gdb_test "up" ".*" ""
f8f6f20b
TJB
86
87gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0
88gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
89
90gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
91gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
18e8c3bc
TT
92gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
93gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
f8f6f20b
TJB
94gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
95gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
96gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
97gdb_test "python print 'result =', f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON" " = True" "test Frame.type"
98gdb_test "python print 'result =', gdb.frame_stop_reason_string (gdb.FRAME_UNWIND_INNER_ID)" " = previous frame inner to this frame \\(corrupt stack\\?\\)" "test gdb.frame_stop_reason_string"
99gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc"
100gdb_test "python print 'result =', f0.older () == f1" " = True" "test Frame.older"
101gdb_test "python print 'result =', f1.newer () == f0" " = True" "test Frame.newer"
102gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_exist')" \
044c0f87 103 "ValueError: Variable 'variable_which_surely_doesnt_exist' not found.*Error while executing Python code." \
f8f6f20b
TJB
104 "test Frame.read_var - error"
105gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
106
107gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
This page took 0.187247 seconds and 4 git commands to generate.