1 /* Multiple source language support for GDB.
3 Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
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 set_case_str (void);
52 static void set_range_str (void);
54 static void set_type_str (void);
56 static void set_lang_str (void);
58 static void unk_lang_error (char *);
60 static int unk_lang_parser (void);
62 static void show_check (char *, int);
64 static void set_check (char *, int);
66 static void set_type_range_case (void);
68 static void unk_lang_emit_char (int c, struct ui_file *stream, int quoter);
70 static void unk_lang_printchar (int c, struct ui_file *stream);
72 static void unk_lang_print_type (struct type *, char *, struct ui_file *,
75 static int unk_lang_value_print (struct value *, struct ui_file *,
76 const struct value_print_options *);
78 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
80 /* Forward declaration */
81 extern const struct language_defn unknown_language_defn;
83 /* The current (default at startup) state of type and range checking.
84 (If the modes are set to "auto", though, these are changed based
85 on the default language at startup, and then again based on the
86 language of the first source file. */
88 enum range_mode range_mode = range_mode_auto;
89 enum range_check range_check = range_check_off;
90 enum type_mode type_mode = type_mode_auto;
91 enum type_check type_check = type_check_off;
92 enum case_mode case_mode = case_mode_auto;
93 enum case_sensitivity case_sensitivity = case_sensitive_on;
95 /* The current language and language_mode (see language.h) */
97 const struct language_defn *current_language = &unknown_language_defn;
98 enum language_mode language_mode = language_mode_auto;
100 /* The language that the user expects to be typing in (the language
101 of main(), or the last language we notified them about, or C). */
103 const struct language_defn *expected_language;
105 /* The list of supported languages. The list itself is malloc'd. */
107 static const struct language_defn **languages;
108 static unsigned languages_size;
109 static unsigned languages_allocsize;
110 #define DEFAULT_ALLOCSIZE 4
112 /* The "set language/type/range" commands all put stuff in these
113 buffers. This is to make them work as set/show commands. The
114 user's string is copied here, then the set_* commands look at
115 them and update them to something that looks nice when it is
118 static char *language;
121 static char *case_sensitive;
123 /* Warning issued when current_language and the language of the current
124 frame do not match. */
125 char lang_frame_mismatch_warn[] =
126 "Warning: the current language does not match this frame.";
128 /* This page contains the functions corresponding to GDB commands
129 and their helpers. */
131 /* Show command. Display a warning if the language set
132 does not match the frame. */
134 show_language_command (struct ui_file *file, int from_tty,
135 struct cmd_list_element *c, const char *value)
137 enum language flang; /* The language of the current frame */
139 deprecated_show_value_hack (file, from_tty, c, value);
140 flang = get_frame_language ();
141 if (flang != language_unknown &&
142 language_mode == language_mode_manual &&
143 current_language->la_language != flang)
144 printf_filtered ("%s\n", lang_frame_mismatch_warn);
147 /* Set command. Change the current working language. */
149 set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
155 if (!language || !language[0])
157 printf_unfiltered (_("\
158 The currently understood settings are:\n\n\
159 local or auto Automatic setting based on source file\n"));
161 for (i = 0; i < languages_size; ++i)
163 /* Already dealt with these above. */
164 if (languages[i]->la_language == language_unknown
165 || languages[i]->la_language == language_auto)
168 /* FIXME: i18n: for now assume that the human-readable name
169 is just a capitalization of the internal name. */
170 printf_unfiltered ("%-16s Use the %c%s language\n",
171 languages[i]->la_name,
172 /* Capitalize first letter of language
174 toupper (languages[i]->la_name[0]),
175 languages[i]->la_name + 1);
177 /* Restore the silly string. */
178 set_language (current_language->la_language);
182 /* Search the list of languages for a match. */
183 for (i = 0; i < languages_size; i++)
185 if (strcmp (languages[i]->la_name, language) == 0)
187 /* Found it! Go into manual mode, and use this language. */
188 if (languages[i]->la_language == language_auto)
190 /* Enter auto mode. Set to the current frame's language, if
191 known, or fallback to the initial language. */
192 language_mode = language_mode_auto;
193 flang = get_frame_language ();
194 if (flang != language_unknown)
195 set_language (flang);
197 set_initial_language ();
198 expected_language = current_language;
203 /* Enter manual mode. Set the specified language. */
204 language_mode = language_mode_manual;
205 current_language = languages[i];
206 set_type_range_case ();
208 expected_language = current_language;
214 /* Reset the language (esp. the global string "language") to the
216 err_lang = savestring (language, strlen (language));
217 make_cleanup (xfree, err_lang); /* Free it after error */
218 set_language (current_language->la_language);
219 error (_("Unknown language `%s'."), err_lang);
222 /* Show command. Display a warning if the type setting does
223 not match the current language. */
225 show_type_command (struct ui_file *file, int from_tty,
226 struct cmd_list_element *c, const char *value)
228 deprecated_show_value_hack (file, from_tty, c, value);
229 if (type_check != current_language->la_type_check)
231 "Warning: the current type check setting does not match the language.\n");
234 /* Set command. Change the setting for type checking. */
236 set_type_command (char *ignore, int from_tty, struct cmd_list_element *c)
238 if (strcmp (type, "on") == 0)
240 type_check = type_check_on;
241 type_mode = type_mode_manual;
243 else if (strcmp (type, "warn") == 0)
245 type_check = type_check_warn;
246 type_mode = type_mode_manual;
248 else if (strcmp (type, "off") == 0)
250 type_check = type_check_off;
251 type_mode = type_mode_manual;
253 else if (strcmp (type, "auto") == 0)
255 type_mode = type_mode_auto;
256 set_type_range_case ();
257 /* Avoid hitting the set_type_str call below. We
258 did it in set_type_range_case. */
263 warning (_("Unrecognized type check setting: \"%s\""), type);
266 show_type_command (NULL, from_tty, NULL, NULL);
269 /* Show command. Display a warning if the range setting does
270 not match the current language. */
272 show_range_command (struct ui_file *file, int from_tty,
273 struct cmd_list_element *c, const char *value)
275 deprecated_show_value_hack (file, from_tty, c, value);
276 if (range_check != current_language->la_range_check)
278 "Warning: the current range check setting does not match the language.\n");
281 /* Set command. Change the setting for range checking. */
283 set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
285 if (strcmp (range, "on") == 0)
287 range_check = range_check_on;
288 range_mode = range_mode_manual;
290 else if (strcmp (range, "warn") == 0)
292 range_check = range_check_warn;
293 range_mode = range_mode_manual;
295 else if (strcmp (range, "off") == 0)
297 range_check = range_check_off;
298 range_mode = range_mode_manual;
300 else if (strcmp (range, "auto") == 0)
302 range_mode = range_mode_auto;
303 set_type_range_case ();
304 /* Avoid hitting the set_range_str call below. We
305 did it in set_type_range_case. */
310 warning (_("Unrecognized range check setting: \"%s\""), range);
313 show_range_command (NULL, from_tty, NULL, NULL);
316 /* Show command. Display a warning if the case sensitivity setting does
317 not match the current language. */
319 show_case_command (struct ui_file *file, int from_tty,
320 struct cmd_list_element *c, const char *value)
322 deprecated_show_value_hack (file, from_tty, c, value);
323 if (case_sensitivity != current_language->la_case_sensitivity)
325 "Warning: the current case sensitivity setting does not match the language.\n");
328 /* Set command. Change the setting for case sensitivity. */
331 set_case_command (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;
346 set_type_range_case ();
347 /* Avoid hitting the set_case_str call below. We did it in
348 set_type_range_case. */
353 warning (_("Unrecognized case-sensitive setting: \"%s\""),
357 show_case_command (NULL, from_tty, NULL, NULL);
360 /* Set the status of range and type checking and case sensitivity based on
361 the current modes and the current language.
362 If SHOW is non-zero, then print out the current language,
363 type and range checking status. */
365 set_type_range_case (void)
368 if (range_mode == range_mode_auto)
369 range_check = current_language->la_range_check;
371 if (type_mode == type_mode_auto)
372 type_check = current_language->la_type_check;
374 if (case_mode == case_mode_auto)
375 case_sensitivity = current_language->la_case_sensitivity;
382 /* Set current language to (enum language) LANG. Returns previous language. */
385 set_language (enum language lang)
388 enum language prev_language;
390 prev_language = current_language->la_language;
392 for (i = 0; i < languages_size; i++)
394 if (languages[i]->la_language == lang)
396 current_language = languages[i];
397 set_type_range_case ();
403 return prev_language;
406 /* This page contains functions that update the global vars
407 language, type and range. */
415 if (language_mode == language_mode_auto)
416 prefix = "auto; currently ";
418 language = concat (prefix, current_language->la_name, (char *)NULL);
424 char *tmp = NULL, *prefix = "";
428 if (type_mode == type_mode_auto)
429 prefix = "auto; currently ";
439 case type_check_warn:
443 error (_("Unrecognized type check setting."));
446 type = concat (prefix, tmp, (char *)NULL);
452 char *tmp, *pref = "";
454 if (range_mode == range_mode_auto)
455 pref = "auto; currently ";
462 case range_check_off:
465 case range_check_warn:
469 error (_("Unrecognized range check setting."));
474 range = concat (pref, tmp, (char *)NULL);
480 char *tmp = NULL, *prefix = "";
482 if (case_mode==case_mode_auto)
483 prefix = "auto; currently ";
485 switch (case_sensitivity)
487 case case_sensitive_on:
490 case case_sensitive_off:
494 error (_("Unrecognized case-sensitive setting."));
497 xfree (case_sensitive);
498 case_sensitive = concat (prefix, tmp, (char *)NULL);
501 /* Print out the current language settings: language, range and
502 type checking. If QUIETLY, print only what has changed. */
505 language_info (int quietly)
507 if (quietly && expected_language == current_language)
510 expected_language = current_language;
511 printf_unfiltered (_("Current language: %s\n"), language);
512 show_language_command (NULL, 1, NULL, NULL);
516 printf_unfiltered (_("Type checking: %s\n"), type);
517 show_type_command (NULL, 1, NULL, NULL);
518 printf_unfiltered (_("Range checking: %s\n"), range);
519 show_range_command (NULL, 1, NULL, NULL);
520 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
521 show_case_command (NULL, 1, NULL, NULL);
525 /* Return the result of a binary operation. */
527 #if 0 /* Currently unused */
530 binop_result_type (struct value *v1, struct value *v2)
533 struct type *t1 = check_typedef (VALUE_TYPE (v1));
534 struct type *t2 = check_typedef (VALUE_TYPE (v2));
536 int l1 = TYPE_LENGTH (t1);
537 int l2 = TYPE_LENGTH (t2);
539 switch (current_language->la_language)
544 if (TYPE_CODE (t1) == TYPE_CODE_FLT)
545 return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ?
546 VALUE_TYPE (v2) : VALUE_TYPE (v1);
547 else if (TYPE_CODE (t2) == TYPE_CODE_FLT)
548 return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ?
549 VALUE_TYPE (v1) : VALUE_TYPE (v2);
550 else if (TYPE_UNSIGNED (t1) && l1 > l2)
551 return VALUE_TYPE (v1);
552 else if (TYPE_UNSIGNED (t2) && l2 > l1)
553 return VALUE_TYPE (v2);
554 else /* Both are signed. Result is the longer type */
555 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
558 /* If we are doing type-checking, l1 should equal l2, so this is
560 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
563 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
564 return (struct type *) 0; /* For lint */
569 /* This page contains functions that are used in type/range checking.
570 They all return zero if the type/range check fails.
572 It is hoped that these will make extending GDB to parse different
573 languages a little easier. These are primarily used in eval.c when
574 evaluating expressions and making sure that their types are correct.
575 Instead of having a mess of conjucted/disjuncted expressions in an "if",
576 the ideas of type can be wrapped up in the following functions.
578 Note that some of them are not currently dependent upon which language
579 is currently being parsed. For example, floats are the same in
580 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
581 TYPE_CODE_FLT), while booleans are different. */
583 /* Returns non-zero if its argument is a simple type. This is the same for
584 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
585 and thus will never cause the failure of the test. */
587 simple_type (struct type *type)
589 CHECK_TYPEDEF (type);
590 switch (TYPE_CODE (type))
596 case TYPE_CODE_RANGE:
605 /* Returns non-zero if its argument is of an ordered type.
606 An ordered type is one in which the elements can be tested for the
607 properties of "greater than", "less than", etc, or for which the
608 operations "increment" or "decrement" make sense. */
610 ordered_type (struct type *type)
612 CHECK_TYPEDEF (type);
613 switch (TYPE_CODE (type))
619 case TYPE_CODE_RANGE:
627 /* Returns non-zero if the two types are the same */
629 same_type (struct type *arg1, struct type *arg2)
631 CHECK_TYPEDEF (type);
632 if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2))
633 /* One is structured and one isn't */
635 else if (structured_type (arg1) && structured_type (arg2))
637 else if (numeric_type (arg1) && numeric_type (arg2))
638 return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) &&
639 (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2))
645 /* Returns non-zero if the type is integral */
647 integral_type (struct type *type)
649 CHECK_TYPEDEF (type);
650 switch (current_language->la_language)
655 return (TYPE_CODE (type) != TYPE_CODE_INT) &&
656 (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
658 case language_pascal:
659 return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1;
661 error (_("Language not supported."));
665 /* Returns non-zero if the value is numeric */
667 numeric_type (struct type *type)
669 CHECK_TYPEDEF (type);
670 switch (TYPE_CODE (type))
681 /* Returns non-zero if the value is a character type */
683 character_type (struct type *type)
685 CHECK_TYPEDEF (type);
686 switch (current_language->la_language)
689 case language_pascal:
690 return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1;
695 return (TYPE_CODE (type) == TYPE_CODE_INT) &&
696 TYPE_LENGTH (type) == sizeof (char)
703 /* Returns non-zero if the value is a string type */
705 string_type (struct type *type)
707 CHECK_TYPEDEF (type);
708 switch (current_language->la_language)
711 case language_pascal:
712 return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1;
717 /* C does not have distinct string type. */
724 /* Returns non-zero if the value is a boolean type */
726 boolean_type (struct type *type)
728 CHECK_TYPEDEF (type);
729 if (TYPE_CODE (type) == TYPE_CODE_BOOL)
731 switch (current_language->la_language)
736 /* Might be more cleanly handled by having a
737 TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
738 languages, or a TYPE_CODE_INT_OR_BOOL for C. */
739 if (TYPE_CODE (type) == TYPE_CODE_INT)
747 /* Returns non-zero if the value is a floating-point type */
749 float_type (struct type *type)
751 CHECK_TYPEDEF (type);
752 return TYPE_CODE (type) == TYPE_CODE_FLT;
755 /* Returns non-zero if the value is a pointer type */
757 pointer_type (struct type *type)
759 return TYPE_CODE (type) == TYPE_CODE_PTR ||
760 TYPE_CODE (type) == TYPE_CODE_REF;
763 /* Returns non-zero if the value is a structured type */
765 structured_type (struct type *type)
767 CHECK_TYPEDEF (type);
768 switch (current_language->la_language)
773 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
774 (TYPE_CODE (type) == TYPE_CODE_UNION) ||
775 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
776 case language_pascal:
777 return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
778 (TYPE_CODE(type) == TYPE_CODE_UNION) ||
779 (TYPE_CODE(type) == TYPE_CODE_SET) ||
780 (TYPE_CODE(type) == TYPE_CODE_ARRAY);
782 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
783 (TYPE_CODE (type) == TYPE_CODE_SET) ||
784 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
791 /* This page contains functions that return info about
792 (struct value) values used in GDB. */
794 /* Returns non-zero if the value VAL represents a true value. */
796 value_true (struct value *val)
798 /* It is possible that we should have some sort of error if a non-boolean
799 value is used in this context. Possibly dependent on some kind of
800 "boolean-checking" option like range checking. But it should probably
801 not depend on the language except insofar as is necessary to identify
802 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
803 should be an error, probably). */
804 return !value_logical_not (val);
807 /* This page contains functions for the printing out of
808 error messages that occur during type- and range-
811 /* These are called when a language fails a type- or range-check. The
812 first argument should be a printf()-style format string, and the
813 rest of the arguments should be its arguments. If
814 [type|range]_check is [type|range]_check_on, an error is printed;
815 if [type|range]_check_warn, a warning; otherwise just the
819 type_error (const char *string,...)
822 va_start (args, string);
826 case type_check_warn:
827 vwarning (string, args);
830 verror (string, args);
833 /* FIXME: cagney/2002-01-30: Should this function print anything
834 when type error is off? */
835 vfprintf_filtered (gdb_stderr, string, args);
836 fprintf_filtered (gdb_stderr, "\n");
839 internal_error (__FILE__, __LINE__, _("bad switch"));
845 range_error (const char *string,...)
848 va_start (args, string);
852 case range_check_warn:
853 vwarning (string, args);
856 verror (string, args);
858 case range_check_off:
859 /* FIXME: cagney/2002-01-30: Should this function print anything
860 when range error is off? */
861 vfprintf_filtered (gdb_stderr, string, args);
862 fprintf_filtered (gdb_stderr, "\n");
865 internal_error (__FILE__, __LINE__, _("bad switch"));
871 /* This page contains miscellaneous functions */
873 /* Return the language enum for a given language string. */
876 language_enum (char *str)
880 for (i = 0; i < languages_size; i++)
881 if (strcmp (languages[i]->la_name, str) == 0)
882 return languages[i]->la_language;
884 return language_unknown;
887 /* Return the language struct for a given language enum. */
889 const struct language_defn *
890 language_def (enum language lang)
894 for (i = 0; i < languages_size; i++)
896 if (languages[i]->la_language == lang)
904 /* Return the language as a string */
906 language_str (enum language lang)
910 for (i = 0; i < languages_size; i++)
912 if (languages[i]->la_language == lang)
914 return languages[i]->la_name;
921 set_check (char *ignore, int from_tty)
924 "\"set check\" must be followed by the name of a check subcommand.\n");
925 help_list (setchecklist, "set check ", -1, gdb_stdout);
929 show_check (char *ignore, int from_tty)
931 cmd_show_list (showchecklist, from_tty, "");
934 /* Add a language to the set of known languages. */
937 add_language (const struct language_defn *lang)
939 if (lang->la_magic != LANG_MAGIC)
941 fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n",
943 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
948 languages_allocsize = DEFAULT_ALLOCSIZE;
949 languages = (const struct language_defn **) xmalloc
950 (languages_allocsize * sizeof (*languages));
952 if (languages_size >= languages_allocsize)
954 languages_allocsize *= 2;
955 languages = (const struct language_defn **) xrealloc ((char *) languages,
956 languages_allocsize * sizeof (*languages));
958 languages[languages_size++] = lang;
961 /* Iterate through all registered languages looking for and calling
962 any non-NULL struct language_defn.skip_trampoline() functions.
963 Return the result from the first that returns non-zero, or 0 if all
966 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
970 for (i = 0; i < languages_size; i++)
972 if (languages[i]->skip_trampoline)
974 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc);
983 /* Return demangled language symbol, or NULL.
984 FIXME: Options are only useful for certain languages and ignored
985 by others, so it would be better to remove them here and have a
986 more flexible demangler for the languages that need it.
987 FIXME: Sometimes the demangler is invoked when we don't know the
988 language, so we can't use this everywhere. */
990 language_demangle (const struct language_defn *current_language,
991 const char *mangled, int options)
993 if (current_language != NULL && current_language->la_demangle)
994 return current_language->la_demangle (mangled, options);
998 /* Return class name from physname or NULL. */
1000 language_class_name_from_physname (const struct language_defn *current_language,
1001 const char *physname)
1003 if (current_language != NULL && current_language->la_class_name_from_physname)
1004 return current_language->la_class_name_from_physname (physname);
1008 /* Return non-zero if TYPE should be passed (and returned) by
1009 reference at the language level. */
1011 language_pass_by_reference (struct type *type)
1013 return current_language->la_pass_by_reference (type);
1016 /* Return zero; by default, types are passed by value at the language
1017 level. The target ABI may pass or return some structs by reference
1018 independent of this. */
1020 default_pass_by_reference (struct type *type)
1025 /* Return the default string containing the list of characters
1026 delimiting words. This is a reasonable default value that
1027 most languages should be able to use. */
1030 default_word_break_characters (void)
1032 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1035 /* Print the index of array elements using the C99 syntax. */
1038 default_print_array_index (struct value *index_value, struct ui_file *stream,
1039 const struct value_print_options *options)
1041 fprintf_filtered (stream, "[");
1042 LA_VALUE_PRINT (index_value, stream, options);
1043 fprintf_filtered (stream, "] = ");
1046 /* Define the language that is no language. */
1049 unk_lang_parser (void)
1055 unk_lang_error (char *msg)
1057 error (_("Attempted to parse an expression with unknown language"));
1061 unk_lang_emit_char (int c, struct ui_file *stream, int quoter)
1063 error (_("internal error - unimplemented function unk_lang_emit_char called."));
1067 unk_lang_printchar (int c, struct ui_file *stream)
1069 error (_("internal error - unimplemented function unk_lang_printchar called."));
1073 unk_lang_printstr (struct ui_file *stream, const gdb_byte *string,
1074 unsigned int length, int width, int force_ellipses,
1075 const struct value_print_options *options)
1077 error (_("internal error - unimplemented function unk_lang_printstr called."));
1081 unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream,
1082 int show, int level)
1084 error (_("internal error - unimplemented function unk_lang_print_type called."));
1088 unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
1089 int embedded_offset, CORE_ADDR address,
1090 struct ui_file *stream, int recurse,
1091 const struct value_print_options *options)
1093 error (_("internal error - unimplemented function unk_lang_val_print called."));
1097 unk_lang_value_print (struct value *val, struct ui_file *stream,
1098 const struct value_print_options *options)
1100 error (_("internal error - unimplemented function unk_lang_value_print called."));
1103 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
1108 /* Unknown languages just use the cplus demangler. */
1109 static char *unk_lang_demangle (const char *mangled, int options)
1111 return cplus_demangle (mangled, options);
1114 static char *unk_lang_class_name (const char *mangled)
1119 static const struct op_print unk_op_print_tab[] =
1121 {NULL, OP_NULL, PREC_NULL, 0}
1125 unknown_language_arch_info (struct gdbarch *gdbarch,
1126 struct language_arch_info *lai)
1128 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
1129 lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
1130 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
1134 const struct language_defn unknown_language_defn =
1143 &exp_descriptor_standard,
1147 unk_lang_printchar, /* Print character constant */
1150 unk_lang_print_type, /* Print a type using appropriate syntax */
1151 default_print_typedef, /* Print a typedef using appropriate syntax */
1152 unk_lang_val_print, /* Print a value using appropriate syntax */
1153 unk_lang_value_print, /* Print a top-level value */
1154 unk_lang_trampoline, /* Language specific skip_trampoline */
1155 "this", /* name_of_this */
1156 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1157 basic_lookup_transparent_type,/* lookup_transparent_type */
1158 unk_lang_demangle, /* Language specific symbol demangler */
1159 unk_lang_class_name, /* Language specific class_name_from_physname */
1160 unk_op_print_tab, /* expression operators for printing */
1161 1, /* c-style arrays */
1162 0, /* String lower bound */
1163 default_word_break_characters,
1164 default_make_symbol_completion_list,
1165 unknown_language_arch_info, /* la_language_arch_info. */
1166 default_print_array_index,
1167 default_pass_by_reference,
1171 /* These two structs define fake entries for the "local" and "auto" options. */
1172 const struct language_defn auto_language_defn =
1181 &exp_descriptor_standard,
1185 unk_lang_printchar, /* Print character constant */
1188 unk_lang_print_type, /* Print a type using appropriate syntax */
1189 default_print_typedef, /* Print a typedef using appropriate syntax */
1190 unk_lang_val_print, /* Print a value using appropriate syntax */
1191 unk_lang_value_print, /* Print a top-level value */
1192 unk_lang_trampoline, /* Language specific skip_trampoline */
1193 "this", /* name_of_this */
1194 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1195 basic_lookup_transparent_type,/* lookup_transparent_type */
1196 unk_lang_demangle, /* Language specific symbol demangler */
1197 unk_lang_class_name, /* Language specific class_name_from_physname */
1198 unk_op_print_tab, /* expression operators for printing */
1199 1, /* c-style arrays */
1200 0, /* String lower bound */
1201 default_word_break_characters,
1202 default_make_symbol_completion_list,
1203 unknown_language_arch_info, /* la_language_arch_info. */
1204 default_print_array_index,
1205 default_pass_by_reference,
1209 const struct language_defn local_language_defn =
1218 &exp_descriptor_standard,
1222 unk_lang_printchar, /* Print character constant */
1225 unk_lang_print_type, /* Print a type using appropriate syntax */
1226 default_print_typedef, /* Print a typedef using appropriate syntax */
1227 unk_lang_val_print, /* Print a value using appropriate syntax */
1228 unk_lang_value_print, /* Print a top-level value */
1229 unk_lang_trampoline, /* Language specific skip_trampoline */
1230 "this", /* name_of_this */
1231 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1232 basic_lookup_transparent_type,/* lookup_transparent_type */
1233 unk_lang_demangle, /* Language specific symbol demangler */
1234 unk_lang_class_name, /* Language specific class_name_from_physname */
1235 unk_op_print_tab, /* expression operators for printing */
1236 1, /* c-style arrays */
1237 0, /* String lower bound */
1238 default_word_break_characters,
1239 default_make_symbol_completion_list,
1240 unknown_language_arch_info, /* la_language_arch_info. */
1241 default_print_array_index,
1242 default_pass_by_reference,
1246 /* Per-architecture language information. */
1248 static struct gdbarch_data *language_gdbarch_data;
1250 struct language_gdbarch
1252 /* A vector of per-language per-architecture info. Indexed by "enum
1254 struct language_arch_info arch_info[nr_languages];
1258 language_gdbarch_post_init (struct gdbarch *gdbarch)
1260 struct language_gdbarch *l;
1263 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
1264 for (i = 0; i < languages_size; i++)
1266 if (languages[i] != NULL
1267 && languages[i]->la_language_arch_info != NULL)
1268 languages[i]->la_language_arch_info
1269 (gdbarch, l->arch_info + languages[i]->la_language);
1275 language_string_char_type (const struct language_defn *la,
1276 struct gdbarch *gdbarch)
1278 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1279 language_gdbarch_data);
1280 return ld->arch_info[la->la_language].string_char_type;
1284 language_bool_type (const struct language_defn *la,
1285 struct gdbarch *gdbarch)
1287 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1288 language_gdbarch_data);
1290 if (ld->arch_info[la->la_language].bool_type_symbol)
1293 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
1294 NULL, VAR_DOMAIN, NULL);
1297 struct type *type = SYMBOL_TYPE (sym);
1298 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
1303 return ld->arch_info[la->la_language].bool_type_default;
1307 language_lookup_primitive_type_by_name (const struct language_defn *la,
1308 struct gdbarch *gdbarch,
1311 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1312 language_gdbarch_data);
1313 struct type *const *p;
1314 for (p = ld->arch_info[la->la_language].primitive_type_vector;
1318 if (strcmp (TYPE_NAME (*p), name) == 0)
1324 /* Initialize the language routines */
1327 _initialize_language (void)
1329 struct cmd_list_element *set, *show;
1331 language_gdbarch_data
1332 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1334 /* GDB commands for language specific stuff */
1336 /* FIXME: cagney/2005-02-20: This should be implemented using an
1338 add_setshow_string_noescape_cmd ("language", class_support, &language, _("\
1339 Set the current source language."), _("\
1340 Show the current source language."), NULL,
1341 set_language_command,
1342 show_language_command,
1343 &setlist, &showlist);
1345 add_prefix_cmd ("check", no_class, set_check,
1346 _("Set the status of the type/range checker."),
1347 &setchecklist, "set check ", 0, &setlist);
1348 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1349 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1351 add_prefix_cmd ("check", no_class, show_check,
1352 _("Show the status of the type/range checker."),
1353 &showchecklist, "show check ", 0, &showlist);
1354 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1355 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1357 /* FIXME: cagney/2005-02-20: This should be implemented using an
1359 add_setshow_string_noescape_cmd ("type", class_support, &type, _("\
1360 Set type checking. (on/warn/off/auto)"), _("\
1361 Show type checking. (on/warn/off/auto)"), NULL,
1364 &setchecklist, &showchecklist);
1366 /* FIXME: cagney/2005-02-20: This should be implemented using an
1368 add_setshow_string_noescape_cmd ("range", class_support, &range, _("\
1369 Set range checking. (on/warn/off/auto)"), _("\
1370 Show range checking. (on/warn/off/auto)"), NULL,
1373 &setchecklist, &showchecklist);
1375 /* FIXME: cagney/2005-02-20: This should be implemented using an
1377 add_setshow_string_noescape_cmd ("case-sensitive", class_support,
1378 &case_sensitive, _("\
1379 Set case sensitivity in name search. (on/off/auto)"), _("\
1380 Show case sensitivity in name search. (on/off/auto)"), _("\
1381 For Fortran the default is off; for other languages the default is on."),
1384 &setlist, &showlist);
1386 add_language (&unknown_language_defn);
1387 add_language (&local_language_defn);
1388 add_language (&auto_language_defn);
1390 language = savestring ("auto", strlen ("auto"));
1391 type = savestring ("auto", strlen ("auto"));
1392 range = savestring ("auto", strlen ("auto"));
1393 case_sensitive = savestring ("auto",strlen ("auto"));
1395 /* Have the above take effect */
1396 set_language (language_auto);