1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2024 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 /* See language.h. */
682 std::unique_ptr
<compile_instance
>
683 language_defn::get_compile_instance () const
688 /* The default implementation of the get_symbol_name_matcher_inner method
689 from the language_defn class. Matches with strncmp_iw. */
692 default_symbol_name_matcher (const char *symbol_search_name
,
693 const lookup_name_info
&lookup_name
,
694 completion_match_result
*comp_match_res
)
696 std::string_view name
= lookup_name
.name ();
697 completion_match_for_lcd
*match_for_lcd
698 = (comp_match_res
!= NULL
? &comp_match_res
->match_for_lcd
: NULL
);
699 strncmp_iw_mode mode
= (lookup_name
.completion_mode ()
700 ? strncmp_iw_mode::NORMAL
701 : strncmp_iw_mode::MATCH_PARAMS
);
703 if (strncmp_iw_with_mode (symbol_search_name
, name
.data (), name
.size (),
704 mode
, language_minimal
, match_for_lcd
) == 0)
706 if (comp_match_res
!= NULL
)
707 comp_match_res
->set_match (symbol_search_name
);
714 /* See language.h. */
716 symbol_name_matcher_ftype
*
717 language_defn::get_symbol_name_matcher
718 (const lookup_name_info
&lookup_name
) const
720 /* If currently in Ada mode, and the lookup name is wrapped in
721 '<...>', hijack all symbol name comparisons using the Ada
722 matcher, which handles the verbatim matching. */
723 if (current_language
->la_language
== language_ada
724 && lookup_name
.ada ().verbatim_p ())
725 return current_language
->get_symbol_name_matcher_inner (lookup_name
);
727 return this->get_symbol_name_matcher_inner (lookup_name
);
730 /* See language.h. */
732 symbol_name_matcher_ftype
*
733 language_defn::get_symbol_name_matcher_inner
734 (const lookup_name_info
&lookup_name
) const
736 return default_symbol_name_matcher
;
739 /* See language.h. */
741 const struct lang_varobj_ops
*
742 language_defn::varobj_ops () const
744 /* The ops for the C language are suitable for the vast majority of the
745 supported languages. */
746 return &c_varobj_ops
;
749 /* Class representing the "unknown" language. */
751 class unknown_language
: public language_defn
754 unknown_language () : language_defn (language_unknown
)
757 /* See language.h. */
758 void language_arch_info (struct gdbarch
*gdbarch
,
759 struct language_arch_info
*lai
) const override
761 lai
->set_string_char_type (builtin_type (gdbarch
)->builtin_char
);
762 lai
->set_bool_type (builtin_type (gdbarch
)->builtin_int
);
765 /* See language.h. */
767 void print_type (struct type
*type
, const char *varstring
,
768 struct ui_file
*stream
, int show
, int level
,
769 const struct type_print_options
*flags
) const override
771 error (_("type printing not implemented for language \"%s\""),
775 /* See language.h. */
777 gdb::unique_xmalloc_ptr
<char> demangle_symbol (const char *mangled
,
778 int options
) const override
780 /* The auto language just uses the C++ demangler. */
781 return gdb_demangle (mangled
, options
);
784 /* See language.h. */
786 void value_print (struct value
*val
, struct ui_file
*stream
,
787 const struct value_print_options
*options
) const override
789 error (_("value printing not implemented for language \"%s\""),
793 /* See language.h. */
795 void value_print_inner
796 (struct value
*val
, struct ui_file
*stream
, int recurse
,
797 const struct value_print_options
*options
) const override
799 error (_("inner value printing not implemented for language \"%s\""),
803 /* See language.h. */
805 int parser (struct parser_state
*ps
) const override
807 error (_("expression parsing not implemented for language \"%s\""),
811 /* See language.h. */
813 void emitchar (int ch
, struct type
*chtype
,
814 struct ui_file
*stream
, int quoter
) const override
816 error (_("emit character not implemented for language \"%s\""),
820 /* See language.h. */
822 void printchar (int ch
, struct type
*chtype
,
823 struct ui_file
*stream
) const override
825 error (_("print character not implemented for language \"%s\""),
829 /* See language.h. */
831 void printstr (struct ui_file
*stream
, struct type
*elttype
,
832 const gdb_byte
*string
, unsigned int length
,
833 const char *encoding
, int force_ellipses
,
834 const struct value_print_options
*options
) const override
836 error (_("print string not implemented for language \"%s\""),
840 /* See language.h. */
842 void print_typedef (struct type
*type
, struct symbol
*new_symbol
,
843 struct ui_file
*stream
) const override
845 error (_("print typedef not implemented for language \"%s\""),
849 /* See language.h. */
851 bool is_string_type_p (struct type
*type
) const override
853 type
= check_typedef (type
);
854 while (type
->code () == TYPE_CODE_REF
)
856 type
= type
->target_type ();
857 type
= check_typedef (type
);
859 return (type
->code () == TYPE_CODE_STRING
);
862 /* See language.h. */
864 const char *name_of_this () const override
867 /* See language.h. */
869 const char *name () const override
870 { return "unknown"; }
872 /* See language.h. */
874 const char *natural_name () const override
875 { return "Unknown"; }
877 /* See language.h. */
879 bool store_sym_names_in_linkage_form_p () const override
883 /* Single instance of the unknown language class. */
885 static unknown_language unknown_language_defn
;
888 /* Per-architecture language information. */
890 struct language_gdbarch
892 /* A vector of per-language per-architecture info. Indexed by "enum
894 struct language_arch_info arch_info
[nr_languages
];
897 static const registry
<gdbarch
>::key
<language_gdbarch
> language_gdbarch_data
;
899 static language_gdbarch
*
900 get_language_gdbarch (struct gdbarch
*gdbarch
)
902 struct language_gdbarch
*l
= language_gdbarch_data
.get (gdbarch
);
905 l
= new struct language_gdbarch
;
906 for (const auto &lang
: language_defn::languages
)
908 gdb_assert (lang
!= nullptr);
909 lang
->language_arch_info (gdbarch
, &l
->arch_info
[lang
->la_language
]);
911 language_gdbarch_data
.set (gdbarch
, l
);
917 /* See language.h. */
920 language_string_char_type (const struct language_defn
*la
,
921 struct gdbarch
*gdbarch
)
923 struct language_gdbarch
*ld
= get_language_gdbarch (gdbarch
);
924 return ld
->arch_info
[la
->la_language
].string_char_type ();
927 /* See language.h. */
930 language_defn::value_string (struct gdbarch
*gdbarch
,
931 const char *ptr
, ssize_t len
) const
933 struct type
*type
= language_string_char_type (this, gdbarch
);
934 return value_cstring (ptr
, len
, type
);
937 /* See language.h. */
940 language_bool_type (const struct language_defn
*la
,
941 struct gdbarch
*gdbarch
)
943 struct language_gdbarch
*ld
= get_language_gdbarch (gdbarch
);
944 return ld
->arch_info
[la
->la_language
].bool_type ();
947 /* See language.h. */
950 language_arch_info::bool_type () const
952 if (m_bool_type_name
!= nullptr)
956 sym
= lookup_symbol (m_bool_type_name
, nullptr, SEARCH_TYPE_DOMAIN
,
960 struct type
*type
= sym
->type ();
961 if (type
!= nullptr && type
->code () == TYPE_CODE_BOOL
)
966 return m_bool_type_default
;
969 /* See language.h. */
972 language_arch_info::type_and_symbol::alloc_type_symbol
973 (enum language lang
, struct type
*type
)
975 struct symbol
*symbol
;
976 struct gdbarch
*gdbarch
;
977 gdb_assert (!type
->is_objfile_owned ());
978 gdbarch
= type
->arch_owner ();
979 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
980 symbol
->m_name
= type
->name ();
981 symbol
->set_language (lang
, nullptr);
982 symbol
->owner
.arch
= gdbarch
;
983 symbol
->set_is_objfile_owned (0);
984 symbol
->set_section_index (0);
985 symbol
->set_type (type
);
986 symbol
->set_domain (TYPE_DOMAIN
);
987 symbol
->set_aclass_index (LOC_TYPEDEF
);
991 /* See language.h. */
993 language_arch_info::type_and_symbol
*
994 language_arch_info::lookup_primitive_type_and_symbol (const char *name
)
996 for (struct type_and_symbol
&tas
: primitive_types_and_symbols
)
998 if (strcmp (tas
.type ()->name (), name
) == 0)
1005 /* See language.h. */
1008 language_arch_info::lookup_primitive_type (const char *name
)
1010 type_and_symbol
*tas
= lookup_primitive_type_and_symbol (name
);
1012 return tas
->type ();
1016 /* See language.h. */
1019 language_arch_info::lookup_primitive_type
1020 (gdb::function_view
<bool (struct type
*)> filter
)
1022 for (struct type_and_symbol
&tas
: primitive_types_and_symbols
)
1024 if (filter (tas
.type ()))
1031 /* See language.h. */
1034 language_arch_info::lookup_primitive_type_as_symbol (const char *name
,
1037 type_and_symbol
*tas
= lookup_primitive_type_and_symbol (name
);
1039 return tas
->symbol (lang
);
1043 /* Helper for the language_lookup_primitive_type overloads to forward
1044 to the corresponding language's lookup_primitive_type overload. */
1046 template<typename T
>
1047 static struct type
*
1048 language_lookup_primitive_type_1 (const struct language_defn
*la
,
1049 struct gdbarch
*gdbarch
,
1052 struct language_gdbarch
*ld
= get_language_gdbarch (gdbarch
);
1053 return ld
->arch_info
[la
->la_language
].lookup_primitive_type (arg
);
1056 /* See language.h. */
1059 language_lookup_primitive_type (const struct language_defn
*la
,
1060 struct gdbarch
*gdbarch
,
1063 return language_lookup_primitive_type_1 (la
, gdbarch
, name
);
1066 /* See language.h. */
1069 language_lookup_primitive_type (const struct language_defn
*la
,
1070 struct gdbarch
*gdbarch
,
1071 gdb::function_view
<bool (struct type
*)> filter
)
1073 return language_lookup_primitive_type_1 (la
, gdbarch
, filter
);
1076 /* See language.h. */
1079 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1080 struct gdbarch
*gdbarch
,
1083 struct language_gdbarch
*ld
= get_language_gdbarch (gdbarch
);
1084 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1086 symbol_lookup_debug_printf
1087 ("language = \"%s\", gdbarch @ %s, type = \"%s\")",
1088 la
->name (), host_address_to_string (gdbarch
), name
);
1091 = lai
->lookup_primitive_type_as_symbol (name
, la
->la_language
);
1093 symbol_lookup_debug_printf ("found symbol @ %s",
1094 host_address_to_string (sym
));
1096 /* Note: The result of symbol lookup is normally a symbol *and* the block
1097 it was found in. Builtin types don't live in blocks. We *could* give
1098 them one, but there is no current need so to keep things simple symbol
1099 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1104 /* Initialize the language routines. */
1106 void _initialize_language ();
1108 _initialize_language ()
1110 static const char *const type_or_range_names
[]
1111 = { "on", "off", "warn", "auto", NULL
};
1113 static const char *const case_sensitive_names
[]
1114 = { "on", "off", "auto", NULL
};
1116 /* GDB commands for language specific stuff. */
1118 set_show_commands setshow_check_cmds
1119 = add_setshow_prefix_cmd ("check", no_class
,
1120 _("Set the status of the type/range checker."),
1121 _("Show the status of the type/range checker."),
1122 &setchecklist
, &showchecklist
,
1123 &setlist
, &showlist
);
1124 add_alias_cmd ("c", setshow_check_cmds
.set
, no_class
, 1, &setlist
);
1125 add_alias_cmd ("ch", setshow_check_cmds
.set
, no_class
, 1, &setlist
);
1126 add_alias_cmd ("c", setshow_check_cmds
.show
, no_class
, 1, &showlist
);
1127 add_alias_cmd ("ch", setshow_check_cmds
.show
, no_class
, 1, &showlist
);
1129 range
= type_or_range_names
[3];
1130 gdb_assert (strcmp (range
, "auto") == 0);
1131 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1133 _("Set range checking (on/warn/off/auto)."),
1134 _("Show range checking (on/warn/off/auto)."),
1135 NULL
, set_range_command
,
1137 &setchecklist
, &showchecklist
);
1139 case_sensitive
= case_sensitive_names
[2];
1140 gdb_assert (strcmp (case_sensitive
, "auto") == 0);
1141 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1142 &case_sensitive
, _("\
1143 Set case sensitivity in name search (on/off/auto)."), _("\
1144 Show case sensitivity in name search (on/off/auto)."), _("\
1145 For Fortran the default is off; for other languages the default is on."),
1148 &setlist
, &showlist
);
1150 add_setshow_boolean_cmd ("warn-language-frame-mismatch", class_obscure
,
1151 &warn_frame_lang_mismatch
, _("\
1152 Enable or disable the frame language-mismatch warning."),
1154 Show the current setting of the frame language-mismatch warning."),
1156 The frame-language-mismatch warning is issued when the current language\n\
1157 does not match the selected frame's language."), nullptr, nullptr,
1158 &setlist
, &showlist
);
1160 add_set_language_command ();