gdb/d-valprint.c - gdb

Functions defined

Source code

  1. /* Support for printing D values for GDB, the GNU debugger.

  2.    Copyright (C) 2008-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "gdbtypes.h"
  16. #include "gdbcore.h"
  17. #include "d-lang.h"
  18. #include "c-lang.h"

  19. /* Assuming that TYPE is a TYPE_CODE_STRUCT, verify that TYPE is a
  20.    dynamic array, and then print its value to STREAM.  Return zero if
  21.    TYPE is a dynamic array, non-zero otherwise.  */

  22. static int
  23. dynamic_array_type (struct type *type, const gdb_byte *valaddr,
  24.                     int embedded_offset, CORE_ADDR address,
  25.                     struct ui_file *stream, int recurse,
  26.                     const struct value *val,
  27.                     const struct value_print_options *options)
  28. {
  29.   if (TYPE_NFIELDS (type) == 2
  30.       && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
  31.       && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
  32.       && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
  33.       && !value_bits_any_optimized_out (val,
  34.                                         TARGET_CHAR_BIT * embedded_offset,
  35.                                         TARGET_CHAR_BIT * TYPE_LENGTH (type)))
  36.     {
  37.       CORE_ADDR addr;
  38.       struct type *elttype;
  39.       struct type *true_type;
  40.       struct type *ptr_type;
  41.       struct value *ival;
  42.       int length;

  43.       length = unpack_field_as_long (type, valaddr + embedded_offset, 0);

  44.       ptr_type = TYPE_FIELD_TYPE (type, 1);
  45.       elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
  46.       addr = unpack_pointer (ptr_type,
  47.                              valaddr + TYPE_FIELD_BITPOS (type, 1) / 8
  48.                              + embedded_offset);
  49.       true_type = check_typedef (elttype);

  50.       true_type = lookup_array_range_type (true_type, 0, length - 1);
  51.       ival = value_at (true_type, addr);
  52.       true_type = value_type (ival);

  53.       d_val_print (true_type,
  54.                    value_contents_for_printing (ival),
  55.                    value_embedded_offset (ival), addr,
  56.                    stream, recurse + 1, ival, options);
  57.       return 0;
  58.     }
  59.   return 1;
  60. }

  61. /* Implements the la_val_print routine for language D.  */
  62. void
  63. d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
  64.              CORE_ADDR address, struct ui_file *stream, int recurse,
  65.              const struct value *val,
  66.              const struct value_print_options *options)
  67. {
  68.   int ret;

  69.   CHECK_TYPEDEF (type);
  70.   switch (TYPE_CODE (type))
  71.     {
  72.       case TYPE_CODE_STRUCT:
  73.         ret = dynamic_array_type (type, valaddr, embedded_offset, address,
  74.                                   stream, recurse, val, options);
  75.         if (ret == 0)
  76.           break;
  77.       default:
  78.         c_val_print (type, valaddr, embedded_offset, address, stream,
  79.                      recurse, val, options);
  80.     }
  81. }