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 void unk_lang_error (const char *);
51 static int unk_lang_parser (struct parser_state *);
53 static void set_range_case (void);
55 static void unk_lang_emit_char (int c, struct type *type,
56 struct ui_file *stream, int quoter);
58 static void unk_lang_printchar (int c, struct type *type,
59 struct ui_file *stream);
61 static void unk_lang_value_print (struct value *, struct ui_file *,
62 const struct value_print_options *);
64 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
66 /* Forward declaration */
67 extern const struct language_defn unknown_language_defn;
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 enum range_mode range_mode = range_mode_auto;
75 enum range_check range_check = range_check_off;
76 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 const struct language_defn *current_language = &unknown_language_defn;
82 enum language_mode language_mode = language_mode_auto;
84 /* The language that the user expects to be typing in (the language
85 of main(), or the last language we notified them about, or C). */
87 const struct language_defn *expected_language;
89 /* The list of supported languages. Keep this in the same order as
90 the 'enum language' values. */
92 static const struct language_defn *languages[] = {
93 &unknown_language_defn,
103 &pascal_language_defn,
104 &opencl_language_defn,
106 &minimal_language_defn,
110 /* The current values of the "set language/type/range" enum
112 static const char *language;
113 static const char *type;
114 static const char *range;
115 static const char *case_sensitive;
117 /* Warning issued when current_language and the language of the current
118 frame do not match. */
119 char lang_frame_mismatch_warn[] =
120 "Warning: the current language does not match this frame.";
122 /* This page contains the functions corresponding to GDB commands
123 and their helpers. */
125 /* Show command. Display a warning if the language set
126 does not match the frame. */
128 show_language_command (struct ui_file *file, int from_tty,
129 struct cmd_list_element *c, const char *value)
131 enum language flang; /* The language of the frame. */
133 if (language_mode == language_mode_auto)
134 fprintf_filtered (gdb_stdout,
135 _("The current source language is "
136 "\"auto; currently %s\".\n"),
137 current_language->la_name);
139 fprintf_filtered (gdb_stdout,
140 _("The current source language is \"%s\".\n"),
141 current_language->la_name);
143 if (has_stack_frames ())
145 struct frame_info *frame;
147 frame = get_selected_frame (NULL);
148 flang = get_frame_language (frame);
149 if (flang != language_unknown
150 && language_mode == language_mode_manual
151 && current_language->la_language != flang)
152 printf_filtered ("%s\n", lang_frame_mismatch_warn);
156 /* Set command. Change the current working language. */
158 set_language_command (const char *ignore,
159 int from_tty, struct cmd_list_element *c)
161 enum language flang = language_unknown;
163 /* "local" is a synonym of "auto". */
164 if (strcmp (language, "local") == 0)
167 /* Search the list of languages for a match. */
168 for (const auto &lang : languages)
170 if (strcmp (lang->la_name, language) == 0)
172 /* Found it! Go into manual mode, and use this language. */
173 if (lang->la_language == language_auto)
175 /* Enter auto mode. Set to the current frame's language, if
176 known, or fallback to the initial language. */
177 language_mode = language_mode_auto;
180 struct frame_info *frame;
182 frame = get_selected_frame (NULL);
183 flang = get_frame_language (frame);
185 CATCH (ex, RETURN_MASK_ERROR)
187 flang = language_unknown;
191 if (flang != language_unknown)
192 set_language (flang);
194 set_initial_language ();
195 expected_language = current_language;
200 /* Enter manual mode. Set the specified language. */
201 language_mode = language_mode_manual;
202 current_language = lang;
204 expected_language = current_language;
210 internal_error (__FILE__, __LINE__,
211 "Couldn't find language `%s' in known languages list.",
215 /* Show command. Display a warning if the range setting does
216 not match the current language. */
218 show_range_command (struct ui_file *file, int from_tty,
219 struct cmd_list_element *c, const char *value)
221 if (range_mode == range_mode_auto)
230 case range_check_off:
233 case range_check_warn:
237 internal_error (__FILE__, __LINE__,
238 "Unrecognized range check setting.");
241 fprintf_filtered (gdb_stdout,
242 _("Range checking is \"auto; currently %s\".\n"),
246 fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"),
249 if (range_check != current_language->la_range_check)
250 warning (_("the current range check setting "
251 "does not match the language.\n"));
254 /* Set command. Change the setting for range checking. */
256 set_range_command (const char *ignore,
257 int from_tty, struct cmd_list_element *c)
259 if (strcmp (range, "on") == 0)
261 range_check = range_check_on;
262 range_mode = range_mode_manual;
264 else if (strcmp (range, "warn") == 0)
266 range_check = range_check_warn;
267 range_mode = range_mode_manual;
269 else if (strcmp (range, "off") == 0)
271 range_check = range_check_off;
272 range_mode = range_mode_manual;
274 else if (strcmp (range, "auto") == 0)
276 range_mode = range_mode_auto;
282 internal_error (__FILE__, __LINE__,
283 _("Unrecognized range check setting: \"%s\""), range);
285 if (range_check != current_language->la_range_check)
286 warning (_("the current range check setting "
287 "does not match the language.\n"));
290 /* Show command. Display a warning if the case sensitivity setting does
291 not match the current language. */
293 show_case_command (struct ui_file *file, int from_tty,
294 struct cmd_list_element *c, const char *value)
296 if (case_mode == case_mode_auto)
298 const char *tmp = NULL;
300 switch (case_sensitivity)
302 case case_sensitive_on:
305 case case_sensitive_off:
309 internal_error (__FILE__, __LINE__,
310 "Unrecognized case-sensitive setting.");
313 fprintf_filtered (gdb_stdout,
314 _("Case sensitivity in "
315 "name search is \"auto; currently %s\".\n"),
319 fprintf_filtered (gdb_stdout,
320 _("Case sensitivity in name search is \"%s\".\n"),
323 if (case_sensitivity != current_language->la_case_sensitivity)
324 warning (_("the current case sensitivity setting does not match "
328 /* Set command. Change the setting for case sensitivity. */
331 set_case_command (const char *ignore, int from_tty, struct cmd_list_element *c)
333 if (strcmp (case_sensitive, "on") == 0)
335 case_sensitivity = case_sensitive_on;
336 case_mode = case_mode_manual;
338 else if (strcmp (case_sensitive, "off") == 0)
340 case_sensitivity = case_sensitive_off;
341 case_mode = case_mode_manual;
343 else if (strcmp (case_sensitive, "auto") == 0)
345 case_mode = case_mode_auto;
351 internal_error (__FILE__, __LINE__,
352 "Unrecognized case-sensitive setting: \"%s\"",
356 if (case_sensitivity != current_language->la_case_sensitivity)
357 warning (_("the current case sensitivity setting does not match "
361 /* Set the status of range and type checking and case sensitivity based on
362 the current modes and the current language.
363 If SHOW is non-zero, then print out the current language,
364 type and range checking status. */
366 set_range_case (void)
368 if (range_mode == range_mode_auto)
369 range_check = current_language->la_range_check;
371 if (case_mode == case_mode_auto)
372 case_sensitivity = current_language->la_case_sensitivity;
375 /* Set current language to (enum language) LANG. Returns previous
379 set_language (enum language lang)
381 enum language prev_language;
383 prev_language = current_language->la_language;
384 current_language = languages[lang];
386 return prev_language;
390 /* Print out the current language settings: language, range and
391 type checking. If QUIETLY, print only what has changed. */
394 language_info (int quietly)
396 if (quietly && expected_language == current_language)
399 expected_language = current_language;
400 printf_unfiltered (_("Current language: %s\n"), language);
401 show_language_command (NULL, 1, NULL, NULL);
405 printf_unfiltered (_("Range checking: %s\n"), range);
406 show_range_command (NULL, 1, NULL, NULL);
407 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
408 show_case_command (NULL, 1, NULL, NULL);
413 /* Returns non-zero if the value is a pointer type. */
415 pointer_type (struct type *type)
417 return TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type);
421 /* This page contains functions that return info about
422 (struct value) values used in GDB. */
424 /* Returns non-zero if the value VAL represents a true value. */
426 value_true (struct value *val)
428 /* It is possible that we should have some sort of error if a non-boolean
429 value is used in this context. Possibly dependent on some kind of
430 "boolean-checking" option like range checking. But it should probably
431 not depend on the language except insofar as is necessary to identify
432 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
433 should be an error, probably). */
434 return !value_logical_not (val);
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 vfprintf_filtered (gdb_stderr, string, args);
465 fprintf_filtered (gdb_stderr, "\n");
468 internal_error (__FILE__, __LINE__, _("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 : languages)
482 if (strcmp (lang->la_name, str) == 0)
483 return lang->la_language;
485 if (strcmp (str, "local") == 0)
486 return language_auto;
488 return language_unknown;
491 /* Return the language struct for a given language enum. */
493 const struct language_defn *
494 language_def (enum language lang)
496 return languages[lang];
499 /* Return the language as a string. */
502 language_str (enum language lang)
504 return languages[lang]->la_name;
508 set_check (const char *ignore, int from_tty)
511 "\"set check\" must be followed by the name of a check subcommand.\n");
512 help_list (setchecklist, "set check ", all_commands, gdb_stdout);
516 show_check (const char *ignore, int from_tty)
518 cmd_show_list (showchecklist, from_tty, "");
522 /* Build and install the "set language LANG" command. */
525 add_set_language_command ()
527 static const char **language_names;
529 /* Build the language names array, to be used as enumeration in the
530 "set language" enum command. +1 for "local" and +1 for NULL
532 language_names = new const char *[ARRAY_SIZE (languages) + 2];
534 /* Display "auto", "local" and "unknown" first, and then the rest,
536 const char **language_names_p = language_names;
537 *language_names_p++ = auto_language_defn.la_name;
538 *language_names_p++ = "local";
539 *language_names_p++ = unknown_language_defn.la_name;
540 const char **sort_begin = language_names_p;
541 for (const auto &lang : languages)
543 /* Already handled above. */
544 if (lang->la_language == language_auto
545 || lang->la_language == language_unknown)
547 *language_names_p++ = lang->la_name;
549 *language_names_p = NULL;
550 std::sort (sort_begin, language_names_p, compare_cstrings);
552 /* Add the filename extensions. */
553 for (const auto &lang : languages)
554 if (lang->la_filename_extensions != NULL)
556 for (size_t i = 0; lang->la_filename_extensions[i] != NULL; ++i)
557 add_filename_language (lang->la_filename_extensions[i],
561 /* Build the "help set language" docs. */
564 doc.printf (_("Set the current source language.\n"
565 "The currently understood settings are:\n\nlocal or "
566 "auto Automatic setting based on source file\n"));
568 for (const auto &lang : languages)
570 /* Already dealt with these above. */
571 if (lang->la_language == language_unknown
572 || lang->la_language == language_auto)
575 /* FIXME: i18n: for now assume that the human-readable name is
576 just a capitalization of the internal name. */
577 doc.printf ("%-16s Use the %c%s language\n",
579 /* Capitalize first letter of language name. */
580 toupper (lang->la_name[0]),
584 add_setshow_enum_cmd ("language", class_support,
588 _("Show the current source language."),
589 NULL, set_language_command,
590 show_language_command,
591 &setlist, &showlist);
594 /* Iterate through all registered languages looking for and calling
595 any non-NULL struct language_defn.skip_trampoline() functions.
596 Return the result from the first that returns non-zero, or 0 if all
599 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
601 for (const auto &lang : languages)
603 if (lang->skip_trampoline != NULL)
605 CORE_ADDR real_pc = lang->skip_trampoline (frame, pc);
615 /* Return demangled language symbol, or NULL.
616 FIXME: Options are only useful for certain languages and ignored
617 by others, so it would be better to remove them here and have a
618 more flexible demangler for the languages that need it.
619 FIXME: Sometimes the demangler is invoked when we don't know the
620 language, so we can't use this everywhere. */
622 language_demangle (const struct language_defn *current_language,
623 const char *mangled, int options)
625 if (current_language != NULL && current_language->la_demangle)
626 return current_language->la_demangle (mangled, options);
630 /* See langauge.h. */
633 language_sniff_from_mangled_name (const struct language_defn *lang,
634 const char *mangled, char **demangled)
636 gdb_assert (lang != NULL);
638 if (lang->la_sniff_from_mangled_name == NULL)
644 return lang->la_sniff_from_mangled_name (mangled, demangled);
647 /* Return class name from physname or NULL. */
649 language_class_name_from_physname (const struct language_defn *lang,
650 const char *physname)
652 if (lang != NULL && lang->la_class_name_from_physname)
653 return lang->la_class_name_from_physname (physname);
657 /* Return non-zero if TYPE should be passed (and returned) by
658 reference at the language level. */
660 language_pass_by_reference (struct type *type)
662 return current_language->la_pass_by_reference (type);
665 /* Return zero; by default, types are passed by value at the language
666 level. The target ABI may pass or return some structs by reference
667 independent of this. */
669 default_pass_by_reference (struct type *type)
674 /* Return the default string containing the list of characters
675 delimiting words. This is a reasonable default value that
676 most languages should be able to use. */
679 default_word_break_characters (void)
681 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
684 /* Print the index of array elements using the C99 syntax. */
687 default_print_array_index (struct value *index_value, struct ui_file *stream,
688 const struct value_print_options *options)
690 fprintf_filtered (stream, "[");
691 LA_VALUE_PRINT (index_value, stream, options);
692 fprintf_filtered (stream, "] = ");
696 default_get_string (struct value *value, gdb_byte **buffer, int *length,
697 struct type **char_type, const char **charset)
699 error (_("Getting a string is unsupported in this language."));
702 /* See language.h. */
705 default_symbol_name_matcher (const char *symbol_search_name,
706 const lookup_name_info &lookup_name,
707 completion_match_result *comp_match_res)
709 const std::string &name = lookup_name.name ();
710 completion_match_for_lcd *match_for_lcd
711 = (comp_match_res != NULL ? &comp_match_res->match_for_lcd : NULL);
712 strncmp_iw_mode mode = (lookup_name.completion_mode ()
713 ? strncmp_iw_mode::NORMAL
714 : strncmp_iw_mode::MATCH_PARAMS);
716 if (strncmp_iw_with_mode (symbol_search_name, name.c_str (), name.size (),
717 mode, language_minimal, match_for_lcd) == 0)
719 if (comp_match_res != NULL)
720 comp_match_res->set_match (symbol_search_name);
727 /* See language.h. */
729 symbol_name_matcher_ftype *
730 get_symbol_name_matcher (const language_defn *lang,
731 const lookup_name_info &lookup_name)
733 /* If currently in Ada mode, and the lookup name is wrapped in
734 '<...>', hijack all symbol name comparisons using the Ada
735 matcher, which handles the verbatim matching. */
736 if (current_language->la_language == language_ada
737 && lookup_name.ada ().verbatim_p ())
738 return current_language->la_get_symbol_name_matcher (lookup_name);
740 if (lang->la_get_symbol_name_matcher != nullptr)
741 return lang->la_get_symbol_name_matcher (lookup_name);
742 return default_symbol_name_matcher;
745 /* Define the language that is no language. */
748 unk_lang_parser (struct parser_state *ps)
754 unk_lang_error (const char *msg)
756 error (_("Attempted to parse an expression with unknown language"));
760 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
763 error (_("internal error - unimplemented "
764 "function unk_lang_emit_char called."));
768 unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
770 error (_("internal error - unimplemented "
771 "function unk_lang_printchar called."));
775 unk_lang_printstr (struct ui_file *stream, struct type *type,
776 const gdb_byte *string, unsigned int length,
777 const char *encoding, int force_ellipses,
778 const struct value_print_options *options)
780 error (_("internal error - unimplemented "
781 "function unk_lang_printstr called."));
785 unk_lang_print_type (struct type *type, const char *varstring,
786 struct ui_file *stream, int show, int level,
787 const struct type_print_options *flags)
789 error (_("internal error - unimplemented "
790 "function unk_lang_print_type called."));
794 unk_lang_val_print (struct type *type,
795 int embedded_offset, CORE_ADDR address,
796 struct ui_file *stream, int recurse,
798 const struct value_print_options *options)
800 error (_("internal error - unimplemented "
801 "function unk_lang_val_print called."));
805 unk_lang_value_print (struct value *val, struct ui_file *stream,
806 const struct value_print_options *options)
808 error (_("internal error - unimplemented "
809 "function unk_lang_value_print called."));
812 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
817 /* Unknown languages just use the cplus demangler. */
818 static char *unk_lang_demangle (const char *mangled, int options)
820 return gdb_demangle (mangled, options);
823 static char *unk_lang_class_name (const char *mangled)
828 static const struct op_print unk_op_print_tab[] =
830 {NULL, OP_NULL, PREC_NULL, 0}
834 unknown_language_arch_info (struct gdbarch *gdbarch,
835 struct language_arch_info *lai)
837 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
838 lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
839 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
843 const struct language_defn unknown_language_defn =
853 &exp_descriptor_standard,
857 unk_lang_printchar, /* Print character constant */
860 unk_lang_print_type, /* Print a type using appropriate syntax */
861 default_print_typedef, /* Print a typedef using appropriate syntax */
862 unk_lang_val_print, /* Print a value using appropriate syntax */
863 unk_lang_value_print, /* Print a top-level value */
864 default_read_var_value, /* la_read_var_value */
865 unk_lang_trampoline, /* Language specific skip_trampoline */
866 "this", /* name_of_this */
867 true, /* store_sym_names_in_linkage_form_p */
868 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
869 basic_lookup_transparent_type,/* lookup_transparent_type */
870 unk_lang_demangle, /* Language specific symbol demangler */
872 unk_lang_class_name, /* Language specific
873 class_name_from_physname */
874 unk_op_print_tab, /* expression operators for printing */
875 1, /* c-style arrays */
876 0, /* String lower bound */
877 default_word_break_characters,
878 default_collect_symbol_completion_matches,
879 unknown_language_arch_info, /* la_language_arch_info. */
880 default_print_array_index,
881 default_pass_by_reference,
883 c_watch_location_expression,
884 NULL, /* la_get_symbol_name_matcher */
885 iterate_over_symbols,
886 default_search_name_hash,
893 /* These two structs define fake entries for the "local" and "auto"
895 const struct language_defn auto_language_defn =
905 &exp_descriptor_standard,
909 unk_lang_printchar, /* Print character constant */
912 unk_lang_print_type, /* Print a type using appropriate syntax */
913 default_print_typedef, /* Print a typedef using appropriate syntax */
914 unk_lang_val_print, /* Print a value using appropriate syntax */
915 unk_lang_value_print, /* Print a top-level value */
916 default_read_var_value, /* la_read_var_value */
917 unk_lang_trampoline, /* Language specific skip_trampoline */
918 "this", /* name_of_this */
919 false, /* store_sym_names_in_linkage_form_p */
920 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
921 basic_lookup_transparent_type,/* lookup_transparent_type */
922 unk_lang_demangle, /* Language specific symbol demangler */
924 unk_lang_class_name, /* Language specific
925 class_name_from_physname */
926 unk_op_print_tab, /* expression operators for printing */
927 1, /* c-style arrays */
928 0, /* String lower bound */
929 default_word_break_characters,
930 default_collect_symbol_completion_matches,
931 unknown_language_arch_info, /* la_language_arch_info. */
932 default_print_array_index,
933 default_pass_by_reference,
935 c_watch_location_expression,
936 NULL, /* la_get_symbol_name_matcher */
937 iterate_over_symbols,
938 default_search_name_hash,
946 /* Per-architecture language information. */
948 static struct gdbarch_data *language_gdbarch_data;
950 struct language_gdbarch
952 /* A vector of per-language per-architecture info. Indexed by "enum
954 struct language_arch_info arch_info[nr_languages];
958 language_gdbarch_post_init (struct gdbarch *gdbarch)
960 struct language_gdbarch *l;
962 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
963 for (const auto &lang : languages)
964 if (lang != NULL && lang->la_language_arch_info != NULL)
966 lang->la_language_arch_info (gdbarch,
967 l->arch_info + lang->la_language);
974 language_string_char_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 return ld->arch_info[la->la_language].string_char_type;
984 language_bool_type (const struct language_defn *la,
985 struct gdbarch *gdbarch)
987 struct language_gdbarch *ld
988 = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
990 if (ld->arch_info[la->la_language].bool_type_symbol)
994 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
995 NULL, VAR_DOMAIN, NULL).symbol;
998 struct type *type = SYMBOL_TYPE (sym);
1000 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
1005 return ld->arch_info[la->la_language].bool_type_default;
1008 /* Helper function for primitive type lookup. */
1010 static struct type **
1011 language_lookup_primitive_type_1 (const struct language_arch_info *lai,
1016 for (p = lai->primitive_type_vector; (*p) != NULL; p++)
1018 if (strcmp (TYPE_NAME (*p), name) == 0)
1024 /* See language.h. */
1027 language_lookup_primitive_type (const struct language_defn *la,
1028 struct gdbarch *gdbarch,
1031 struct language_gdbarch *ld =
1032 (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
1033 struct type **typep;
1035 typep = language_lookup_primitive_type_1 (&ld->arch_info[la->la_language],
1042 /* Helper function for type lookup as a symbol.
1043 Create the symbol corresponding to type TYPE in language LANG. */
1045 static struct symbol *
1046 language_alloc_type_symbol (enum language lang, struct type *type)
1048 struct symbol *symbol;
1049 struct gdbarch *gdbarch;
1051 gdb_assert (!TYPE_OBJFILE_OWNED (type));
1053 gdbarch = TYPE_OWNER (type).gdbarch;
1054 symbol = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct symbol);
1056 symbol->ginfo.name = TYPE_NAME (type);
1057 symbol->ginfo.language = lang;
1058 symbol->owner.arch = gdbarch;
1059 SYMBOL_OBJFILE_OWNED (symbol) = 0;
1060 SYMBOL_TYPE (symbol) = type;
1061 SYMBOL_DOMAIN (symbol) = VAR_DOMAIN;
1062 SYMBOL_ACLASS_INDEX (symbol) = LOC_TYPEDEF;
1067 /* Initialize the primitive type symbols of language LD.
1068 The primitive type vector must have already been initialized. */
1071 language_init_primitive_type_symbols (struct language_arch_info *lai,
1072 const struct language_defn *la,
1073 struct gdbarch *gdbarch)
1077 gdb_assert (lai->primitive_type_vector != NULL);
1079 for (n = 0; lai->primitive_type_vector[n] != NULL; ++n)
1082 lai->primitive_type_symbols
1083 = GDBARCH_OBSTACK_CALLOC (gdbarch, n + 1, struct symbol *);
1085 for (n = 0; lai->primitive_type_vector[n] != NULL; ++n)
1087 lai->primitive_type_symbols[n]
1088 = language_alloc_type_symbol (la->la_language,
1089 lai->primitive_type_vector[n]);
1092 /* Note: The result of symbol lookup is normally a symbol *and* the block
1093 it was found in. Builtin types don't live in blocks. We *could* give
1094 them one, but there is no current need so to keep things simple symbol
1095 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1098 /* See language.h. */
1101 language_lookup_primitive_type_as_symbol (const struct language_defn *la,
1102 struct gdbarch *gdbarch,
1105 struct language_gdbarch *ld
1106 = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
1107 struct language_arch_info *lai = &ld->arch_info[la->la_language];
1108 struct type **typep;
1111 if (symbol_lookup_debug)
1113 fprintf_unfiltered (gdb_stdlog,
1114 "language_lookup_primitive_type_as_symbol"
1116 la->la_name, host_address_to_string (gdbarch), name);
1119 typep = language_lookup_primitive_type_1 (lai, name);
1122 if (symbol_lookup_debug)
1123 fprintf_unfiltered (gdb_stdlog, " = NULL\n");
1127 /* The set of symbols is lazily initialized. */
1128 if (lai->primitive_type_symbols == NULL)
1129 language_init_primitive_type_symbols (lai, la, gdbarch);
1131 sym = lai->primitive_type_symbols[typep - lai->primitive_type_vector];
1133 if (symbol_lookup_debug)
1134 fprintf_unfiltered (gdb_stdlog, " = %s\n", host_address_to_string (sym));
1138 /* Initialize the language routines. */
1141 _initialize_language (void)
1143 static const char *const type_or_range_names[]
1144 = { "on", "off", "warn", "auto", NULL };
1146 static const char *const case_sensitive_names[]
1147 = { "on", "off", "auto", NULL };
1149 language_gdbarch_data
1150 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1152 /* GDB commands for language specific stuff. */
1154 add_prefix_cmd ("check", no_class, set_check,
1155 _("Set the status of the type/range checker."),
1156 &setchecklist, "set check ", 0, &setlist);
1157 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1158 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1160 add_prefix_cmd ("check", no_class, show_check,
1161 _("Show the status of the type/range checker."),
1162 &showchecklist, "show check ", 0, &showlist);
1163 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1164 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1166 add_setshow_enum_cmd ("range", class_support, type_or_range_names,
1168 _("Set range checking. (on/warn/off/auto)"),
1169 _("Show range checking. (on/warn/off/auto)"),
1170 NULL, set_range_command,
1172 &setchecklist, &showchecklist);
1174 add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names,
1175 &case_sensitive, _("\
1176 Set case sensitivity in name search. (on/off/auto)"), _("\
1177 Show case sensitivity in name search. (on/off/auto)"), _("\
1178 For Fortran the default is off; for other languages the default is on."),
1181 &setlist, &showlist);
1183 add_set_language_command ();
1185 language = xstrdup ("auto");
1186 type = xstrdup ("auto");
1187 range = xstrdup ("auto");
1188 case_sensitive = xstrdup ("auto");
1190 /* Have the above take effect. */
1191 set_language (language_auto);