D language support.
[deliverable/binutils-gdb.git] / gdb / d-valprint.c
CommitLineData
6aecb9c2
JB
1/* Support for printing D values for GDB, the GNU debugger.
2
3 Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "gdbtypes.h"
22#include "gdbcore.h"
23#include "d-lang.h"
24#include "c-lang.h"
25
26/* Assuming that TYPE is a TYPE_CODE_STRUCT, verify that TYPE is
27 a dynamic array, and then print its value to STREAM. Return
28 the number of string characters printed, or -1 if TYPE is not
29 a dynamic array. */
30static int
31dynamic_array_type (struct type *type, const gdb_byte *valaddr,
32 int embedded_offset, CORE_ADDR address,
33 struct ui_file *stream, int recurse,
34 const struct value_print_options *options)
35{
36 if (TYPE_NFIELDS (type) == 2
37 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
38 && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
39 && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0)
40 {
41 CORE_ADDR addr;
42 struct type *elttype;
43 struct type *true_type;
44 struct type *ptr_type;
45 struct type *range_type;
46 const gdb_byte *ptraddr;
47 struct value *val;
48 int length;
49
50 length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
51
52 ptr_type = TYPE_FIELD_TYPE (type, 1);
53 elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
54 addr = unpack_pointer (ptr_type,
55 valaddr + TYPE_FIELD_BITPOS (type, 1) / 8
56 + embedded_offset);
57 true_type = check_typedef (elttype);
58
59 true_type = lookup_array_range_type (true_type, 0, length - 1);
60 val = value_at (true_type, addr);
61 ptraddr = value_contents (val);
62
63 return d_val_print (true_type, ptraddr, 0, addr, stream, recurse + 1,
64 options);
65 }
66 return -1;
67}
68
69/* Implements the la_val_print routine for language D. */
70int
71d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
72 CORE_ADDR address, struct ui_file *stream, int recurse,
73 const struct value_print_options *options)
74{
75 int ret;
76
77 CHECK_TYPEDEF (type);
78 switch (TYPE_CODE (type))
79 {
80 case TYPE_CODE_STRUCT:
81 ret = dynamic_array_type (type, valaddr, embedded_offset, address,
82 stream, recurse, options);
83 if (ret != -1)
84 break;
85 default:
86 ret = c_val_print (type, valaddr, embedded_offset, address, stream,
87 recurse, options);
88 }
89
90 return ret;
91}
This page took 0.026628 seconds and 4 git commands to generate.