2014-01-01 03:54:24 +00:00
# Copyright (C) 2008-2014 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.
2010-10-01 17:03:50 +00:00
load_lib gdb-python.exp
* gdb.python/lib-types.exp: Use standard_testfile,
prepare_for_testing.
* gdb.python/py-block.exp: Use standard_testfile.
* gdb.python/py-breakpoint.exp: Use standard_testfile.
* gdb.python/py-events.exp: Use standard_testfile,
standard_output_file.
* gdb.python/py-evsignal.exp: Use standard_testfile.
* gdb.python/py-evethreads.exp: Use standard_testfile.
* gdb.python/py-explore-cc.exp: Use standard_testfile.
* gdb.python/py-explore.exp: Use standard_testfile.
* gdb.python/py-finish-breakpoint.exp: Use standard_testfile,
standard_output_file.
* gdb.python/py-finish-breakpoint2.exp: Use standard_testfile,
prepare_for_testing.
* gdb.python/py-frame-inline.exp: Use standard_testfile.
* gdb.python/py-frame.exp: Use standard_testfile.
* gdb.python/py-inferior.exp: Use standard_testfile.
* gdb.python/py-infthread.exp: Use standard_testfile.
* gdb.python/py-mi.exp: Use standard_testfile.
* gdb.python/py-objfile-script.exp: Use standard_testfile,
build_executable.
* gdb.python/py-objfile.exp: Use standard_testfile.
* gdb.python/py-pp-maint.exp: Use standard_testfile,
prepare_for_testing.
* gdb.python/py-prettyprint.exp: Use standard_testfile.
* gdb.python/py-progspace.exp: Use standard_testfile,
build_executable.
* gdb.python/py-prompt.exp: Use standard_testfile,
build_executable.
* gdb.python/py-section-script.exp: Use standard_testfile,
build_executable.
* gdb.python/py-shared.exp: Use standard_testfile,
standard_output_file, clean_restart.
* gdb.python/py-symbol.exp: Use standard_output_file,
prepare_for_testing.
* gdb.python/py-symtab.exp: Use standard_output_file,
prepare_for_testing
* gdb.python/py-template.exp: Use standard_testfile.
* gdb.python/py-type.exp: Use standard_testfile.
* gdb.python/py-value-cc.exp: Use standard_testfile.
* gdb.python/py-value.exp: Use standard_testfile.
* gdb.python/python.exp: Use standard_testfile, build_executable.
2012-06-22 17:59:33 +00:00
standard_testfile
2009-05-28 01:05:14 +00:00
# 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
2011-07-26 18:38:55 +00:00
proc run_lang_tests {exefile lang} {
global srcdir subdir srcfile testfile hex
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } {
2009-05-28 01:05:14 +00:00
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
2011-07-26 18:38:55 +00:00
gdb_load ${exefile}
2009-05-28 01:05:14 +00:00
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
2013-08-22 13:51:08 +00:00
set remote_python_file [gdb_remote_download host \
${srcdir}/${subdir}/${testfile}.py]
2009-11-12 15:15:26 +00:00
2013-08-22 13:51:08 +00:00
gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
"python exec (open ('[file tail ${remote_python_file}]').read ())"
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
}
Stop using errno values around target_xfer interfaces and memory errors.
target_read_memory & friends build on top of target_read (thus on top
of the target_xfer machinery), but turn all errors to EIO, an errno
value. I think we'd better convert all these to return a
target_xfer_error too, like target_xfer_partial in a previous patch.
The patch starts by doing that.
(The patch does not add a enum target_xfer_error value for '0'/no
error, and likewise does not change the return type of several of
these functions to enum target_xfer_error, because different functions
return '0' with different semantics.)
I audited the tree for memory_error calls, EIO checks, places where
GDB hardcodes 'errno = EIO', and also for strerror calls. What I
found is that nowadays there's really no need to handle random errno
values, other than the EIOs gdb itself hardcodes. No doubt errno
values would appear in common code back in the day when
target_xfer_memory was the main interface to access memory, but
nowadays, any errno value that deprecated interface could return is
just absorved by default_xfer_partial:
else if (xfered == 0 && errno == 0)
/* "deprecated_xfer_memory" uses 0, cross checked against
ERRNO as one indication of an error. */
return 0;
else
return -1;
There are two places in the code that check for EIO and print "out of
bounds", and defer to strerror for other errors. That's
c-lang.c:c_get_string, and valprint.c.:val_print_string. AFAICT, the
strerror branch can never be reached nowadays, as the only error
possible to get at those points is EIO, given that it's GDB itself
that set that errno value (in target_read_memory, etc.).
breakpoint.c:insert_bp_location always prints the error val as if an
errno, returned by target_insert_breakpoint, with strerr. Now the
error here is either always EIO for mem-break.c targets (again
hardcoded by the target_read_memory/target_write_memory functions), so
this always prints "Input/output error" or similar (depending on
host), or, for remote targets (and probably others), this gem:
Error accessing memory address 0x80200400: Unknown error -1.
This patch makes these 3 places print the exact same error
memory_error prints. This changes output, but I think this is better,
for making memory error output consistent with other commands, and, it
means we have a central place to tweak for memory errors.
E.g., this changes:
Cannot insert breakpoint 1.
Error accessing memory address 0x5fc660: Input/output error.
to:
Cannot insert breakpoint 1.
Cannot access memory at address 0x5fc660
Which I find pretty much acceptable.
Surprisingly, only py-prettyprint.exp had a regression, for needing an
adjustment. I also grepped the testsuite for the old errors, and
found no other hits.
Now that errno values aren't used anywhere in any of these memory
access related routines, I made memory_error itself take a
target_xfer_error instead of an errno. The new
target_xfer_memory_error function added recently is no longer
necessary, and is thus removed.
Tested on x86_64 Fedora 17, native and gdbserver.
gdb/
2013-10-09 Pedro Alves <palves@redhat.com>
* breakpoint.c (insert_bp_location): Use memory_error_message to
build the memory error string.
* c-lang.c: Include "gdbcore.h".
(c_get_string): Use memory_error to throw error.
(target_xfer_memory_error): Delete.
(memory_error_message): New, factored out from
target_xfer_memory_error.
(memory_error): Change parameter type to target_xfer_error.
Rewrite.
(read_memory): Use memory_error instead of
target_xfer_memory_error.
* gdbcore.h: Include "target.h".
(memory_error): Change parameter type to target_xfer_error.
(memory_error_message): Declare function.
* target.c (target_read_memory, target_read_stack)
(target_write_memory, target_write_raw_memory): Return
TARGET_XFER_E_IO on error. Adjust comments.
(get_target_memory): Pass TARGET_XFER_E_IO to memory_error,
instead of EIO.
* target.h (target_read, target_insert_breakpoint)
(target_remove_breakpoint): Adjust comments.
* valprint.c (partial_memory_read): Rename parameter, and adjust
comment.
(val_print_string): Use memory_error_message to build the memory
error string.
gdb/testsuite/
2013-10-09 Pedro Alves <palves@redhat.com>
* gdb.python/py-prettyprint.exp (run_lang_tests): Adjust expected
output.
2013-10-09 17:00:00 +00:00
gdb_test "print ns2" ".error reading variable: Cannot access memory at address 0x0."
2010-11-12 20:49:43 +00:00
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
2011-01-26 20:58:49 +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>"
2011-12-16 15:55:40 +00:00
gdb_test_no_output "set python print-stack full"
2011-04-11 17:40:41 +00:00
gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val"
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}"
2011-01-26 20:58:49 +00:00
gdb_test_no_output "set print pretty off"
gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \
"print nstype on one line"
2011-03-07 16:03:04 +00:00
gdb_continue_to_end
2009-11-12 15:15:26 +00:00
remote_file host delete ${remote_python_file}
2009-05-28 01:05:14 +00:00
}
2011-07-26 18:38:55 +00:00
run_lang_tests "${binfile}" "c"
run_lang_tests "${binfile}-cxx" "c++"
2010-06-04 18:18:28 +00:00
# Run various other tests.
# 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
}
2013-08-22 13:51:08 +00:00
set remote_python_file [gdb_remote_download host \
${srcdir}/${subdir}/${testfile}.py]
2010-06-04 18:18:28 +00:00
2013-08-22 13:51:08 +00:00
gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
"python exec (open ('[file tail ${remote_python_file}]').read ())"
2010-06-04 18:18:28 +00:00
2012-07-16 19:15:39 +00:00
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.*"
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}