1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2018 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"
49 static int unk_lang_parser (struct parser_state *);
51 static void set_range_case (void);
53 static void unk_lang_emit_char (int c, struct type *type,
54 struct ui_file *stream, int quoter);
56 static void unk_lang_printchar (int c, struct type *type,
57 struct ui_file *stream);
59 static void unk_lang_value_print (struct value *, struct ui_file *,
60 const struct value_print_options *);
62 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
64 /* Forward declaration */
65 extern const struct language_defn unknown_language_defn;
67 /* The current (default at startup) state of type and range checking.
68 (If the modes are set to "auto", though, these are changed based
69 on the default language at startup, and then again based on the
70 language of the first source file. */
72 enum range_mode range_mode = range_mode_auto;
73 enum range_check range_check = range_check_off;
74 enum case_mode case_mode = case_mode_auto;
75 enum case_sensitivity case_sensitivity = case_sensitive_on;
77 /* The current language and language_mode (see language.h). */
79 const struct language_defn *current_language = &unknown_language_defn;
80 enum language_mode language_mode = language_mode_auto;
82 /* The language that the user expects to be typing in (the language
83 of main(), or the last language we notified them about, or C). */
85 const struct language_defn *expected_language;
87 /* The list of supported languages. Keep this in the same order as
88 the 'enum language' values. */
90 static const struct language_defn *languages[] = {
91 &unknown_language_defn,
101 &pascal_language_defn,
102 &opencl_language_defn,
104 &minimal_language_defn,
108 /* The current values of the "set language/range/case-sensitive" enum
110 static const char *language;
111 static const char *range;
112 static const char *case_sensitive;
114 /* Warning issued when current_language and the language of the current
115 frame do not match. */
116 char lang_frame_mismatch_warn[] =
117 "Warning: the current language does not match this frame.";
119 /* This page contains the functions corresponding to GDB commands
120 and their helpers. */
122 /* Show command. Display a warning if the language set
123 does not match the frame. */
125 show_language_command (struct ui_file *file, int from_tty,
126 struct cmd_list_element *c, const char *value)
128 enum language flang; /* The language of the frame. */
130 if (language_mode == language_mode_auto)
131 fprintf_filtered (gdb_stdout,
132 _("The current source language is "
133 "\"auto; currently %s\".\n"),
134 current_language->la_name);
136 fprintf_filtered (gdb_stdout,
137 _("The current source language is \"%s\".\n"),
138 current_language->la_name);
140 if (has_stack_frames ())
142 struct frame_info *frame;
144 frame = get_selected_frame (NULL);
145 flang = get_frame_language (frame);
146 if (flang != language_unknown
147 && language_mode == language_mode_manual
148 && current_language->la_language != flang)
149 printf_filtered ("%s\n", lang_frame_mismatch_warn);
153 /* Set command. Change the current working language. */
155 set_language_command (const char *ignore,
156 int from_tty, struct cmd_list_element *c)
158 enum language flang = language_unknown;
160 /* "local" is a synonym of "auto". */
161 if (strcmp (language, "local") == 0)
164 /* Search the list of languages for a match. */
165 for (const auto &lang : languages)
167 if (strcmp (lang->la_name, language) == 0)
169 /* Found it! Go into manual mode, and use this language. */
170 if (lang->la_language == language_auto)
172 /* Enter auto mode. Set to the current frame's language, if
173 known, or fallback to the initial language. */
174 language_mode = language_mode_auto;
177 struct frame_info *frame;
179 frame = get_selected_frame (NULL);
180 flang = get_frame_language (frame);
182 CATCH (ex, RETURN_MASK_ERROR)
184 flang = language_unknown;
188 if (flang != language_unknown)
189 set_language (flang);
191 set_initial_language ();
192 expected_language = current_language;
197 /* Enter manual mode. Set the specified language. */
198 language_mode = language_mode_manual;
199 current_language = lang;
201 expected_language = current_language;
207 internal_error (__FILE__, __LINE__,
208 "Couldn't find language `%s' in known languages list.",
212 /* Show command. Display a warning if the range setting does
213 not match the current language. */
215 show_range_command (struct ui_file *file, int from_tty,
216 struct cmd_list_element *c, const char *value)
218 if (range_mode == range_mode_auto)
227 case range_check_off:
230 case range_check_warn:
234 internal_error (__FILE__, __LINE__,
235 "Unrecognized range check setting.");
238 fprintf_filtered (gdb_stdout,
239 _("Range checking is \"auto; currently %s\".\n"),
243 fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"),
246 if (range_check != current_language->la_range_check)
247 warning (_("the current range check setting "
248 "does not match the language.\n"));
251 /* Set command. Change the setting for range checking. */
253 set_range_command (const char *ignore,
254 int from_tty, struct cmd_list_element *c)
256 if (strcmp (range, "on") == 0)
258 range_check = range_check_on;
259 range_mode = range_mode_manual;
261 else if (strcmp (range, "warn") == 0)
263 range_check = range_check_warn;
264 range_mode = range_mode_manual;
266 else if (strcmp (range, "off") == 0)
268 range_check = range_check_off;
269 range_mode = range_mode_manual;
271 else if (strcmp (range, "auto") == 0)
273 range_mode = range_mode_auto;
279 internal_error (__FILE__, __LINE__,
280 _("Unrecognized range check setting: \"%s\""), range);
282 if (range_check != current_language->la_range_check)
283 warning (_("the current range check setting "
284 "does not match the language.\n"));
287 /* Show command. Display a warning if the case sensitivity setting does
288 not match the current language. */
290 show_case_command (struct ui_file *file, int from_tty,
291 struct cmd_list_element *c, const char *value)
293 if (case_mode == case_mode_auto)
295 const char *tmp = NULL;
297 switch (case_sensitivity)
299 case case_sensitive_on:
302 case case_sensitive_off:
306 internal_error (__FILE__, __LINE__,
307 "Unrecognized case-sensitive setting.");
310 fprintf_filtered (gdb_stdout,
311 _("Case sensitivity in "
312 "name search is \"auto; currently %s\".\n"),
316 fprintf_filtered (gdb_stdout,
317 _("Case sensitivity in name search is \"%s\".\n"),
320 if (case_sensitivity != current_language->la_case_sensitivity)
321 warning (_("the current case sensitivity setting does not match "
325 /* Set command. Change the setting for case sensitivity. */
328 set_case_command (const char *ignore, int from_tty, struct cmd_list_element *c)
330 if (strcmp (case_sensitive, "on") == 0)
332 case_sensitivity = case_sensitive_on;
333 case_mode = case_mode_manual;
335 else if (strcmp (case_sensitive, "off") == 0)
337 case_sensitivity = case_sensitive_off;
338 case_mode = case_mode_manual;
340 else if (strcmp (case_sensitive, "auto") == 0)
342 case_mode = case_mode_auto;
348 internal_error (__FILE__, __LINE__,
349 "Unrecognized case-sensitive setting: \"%s\"",
353 if (case_sensitivity != current_language->la_case_sensitivity)
354 warning (_("the current case sensitivity setting does not match "
358 /* Set the status of range and type checking and case sensitivity based on
359 the current modes and the current language.
360 If SHOW is non-zero, then print out the current language,
361 type and range checking status. */
363 set_range_case (void)
365 if (range_mode == range_mode_auto)
366 range_check = current_language->la_range_check;
368 if (case_mode == case_mode_auto)
369 case_sensitivity = current_language->la_case_sensitivity;
372 /* Set current language to (enum language) LANG. Returns previous
376 set_language (enum language lang)
378 enum language prev_language;
380 prev_language = current_language->la_language;
381 current_language = languages[lang];
383 return prev_language;
387 /* Print out the current language settings: language, range and
388 type checking. If QUIETLY, print only what has changed. */
391 language_info (int quietly)
393 if (quietly && expected_language == current_language)
396 expected_language = current_language;
397 printf_unfiltered (_("Current language: %s\n"), language);
398 show_language_command (NULL, 1, NULL, NULL);
402 printf_unfiltered (_("Range checking: %s\n"), range);
403 show_range_command (NULL, 1, NULL, NULL);
404 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
405 show_case_command (NULL, 1, NULL, NULL);
410 /* Returns non-zero if the value is a pointer type. */
412 pointer_type (struct type *type)
414 return TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type);
418 /* This page contains functions that return info about
419 (struct value) values used in GDB. */
421 /* Returns non-zero if the value VAL represents a true value. */
423 value_true (struct value *val)
425 /* It is possible that we should have some sort of error if a non-boolean
426 value is used in this context. Possibly dependent on some kind of
427 "boolean-checking" option like range checking. But it should probably
428 not depend on the language except insofar as is necessary to identify
429 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
430 should be an error, probably). */
431 return !value_logical_not (val);
434 /* This page contains functions for the printing out of
435 error messages that occur during type- and range-
438 /* This is called when a language fails a range-check. The
439 first argument should be a printf()-style format string, and the
440 rest of the arguments should be its arguments. If range_check is
441 range_check_on, an error is printed; if range_check_warn, a warning;
442 otherwise just the message. */
445 range_error (const char *string,...)
449 va_start (args, string);
452 case range_check_warn:
453 vwarning (string, args);
456 verror (string, args);
458 case range_check_off:
459 /* FIXME: cagney/2002-01-30: Should this function print anything
460 when range error is off? */
461 vfprintf_filtered (gdb_stderr, string, args);
462 fprintf_filtered (gdb_stderr, "\n");
465 internal_error (__FILE__, __LINE__, _("bad switch"));
471 /* This page contains miscellaneous functions. */
473 /* Return the language enum for a given language string. */
476 language_enum (const char *str)
478 for (const auto &lang : languages)
479 if (strcmp (lang->la_name, str) == 0)
480 return lang->la_language;
482 if (strcmp (str, "local") == 0)
483 return language_auto;
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 return languages[lang];
496 /* Return the language as a string. */
499 language_str (enum language lang)
501 return languages[lang]->la_name;
505 set_check (const char *ignore, int from_tty)
508 "\"set check\" must be followed by the name of a check subcommand.\n");
509 help_list (setchecklist, "set check ", all_commands, gdb_stdout);
513 show_check (const char *ignore, int from_tty)
515 cmd_show_list (showchecklist, from_tty, "");
519 /* Build and install the "set language LANG" command. */
522 add_set_language_command ()
524 static const char **language_names;
526 /* Build the language names array, to be used as enumeration in the
527 "set language" enum command. +1 for "local" and +1 for NULL
529 language_names = new const char *[ARRAY_SIZE (languages) + 2];
531 /* Display "auto", "local" and "unknown" first, and then the rest,
533 const char **language_names_p = language_names;
534 *language_names_p++ = auto_language_defn.la_name;
535 *language_names_p++ = "local";
536 *language_names_p++ = unknown_language_defn.la_name;
537 const char **sort_begin = language_names_p;
538 for (const auto &lang : languages)
540 /* Already handled above. */
541 if (lang->la_language == language_auto
542 || lang->la_language == language_unknown)
544 *language_names_p++ = lang->la_name;
546 *language_names_p = NULL;
547 std::sort (sort_begin, language_names_p, compare_cstrings);
549 /* Add the filename extensions. */
550 for (const auto &lang : languages)
551 if (lang->la_filename_extensions != NULL)
553 for (size_t i = 0; lang->la_filename_extensions[i] != NULL; ++i)
554 add_filename_language (lang->la_filename_extensions[i],
558 /* Build the "help set language" docs. */
561 doc.printf (_("Set the current source language.\n"
562 "The currently understood settings are:\n\nlocal or "
563 "auto Automatic setting based on source file\n"));
565 for (const auto &lang : languages)
567 /* Already dealt with these above. */
568 if (lang->la_language == language_unknown
569 || lang->la_language == language_auto)
572 /* FIXME: i18n: for now assume that the human-readable name is
573 just a capitalization of the internal name. */
574 doc.printf ("%-16s Use the %c%s language\n",
576 /* Capitalize first letter of language name. */
577 toupper (lang->la_name[0]),
581 add_setshow_enum_cmd ("language", class_support,
585 _("Show the current source language."),
586 NULL, set_language_command,
587 show_language_command,
588 &setlist, &showlist);
591 /* Iterate through all registered languages looking for and calling
592 any non-NULL struct language_defn.skip_trampoline() functions.
593 Return the result from the first that returns non-zero, or 0 if all
596 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
598 for (const auto &lang : languages)
600 if (lang->skip_trampoline != NULL)
602 CORE_ADDR real_pc = lang->skip_trampoline (frame, pc);
612 /* Return demangled language symbol, or NULL.
613 FIXME: Options are only useful for certain languages and ignored
614 by others, so it would be better to remove them here and have a
615 more flexible demangler for the languages that need it.
616 FIXME: Sometimes the demangler is invoked when we don't know the
617 language, so we can't use this everywhere. */
619 language_demangle (const struct language_defn *current_language,
620 const char *mangled, int options)
622 if (current_language != NULL && current_language->la_demangle)
623 return current_language->la_demangle (mangled, options);
627 /* See langauge.h. */
630 language_sniff_from_mangled_name (const struct language_defn *lang,
631 const char *mangled, char **demangled)
633 gdb_assert (lang != NULL);
635 if (lang->la_sniff_from_mangled_name == NULL)
641 return lang->la_sniff_from_mangled_name (mangled, demangled);
644 /* Return class name from physname or NULL. */
646 language_class_name_from_physname (const struct language_defn *lang,
647 const char *physname)
649 if (lang != NULL && lang->la_class_name_from_physname)
650 return lang->la_class_name_from_physname (physname);
654 /* Return non-zero if TYPE should be passed (and returned) by
655 reference at the language level. */
657 language_pass_by_reference (struct type *type)
659 return current_language->la_pass_by_reference (type);
662 /* Return zero; by default, types are passed by value at the language
663 level. The target ABI may pass or return some structs by reference
664 independent of this. */
666 default_pass_by_reference (struct type *type)
671 /* Return the default string containing the list of characters
672 delimiting words. This is a reasonable default value that
673 most languages should be able to use. */
676 default_word_break_characters (void)
678 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
681 /* Print the index of array elements using the C99 syntax. */
684 default_print_array_index (struct value *index_value, struct ui_file *stream,
685 const struct value_print_options *options)
687 fprintf_filtered (stream, "[");
688 LA_VALUE_PRINT (index_value, stream, options);
689 fprintf_filtered (stream, "] = ");
693 default_get_string (struct value *value,
694 gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
695 int *length, struct type **char_type, const char **charset)
697 error (_("Getting a string is unsupported in this language."));
700 /* See language.h. */
703 default_symbol_name_matcher (const char *symbol_search_name,
704 const lookup_name_info &lookup_name,
705 completion_match_result *comp_match_res)
707 const std::string &name = lookup_name.name ();
708 completion_match_for_lcd *match_for_lcd
709 = (comp_match_res != NULL ? &comp_match_res->match_for_lcd : NULL);
710 strncmp_iw_mode mode = (lookup_name.completion_mode ()
711 ? strncmp_iw_mode::NORMAL
712 : strncmp_iw_mode::MATCH_PARAMS);
714 if (strncmp_iw_with_mode (symbol_search_name, name.c_str (), name.size (),
715 mode, language_minimal, match_for_lcd) == 0)
717 if (comp_match_res != NULL)
718 comp_match_res->set_match (symbol_search_name);
725 /* See language.h. */
727 symbol_name_matcher_ftype *
728 get_symbol_name_matcher (const language_defn *lang,
729 const lookup_name_info &lookup_name)
731 /* If currently in Ada mode, and the lookup name is wrapped in
732 '<...>', hijack all symbol name comparisons using the Ada
733 matcher, which handles the verbatim matching. */
734 if (current_language->la_language == language_ada
735 && lookup_name.ada ().verbatim_p ())
736 return current_language->la_get_symbol_name_matcher (lookup_name);
738 if (lang->la_get_symbol_name_matcher != nullptr)
739 return lang->la_get_symbol_name_matcher (lookup_name);
740 return default_symbol_name_matcher;
743 /* Define the language that is no language. */
746 unk_lang_parser (struct parser_state *ps)
752 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
755 error (_("internal error - unimplemented "
756 "function unk_lang_emit_char called."));
760 unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
762 error (_("internal error - unimplemented "
763 "function unk_lang_printchar called."));
767 unk_lang_printstr (struct ui_file *stream, struct type *type,
768 const gdb_byte *string, unsigned int length,
769 const char *encoding, int force_ellipses,
770 const struct value_print_options *options)
772 error (_("internal error - unimplemented "
773 "function unk_lang_printstr called."));
777 unk_lang_print_type (struct type *type, const char *varstring,
778 struct ui_file *stream, int show, int level,
779 const struct type_print_options *flags)
781 error (_("internal error - unimplemented "
782 "function unk_lang_print_type called."));
786 unk_lang_val_print (struct type *type,
787 int embedded_offset, CORE_ADDR address,
788 struct ui_file *stream, int recurse,
790 const struct value_print_options *options)
792 error (_("internal error - unimplemented "
793 "function unk_lang_val_print called."));
797 unk_lang_value_print (struct value *val, struct ui_file *stream,
798 const struct value_print_options *options)
800 error (_("internal error - unimplemented "
801 "function unk_lang_value_print called."));
804 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
809 /* Unknown languages just use the cplus demangler. */
810 static char *unk_lang_demangle (const char *mangled, int options)
812 return gdb_demangle (mangled, options);
815 static char *unk_lang_class_name (const char *mangled)
820 static const struct op_print unk_op_print_tab[] =
822 {NULL, OP_NULL, PREC_NULL, 0}
826 unknown_language_arch_info (struct gdbarch *gdbarch,
827 struct language_arch_info *lai)
829 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
830 lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
831 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
835 const struct language_defn unknown_language_defn =
845 &exp_descriptor_standard,
848 unk_lang_printchar, /* Print character constant */
851 unk_lang_print_type, /* Print a type using appropriate syntax */
852 default_print_typedef, /* Print a typedef using appropriate syntax */
853 unk_lang_val_print, /* Print a value using appropriate syntax */
854 unk_lang_value_print, /* Print a top-level value */
855 default_read_var_value, /* la_read_var_value */
856 unk_lang_trampoline, /* Language specific skip_trampoline */
857 "this", /* name_of_this */
858 true, /* store_sym_names_in_linkage_form_p */
859 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
860 basic_lookup_transparent_type,/* lookup_transparent_type */
861 unk_lang_demangle, /* Language specific symbol demangler */
863 unk_lang_class_name, /* Language specific
864 class_name_from_physname */
865 unk_op_print_tab, /* expression operators for printing */
866 1, /* c-style arrays */
867 0, /* String lower bound */
868 default_word_break_characters,
869 default_collect_symbol_completion_matches,
870 unknown_language_arch_info, /* la_language_arch_info. */
871 default_print_array_index,
872 default_pass_by_reference,
874 c_watch_location_expression,
875 NULL, /* la_get_symbol_name_matcher */
876 iterate_over_symbols,
877 default_search_name_hash,
884 /* These two structs define fake entries for the "local" and "auto"
886 const struct language_defn auto_language_defn =
896 &exp_descriptor_standard,
899 unk_lang_printchar, /* Print character constant */
902 unk_lang_print_type, /* Print a type using appropriate syntax */
903 default_print_typedef, /* Print a typedef using appropriate syntax */
904 unk_lang_val_print, /* Print a value using appropriate syntax */
905 unk_lang_value_print, /* Print a top-level value */
906 default_read_var_value, /* la_read_var_value */
907 unk_lang_trampoline, /* Language specific skip_trampoline */
908 "this", /* name_of_this */
909 false, /* store_sym_names_in_linkage_form_p */
910 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
911 basic_lookup_transparent_type,/* lookup_transparent_type */
912 unk_lang_demangle, /* Language specific symbol demangler */
914 unk_lang_class_name, /* Language specific
915 class_name_from_physname */
916 unk_op_print_tab, /* expression operators for printing */
917 1, /* c-style arrays */
918 0, /* String lower bound */
919 default_word_break_characters,
920 default_collect_symbol_completion_matches,
921 unknown_language_arch_info, /* la_language_arch_info. */
922 default_print_array_index,
923 default_pass_by_reference,
925 c_watch_location_expression,
926 NULL, /* la_get_symbol_name_matcher */
927 iterate_over_symbols,
928 default_search_name_hash,
936 /* Per-architecture language information. */
938 static struct gdbarch_data *language_gdbarch_data;
940 struct language_gdbarch
942 /* A vector of per-language per-architecture info. Indexed by "enum
944 struct language_arch_info arch_info[nr_languages];
948 language_gdbarch_post_init (struct gdbarch *gdbarch)
950 struct language_gdbarch *l;
952 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
953 for (const auto &lang : languages)
954 if (lang != NULL && lang->la_language_arch_info != NULL)
956 lang->la_language_arch_info (gdbarch,
957 l->arch_info + lang->la_language);
964 language_string_char_type (const struct language_defn *la,
965 struct gdbarch *gdbarch)
967 struct language_gdbarch *ld
968 = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
970 return ld->arch_info[la->la_language].string_char_type;
974 language_bool_type (const struct language_defn *la,
975 struct gdbarch *gdbarch)
977 struct language_gdbarch *ld
978 = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
980 if (ld->arch_info[la->la_language].bool_type_symbol)
984 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
985 NULL, VAR_DOMAIN, NULL).symbol;
988 struct type *type = SYMBOL_TYPE (sym);
990 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
995 return ld->arch_info[la->la_language].bool_type_default;
998 /* Helper function for primitive type lookup. */
1000 static struct type **
1001 language_lookup_primitive_type_1 (const struct language_arch_info *lai,
1006 for (p = lai->primitive_type_vector; (*p) != NULL; p++)
1008 if (strcmp (TYPE_NAME (*p), name) == 0)
1014 /* See language.h. */
1017 language_lookup_primitive_type (const struct language_defn *la,
1018 struct gdbarch *gdbarch,
1021 struct language_gdbarch *ld =
1022 (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
1023 struct type **typep;
1025 typep = language_lookup_primitive_type_1 (&ld->arch_info[la->la_language],
1032 /* Helper function for type lookup as a symbol.
1033 Create the symbol corresponding to type TYPE in language LANG. */
1035 static struct symbol *
1036 language_alloc_type_symbol (enum language lang, struct type *type)
1038 struct symbol *symbol;
1039 struct gdbarch *gdbarch;
1041 gdb_assert (!TYPE_OBJFILE_OWNED (type));
1043 gdbarch = TYPE_OWNER (type).gdbarch;
1044 symbol = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct symbol);
1046 symbol->ginfo.name = TYPE_NAME (type);
1047 symbol->ginfo.language = lang;
1048 symbol->owner.arch = gdbarch;
1049 SYMBOL_OBJFILE_OWNED (symbol) = 0;
1050 SYMBOL_TYPE (symbol) = type;
1051 SYMBOL_DOMAIN (symbol) = VAR_DOMAIN;
1052 SYMBOL_ACLASS_INDEX (symbol) = LOC_TYPEDEF;
1057 /* Initialize the primitive type symbols of language LD.
1058 The primitive type vector must have already been initialized. */
1061 language_init_primitive_type_symbols (struct language_arch_info *lai,
1062 const struct language_defn *la,
1063 struct gdbarch *gdbarch)
1067 gdb_assert (lai->primitive_type_vector != NULL);
1069 for (n = 0; lai->primitive_type_vector[n] != NULL; ++n)
1072 lai->primitive_type_symbols
1073 = GDBARCH_OBSTACK_CALLOC (gdbarch, n + 1, struct symbol *);
1075 for (n = 0; lai->primitive_type_vector[n] != NULL; ++n)
1077 lai->primitive_type_symbols[n]
1078 = language_alloc_type_symbol (la->la_language,
1079 lai->primitive_type_vector[n]);
1082 /* Note: The result of symbol lookup is normally a symbol *and* the block
1083 it was found in. Builtin types don't live in blocks. We *could* give
1084 them one, but there is no current need so to keep things simple symbol
1085 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1088 /* See language.h. */
1091 language_lookup_primitive_type_as_symbol (const struct language_defn *la,
1092 struct gdbarch *gdbarch,
1095 struct language_gdbarch *ld
1096 = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
1097 struct language_arch_info *lai = &ld->arch_info[la->la_language];
1098 struct type **typep;
1101 if (symbol_lookup_debug)
1103 fprintf_unfiltered (gdb_stdlog,
1104 "language_lookup_primitive_type_as_symbol"
1106 la->la_name, host_address_to_string (gdbarch), name);
1109 typep = language_lookup_primitive_type_1 (lai, name);
1112 if (symbol_lookup_debug)
1113 fprintf_unfiltered (gdb_stdlog, " = NULL\n");
1117 /* The set of symbols is lazily initialized. */
1118 if (lai->primitive_type_symbols == NULL)
1119 language_init_primitive_type_symbols (lai, la, gdbarch);
1121 sym = lai->primitive_type_symbols[typep - lai->primitive_type_vector];
1123 if (symbol_lookup_debug)
1124 fprintf_unfiltered (gdb_stdlog, " = %s\n", host_address_to_string (sym));
1128 /* Initialize the language routines. */
1131 _initialize_language (void)
1133 static const char *const type_or_range_names[]
1134 = { "on", "off", "warn", "auto", NULL };
1136 static const char *const case_sensitive_names[]
1137 = { "on", "off", "auto", NULL };
1139 language_gdbarch_data
1140 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1142 /* GDB commands for language specific stuff. */
1144 add_prefix_cmd ("check", no_class, set_check,
1145 _("Set the status of the type/range checker."),
1146 &setchecklist, "set check ", 0, &setlist);
1147 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1148 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1150 add_prefix_cmd ("check", no_class, show_check,
1151 _("Show the status of the type/range checker."),
1152 &showchecklist, "show check ", 0, &showlist);
1153 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1154 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1156 add_setshow_enum_cmd ("range", class_support, type_or_range_names,
1158 _("Set range checking. (on/warn/off/auto)"),
1159 _("Show range checking. (on/warn/off/auto)"),
1160 NULL, set_range_command,
1162 &setchecklist, &showchecklist);
1164 add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names,
1165 &case_sensitive, _("\
1166 Set case sensitivity in name search. (on/off/auto)"), _("\
1167 Show case sensitivity in name search. (on/off/auto)"), _("\
1168 For Fortran the default is off; for other languages the default is on."),
1171 &setlist, &showlist);
1173 add_set_language_command ();
1175 language = xstrdup ("auto");
1176 range = xstrdup ("auto");
1177 case_sensitive = xstrdup ("auto");
1179 /* Have the above take effect. */
1180 set_language (language_auto);