diff options
author | Joel Brobecker <brobecker@adacore.com> | 2018-01-05 02:37:38 -0500 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2018-01-05 02:41:28 -0500 |
commit | cc0e770c0d00acececc43826f4673896d09b3dff (patch) | |
tree | da78382b495b44e81d9fb00ed26c1ef916e6b251 /gdb/ada-lang.c | |
parent | f79da888eb68d5add4eaa7f336923cad95367335 (diff) | |
download | gdb-cc0e770c0d00acececc43826f4673896d09b3dff.zip gdb-cc0e770c0d00acececc43826f4673896d09b3dff.tar.gz gdb-cc0e770c0d00acececc43826f4673896d09b3dff.tar.bz2 |
memory error printing component of record from convenience variable
Consider the following situation Ada code:
type Kind_T is (One, Two, Three);
type Time_Set_T is array (Kind_T) of Integer;
type T is record
Started : Time_Set_T;
end record;
Null_T : constant T := (Started => (others => 0));
My_Item : Pck.T := Pck.Null_T;
Trying to print the value of My_Item.Started is no problem:
(gdb) p item.started
$1 = (0, 0, 0)
However, if you save My_Item into a convenience variable first,
and then try to print a component of that record, you get
an unexpected memory error, instead of getting the same result.
For instance:
(gdb) set variable $item := item
(gdb) p $item.started
Cannot access memory at address 0x0
The issue occurs when, after we extracted the component from
the convenience variable, we next try to "fix" it (which is
ada-lang speak for resolving the type into a static type).
This is done in ada_to_fixed_value, which delegates to
ada_to_fixed_value_create via:
val = ada_to_fixed_value_create (value_type (val),
value_address (val), val);
And looking at ada_to_fixed_value_create, we see that:
struct type *type = ada_to_fixed_type (type0, 0, address, NULL, 1);
if (type == type0 && val0 != NULL)
return val0;
else
return value_from_contents_and_address (type, 0, address);
The part that interests us, in this case, is the "else" branch,
where we obviously make the implicit assumption that our object
has an address, which is not true, in this case, because we are
actually dealing with a convenience variable.
This patch plugs that hole by adding special handing for situations
where val does not live in memory. In that case, we just create
a not_lval value using val's contents.
gdb/ChangeLog:
* ada-lang.c (ada_to_fixed_value_create): Add handling of
the case where VALUE_LVAL (val0) is not lval_memory.
gdb/testsuite/ChangeLog:
* gdb.ada/convvar_comp: New testcase.
Tested on x86_64-linux.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r-- | gdb/ada-lang.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 4ecf7b0..85e50cc 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -9344,8 +9344,16 @@ ada_to_fixed_value_create (struct type *type0, CORE_ADDR address, if (type == type0 && val0 != NULL) return val0; - else - return value_from_contents_and_address (type, 0, address); + + if (VALUE_LVAL (val0) != lval_memory) + { + /* Our value does not live in memory; it could be a convenience + variable, for instance. Create a not_lval value using val0's + contents. */ + return value_from_contents (type, value_contents (val0)); + } + + return value_from_contents_and_address (type, 0, address); } /* A value representing VAL, but with a standard (static-sized) type |