aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-valprint.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2012-02-29 19:33:02 +0000
committerJoel Brobecker <brobecker@gnat.com>2012-02-29 19:33:02 +0000
commit2d4a02ee9526f370ccd9bdc3f30510f03ee59d19 (patch)
tree7b8bebd3cfae84ee7be07dbe758a0956444f9df1 /gdb/ada-valprint.c
parentc48db5caef25bc89b8f444300c7740f01405938b (diff)
downloadgdb-2d4a02ee9526f370ccd9bdc3f30510f03ee59d19.zip
gdb-2d4a02ee9526f370ccd9bdc3f30510f03ee59d19.tar.gz
gdb-2d4a02ee9526f370ccd9bdc3f30510f03ee59d19.tar.bz2
[Ada] Handle reference to array descriptors
This patch is to help handle aliased array variables, such as: type Bounded is array (Integer range <>) of Integer; function New_Bounded (Low, High : Integer) return Bounded; BT : aliased Bounded := New_Bounded (Low => 1, High => 3); In that case, the compiler describes variable "BT" as a reference to a thin pointer, and GDB is unable to print its value: (gdb) p bt $1 = The problems starts when ada_value_print deconstructs the struct value into contents and address in order to call val_print. It turns out in this case that "bt" is not an lval. In the debug information, this variable's location is described as: .uleb128 0xd # (DIE (0xe0) DW_TAG_variable) .ascii "bt\0" # DW_AT_name [...] .byte 0x6 # DW_AT_location .byte 0x91 # DW_OP_fbreg .sleb128 -56 .byte 0x6 # DW_OP_deref .byte 0x23 # DW_OP_plus_uconst .uleb128 0x8 .byte 0x9f # DW_OP_stack_value So, when ada_value_print passes the bt's (value) address, it passes in effect a meaningless address. The problem continues shortly after when ada_val_print_1 re-creates the value from the contents and address. The value has become an lval_memory, with a null address. As a result, we trigger a memory error later on, while trying to read the array bounds in order to transform our value into a simple array. To avoid the problem entirely, the fix is to coerce references before transforming array descriptors into simple arrays. gdb/ChangeLog: * ada-valprint.c (ada_val_print_1): If our value is a reference to an array descriptor, dereference it before converting it to a simple array. gdb/testsuite/ChangeLog: * gdb.ada/aliased_array: New testcase.
Diffstat (limited to 'gdb/ada-valprint.c')
-rw-r--r--gdb/ada-valprint.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index f43f3e3..5cb2f98 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -689,6 +689,10 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
struct value *val;
val = value_from_contents_and_address (type, valaddr + offset, address);
+ /* If this is a reference, coerce it now. This helps taking care
+ of the case where ADDRESS is meaningless because original_value
+ was not an lval. */
+ val = coerce_ref (val);
if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */
val = ada_coerce_to_simple_array_ptr (val);
else