1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2025 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. */
35 #include "cli/cli-cmds.h"
36 #include "expression.h"
40 #include "parser-defs.h"
43 #include "cp-support.h"
49 static void set_range_case (void);
52 range_mode_auto: range_check set automatically to default of language.
53 range_mode_manual: range_check set manually by user. */
57 range_mode_auto
, range_mode_manual
61 case_mode_auto: case_sensitivity set upon selection of scope.
62 case_mode_manual: case_sensitivity set only by user. */
66 case_mode_auto
, case_mode_manual
69 /* The current (default at startup) state of type and range checking.
70 (If the modes are set to "auto", though, these are changed based
71 on the default language at startup, and then again based on the
72 language of the first source file. */
74 static enum range_mode range_mode
= range_mode_auto
;
75 enum range_check range_check
= range_check_off
;
76 static enum case_mode case_mode
= case_mode_auto
;
77 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
79 /* The current language and language_mode (see language.h). */
81 static const struct language_defn
*global_current_language
;
82 static lazily_set_language_ftype
*lazy_language_setter
;
83 enum language_mode language_mode
= language_mode_auto
;
85 /* Whether to warn on language changes. */
86 bool warn_frame_lang_mismatch
= true;
90 const struct language_defn
*
91 get_current_language ()
93 if (lazy_language_setter
!= nullptr)
95 /* Avoid recursive calls -- set_language refers to
97 lazily_set_language_ftype
*call
= lazy_language_setter
;
98 lazy_language_setter
= nullptr;
101 return global_current_language
;
105 lazily_set_language (lazily_set_language_ftype
*fun
)
107 lazy_language_setter
= fun
;
110 scoped_restore_current_language::scoped_restore_current_language ()
111 : m_lang (global_current_language
),
112 m_fun (lazy_language_setter
)
116 scoped_restore_current_language::scoped_restore_current_language
118 : scoped_restore_current_language ()
123 scoped_restore_current_language::~scoped_restore_current_language ()
125 /* If both are NULL, then that means dont_restore was called. */
126 if (m_lang
!= nullptr || m_fun
!= nullptr)
128 global_current_language
= m_lang
;
129 lazy_language_setter
= m_fun
;
130 if (lazy_language_setter
== nullptr)
135 /* The language that the user expects to be typing in (the language
136 of main(), or the last language we notified them about, or C). */
138 const struct language_defn
*expected_language
;
140 /* Define the array containing all languages. */
142 const struct language_defn
*language_defn::languages
[nr_languages
];
144 /* The current values of the "set language/range/case-sensitive" enum
146 static const char *range
;
147 static const char *case_sensitive
;
149 /* See language.h. */
150 const char lang_frame_mismatch_warn
[] =
151 N_("Warning: the current language does not match this frame.");
153 /* This page contains the functions corresponding to GDB commands
154 and their helpers. */
156 /* Show command. Display a warning if the language set
157 does not match the frame. */
159 show_language_command (struct ui_file
*file
, int from_tty
,
160 struct cmd_list_element
*c
, const char *value
)
162 enum language flang
; /* The language of the frame. */
164 if (language_mode
== language_mode_auto
)
166 _("The current source language is "
167 "\"auto; currently %s\".\n"),
168 current_language
->name ());
171 _("The current source language is \"%s\".\n"),
172 current_language
->name ());
174 if (warn_frame_lang_mismatch
&& has_stack_frames ())
176 frame_info_ptr frame
;
178 frame
= get_selected_frame (NULL
);
179 flang
= get_frame_language (frame
);
180 if (flang
!= language_unknown
181 && language_mode
== language_mode_manual
182 && current_language
->la_language
!= flang
)
183 gdb_printf (file
, "%s\n", _(lang_frame_mismatch_warn
));
187 /* Set callback for the "set/show language" setting. */
190 set_language (const char *language
)
192 enum language flang
= language_unknown
;
194 /* "local" is a synonym of "auto". */
195 if (strcmp (language
, "auto") == 0
196 || strcmp (language
, "local") == 0)
198 /* Enter auto mode. Set to the current frame's language, if
199 known, or fallback to the initial language. */
200 language_mode
= language_mode_auto
;
203 frame_info_ptr frame
;
205 frame
= get_selected_frame (NULL
);
206 flang
= get_frame_language (frame
);
208 catch (const gdb_exception_error
&ex
)
210 flang
= language_unknown
;
213 if (flang
!= language_unknown
)
214 set_language (flang
);
216 set_initial_language ();
218 expected_language
= current_language
;
222 /* Search the list of languages for a match. */
223 for (const auto &lang
: language_defn::languages
)
225 if (strcmp (lang
->name (), language
) != 0)
228 /* Found it! Go into manual mode, and use this language. */
229 language_mode
= language_mode_manual
;
230 lazy_language_setter
= nullptr;
231 global_current_language
= lang
;
233 expected_language
= lang
;
237 internal_error ("Couldn't find language `%s' in known languages list.",
241 /* Get callback for the "set/show language" setting. */
246 if (language_mode
== language_mode_auto
)
249 return current_language
->name ();
252 /* Show command. Display a warning if the range setting does
253 not match the current language. */
255 show_range_command (struct ui_file
*file
, int from_tty
,
256 struct cmd_list_element
*c
, const char *value
)
258 if (range_mode
== range_mode_auto
)
267 case range_check_off
:
270 case range_check_warn
:
274 internal_error ("Unrecognized range check setting.");
278 _("Range checking is \"auto; currently %s\".\n"),
282 gdb_printf (file
, _("Range checking is \"%s\".\n"),
285 if (range_check
== range_check_warn
286 || ((range_check
== range_check_on
)
287 != current_language
->range_checking_on_by_default ()))
288 warning (_("the current range check setting "
289 "does not match the language."));
292 /* Set command. Change the setting for range checking. */
294 set_range_command (const char *ignore
,
295 int from_tty
, struct cmd_list_element
*c
)
297 if (strcmp (range
, "on") == 0)
299 range_check
= range_check_on
;
300 range_mode
= range_mode_manual
;
302 else if (strcmp (range
, "warn") == 0)
304 range_check
= range_check_warn
;
305 range_mode
= range_mode_manual
;
307 else if (strcmp (range
, "off") == 0)
309 range_check
= range_check_off
;
310 range_mode
= range_mode_manual
;
312 else if (strcmp (range
, "auto") == 0)
314 range_mode
= range_mode_auto
;
320 internal_error (_("Unrecognized range check setting: \"%s\""), range
);
322 if (range_check
== range_check_warn
323 || ((range_check
== range_check_on
)
324 != current_language
->range_checking_on_by_default ()))
325 warning (_("the current range check setting "
326 "does not match the language."));
329 /* Show command. Display a warning if the case sensitivity setting does
330 not match the current language. */
332 show_case_command (struct ui_file
*file
, int from_tty
,
333 struct cmd_list_element
*c
, const char *value
)
335 if (case_mode
== case_mode_auto
)
337 const char *tmp
= NULL
;
339 switch (case_sensitivity
)
341 case case_sensitive_on
:
344 case case_sensitive_off
:
348 internal_error ("Unrecognized case-sensitive setting.");
352 _("Case sensitivity in "
353 "name search is \"auto; currently %s\".\n"),
358 _("Case sensitivity in name search is \"%s\".\n"),
361 if (case_sensitivity
!= current_language
->case_sensitivity ())
362 warning (_("the current case sensitivity setting does not match "
366 /* Set command. Change the setting for case sensitivity. */
369 set_case_command (const char *ignore
, int from_tty
, struct cmd_list_element
*c
)
371 if (strcmp (case_sensitive
, "on") == 0)
373 case_sensitivity
= case_sensitive_on
;
374 case_mode
= case_mode_manual
;
376 else if (strcmp (case_sensitive
, "off") == 0)
378 case_sensitivity
= case_sensitive_off
;
379 case_mode
= case_mode_manual
;
381 else if (strcmp (case_sensitive
, "auto") == 0)
383 case_mode
= case_mode_auto
;
389 internal_error ("Unrecognized case-sensitive setting: \"%s\"",
393 if (case_sensitivity
!= current_language
->case_sensitivity ())
394 warning (_("the current case sensitivity setting does not match "
398 /* Set the status of range and type checking and case sensitivity based on
399 the current modes and the current language.
400 If SHOW is non-zero, then print out the current language,
401 type and range checking status. */
403 set_range_case (void)
405 if (range_mode
== range_mode_auto
)
406 range_check
= (current_language
->range_checking_on_by_default ()
407 ? range_check_on
: range_check_off
);
409 if (case_mode
== case_mode_auto
)
410 case_sensitivity
= current_language
->case_sensitivity ();
413 /* See language.h. */
416 set_language (enum language lang
)
418 lazy_language_setter
= nullptr;
419 global_current_language
= language_def (lang
);
424 /* See language.h. */
429 if (expected_language
== current_language
)
432 expected_language
= current_language
;
433 gdb_printf (_("Current language: %s\n"), get_language ());
434 show_language_command (gdb_stdout
, 1, NULL
, NULL
);
437 /* This page contains functions for the printing out of
438 error messages that occur during type- and range-
441 /* This is called when a language fails a range-check. The
442 first argument should be a printf()-style format string, and the
443 rest of the arguments should be its arguments. If range_check is
444 range_check_on, an error is printed; if range_check_warn, a warning;
445 otherwise just the message. */
448 range_error (const char *string
,...)
452 va_start (args
, string
);
455 case range_check_warn
:
456 vwarning (string
, args
);
459 verror (string
, args
);
461 case range_check_off
:
462 /* FIXME: cagney/2002-01-30: Should this function print anything
463 when range error is off? */
464 gdb_vprintf (gdb_stderr
, string
, args
);
465 gdb_printf (gdb_stderr
, "\n");
468 internal_error (_("bad switch"));
474 /* This page contains miscellaneous functions. */
476 /* Return the language enum for a given language string. */
479 language_enum (const char *str
)
481 for (const auto &lang
: language_defn::languages
)
482 if (strcmp (lang
->name (), str
) == 0)
483 return lang
->la_language
;
485 return language_unknown
;
488 /* Return the language struct for a given language enum. */
490 const struct language_defn
*
491 language_def (enum language lang
)
493 const struct language_defn
*l
= language_defn::languages
[lang
];
494 gdb_assert (l
!= nullptr);
498 /* Return the language as a string. */
501 language_str (enum language lang
)
503 return language_def (lang
)->name ();
508 /* Build and install the "set language LANG" command. */
511 add_set_language_command ()
513 static const char **language_names
;
515 /* Build the language names array, to be used as enumeration in the
516 "set language" enum command. +3 for "auto", "local" and NULL
518 language_names
= new const char *[ARRAY_SIZE (language_defn::languages
) + 3];
520 /* Display "auto", "local" and "unknown" first, and then the rest,
522 const char **language_names_p
= language_names
;
523 *language_names_p
++ = "auto";
524 *language_names_p
++ = "local";
525 *language_names_p
++ = language_def (language_unknown
)->name ();
526 const char **sort_begin
= language_names_p
;
527 for (const auto &lang
: language_defn::languages
)
529 /* Already handled above. */
530 if (lang
->la_language
== language_unknown
)
532 *language_names_p
++ = lang
->name ();
534 *language_names_p
= NULL
;
535 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
537 /* Add the filename extensions. */
538 for (const auto &lang
: language_defn::languages
)
539 for (const char * const &ext
: lang
->filename_extensions ())
540 add_filename_language (ext
, lang
->la_language
);
542 /* Build the "help set language" docs. */
545 doc
.printf (_("Set the current source language.\n"
546 "The currently understood settings are:\n\nlocal or "
547 "auto Automatic setting based on source file"));
549 for (const auto &lang
: language_defn::languages
)
551 /* Already dealt with these above. */
552 if (lang
->la_language
== language_unknown
)
555 /* Note that we add the newline at the front, so we don't wind
556 up with a trailing newline. */
557 doc
.printf ("\n%-16s Use the %s language",
559 lang
->natural_name ());
562 add_setshow_enum_cmd ("language", class_support
,
565 _("Show the current source language."),
569 show_language_command
,
570 &setlist
, &showlist
);
573 /* Iterate through all registered languages looking for and calling
574 any non-NULL struct language_defn.skip_trampoline() functions.
575 Return the result from the first that returns non-zero, or 0 if all
578 skip_language_trampoline (const frame_info_ptr
&frame
, CORE_ADDR pc
)
580 for (const auto &lang
: language_defn::languages
)
582 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
591 /* Return information about whether TYPE should be passed
592 (and returned) by reference at the language level. */
594 struct language_pass_by_ref_info
595 language_pass_by_reference (struct type
*type
)
597 return current_language
->pass_by_reference_info (type
);
600 /* Return the default string containing the list of characters
601 delimiting words. This is a reasonable default value that
602 most languages should be able to use. */
605 default_word_break_characters (void)
607 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
610 /* See language.h. */
613 language_defn::print_array_index (struct type
*index_type
, LONGEST index
,
614 struct ui_file
*stream
,
615 const value_print_options
*options
) const
617 struct value
*index_value
= value_from_longest (index_type
, index
);
619 gdb_printf (stream
, "[");
620 value_print (index_value
, stream
, options
);
621 gdb_printf (stream
, "] = ");
624 /* See language.h. */
626 gdb::unique_xmalloc_ptr
<char>
627 language_defn::watch_location_expression (struct type
*type
,
628 CORE_ADDR addr
) const
630 /* Generates an expression that assumes a C like syntax is valid. */
631 type
= check_typedef (check_typedef (type
)->target_type ());
632 std::string name
= type_to_string (type
);
633 return xstrprintf ("* (%s *) %s", name
.c_str (), core_addr_to_string (addr
));
636 /* See language.h. */
639 language_defn::value_print (struct value
*val
, struct ui_file
*stream
,
640 const struct value_print_options
*options
) const
642 return c_value_print (val
, stream
, options
);
645 /* See language.h. */
648 language_defn::parser (struct parser_state
*ps
) const
653 /* See language.h. */
656 language_defn::value_print_inner
657 (struct value
*val
, struct ui_file
*stream
, int recurse
,
658 const struct value_print_options
*options
) const
660 return c_value_print_inner (val
, stream
, recurse
, options
);
663 /* See language.h. */
666 language_defn::print_typedef (struct type
*type
, struct symbol
*new_symbol
,
667 struct ui_file
*stream
) const
669 c_print_typedef (type
, new_symbol
, stream
);
672 /* See language.h. */
675 language_defn::is_string_type_p (struct type
*type
) const
677 return c_is_string_type_p (type
);
680 /* The default implementation of the get_symbol_name_matcher_inner method
681 from the language_defn class. Matches with strncmp_iw. */
684 default_symbol_name_matcher (const char *symbol_search_name
,
685 const lookup_name_info
&lookup_name
,
686 completion_match_result
*comp_match_res
)
688 std::string_view name
= lookup_name
.name ();
689 completion_match_for_lcd
*match_for_lcd
690 = (comp_match_res
!= NULL
? &comp_match_res
->match_for_lcd
: NULL
);
691 strncmp_iw_mode mode
= (lookup_name
.completion_mode ()
692 ? strncmp_iw_mode::NORMAL
693 : strncmp_iw_mode::MATCH_PARAMS
);
695 if (strncmp_iw_with_mode (symbol_search_name
, name
.data (), name
.size (),
696 mode
, language_minimal
, match_for_lcd
) == 0)
698 if (comp_match_res
!= NULL
)
699 comp_match_res
->set_match (symbol_search_name
);
706 /* See language.h. */
708 symbol_name_matcher_ftype
*
709 language_defn::get_symbol_name_matcher
710 (const lookup_name_info
&lookup_name
) const
712 /* If currently in Ada mode, and the lookup name is wrapped in
713 '<...>', hijack all symbol name comparisons using the Ada
714 matcher, which handles the verbatim matching. */
715 if (current_language
->la_language
== language_ada
716 && lookup_name
.ada ().verbatim_p ())
717 return current_language
->get_symbol_name_matcher_inner (lookup_name
);
719 return this->get_symbol_name_matcher_inner (lookup_name
);
722 /* See language.h. */
724 symbol_name_matcher_ftype
*
725 language_defn::get_symbol_name_matcher_inner
726 (const lookup_name_info
&lookup_name
) const
728 return default_symbol_name_matcher
;
731 /* See language.h. */
733 const struct lang_varobj_ops
*
734 language_defn::varobj_ops () const
736 /* The ops for the C language are suitable for the vast majority of the
737 supported languages. */
738 return &c_varobj_ops
;
741 /* Class representing the "unknown" language. */
743 class unknown_language
: public language_defn
746 unknown_language () : language_defn (language_unknown
)
749 /* See language.h. */
750 void language_arch_info (struct gdbarch
*gdbarch
,
751 struct language_arch_info
*lai
) const override
753 lai
->set_string_char_type (builtin_type (gdbarch
)->builtin_char
);
754 lai
->set_bool_type (builtin_type (gdbarch
)->builtin_int
);
757 /* See language.h. */
759 void print_type (struct type
*type
, const char *varstring
,
760 struct ui_file
*stream
, int show
, int level
,
761 const struct type_print_options
*flags
) const override
763 error (_("type printing not implemented for language \"%s\""),
767 /* See language.h. */
769 gdb::unique_xmalloc_ptr
<char> demangle_symbol (const char *mangled
,
770 int options
) const override
772 /* The auto language just uses the C++ demangler. */
773 return gdb_demangle (mangled
, options
);
776 /* See language.h. */
778 void value_print (struct value
*val
, struct ui_file
*stream
,
779 const struct value_print_options
*options
) const override
781 error (_("value printing not implemented for language \"%s\""),
785 /* See language.h. */
787 void value_print_inner
788 (struct value
*val
, struct ui_file
*stream
, int recurse
,
789 const struct value_print_options
*options
) const override
791 error (_("inner value printing not implemented for language \"%s\""),
795 /* See language.h. */
797 int parser (struct parser_state
*ps
) const override
799 error (_("expression parsing not implemented for language \"%s\""),
803 /* See language.h. */
805 void emitchar (int ch
, struct type
*chtype
,
806 struct ui_file
*stream
, int quoter
) const override
808 error (_("emit character not implemented for language \"%s\""),
812 /* See language.h. */
814 void printchar (int ch
, struct type
*chtype
,
815 struct ui_file
*stream
) const override
817 error (_("print character not implemented for language \"%s\""),
821 /* See language.h. */
823 void printstr (struct ui_file
*stream
, struct type
*elttype
,
824 const gdb_byte
*string
, unsigned int length
,
825 const char *encoding
, int force_ellipses
,
826 const struct value_print_options
*options
) const override
828 error (_("print string not implemented for language \"%s\""),
832 /* See language.h. */
834 void print_typedef (struct type
*type
, struct symbol
*new_symbol
,
835 struct ui_file
*stream
) const override
837 error (_("print typedef not implemented for language \"%s\""),
841 /* See language.h. */
843 bool is_string_type_p (struct type
*type
) const override
845 type
= check_typedef (type
);
846 while (type
->code () == TYPE_CODE_REF
)
848 type
= type
->target_type ();
849 type
= check_typedef (type
);
851 return (type
->code () == TYPE_CODE_STRING
);
854 /* See language.h. */
856 const char *name_of_this () const override
859 /* See language.h. */
861 const char *name () const override
862 { return "unknown"; }
864 /* See language.h. */
866 const char *natural_name () const override
867 { return "Unknown"; }
869 /* See language.h. */
871 bool store_sym_names_in_linkage_form_p () const override
875 /* Single instance of the unknown language class. */
877 static unknown_language unknown_language_defn
;
880 /* Per-architecture language information. */
882 struct language_gdbarch
884 /* A vector of per-language per-architecture info. Indexed by "enum
886 struct language_arch_info arch_info
[nr_languages
];
889 static const registry
<gdbarch
>::key
<language_gdbarch
> language_gdbarch_data
;
891 static language_gdbarch
*
892 get_language_gdbarch (struct gdbarch
*gdbarch
)
894 struct language_gdbarch
*l
= language_gdbarch_data
.get (gdbarch
);
897 l
= new struct language_gdbarch
;
898 for (const auto &lang
: language_defn::languages
)
900 gdb_assert (lang
!= nullptr);
901 lang
->language_arch_info (gdbarch
, &l
->arch_info
[lang
->la_language
]);
903 language_gdbarch_data
.set (gdbarch
, l
);
909 /* See language.h. */
912 language_string_char_type (const struct language_defn
*la
,
913 struct gdbarch
*gdbarch
)
915 struct language_gdbarch
*ld
= get_language_gdbarch (gdbarch
);
916 return ld
->arch_info
[la
->la_language
].string_char_type ();
919 /* See language.h. */
922 language_defn::value_string (struct gdbarch
*gdbarch
,
923 const char *ptr
, ssize_t len
) const
925 struct type
*type
= language_string_char_type (this, gdbarch
);
926 return value_cstring (ptr
, len
, type
);
929 /* See language.h. */
932 language_bool_type (const struct language_defn
*la
,
933 struct gdbarch
*gdbarch
)
935 struct language_gdbarch
*ld
= get_language_gdbarch (gdbarch
);
936 return ld
->arch_info
[la
->la_language
].bool_type ();
939 /* See language.h. */
942 language_arch_info::bool_type () const
944 if (m_bool_type_name
!= nullptr)
948 sym
= lookup_symbol (m_bool_type_name
, nullptr, SEARCH_TYPE_DOMAIN
,
952 struct type
*type
= sym
->type ();
953 if (type
!= nullptr && type
->code () == TYPE_CODE_BOOL
)
958 return m_bool_type_default
;
961 /* See language.h. */
964 language_arch_info::type_and_symbol::alloc_type_symbol
965 (enum language lang
, struct type
*type
)
967 struct symbol
*symbol
;
968 struct gdbarch
*gdbarch
;
969 gdb_assert (!type
->is_objfile_owned ());
970 gdbarch
= type
->arch_owner ();
971 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
972 symbol
->m_name
= type
->name ();
973 symbol
->set_language (lang
, nullptr);
974 symbol
->owner
.arch
= gdbarch
;
975 symbol
->set_is_objfile_owned (0);
976 symbol
->set_section_index (0);
977 symbol
->set_type (type
);
978 symbol
->set_domain (TYPE_DOMAIN
);
979 symbol
->set_aclass_index (LOC_TYPEDEF
);
983 /* See language.h. */
985 language_arch_info::type_and_symbol
*
986 language_arch_info::lookup_primitive_type_and_symbol (const char *name
)
988 for (struct type_and_symbol
&tas
: primitive_types_and_symbols
)
990 if (strcmp (tas
.type ()->name (), name
) == 0)
997 /* See language.h. */
1000 language_arch_info::lookup_primitive_type (const char *name
)
1002 type_and_symbol
*tas
= lookup_primitive_type_and_symbol (name
);
1004 return tas
->type ();
1008 /* See language.h. */
1011 language_arch_info::lookup_primitive_type
1012 (gdb::function_view
<bool (struct type
*)> filter
)
1014 for (struct type_and_symbol
&tas
: primitive_types_and_symbols
)
1016 if (filter (tas
.type ()))
1023 /* See language.h. */
1026 language_arch_info::lookup_primitive_type_as_symbol (const char *name
,
1029 type_and_symbol
*tas
= lookup_primitive_type_and_symbol (name
);
1031 return tas
->symbol (lang
);
1035 /* Helper for the language_lookup_primitive_type overloads to forward
1036 to the corresponding language's lookup_primitive_type overload. */
1038 template<typename T
>
1039 static struct type
*
1040 language_lookup_primitive_type_1 (const struct language_defn
*la
,
1041 struct gdbarch
*gdbarch
,
1044 struct language_gdbarch
*ld
= get_language_gdbarch (gdbarch
);
1045 return ld
->arch_info
[la
->la_language
].lookup_primitive_type (arg
);
1048 /* See language.h. */
1051 language_lookup_primitive_type (const struct language_defn
*la
,
1052 struct gdbarch
*gdbarch
,
1055 return language_lookup_primitive_type_1 (la
, gdbarch
, name
);
1058 /* See language.h. */
1061 language_lookup_primitive_type (const struct language_defn
*la
,
1062 struct gdbarch
*gdbarch
,
1063 gdb::function_view
<bool (struct type
*)> filter
)
1065 return language_lookup_primitive_type_1 (la
, gdbarch
, filter
);
1068 /* See language.h. */
1071 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1072 struct gdbarch
*gdbarch
,
1075 struct language_gdbarch
*ld
= get_language_gdbarch (gdbarch
);
1076 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1078 symbol_lookup_debug_printf
1079 ("language = \"%s\", gdbarch @ %s, type = \"%s\")",
1080 la
->name (), host_address_to_string (gdbarch
), name
);
1083 = lai
->lookup_primitive_type_as_symbol (name
, la
->la_language
);
1085 symbol_lookup_debug_printf ("found symbol @ %s",
1086 host_address_to_string (sym
));
1088 /* Note: The result of symbol lookup is normally a symbol *and* the block
1089 it was found in. Builtin types don't live in blocks. We *could* give
1090 them one, but there is no current need so to keep things simple symbol
1091 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1096 /* Initialize the language routines. */
1098 INIT_GDB_FILE (language
)
1100 static const char *const type_or_range_names
[]
1101 = { "on", "off", "warn", "auto", NULL
};
1103 static const char *const case_sensitive_names
[]
1104 = { "on", "off", "auto", NULL
};
1106 /* GDB commands for language specific stuff. */
1108 set_show_commands setshow_check_cmds
1109 = add_setshow_prefix_cmd ("check", no_class
,
1110 _("Set the status of the type/range checker."),
1111 _("Show the status of the type/range checker."),
1112 &setchecklist
, &showchecklist
,
1113 &setlist
, &showlist
);
1114 add_alias_cmd ("c", setshow_check_cmds
.set
, no_class
, 1, &setlist
);
1115 add_alias_cmd ("ch", setshow_check_cmds
.set
, no_class
, 1, &setlist
);
1116 add_alias_cmd ("c", setshow_check_cmds
.show
, no_class
, 1, &showlist
);
1117 add_alias_cmd ("ch", setshow_check_cmds
.show
, no_class
, 1, &showlist
);
1119 range
= type_or_range_names
[3];
1120 gdb_assert (strcmp (range
, "auto") == 0);
1121 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1123 _("Set range checking (on/warn/off/auto)."),
1124 _("Show range checking (on/warn/off/auto)."),
1125 NULL
, set_range_command
,
1127 &setchecklist
, &showchecklist
);
1129 case_sensitive
= case_sensitive_names
[2];
1130 gdb_assert (strcmp (case_sensitive
, "auto") == 0);
1131 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1132 &case_sensitive
, _("\
1133 Set case sensitivity in name search (on/off/auto)."), _("\
1134 Show case sensitivity in name search (on/off/auto)."), _("\
1135 For Fortran the default is off; for other languages the default is on."),
1138 &setlist
, &showlist
);
1140 add_setshow_boolean_cmd ("warn-language-frame-mismatch", class_obscure
,
1141 &warn_frame_lang_mismatch
, _("\
1142 Enable or disable the frame language-mismatch warning."),
1144 Show the current setting of the frame language-mismatch warning."),
1146 The frame-language-mismatch warning is issued when the current language\n\
1147 does not match the selected frame's language."), nullptr, nullptr,
1148 &setlist
, &showlist
);
1150 add_set_language_command ();