Commit | Line | Data |
---|---|---|
c5a57081 | 1 | # Copyright (C) 2008-2012 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 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
a2c09bd0 DE |
23 | load_lib gdb-python.exp |
24 | ||
5172aecb | 25 | set testfile "py-prettyprint" |
a6bac58e TT |
26 | set srcfile ${testfile}.c |
27 | set binfile ${objdir}/${subdir}/${testfile} | |
28 | ||
29 | # Start with a fresh gdb. | |
30 | gdb_exit | |
31 | gdb_start | |
f6bbabf0 PM |
32 | |
33 | # Skip all tests if Python scripting is not enabled. | |
34 | if { [skip_python_tests] } { continue } | |
a6bac58e | 35 | |
db8e4570 UW |
36 | proc run_lang_tests {exefile lang} { |
37 | global srcdir subdir srcfile testfile hex | |
38 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } { | |
a6bac58e TT |
39 | untested "Couldn't compile ${srcfile} in $lang mode" |
40 | return -1 | |
41 | } | |
42 | ||
43 | set nl "\[\r\n\]+" | |
44 | ||
45 | # Start with a fresh gdb. | |
46 | gdb_exit | |
47 | gdb_start | |
48 | gdb_reinitialize_dir $srcdir/$subdir | |
db8e4570 | 49 | gdb_load ${exefile} |
a6bac58e | 50 | |
a6bac58e TT |
51 | if ![runto_main ] then { |
52 | perror "couldn't run to breakpoint" | |
53 | return | |
54 | } | |
55 | ||
89493308 | 56 | gdb_test_no_output "set print pretty on" |
a6bac58e TT |
57 | |
58 | gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \ | |
59 | ".*Breakpoint.*" | |
60 | gdb_test "continue" ".*Breakpoint.*" | |
f24fce77 NF |
61 | |
62 | set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] | |
63 | ||
89493308 | 64 | gdb_test_no_output "python execfile ('${remote_python_file}')" |
a6bac58e TT |
65 | |
66 | gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" | |
67 | gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>" | |
68 | gdb_test "print ssa" " = {a=< a=<3> b=<$hex>> b=< a=<4> b=<$hex>>, a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>}" | |
69 | ||
91158a56 TT |
70 | gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>, a=<24> b=<$hex>} *$nl *}" |
71 | ||
a6bac58e TT |
72 | if {$lang == "c++"} { |
73 | gdb_test "print cps" "= a=<8> b=<$hex>" | |
74 | gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}" | |
75 | gdb_test "print cpssa\[0\]" " = {$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl}" | |
76 | gdb_test "print cpssa\[1\]" " = {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl}" | |
77 | gdb_test "print cpssa" " = {{$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl *}, {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl *}}" | |
78 | gdb_test "print sss" "= a=<15> b=< a=<8> b=<$hex>>" | |
79 | gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>" | |
80 | gdb_test "print derived" \ | |
81 | " = \{.*<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 | 82 | gdb_test "print ns " "\"embedded\\\\000null\\\\000string\"" |
7a9fe101 PM |
83 | gdb_py_test_silent_cmd "set print elements 3" "" 1 |
84 | gdb_test "print ns" "emb\.\.\.." | |
85 | gdb_py_test_silent_cmd "set print elements 10" "" 1 | |
86 | gdb_test "print ns" "embedded\\\\000n\.\.\.." | |
87 | gdb_py_test_silent_cmd "set print elements 200" "" 1 | |
a6bac58e TT |
88 | } |
89 | ||
621c8364 TT |
90 | gdb_test "print ns2" ".error reading variable: Address 0x0 out of bounds." |
91 | ||
269f82e5 PP |
92 | gdb_test "print x" " = \"this is x\"" |
93 | gdb_test "print cstring" " = \"const string\"" | |
a6bac58e | 94 | |
a81766d8 | 95 | gdb_test "print estring" " = \"embedded x\\\\201\\\\202\\\\203\\\\204\"" |
3a772aa4 TT |
96 | |
97 | gdb_test_no_output "python pp_ls_encoding = 'UTF-8'" | |
98 | gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>" | |
99 | ||
80b6e756 | 100 | gdb_test_no_output "set python print-stack full" |
e1ab1f9c JK |
101 | gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val" |
102 | ||
269f82e5 | 103 | gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}" |
a6bac58e | 104 | |
79f283fe | 105 | gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}" |
a81766d8 TT |
106 | |
107 | gdb_test_no_output "set print pretty off" | |
108 | gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \ | |
109 | "print nstype on one line" | |
110 | ||
fda326dd | 111 | gdb_continue_to_end |
f24fce77 NF |
112 | |
113 | remote_file host delete ${remote_python_file} | |
a6bac58e TT |
114 | } |
115 | ||
db8e4570 UW |
116 | run_lang_tests "${binfile}" "c" |
117 | run_lang_tests "${binfile}-cxx" "c++" | |
967cf477 DE |
118 | |
119 | # Run various other tests. | |
120 | ||
967cf477 DE |
121 | # Start with a fresh gdb. |
122 | gdb_exit | |
123 | gdb_start | |
124 | gdb_reinitialize_dir $srcdir/$subdir | |
125 | gdb_load ${binfile} | |
126 | ||
127 | if ![runto_main ] then { | |
128 | perror "couldn't run to breakpoint" | |
129 | return | |
130 | } | |
131 | ||
132 | gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \ | |
133 | ".*Breakpoint.*" | |
134 | gdb_test "continue" ".*Breakpoint.*" | |
135 | ||
136 | set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] | |
137 | ||
f6978de9 | 138 | gdb_test_no_output "python execfile ('${remote_python_file}')" |
967cf477 DE |
139 | |
140 | gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \ | |
141 | "print ss enabled #1" | |
142 | ||
f6978de9 | 143 | gdb_test_no_output "python disable_lookup_function ()" |
967cf477 DE |
144 | |
145 | gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \ | |
146 | "print ss disabled" | |
147 | ||
f6978de9 | 148 | gdb_test_no_output "python enable_lookup_function ()" |
967cf477 DE |
149 | |
150 | gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \ | |
151 | "print ss enabled #2" | |
152 | ||
153 | remote_file host delete ${remote_python_file} |