Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright (C) 2008-2022 Free Software Foundation, Inc. |
ed3ef339 DE |
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 Guile-based pretty-printing for the CLI. | |
18 | ||
19 | load_lib gdb-guile.exp | |
20 | ||
21 | standard_testfile | |
22 | ||
23 | # Start with a fresh gdb. | |
24 | gdb_exit | |
25 | gdb_start | |
26 | ||
27 | # Skip all tests if Guile scripting is not enabled. | |
28 | if { [skip_guile_tests] } { continue } | |
29 | ||
30 | proc run_lang_tests {exefile lang} { | |
4a0a0bd2 AB |
31 | with_test_prefix "lang=$lang" { |
32 | global srcdir subdir srcfile testfile hex | |
33 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } { | |
34 | untested "failed to compile in $lang mode" | |
35 | return | |
36 | } | |
37 | ||
38 | set nl "\[\r\n\]+" | |
39 | ||
40 | # Start with a fresh gdb. | |
41 | gdb_exit | |
42 | gdb_start | |
43 | gdb_reinitialize_dir $srcdir/$subdir | |
44 | gdb_load ${exefile} | |
45 | ||
46 | if ![gdb_guile_runto_main] { | |
47 | return | |
48 | } | |
49 | ||
50 | gdb_test_no_output "set print pretty on" | |
51 | ||
52 | gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \ | |
53 | ".*Breakpoint.*" | |
54 | gdb_test "continue" ".*Breakpoint.*" | |
55 | ||
56 | set remote_scheme_file [gdb_remote_download host \ | |
57 | ${srcdir}/${subdir}/${testfile}.scm] | |
58 | ||
59 | gdb_scm_load_file ${remote_scheme_file} | |
60 | ||
61 | gdb_test "print ss" " = a=<a=<1> b=<$hex>> b=<a=<2> b=<$hex>>" | |
62 | gdb_test "print ssa\[1\]" " = a=<a=<5> b=<$hex>> b=<a=<6> b=<$hex>>" | |
63 | gdb_test "print ssa" " = {a=<a=<3> b=<$hex>> b=<a=<4> b=<$hex>>, a=<a=<5> b=<$hex>> b=<a=<6> b=<$hex>>}" | |
64 | ||
65 | gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = {a=<23> b=<$hex>, a=<24> b=<$hex>} *$nl *}" | |
66 | ||
67 | if {$lang == "c++"} { | |
68 | gdb_test "print cps" "= a=<8> b=<$hex>" | |
69 | gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}" | |
70 | gdb_test "print cpssa\[0\]" " = {$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl}" | |
71 | gdb_test "print cpssa\[1\]" " = {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl}" | |
72 | gdb_test "print cpssa" " = {{$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl *}, {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl *}}" | |
73 | gdb_test "print sss" "= a=<15> b=<a=<8> b=<$hex>>" | |
74 | gdb_test "print ref" "= a=<15> b=<a=<8> b=<$hex>>" | |
75 | gdb_test "print derived" \ | |
76 | " = \{.*<Vbase1> = pp class name: Vbase1.*<Vbase2> = \{.*<VirtualTest> = pp value variable is: 1,.*members of Vbase2:.*_vptr.Vbase2 = $hex.*<Vbase3> = \{.*members of Vbase3.*members of Derived:.*value = 2.*" | |
77 | gdb_test "print ns " "\"embedded\\\\000null\\\\000string\"" \ | |
78 | "print ns with 200 elements" | |
79 | gdb_test_no_output "set print elements 3" "" | |
80 | gdb_test "print ns" "emb\.\.\.." \ | |
81 | "print ns with 3 elements" | |
82 | gdb_test_no_output "set print elements 10" "" | |
83 | gdb_test "print ns" "embedded\\\\000n\.\.\.." \ | |
84 | "print ns with 10 elements" | |
85 | gdb_test_no_output "set print elements 200" "" | |
86 | } | |
87 | ||
88 | if { ![is_address_zero_readable] } { | |
89 | gdb_test "print ns2" "<error reading variable: ERROR: Cannot access memory at address 0x0>" | |
90 | } | |
91 | ||
92 | gdb_test "print x" " = \"this is x\"" | |
d9211df2 AB |
93 | gdb_test "print cstring" " = \"const string\"" \ |
94 | "print cstring with max-depth unlimited" | |
ecf25064 | 95 | gdb_test_no_output "set print max-depth 0" |
d9211df2 AB |
96 | gdb_test "print cstring" " = \"const string\"" \ |
97 | "print cstring with max-depth 0" | |
ecf25064 KC |
98 | gdb_test_no_output "set print max-depth unlimited" |
99 | ||
4a0a0bd2 AB |
100 | gdb_test "print estring" " = \"embedded x\\\\201\\\\202\\\\203\\\\204\"" |
101 | ||
102 | gdb_test_no_output "guile (set! *pp-ls-encoding* \"UTF-8\")" | |
103 | gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>" | |
104 | ||
105 | gdb_test_no_output "set guile print-stack full" | |
106 | gdb_test "print hint_error" "ERROR: Invalid display hint: 42\r\nhint_error_val" | |
107 | ||
108 | gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}" | |
109 | ||
110 | gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}" | |
111 | ||
112 | gdb_test_no_output "set print pretty off" | |
113 | gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \ | |
114 | "print nstype on one line" | |
115 | ||
116 | gdb_continue_to_end | |
ed3ef339 | 117 | } |
ed3ef339 DE |
118 | } |
119 | ||
120 | run_lang_tests "${binfile}" "c" | |
121 | run_lang_tests "${binfile}-cxx" "c++" | |
122 | ||
123 | # Run various other tests. | |
124 | ||
125 | # Start with a fresh gdb. | |
126 | gdb_exit | |
127 | gdb_start | |
128 | gdb_reinitialize_dir $srcdir/$subdir | |
129 | gdb_load ${binfile} | |
130 | ||
131 | if ![gdb_guile_runto_main] { | |
132 | return | |
133 | } | |
134 | ||
135 | set remote_scheme_file [gdb_remote_download host \ | |
136 | ${srcdir}/${subdir}/${testfile}.scm] | |
137 | ||
138 | gdb_scm_load_file ${remote_scheme_file} | |
139 | ||
140 | gdb_breakpoint [gdb_get_line_number "eval-break"] | |
141 | gdb_continue_to_breakpoint "eval-break" ".* eval-break .*" | |
142 | ||
143 | gdb_test "info locals" "eval9 = eval=<123456789>" | |
144 | ||
145 | gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \ | |
146 | ".*Breakpoint.*" | |
147 | gdb_test "continue" ".*Breakpoint.*" | |
148 | ||
149 | gdb_test "print ss" " = a=<a=<1> b=<$hex>> b=<a=<2> b=<$hex>>" \ | |
150 | "print ss enabled #1" | |
151 | ||
152 | gdb_test_no_output "guile (disable-matcher!)" | |
ed3ef339 DE |
153 | gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \ |
154 | "print ss disabled" | |
155 | ||
156 | gdb_test_no_output "guile (enable-matcher!)" | |
ed3ef339 DE |
157 | gdb_test "print ss" " = a=<a=<1> b=<$hex>> b=<a=<2> b=<$hex>>" \ |
158 | "print ss enabled #2" | |
ded03782 DE |
159 | |
160 | gdb_test_no_output "guile (install-progspace-pretty-printers! (current-progspace))" | |
161 | gdb_test "print ss" \ | |
162 | " = a=<progspace a=<1> b=<$hex>> b=<progspace a=<2> b=<$hex>>" \ | |
163 | "print ss via progspace" | |
164 | ||
165 | gdb_test_no_output "guile (install-objfile-pretty-printers! (current-progspace) \"scm-pretty-print\")" | |
166 | gdb_test "print ss" \ | |
167 | " = a=<objfile a=<1> b=<$hex>> b=<objfile a=<2> b=<$hex>>" \ | |
168 | "print ss via objfile" |