]>
Commit | Line | Data |
---|---|---|
6aecb9c2 JB |
1 | /* D language support routines for GDB, the GNU debugger. |
2 | ||
d01e8234 | 3 | Copyright (C) 2005-2025 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 | ||
d55e5aa6 | 20 | #include "symtab.h" |
4de283e4 | 21 | #include "language.h" |
d55e5aa6 | 22 | #include "varobj.h" |
4de283e4 TT |
23 | #include "d-lang.h" |
24 | #include "c-lang.h" | |
25 | #include "demangle.h" | |
26 | #include "cp-support.h" | |
0d12e84c | 27 | #include "gdbarch.h" |
af30c400 | 28 | #include "parser-defs.h" |
6aecb9c2 | 29 | |
63778547 IB |
30 | /* The name of the symbol to use to get the name of the main subprogram. */ |
31 | static const char D_MAIN[] = "D main"; | |
32 | ||
33 | /* Function returning the special symbol name used by D for the main | |
34 | procedure in the main program if it is found in minimal symbol list. | |
35 | This function tries to find minimal symbols so that it finds them even | |
36 | if the program was compiled without debugging information. */ | |
37 | ||
38 | const char * | |
39 | d_main_name (void) | |
40 | { | |
4144d36a SM |
41 | bound_minimal_symbol msym |
42 | = lookup_minimal_symbol (current_program_space, D_MAIN); | |
3b7344d5 | 43 | if (msym.minsym != NULL) |
63778547 IB |
44 | return D_MAIN; |
45 | ||
46 | /* No known entry procedure found, the main program is probably not D. */ | |
47 | return NULL; | |
48 | } | |
49 | ||
6aecb9c2 | 50 | /* Implements the la_demangle language_defn routine for language D. */ |
ec9f644a | 51 | |
3456e70c | 52 | gdb::unique_xmalloc_ptr<char> |
6aecb9c2 JB |
53 | d_demangle (const char *symbol, int options) |
54 | { | |
35a49624 | 55 | return gdb_demangle (symbol, options | DMGL_DLANG); |
6aecb9c2 JB |
56 | } |
57 | ||
0874fd07 AB |
58 | /* Class representing the D language. */ |
59 | ||
60 | class d_language : public language_defn | |
61 | { | |
62 | public: | |
63 | d_language () | |
0e25e767 | 64 | : language_defn (language_d) |
0874fd07 | 65 | { /* Nothing. */ } |
1fb314aa | 66 | |
6f7664a9 AB |
67 | /* See language.h. */ |
68 | ||
69 | const char *name () const override | |
70 | { return "d"; } | |
71 | ||
72 | /* See language.h. */ | |
73 | ||
74 | const char *natural_name () const override | |
75 | { return "D"; } | |
76 | ||
e171d6f1 AB |
77 | /* See language.h. */ |
78 | ||
79 | const std::vector<const char *> &filename_extensions () const override | |
80 | { | |
81 | static const std::vector<const char *> extensions = { ".d" }; | |
82 | return extensions; | |
83 | } | |
84 | ||
1fb314aa AB |
85 | /* See language.h. */ |
86 | void language_arch_info (struct gdbarch *gdbarch, | |
87 | struct language_arch_info *lai) const override | |
88 | { | |
89 | const struct builtin_d_type *builtin = builtin_d_type (gdbarch); | |
90 | ||
7bea47f0 AB |
91 | /* Helper function to allow shorter lines below. */ |
92 | auto add = [&] (struct type * t) | |
93 | { | |
94 | lai->add_primitive_type (t); | |
95 | }; | |
96 | ||
97 | add (builtin->builtin_void); | |
98 | add (builtin->builtin_bool); | |
99 | add (builtin->builtin_byte); | |
100 | add (builtin->builtin_ubyte); | |
101 | add (builtin->builtin_short); | |
102 | add (builtin->builtin_ushort); | |
103 | add (builtin->builtin_int); | |
104 | add (builtin->builtin_uint); | |
105 | add (builtin->builtin_long); | |
106 | add (builtin->builtin_ulong); | |
107 | add (builtin->builtin_cent); | |
108 | add (builtin->builtin_ucent); | |
109 | add (builtin->builtin_float); | |
110 | add (builtin->builtin_double); | |
111 | add (builtin->builtin_real); | |
112 | add (builtin->builtin_ifloat); | |
113 | add (builtin->builtin_idouble); | |
114 | add (builtin->builtin_ireal); | |
115 | add (builtin->builtin_cfloat); | |
116 | add (builtin->builtin_cdouble); | |
117 | add (builtin->builtin_creal); | |
118 | add (builtin->builtin_char); | |
119 | add (builtin->builtin_wchar); | |
120 | add (builtin->builtin_dchar); | |
121 | ||
122 | lai->set_string_char_type (builtin->builtin_char); | |
123 | lai->set_bool_type (builtin->builtin_bool, "bool"); | |
1fb314aa | 124 | } |
6f827019 AB |
125 | |
126 | /* See language.h. */ | |
3456e70c TT |
127 | bool sniff_from_mangled_name |
128 | (const char *mangled, | |
129 | gdb::unique_xmalloc_ptr<char> *demangled) const override | |
6f827019 AB |
130 | { |
131 | *demangled = d_demangle (mangled, 0); | |
132 | return *demangled != NULL; | |
133 | } | |
fbfb0a46 AB |
134 | |
135 | /* See language.h. */ | |
136 | ||
3456e70c TT |
137 | gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled, |
138 | int options) const override | |
0a50df5d AB |
139 | { |
140 | return d_demangle (mangled, options); | |
141 | } | |
142 | ||
143 | /* See language.h. */ | |
144 | ||
97e20099 TT |
145 | bool can_print_type_offsets () const override |
146 | { | |
147 | return true; | |
148 | } | |
149 | ||
150 | /* See language.h. */ | |
151 | ||
fbfb0a46 AB |
152 | void print_type (struct type *type, const char *varstring, |
153 | struct ui_file *stream, int show, int level, | |
154 | const struct type_print_options *flags) const override | |
155 | { | |
1c6fbf42 | 156 | c_print_type (type, varstring, stream, show, level, la_language, flags); |
fbfb0a46 | 157 | } |
ebe2334e AB |
158 | |
159 | /* See language.h. */ | |
160 | ||
161 | void value_print_inner | |
162 | (struct value *val, struct ui_file *stream, int recurse, | |
163 | const struct value_print_options *options) const override | |
164 | { | |
165 | return d_value_print_inner (val, stream, recurse, options); | |
166 | } | |
a78a19b1 AB |
167 | |
168 | /* See language.h. */ | |
169 | ||
170 | struct block_symbol lookup_symbol_nonlocal | |
171 | (const char *name, const struct block *block, | |
ccf41c24 | 172 | const domain_search_flags domain) const override |
a78a19b1 AB |
173 | { |
174 | return d_lookup_symbol_nonlocal (this, name, block, domain); | |
175 | } | |
87afa652 AB |
176 | |
177 | /* See language.h. */ | |
178 | ||
179 | int parser (struct parser_state *ps) const override | |
180 | { | |
181 | return d_parse (ps); | |
182 | } | |
5bae7c4e AB |
183 | |
184 | /* See language.h. */ | |
185 | ||
186 | const char *name_of_this () const override | |
187 | { return "this"; } | |
0874fd07 AB |
188 | }; |
189 | ||
190 | /* Single instance of the D language class. */ | |
191 | ||
192 | static d_language d_language_defn; | |
193 | ||
94b1b47e IB |
194 | /* Build all D language types for the specified architecture. */ |
195 | ||
cb275538 | 196 | static struct builtin_d_type * |
94b1b47e IB |
197 | build_d_types (struct gdbarch *gdbarch) |
198 | { | |
cb275538 | 199 | struct builtin_d_type *builtin_d_type = new struct builtin_d_type; |
94b1b47e IB |
200 | |
201 | /* Basic types. */ | |
2d39ccd3 | 202 | type_allocator alloc (gdbarch); |
95751990 | 203 | builtin_d_type->builtin_void = builtin_type (gdbarch)->builtin_void; |
94b1b47e | 204 | builtin_d_type->builtin_bool |
46c04ea3 | 205 | = init_boolean_type (alloc, 8, 1, "bool"); |
94b1b47e | 206 | builtin_d_type->builtin_byte |
2d39ccd3 | 207 | = init_integer_type (alloc, 8, 0, "byte"); |
94b1b47e | 208 | builtin_d_type->builtin_ubyte |
2d39ccd3 | 209 | = init_integer_type (alloc, 8, 1, "ubyte"); |
94b1b47e | 210 | builtin_d_type->builtin_short |
2d39ccd3 | 211 | = init_integer_type (alloc, 16, 0, "short"); |
94b1b47e | 212 | builtin_d_type->builtin_ushort |
2d39ccd3 | 213 | = init_integer_type (alloc, 16, 1, "ushort"); |
94b1b47e | 214 | builtin_d_type->builtin_int |
2d39ccd3 | 215 | = init_integer_type (alloc, 32, 0, "int"); |
94b1b47e | 216 | builtin_d_type->builtin_uint |
2d39ccd3 | 217 | = init_integer_type (alloc, 32, 1, "uint"); |
94b1b47e | 218 | builtin_d_type->builtin_long |
2d39ccd3 | 219 | = init_integer_type (alloc, 64, 0, "long"); |
94b1b47e | 220 | builtin_d_type->builtin_ulong |
2d39ccd3 | 221 | = init_integer_type (alloc, 64, 1, "ulong"); |
94b1b47e | 222 | builtin_d_type->builtin_cent |
2d39ccd3 | 223 | = init_integer_type (alloc, 128, 0, "cent"); |
94b1b47e | 224 | builtin_d_type->builtin_ucent |
2d39ccd3 | 225 | = init_integer_type (alloc, 128, 1, "ucent"); |
94b1b47e | 226 | builtin_d_type->builtin_float |
77c5f496 | 227 | = init_float_type (alloc, gdbarch_float_bit (gdbarch), |
49f190bc | 228 | "float", gdbarch_float_format (gdbarch)); |
94b1b47e | 229 | builtin_d_type->builtin_double |
77c5f496 | 230 | = init_float_type (alloc, gdbarch_double_bit (gdbarch), |
49f190bc | 231 | "double", gdbarch_double_format (gdbarch)); |
94b1b47e | 232 | builtin_d_type->builtin_real |
77c5f496 | 233 | = init_float_type (alloc, gdbarch_long_double_bit (gdbarch), |
49f190bc | 234 | "real", gdbarch_long_double_format (gdbarch)); |
94b1b47e | 235 | |
314ad88d PA |
236 | builtin_d_type->builtin_byte->set_instance_flags |
237 | (builtin_d_type->builtin_byte->instance_flags () | |
238 | | TYPE_INSTANCE_FLAG_NOTTEXT); | |
239 | ||
240 | builtin_d_type->builtin_ubyte->set_instance_flags | |
241 | (builtin_d_type->builtin_ubyte->instance_flags () | |
242 | | TYPE_INSTANCE_FLAG_NOTTEXT); | |
94b1b47e IB |
243 | |
244 | /* Imaginary and complex types. */ | |
245 | builtin_d_type->builtin_ifloat | |
77c5f496 | 246 | = init_float_type (alloc, gdbarch_float_bit (gdbarch), |
49f190bc | 247 | "ifloat", gdbarch_float_format (gdbarch)); |
94b1b47e | 248 | builtin_d_type->builtin_idouble |
77c5f496 | 249 | = init_float_type (alloc, gdbarch_double_bit (gdbarch), |
49f190bc | 250 | "idouble", gdbarch_double_format (gdbarch)); |
94b1b47e | 251 | builtin_d_type->builtin_ireal |
77c5f496 | 252 | = init_float_type (alloc, gdbarch_long_double_bit (gdbarch), |
49f190bc | 253 | "ireal", gdbarch_long_double_format (gdbarch)); |
94b1b47e | 254 | builtin_d_type->builtin_cfloat |
5b930b45 | 255 | = init_complex_type ("cfloat", builtin_d_type->builtin_float); |
94b1b47e | 256 | builtin_d_type->builtin_cdouble |
5b930b45 | 257 | = init_complex_type ("cdouble", builtin_d_type->builtin_double); |
94b1b47e | 258 | builtin_d_type->builtin_creal |
5b930b45 | 259 | = init_complex_type ("creal", builtin_d_type->builtin_real); |
94b1b47e IB |
260 | |
261 | /* Character types. */ | |
262 | builtin_d_type->builtin_char | |
f50b437c | 263 | = init_character_type (alloc, 8, 1, "char"); |
94b1b47e | 264 | builtin_d_type->builtin_wchar |
f50b437c | 265 | = init_character_type (alloc, 16, 1, "wchar"); |
94b1b47e | 266 | builtin_d_type->builtin_dchar |
f50b437c | 267 | = init_character_type (alloc, 32, 1, "dchar"); |
94b1b47e IB |
268 | |
269 | return builtin_d_type; | |
270 | } | |
271 | ||
cb275538 | 272 | static const registry<gdbarch>::key<struct builtin_d_type> d_type_data; |
94b1b47e IB |
273 | |
274 | /* Return the D type table for the specified architecture. */ | |
275 | ||
276 | const struct builtin_d_type * | |
277 | builtin_d_type (struct gdbarch *gdbarch) | |
278 | { | |
cb275538 TT |
279 | struct builtin_d_type *result = d_type_data.get (gdbarch); |
280 | if (result == nullptr) | |
281 | { | |
282 | result = build_d_types (gdbarch); | |
283 | d_type_data.set (gdbarch, result); | |
284 | } | |
94b1b47e | 285 | |
cb275538 | 286 | return result; |
6aecb9c2 | 287 | } |