Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-frame.exp
CommitLineData
88b9d363 1# Copyright (C) 2009-2022 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
a2c09bd0
DE
19load_lib gdb-python.exp
20
b4a58790
TT
21standard_testfile
22
5b362f04 23if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
f8f6f20b
TJB
24 return -1
25}
26
f6bbabf0
PM
27# Skip all tests if Python scripting is not enabled.
28if { [skip_python_tests] } { continue }
f8f6f20b
TJB
29
30# The following tests require execution.
31
32if ![runto_main] then {
bc6c7af4 33 fail "can't run to main"
f8f6f20b
TJB
34 return 0
35}
36
dc00d89f
PM
37gdb_breakpoint [gdb_get_line_number "Block break here."]
38gdb_continue_to_breakpoint "Block break here."
39gdb_py_test_silent_cmd "python bf1 = gdb.selected_frame ()" "get frame" 0
40
bea883fd
SCR
41# Test Frame.architecture() method.
42gdb_py_test_silent_cmd "python show_arch_str = gdb.execute(\"show architecture\", to_string=True)" "show arch" 0
8f28f522 43gdb_test "python print (bf1.architecture().name() in show_arch_str)" "True" "test Frame.architecture()"
bea883fd 44
dc00d89f 45# First test that read_var is unaffected by PR 11036 changes.
9325cb04
PK
46gdb_test "python print (bf1.read_var(\"i\"))" "\"stuff\"" "test i"
47gdb_test "python print (bf1.read_var(\"f\"))" "\"foo\"" "test f"
48gdb_test "python print (bf1.read_var(\"b\"))" "\"bar\"" "test b"
dc00d89f
PM
49
50# Test the read_var function in another block other than the current
51# block (in this case, the super block). Test thar read_var is reading
52# the correct variables of i and f but they are the correct value and type.
53gdb_py_test_silent_cmd "python sb = bf1.block().superblock" "get superblock" 0
9325cb04
PK
54gdb_test "python print (bf1.read_var(\"i\", sb))" "1.1.*" "test i = 1.1"
55gdb_test "python print (bf1.read_var(\"i\", sb).type)" "double" "test double i"
56gdb_test "python print (bf1.read_var(\"f\", sb))" "2.2.*" "test f = 2.2"
57gdb_test "python print (bf1.read_var(\"f\", sb).type)" "double" "test double f"
dc00d89f
PM
58
59# And again test another outerblock, this time testing "i" is the
60# correct value and type.
61gdb_py_test_silent_cmd "python sb = sb.superblock" "get superblock" 0
9325cb04
PK
62gdb_test "python print (bf1.read_var(\"i\", sb))" "99" "test i = 99"
63gdb_test "python print (bf1.read_var(\"i\", sb).type)" "int" "test int i"
dc00d89f 64
f8f6f20b
TJB
65gdb_breakpoint "f2"
66gdb_continue_to_breakpoint "breakpoint at f2"
d8e22779
TT
67gdb_py_test_silent_cmd "python bframe = gdb.selected_frame()" \
68 "get bottommost frame" 0
de7ff789 69gdb_test "up" ".*" ""
f8f6f20b
TJB
70
71gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0
72gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
d52b8007
AB
73gdb_py_test_silent_cmd "python f2 = f1.older ()" "get last frame" 0
74
75# Check the Frame.level method.
76gdb_test "python print ('bframe.level = %d' % bframe.level ())" \
77 "bframe\\.level = 0"
78gdb_test "python print ('f0.level = %d' % f0.level ())" \
79 "f0\\.level = 0"
80gdb_test "python print ('f1.level = %d' % f1.level ())" \
81 "f1\\.level = 1"
82gdb_test "python print ('f2.level = %d' % f2.level ())" \
83 "f2\\.level = 2"
f8f6f20b 84
9325cb04 85gdb_test "python print (f1 == gdb.newest_frame())" False \
d8e22779 86 "selected frame -vs- newest frame"
9325cb04 87gdb_test "python print (bframe == gdb.newest_frame())" True \
d8e22779
TT
88 "newest frame -vs- newest frame"
89
9325cb04
PK
90gdb_test "python print ('result = %s' % (f0 == f1))" " = False" "test equality comparison (false)"
91gdb_test "python print ('result = %s' % (f0 == f0))" " = True" "test equality comparison (true)"
92gdb_test "python print ('result = %s' % (f0 != f1))" " = True" "test inequality comparison (true)"
93gdb_test "python print ('result = %s' % (f0 != f0))" " = False" "test inequality comparison (false)"
94gdb_test "python print ('result = %s' % f0.is_valid ())" " = True" "test Frame.is_valid"
95gdb_test "python print ('result = %s' % f0.name ())" " = f2" "test Frame.name"
96gdb_test "python print ('result = %s' % (f0.type () == gdb.NORMAL_FRAME))" " = True" "test Frame.type"
7f99d636
AB
97gdb_test "python print ('result = %s' % (f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON))" \
98 " = True" "test Frame.unwind_stop_reason"
9325cb04
PK
99gdb_test "python print ('result = %s' % gdb.frame_stop_reason_string (gdb.FRAME_UNWIND_INNER_ID))" " = previous frame inner to this frame \\(corrupt stack\\?\\)" "test gdb.frame_stop_reason_string"
100gdb_test "python print ('result = %s' % f0.pc ())" " = \[0-9\]+" "test Frame.pc"
101gdb_test "python print ('result = %s' % (f0.older () == f1))" " = True" "test Frame.older"
102gdb_test "python print ('result = %s' % (f1.newer () == f0))" " = True" "test Frame.newer"
103gdb_test "python print ('result = %s' % f0.read_var ('variable_which_surely_doesnt_exist'))" \
044c0f87 104 "ValueError: Variable 'variable_which_surely_doesnt_exist' not found.*Error while executing Python code." \
f8f6f20b 105 "test Frame.read_var - error"
9325cb04 106gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.read_var - success"
f8f6f20b 107
9325cb04 108gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame"
5f3b99cf
SS
109
110# Can read SP register.
111gdb_test "python print ('result = %s' % (gdb.selected_frame ().read_register ('sp') == gdb.parse_and_eval ('\$sp')))" \
112 " = True" \
113 "test Frame.read_register(sp)"
114
115# PC value obtained via read_register is as expected.
116gdb_test "python print ('result = %s' % (f0.read_register('pc') == f0.pc()))" \
117 " = True" \
118 "test Frame.read_register(pc)"
119
7e67715d
JK
120# Test arch-specific register name.
121set pc ""
122if {[is_amd64_regs_target]} {
123 set pc "rip"
124} elseif {[is_x86_like_target]} {
125 set pc "eip"
126}
127if { $pc != "" } {
128 gdb_test "python print ('result = %s' % (f0.read_register('pc') == f0.read_register('$pc')))" \
5f3b99cf 129 " = True" \
7e67715d 130 "test Frame.read_register($pc)"
5f3b99cf 131}
This page took 1.483593 seconds and 4 git commands to generate.