2010-04-29 14:45:39 +00:00
|
|
|
/* Support for printing D values for GDB, the GNU debugger.
|
|
|
|
|
2011-01-01 15:34:07 +00:00
|
|
|
Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
2010-04-29 14:45:39 +00:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "gdbtypes.h"
|
|
|
|
#include "gdbcore.h"
|
|
|
|
#include "d-lang.h"
|
|
|
|
#include "c-lang.h"
|
|
|
|
|
|
|
|
/* Assuming that TYPE is a TYPE_CODE_STRUCT, verify that TYPE is
|
|
|
|
a dynamic array, and then print its value to STREAM. Return
|
|
|
|
the number of string characters printed, or -1 if TYPE is not
|
|
|
|
a dynamic array. */
|
|
|
|
static int
|
|
|
|
dynamic_array_type (struct type *type, const gdb_byte *valaddr,
|
|
|
|
int embedded_offset, CORE_ADDR address,
|
|
|
|
struct ui_file *stream, int recurse,
|
2010-06-11 15:36:10 +00:00
|
|
|
const struct value *val,
|
2010-04-29 14:45:39 +00:00
|
|
|
const struct value_print_options *options)
|
|
|
|
{
|
|
|
|
if (TYPE_NFIELDS (type) == 2
|
|
|
|
&& TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
|
|
|
|
&& strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
|
2010-06-11 15:36:10 +00:00
|
|
|
&& strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
|
|
|
|
&& value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
|
|
|
|
TARGET_CHAR_BIT * TYPE_LENGTH (type)))
|
2010-04-29 14:45:39 +00:00
|
|
|
{
|
|
|
|
CORE_ADDR addr;
|
|
|
|
struct type *elttype;
|
|
|
|
struct type *true_type;
|
|
|
|
struct type *ptr_type;
|
2011-02-27 21:24:27 +00:00
|
|
|
struct value *ival;
|
2010-04-29 14:45:39 +00:00
|
|
|
int length;
|
|
|
|
|
|
|
|
length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
|
|
|
|
|
|
|
|
ptr_type = TYPE_FIELD_TYPE (type, 1);
|
|
|
|
elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
|
|
|
|
addr = unpack_pointer (ptr_type,
|
|
|
|
valaddr + TYPE_FIELD_BITPOS (type, 1) / 8
|
|
|
|
+ embedded_offset);
|
|
|
|
true_type = check_typedef (elttype);
|
|
|
|
|
|
|
|
true_type = lookup_array_range_type (true_type, 0, length - 1);
|
2011-02-27 21:24:27 +00:00
|
|
|
ival = value_at (true_type, addr);
|
2010-04-29 14:45:39 +00:00
|
|
|
|
2011-01-24 Pedro Alves <pedro@codesourcery.com>
Don't lose embedded_offset in printing routines throughout.
gdb/
* valprint.h (val_print_array_elements): Change prototype.
* valprint.c (val_print_array_elements): Add `embedded_offset'
parameter, and adjust to pass it down to val_print, while passing
`valaddr' or `address' unmodified. Take embedded_offset into
account when checking repetitions.
* c-valprint.c (c_val_print): Pass embedded_offset to
val_print_array_elements instead of adjusting `valaddr' and
`address'.
* m2-valprint.c (m2_print_array_contents, m2_val_print): Pass
embedded_offset to val_print_array_elements instead of adjusting
`valaddr'.
* p-lang.h (pascal_object_print_value_fields): Adjust prototype.
* p-valprint.c (pascal_val_print): Pass embedded_offset to
val_print_array_elements and pascal_object_print_value_fields
instead of adjusting `valaddr'.
(pascal_object_print_value_fields): Add `offset' parameter, and
adjust to use it.
(pascal_object_print_value): Add `offset' parameter, and adjust to
use it.
(pascal_object_print_static_field): Use
value_contents_for_printing/value_embedded_offset, rather than
value_contents.
* ada-valprint.c (val_print_packed_array_elements): Add `offset'
parameter, and adjust to use it. Use
value_contents_for_printing/value_embedded_offset, rather than
value_contents.
(ada_val_print): Rename `valaddr0' parameter to `valaddr'.
(ada_val_print_array): Add `offset' parameter, and adjust to use
it.
(ada_val_print_1): Rename `valaddr0' parameter to `valaddr', and
`embedded_offset' to `offset'. Don't re-adjust `valaddr'.
Instead work with offsets. Use
value_contents_for_printing/value_embedded_offset, rather than
value_contents. Change `defer_val_int' local type to CORE_ADDR,
and use value_from_pointer to extract a target pointer, rather
than value_from_longest.
(print_variant_part): Add `offset' parameter. Replace
`outer_valaddr' parameter by a new `outer_offset' parameter.
Don't re-adjust `valaddr'. Instead pass down adjusted offsets.
(ada_value_print): Use
value_contents_for_printing/value_embedded_offset, rather than
value_contents.
(print_record): Add `offset' parameter, and adjust to pass it
down.
(print_field_values): Add `offset' parameter. Replace
`outer_valaddr' parameter by a new `outer_offset' parameter.
Don't re-adjust `valaddr'. Instead pass down adjusted offsets.
Use value_contents_for_printing/value_embedded_offset, rather than
value_contents.
* d-valprint.c (dynamic_array_type): Use
value_contents_for_printing/value_embedded_offset, rather than
value_contents.
* jv-valprint.c (java_print_value_fields): Add `offset' parameter.
Don't re-adjust `valaddr'. Instead pass down adjusted offsets.
(java_print_value_fields): Take `offset' into account. Don't
re-adjust `valaddr'. Instead pass down adjusted offsets.
(java_val_print): Take `embedded_offset' into account. Pass it to
java_print_value_fields.
* f-valprint.c (f77_print_array_1): Add `embedded_offset'
parameter. Don't re-adjust `valaddr' or `address'. Instead pass
down adjusted offsets.
(f77_print_array): Add `embedded_offset' parameter. Pass it down.
(f_val_print): Take `embedded_offset' into account.
gdb/testsuite/
* gdb.base/printcmds.c (some_struct): New struct and instance.
* gdb.base/printcmds.exp (test_print_repeats_embedded_array): New
procedure.
<global scope>: Call it.
2011-01-24 18:54:17 +00:00
|
|
|
return d_val_print (true_type,
|
2011-02-27 21:24:27 +00:00
|
|
|
value_contents_for_printing (ival),
|
|
|
|
value_embedded_offset (ival), addr,
|
|
|
|
stream, recurse + 1, ival, options);
|
2010-04-29 14:45:39 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implements the la_val_print routine for language D. */
|
|
|
|
int
|
|
|
|
d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
|
|
|
|
CORE_ADDR address, struct ui_file *stream, int recurse,
|
2010-06-11 15:36:10 +00:00
|
|
|
const struct value *val,
|
2010-04-29 14:45:39 +00:00
|
|
|
const struct value_print_options *options)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
switch (TYPE_CODE (type))
|
|
|
|
{
|
|
|
|
case TYPE_CODE_STRUCT:
|
|
|
|
ret = dynamic_array_type (type, valaddr, embedded_offset, address,
|
2010-06-11 15:36:10 +00:00
|
|
|
stream, recurse, val, options);
|
2010-04-29 14:45:39 +00:00
|
|
|
if (ret != -1)
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = c_val_print (type, valaddr, embedded_offset, address, stream,
|
2010-06-11 15:36:10 +00:00
|
|
|
recurse, val, options);
|
2010-04-29 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|