1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2021 Free Software Foundation, Inc.
5 Contributed by the Department of Computer Science at the State University
6 of New York at Buffalo.
8 This file is part of GDB.
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.
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.
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/>. */
23 /* This file contains functions that return things that are specific
24 to languages. Each function should examine current_language if necessary,
25 and return the appropriate result. */
27 /* FIXME: Most of these would be better organized as macros which
28 return data out of a "language-specific" struct pointer that is set
29 whenever the working language changes. That would be a lot faster. */
37 #include "expression.h"
41 #include "parser-defs.h"
44 #include "cp-support.h"
50 static void set_range_case (void);
53 range_mode_auto: range_check set automatically to default of language.
54 range_mode_manual: range_check set manually by user. */
58 range_mode_auto
, range_mode_manual
62 case_mode_auto: case_sensitivity set upon selection of scope.
63 case_mode_manual: case_sensitivity set only by user. */
67 case_mode_auto
, case_mode_manual
70 /* The current (default at startup) state of type and range checking.
71 (If the modes are set to "auto", though, these are changed based
72 on the default language at startup, and then again based on the
73 language of the first source file. */
75 static enum range_mode range_mode
= range_mode_auto
;
76 enum range_check range_check
= range_check_off
;
77 static enum case_mode case_mode
= case_mode_auto
;
78 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
80 /* The current language and language_mode (see language.h). */
82 const struct language_defn
*current_language
= nullptr;
83 enum language_mode language_mode
= language_mode_auto
;
85 /* The language that the user expects to be typing in (the language
86 of main(), or the last language we notified them about, or C). */
88 const struct language_defn
*expected_language
;
90 /* Define the array containing all languages. */
92 const struct language_defn
*language_defn::languages
[nr_languages
];
94 /* The current values of the "set language/range/case-sensitive" enum
96 static const char *language
;
97 static const char *range
;
98 static const char *case_sensitive
;
100 /* See language.h. */
101 const char lang_frame_mismatch_warn
[] =
102 N_("Warning: the current language does not match this frame.");
104 /* This page contains the functions corresponding to GDB commands
105 and their helpers. */
107 /* Show command. Display a warning if the language set
108 does not match the frame. */
110 show_language_command (struct ui_file
*file
, int from_tty
,
111 struct cmd_list_element
*c
, const char *value
)
113 enum language flang
; /* The language of the frame. */
115 if (language_mode
== language_mode_auto
)
116 fprintf_filtered (gdb_stdout
,
117 _("The current source language is "
118 "\"auto; currently %s\".\n"),
119 current_language
->name ());
121 fprintf_filtered (gdb_stdout
,
122 _("The current source language is \"%s\".\n"),
123 current_language
->name ());
125 if (has_stack_frames ())
127 struct frame_info
*frame
;
129 frame
= get_selected_frame (NULL
);
130 flang
= get_frame_language (frame
);
131 if (flang
!= language_unknown
132 && language_mode
== language_mode_manual
133 && current_language
->la_language
!= flang
)
134 printf_filtered ("%s\n", _(lang_frame_mismatch_warn
));
138 /* Set command. Change the current working language. */
140 set_language_command (const char *ignore
,
141 int from_tty
, struct cmd_list_element
*c
)
143 enum language flang
= language_unknown
;
145 /* "local" is a synonym of "auto". */
146 if (strcmp (language
, "local") == 0)
149 /* Search the list of languages for a match. */
150 for (const auto &lang
: language_defn::languages
)
152 if (strcmp (lang
->name (), language
) == 0)
154 /* Found it! Go into manual mode, and use this language. */
155 if (lang
->la_language
== language_auto
)
157 /* Enter auto mode. Set to the current frame's language, if
158 known, or fallback to the initial language. */
159 language_mode
= language_mode_auto
;
162 struct frame_info
*frame
;
164 frame
= get_selected_frame (NULL
);
165 flang
= get_frame_language (frame
);
167 catch (const gdb_exception_error
&ex
)
169 flang
= language_unknown
;
172 if (flang
!= language_unknown
)
173 set_language (flang
);
175 set_initial_language ();
176 expected_language
= current_language
;
181 /* Enter manual mode. Set the specified language. */
182 language_mode
= language_mode_manual
;
183 current_language
= lang
;
185 expected_language
= current_language
;
191 internal_error (__FILE__
, __LINE__
,
192 "Couldn't find language `%s' in known languages list.",
196 /* Show command. Display a warning if the range setting does
197 not match the current language. */
199 show_range_command (struct ui_file
*file
, int from_tty
,
200 struct cmd_list_element
*c
, const char *value
)
202 if (range_mode
== range_mode_auto
)
211 case range_check_off
:
214 case range_check_warn
:
218 internal_error (__FILE__
, __LINE__
,
219 "Unrecognized range check setting.");
222 fprintf_filtered (gdb_stdout
,
223 _("Range checking is \"auto; currently %s\".\n"),
227 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
230 if (range_check
== range_check_warn
231 || ((range_check
== range_check_on
)
232 != current_language
->range_checking_on_by_default ()))
233 warning (_("the current range check setting "
234 "does not match the language.\n"));
237 /* Set command. Change the setting for range checking. */
239 set_range_command (const char *ignore
,
240 int from_tty
, struct cmd_list_element
*c
)
242 if (strcmp (range
, "on") == 0)
244 range_check
= range_check_on
;
245 range_mode
= range_mode_manual
;
247 else if (strcmp (range
, "warn") == 0)
249 range_check
= range_check_warn
;
250 range_mode
= range_mode_manual
;
252 else if (strcmp (range
, "off") == 0)
254 range_check
= range_check_off
;
255 range_mode
= range_mode_manual
;
257 else if (strcmp (range
, "auto") == 0)
259 range_mode
= range_mode_auto
;
265 internal_error (__FILE__
, __LINE__
,
266 _("Unrecognized range check setting: \"%s\""), range
);
268 if (range_check
== range_check_warn
269 || ((range_check
== range_check_on
)
270 != current_language
->range_checking_on_by_default ()))
271 warning (_("the current range check setting "
272 "does not match the language.\n"));
275 /* Show command. Display a warning if the case sensitivity setting does
276 not match the current language. */
278 show_case_command (struct ui_file
*file
, int from_tty
,
279 struct cmd_list_element
*c
, const char *value
)
281 if (case_mode
== case_mode_auto
)
283 const char *tmp
= NULL
;
285 switch (case_sensitivity
)
287 case case_sensitive_on
:
290 case case_sensitive_off
:
294 internal_error (__FILE__
, __LINE__
,
295 "Unrecognized case-sensitive setting.");
298 fprintf_filtered (gdb_stdout
,
299 _("Case sensitivity in "
300 "name search is \"auto; currently %s\".\n"),
304 fprintf_filtered (gdb_stdout
,
305 _("Case sensitivity in name search is \"%s\".\n"),
308 if (case_sensitivity
!= current_language
->case_sensitivity ())
309 warning (_("the current case sensitivity setting does not match "
313 /* Set command. Change the setting for case sensitivity. */
316 set_case_command (const char *ignore
, int from_tty
, struct cmd_list_element
*c
)
318 if (strcmp (case_sensitive
, "on") == 0)
320 case_sensitivity
= case_sensitive_on
;
321 case_mode
= case_mode_manual
;
323 else if (strcmp (case_sensitive
, "off") == 0)
325 case_sensitivity
= case_sensitive_off
;
326 case_mode
= case_mode_manual
;
328 else if (strcmp (case_sensitive
, "auto") == 0)
330 case_mode
= case_mode_auto
;
336 internal_error (__FILE__
, __LINE__
,
337 "Unrecognized case-sensitive setting: \"%s\"",
341 if (case_sensitivity
!= current_language
->case_sensitivity ())
342 warning (_("the current case sensitivity setting does not match "
346 /* Set the status of range and type checking and case sensitivity based on
347 the current modes and the current language.
348 If SHOW is non-zero, then print out the current language,
349 type and range checking status. */
351 set_range_case (void)
353 if (range_mode
== range_mode_auto
)
354 range_check
= (current_language
->range_checking_on_by_default ()
355 ? range_check_on
: range_check_off
);
357 if (case_mode
== case_mode_auto
)
358 case_sensitivity
= current_language
->case_sensitivity ();
361 /* Set current language to (enum language) LANG. Returns previous
365 set_language (enum language lang
)
367 enum language prev_language
;
369 prev_language
= current_language
->la_language
;
370 current_language
= language_def (lang
);
372 return prev_language
;
376 /* Print out the current language settings: language, range and
377 type checking. If QUIETLY, print only what has changed. */
380 language_info (int quietly
)
382 if (quietly
&& expected_language
== current_language
)
385 expected_language
= current_language
;
386 printf_unfiltered (_("Current language: %s\n"), language
);
387 show_language_command (NULL
, 1, NULL
, NULL
);
391 printf_unfiltered (_("Range checking: %s\n"), range
);
392 show_range_command (NULL
, 1, NULL
, NULL
);
393 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
394 show_case_command (NULL
, 1, NULL
, NULL
);
399 /* Returns non-zero if the value is a pointer type. */
401 pointer_type (struct type
*type
)
403 return type
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
407 /* This page contains functions that return info about
408 (struct value) values used in GDB. */
410 /* Returns non-zero if the value VAL represents a true value. */
412 value_true (struct value
*val
)
414 /* It is possible that we should have some sort of error if a non-boolean
415 value is used in this context. Possibly dependent on some kind of
416 "boolean-checking" option like range checking. But it should probably
417 not depend on the language except insofar as is necessary to identify
418 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
419 should be an error, probably). */
420 return !value_logical_not (val
);
423 /* This page contains functions for the printing out of
424 error messages that occur during type- and range-
427 /* This is called when a language fails a range-check. The
428 first argument should be a printf()-style format string, and the
429 rest of the arguments should be its arguments. If range_check is
430 range_check_on, an error is printed; if range_check_warn, a warning;
431 otherwise just the message. */
434 range_error (const char *string
,...)
438 va_start (args
, string
);
441 case range_check_warn
:
442 vwarning (string
, args
);
445 verror (string
, args
);
447 case range_check_off
:
448 /* FIXME: cagney/2002-01-30: Should this function print anything
449 when range error is off? */
450 vfprintf_filtered (gdb_stderr
, string
, args
);
451 fprintf_filtered (gdb_stderr
, "\n");
454 internal_error (__FILE__
, __LINE__
, _("bad switch"));
460 /* This page contains miscellaneous functions. */
462 /* Return the language enum for a given language string. */
465 language_enum (const char *str
)
467 for (const auto &lang
: language_defn::languages
)
468 if (strcmp (lang
->name (), str
) == 0)
469 return lang
->la_language
;
471 if (strcmp (str
, "local") == 0)
472 return language_auto
;
474 return language_unknown
;
477 /* Return the language struct for a given language enum. */
479 const struct language_defn
*
480 language_def (enum language lang
)
482 const struct language_defn
*l
= language_defn::languages
[lang
];
483 gdb_assert (l
!= nullptr);
487 /* Return the language as a string. */
490 language_str (enum language lang
)
492 return language_def (lang
)->name ();
497 /* Build and install the "set language LANG" command. */
500 add_set_language_command ()
502 static const char **language_names
;
504 /* Build the language names array, to be used as enumeration in the
505 "set language" enum command. +1 for "local" and +1 for NULL
507 language_names
= new const char *[ARRAY_SIZE (language_defn::languages
) + 2];
509 /* Display "auto", "local" and "unknown" first, and then the rest,
511 const char **language_names_p
= language_names
;
512 *language_names_p
++ = language_def (language_auto
)->name ();
513 *language_names_p
++ = "local";
514 *language_names_p
++ = language_def (language_unknown
)->name ();
515 const char **sort_begin
= language_names_p
;
516 for (const auto &lang
: language_defn::languages
)
518 /* Already handled above. */
519 if (lang
->la_language
== language_auto
520 || lang
->la_language
== language_unknown
)
522 *language_names_p
++ = lang
->name ();
524 *language_names_p
= NULL
;
525 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
527 /* Add the filename extensions. */
528 for (const auto &lang
: language_defn::languages
)
529 for (const char * const &ext
: lang
->filename_extensions ())
530 add_filename_language (ext
, lang
->la_language
);
532 /* Build the "help set language" docs. */
535 doc
.printf (_("Set the current source language.\n"
536 "The currently understood settings are:\n\nlocal or "
537 "auto Automatic setting based on source file"));
539 for (const auto &lang
: language_defn::languages
)
541 /* Already dealt with these above. */
542 if (lang
->la_language
== language_unknown
543 || lang
->la_language
== language_auto
)
546 /* Note that we add the newline at the front, so we don't wind
547 up with a trailing newline. */
548 doc
.printf ("\n%-16s Use the %s language",
550 lang
->natural_name ());
553 add_setshow_enum_cmd ("language", class_support
,
557 _("Show the current source language."),
558 NULL
, set_language_command
,
559 show_language_command
,
560 &setlist
, &showlist
);
563 /* Iterate through all registered languages looking for and calling
564 any non-NULL struct language_defn.skip_trampoline() functions.
565 Return the result from the first that returns non-zero, or 0 if all
568 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
570 for (const auto &lang
: language_defn::languages
)
572 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
581 /* Return demangled language symbol, or NULL.
582 FIXME: Options are only useful for certain languages and ignored
583 by others, so it would be better to remove them here and have a
584 more flexible demangler for the languages that need it.
585 FIXME: Sometimes the demangler is invoked when we don't know the
586 language, so we can't use this everywhere. */
588 language_demangle (const struct language_defn
*current_language
,
589 const char *mangled
, int options
)
591 if (current_language
!= NULL
)
592 return current_language
->demangle_symbol (mangled
, options
);
596 /* Return information about whether TYPE should be passed
597 (and returned) by reference at the language level. */
599 struct language_pass_by_ref_info
600 language_pass_by_reference (struct type
*type
)
602 return current_language
->pass_by_reference_info (type
);
605 /* Return the default string containing the list of characters
606 delimiting words. This is a reasonable default value that
607 most languages should be able to use. */
610 default_word_break_characters (void)
612 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
615 /* See language.h. */
618 language_defn::print_array_index (struct type
*index_type
, LONGEST index
,
619 struct ui_file
*stream
,
620 const value_print_options
*options
) const
622 struct value
*index_value
= value_from_longest (index_type
, index
);
624 fprintf_filtered (stream
, "[");
625 value_print (index_value
, stream
, options
);
626 fprintf_filtered (stream
, "] = ");
629 /* See language.h. */
631 gdb::unique_xmalloc_ptr
<char>
632 language_defn::watch_location_expression (struct type
*type
,
633 CORE_ADDR addr
) const
635 /* Generates an expression that assumes a C like syntax is valid. */
636 type
= check_typedef (TYPE_TARGET_TYPE (check_typedef (type
)));
637 std::string name
= type_to_string (type
);
638 return gdb::unique_xmalloc_ptr
<char>
639 (xstrprintf ("* (%s *) %s", name
.c_str (), core_addr_to_string (addr
)));
642 /* See language.h. */
645 language_defn::value_print (struct value
*val
, struct ui_file
*stream
,
646 const struct value_print_options
*options
) const
648 return c_value_print (val
, stream
, options
);
651 /* See language.h. */
654 language_defn::parser (struct parser_state
*ps
) const
659 /* See language.h. */
662 language_defn::value_print_inner
663 (struct value
*val
, struct ui_file
*stream
, int recurse
,
664 const struct value_print_options
*options
) const
666 return c_value_print_inner (val
, stream
, recurse
, options
);
669 /* See language.h. */
672 language_defn::emitchar (int ch
, struct type
*chtype
,
673 struct ui_file
* stream
, int quoter
) const
675 c_emit_char (ch
, chtype
, stream
, quoter
);
678 /* See language.h. */
681 language_defn::printstr (struct ui_file
*stream
, struct type
*elttype
,
682 const gdb_byte
*string
, unsigned int length
,
683 const char *encoding
, int force_ellipses
,
684 const struct value_print_options
*options
) const
686 c_printstr (stream
, elttype
, string
, length
, encoding
, force_ellipses
,
690 /* See language.h. */
693 language_defn::print_typedef (struct type
*type
, struct symbol
*new_symbol
,
694 struct ui_file
*stream
) const
696 c_print_typedef (type
, new_symbol
, stream
);
699 /* See language.h. */
702 language_defn::is_string_type_p (struct type
*type
) const
704 return c_is_string_type_p (type
);
707 /* The default implementation of the get_symbol_name_matcher_inner method
708 from the language_defn class. Matches with strncmp_iw. */
711 default_symbol_name_matcher (const char *symbol_search_name
,
712 const lookup_name_info
&lookup_name
,
713 completion_match_result
*comp_match_res
)
715 gdb::string_view name
= lookup_name
.name ();
716 completion_match_for_lcd
*match_for_lcd
717 = (comp_match_res
!= NULL
? &comp_match_res
->match_for_lcd
: NULL
);
718 strncmp_iw_mode mode
= (lookup_name
.completion_mode ()
719 ? strncmp_iw_mode::NORMAL
720 : strncmp_iw_mode::MATCH_PARAMS
);
722 if (strncmp_iw_with_mode (symbol_search_name
, name
.data (), name
.size (),
723 mode
, language_minimal
, match_for_lcd
) == 0)
725 if (comp_match_res
!= NULL
)
726 comp_match_res
->set_match (symbol_search_name
);
733 /* See language.h. */
735 symbol_name_matcher_ftype
*
736 language_defn::get_symbol_name_matcher
737 (const lookup_name_info
&lookup_name
) const
739 /* If currently in Ada mode, and the lookup name is wrapped in
740 '<...>', hijack all symbol name comparisons using the Ada
741 matcher, which handles the verbatim matching. */
742 if (current_language
->la_language
== language_ada
743 && lookup_name
.ada ().verbatim_p ())
744 return current_language
->get_symbol_name_matcher_inner (lookup_name
);
746 return this->get_symbol_name_matcher_inner (lookup_name
);
749 /* See language.h. */
751 symbol_name_matcher_ftype
*
752 language_defn::get_symbol_name_matcher_inner
753 (const lookup_name_info
&lookup_name
) const
755 return default_symbol_name_matcher
;
758 /* See language.h. */
760 const struct lang_varobj_ops
*
761 language_defn::varobj_ops () const
763 /* The ops for the C language are suitable for the vast majority of the
764 supported languages. */
765 return &c_varobj_ops
;
768 /* See language.h. */
770 const struct exp_descriptor
*
771 language_defn::expression_ops () const
773 return &exp_descriptor_standard
;
776 /* Parent class for both the "auto" and "unknown" languages. These two
777 pseudo-languages are very similar so merging their implementations like
780 class auto_or_unknown_language
: public language_defn
783 auto_or_unknown_language (enum language lang
)
784 : language_defn (lang
)
787 /* See language.h. */
788 void language_arch_info (struct gdbarch
*gdbarch
,
789 struct language_arch_info
*lai
) const override
791 lai
->set_string_char_type (builtin_type (gdbarch
)->builtin_char
);
792 lai
->set_bool_type (builtin_type (gdbarch
)->builtin_int
);
795 /* See language.h. */
797 void print_type (struct type
*type
, const char *varstring
,
798 struct ui_file
*stream
, int show
, int level
,
799 const struct type_print_options
*flags
) const override
801 error (_("type printing not implemented for language \"%s\""),
805 /* See language.h. */
807 char *demangle_symbol (const char *mangled
, int options
) const override
809 /* The auto language just uses the C++ demangler. */
810 return gdb_demangle (mangled
, options
);
813 /* See language.h. */
815 void value_print (struct value
*val
, struct ui_file
*stream
,
816 const struct value_print_options
*options
) const override
818 error (_("value printing not implemented for language \"%s\""),
822 /* See language.h. */
824 void value_print_inner
825 (struct value
*val
, struct ui_file
*stream
, int recurse
,
826 const struct value_print_options
*options
) const override
828 error (_("inner value printing not implemented for language \"%s\""),
832 /* See language.h. */
834 int parser (struct parser_state
*ps
) const override
836 /* No parsing is done, just claim success. */
840 /* See language.h. */
842 void emitchar (int ch
, struct type
*chtype
,
843 struct ui_file
*stream
, int quoter
) const override
845 error (_("emit character not implemented for language \"%s\""),
849 /* See language.h. */
851 void printchar (int ch
, struct type
*chtype
,
852 struct ui_file
*stream
) const override
854 error (_("print character not implemented for language \"%s\""),
858 /* See language.h. */
860 void printstr (struct ui_file
*stream
, struct type
*elttype
,
861 const gdb_byte
*string
, unsigned int length
,
862 const char *encoding
, int force_ellipses
,
863 const struct value_print_options
*options
) const override
865 error (_("print string not implemented for language \"%s\""),
869 /* See language.h. */
871 void print_typedef (struct type
*type
, struct symbol
*new_symbol
,
872 struct ui_file
*stream
) const override
874 error (_("print typedef not implemented for language \"%s\""),
878 /* See language.h. */
880 bool is_string_type_p (struct type
*type
) const override
882 type
= check_typedef (type
);
883 while (type
->code () == TYPE_CODE_REF
)
885 type
= TYPE_TARGET_TYPE (type
);
886 type
= check_typedef (type
);
888 return (type
->code () == TYPE_CODE_STRING
);
891 /* See language.h. */
893 const char *name_of_this () const override
896 /* See language.h. */
898 const struct op_print
*opcode_print_table () const override
900 static const struct op_print unk_op_print_tab
[] =
902 {NULL
, OP_NULL
, PREC_NULL
, 0}
905 return unk_op_print_tab
;
909 /* Class representing the fake "auto" language. */
911 class auto_language
: public auto_or_unknown_language
915 : auto_or_unknown_language (language_auto
)
918 /* See language.h. */
920 const char *name () const override
923 /* See language.h. */
925 const char *natural_name () const override
929 /* Single instance of the fake "auto" language. */
931 static auto_language auto_language_defn
;
933 /* Class representing the unknown language. */
935 class unknown_language
: public auto_or_unknown_language
939 : auto_or_unknown_language (language_unknown
)
942 /* See language.h. */
944 const char *name () const override
945 { return "unknown"; }
947 /* See language.h. */
949 const char *natural_name () const override
950 { return "Unknown"; }
952 /* See language.h. */
954 bool store_sym_names_in_linkage_form_p () const override
958 /* Single instance of the unknown language class. */
960 static unknown_language unknown_language_defn
;
963 /* Per-architecture language information. */
965 static struct gdbarch_data
*language_gdbarch_data
;
967 struct language_gdbarch
969 /* A vector of per-language per-architecture info. Indexed by "enum
971 struct language_arch_info arch_info
[nr_languages
];
975 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
977 struct language_gdbarch
*l
978 = obstack_new
<struct language_gdbarch
> (gdbarch_obstack (gdbarch
));
979 for (const auto &lang
: language_defn::languages
)
981 gdb_assert (lang
!= nullptr);
982 lang
->language_arch_info (gdbarch
, &l
->arch_info
[lang
->la_language
]);
988 /* See language.h. */
991 language_string_char_type (const struct language_defn
*la
,
992 struct gdbarch
*gdbarch
)
994 struct language_gdbarch
*ld
995 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
996 return ld
->arch_info
[la
->la_language
].string_char_type ();
999 /* See language.h. */
1002 language_bool_type (const struct language_defn
*la
,
1003 struct gdbarch
*gdbarch
)
1005 struct language_gdbarch
*ld
1006 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1007 return ld
->arch_info
[la
->la_language
].bool_type ();
1010 /* See language.h. */
1013 language_arch_info::bool_type () const
1015 if (m_bool_type_name
!= nullptr)
1019 sym
= lookup_symbol (m_bool_type_name
, NULL
, VAR_DOMAIN
, NULL
).symbol
;
1022 struct type
*type
= SYMBOL_TYPE (sym
);
1023 if (type
!= nullptr && type
->code () == TYPE_CODE_BOOL
)
1028 return m_bool_type_default
;
1031 /* See language.h. */
1034 language_arch_info::type_and_symbol::alloc_type_symbol
1035 (enum language lang
, struct type
*type
)
1037 struct symbol
*symbol
;
1038 struct gdbarch
*gdbarch
;
1039 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1040 gdbarch
= type
->arch ();
1041 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
1042 symbol
->m_name
= type
->name ();
1043 symbol
->set_language (lang
, nullptr);
1044 symbol
->owner
.arch
= gdbarch
;
1045 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1046 SYMBOL_SECTION (symbol
) = 0;
1047 SYMBOL_TYPE (symbol
) = type
;
1048 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1049 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1053 /* See language.h. */
1055 language_arch_info::type_and_symbol
*
1056 language_arch_info::lookup_primitive_type_and_symbol (const char *name
)
1058 for (struct type_and_symbol
&tas
: primitive_types_and_symbols
)
1060 if (strcmp (tas
.type ()->name (), name
) == 0)
1067 /* See language.h. */
1070 language_arch_info::lookup_primitive_type (const char *name
)
1072 type_and_symbol
*tas
= lookup_primitive_type_and_symbol (name
);
1074 return tas
->type ();
1078 /* See language.h. */
1081 language_arch_info::lookup_primitive_type
1082 (gdb::function_view
<bool (struct type
*)> filter
)
1084 for (struct type_and_symbol
&tas
: primitive_types_and_symbols
)
1086 if (filter (tas
.type ()))
1093 /* See language.h. */
1096 language_arch_info::lookup_primitive_type_as_symbol (const char *name
,
1099 type_and_symbol
*tas
= lookup_primitive_type_and_symbol (name
);
1101 return tas
->symbol (lang
);
1105 /* Helper for the language_lookup_primitive_type overloads to forward
1106 to the corresponding language's lookup_primitive_type overload. */
1108 template<typename T
>
1109 static struct type
*
1110 language_lookup_primitive_type_1 (const struct language_defn
*la
,
1111 struct gdbarch
*gdbarch
,
1114 struct language_gdbarch
*ld
=
1115 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1116 return ld
->arch_info
[la
->la_language
].lookup_primitive_type (arg
);
1119 /* See language.h. */
1122 language_lookup_primitive_type (const struct language_defn
*la
,
1123 struct gdbarch
*gdbarch
,
1126 return language_lookup_primitive_type_1 (la
, gdbarch
, name
);
1129 /* See language.h. */
1132 language_lookup_primitive_type (const struct language_defn
*la
,
1133 struct gdbarch
*gdbarch
,
1134 gdb::function_view
<bool (struct type
*)> filter
)
1136 return language_lookup_primitive_type_1 (la
, gdbarch
, filter
);
1139 /* See language.h. */
1142 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1143 struct gdbarch
*gdbarch
,
1146 struct language_gdbarch
*ld
1147 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1148 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1150 if (symbol_lookup_debug
)
1151 fprintf_unfiltered (gdb_stdlog
,
1152 "language_lookup_primitive_type_as_symbol"
1154 la
->name (), host_address_to_string (gdbarch
), name
);
1157 = lai
->lookup_primitive_type_as_symbol (name
, la
->la_language
);
1159 if (symbol_lookup_debug
)
1160 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1162 /* Note: The result of symbol lookup is normally a symbol *and* the block
1163 it was found in. Builtin types don't live in blocks. We *could* give
1164 them one, but there is no current need so to keep things simple symbol
1165 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1170 /* Initialize the language routines. */
1172 void _initialize_language ();
1174 _initialize_language ()
1176 static const char *const type_or_range_names
[]
1177 = { "on", "off", "warn", "auto", NULL
};
1179 static const char *const case_sensitive_names
[]
1180 = { "on", "off", "auto", NULL
};
1182 language_gdbarch_data
1183 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1185 /* GDB commands for language specific stuff. */
1187 add_basic_prefix_cmd ("check", no_class
,
1188 _("Set the status of the type/range checker."),
1189 &setchecklist
, "set check ", 0, &setlist
);
1190 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1191 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1193 add_show_prefix_cmd ("check", no_class
,
1194 _("Show the status of the type/range checker."),
1195 &showchecklist
, "show check ", 0, &showlist
);
1196 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1197 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1199 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1201 _("Set range checking (on/warn/off/auto)."),
1202 _("Show range checking (on/warn/off/auto)."),
1203 NULL
, set_range_command
,
1205 &setchecklist
, &showchecklist
);
1207 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1208 &case_sensitive
, _("\
1209 Set case sensitivity in name search (on/off/auto)."), _("\
1210 Show case sensitivity in name search (on/off/auto)."), _("\
1211 For Fortran the default is off; for other languages the default is on."),
1214 &setlist
, &showlist
);
1216 /* In order to call SET_LANGUAGE (below) we need to make sure that
1217 CURRENT_LANGUAGE is not NULL. So first set the language to unknown,
1218 then we can change the language to 'auto'. */
1219 current_language
= language_def (language_unknown
);
1221 add_set_language_command ();
1225 case_sensitive
= "auto";
1227 /* Have the above take effect. */
1228 set_language (language_auto
);