]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-frame.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-frame.exp
1 # Copyright (C) 2009-2023 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 load_lib gdb-python.exp
20
21 standard_testfile
22
23 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
24 return -1
25 }
26
27 # Skip all tests if Python scripting is not enabled.
28 if { [skip_python_tests] } { continue }
29
30 # The following tests require execution.
31
32 if {![runto_main]} {
33 return 0
34 }
35
36 gdb_breakpoint [gdb_get_line_number "Block break here."]
37 gdb_continue_to_breakpoint "Block break here."
38 gdb_py_test_silent_cmd "python bf1 = gdb.selected_frame ()" "get frame" 0
39
40 # Test Frame.architecture() method.
41 gdb_py_test_silent_cmd "python show_arch_str = gdb.execute(\"show architecture\", to_string=True)" "show arch" 0
42 gdb_test "python print (bf1.architecture().name() in show_arch_str)" "True" "test Frame.architecture()"
43
44 # First test that read_var is unaffected by PR 11036 changes.
45 gdb_test "python print (bf1.read_var(\"i\"))" "\"stuff\"" "test i"
46 gdb_test "python print (bf1.read_var(\"f\"))" "\"foo\"" "test f"
47 gdb_test "python print (bf1.read_var(\"b\"))" "\"bar\"" "test b"
48
49 # Test the read_var function in another block other than the current
50 # block (in this case, the super block). Test thar read_var is reading
51 # the correct variables of i and f but they are the correct value and type.
52 gdb_py_test_silent_cmd "python sb = bf1.block().superblock" "get superblock" 0
53 gdb_test "python print (bf1.read_var(\"i\", sb))" "1.1.*" "test i = 1.1"
54 gdb_test "python print (bf1.read_var(\"i\", sb).type)" "double" "test double i"
55 gdb_test "python print (bf1.read_var(\"f\", sb))" "2.2.*" "test f = 2.2"
56 gdb_test "python print (bf1.read_var(\"f\", sb).type)" "double" "test double f"
57
58 # And again test another outerblock, this time testing "i" is the
59 # correct value and type.
60 gdb_py_test_silent_cmd "python sb = sb.superblock" "get superblock" 0
61 gdb_test "python print (bf1.read_var(\"i\", sb))" "99" "test i = 99"
62 gdb_test "python print (bf1.read_var(\"i\", sb).type)" "int" "test int i"
63
64 gdb_breakpoint "f2"
65 gdb_continue_to_breakpoint "breakpoint at f2"
66 gdb_py_test_silent_cmd "python bframe = gdb.selected_frame()" \
67 "get bottommost frame" 0
68 gdb_test "up" ".*" ""
69
70 gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0
71 gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
72 gdb_py_test_silent_cmd "python f2 = f1.older ()" "get last frame" 0
73
74 # Check the Frame.level method.
75 gdb_test "python print ('bframe.level = %d' % bframe.level ())" \
76 "bframe\\.level = 0"
77 gdb_test "python print ('f0.level = %d' % f0.level ())" \
78 "f0\\.level = 0"
79 gdb_test "python print ('f1.level = %d' % f1.level ())" \
80 "f1\\.level = 1"
81 gdb_test "python print ('f2.level = %d' % f2.level ())" \
82 "f2\\.level = 2"
83
84 gdb_test "python print (f1 == gdb.newest_frame())" False \
85 "selected frame -vs- newest frame"
86 gdb_test "python print (bframe == gdb.newest_frame())" True \
87 "newest frame -vs- newest frame"
88
89 gdb_test "python print ('result = %s' % (f0 == f1))" " = False" "test equality comparison (false)"
90 gdb_test "python print ('result = %s' % (f0 == f0))" " = True" "test equality comparison (true)"
91 gdb_test "python print ('result = %s' % (f0 != f1))" " = True" "test inequality comparison (true)"
92 gdb_test "python print ('result = %s' % (f0 != f0))" " = False" "test inequality comparison (false)"
93 gdb_test "python print ('result = %s' % f0.is_valid ())" " = True" "test Frame.is_valid"
94 gdb_test "python print ('result = %s' % f0.name ())" " = f2" "test Frame.name"
95 gdb_test "python print ('result = %s' % (f0.type () == gdb.NORMAL_FRAME))" " = True" "test Frame.type"
96 gdb_test "python print ('result = %s' % (f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON))" \
97 " = True" "test Frame.unwind_stop_reason"
98 gdb_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"
99 gdb_test "python print ('result = %s' % f0.pc ())" " = \[0-9\]+" "test Frame.pc"
100 gdb_test "python print ('result = %s' % (f0.older () == f1))" " = True" "test Frame.older"
101 gdb_test "python print ('result = %s' % (f1.newer () == f0))" " = True" "test Frame.newer"
102 gdb_test "python print ('result = %s' % f0.read_var ('variable_which_surely_doesnt_exist'))" \
103 "ValueError: Variable 'variable_which_surely_doesnt_exist' not found.*Error while executing Python code." \
104 "test Frame.read_var - error"
105 gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.read_var - success"
106
107 gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame"
108
109 # Can read SP register.
110 gdb_test "python print ('result = %s' % (gdb.selected_frame ().read_register ('sp') == gdb.parse_and_eval ('\$sp')))" \
111 " = True" \
112 "test Frame.read_register(sp)"
113
114 # PC value obtained via read_register is as expected.
115 gdb_test "python print ('result = %s' % (f0.read_register('pc') == f0.pc()))" \
116 " = True" \
117 "test Frame.read_register(pc)"
118
119 # Test arch-specific register name.
120 set pc ""
121 if {[is_amd64_regs_target]} {
122 set pc "rip"
123 } elseif {[is_x86_like_target]} {
124 set pc "eip"
125 }
126 if { $pc != "" } {
127 gdb_test "python print ('result = %s' % (f0.read_register('pc') == f0.read_register('$pc')))" \
128 " = True" \
129 "test Frame.read_register($pc)"
130 }
131
132 # Test language.
133 gdb_test "python print(gdb.selected_frame().language())" "c"
134 gdb_test "set language ada"
135 gdb_test "python print(gdb.selected_frame().language())" "c" \
136 "frame language is not affected by global language"
137
138 # This previously caused a crash -- the implementation was missing the
139 # case where a register had an unexpected type.
140 gdb_test "python print(gdb.selected_frame().read_register(list()))" \
141 ".*Invalid type for register.*" \
142 "test Frame.read_register with list"