diff options
author | Joel Brobecker <brobecker@gnat.com> | 2010-04-20 22:26:57 +0000 |
---|---|---|
committer | Joel Brobecker <brobecker@gnat.com> | 2010-04-20 22:26:57 +0000 |
commit | 0c3acc092379d8b0c9d74a47c9cc03375dbad5fc (patch) | |
tree | 9e2defc0cfb6cf3c456579c6659ed110fda94792 /gdb/valprint.c | |
parent | 418205099be3d614ad92c8c78486b1a60b498916 (diff) | |
download | gdb-0c3acc092379d8b0c9d74a47c9cc03375dbad5fc.zip gdb-0c3acc092379d8b0c9d74a47c9cc03375dbad5fc.tar.gz gdb-0c3acc092379d8b0c9d74a47c9cc03375dbad5fc.tar.bz2 |
Wrong value printed by info locals for dynamic object.
The problem is printing the wrong value for dynamic local variables
when using the "info locals" command. Consider the following code:
procedure Print (I1 : Positive; I2 : Positive) is
type My_String is array (I1 .. I2) of Character;
I : My_String := (others => 'A');
S : String (1 .. I2 + 3) := (others => ' ');
begin
S (I1 .. I2) := String (I); -- BREAK
Put_Line (S);
end Print;
After the debugger stopped at BREAK, we try printing all local variables.
Here is what we get:
(gdb) info locals
i = "["00"]["00"]"
s = "["00"]["00"]["00"]["00"]["00"]["00"]["00"]["00"]"
Curiously, printing their value using the "print" command works:
(gdb) print i
$1 = "AA"
(gdb) print s
$2 = " "
We traced the problem to trying to get the contents of a variable
(call to value_contents) before "fix'ing" it. For those not familiar
with the Ada language support, "fixing" a value consists of swapping
the value's dynamic type with a static version that is appropriate
for our actual value. As a result, the dynamic type was used to
determine the value size, which is zero, and thus the value contents
was empty.
gdb/ChangeLog:
* valprint.c (common_val_print): Fix the value before extracting
its contents.
* ada-lang.c (ada_to_fixed_value): Make this function extern.
* ada-lang.h (ada_to_fixed_value): New function declaration.
* ada-valprint.c (ada_value_print): Use ada_to_fixed_value
to avoid code duplication and fix a bug in the handling of
fixed types contents.
gdb/testsuite/ChangeLog:
* gdb.ada/dyn_loc: New testcase.
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r-- | gdb/valprint.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c index 3f21ae4..d6ecc04 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -35,6 +35,7 @@ #include "exceptions.h" #include "dfp.h" #include "python/python.h" +#include "ada-lang.h" #include <errno.h> @@ -361,6 +362,13 @@ common_val_print (struct value *val, struct ui_file *stream, int recurse, if (!value_check_printable (val, stream)) return 0; + if (language->la_language == language_ada) + /* The value might have a dynamic type, which would cause trouble + below when trying to extract the value contents (since the value + size is determined from the type size which is unknown). So + get a fixed representation of our value. */ + val = ada_to_fixed_value (val); + return val_print (value_type (val), value_contents_all (val), value_embedded_offset (val), value_address (val), stream, recurse, options, language); |