2010-01-01 07:32:07 +00:00
# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
2009-05-28 01:05:14 +00:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file is part of the GDB testsuite. It tests Python-based
# pretty-printing for the CLI.
if $tracelevel then {
strace $tracelevel
}
2010-10-01 17:03:50 +00:00
load_lib gdb-python.exp
2009-09-09 17:45:42 +00:00
set testfile "py-prettyprint"
2009-05-28 01:05:14 +00:00
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
# Start with a fresh gdb.
gdb_exit
gdb_start
2010-02-24 11:11:17 +00:00
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
2009-05-28 01:05:14 +00:00
proc run_lang_tests {lang} {
global srcdir subdir srcfile binfile testfile hex
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug $lang"] != "" } {
untested "Couldn't compile ${srcfile} in $lang mode"
return -1
}
set nl "\[\r\n\]+"
# Start with a fresh gdb.
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
if ![runto_main ] then {
perror "couldn't run to breakpoint"
return
}
2010-06-02 21:50:56 +00:00
gdb_test_no_output "set print pretty on"
2009-05-28 01:05:14 +00:00
gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
".*Breakpoint.*"
gdb_test "continue" ".*Breakpoint.*"
2009-11-12 15:15:26 +00:00
set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
2010-06-02 21:50:56 +00:00
gdb_test_no_output "python execfile ('${remote_python_file}')"
2009-05-28 01:05:14 +00:00
gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>"
gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>"
gdb_test "print ssa" " = {a=< a=<3> b=<$hex>> b=< a=<4> b=<$hex>>, a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>}"
2010-07-14 14:13:55 +00:00
gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>, a=<24> b=<$hex>} *$nl *}"
2009-05-28 01:05:14 +00:00
if {$lang == "c++"} {
gdb_test "print cps" "= a=<8> b=<$hex>"
gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}"
gdb_test "print cpssa\[0\]" " = {$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl}"
gdb_test "print cpssa\[1\]" " = {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl}"
gdb_test "print cpssa" " = {{$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl *}, {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl *}}"
gdb_test "print sss" "= a=<15> b=< a=<8> b=<$hex>>"
gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>"
gdb_test "print derived" \
" = \{.*<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.*"
2009-07-10 10:35:17 +00:00
gdb_test "print ns " "\"embedded\\\\000null\\\\000string\""
2009-09-21 09:39:53 +00:00
gdb_py_test_silent_cmd "set print elements 3" "" 1
gdb_test "print ns" "emb\.\.\.."
gdb_py_test_silent_cmd "set print elements 10" "" 1
gdb_test "print ns" "embedded\\\\000n\.\.\.."
gdb_py_test_silent_cmd "set print elements 200" "" 1
2009-05-28 01:05:14 +00:00
}
2010-11-12 20:49:43 +00:00
gdb_test "print ns2" ".error reading variable: Address 0x0 out of bounds."
2009-11-13 17:17:57 +00:00
gdb_test "print x" " = \"this is x\""
gdb_test "print cstring" " = \"const string\""
2009-05-28 01:05:14 +00:00
2010-01-14 08:03:37 +00:00
gdb_test "print estring" "\"embedded x\\\\201\\\\202\\\\203\\\\204\""
2010-10-18 19:14:03 +00:00
gdb_test_no_output "python pp_ls_encoding = 'UTF-8'"
gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>"
2009-11-13 17:17:57 +00:00
gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
2009-05-28 01:05:14 +00:00
2010-04-14 12:02:46 +00:00
gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
2009-05-28 01:05:14 +00:00
gdb_test "continue" "Program exited normally\."
2009-11-12 15:15:26 +00:00
remote_file host delete ${remote_python_file}
2009-05-28 01:05:14 +00:00
}
run_lang_tests "c"
run_lang_tests "c++"
2010-06-04 18:18:28 +00:00
# Run various other tests.
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug"] != "" } {
untested "Couldn't compile ${srcfile}"
return -1
}
# Start with a fresh gdb.
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
if ![runto_main ] then {
perror "couldn't run to breakpoint"
return
}
gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
".*Breakpoint.*"
gdb_test "continue" ".*Breakpoint.*"
set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
2010-06-10 19:48:20 +00:00
gdb_test_no_output "python execfile ('${remote_python_file}')"
2010-06-04 18:18:28 +00:00
gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \
"print ss enabled #1"
2010-06-10 19:48:20 +00:00
gdb_test_no_output "python disable_lookup_function ()"
2010-06-04 18:18:28 +00:00
gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \
"print ss disabled"
2010-06-10 19:48:20 +00:00
gdb_test_no_output "python enable_lookup_function ()"
2010-06-04 18:18:28 +00:00
gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \
"print ss enabled #2"
remote_file host delete ${remote_python_file}