gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / d-valprint.c
CommitLineData
6aecb9c2
JB
1/* Support for printing D values for GDB, the GNU debugger.
2
b811d2c2 3 Copyright (C) 2008-2020 Free Software Foundation, Inc.
6aecb9c2
JB
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"
d55e5aa6 21#include "gdbtypes.h"
4de283e4
TT
22#include "gdbcore.h"
23#include "d-lang.h"
24#include "c-lang.h"
6aecb9c2 25
d3eab38a
TT
26/* Assuming that TYPE is a TYPE_CODE_STRUCT, verify that TYPE is a
27 dynamic array, and then print its value to STREAM. Return zero if
28 TYPE is a dynamic array, non-zero otherwise. */
29
6aecb9c2 30static int
e8b24d9f 31dynamic_array_type (struct type *type,
6b850546 32 LONGEST embedded_offset, CORE_ADDR address,
6aecb9c2 33 struct ui_file *stream, int recurse,
e8b24d9f 34 struct value *val,
6aecb9c2
JB
35 const struct value_print_options *options)
36{
1f704f76 37 if (type->num_fields () == 2
78134374 38 && TYPE_FIELD_TYPE (type, 0)->code () == TYPE_CODE_INT
6aecb9c2 39 && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
0e03807e 40 && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
9a0dc9e3
PA
41 && !value_bits_any_optimized_out (val,
42 TARGET_CHAR_BIT * embedded_offset,
43 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
6aecb9c2
JB
44 {
45 CORE_ADDR addr;
46 struct type *elttype;
47 struct type *true_type;
48 struct type *ptr_type;
7d488639 49 struct value *ival;
6aecb9c2 50 int length;
e8b24d9f 51 const gdb_byte *valaddr = value_contents_for_printing (val);
6aecb9c2
JB
52
53 length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
54
55 ptr_type = TYPE_FIELD_TYPE (type, 1);
56 elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
57 addr = unpack_pointer (ptr_type,
58 valaddr + TYPE_FIELD_BITPOS (type, 1) / 8
59 + embedded_offset);
60 true_type = check_typedef (elttype);
61
62 true_type = lookup_array_range_type (true_type, 0, length - 1);
7d488639 63 ival = value_at (true_type, addr);
9f1f738a 64 true_type = value_type (ival);
6aecb9c2 65
d133c3e1 66 d_value_print_inner (ival, stream, recurse + 1, options);
d3eab38a 67 return 0;
6aecb9c2 68 }
d3eab38a 69 return 1;
6aecb9c2
JB
70}
71
d133c3e1
TT
72/* See d-lang.h. */
73
74void
75d_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
76 const struct value_print_options *options)
77{
78 int ret;
79
80 struct type *type = check_typedef (value_type (val));
78134374 81 switch (type->code ())
d133c3e1
TT
82 {
83 case TYPE_CODE_STRUCT:
84 ret = dynamic_array_type (type, value_embedded_offset (val),
85 value_address (val),
86 stream, recurse, val, options);
87 if (ret == 0)
88 break;
89 /* Fall through. */
90 default:
91 c_value_print_inner (val, stream, recurse, options);
92 break;
93 }
94}
This page took 0.743174 seconds and 4 git commands to generate.