]>
Commit | Line | Data |
---|---|---|
6aecb9c2 JB |
1 | /* Support for printing D values for GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | Copyright (C) 2008-2024 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 | 30 | static int |
e8b24d9f | 31 | dynamic_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 |
940da03e | 38 | && type->field (0).type ()->code () == TYPE_CODE_INT |
33d16dd9 SM |
39 | && strcmp (type->field (0).name (), "length") == 0 |
40 | && strcmp (type->field (1).name (), "ptr") == 0 | |
d00664db TT |
41 | && !val->bits_any_optimized_out (TARGET_CHAR_BIT * embedded_offset, |
42 | TARGET_CHAR_BIT * type->length ())) | |
6aecb9c2 JB |
43 | { |
44 | CORE_ADDR addr; | |
45 | struct type *elttype; | |
46 | struct type *true_type; | |
47 | struct type *ptr_type; | |
7d488639 | 48 | struct value *ival; |
6aecb9c2 | 49 | int length; |
efaf1ae0 | 50 | const gdb_byte *valaddr = val->contents_for_printing ().data (); |
6aecb9c2 JB |
51 | |
52 | length = unpack_field_as_long (type, valaddr + embedded_offset, 0); | |
53 | ||
940da03e | 54 | ptr_type = type->field (1).type (); |
27710edb | 55 | elttype = check_typedef (ptr_type->target_type ()); |
6aecb9c2 | 56 | addr = unpack_pointer (ptr_type, |
b610c045 | 57 | valaddr + type->field (1).loc_bitpos () / 8 |
6aecb9c2 JB |
58 | + embedded_offset); |
59 | true_type = check_typedef (elttype); | |
60 | ||
61 | true_type = lookup_array_range_type (true_type, 0, length - 1); | |
7d488639 | 62 | ival = value_at (true_type, addr); |
d0c97917 | 63 | true_type = ival->type (); |
6aecb9c2 | 64 | |
d133c3e1 | 65 | d_value_print_inner (ival, stream, recurse + 1, options); |
d3eab38a | 66 | return 0; |
6aecb9c2 | 67 | } |
d3eab38a | 68 | return 1; |
6aecb9c2 JB |
69 | } |
70 | ||
d133c3e1 TT |
71 | /* See d-lang.h. */ |
72 | ||
73 | void | |
74 | d_value_print_inner (struct value *val, struct ui_file *stream, int recurse, | |
75 | const struct value_print_options *options) | |
76 | { | |
77 | int ret; | |
78 | ||
d0c97917 | 79 | struct type *type = check_typedef (val->type ()); |
78134374 | 80 | switch (type->code ()) |
d133c3e1 TT |
81 | { |
82 | case TYPE_CODE_STRUCT: | |
391f8628 | 83 | ret = dynamic_array_type (type, val->embedded_offset (), |
9feb2d07 | 84 | val->address (), |
d133c3e1 TT |
85 | stream, recurse, val, options); |
86 | if (ret == 0) | |
87 | break; | |
d182e398 | 88 | [[fallthrough]]; |
d133c3e1 TT |
89 | default: |
90 | c_value_print_inner (val, stream, recurse, options); | |
91 | break; | |
92 | } | |
93 | } |