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, 2009 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 type *type,
69 struct ui_file *stream, int quoter);
71 static void unk_lang_printchar (int c, struct type *type,
72 struct ui_file *stream);
74 static void unk_lang_print_type (struct type *, char *, struct ui_file *,
77 static int unk_lang_value_print (struct value *, struct ui_file *,
78 const struct value_print_options *);
80 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
82 /* Forward declaration */
83 extern const struct language_defn unknown_language_defn;
85 /* The current (default at startup) state of type and range checking.
86 (If the modes are set to "auto", though, these are changed based
87 on the default language at startup, and then again based on the
88 language of the first source file. */
90 enum range_mode range_mode = range_mode_auto;
91 enum range_check range_check = range_check_off;
92 enum type_mode type_mode = type_mode_auto;
93 enum type_check type_check = type_check_off;
94 enum case_mode case_mode = case_mode_auto;
95 enum case_sensitivity case_sensitivity = case_sensitive_on;
97 /* The current language and language_mode (see language.h) */
99 const struct language_defn *current_language = &unknown_language_defn;
100 enum language_mode language_mode = language_mode_auto;
102 /* The language that the user expects to be typing in (the language
103 of main(), or the last language we notified them about, or C). */
105 const struct language_defn *expected_language;
107 /* The list of supported languages. The list itself is malloc'd. */
109 static const struct language_defn **languages;
110 static unsigned languages_size;
111 static unsigned languages_allocsize;
112 #define DEFAULT_ALLOCSIZE 4
114 /* The "set language/type/range" commands all put stuff in these
115 buffers. This is to make them work as set/show commands. The
116 user's string is copied here, then the set_* commands look at
117 them and update them to something that looks nice when it is
120 static char *language;
123 static char *case_sensitive;
125 /* Warning issued when current_language and the language of the current
126 frame do not match. */
127 char lang_frame_mismatch_warn[] =
128 "Warning: the current language does not match this frame.";
130 /* This page contains the functions corresponding to GDB commands
131 and their helpers. */
133 /* Show command. Display a warning if the language set
134 does not match the frame. */
136 show_language_command (struct ui_file *file, int from_tty,
137 struct cmd_list_element *c, const char *value)
139 enum language flang; /* The language of the current frame */
141 deprecated_show_value_hack (file, from_tty, c, value);
142 flang = get_frame_language ();
143 if (flang != language_unknown &&
144 language_mode == language_mode_manual &&
145 current_language->la_language != flang)
146 printf_filtered ("%s\n", lang_frame_mismatch_warn);
149 /* Set command. Change the current working language. */
151 set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
155 char *err_lang, *tem;
157 /* Strip trailing whitespace. */
162 len = strlen (language);
163 while (len > 0 && language[len - 1] == ' ')
169 printf_unfiltered (_("\
170 The currently understood settings are:\n\n\
171 local or auto Automatic setting based on source file\n"));
173 for (i = 0; i < languages_size; ++i)
175 /* Already dealt with these above. */
176 if (languages[i]->la_language == language_unknown
177 || languages[i]->la_language == language_auto)
180 /* FIXME: i18n: for now assume that the human-readable name
181 is just a capitalization of the internal name. */
182 printf_unfiltered ("%-16s Use the %c%s language\n",
183 languages[i]->la_name,
184 /* Capitalize first letter of language
186 toupper (languages[i]->la_name[0]),
187 languages[i]->la_name + 1);
189 /* Restore the silly string. */
190 set_language (current_language->la_language);
194 /* Reset LANGUAGE to avoid trailing spaces. */
195 tem = savestring (language, len);
199 /* Search the list of languages for a match. */
200 for (i = 0; i < languages_size; i++)
202 if (strcmp (languages[i]->la_name, language) == 0)
204 /* Found it! Go into manual mode, and use this language. */
205 if (languages[i]->la_language == language_auto)
207 /* Enter auto mode. Set to the current frame's language, if
208 known, or fallback to the initial language. */
209 language_mode = language_mode_auto;
210 flang = get_frame_language ();
211 if (flang != language_unknown)
212 set_language (flang);
214 set_initial_language ();
215 expected_language = current_language;
220 /* Enter manual mode. Set the specified language. */
221 language_mode = language_mode_manual;
222 current_language = languages[i];
223 set_type_range_case ();
225 expected_language = current_language;
231 /* Reset the language (esp. the global string "language") to the
233 err_lang = xstrdup (language);
234 make_cleanup (xfree, err_lang); /* Free it after error */
235 set_language (current_language->la_language);
236 error (_("Unknown language `%s'."), err_lang);
240 language_completer (struct cmd_list_element *self, char *text, char *word)
243 const char **langnames
244 = (const char **) alloca ((languages_size + 1) * sizeof (const char *));
246 for (i = 0; i < languages_size; ++i)
247 langnames[i] = languages[i]->la_name;
250 return complete_on_enum (langnames, text, word);
253 /* Show command. Display a warning if the type setting does
254 not match the current language. */
256 show_type_command (struct ui_file *file, int from_tty,
257 struct cmd_list_element *c, const char *value)
259 deprecated_show_value_hack (file, from_tty, c, value);
260 if (type_check != current_language->la_type_check)
262 "Warning: the current type check setting does not match the language.\n");
265 /* Set command. Change the setting for type checking. */
267 set_type_command (char *ignore, int from_tty, struct cmd_list_element *c)
272 /* Strip trailing whitespace. */
274 while (len > 0 && type[len - 1] == ' ')
277 tem = savestring (type, len);
281 if (strcmp (type, "on") == 0)
283 type_check = type_check_on;
284 type_mode = type_mode_manual;
286 else if (strcmp (type, "warn") == 0)
288 type_check = type_check_warn;
289 type_mode = type_mode_manual;
291 else if (strcmp (type, "off") == 0)
293 type_check = type_check_off;
294 type_mode = type_mode_manual;
296 else if (strcmp (type, "auto") == 0)
298 type_mode = type_mode_auto;
299 set_type_range_case ();
300 /* Avoid hitting the set_type_str call below. We
301 did it in set_type_range_case. */
306 warning (_("Unrecognized type check setting: \"%s\""), type);
309 show_type_command (NULL, from_tty, NULL, NULL);
312 /* Show command. Display a warning if the range setting does
313 not match the current language. */
315 show_range_command (struct ui_file *file, int from_tty,
316 struct cmd_list_element *c, const char *value)
318 deprecated_show_value_hack (file, from_tty, c, value);
319 if (range_check != current_language->la_range_check)
321 "Warning: the current range check setting does not match the language.\n");
324 /* Set command. Change the setting for range checking. */
326 set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
331 /* Strip trailing whitespace. */
332 len = strlen (range);
333 while (len > 0 && range[len - 1] == ' ')
336 tem = savestring (range, len);
340 if (strcmp (range, "on") == 0)
342 range_check = range_check_on;
343 range_mode = range_mode_manual;
345 else if (strcmp (range, "warn") == 0)
347 range_check = range_check_warn;
348 range_mode = range_mode_manual;
350 else if (strcmp (range, "off") == 0)
352 range_check = range_check_off;
353 range_mode = range_mode_manual;
355 else if (strcmp (range, "auto") == 0)
357 range_mode = range_mode_auto;
358 set_type_range_case ();
359 /* Avoid hitting the set_range_str call below. We
360 did it in set_type_range_case. */
365 warning (_("Unrecognized range check setting: \"%s\""), range);
368 show_range_command (NULL, from_tty, NULL, NULL);
371 /* Completer for range and type parameters. */
373 range_or_type_completer (struct cmd_list_element *self, char *text, char *word)
375 static const char *values[] = { "on", "off", "warn", "auto", NULL };
376 return complete_on_enum (values, text, word);
379 /* Show command. Display a warning if the case sensitivity setting does
380 not match the current language. */
382 show_case_command (struct ui_file *file, int from_tty,
383 struct cmd_list_element *c, const char *value)
385 deprecated_show_value_hack (file, from_tty, c, value);
386 if (case_sensitivity != current_language->la_case_sensitivity)
388 "Warning: the current case sensitivity setting does not match the language.\n");
391 /* Set command. Change the setting for case sensitivity. */
394 set_case_command (char *ignore, int from_tty, struct cmd_list_element *c)
396 if (strcmp (case_sensitive, "on") == 0)
398 case_sensitivity = case_sensitive_on;
399 case_mode = case_mode_manual;
401 else if (strcmp (case_sensitive, "off") == 0)
403 case_sensitivity = case_sensitive_off;
404 case_mode = case_mode_manual;
406 else if (strcmp (case_sensitive, "auto") == 0)
408 case_mode = case_mode_auto;
409 set_type_range_case ();
410 /* Avoid hitting the set_case_str call below. We did it in
411 set_type_range_case. */
416 warning (_("Unrecognized case-sensitive setting: \"%s\""),
420 show_case_command (NULL, from_tty, NULL, NULL);
423 /* Completer for case-sensitive parameter. */
425 case_completer (struct cmd_list_element *self, char *text, char *word)
427 static const char *values[] = { "on", "off", "auto", NULL };
428 return complete_on_enum (values, text, word);
431 /* Set the status of range and type checking and case sensitivity based on
432 the current modes and the current language.
433 If SHOW is non-zero, then print out the current language,
434 type and range checking status. */
436 set_type_range_case (void)
439 if (range_mode == range_mode_auto)
440 range_check = current_language->la_range_check;
442 if (type_mode == type_mode_auto)
443 type_check = current_language->la_type_check;
445 if (case_mode == case_mode_auto)
446 case_sensitivity = current_language->la_case_sensitivity;
453 /* Set current language to (enum language) LANG. Returns previous language. */
456 set_language (enum language lang)
459 enum language prev_language;
461 prev_language = current_language->la_language;
463 for (i = 0; i < languages_size; i++)
465 if (languages[i]->la_language == lang)
467 current_language = languages[i];
468 set_type_range_case ();
474 return prev_language;
477 /* This page contains functions that update the global vars
478 language, type and range. */
486 if (language_mode == language_mode_auto)
487 prefix = "auto; currently ";
489 language = concat (prefix, current_language->la_name, (char *)NULL);
495 char *tmp = NULL, *prefix = "";
499 if (type_mode == type_mode_auto)
500 prefix = "auto; currently ";
510 case type_check_warn:
514 error (_("Unrecognized type check setting."));
517 type = concat (prefix, tmp, (char *)NULL);
523 char *tmp, *pref = "";
525 if (range_mode == range_mode_auto)
526 pref = "auto; currently ";
533 case range_check_off:
536 case range_check_warn:
540 error (_("Unrecognized range check setting."));
545 range = concat (pref, tmp, (char *)NULL);
551 char *tmp = NULL, *prefix = "";
553 if (case_mode==case_mode_auto)
554 prefix = "auto; currently ";
556 switch (case_sensitivity)
558 case case_sensitive_on:
561 case case_sensitive_off:
565 error (_("Unrecognized case-sensitive setting."));
568 xfree (case_sensitive);
569 case_sensitive = concat (prefix, tmp, (char *)NULL);
572 /* Print out the current language settings: language, range and
573 type checking. If QUIETLY, print only what has changed. */
576 language_info (int quietly)
578 if (quietly && expected_language == current_language)
581 expected_language = current_language;
582 printf_unfiltered (_("Current language: %s\n"), language);
583 show_language_command (NULL, 1, NULL, NULL);
587 printf_unfiltered (_("Type checking: %s\n"), type);
588 show_type_command (NULL, 1, NULL, NULL);
589 printf_unfiltered (_("Range checking: %s\n"), range);
590 show_range_command (NULL, 1, NULL, NULL);
591 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
592 show_case_command (NULL, 1, NULL, NULL);
596 /* Return the result of a binary operation. */
598 #if 0 /* Currently unused */
601 binop_result_type (struct value *v1, struct value *v2)
604 struct type *t1 = check_typedef (VALUE_TYPE (v1));
605 struct type *t2 = check_typedef (VALUE_TYPE (v2));
607 int l1 = TYPE_LENGTH (t1);
608 int l2 = TYPE_LENGTH (t2);
610 switch (current_language->la_language)
615 if (TYPE_CODE (t1) == TYPE_CODE_FLT)
616 return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ?
617 VALUE_TYPE (v2) : VALUE_TYPE (v1);
618 else if (TYPE_CODE (t2) == TYPE_CODE_FLT)
619 return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ?
620 VALUE_TYPE (v1) : VALUE_TYPE (v2);
621 else if (TYPE_UNSIGNED (t1) && l1 > l2)
622 return VALUE_TYPE (v1);
623 else if (TYPE_UNSIGNED (t2) && l2 > l1)
624 return VALUE_TYPE (v2);
625 else /* Both are signed. Result is the longer type */
626 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
629 /* If we are doing type-checking, l1 should equal l2, so this is
631 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
634 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
635 return (struct type *) 0; /* For lint */
640 /* This page contains functions that are used in type/range checking.
641 They all return zero if the type/range check fails.
643 It is hoped that these will make extending GDB to parse different
644 languages a little easier. These are primarily used in eval.c when
645 evaluating expressions and making sure that their types are correct.
646 Instead of having a mess of conjucted/disjuncted expressions in an "if",
647 the ideas of type can be wrapped up in the following functions.
649 Note that some of them are not currently dependent upon which language
650 is currently being parsed. For example, floats are the same in
651 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
652 TYPE_CODE_FLT), while booleans are different. */
654 /* Returns non-zero if its argument is a simple type. This is the same for
655 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
656 and thus will never cause the failure of the test. */
658 simple_type (struct type *type)
660 CHECK_TYPEDEF (type);
661 switch (TYPE_CODE (type))
667 case TYPE_CODE_RANGE:
676 /* Returns non-zero if its argument is of an ordered type.
677 An ordered type is one in which the elements can be tested for the
678 properties of "greater than", "less than", etc, or for which the
679 operations "increment" or "decrement" make sense. */
681 ordered_type (struct type *type)
683 CHECK_TYPEDEF (type);
684 switch (TYPE_CODE (type))
690 case TYPE_CODE_RANGE:
698 /* Returns non-zero if the two types are the same */
700 same_type (struct type *arg1, struct type *arg2)
702 CHECK_TYPEDEF (type);
703 if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2))
704 /* One is structured and one isn't */
706 else if (structured_type (arg1) && structured_type (arg2))
708 else if (numeric_type (arg1) && numeric_type (arg2))
709 return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) &&
710 (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2))
716 /* Returns non-zero if the type is integral */
718 integral_type (struct type *type)
720 CHECK_TYPEDEF (type);
721 switch (current_language->la_language)
726 return (TYPE_CODE (type) != TYPE_CODE_INT) &&
727 (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
729 case language_pascal:
730 return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1;
732 error (_("Language not supported."));
736 /* Returns non-zero if the value is numeric */
738 numeric_type (struct type *type)
740 CHECK_TYPEDEF (type);
741 switch (TYPE_CODE (type))
752 /* Returns non-zero if the value is a character type */
754 character_type (struct type *type)
756 CHECK_TYPEDEF (type);
757 switch (current_language->la_language)
760 case language_pascal:
761 return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1;
766 return (TYPE_CODE (type) == TYPE_CODE_INT) &&
767 TYPE_LENGTH (type) == sizeof (char)
774 /* Returns non-zero if the value is a string type */
776 string_type (struct type *type)
778 CHECK_TYPEDEF (type);
779 switch (current_language->la_language)
782 case language_pascal:
783 return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1;
788 /* C does not have distinct string type. */
795 /* Returns non-zero if the value is a boolean type */
797 boolean_type (struct type *type)
799 CHECK_TYPEDEF (type);
800 if (TYPE_CODE (type) == TYPE_CODE_BOOL)
802 switch (current_language->la_language)
807 /* Might be more cleanly handled by having a
808 TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
809 languages, or a TYPE_CODE_INT_OR_BOOL for C. */
810 if (TYPE_CODE (type) == TYPE_CODE_INT)
818 /* Returns non-zero if the value is a floating-point type */
820 float_type (struct type *type)
822 CHECK_TYPEDEF (type);
823 return TYPE_CODE (type) == TYPE_CODE_FLT;
826 /* Returns non-zero if the value is a pointer type */
828 pointer_type (struct type *type)
830 return TYPE_CODE (type) == TYPE_CODE_PTR ||
831 TYPE_CODE (type) == TYPE_CODE_REF;
834 /* Returns non-zero if the value is a structured type */
836 structured_type (struct type *type)
838 CHECK_TYPEDEF (type);
839 switch (current_language->la_language)
844 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
845 (TYPE_CODE (type) == TYPE_CODE_UNION) ||
846 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
847 case language_pascal:
848 return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
849 (TYPE_CODE(type) == TYPE_CODE_UNION) ||
850 (TYPE_CODE(type) == TYPE_CODE_SET) ||
851 (TYPE_CODE(type) == TYPE_CODE_ARRAY);
853 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
854 (TYPE_CODE (type) == TYPE_CODE_SET) ||
855 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
862 /* This page contains functions that return info about
863 (struct value) values used in GDB. */
865 /* Returns non-zero if the value VAL represents a true value. */
867 value_true (struct value *val)
869 /* It is possible that we should have some sort of error if a non-boolean
870 value is used in this context. Possibly dependent on some kind of
871 "boolean-checking" option like range checking. But it should probably
872 not depend on the language except insofar as is necessary to identify
873 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
874 should be an error, probably). */
875 return !value_logical_not (val);
878 /* This page contains functions for the printing out of
879 error messages that occur during type- and range-
882 /* These are called when a language fails a type- or range-check. The
883 first argument should be a printf()-style format string, and the
884 rest of the arguments should be its arguments. If
885 [type|range]_check is [type|range]_check_on, an error is printed;
886 if [type|range]_check_warn, a warning; otherwise just the
890 type_error (const char *string,...)
893 va_start (args, string);
897 case type_check_warn:
898 vwarning (string, args);
901 verror (string, args);
904 /* FIXME: cagney/2002-01-30: Should this function print anything
905 when type error is off? */
906 vfprintf_filtered (gdb_stderr, string, args);
907 fprintf_filtered (gdb_stderr, "\n");
910 internal_error (__FILE__, __LINE__, _("bad switch"));
916 range_error (const char *string,...)
919 va_start (args, string);
923 case range_check_warn:
924 vwarning (string, args);
927 verror (string, args);
929 case range_check_off:
930 /* FIXME: cagney/2002-01-30: Should this function print anything
931 when range error is off? */
932 vfprintf_filtered (gdb_stderr, string, args);
933 fprintf_filtered (gdb_stderr, "\n");
936 internal_error (__FILE__, __LINE__, _("bad switch"));
942 /* This page contains miscellaneous functions */
944 /* Return the language enum for a given language string. */
947 language_enum (char *str)
951 for (i = 0; i < languages_size; i++)
952 if (strcmp (languages[i]->la_name, str) == 0)
953 return languages[i]->la_language;
955 return language_unknown;
958 /* Return the language struct for a given language enum. */
960 const struct language_defn *
961 language_def (enum language lang)
965 for (i = 0; i < languages_size; i++)
967 if (languages[i]->la_language == lang)
975 /* Return the language as a string */
977 language_str (enum language lang)
981 for (i = 0; i < languages_size; i++)
983 if (languages[i]->la_language == lang)
985 return languages[i]->la_name;
992 set_check (char *ignore, int from_tty)
995 "\"set check\" must be followed by the name of a check subcommand.\n");
996 help_list (setchecklist, "set check ", -1, gdb_stdout);
1000 show_check (char *ignore, int from_tty)
1002 cmd_show_list (showchecklist, from_tty, "");
1005 /* Add a language to the set of known languages. */
1008 add_language (const struct language_defn *lang)
1010 if (lang->la_magic != LANG_MAGIC)
1012 fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n",
1014 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
1019 languages_allocsize = DEFAULT_ALLOCSIZE;
1020 languages = (const struct language_defn **) xmalloc
1021 (languages_allocsize * sizeof (*languages));
1023 if (languages_size >= languages_allocsize)
1025 languages_allocsize *= 2;
1026 languages = (const struct language_defn **) xrealloc ((char *) languages,
1027 languages_allocsize * sizeof (*languages));
1029 languages[languages_size++] = lang;
1032 /* Iterate through all registered languages looking for and calling
1033 any non-NULL struct language_defn.skip_trampoline() functions.
1034 Return the result from the first that returns non-zero, or 0 if all
1037 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
1041 for (i = 0; i < languages_size; i++)
1043 if (languages[i]->skip_trampoline)
1045 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc);
1054 /* Return demangled language symbol, or NULL.
1055 FIXME: Options are only useful for certain languages and ignored
1056 by others, so it would be better to remove them here and have a
1057 more flexible demangler for the languages that need it.
1058 FIXME: Sometimes the demangler is invoked when we don't know the
1059 language, so we can't use this everywhere. */
1061 language_demangle (const struct language_defn *current_language,
1062 const char *mangled, int options)
1064 if (current_language != NULL && current_language->la_demangle)
1065 return current_language->la_demangle (mangled, options);
1069 /* Return class name from physname or NULL. */
1071 language_class_name_from_physname (const struct language_defn *current_language,
1072 const char *physname)
1074 if (current_language != NULL && current_language->la_class_name_from_physname)
1075 return current_language->la_class_name_from_physname (physname);
1079 /* Return non-zero if TYPE should be passed (and returned) by
1080 reference at the language level. */
1082 language_pass_by_reference (struct type *type)
1084 return current_language->la_pass_by_reference (type);
1087 /* Return zero; by default, types are passed by value at the language
1088 level. The target ABI may pass or return some structs by reference
1089 independent of this. */
1091 default_pass_by_reference (struct type *type)
1096 /* Return the default string containing the list of characters
1097 delimiting words. This is a reasonable default value that
1098 most languages should be able to use. */
1101 default_word_break_characters (void)
1103 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1106 /* Print the index of array elements using the C99 syntax. */
1109 default_print_array_index (struct value *index_value, struct ui_file *stream,
1110 const struct value_print_options *options)
1112 fprintf_filtered (stream, "[");
1113 LA_VALUE_PRINT (index_value, stream, options);
1114 fprintf_filtered (stream, "] = ");
1118 default_get_string (struct value *value, gdb_byte **buffer, int *length,
1119 const char **charset)
1121 error (_("Getting a string is unsupported in this language."));
1124 /* Define the language that is no language. */
1127 unk_lang_parser (void)
1133 unk_lang_error (char *msg)
1135 error (_("Attempted to parse an expression with unknown language"));
1139 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
1142 error (_("internal error - unimplemented function unk_lang_emit_char called."));
1146 unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
1148 error (_("internal error - unimplemented function unk_lang_printchar called."));
1152 unk_lang_printstr (struct ui_file *stream, struct type *type,
1153 const gdb_byte *string, unsigned int length,
1155 const struct value_print_options *options)
1157 error (_("internal error - unimplemented function unk_lang_printstr called."));
1161 unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream,
1162 int show, int level)
1164 error (_("internal error - unimplemented function unk_lang_print_type called."));
1168 unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
1169 int embedded_offset, CORE_ADDR address,
1170 struct ui_file *stream, int recurse,
1171 const struct value_print_options *options)
1173 error (_("internal error - unimplemented function unk_lang_val_print called."));
1177 unk_lang_value_print (struct value *val, struct ui_file *stream,
1178 const struct value_print_options *options)
1180 error (_("internal error - unimplemented function unk_lang_value_print called."));
1183 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
1188 /* Unknown languages just use the cplus demangler. */
1189 static char *unk_lang_demangle (const char *mangled, int options)
1191 return cplus_demangle (mangled, options);
1194 static char *unk_lang_class_name (const char *mangled)
1199 static const struct op_print unk_op_print_tab[] =
1201 {NULL, OP_NULL, PREC_NULL, 0}
1205 unknown_language_arch_info (struct gdbarch *gdbarch,
1206 struct language_arch_info *lai)
1208 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
1209 lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
1210 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
1214 const struct language_defn unknown_language_defn =
1223 &exp_descriptor_standard,
1227 unk_lang_printchar, /* Print character constant */
1230 unk_lang_print_type, /* Print a type using appropriate syntax */
1231 default_print_typedef, /* Print a typedef using appropriate syntax */
1232 unk_lang_val_print, /* Print a value using appropriate syntax */
1233 unk_lang_value_print, /* Print a top-level value */
1234 unk_lang_trampoline, /* Language specific skip_trampoline */
1235 "this", /* name_of_this */
1236 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1237 basic_lookup_transparent_type,/* lookup_transparent_type */
1238 unk_lang_demangle, /* Language specific symbol demangler */
1239 unk_lang_class_name, /* Language specific class_name_from_physname */
1240 unk_op_print_tab, /* expression operators for printing */
1241 1, /* c-style arrays */
1242 0, /* String lower bound */
1243 default_word_break_characters,
1244 default_make_symbol_completion_list,
1245 unknown_language_arch_info, /* la_language_arch_info. */
1246 default_print_array_index,
1247 default_pass_by_reference,
1252 /* These two structs define fake entries for the "local" and "auto" options. */
1253 const struct language_defn auto_language_defn =
1262 &exp_descriptor_standard,
1266 unk_lang_printchar, /* Print character constant */
1269 unk_lang_print_type, /* Print a type using appropriate syntax */
1270 default_print_typedef, /* Print a typedef using appropriate syntax */
1271 unk_lang_val_print, /* Print a value using appropriate syntax */
1272 unk_lang_value_print, /* Print a top-level value */
1273 unk_lang_trampoline, /* Language specific skip_trampoline */
1274 "this", /* name_of_this */
1275 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1276 basic_lookup_transparent_type,/* lookup_transparent_type */
1277 unk_lang_demangle, /* Language specific symbol demangler */
1278 unk_lang_class_name, /* Language specific class_name_from_physname */
1279 unk_op_print_tab, /* expression operators for printing */
1280 1, /* c-style arrays */
1281 0, /* String lower bound */
1282 default_word_break_characters,
1283 default_make_symbol_completion_list,
1284 unknown_language_arch_info, /* la_language_arch_info. */
1285 default_print_array_index,
1286 default_pass_by_reference,
1291 const struct language_defn local_language_defn =
1300 &exp_descriptor_standard,
1304 unk_lang_printchar, /* Print character constant */
1307 unk_lang_print_type, /* Print a type using appropriate syntax */
1308 default_print_typedef, /* Print a typedef using appropriate syntax */
1309 unk_lang_val_print, /* Print a value using appropriate syntax */
1310 unk_lang_value_print, /* Print a top-level value */
1311 unk_lang_trampoline, /* Language specific skip_trampoline */
1312 "this", /* name_of_this */
1313 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1314 basic_lookup_transparent_type,/* lookup_transparent_type */
1315 unk_lang_demangle, /* Language specific symbol demangler */
1316 unk_lang_class_name, /* Language specific class_name_from_physname */
1317 unk_op_print_tab, /* expression operators for printing */
1318 1, /* c-style arrays */
1319 0, /* String lower bound */
1320 default_word_break_characters,
1321 default_make_symbol_completion_list,
1322 unknown_language_arch_info, /* la_language_arch_info. */
1323 default_print_array_index,
1324 default_pass_by_reference,
1329 /* Per-architecture language information. */
1331 static struct gdbarch_data *language_gdbarch_data;
1333 struct language_gdbarch
1335 /* A vector of per-language per-architecture info. Indexed by "enum
1337 struct language_arch_info arch_info[nr_languages];
1341 language_gdbarch_post_init (struct gdbarch *gdbarch)
1343 struct language_gdbarch *l;
1346 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
1347 for (i = 0; i < languages_size; i++)
1349 if (languages[i] != NULL
1350 && languages[i]->la_language_arch_info != NULL)
1351 languages[i]->la_language_arch_info
1352 (gdbarch, l->arch_info + languages[i]->la_language);
1358 language_string_char_type (const struct language_defn *la,
1359 struct gdbarch *gdbarch)
1361 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1362 language_gdbarch_data);
1363 return ld->arch_info[la->la_language].string_char_type;
1367 language_bool_type (const struct language_defn *la,
1368 struct gdbarch *gdbarch)
1370 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1371 language_gdbarch_data);
1373 if (ld->arch_info[la->la_language].bool_type_symbol)
1376 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
1377 NULL, VAR_DOMAIN, NULL);
1380 struct type *type = SYMBOL_TYPE (sym);
1381 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
1386 return ld->arch_info[la->la_language].bool_type_default;
1390 language_lookup_primitive_type_by_name (const struct language_defn *la,
1391 struct gdbarch *gdbarch,
1394 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1395 language_gdbarch_data);
1396 struct type *const *p;
1397 for (p = ld->arch_info[la->la_language].primitive_type_vector;
1401 if (strcmp (TYPE_NAME (*p), name) == 0)
1407 /* Initialize the language routines */
1410 _initialize_language (void)
1412 struct cmd_list_element *command;
1414 language_gdbarch_data
1415 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1417 /* GDB commands for language specific stuff */
1419 command = add_setshow_string_noescape_cmd ("language", class_support,
1421 Set the current source language."), _("\
1422 Show the current source language."), NULL,
1423 set_language_command,
1424 show_language_command,
1425 &setlist, &showlist);
1426 set_cmd_completer (command, language_completer);
1428 add_prefix_cmd ("check", no_class, set_check,
1429 _("Set the status of the type/range checker."),
1430 &setchecklist, "set check ", 0, &setlist);
1431 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1432 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1434 add_prefix_cmd ("check", no_class, show_check,
1435 _("Show the status of the type/range checker."),
1436 &showchecklist, "show check ", 0, &showlist);
1437 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1438 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1441 add_setshow_string_noescape_cmd ("type", class_support,
1443 Set type checking. (on/warn/off/auto)"), _("\
1444 Show type checking. (on/warn/off/auto)"), NULL,
1447 &setchecklist, &showchecklist);
1448 set_cmd_completer (command, range_or_type_completer);
1451 add_setshow_string_noescape_cmd ("range", class_support,
1453 Set range checking. (on/warn/off/auto)"), _("\
1454 Show range checking. (on/warn/off/auto)"), NULL,
1457 &setchecklist, &showchecklist);
1458 set_cmd_completer (command, range_or_type_completer);
1461 add_setshow_string_noescape_cmd ("case-sensitive", class_support,
1462 &case_sensitive, _("\
1463 Set case sensitivity in name search. (on/off/auto)"), _("\
1464 Show case sensitivity in name search. (on/off/auto)"), _("\
1465 For Fortran the default is off; for other languages the default is on."),
1468 &setlist, &showlist);
1469 set_cmd_completer (command, case_completer);
1471 add_language (&unknown_language_defn);
1472 add_language (&local_language_defn);
1473 add_language (&auto_language_defn);
1475 language = xstrdup ("auto");
1476 type = xstrdup ("auto");
1477 range = xstrdup ("auto");
1478 case_sensitive = xstrdup ("auto");
1480 /* Have the above take effect */
1481 set_language (language_auto);