* 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.
This commit is contained in:
parent
dcf4fbde10
commit
694182d2ba
@ -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.
|
||||
|
@ -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)
|
||||
|
42
gdb/testsuite/gdb.base/structs3.c
Normal file
42
gdb/testsuite/gdb.base/structs3.c
Normal file
@ -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;
|
||||
}
|
37
gdb/testsuite/gdb.base/structs3.exp
Normal file
37
gdb/testsuite/gdb.base/structs3.exp
Normal file
@ -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}"
|
16
gdb/valops.c
16
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user