From f3134b888619774c6511acbf8d978bd7427ce1ad Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 30 Oct 2008 21:44:15 +0000 Subject: [PATCH] gdb * value.c (coerce_array): Use check_typedef. gdb/testsuite * gdb.base/pointers.exp: Add test. * gdb.base/pointers.c (k, S): New typedefs. (instance): New global. --- gdb/ChangeLog | 4 ++++ gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.base/pointers.c | 9 +++++++++ gdb/testsuite/gdb.base/pointers.exp | 4 ++++ gdb/value.c | 19 ++++++++++++++----- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6bb1c9b288a..00c4fb7d66c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2008-10-02 Tom Tromey + + * value.c (coerce_array): Use check_typedef. + 2008-10-28 Tom Tromey * cli/cli-logging.c (handle_redirections): Make a cleanup. diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 9ad4f2d68db..65966acefd5 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-10-30 Tom Tromey + + * gdb.base/pointers.exp: Add test. + * gdb.base/pointers.c (k, S): New typedefs. + (instance): New global. + 2008-10-30 Andreas Schwab * gdb.base/args.exp: Add tests for newlines. diff --git a/gdb/testsuite/gdb.base/pointers.c b/gdb/testsuite/gdb.base/pointers.c index 85bfdc98917..4ee5e78a04a 100644 --- a/gdb/testsuite/gdb.base/pointers.c +++ b/gdb/testsuite/gdb.base/pointers.c @@ -71,6 +71,15 @@ float ** ptr_to_ptr_to_float; int y; + +typedef long k[5]; + +typedef struct { + k array_variable; +} S; + +S instance; + /* Do nothing function used for forcing some of the above variables to be referenced by the program source. If the variables are not referenced, some linkers will remove the symbol from the symbol diff --git a/gdb/testsuite/gdb.base/pointers.exp b/gdb/testsuite/gdb.base/pointers.exp index 55321404cf2..d7d17e777cd 100644 --- a/gdb/testsuite/gdb.base/pointers.exp +++ b/gdb/testsuite/gdb.base/pointers.exp @@ -596,3 +596,7 @@ gdb_expect { timeout { fail "(timeout) ptype ppppppC" } } +# Regression test for a crash. + +gdb_test "p instance.array_variable + 0" \ + " = \\(long int \\*\\) 0x\[0-9a-f\]*" diff --git a/gdb/value.c b/gdb/value.c index 1fa376d6555..695aa334390 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1728,12 +1728,21 @@ coerce_ref (struct value *arg) struct value * coerce_array (struct value *arg) { + struct type *type; + arg = coerce_ref (arg); - if (current_language->c_style_arrays - && TYPE_CODE (value_type (arg)) == TYPE_CODE_ARRAY) - arg = value_coerce_array (arg); - if (TYPE_CODE (value_type (arg)) == TYPE_CODE_FUNC) - arg = value_coerce_function (arg); + type = check_typedef (value_type (arg)); + + switch (TYPE_CODE (type)) + { + case TYPE_CODE_ARRAY: + if (current_language->c_style_arrays) + arg = value_coerce_array (arg); + break; + case TYPE_CODE_FUNC: + arg = value_coerce_function (arg); + break; + } return arg; } -- 2.30.2