GDB (xrefs)
Loading...
Searching...
No Matches
f-lang.h
Go to the documentation of this file.
1/* Fortran language support definitions for GDB, the GNU debugger.
2
3 Copyright (C) 1992-2023 Free Software Foundation, Inc.
4
5 Contributed by Motorola. Adapted from the C definitions by Farooq Butt
6 (fmbutt@engage.sps.mot.com).
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23#ifndef F_LANG_H
24#define F_LANG_H
25
26#include "language.h"
27#include "valprint.h"
28
30struct parser_state;
31
32/* Class representing the Fortran language. */
33
35{
36public:
39 { /* Nothing. */ }
40
41 /* See language.h. */
42
43 const char *name () const override
44 { return "fortran"; }
45
46 /* See language.h. */
47
48 const char *natural_name () const override
49 { return "Fortran"; }
50
51 /* See language.h. */
52
53 const std::vector<const char *> &filename_extensions () const override
54 {
55 static const std::vector<const char *> extensions = {
56 ".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP",
57 ".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08"
58 };
59 return extensions;
60 }
61
62 /* See language.h. */
63 void print_array_index (struct type *index_type,
64 LONGEST index,
65 struct ui_file *stream,
66 const value_print_options *options) const override;
67
68 /* See language.h. */
70 struct language_arch_info *lai) const override;
71
72 /* See language.h. */
73 unsigned int search_name_hash (const char *name) const override;
74
75 /* See language.h. */
76
77 gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
78 int options) const override
79 {
80 /* We could support demangling here to provide module namespaces
81 also for inferiors with only minimal symbol table (ELF symbols).
82 Just the mangling standard is not standardized across compilers
83 and there is no DW_AT_producer available for inferiors with only
84 the ELF symbols to check the mangling kind. */
85 return nullptr;
86 }
87
88 /* See language.h. */
89
90 void print_type (struct type *type, const char *varstring,
91 struct ui_file *stream, int show, int level,
92 const struct type_print_options *flags) const override;
93
94 /* See language.h. This just returns default set of word break
95 characters but with the modules separator `::' removed. */
96
97 const char *word_break_characters (void) const override
98 {
99 static char *retval;
100
101 if (!retval)
102 {
103 char *s;
104
105 retval = xstrdup (language_defn::word_break_characters ());
106 s = strchr (retval, ':');
107 if (s)
108 {
109 char *last_char = &s[strlen (s) - 1];
110
111 *s = *last_char;
112 *last_char = 0;
113 }
114 }
115 return retval;
116 }
117
118
119 /* See language.h. */
120
123 symbol_name_match_type name_match_type,
124 const char *text, const char *word,
125 enum type_code code) const override
126 {
127 /* Consider the modules separator :: as a valid symbol name character
128 class. */
130 name_match_type,
131 text, word, ":",
132 code);
133 }
134
135 /* See language.h. */
136
138 (struct value *val, struct ui_file *stream, int recurse,
139 const struct value_print_options *options) const override;
140
141 /* See language.h. */
142
144 (const char *name, const struct block *block,
145 const domain_enum domain) const override;
146
147 /* See language.h. */
148
149 int parser (struct parser_state *ps) const override;
150
151 /* See language.h. */
152
153 void emitchar (int ch, struct type *chtype,
154 struct ui_file *stream, int quoter) const override
155 {
156 const char *encoding = get_encoding (chtype);
157 generic_emit_char (ch, chtype, stream, quoter, encoding);
158 }
159
160 /* See language.h. */
161
162 void printchar (int ch, struct type *chtype,
163 struct ui_file *stream) const override
164 {
165 gdb_puts ("'", stream);
166 emitchar (ch, chtype, stream, '\'');
167 gdb_puts ("'", stream);
168 }
169
170 /* See language.h. */
171
172 void printstr (struct ui_file *stream, struct type *elttype,
173 const gdb_byte *string, unsigned int length,
174 const char *encoding, int force_ellipses,
175 const struct value_print_options *options) const override
176 {
177 const char *type_encoding = get_encoding (elttype);
178
179 if (elttype->length () == 4)
180 gdb_puts ("4_", stream);
181
182 if (!encoding || !*encoding)
183 encoding = type_encoding;
184
185 generic_printstr (stream, elttype, string, length, encoding,
186 force_ellipses, '\'', 0, options);
187 }
188
189 /* See language.h. */
190
191 void print_typedef (struct type *type, struct symbol *new_symbol,
192 struct ui_file *stream) const override;
193
194 /* See language.h. */
195
196 bool is_string_type_p (struct type *type) const override
197 {
199 return (type->code () == TYPE_CODE_STRING
200 || (type->code () == TYPE_CODE_ARRAY
201 && type->target_type ()->code () == TYPE_CODE_CHAR));
202 }
203
204 /* See language.h. */
205
206 struct value *value_string (struct gdbarch *gdbarch,
207 const char *ptr, ssize_t len) const override;
208
209 /* See language.h. */
210
211 const char *struct_too_deep_ellipsis () const override
212 { return "(...)"; }
213
214 /* See language.h. */
215
216 bool c_style_arrays_p () const override
217 { return false; }
218
219 /* See language.h. */
220
221 bool range_checking_on_by_default () const override
222 { return true; }
223
224 /* See language.h. */
225
226 enum case_sensitivity case_sensitivity () const override
227 { return case_sensitive_off; }
228
229 /* See language.h. */
230
231 enum array_ordering array_ordering () const override
232 { return array_column_major; }
233
234protected:
235
236 /* See language.h. */
237
239 (const lookup_name_info &lookup_name) const override;
240
241private:
242 /* Return the encoding that should be used for the character type
243 TYPE. */
244
245 static const char *get_encoding (struct type *type);
246
247 /* Print any asterisks or open-parentheses needed before the variable
248 name (to describe its type).
249
250 On outermost call, pass 0 for PASSED_A_PTR.
251 On outermost call, SHOW > 0 means should ignore
252 any typename for TYPE and show its details.
253 SHOW is always zero on recursive calls. */
254
256 struct ui_file * stream,
257 int show, int passed_a_ptr) const;
258
259 /* Print any array sizes, function arguments or close parentheses needed
260 after the variable name (to describe its type). Args work like
261 c_type_print_varspec_prefix.
262
263 PRINT_RANK_ONLY is true when TYPE is an array which should be printed
264 without the upper and lower bounds being specified, this will occur
265 when the array is not allocated or not associated and so there are no
266 known upper or lower bounds. */
267
269 struct ui_file *stream,
270 int show, int passed_a_ptr,
271 int demangled_args,
272 int arrayprint_recurse_level,
273 bool print_rank_only) const;
274
275 /* If TYPE is an extended type, then print out derivation information.
276
277 A typical output could look like this:
278 "Type, extends(point) :: waypoint"
279 " Type point :: point"
280 " real(kind=4) :: angle"
281 "End Type waypoint". */
282
284 struct ui_file *stream) const;
285
286 /* Print the name of the type (or the ultimate pointer target, function
287 value or array element), or the description of a structure or union.
288
289 SHOW nonzero means don't print this type as just its name;
290 show its real definition even if it has a name.
291 SHOW zero means print just typename or struct tag if there is one
292 SHOW negative means abbreviate structure elements.
293 SHOW is decremented for printing of structure elements.
294
295 LEVEL is the depth to indent by. We increase it for some recursive
296 calls. */
297
298 void f_type_print_base (struct type *type, struct ui_file *stream, int show,
299 int level) const;
300};
301
302/* Language-specific data structures */
303
304/* A common block. */
305
307{
308 /* The number of entries in the block. */
309 size_t n_entries;
310
311 /* The contents of the block, allocated using the struct hack. All
312 pointers in the array are non-NULL. */
313 struct symbol *contents[1];
314};
315
316extern LONGEST f77_get_upperbound (struct type *);
317
318extern LONGEST f77_get_lowerbound (struct type *);
319
320extern int calc_f77_array_dims (struct type *);
321
322/* Fortran (F77) types */
323
325{
326 struct type *builtin_character = nullptr;
327 struct type *builtin_integer_s1 = nullptr;
328 struct type *builtin_integer_s2 = nullptr;
329 struct type *builtin_integer = nullptr;
330 struct type *builtin_integer_s8 = nullptr;
331 struct type *builtin_logical_s1 = nullptr;
332 struct type *builtin_logical_s2 = nullptr;
333 struct type *builtin_logical = nullptr;
334 struct type *builtin_logical_s8 = nullptr;
335 struct type *builtin_real = nullptr;
336 struct type *builtin_real_s8 = nullptr;
337 struct type *builtin_real_s16 = nullptr;
338 struct type *builtin_complex = nullptr;
339 struct type *builtin_complex_s8 = nullptr;
340 struct type *builtin_complex_s16 = nullptr;
341 struct type *builtin_void = nullptr;
342};
343
344/* Return the Fortran type table for the specified architecture. */
345extern const struct builtin_f_type *builtin_f_type (struct gdbarch *gdbarch);
346
347/* Ensures that function argument TYPE is appropriate to inform the debugger
348 that ARG should be passed as a pointer. Returns the potentially updated
349 argument type.
350
351 If ARG is of type pointer then the type of ARG is returned, otherwise
352 TYPE is returned untouched.
353
354 This function exists to augment the types of Fortran function call
355 parameters to be pointers to the reported value, when the corresponding ARG
356 has also been wrapped in a pointer (by fortran_argument_convert). This
357 informs the debugger that these arguments should be passed as a pointer
358 rather than as the pointed to type. */
359
360extern struct type *fortran_preserve_arg_pointer (struct value *arg,
361 struct type *type);
362
363/* Fortran arrays can have a negative stride. When this happens it is
364 often the case that the base address for an object is not the lowest
365 address occupied by that object. For example, an array slice (10:1:-1)
366 will be encoded with lower bound 1, upper bound 10, a stride of
367 -ELEMENT_SIZE, and have a base address pointer that points at the
368 element with the highest address in memory.
369
370 This really doesn't play well with our current model of value contents,
371 but could easily require a significant update in order to be supported
372 "correctly".
373
374 For now, we manually force the base address to be the lowest addressed
375 element here. Yes, this will break some things, but it fixes other
376 things. The hope is that it fixes more than it breaks. */
377
379 (struct type *type, CORE_ADDR address);
380
381#endif /* F_LANG_H */
int code
Definition ada-lex.l:670
void print_array_index(struct type *index_type, LONGEST index, struct ui_file *stream, const value_print_options *options) const override
Definition f-lang.c:1664
bool range_checking_on_by_default() const override
Definition f-lang.h:221
void f_type_print_base(struct type *type, struct ui_file *stream, int show, int level) const
const char * word_break_characters(void) const override
Definition f-lang.h:97
const std::vector< const char * > & filename_extensions() const override
Definition f-lang.h:53
void value_print_inner(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options) const override
Definition f-valprint.c:453
void f_type_print_varspec_suffix(struct type *type, struct ui_file *stream, int show, int passed_a_ptr, int demangled_args, int arrayprint_recurse_level, bool print_rank_only) const
void emitchar(int ch, struct type *chtype, struct ui_file *stream, int quoter) const override
Definition f-lang.h:153
struct value * value_string(struct gdbarch *gdbarch, const char *ptr, ssize_t len) const override
Definition f-lang.c:107
f_language()
Definition f-lang.h:37
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 f-typeprint.c:49
void f_type_print_derivation_info(struct type *type, struct ui_file *stream) const
int parser(struct parser_state *ps) const override
Definition f-exp.c:3601
void f_type_print_varspec_prefix(struct type *type, struct ui_file *stream, int show, int passed_a_ptr) const
Definition f-typeprint.c:93
void language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai) const override
Definition f-lang.c:1678
void collect_symbol_completion_matches(completion_tracker &tracker, complete_symbol_mode mode, symbol_name_match_type name_match_type, const char *text, const char *word, enum type_code code) const override
Definition f-lang.h:121
symbol_name_matcher_ftype * get_symbol_name_matcher_inner(const lookup_name_info &lookup_name) const override
Definition f-lang.c:1727
enum case_sensitivity case_sensitivity() const override
Definition f-lang.h:226
const char * struct_too_deep_ellipsis() const override
Definition f-lang.h:211
struct block_symbol lookup_symbol_nonlocal(const char *name, const struct block *block, const domain_enum domain) const override
Definition f-lang.c:1716
unsigned int search_name_hash(const char *name) const override
Definition f-lang.c:1708
void print_typedef(struct type *type, struct symbol *new_symbol, struct ui_file *stream) const override
Definition f-typeprint.c:39
enum array_ordering array_ordering() const override
Definition f-lang.h:231
static const char * get_encoding(struct type *type)
Definition f-lang.c:81
void printstr(struct ui_file *stream, struct type *elttype, const gdb_byte *string, unsigned int length, const char *encoding, int force_ellipses, const struct value_print_options *options) const override
Definition f-lang.h:172
const char * name() const override
Definition f-lang.h:43
void printchar(int ch, struct type *chtype, struct ui_file *stream) const override
Definition f-lang.h:162
bool c_style_arrays_p() const override
Definition f-lang.h:216
bool is_string_type_p(struct type *type) const override
Definition f-lang.h:196
gdb::unique_xmalloc_ptr< char > demangle_symbol(const char *mangled, int options) const override
Definition f-lang.h:77
const char * natural_name() const override
Definition f-lang.h:48
@ language_fortran
Definition defs.h:219
const struct builtin_f_type * builtin_f_type(struct gdbarch *gdbarch)
Definition f-lang.c:1813
int calc_f77_array_dims(struct type *)
Definition f-lang.c:231
struct type * fortran_preserve_arg_pointer(struct value *arg, struct type *type)
Definition f-lang.c:1968
LONGEST f77_get_lowerbound(struct type *)
Definition f-valprint.c:44
LONGEST f77_get_upperbound(struct type *)
Definition f-valprint.c:53
CORE_ADDR fortran_adjust_dynamic_array_base_address_hack(struct type *type, CORE_ADDR address)
Definition f-lang.c:1978
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:2966
type_code
Definition gdbtypes.h:82
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
array_ordering
Definition language.h:61
@ array_column_major
Definition language.h:62
case_sensitivity
Definition language.h:72
@ case_sensitive_off
Definition language.h:73
static struct symbol * new_symbol(struct die_info *, struct type *, struct dwarf2_cu *, struct symbol *=NULL)
Definition read.c:18978
Definition block.h:109
struct type * builtin_logical_s2
Definition f-lang.h:332
struct type * builtin_logical_s8
Definition f-lang.h:334
struct type * builtin_logical_s1
Definition f-lang.h:331
struct type * builtin_void
Definition f-lang.h:341
struct type * builtin_real
Definition f-lang.h:335
struct type * builtin_real_s8
Definition f-lang.h:336
struct type * builtin_complex_s8
Definition f-lang.h:339
struct type * builtin_integer
Definition f-lang.h:329
struct type * builtin_logical
Definition f-lang.h:333
struct type * builtin_real_s16
Definition f-lang.h:337
struct type * builtin_complex
Definition f-lang.h:338
struct type * builtin_integer_s1
Definition f-lang.h:327
struct type * builtin_integer_s2
Definition f-lang.h:328
struct type * builtin_character
Definition f-lang.h:326
struct type * builtin_integer_s8
Definition f-lang.h:330
struct type * builtin_complex_s16
Definition f-lang.h:340
struct symbol * contents[1]
Definition f-lang.h:313
size_t n_entries
Definition f-lang.h:309
virtual const char * word_break_characters(void) const
Definition language.h:486
struct type * target_type() const
Definition gdbtypes.h:1037
type_code code() const
Definition gdbtypes.h:956
ULONGEST length() const
Definition gdbtypes.h:983
Definition value.h:130
void default_collect_symbol_completion_matches_break_on(completion_tracker &tracker, complete_symbol_mode mode, symbol_name_match_type name_match_type, const char *text, const char *word, const char *break_on, enum type_code code)
Definition symtab.c:5746
symbol_name_match_type
Definition symtab.h:63
bool symbol_name_matcher_ftype(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
Definition symtab.h:399
domain_enum
Definition symtab.h:900
complete_symbol_mode
Definition symtab.h:2385
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1809
void generic_emit_char(int c, struct type *type, struct ui_file *stream, int quoter, const char *encoding)
Definition valprint.c:2205
void generic_printstr(struct ui_file *stream, struct type *type, const gdb_byte *string, unsigned int length, const char *encoding, int force_ellipses, int quote_char, int c_style_terminator, const struct value_print_options *options)
Definition valprint.c:2536