]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-prettyprint.exp
update copyright year range in GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prettyprint.exp
CommitLineData
61baf725 1# Copyright (C) 2008-2017 Free Software Foundation, Inc.
a6bac58e
TT
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 Python-based
17# pretty-printing for the CLI.
18
a2c09bd0
DE
19load_lib gdb-python.exp
20
b4a58790 21standard_testfile
a6bac58e
TT
22
23# Start with a fresh gdb.
24gdb_exit
25gdb_start
f6bbabf0
PM
26
27# Skip all tests if Python scripting is not enabled.
28if { [skip_python_tests] } { continue }
a6bac58e 29
db8e4570
UW
30proc run_lang_tests {exefile lang} {
31 global srcdir subdir srcfile testfile hex
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } {
84c93cd5 33 untested "failed to compile in $lang mode"
a6bac58e
TT
34 return -1
35 }
36
37 set nl "\[\r\n\]+"
38
39 # Start with a fresh gdb.
40 gdb_exit
41 gdb_start
42 gdb_reinitialize_dir $srcdir/$subdir
db8e4570 43 gdb_load ${exefile}
a6bac58e 44
a6bac58e
TT
45 if ![runto_main ] then {
46 perror "couldn't run to breakpoint"
47 return
48 }
49
89493308 50 gdb_test_no_output "set print pretty on"
a6bac58e
TT
51
52 gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
53 ".*Breakpoint.*"
54 gdb_test "continue" ".*Breakpoint.*"
f24fce77 55
8448e842
TT
56 set remote_python_file [gdb_remote_download host \
57 ${srcdir}/${subdir}/${testfile}.py]
f24fce77 58
8448e842
TT
59 gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
60 "python exec (open ('[file tail ${remote_python_file}]').read ())"
a6bac58e
TT
61
62 gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>"
63 gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>"
64 gdb_test "print ssa" " = {a=< a=<3> b=<$hex>> b=< a=<4> b=<$hex>>, a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>}"
65
91158a56
TT
66 gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>, a=<24> b=<$hex>} *$nl *}"
67
a6bac58e
TT
68 if {$lang == "c++"} {
69 gdb_test "print cps" "= a=<8> b=<$hex>"
70 gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}"
71 gdb_test "print cpssa\[0\]" " = {$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl}"
72 gdb_test "print cpssa\[1\]" " = {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl}"
73 gdb_test "print cpssa" " = {{$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl *}, {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl *}}"
74 gdb_test "print sss" "= a=<15> b=< a=<8> b=<$hex>>"
75 gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>"
76 gdb_test "print derived" \
77 " = \{.*<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.*"
fbb8f299 78 gdb_test "print ns " "\"embedded\\\\000null\\\\000string\""
7a9fe101
PM
79 gdb_py_test_silent_cmd "set print elements 3" "" 1
80 gdb_test "print ns" "emb\.\.\.."
81 gdb_py_test_silent_cmd "set print elements 10" "" 1
82 gdb_test "print ns" "embedded\\\\000n\.\.\.."
83 gdb_py_test_silent_cmd "set print elements 200" "" 1
a6bac58e
TT
84 }
85
20c6f1e1
YQ
86 if { ![is_address_zero_readable] } {
87 gdb_test "print ns2" \
88 ".error reading variable: Cannot access memory at address 0x0."
89 }
621c8364 90
269f82e5
PP
91 gdb_test "print x" " = \"this is x\""
92 gdb_test "print cstring" " = \"const string\""
a6bac58e 93
a81766d8 94 gdb_test "print estring" " = \"embedded x\\\\201\\\\202\\\\203\\\\204\""
bf7b9cd9
SM
95 if { ![is_address_zero_readable] } {
96 gdb_test "print estring3" \
97 " = <error reading variable: Cannot create a lazy string with address 0x0, and a non-zero length.>"
98 }
3a772aa4
TT
99
100 gdb_test_no_output "python pp_ls_encoding = 'UTF-8'"
101 gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>"
102
80b6e756 103 gdb_test_no_output "set python print-stack full"
e1ab1f9c
JK
104 gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val"
105
269f82e5 106 gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
a6bac58e 107
79f283fe 108 gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
a81766d8
TT
109
110 gdb_test_no_output "set print pretty off"
111 gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \
112 "print nstype on one line"
113
fda326dd 114 gdb_continue_to_end
a6bac58e
TT
115}
116
e70b6e8e
DE
117if { [run_lang_tests "${binfile}" "c"] == -1 } {
118 return
119}
120if { [run_lang_tests "${binfile}-cxx" "c++"] == -1 } {
121 return
122}
967cf477
DE
123
124# Run various other tests.
125
967cf477
DE
126# Start with a fresh gdb.
127gdb_exit
128gdb_start
129gdb_reinitialize_dir $srcdir/$subdir
130gdb_load ${binfile}
131
132if ![runto_main ] then {
133 perror "couldn't run to breakpoint"
134 return
135}
136
8448e842
TT
137set remote_python_file [gdb_remote_download host \
138 ${srcdir}/${subdir}/${testfile}.py]
967cf477 139
8448e842
TT
140gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
141 "python exec (open ('[file tail ${remote_python_file}]').read ())"
967cf477 142
8f043999
JK
143gdb_breakpoint [gdb_get_line_number "eval-break"]
144gdb_continue_to_breakpoint "eval-break" ".* eval-break .*"
145
146gdb_test "info locals" "eval9 = eval=<123456789>"
147
148gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
149 ".*Breakpoint.*"
150gdb_test "continue" ".*Breakpoint.*"
151
967cf477
DE
152gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \
153 "print ss enabled #1"
154
f6978de9 155gdb_test_no_output "python disable_lookup_function ()"
967cf477
DE
156
157gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \
158 "print ss disabled"
159
f6978de9 160gdb_test_no_output "python enable_lookup_function ()"
967cf477
DE
161
162gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \
163 "print ss enabled #2"