gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / python-frame.exp
CommitLineData
f8f6f20b
TJB
1# Copyright (C) 2009 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
19if $tracelevel then {
20 strace $tracelevel
21}
22
23set testfile "python-frame"
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
49gdb_test_multiple "python print 'hello, world!'" "verify python support" {
50 -re "not supported.*$gdb_prompt $" {
51 unsupported "python support is disabled"
52 return -1
53 }
54 -re "$gdb_prompt $" {}
55}
56
57# The following tests require execution.
58
59if ![runto_main] then {
60 fail "Can't run to main"
61 return 0
62}
63
64gdb_breakpoint "f2"
65gdb_continue_to_breakpoint "breakpoint at f2"
66gdb_test "up" "" ""
67
68gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0
69gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
70
71gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
72gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
18e8c3bc
TT
73gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
74gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
f8f6f20b
TJB
75gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
76gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
77gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
78gdb_test "python print 'result =', f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON" " = True" "test Frame.type"
79gdb_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"
80gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc"
81gdb_test "python print 'result =', f0.older () == f1" " = True" "test Frame.older"
82gdb_test "python print 'result =', f1.newer () == f0" " = True" "test Frame.newer"
83gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_exist')" \
84 "ValueError: variable 'variable_which_surely_doesnt_exist' not found.*Error while executing Python code." \
85 "test Frame.read_var - error"
86gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
87
88gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
This page took 0.051871 seconds and 4 git commands to generate.