]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.guile/scm-frame.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.guile / scm-frame.exp
1 # Copyright (C) 2009-2024 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.
17 # It tests the frame support in Guile.
18
19 load_lib gdb-guile.exp
20
21 require allow_guile_tests
22
23 standard_testfile
24
25 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
26 return -1
27 }
28
29 # The following tests require execution.
30
31 if ![gdb_guile_runto_main] {
32 return
33 }
34
35 gdb_breakpoint [gdb_get_line_number "Block break here."]
36 gdb_continue_to_breakpoint "Block break here."
37 gdb_scm_test_silent_cmd "guile (define bf1 (selected-frame))" \
38 "get frame"
39
40 # Test frame-architecture method.
41 gdb_scm_test_silent_cmd "guile (define show-arch-str (execute \"show architecture\" #:to-string #t))" \
42 "show arch"
43 gdb_test "guile (print (->bool (string-contains show-arch-str (arch-name (frame-arch bf1)))))" \
44 "#t" "test frame-arch"
45
46 # First test that read-var is unaffected by PR 11036 changes.
47 gdb_test "guile (print (frame-read-var bf1 \"i\"))" \
48 "\"stuff\"" "test i"
49 gdb_test "guile (print (frame-read-var bf1 \"f\"))" \
50 "\"foo\"" "test f"
51 gdb_test "guile (print (frame-read-var bf1 \"b\"))" \
52 "\"bar\"" "test b"
53
54 # Test the read-var function in another block other than the current
55 # block (in this case, the super block). Test thar read-var is reading
56 # the correct variables of i and f but they are the correct value and type.
57 gdb_scm_test_silent_cmd "guile (define sb (block-superblock (frame-block bf1)))" \
58 "get superblock"
59 gdb_test "guile (print (frame-read-var bf1 \"i\" #:block sb))" "1.1.*" \
60 "test i = 1.1"
61 gdb_test "guile (print (value-type (frame-read-var bf1 \"i\" #:block sb)))" \
62 "double" "test double i"
63 gdb_test "guile (print (frame-read-var bf1 \"f\" #:block sb))" \
64 "2.2.*" "test f = 2.2"
65 gdb_test "guile (print (value-type (frame-read-var bf1 \"f\" #:block sb)))" \
66 "double" "test double f"
67
68 # And again test another outerblock, this time testing "i" is the
69 # correct value and type.
70 gdb_scm_test_silent_cmd "guile (set! sb (block-superblock sb))" \
71 "get superblock #2"
72 gdb_test "guile (print (frame-read-var bf1 \"i\" #:block sb))" \
73 "99" "test i = 99"
74 gdb_test "guile (print (value-type (frame-read-var bf1 \"i\" #:block sb)))" \
75 "int" "test int i"
76
77 gdb_breakpoint "f2"
78 gdb_continue_to_breakpoint "breakpoint at f2"
79 gdb_scm_test_silent_cmd "guile (define bframe (selected-frame))" \
80 "get bottom-most frame"
81 gdb_test "up" ".*" ""
82
83 gdb_scm_test_silent_cmd "guile (define f1 (selected-frame))" \
84 "get second frame"
85 gdb_scm_test_silent_cmd "guile (define f0 (frame-newer f1))" \
86 "get first frame"
87
88 gdb_test "guile (print (eq? f1 (newest-frame)))" \
89 #f "selected frame -vs- newest frame"
90 gdb_test "guile (print (eq? bframe (newest-frame)))" \
91 #t "newest frame -vs- newest frame"
92
93 gdb_test "guile (print (eq? f0 f1))" \
94 "#f" "test equality comparison (false)"
95 gdb_test "guile (print (eq? f0 f0))" \
96 "#t" "test equality comparison (true)"
97 gdb_test "guile (print (frame-valid? f0))" \
98 "#t" "test frame-valid?"
99 gdb_test "guile (print (frame-name f0))" \
100 "f2" "test frame-name"
101 gdb_test "guile (print (= (frame-type f0) NORMAL_FRAME))" \
102 "#t" "test frame-type"
103 gdb_test "guile (print (= (frame-unwind-stop-reason f0) FRAME_UNWIND_NO_REASON))" \
104 "#t" "test frame-unwind-stop-reason"
105 gdb_test "guile (print (unwind-stop-reason-string FRAME_UNWIND_INNER_ID))" \
106 "previous frame inner to this frame \\(corrupt stack\\?\\)" \
107 "test unwind-stop-reason-string"
108 gdb_test "guile (print (format #f \"= ~A\" (frame-pc f0)))" \
109 "= \[0-9\]+" "test frame-pc"
110 gdb_test "guile (print (format #f \"= ~A\" (eq? (frame-older f0) f1)))" \
111 "= #t" "test frame-older"
112 gdb_test "guile (print (format #f \"= ~A\" (eq? (frame-newer f1) f0)))" \
113 "= #t" "test frame-newer"
114 gdb_test "guile (print (frame-read-var f0 \"variable_which_surely_doesnt_exist\"))" \
115 "ERROR: .*: Out of range: variable not found: \"variable_which_surely_doesnt_exist\".*" \
116 "test frame-read-var - error"
117 gdb_test "guile (print (format #f \"= ~A\" (frame-read-var f0 \"a\")))" \
118 "= 1" "test frame-read-var - success"
119
120 gdb_test "guile (print (format #f \"= ~A\" (eq? (selected-frame) f1)))" \
121 "= #t" "test selected-frame"
122
123 # Can read SP register.
124 gdb_test "guile (print (equal? (frame-read-register (selected-frame) \"sp\") (parse-and-eval \"\$sp\")))" \
125 "= #t" "test frame-read-register of sp"
126
127 # PC value obtained via read_register is as expected.
128 gdb_test "guile (print (equal? (value->integer (frame-read-register f0 \"pc\")) (frame-pc f0)))" \
129 "= #t" "test frame-read-register of pc"
130
131 # Test arch-specific register name.
132 set pc ""
133 if {[is_amd64_regs_target]} {
134 set pc "rip"
135 } elseif {[is_x86_like_target]} {
136 set pc "eip"
137 }
138 if { $pc != "" } {
139 gdb_test "guile (print (equal? (frame-read-register f0 \"pc\") (frame-read-register f0 \"$pc\")))" \
140 "= #t" "test frame-read-register of $pc"
141 }