-# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2008-2016 Free Software Foundation, Inc.
# 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
# This file is part of the GDB testsuite. It tests Python-based
# pretty-printing for the CLI.
-if $tracelevel then {
- strace $tracelevel
-}
+load_lib gdb-python.exp
-set testfile "py-prettyprint"
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
+standard_testfile
# Start with a fresh gdb.
gdb_exit
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
-# Run a command in GDB, and report a failure if a Python exception is thrown.
-# If report_pass is true, report a pass if no exception is thrown.
-proc gdb_py_test_silent_cmd {cmd name report_pass} {
- global gdb_prompt
-
- gdb_test_multiple $cmd $name {
- -re "Traceback.*$gdb_prompt $" { fail $name }
- -re "$gdb_prompt $" { if $report_pass { pass $name } }
- }
-}
-
-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"
+proc run_lang_tests {exefile lang} {
+ global srcdir subdir srcfile testfile hex
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } {
+ untested "couldn't compile ${srcfile} in $lang mode"
return -1
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
- gdb_load ${binfile}
+ gdb_load ${exefile}
if ![runto_main ] then {
perror "couldn't run to breakpoint"
".*Breakpoint.*"
gdb_test "continue" ".*Breakpoint.*"
- set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
+ set remote_python_file [gdb_remote_download host \
+ ${srcdir}/${subdir}/${testfile}.py]
- gdb_test_no_output "python execfile ('${remote_python_file}')"
+ gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
+ "python exec (open ('[file tail ${remote_python_file}]').read ())"
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>>}"
+ gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>, a=<24> b=<$hex>} *$nl *}"
+
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_py_test_silent_cmd "set print elements 200" "" 1
}
+ if { ![is_address_zero_readable] } {
+ gdb_test "print ns2" \
+ ".error reading variable: Cannot access memory at address 0x0."
+ }
+
gdb_test "print x" " = \"this is x\""
gdb_test "print cstring" " = \"const string\""
- gdb_test "print estring" "\"embedded x\\\\201\\\\202\\\\203\\\\204\""
+ gdb_test "print estring" " = \"embedded x\\\\201\\\\202\\\\203\\\\204\""
+ if { ![is_address_zero_readable] } {
+ gdb_test "print estring3" \
+ " = <error reading variable: Cannot create a lazy string with address 0x0, and a non-zero length.>"
+ }
+
+ gdb_test_no_output "python pp_ls_encoding = 'UTF-8'"
+ gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>"
+
+ gdb_test_no_output "set python print-stack full"
+ gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val"
+
gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
- gdb_test "continue" "Program exited normally\."
- remote_file host delete ${remote_python_file}
+ gdb_test_no_output "set print pretty off"
+ gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \
+ "print nstype on one line"
+
+ gdb_continue_to_end
}
-run_lang_tests "c"
-run_lang_tests "c++"
+if { [run_lang_tests "${binfile}" "c"] == -1 } {
+ return
+}
+if { [run_lang_tests "${binfile}-cxx" "c++"] == -1 } {
+ return
+}
# 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
return
}
+set remote_python_file [gdb_remote_download host \
+ ${srcdir}/${subdir}/${testfile}.py]
+
+gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
+ "python exec (open ('[file tail ${remote_python_file}]').read ())"
+
+gdb_breakpoint [gdb_get_line_number "eval-break"]
+gdb_continue_to_breakpoint "eval-break" ".* eval-break .*"
+
+gdb_test "info locals" "eval9 = eval=<123456789>"
+
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]
-
-gdb_test "python execfile ('${remote_python_file}')" ""
-
gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \
"print ss enabled #1"
-gdb_test "python disable_lookup_function ()" ""
+gdb_test_no_output "python disable_lookup_function ()"
gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \
"print ss disabled"
-gdb_test "python enable_lookup_function ()" ""
+gdb_test_no_output "python enable_lookup_function ()"
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}