Index: gdb/ChangeLog =================================================================== RCS file: /cvs/src/src/gdb/ChangeLog,v retrieving revision 1.11289 diff -u -r1.11289 ChangeLog --- gdb/ChangeLog 25 Jan 2010 19:31:23 -0000 1.11289 +++ gdb/ChangeLog 27 Jan 2010 18:56:27 -0000 @@ -1,3 +1,9 @@ +2010-01-25 Chris Moller + + PR gdb/10728: + * valarith.c (value_ptrdiff): Added a test for a zero type length, + warn if found, and assume length = 1. + 2010-01-25 Tom Tromey PR gdb/11049: Index: gdb/valarith.c =================================================================== RCS file: /cvs/src/src/gdb/valarith.c,v retrieving revision 1.79 diff -u -r1.79 valarith.c --- gdb/valarith.c 20 Jan 2010 18:06:15 -0000 1.79 +++ gdb/valarith.c 27 Jan 2010 18:56:29 -0000 @@ -122,6 +122,13 @@ an integer nor a pointer of the same type.")); sz = TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1))); + if (sz == 0) + { + warning (_("Type size unknown, assuming 1. " + "Try casting to a known type, or void *.")); + sz = 1; + } + return (value_as_long (arg1) - value_as_long (arg2)) / sz; } Index: gdb/testsuite/ChangeLog =================================================================== RCS file: /cvs/src/src/gdb/testsuite/ChangeLog,v retrieving revision 1.2101 diff -u -r1.2101 ChangeLog --- gdb/testsuite/ChangeLog 25 Jan 2010 19:31:23 -0000 1.2101 +++ gdb/testsuite/ChangeLog 27 Jan 2010 18:56:45 -0000 @@ -1,3 +1,12 @@ +2010-01-26 Chris Moller + + PR gdb/10728 + * gdb.cp/pr10728-x.h: New file. + * gdb.cp/pr10728-x.cc: New file. + * gdb.cp/pr10728-y.cc: New file. + * gdb.cp/pr10728.exp: New file. + * gdb.cp/Makefile.in (EXECUTABLES): Add pr10728 + 2010-01-25 Tom Tromey PR gdb/11049: Index: gdb/testsuite/gdb.cp/Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/Makefile.in,v retrieving revision 1.7 diff -u -r1.7 Makefile.in --- gdb/testsuite/gdb.cp/Makefile.in 10 Dec 2009 20:57:10 -0000 1.7 +++ gdb/testsuite/gdb.cp/Makefile.in 27 Jan 2010 18:56:45 -0000 @@ -4,7 +4,7 @@ EXECUTABLES = ambiguous annota2 anon-union cplusfuncs cttiadd \ derivation inherit local member-ptr method misc \ overload ovldbreak ref-typ ref-typ2 templates userdef virtfunc namespace \ - ref-types ref-params method2 pr9594 gdb2495 virtfunc2 + ref-types ref-params method2 pr9594 gdb2495 virtfunc2 pr10728 all info install-info dvi install uninstall installcheck check: @echo "Nothing to be done for $@..." Index: gdb/testsuite/gdb.cp/pr10728-x.cc =================================================================== RCS file: gdb/testsuite/gdb.cp/pr10728-x.cc diff -N gdb/testsuite/gdb.cp/pr10728-x.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gdb/testsuite/gdb.cp/pr10728-x.cc 27 Jan 2010 18:56:45 -0000 @@ -0,0 +1,7 @@ +#include "pr10728-x.h" + +int main() +{ + X* x = y(); + return 0; // marker 1 +} Index: gdb/testsuite/gdb.cp/pr10728-x.h =================================================================== RCS file: gdb/testsuite/gdb.cp/pr10728-x.h diff -N gdb/testsuite/gdb.cp/pr10728-x.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gdb/testsuite/gdb.cp/pr10728-x.h 27 Jan 2010 18:56:45 -0000 @@ -0,0 +1,9 @@ +struct Y; +struct X +{ + Y* y1; + Y* y2; +}; + +X* y(); + Index: gdb/testsuite/gdb.cp/pr10728-y.cc =================================================================== RCS file: gdb/testsuite/gdb.cp/pr10728-y.cc diff -N gdb/testsuite/gdb.cp/pr10728-y.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gdb/testsuite/gdb.cp/pr10728-y.cc 27 Jan 2010 18:56:45 -0000 @@ -0,0 +1,11 @@ +#include "pr10728-x.h" +struct Y{}; + +X* y() +{ + static X xx; + static Y yy; + xx.y1 = &yy; + xx.y2 = xx.y1+1; + return &xx; +} Index: gdb/testsuite/gdb.cp/pr10728.exp =================================================================== RCS file: gdb/testsuite/gdb.cp/pr10728.exp diff -N gdb/testsuite/gdb.cp/pr10728.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gdb/testsuite/gdb.cp/pr10728.exp 27 Jan 2010 18:56:45 -0000 @@ -0,0 +1,73 @@ +# Copyright 2010 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 +# 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 . + +# This file is part of the gdb testsuite + +set nl "\[\r\n\]+" + +if { [skip_cplus_tests] } { continue } + +load_lib "cp-support.exp" + +set testfile "pr10728" +set srcfile ${testfile}-x.cc +set tfx ${testfile}-x +set tfy ${testfile}-y +set binfile ${objdir}/${subdir}/${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${tfy}.cc" "${tfy}.o" object {c++}] != "" } { + untested psmang.exp + return -1 +} + +if { [gdb_compile "${srcdir}/${subdir}/${tfx}.cc" "${tfx}.o" object {debug c++}] != "" } { + untested psmang.exp + return -1 +} + +if { [gdb_compile "${tfx}.o ${tfy}.o" ${binfile} executable {debug c++}] != "" } { + untested psmang.exp + return -1 +} + + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint" + continue +} + +# set a breakpoint at the return stmt + +gdb_breakpoint [gdb_get_line_number "marker 1"] +gdb_continue_to_breakpoint "marker 1" + +send_gdb "print x->y2 - x->y1\n" + +gdb_expect { + -re "warning: Type size unknown, assuming 1\. Try casting to a known type, or void \*\.\[^=\]*= 1" { + pass "print x->y2 - x->y1" + } + timeout { fail "(timeout) print x->y2 - x->y1" } +} + +gdb_exit +return 0 + +