2010-01-13 Phil Muldoon <pmuldoon@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prettyprint.exp
CommitLineData
4c38e0a4 1# Copyright (C) 2008, 2009, 2010 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
19if $tracelevel then {
20 strace $tracelevel
21}
22
5172aecb 23set testfile "py-prettyprint"
a6bac58e
TT
24set srcfile ${testfile}.c
25set binfile ${objdir}/${subdir}/${testfile}
26
27# Start with a fresh gdb.
28gdb_exit
29gdb_start
30gdb_test_multiple "python print 'hello, world!'" "verify python support" {
31 -re "not supported.*$gdb_prompt $" {
32 unsupported "python support is disabled"
33 return -1
34 }
35 -re "$gdb_prompt $" {}
36}
37
7a9fe101
PM
38# Run a command in GDB, and report a failure if a Python exception is thrown.
39# If report_pass is true, report a pass if no exception is thrown.
40proc gdb_py_test_silent_cmd {cmd name report_pass} {
41 global gdb_prompt
42
43 gdb_test_multiple $cmd $name {
44 -re "Traceback.*$gdb_prompt $" { fail $name }
45 -re "$gdb_prompt $" { if $report_pass { pass $name } }
46 }
47}
48
a6bac58e
TT
49proc run_lang_tests {lang} {
50 global srcdir subdir srcfile binfile testfile hex
51 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug $lang"] != "" } {
52 untested "Couldn't compile ${srcfile} in $lang mode"
53 return -1
54 }
55
56 set nl "\[\r\n\]+"
57
58 # Start with a fresh gdb.
59 gdb_exit
60 gdb_start
61 gdb_reinitialize_dir $srcdir/$subdir
62 gdb_load ${binfile}
63
64
65 if ![runto_main ] then {
66 perror "couldn't run to breakpoint"
67 return
68 }
69
70 gdb_test "set print pretty on" ""
71
72 gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
73 ".*Breakpoint.*"
74 gdb_test "continue" ".*Breakpoint.*"
f24fce77
NF
75
76 set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
77
78 gdb_test "python execfile ('${remote_python_file}')" ""
a6bac58e
TT
79
80 gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>"
81 gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>"
82 gdb_test "print ssa" " = {a=< a=<3> b=<$hex>> b=< a=<4> b=<$hex>>, a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>}"
83
84 if {$lang == "c++"} {
85 gdb_test "print cps" "= a=<8> b=<$hex>"
86 gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}"
87 gdb_test "print cpssa\[0\]" " = {$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl}"
88 gdb_test "print cpssa\[1\]" " = {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl}"
89 gdb_test "print cpssa" " = {{$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl *}, {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl *}}"
90 gdb_test "print sss" "= a=<15> b=< a=<8> b=<$hex>>"
91 gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>"
92 gdb_test "print derived" \
93 " = \{.*<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 94 gdb_test "print ns " "\"embedded\\\\000null\\\\000string\""
7a9fe101
PM
95 gdb_py_test_silent_cmd "set print elements 3" "" 1
96 gdb_test "print ns" "emb\.\.\.."
97 gdb_py_test_silent_cmd "set print elements 10" "" 1
98 gdb_test "print ns" "embedded\\\\000n\.\.\.."
99 gdb_py_test_silent_cmd "set print elements 200" "" 1
a6bac58e
TT
100 }
101
269f82e5
PP
102 gdb_test "print x" " = \"this is x\""
103 gdb_test "print cstring" " = \"const string\""
a6bac58e 104
be759fcf 105 gdb_test "print estring" "\"embedded x\\\\201\\\\202\\\\203\\\\204\""
269f82e5 106 gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
a6bac58e
TT
107
108 gdb_test "continue" "Program exited normally\."
f24fce77
NF
109
110 remote_file host delete ${remote_python_file}
a6bac58e
TT
111}
112
113run_lang_tests "c"
114run_lang_tests "c++"
This page took 0.097458 seconds and 4 git commands to generate.