diff options
author | Daniel Jacobowitz <drow@false.org> | 2008-09-08 22:16:51 +0000 |
---|---|---|
committer | Daniel Jacobowitz <drow@false.org> | 2008-09-08 22:16:51 +0000 |
commit | 694182d2ba45b3a4e97846f59cf04b75ad66901a (patch) | |
tree | 941a3baa7a87ff8f6b50a2556fb61a25a5f5ac6a /gdb | |
parent | dcf4fbde10e63c5cc5fa08b7280b751d01a8efaf (diff) | |
download | gdb-694182d2ba45b3a4e97846f59cf04b75ad66901a.zip gdb-694182d2ba45b3a4e97846f59cf04b75ad66901a.tar.gz gdb-694182d2ba45b3a4e97846f59cf04b75ad66901a.tar.bz2 |
* valops.c (value_cast_structs): Return NULL for failure.
(value_cast): Handle NULL from value_cast_structs.
(value_fetch_lazy): Call check_typedef. Remove unused variable.
testsuite/
* gdb.base/structs3.c, gdb.base/structs3.exp: New files.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/structs3.c | 42 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/structs3.exp | 37 | ||||
-rw-r--r-- | gdb/valops.c | 16 |
5 files changed, 100 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c679592..8edf7dd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2008-09-08 Daniel Jacobowitz <dan@codesourcery.com> + + * valops.c (value_cast_structs): Return NULL for failure. + (value_cast): Handle NULL from value_cast_structs. + (value_fetch_lazy): Call check_typedef. Remove unused variable. + 2008-09-08 Pedro Alves <pedro@codesourcery.com> * inferior.h (context_switch_to): Delete. diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 4044b60..59b26a4 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2008-09-08 Daniel Jacobowitz <dan@codesourcery.com> + + * gdb.base/structs3.c, gdb.base/structs3.exp: New files. + 2008-09-08 Jerome Guitton <guitton@adacore.com> * gdb.arch/powerpc-aix-prologue.c (stack_check_probe_1) diff --git a/gdb/testsuite/gdb.base/structs3.c b/gdb/testsuite/gdb.base/structs3.c new file mode 100644 index 0000000..0c20fd7 --- /dev/null +++ b/gdb/testsuite/gdb.base/structs3.c @@ -0,0 +1,42 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008 + 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 <http://www.gnu.org/licenses/>. */ + +struct One +{ + int x; +}; + +struct Two +{ + struct One one; + int x, y; +}; + +struct Two two = { { 1 }, 2, 3 }; + +typedef struct One tOne; +typedef struct Two tTwo; + +tOne *onep = &two.one; +tTwo *twop = &two; + +int main() +{ + onep->x = twop->y; + return 0; +} diff --git a/gdb/testsuite/gdb.base/structs3.exp b/gdb/testsuite/gdb.base/structs3.exp new file mode 100644 index 0000000..bec93b6 --- /dev/null +++ b/gdb/testsuite/gdb.base/structs3.exp @@ -0,0 +1,37 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2008 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 <http://www.gnu.org/licenses/>. + +set testfile "structs3" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [prepare_for_testing structs3.exp "structs3" "" {debug}] } { + return -1 +} + +set vhn "\\$\[0-9\]+" + +# Check the real contents. +gdb_test "print two" "$vhn = {one = {x = 1}, x = 2, y = 3}" + +# Check through the pointer. +gdb_test "print *twop" "$vhn = {one = {x = 1}, x = 2, y = 3}" + +# Check through a pointer to a smaller type, casted up. +gdb_test "print *(struct Two *)onep" "$vhn = {one = {x = 1}, x = 2, y = 3}" + +gdb_test "print *(tTwo *)onep" "$vhn = {one = {x = 1}, x = 2, y = 3}" diff --git a/gdb/valops.c b/gdb/valops.c index 4910649..0d1ffdf 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -193,7 +193,8 @@ allocate_space_in_inferior (int len) /* Cast struct value VAL to type TYPE and return as a value. Both type and val must be of TYPE_CODE_STRUCT or TYPE_CODE_UNION - for this to work. Typedef to one of the codes is permitted. */ + for this to work. Typedef to one of the codes is permitted. + Returns NULL if the cast is neither an upcast nor a downcast. */ static struct value * value_cast_structs (struct type *type, struct value *v2) @@ -244,7 +245,8 @@ value_cast_structs (struct type *type, struct value *v2) return value_at (type, addr2); } } - return v2; + + return NULL; } /* Cast one pointer or reference type to another. Both TYPE and @@ -397,7 +399,12 @@ value_cast (struct type *type, struct value *arg2) if ((code1 == TYPE_CODE_STRUCT || code1 == TYPE_CODE_UNION) && (code2 == TYPE_CODE_STRUCT || code2 == TYPE_CODE_UNION) && TYPE_NAME (type) != 0) - return value_cast_structs (type, arg2); + { + struct value *v = value_cast_structs (type, arg2); + if (v) + return v; + } + if (code1 == TYPE_CODE_FLT && scalar) return value_from_double (type, value_as_double (arg2)); else if (code1 == TYPE_CODE_DECFLOAT && scalar) @@ -615,9 +622,8 @@ value_fetch_lazy (struct value *val) if (VALUE_LVAL (val) == lval_memory) { CORE_ADDR addr = VALUE_ADDRESS (val) + value_offset (val); - int length = TYPE_LENGTH (value_enclosing_type (val)); + int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val))); - struct type *type = value_type (val); if (length) read_memory (addr, value_contents_all_raw (val), length); } |