This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit/Ada] variables whose type is a typedef to an array pointer
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Cc: Joel Brobecker <brobecker at adacore dot com>
- Date: Fri, 1 Jul 2011 11:45:31 -0700
- Subject: [commit/Ada] variables whose type is a typedef to an array pointer
If we declare a type as being an access to array type, and then
declare a variable of that type, for instance:
type Some_Array is array [...];
type Array_Access is access all Some_Array;
Table : Array_Access := [...];
The variable "Table" may be defined in the debugging information
as being a typedef to the array pointer type. In the past, it was
defined directly as the array pointer type, but this has been changed
to make sure that the typedef type gets used.
If the typedef type wasn't used, it would allow the compiler to stop
emitting that typedef type when compiling with
-feliminate-unused-debug-types. The removal of this typedef would
be a problem, because GDB relies on the typedef to create symbols
for pointer types, and without it, we would no longer be able to
do "ptype array_access".
This patch helps prevent incorrect output or even crashes when that
extra typedef layer is used.
The testing is already mostly covered by arrayptr.exp, but I still
added a 'ptype' test, just for good measure.
gdb/ChangeLog: (Eric Botcazou)
* ada-lang.c (thin_descriptor_type): Deal with typedefs.
(decode_constrained_packed_array): Likewise.
(ada_evaluate_subexp) <TERNOP_SLICE>: Likewise.
gdb/testsuite/ChangeLog (Joel Brobecker):
* gdb.ada/arrayptr.exp: Add ptype test.
Tested on x86_64-linux. Checked in.
---
gdb/ChangeLog | 6 ++++++
gdb/ada-lang.c | 15 ++++++++-------
gdb/testsuite/ChangeLog | 4 ++++
gdb/testsuite/gdb.ada/arrayptr.exp | 2 ++
4 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 87832cf..699b40c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2011-07-01 Eric Botcazou <ebotcazou@adacore.com>
+
+ * ada-lang.c (thin_descriptor_type): Deal with typedefs.
+ (decode_constrained_packed_array): Likewise.
+ (ada_evaluate_subexp) <TERNOP_SLICE>: Likewise.
+
2011-07-01 Joel Brobecker <brobecker@adacore.com>
* ada-exp.y (convert_char_literal): Handle typedef types.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 4f6e161..3e30c9e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1443,7 +1443,7 @@ thin_descriptor_type (struct type *type)
static struct value *
thin_data_pntr (struct value *val)
{
- struct type *type = value_type (val);
+ struct type *type = ada_check_typedef (value_type (val));
struct type *data_type = desc_data_target_type (thin_descriptor_type (type));
data_type = lookup_pointer_type (data_type);
@@ -2093,7 +2093,7 @@ decode_constrained_packed_array (struct value *arr)
of the routine assumes that the array hasn't been decoded yet,
so we use the basic "value_ind" routine to perform the dereferencing,
as opposed to using "ada_value_ind". */
- if (TYPE_CODE (value_type (arr)) == TYPE_CODE_PTR)
+ if (TYPE_CODE (ada_check_typedef (value_type (arr))) == TYPE_CODE_PTR)
arr = value_ind (arr);
type = decode_constrained_packed_array_type (value_type (arr));
@@ -9522,16 +9522,17 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
if (!ada_is_simple_array_type (value_type (array)))
error (_("cannot take slice of non-array"));
- if (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR)
+ if (TYPE_CODE (ada_check_typedef (value_type (array)))
+ == TYPE_CODE_PTR)
{
+ struct type *type0 = ada_check_typedef (value_type (array));
+
if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS)
- return empty_array (TYPE_TARGET_TYPE (value_type (array)),
- low_bound);
+ return empty_array (TYPE_TARGET_TYPE (type0), low_bound);
else
{
struct type *arr_type0 =
- to_fixed_array_type (TYPE_TARGET_TYPE (value_type (array)),
- NULL, 1);
+ to_fixed_array_type (TYPE_TARGET_TYPE (type0), NULL, 1);
return ada_value_slice_from_ptr (array, arr_type0,
longest_to_int (low_bound),
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a27a8bd..1dc763d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2011-07-01 Joel Brobecker <brobecker@adacore.com>
+ * gdb.ada/arrayptr.exp: Add ptype test.
+
+2011-07-01 Joel Brobecker <brobecker@adacore.com>
+
* gdb.ada/char_enum: New testcase.
2011-07-01 Yao Qi <yao@codesourcery.com>
diff --git a/gdb/testsuite/gdb.ada/arrayptr.exp b/gdb/testsuite/gdb.ada/arrayptr.exp
index ba30d61..9b06bc1 100644
--- a/gdb/testsuite/gdb.ada/arrayptr.exp
+++ b/gdb/testsuite/gdb.ada/arrayptr.exp
@@ -51,3 +51,5 @@ gdb_test "print arr_ptr (2)" "= 22"
gdb_test "print arr_ptr (3..4)" "= \\(3 => 23, 24\\)"
+gdb_test "ptype string_access" "= access array \\(<>\\) of character"
+
--
1.7.1