GDB (xrefs)
Loading...
Searching...
No Matches
d-lang.c
Go to the documentation of this file.
1/* D language support routines for GDB, the GNU debugger.
2
3 Copyright (C) 2005-2023 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 "symtab.h"
22#include "language.h"
23#include "varobj.h"
24#include "d-lang.h"
25#include "c-lang.h"
26#include "demangle.h"
27#include "cp-support.h"
28#include "gdbarch.h"
29#include "parser-defs.h"
30
31/* The name of the symbol to use to get the name of the main subprogram. */
32static const char D_MAIN[] = "D main";
33
34/* Function returning the special symbol name used by D for the main
35 procedure in the main program if it is found in minimal symbol list.
36 This function tries to find minimal symbols so that it finds them even
37 if the program was compiled without debugging information. */
38
39const char *
41{
42 struct bound_minimal_symbol msym;
43
44 msym = lookup_minimal_symbol (D_MAIN, NULL, NULL);
45 if (msym.minsym != NULL)
46 return D_MAIN;
47
48 /* No known entry procedure found, the main program is probably not D. */
49 return NULL;
50}
51
52/* Implements the la_demangle language_defn routine for language D. */
53
54gdb::unique_xmalloc_ptr<char>
55d_demangle (const char *symbol, int options)
56{
57 return gdb_demangle (symbol, options | DMGL_DLANG);
58}
59
60/* Class representing the D language. */
61
63{
64public:
67 { /* Nothing. */ }
68
69 /* See language.h. */
70
71 const char *name () const override
72 { return "d"; }
73
74 /* See language.h. */
75
76 const char *natural_name () const override
77 { return "D"; }
78
79 /* See language.h. */
80
81 const std::vector<const char *> &filename_extensions () const override
82 {
83 static const std::vector<const char *> extensions = { ".d" };
84 return extensions;
85 }
86
87 /* See language.h. */
89 struct language_arch_info *lai) const override
90 {
91 const struct builtin_d_type *builtin = builtin_d_type (gdbarch);
92
93 /* Helper function to allow shorter lines below. */
94 auto add = [&] (struct type * t)
95 {
96 lai->add_primitive_type (t);
97 };
98
99 add (builtin->builtin_void);
100 add (builtin->builtin_bool);
101 add (builtin->builtin_byte);
102 add (builtin->builtin_ubyte);
103 add (builtin->builtin_short);
104 add (builtin->builtin_ushort);
105 add (builtin->builtin_int);
106 add (builtin->builtin_uint);
107 add (builtin->builtin_long);
108 add (builtin->builtin_ulong);
109 add (builtin->builtin_cent);
110 add (builtin->builtin_ucent);
111 add (builtin->builtin_float);
112 add (builtin->builtin_double);
113 add (builtin->builtin_real);
114 add (builtin->builtin_ifloat);
115 add (builtin->builtin_idouble);
116 add (builtin->builtin_ireal);
117 add (builtin->builtin_cfloat);
118 add (builtin->builtin_cdouble);
119 add (builtin->builtin_creal);
120 add (builtin->builtin_char);
121 add (builtin->builtin_wchar);
122 add (builtin->builtin_dchar);
123
124 lai->set_string_char_type (builtin->builtin_char);
125 lai->set_bool_type (builtin->builtin_bool, "bool");
126 }
127
128 /* See language.h. */
130 (const char *mangled,
131 gdb::unique_xmalloc_ptr<char> *demangled) const override
132 {
133 *demangled = d_demangle (mangled, 0);
134 return *demangled != NULL;
135 }
136
137 /* See language.h. */
138
139 gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
140 int options) const override
141 {
142 return d_demangle (mangled, options);
143 }
144
145 /* See language.h. */
146
147 bool can_print_type_offsets () const override
148 {
149 return true;
150 }
151
152 /* See language.h. */
153
154 void print_type (struct type *type, const char *varstring,
155 struct ui_file *stream, int show, int level,
156 const struct type_print_options *flags) const override
157 {
158 c_print_type (type, varstring, stream, show, level, la_language, flags);
159 }
160
161 /* See language.h. */
162
164 (struct value *val, struct ui_file *stream, int recurse,
165 const struct value_print_options *options) const override
166 {
167 return d_value_print_inner (val, stream, recurse, options);
168 }
169
170 /* See language.h. */
171
173 (const char *name, const struct block *block,
174 const domain_enum domain) const override
175 {
176 return d_lookup_symbol_nonlocal (this, name, block, domain);
177 }
178
179 /* See language.h. */
180
181 int parser (struct parser_state *ps) const override
182 {
183 return d_parse (ps);
184 }
185
186 /* See language.h. */
187
188 const char *name_of_this () const override
189 { return "this"; }
190};
191
192/* Single instance of the D language class. */
193
195
196/* Build all D language types for the specified architecture. */
197
198static struct builtin_d_type *
200{
201 struct builtin_d_type *builtin_d_type = new struct builtin_d_type;
202
203 /* Basic types. */
204 type_allocator alloc (gdbarch);
207 = init_boolean_type (alloc, 8, 1, "bool");
209 = init_integer_type (alloc, 8, 0, "byte");
211 = init_integer_type (alloc, 8, 1, "ubyte");
213 = init_integer_type (alloc, 16, 0, "short");
215 = init_integer_type (alloc, 16, 1, "ushort");
217 = init_integer_type (alloc, 32, 0, "int");
219 = init_integer_type (alloc, 32, 1, "uint");
221 = init_integer_type (alloc, 64, 0, "long");
223 = init_integer_type (alloc, 64, 1, "ulong");
225 = init_integer_type (alloc, 128, 0, "cent");
227 = init_integer_type (alloc, 128, 1, "ucent");
230 "float", gdbarch_float_format (gdbarch));
233 "double", gdbarch_double_format (gdbarch));
237
241
245
246 /* Imaginary and complex types. */
249 "ifloat", gdbarch_float_format (gdbarch));
252 "idouble", gdbarch_double_format (gdbarch));
262
263 /* Character types. */
265 = init_character_type (alloc, 8, 1, "char");
267 = init_character_type (alloc, 16, 1, "wchar");
269 = init_character_type (alloc, 32, 1, "dchar");
270
271 return builtin_d_type;
272}
273
275
276/* Return the D type table for the specified architecture. */
277
278const struct builtin_d_type *
280{
281 struct builtin_d_type *result = d_type_data.get (gdbarch);
282 if (result == nullptr)
283 {
284 result = build_d_types (gdbarch);
285 d_type_data.set (gdbarch, result);
286 }
287
288 return result;
289}
void c_print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, enum language language, const struct type_print_options *flags)
int parser(struct parser_state *ps) const override
Definition d-lang.c:181
void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override
Definition d-lang.c:154
const char * name() const override
Definition d-lang.c:71
bool sniff_from_mangled_name(const char *mangled, gdb::unique_xmalloc_ptr< char > *demangled) const override
Definition d-lang.c:130
const char * natural_name() const override
Definition d-lang.c:76
void language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai) const override
Definition d-lang.c:88
gdb::unique_xmalloc_ptr< char > demangle_symbol(const char *mangled, int options) const override
Definition d-lang.c:139
void value_print_inner(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options) const override
Definition d-lang.c:164
const char * name_of_this() const override
Definition d-lang.c:188
struct block_symbol lookup_symbol_nonlocal(const char *name, const struct block *block, const domain_enum domain) const override
Definition d-lang.c:173
const std::vector< const char * > & filename_extensions() const override
Definition d-lang.c:81
d_language()
Definition d-lang.c:65
bool can_print_type_offsets() const override
Definition d-lang.c:147
void set(unsigned key, void *datum)
Definition registry.h:204
void * get(unsigned key)
Definition registry.h:211
gdb::unique_xmalloc_ptr< char > gdb_demangle(const char *name, int options)
int d_parse(struct parser_state *par_state)
Definition d-exp.c:3298
static struct builtin_d_type * build_d_types(struct gdbarch *gdbarch)
Definition d-lang.c:199
static d_language d_language_defn
Definition d-lang.c:194
const char * d_main_name(void)
Definition d-lang.c:40
static const char D_MAIN[]
Definition d-lang.c:32
static const registry< gdbarch >::key< struct builtin_d_type > d_type_data
Definition d-lang.c:274
const struct builtin_d_type * builtin_d_type(struct gdbarch *gdbarch)
Definition d-lang.c:279
gdb::unique_xmalloc_ptr< char > d_demangle(const char *symbol, int options)
Definition d-lang.c:55
struct block_symbol d_lookup_symbol_nonlocal(const struct language_defn *, const char *, const struct block *, const domain_enum)
void d_value_print_inner(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options)
Definition d-valprint.c:74
@ language_d
Definition defs.h:217
int gdbarch_float_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1568
const struct floatformat ** gdbarch_double_format(struct gdbarch *gdbarch)
Definition gdbarch.c:1619
int gdbarch_long_double_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1636
const struct floatformat ** gdbarch_float_format(struct gdbarch *gdbarch)
Definition gdbarch.c:1585
const struct floatformat ** gdbarch_long_double_format(struct gdbarch *gdbarch)
Definition gdbarch.c:1653
int gdbarch_double_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1602
struct type * init_character_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3374
struct type * init_integer_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3355
struct type * init_float_type(type_allocator &alloc, int bit, const char *name, const struct floatformat **floatformats, enum bfd_endian byte_order)
Definition gdbtypes.c:3408
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
struct type * init_complex_type(const char *name, struct type *target_type)
Definition gdbtypes.c:3449
struct type * init_boolean_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3389
@ TYPE_INSTANCE_FLAG_NOTTEXT
Definition gdbtypes.h:102
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
Definition block.h:109
struct minimal_symbol * minsym
Definition minsyms.h:49
struct type * builtin_idouble
Definition d-lang.h:47
struct type * builtin_cdouble
Definition d-lang.h:50
struct type * builtin_byte
Definition d-lang.h:33
struct type * builtin_creal
Definition d-lang.h:51
struct type * builtin_void
Definition d-lang.h:31
struct type * builtin_wchar
Definition d-lang.h:53
struct type * builtin_ubyte
Definition d-lang.h:34
struct type * builtin_cent
Definition d-lang.h:41
struct type * builtin_ushort
Definition d-lang.h:36
struct type * builtin_real
Definition d-lang.h:45
struct type * builtin_long
Definition d-lang.h:39
struct type * builtin_dchar
Definition d-lang.h:54
struct type * builtin_ifloat
Definition d-lang.h:46
struct type * builtin_ireal
Definition d-lang.h:48
struct type * builtin_bool
Definition d-lang.h:32
struct type * builtin_cfloat
Definition d-lang.h:49
struct type * builtin_double
Definition d-lang.h:44
struct type * builtin_char
Definition d-lang.h:52
struct type * builtin_ulong
Definition d-lang.h:40
struct type * builtin_uint
Definition d-lang.h:38
struct type * builtin_short
Definition d-lang.h:35
struct type * builtin_int
Definition d-lang.h:37
struct type * builtin_ucent
Definition d-lang.h:42
struct type * builtin_float
Definition d-lang.h:43
struct type * builtin_void
Definition gdbtypes.h:2077
void set_string_char_type(struct type *type)
Definition language.h:114
void add_primitive_type(struct type *type)
Definition language.h:130
void set_bool_type(struct type *type, const char *name=nullptr)
Definition language.h:102
enum language la_language
Definition language.h:275
void set_instance_flags(type_instance_flags flags)
Definition gdbtypes.h:1059
const type_instance_flags instance_flags() const
Definition gdbtypes.h:1053
Definition value.h:130
domain_enum
Definition symtab.h:900