1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-1996, 1998-2005, 2007-2012 Free Software
6 Contributed by the Department of Computer Science at the State University
7 of New York at Buffalo.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 /* This file contains functions that return things that are specific
25 to languages. Each function should examine current_language if necessary,
26 and return the appropriate result. */
28 /* FIXME: Most of these would be better organized as macros which
29 return data out of a "language-specific" struct pointer that is set
30 whenever the working language changes. That would be a lot faster. */
34 #include "gdb_string.h"
40 #include "expression.h"
43 #include "parser-defs.h"
48 extern void _initialize_language (void);
50 static void unk_lang_error (char *);
52 static int unk_lang_parser (void);
54 static void show_check (char *, int);
56 static void set_check (char *, int);
58 static void set_type_range_case (void);
60 static void unk_lang_emit_char (int c, struct type *type,
61 struct ui_file *stream, int quoter);
63 static void unk_lang_printchar (int c, struct type *type,
64 struct ui_file *stream);
66 static void unk_lang_print_type (struct type *, const char *, struct ui_file *,
69 static void unk_lang_value_print (struct value *, struct ui_file *,
70 const struct value_print_options *);
72 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
74 /* Forward declaration */
75 extern const struct language_defn unknown_language_defn;
77 /* The current (default at startup) state of type and range checking.
78 (If the modes are set to "auto", though, these are changed based
79 on the default language at startup, and then again based on the
80 language of the first source file. */
82 enum range_mode range_mode = range_mode_auto;
83 enum range_check range_check = range_check_off;
84 enum type_mode type_mode = type_mode_auto;
85 enum type_check type_check = type_check_off;
86 enum case_mode case_mode = case_mode_auto;
87 enum case_sensitivity case_sensitivity = case_sensitive_on;
89 /* The current language and language_mode (see language.h). */
91 const struct language_defn *current_language = &unknown_language_defn;
92 enum language_mode language_mode = language_mode_auto;
94 /* The language that the user expects to be typing in (the language
95 of main(), or the last language we notified them about, or C). */
97 const struct language_defn *expected_language;
99 /* The list of supported languages. The list itself is malloc'd. */
101 static const struct language_defn **languages;
102 static unsigned languages_size;
103 static unsigned languages_allocsize;
104 #define DEFAULT_ALLOCSIZE 4
106 /* The current values of the "set language/type/range" enum
108 static const char *language;
109 static const char *type;
110 static const char *range;
111 static const char *case_sensitive;
113 /* Warning issued when current_language and the language of the current
114 frame do not match. */
115 char lang_frame_mismatch_warn[] =
116 "Warning: the current language does not match this frame.";
118 /* This page contains the functions corresponding to GDB commands
119 and their helpers. */
121 /* Show command. Display a warning if the language set
122 does not match the frame. */
124 show_language_command (struct ui_file *file, int from_tty,
125 struct cmd_list_element *c, const char *value)
127 enum language flang; /* The language of the current frame. */
129 if (language_mode == language_mode_auto)
130 fprintf_filtered (gdb_stdout,
131 _("The current source language is "
132 "\"auto; currently %s\".\n"),
133 current_language->la_name);
135 fprintf_filtered (gdb_stdout,
136 _("The current source language is \"%s\".\n"),
137 current_language->la_name);
139 flang = get_frame_language ();
140 if (flang != language_unknown &&
141 language_mode == language_mode_manual &&
142 current_language->la_language != flang)
143 printf_filtered ("%s\n", lang_frame_mismatch_warn);
146 /* Set command. Change the current working language. */
148 set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
153 /* Search the list of languages for a match. */
154 for (i = 0; i < languages_size; i++)
156 if (strcmp (languages[i]->la_name, language) == 0)
158 /* Found it! Go into manual mode, and use this language. */
159 if (languages[i]->la_language == language_auto)
161 /* Enter auto mode. Set to the current frame's language, if
162 known, or fallback to the initial language. */
163 language_mode = language_mode_auto;
164 flang = get_frame_language ();
165 if (flang != language_unknown)
166 set_language (flang);
168 set_initial_language ();
169 expected_language = current_language;
174 /* Enter manual mode. Set the specified language. */
175 language_mode = language_mode_manual;
176 current_language = languages[i];
177 set_type_range_case ();
178 expected_language = current_language;
184 internal_error (__FILE__, __LINE__,
185 "Couldn't find language `%s' in known languages list.",
189 /* Show command. Display a warning if the type setting does
190 not match the current language. */
192 show_type_command (struct ui_file *file, int from_tty,
193 struct cmd_list_element *c, const char *value)
195 if (type_mode == type_mode_auto)
207 case type_check_warn:
211 internal_error (__FILE__, __LINE__,
212 "Unrecognized type check setting.");
215 fprintf_filtered (gdb_stdout,
216 _("Type checking is \"auto; currently %s\".\n"),
220 fprintf_filtered (gdb_stdout, _("Type checking is \"%s\".\n"),
223 if (type_check != current_language->la_type_check)
224 warning (_("the current type check setting"
225 " does not match the language.\n"));
228 /* Set command. Change the setting for type checking. */
230 set_type_command (char *ignore, int from_tty, struct cmd_list_element *c)
232 if (strcmp (type, "on") == 0)
234 type_check = type_check_on;
235 type_mode = type_mode_manual;
237 else if (strcmp (type, "warn") == 0)
239 type_check = type_check_warn;
240 type_mode = type_mode_manual;
242 else if (strcmp (type, "off") == 0)
244 type_check = type_check_off;
245 type_mode = type_mode_manual;
247 else if (strcmp (type, "auto") == 0)
249 type_mode = type_mode_auto;
250 set_type_range_case ();
254 internal_error (__FILE__, __LINE__,
255 _("Unrecognized type check setting: \"%s\""), type);
257 if (type_check != current_language->la_type_check)
258 warning (_("the current type check setting"
259 " does not match the language.\n"));
262 /* Show command. Display a warning if the range setting does
263 not match the current language. */
265 show_range_command (struct ui_file *file, int from_tty,
266 struct cmd_list_element *c, const char *value)
268 if (range_mode == range_mode_auto)
277 case range_check_off:
280 case range_check_warn:
284 internal_error (__FILE__, __LINE__,
285 "Unrecognized range check setting.");
288 fprintf_filtered (gdb_stdout,
289 _("Range checking is \"auto; currently %s\".\n"),
293 fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"),
296 if (range_check != current_language->la_range_check)
297 warning (_("the current range check setting "
298 "does not match the language.\n"));
301 /* Set command. Change the setting for range checking. */
303 set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
305 if (strcmp (range, "on") == 0)
307 range_check = range_check_on;
308 range_mode = range_mode_manual;
310 else if (strcmp (range, "warn") == 0)
312 range_check = range_check_warn;
313 range_mode = range_mode_manual;
315 else if (strcmp (range, "off") == 0)
317 range_check = range_check_off;
318 range_mode = range_mode_manual;
320 else if (strcmp (range, "auto") == 0)
322 range_mode = range_mode_auto;
323 set_type_range_case ();
328 internal_error (__FILE__, __LINE__,
329 _("Unrecognized range check setting: \"%s\""), range);
331 if (range_check != current_language->la_range_check)
332 warning (_("the current range check setting "
333 "does not match the language.\n"));
336 /* Show command. Display a warning if the case sensitivity setting does
337 not match the current language. */
339 show_case_command (struct ui_file *file, int from_tty,
340 struct cmd_list_element *c, const char *value)
342 if (case_mode == case_mode_auto)
346 switch (case_sensitivity)
348 case case_sensitive_on:
351 case case_sensitive_off:
355 internal_error (__FILE__, __LINE__,
356 "Unrecognized case-sensitive setting.");
359 fprintf_filtered (gdb_stdout,
360 _("Case sensitivity in "
361 "name search is \"auto; currently %s\".\n"),
365 fprintf_filtered (gdb_stdout,
366 _("Case sensitivity in name search is \"%s\".\n"),
369 if (case_sensitivity != current_language->la_case_sensitivity)
370 warning (_("the current case sensitivity setting does not match "
374 /* Set command. Change the setting for case sensitivity. */
377 set_case_command (char *ignore, int from_tty, struct cmd_list_element *c)
379 if (strcmp (case_sensitive, "on") == 0)
381 case_sensitivity = case_sensitive_on;
382 case_mode = case_mode_manual;
384 else if (strcmp (case_sensitive, "off") == 0)
386 case_sensitivity = case_sensitive_off;
387 case_mode = case_mode_manual;
389 else if (strcmp (case_sensitive, "auto") == 0)
391 case_mode = case_mode_auto;
392 set_type_range_case ();
397 internal_error (__FILE__, __LINE__,
398 "Unrecognized case-sensitive setting: \"%s\"",
402 if (case_sensitivity != current_language->la_case_sensitivity)
403 warning (_("the current case sensitivity setting does not match "
407 /* Set the status of range and type checking and case sensitivity based on
408 the current modes and the current language.
409 If SHOW is non-zero, then print out the current language,
410 type and range checking status. */
412 set_type_range_case (void)
414 if (range_mode == range_mode_auto)
415 range_check = current_language->la_range_check;
417 if (type_mode == type_mode_auto)
418 type_check = current_language->la_type_check;
420 if (case_mode == case_mode_auto)
421 case_sensitivity = current_language->la_case_sensitivity;
424 /* Set current language to (enum language) LANG. Returns previous
428 set_language (enum language lang)
431 enum language prev_language;
433 prev_language = current_language->la_language;
435 for (i = 0; i < languages_size; i++)
437 if (languages[i]->la_language == lang)
439 current_language = languages[i];
440 set_type_range_case ();
445 return prev_language;
449 /* Print out the current language settings: language, range and
450 type checking. If QUIETLY, print only what has changed. */
453 language_info (int quietly)
455 if (quietly && expected_language == current_language)
458 expected_language = current_language;
459 printf_unfiltered (_("Current language: %s\n"), language);
460 show_language_command (NULL, 1, NULL, NULL);
464 printf_unfiltered (_("Type checking: %s\n"), type);
465 show_type_command (NULL, 1, NULL, NULL);
466 printf_unfiltered (_("Range checking: %s\n"), range);
467 show_range_command (NULL, 1, NULL, NULL);
468 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
469 show_case_command (NULL, 1, NULL, NULL);
474 /* Returns non-zero if the value is a pointer type. */
476 pointer_type (struct type *type)
478 return TYPE_CODE (type) == TYPE_CODE_PTR ||
479 TYPE_CODE (type) == TYPE_CODE_REF;
483 /* This page contains functions that return info about
484 (struct value) values used in GDB. */
486 /* Returns non-zero if the value VAL represents a true value. */
488 value_true (struct value *val)
490 /* It is possible that we should have some sort of error if a non-boolean
491 value is used in this context. Possibly dependent on some kind of
492 "boolean-checking" option like range checking. But it should probably
493 not depend on the language except insofar as is necessary to identify
494 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
495 should be an error, probably). */
496 return !value_logical_not (val);
499 /* This page contains functions for the printing out of
500 error messages that occur during type- and range-
503 /* These are called when a language fails a type- or range-check. The
504 first argument should be a printf()-style format string, and the
505 rest of the arguments should be its arguments. If
506 [type|range]_check is [type|range]_check_on, an error is printed;
507 if [type|range]_check_warn, a warning; otherwise just the
511 type_error (const char *string,...)
515 va_start (args, string);
518 case type_check_warn:
519 vwarning (string, args);
522 verror (string, args);
525 /* FIXME: cagney/2002-01-30: Should this function print anything
526 when type error is off? */
527 vfprintf_filtered (gdb_stderr, string, args);
528 fprintf_filtered (gdb_stderr, "\n");
531 internal_error (__FILE__, __LINE__, _("bad switch"));
537 range_error (const char *string,...)
541 va_start (args, string);
544 case range_check_warn:
545 vwarning (string, args);
548 verror (string, args);
550 case range_check_off:
551 /* FIXME: cagney/2002-01-30: Should this function print anything
552 when range error is off? */
553 vfprintf_filtered (gdb_stderr, string, args);
554 fprintf_filtered (gdb_stderr, "\n");
557 internal_error (__FILE__, __LINE__, _("bad switch"));
563 /* This page contains miscellaneous functions. */
565 /* Return the language enum for a given language string. */
568 language_enum (char *str)
572 for (i = 0; i < languages_size; i++)
573 if (strcmp (languages[i]->la_name, str) == 0)
574 return languages[i]->la_language;
576 return language_unknown;
579 /* Return the language struct for a given language enum. */
581 const struct language_defn *
582 language_def (enum language lang)
586 for (i = 0; i < languages_size; i++)
588 if (languages[i]->la_language == lang)
596 /* Return the language as a string. */
598 language_str (enum language lang)
602 for (i = 0; i < languages_size; i++)
604 if (languages[i]->la_language == lang)
606 return languages[i]->la_name;
613 set_check (char *ignore, int from_tty)
616 "\"set check\" must be followed by the name of a check subcommand.\n");
617 help_list (setchecklist, "set check ", -1, gdb_stdout);
621 show_check (char *ignore, int from_tty)
623 cmd_show_list (showchecklist, from_tty, "");
626 /* Add a language to the set of known languages. */
629 add_language (const struct language_defn *lang)
631 /* For the "set language" command. */
632 static char **language_names = NULL;
633 /* For the "help set language" command. */
634 char *language_set_doc = NULL;
637 struct ui_file *tmp_stream;
639 if (lang->la_magic != LANG_MAGIC)
641 fprintf_unfiltered (gdb_stderr,
642 "Magic number of %s language struct wrong\n",
644 internal_error (__FILE__, __LINE__,
645 _("failed internal consistency check"));
650 languages_allocsize = DEFAULT_ALLOCSIZE;
651 languages = (const struct language_defn **) xmalloc
652 (languages_allocsize * sizeof (*languages));
654 if (languages_size >= languages_allocsize)
656 languages_allocsize *= 2;
657 languages = (const struct language_defn **) xrealloc ((char *) languages,
658 languages_allocsize * sizeof (*languages));
660 languages[languages_size++] = lang;
662 /* Build the language names array, to be used as enumeration in the
663 set language" enum command. */
664 language_names = xrealloc (language_names,
665 (languages_size + 1) * sizeof (const char *));
666 for (i = 0; i < languages_size; ++i)
667 language_names[i] = languages[i]->la_name;
668 language_names[i] = NULL;
670 /* Build the "help set language" docs. */
671 tmp_stream = mem_fileopen ();
673 fprintf_unfiltered (tmp_stream,
674 _("Set the current source language.\n"
675 "The currently understood settings are:\n\nlocal or "
676 "auto Automatic setting based on source file\n"));
678 for (i = 0; i < languages_size; ++i)
680 /* Already dealt with these above. */
681 if (languages[i]->la_language == language_unknown
682 || languages[i]->la_language == language_auto)
685 /* FIXME: i18n: for now assume that the human-readable name
686 is just a capitalization of the internal name. */
687 fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n",
688 languages[i]->la_name,
689 /* Capitalize first letter of language
691 toupper (languages[i]->la_name[0]),
692 languages[i]->la_name + 1);
695 language_set_doc = ui_file_xstrdup (tmp_stream, NULL);
696 ui_file_delete (tmp_stream);
698 add_setshow_enum_cmd ("language", class_support,
699 (const char **) language_names,
702 _("Show the current source language."),
703 NULL, set_language_command,
704 show_language_command,
705 &setlist, &showlist);
707 xfree (language_set_doc);
710 /* Iterate through all registered languages looking for and calling
711 any non-NULL struct language_defn.skip_trampoline() functions.
712 Return the result from the first that returns non-zero, or 0 if all
715 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
719 for (i = 0; i < languages_size; i++)
721 if (languages[i]->skip_trampoline)
723 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc);
733 /* Return demangled language symbol, or NULL.
734 FIXME: Options are only useful for certain languages and ignored
735 by others, so it would be better to remove them here and have a
736 more flexible demangler for the languages that need it.
737 FIXME: Sometimes the demangler is invoked when we don't know the
738 language, so we can't use this everywhere. */
740 language_demangle (const struct language_defn *current_language,
741 const char *mangled, int options)
743 if (current_language != NULL && current_language->la_demangle)
744 return current_language->la_demangle (mangled, options);
748 /* Return class name from physname or NULL. */
750 language_class_name_from_physname (const struct language_defn *lang,
751 const char *physname)
753 if (lang != NULL && lang->la_class_name_from_physname)
754 return lang->la_class_name_from_physname (physname);
758 /* Return non-zero if TYPE should be passed (and returned) by
759 reference at the language level. */
761 language_pass_by_reference (struct type *type)
763 return current_language->la_pass_by_reference (type);
766 /* Return zero; by default, types are passed by value at the language
767 level. The target ABI may pass or return some structs by reference
768 independent of this. */
770 default_pass_by_reference (struct type *type)
775 /* Return the default string containing the list of characters
776 delimiting words. This is a reasonable default value that
777 most languages should be able to use. */
780 default_word_break_characters (void)
782 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
785 /* Print the index of array elements using the C99 syntax. */
788 default_print_array_index (struct value *index_value, struct ui_file *stream,
789 const struct value_print_options *options)
791 fprintf_filtered (stream, "[");
792 LA_VALUE_PRINT (index_value, stream, options);
793 fprintf_filtered (stream, "] = ");
797 default_get_string (struct value *value, gdb_byte **buffer, int *length,
798 struct type **char_type, const char **charset)
800 error (_("Getting a string is unsupported in this language."));
803 /* Define the language that is no language. */
806 unk_lang_parser (void)
812 unk_lang_error (char *msg)
814 error (_("Attempted to parse an expression with unknown language"));
818 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
821 error (_("internal error - unimplemented "
822 "function unk_lang_emit_char called."));
826 unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
828 error (_("internal error - unimplemented "
829 "function unk_lang_printchar called."));
833 unk_lang_printstr (struct ui_file *stream, struct type *type,
834 const gdb_byte *string, unsigned int length,
835 const char *encoding, int force_ellipses,
836 const struct value_print_options *options)
838 error (_("internal error - unimplemented "
839 "function unk_lang_printstr called."));
843 unk_lang_print_type (struct type *type, const char *varstring,
844 struct ui_file *stream, int show, int level)
846 error (_("internal error - unimplemented "
847 "function unk_lang_print_type called."));
851 unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
852 int embedded_offset, CORE_ADDR address,
853 struct ui_file *stream, int recurse,
854 const struct value *val,
855 const struct value_print_options *options)
857 error (_("internal error - unimplemented "
858 "function unk_lang_val_print called."));
862 unk_lang_value_print (struct value *val, struct ui_file *stream,
863 const struct value_print_options *options)
865 error (_("internal error - unimplemented "
866 "function unk_lang_value_print called."));
869 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
874 /* Unknown languages just use the cplus demangler. */
875 static char *unk_lang_demangle (const char *mangled, int options)
877 return cplus_demangle (mangled, options);
880 static char *unk_lang_class_name (const char *mangled)
885 static const struct op_print unk_op_print_tab[] =
887 {NULL, OP_NULL, PREC_NULL, 0}
891 unknown_language_arch_info (struct gdbarch *gdbarch,
892 struct language_arch_info *lai)
894 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
895 lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
896 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
900 const struct language_defn unknown_language_defn =
909 &exp_descriptor_standard,
913 unk_lang_printchar, /* Print character constant */
916 unk_lang_print_type, /* Print a type using appropriate syntax */
917 default_print_typedef, /* Print a typedef using appropriate syntax */
918 unk_lang_val_print, /* Print a value using appropriate syntax */
919 unk_lang_value_print, /* Print a top-level value */
920 default_read_var_value, /* la_read_var_value */
921 unk_lang_trampoline, /* Language specific skip_trampoline */
922 "this", /* name_of_this */
923 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
924 basic_lookup_transparent_type,/* lookup_transparent_type */
925 unk_lang_demangle, /* Language specific symbol demangler */
926 unk_lang_class_name, /* Language specific
927 class_name_from_physname */
928 unk_op_print_tab, /* expression operators for printing */
929 1, /* c-style arrays */
930 0, /* String lower bound */
931 default_word_break_characters,
932 default_make_symbol_completion_list,
933 unknown_language_arch_info, /* la_language_arch_info. */
934 default_print_array_index,
935 default_pass_by_reference,
937 NULL, /* la_get_symbol_name_cmp */
938 iterate_over_symbols,
942 /* These two structs define fake entries for the "local" and "auto"
944 const struct language_defn auto_language_defn =
953 &exp_descriptor_standard,
957 unk_lang_printchar, /* Print character constant */
960 unk_lang_print_type, /* Print a type using appropriate syntax */
961 default_print_typedef, /* Print a typedef using appropriate syntax */
962 unk_lang_val_print, /* Print a value using appropriate syntax */
963 unk_lang_value_print, /* Print a top-level value */
964 default_read_var_value, /* la_read_var_value */
965 unk_lang_trampoline, /* Language specific skip_trampoline */
966 "this", /* name_of_this */
967 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
968 basic_lookup_transparent_type,/* lookup_transparent_type */
969 unk_lang_demangle, /* Language specific symbol demangler */
970 unk_lang_class_name, /* Language specific
971 class_name_from_physname */
972 unk_op_print_tab, /* expression operators for printing */
973 1, /* c-style arrays */
974 0, /* String lower bound */
975 default_word_break_characters,
976 default_make_symbol_completion_list,
977 unknown_language_arch_info, /* la_language_arch_info. */
978 default_print_array_index,
979 default_pass_by_reference,
981 NULL, /* la_get_symbol_name_cmp */
982 iterate_over_symbols,
986 const struct language_defn local_language_defn =
995 &exp_descriptor_standard,
999 unk_lang_printchar, /* Print character constant */
1002 unk_lang_print_type, /* Print a type using appropriate syntax */
1003 default_print_typedef, /* Print a typedef using appropriate syntax */
1004 unk_lang_val_print, /* Print a value using appropriate syntax */
1005 unk_lang_value_print, /* Print a top-level value */
1006 default_read_var_value, /* la_read_var_value */
1007 unk_lang_trampoline, /* Language specific skip_trampoline */
1008 "this", /* name_of_this */
1009 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1010 basic_lookup_transparent_type,/* lookup_transparent_type */
1011 unk_lang_demangle, /* Language specific symbol demangler */
1012 unk_lang_class_name, /* Language specific
1013 class_name_from_physname */
1014 unk_op_print_tab, /* expression operators for printing */
1015 1, /* c-style arrays */
1016 0, /* String lower bound */
1017 default_word_break_characters,
1018 default_make_symbol_completion_list,
1019 unknown_language_arch_info, /* la_language_arch_info. */
1020 default_print_array_index,
1021 default_pass_by_reference,
1023 NULL, /* la_get_symbol_name_cmp */
1024 iterate_over_symbols,
1028 /* Per-architecture language information. */
1030 static struct gdbarch_data *language_gdbarch_data;
1032 struct language_gdbarch
1034 /* A vector of per-language per-architecture info. Indexed by "enum
1036 struct language_arch_info arch_info[nr_languages];
1040 language_gdbarch_post_init (struct gdbarch *gdbarch)
1042 struct language_gdbarch *l;
1045 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
1046 for (i = 0; i < languages_size; i++)
1048 if (languages[i] != NULL
1049 && languages[i]->la_language_arch_info != NULL)
1050 languages[i]->la_language_arch_info
1051 (gdbarch, l->arch_info + languages[i]->la_language);
1057 language_string_char_type (const struct language_defn *la,
1058 struct gdbarch *gdbarch)
1060 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1061 language_gdbarch_data);
1063 return ld->arch_info[la->la_language].string_char_type;
1067 language_bool_type (const struct language_defn *la,
1068 struct gdbarch *gdbarch)
1070 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1071 language_gdbarch_data);
1073 if (ld->arch_info[la->la_language].bool_type_symbol)
1077 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
1078 NULL, VAR_DOMAIN, NULL);
1081 struct type *type = SYMBOL_TYPE (sym);
1083 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
1088 return ld->arch_info[la->la_language].bool_type_default;
1092 language_lookup_primitive_type_by_name (const struct language_defn *la,
1093 struct gdbarch *gdbarch,
1096 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1097 language_gdbarch_data);
1098 struct type *const *p;
1100 for (p = ld->arch_info[la->la_language].primitive_type_vector;
1104 if (strcmp (TYPE_NAME (*p), name) == 0)
1110 /* Initialize the language routines. */
1113 _initialize_language (void)
1115 static const char *const type_or_range_names[]
1116 = { "on", "off", "warn", "auto", NULL };
1118 static const char *const case_sensitive_names[]
1119 = { "on", "off", "auto", NULL };
1121 language_gdbarch_data
1122 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1124 /* GDB commands for language specific stuff. */
1126 add_prefix_cmd ("check", no_class, set_check,
1127 _("Set the status of the type/range checker."),
1128 &setchecklist, "set check ", 0, &setlist);
1129 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1130 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1132 add_prefix_cmd ("check", no_class, show_check,
1133 _("Show the status of the type/range checker."),
1134 &showchecklist, "show check ", 0, &showlist);
1135 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1136 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1138 add_setshow_enum_cmd ("type", class_support, type_or_range_names, &type,
1139 _("Set type checking. (on/warn/off/auto)"),
1140 _("Show type checking. (on/warn/off/auto)"),
1141 NULL, set_type_command,
1143 &setchecklist, &showchecklist);
1145 add_setshow_enum_cmd ("range", class_support, type_or_range_names,
1147 _("Set range checking. (on/warn/off/auto)"),
1148 _("Show range checking. (on/warn/off/auto)"),
1149 NULL, set_range_command,
1151 &setchecklist, &showchecklist);
1153 add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names,
1154 &case_sensitive, _("\
1155 Set case sensitivity in name search. (on/off/auto)"), _("\
1156 Show case sensitivity in name search. (on/off/auto)"), _("\
1157 For Fortran the default is off; for other languages the default is on."),
1160 &setlist, &showlist);
1162 add_language (&auto_language_defn);
1163 add_language (&local_language_defn);
1164 add_language (&unknown_language_defn);
1166 language = xstrdup ("auto");
1167 type = xstrdup ("auto");
1168 range = xstrdup ("auto");
1169 case_sensitive = xstrdup ("auto");
1171 /* Have the above take effect. */
1172 set_language (language_auto);