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 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"
47 extern void _initialize_language (void);
49 static void set_case_str (void);
51 static void set_range_str (void);
53 static void set_type_str (void);
55 static void set_lang_str (void);
57 static void unk_lang_error (char *);
59 static int unk_lang_parser (void);
61 static void show_check (char *, int);
63 static void set_check (char *, int);
65 static void set_type_range_case (void);
67 static void unk_lang_emit_char (int c, struct ui_file *stream, int quoter);
69 static void unk_lang_printchar (int c, struct ui_file *stream);
71 static void unk_lang_print_type (struct type *, char *, struct ui_file *,
74 static int unk_lang_value_print (struct value *, struct ui_file *, int, enum val_prettyprint);
76 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
78 /* Forward declaration */
79 extern const struct language_defn unknown_language_defn;
81 /* The current (default at startup) state of type and range checking.
82 (If the modes are set to "auto", though, these are changed based
83 on the default language at startup, and then again based on the
84 language of the first source file. */
86 enum range_mode range_mode = range_mode_auto;
87 enum range_check range_check = range_check_off;
88 enum type_mode type_mode = type_mode_auto;
89 enum type_check type_check = type_check_off;
90 enum case_mode case_mode = case_mode_auto;
91 enum case_sensitivity case_sensitivity = case_sensitive_on;
93 /* The current language and language_mode (see language.h) */
95 const struct language_defn *current_language = &unknown_language_defn;
96 enum language_mode language_mode = language_mode_auto;
98 /* The language that the user expects to be typing in (the language
99 of main(), or the last language we notified them about, or C). */
101 const struct language_defn *expected_language;
103 /* The list of supported languages. The list itself is malloc'd. */
105 static const struct language_defn **languages;
106 static unsigned languages_size;
107 static unsigned languages_allocsize;
108 #define DEFAULT_ALLOCSIZE 4
110 /* The "set language/type/range" commands all put stuff in these
111 buffers. This is to make them work as set/show commands. The
112 user's string is copied here, then the set_* commands look at
113 them and update them to something that looks nice when it is
116 static char *language;
119 static char *case_sensitive;
121 /* Warning issued when current_language and the language of the current
122 frame do not match. */
123 char lang_frame_mismatch_warn[] =
124 "Warning: the current language does not match this frame.";
126 /* This page contains the functions corresponding to GDB commands
127 and their helpers. */
129 /* Show command. Display a warning if the language set
130 does not match the frame. */
132 show_language_command (struct ui_file *file, int from_tty,
133 struct cmd_list_element *c, const char *value)
135 enum language flang; /* The language of the current frame */
137 deprecated_show_value_hack (file, from_tty, c, value);
138 flang = get_frame_language ();
139 if (flang != language_unknown &&
140 language_mode == language_mode_manual &&
141 current_language->la_language != flang)
142 printf_filtered ("%s\n", lang_frame_mismatch_warn);
145 /* Set command. Change the current working language. */
147 set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
153 if (!language || !language[0])
155 printf_unfiltered (_("\
156 The currently understood settings are:\n\n\
157 local or auto Automatic setting based on source file\n"));
159 for (i = 0; i < languages_size; ++i)
161 /* Already dealt with these above. */
162 if (languages[i]->la_language == language_unknown
163 || languages[i]->la_language == language_auto)
166 /* FIXME: i18n: for now assume that the human-readable name
167 is just a capitalization of the internal name. */
168 printf_unfiltered ("%-16s Use the %c%s language\n",
169 languages[i]->la_name,
170 /* Capitalize first letter of language
172 toupper (languages[i]->la_name[0]),
173 languages[i]->la_name + 1);
175 /* Restore the silly string. */
176 set_language (current_language->la_language);
180 /* Search the list of languages for a match. */
181 for (i = 0; i < languages_size; i++)
183 if (strcmp (languages[i]->la_name, language) == 0)
185 /* Found it! Go into manual mode, and use this language. */
186 if (languages[i]->la_language == language_auto)
188 /* Enter auto mode. Set to the current frame's language, if known. */
189 language_mode = language_mode_auto;
190 flang = get_frame_language ();
191 if (flang != language_unknown)
192 set_language (flang);
193 expected_language = current_language;
198 /* Enter manual mode. Set the specified language. */
199 language_mode = language_mode_manual;
200 current_language = languages[i];
201 set_type_range_case ();
203 expected_language = current_language;
209 /* Reset the language (esp. the global string "language") to the
211 err_lang = savestring (language, strlen (language));
212 make_cleanup (xfree, err_lang); /* Free it after error */
213 set_language (current_language->la_language);
214 error (_("Unknown language `%s'."), err_lang);
217 /* Show command. Display a warning if the type setting does
218 not match the current language. */
220 show_type_command (struct ui_file *file, int from_tty,
221 struct cmd_list_element *c, const char *value)
223 deprecated_show_value_hack (file, from_tty, c, value);
224 if (type_check != current_language->la_type_check)
226 "Warning: the current type check setting does not match the language.\n");
229 /* Set command. Change the setting for type checking. */
231 set_type_command (char *ignore, int from_tty, struct cmd_list_element *c)
233 if (strcmp (type, "on") == 0)
235 type_check = type_check_on;
236 type_mode = type_mode_manual;
238 else if (strcmp (type, "warn") == 0)
240 type_check = type_check_warn;
241 type_mode = type_mode_manual;
243 else if (strcmp (type, "off") == 0)
245 type_check = type_check_off;
246 type_mode = type_mode_manual;
248 else if (strcmp (type, "auto") == 0)
250 type_mode = type_mode_auto;
251 set_type_range_case ();
252 /* Avoid hitting the set_type_str call below. We
253 did it in set_type_range_case. */
258 warning (_("Unrecognized type check setting: \"%s\""), type);
261 show_type_command (NULL, from_tty, NULL, NULL);
264 /* Show command. Display a warning if the range setting does
265 not match the current language. */
267 show_range_command (struct ui_file *file, int from_tty,
268 struct cmd_list_element *c, const char *value)
270 deprecated_show_value_hack (file, from_tty, c, value);
271 if (range_check != current_language->la_range_check)
273 "Warning: the current range check setting does not match the language.\n");
276 /* Set command. Change the setting for range checking. */
278 set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
280 if (strcmp (range, "on") == 0)
282 range_check = range_check_on;
283 range_mode = range_mode_manual;
285 else if (strcmp (range, "warn") == 0)
287 range_check = range_check_warn;
288 range_mode = range_mode_manual;
290 else if (strcmp (range, "off") == 0)
292 range_check = range_check_off;
293 range_mode = range_mode_manual;
295 else if (strcmp (range, "auto") == 0)
297 range_mode = range_mode_auto;
298 set_type_range_case ();
299 /* Avoid hitting the set_range_str call below. We
300 did it in set_type_range_case. */
305 warning (_("Unrecognized range check setting: \"%s\""), range);
308 show_range_command (NULL, from_tty, NULL, NULL);
311 /* Show command. Display a warning if the case sensitivity setting does
312 not match the current language. */
314 show_case_command (struct ui_file *file, int from_tty,
315 struct cmd_list_element *c, const char *value)
317 deprecated_show_value_hack (file, from_tty, c, value);
318 if (case_sensitivity != current_language->la_case_sensitivity)
320 "Warning: the current case sensitivity setting does not match the language.\n");
323 /* Set command. Change the setting for case sensitivity. */
326 set_case_command (char *ignore, int from_tty, struct cmd_list_element *c)
328 if (strcmp (case_sensitive, "on") == 0)
330 case_sensitivity = case_sensitive_on;
331 case_mode = case_mode_manual;
333 else if (strcmp (case_sensitive, "off") == 0)
335 case_sensitivity = case_sensitive_off;
336 case_mode = case_mode_manual;
338 else if (strcmp (case_sensitive, "auto") == 0)
340 case_mode = case_mode_auto;
341 set_type_range_case ();
342 /* Avoid hitting the set_case_str call below. We did it in
343 set_type_range_case. */
348 warning (_("Unrecognized case-sensitive setting: \"%s\""),
352 show_case_command (NULL, from_tty, NULL, NULL);
355 /* Set the status of range and type checking and case sensitivity based on
356 the current modes and the current language.
357 If SHOW is non-zero, then print out the current language,
358 type and range checking status. */
360 set_type_range_case (void)
363 if (range_mode == range_mode_auto)
364 range_check = current_language->la_range_check;
366 if (type_mode == type_mode_auto)
367 type_check = current_language->la_type_check;
369 if (case_mode == case_mode_auto)
370 case_sensitivity = current_language->la_case_sensitivity;
377 /* Set current language to (enum language) LANG. Returns previous language. */
380 set_language (enum language lang)
383 enum language prev_language;
385 prev_language = current_language->la_language;
387 for (i = 0; i < languages_size; i++)
389 if (languages[i]->la_language == lang)
391 current_language = languages[i];
392 set_type_range_case ();
398 return prev_language;
401 /* This page contains functions that update the global vars
402 language, type and range. */
410 if (language_mode == language_mode_auto)
411 prefix = "auto; currently ";
413 language = concat (prefix, current_language->la_name, (char *)NULL);
419 char *tmp = NULL, *prefix = "";
423 if (type_mode == type_mode_auto)
424 prefix = "auto; currently ";
434 case type_check_warn:
438 error (_("Unrecognized type check setting."));
441 type = concat (prefix, tmp, (char *)NULL);
447 char *tmp, *pref = "";
449 if (range_mode == range_mode_auto)
450 pref = "auto; currently ";
457 case range_check_off:
460 case range_check_warn:
464 error (_("Unrecognized range check setting."));
469 range = concat (pref, tmp, (char *)NULL);
475 char *tmp = NULL, *prefix = "";
477 if (case_mode==case_mode_auto)
478 prefix = "auto; currently ";
480 switch (case_sensitivity)
482 case case_sensitive_on:
485 case case_sensitive_off:
489 error (_("Unrecognized case-sensitive setting."));
492 xfree (case_sensitive);
493 case_sensitive = concat (prefix, tmp, (char *)NULL);
496 /* Print out the current language settings: language, range and
497 type checking. If QUIETLY, print only what has changed. */
500 language_info (int quietly)
502 if (quietly && expected_language == current_language)
505 expected_language = current_language;
506 printf_unfiltered (_("Current language: %s\n"), language);
507 show_language_command (NULL, 1, NULL, NULL);
511 printf_unfiltered (_("Type checking: %s\n"), type);
512 show_type_command (NULL, 1, NULL, NULL);
513 printf_unfiltered (_("Range checking: %s\n"), range);
514 show_range_command (NULL, 1, NULL, NULL);
515 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
516 show_case_command (NULL, 1, NULL, NULL);
520 /* Return the result of a binary operation. */
522 #if 0 /* Currently unused */
525 binop_result_type (struct value *v1, struct value *v2)
528 struct type *t1 = check_typedef (VALUE_TYPE (v1));
529 struct type *t2 = check_typedef (VALUE_TYPE (v2));
531 int l1 = TYPE_LENGTH (t1);
532 int l2 = TYPE_LENGTH (t2);
534 switch (current_language->la_language)
539 if (TYPE_CODE (t1) == TYPE_CODE_FLT)
540 return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ?
541 VALUE_TYPE (v2) : VALUE_TYPE (v1);
542 else if (TYPE_CODE (t2) == TYPE_CODE_FLT)
543 return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ?
544 VALUE_TYPE (v1) : VALUE_TYPE (v2);
545 else if (TYPE_UNSIGNED (t1) && l1 > l2)
546 return VALUE_TYPE (v1);
547 else if (TYPE_UNSIGNED (t2) && l2 > l1)
548 return VALUE_TYPE (v2);
549 else /* Both are signed. Result is the longer type */
550 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
553 /* If we are doing type-checking, l1 should equal l2, so this is
555 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
558 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
559 return (struct type *) 0; /* For lint */
564 /* This page contains functions that are used in type/range checking.
565 They all return zero if the type/range check fails.
567 It is hoped that these will make extending GDB to parse different
568 languages a little easier. These are primarily used in eval.c when
569 evaluating expressions and making sure that their types are correct.
570 Instead of having a mess of conjucted/disjuncted expressions in an "if",
571 the ideas of type can be wrapped up in the following functions.
573 Note that some of them are not currently dependent upon which language
574 is currently being parsed. For example, floats are the same in
575 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
576 TYPE_CODE_FLT), while booleans are different. */
578 /* Returns non-zero if its argument is a simple type. This is the same for
579 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
580 and thus will never cause the failure of the test. */
582 simple_type (struct type *type)
584 CHECK_TYPEDEF (type);
585 switch (TYPE_CODE (type))
591 case TYPE_CODE_RANGE:
600 /* Returns non-zero if its argument is of an ordered type.
601 An ordered type is one in which the elements can be tested for the
602 properties of "greater than", "less than", etc, or for which the
603 operations "increment" or "decrement" make sense. */
605 ordered_type (struct type *type)
607 CHECK_TYPEDEF (type);
608 switch (TYPE_CODE (type))
614 case TYPE_CODE_RANGE:
622 /* Returns non-zero if the two types are the same */
624 same_type (struct type *arg1, struct type *arg2)
626 CHECK_TYPEDEF (type);
627 if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2))
628 /* One is structured and one isn't */
630 else if (structured_type (arg1) && structured_type (arg2))
632 else if (numeric_type (arg1) && numeric_type (arg2))
633 return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) &&
634 (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2))
640 /* Returns non-zero if the type is integral */
642 integral_type (struct type *type)
644 CHECK_TYPEDEF (type);
645 switch (current_language->la_language)
650 return (TYPE_CODE (type) != TYPE_CODE_INT) &&
651 (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
653 case language_pascal:
654 return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1;
656 error (_("Language not supported."));
660 /* Returns non-zero if the value is numeric */
662 numeric_type (struct type *type)
664 CHECK_TYPEDEF (type);
665 switch (TYPE_CODE (type))
676 /* Returns non-zero if the value is a character type */
678 character_type (struct type *type)
680 CHECK_TYPEDEF (type);
681 switch (current_language->la_language)
684 case language_pascal:
685 return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1;
690 return (TYPE_CODE (type) == TYPE_CODE_INT) &&
691 TYPE_LENGTH (type) == sizeof (char)
698 /* Returns non-zero if the value is a string type */
700 string_type (struct type *type)
702 CHECK_TYPEDEF (type);
703 switch (current_language->la_language)
706 case language_pascal:
707 return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1;
712 /* C does not have distinct string type. */
719 /* Returns non-zero if the value is a boolean type */
721 boolean_type (struct type *type)
723 CHECK_TYPEDEF (type);
724 if (TYPE_CODE (type) == TYPE_CODE_BOOL)
726 switch (current_language->la_language)
731 /* Might be more cleanly handled by having a
732 TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
733 languages, or a TYPE_CODE_INT_OR_BOOL for C. */
734 if (TYPE_CODE (type) == TYPE_CODE_INT)
742 /* Returns non-zero if the value is a floating-point type */
744 float_type (struct type *type)
746 CHECK_TYPEDEF (type);
747 return TYPE_CODE (type) == TYPE_CODE_FLT;
750 /* Returns non-zero if the value is a pointer type */
752 pointer_type (struct type *type)
754 return TYPE_CODE (type) == TYPE_CODE_PTR ||
755 TYPE_CODE (type) == TYPE_CODE_REF;
758 /* Returns non-zero if the value is a structured type */
760 structured_type (struct type *type)
762 CHECK_TYPEDEF (type);
763 switch (current_language->la_language)
768 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
769 (TYPE_CODE (type) == TYPE_CODE_UNION) ||
770 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
771 case language_pascal:
772 return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
773 (TYPE_CODE(type) == TYPE_CODE_UNION) ||
774 (TYPE_CODE(type) == TYPE_CODE_SET) ||
775 (TYPE_CODE(type) == TYPE_CODE_ARRAY);
777 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
778 (TYPE_CODE (type) == TYPE_CODE_SET) ||
779 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
787 lang_bool_type (void)
791 switch (current_language->la_language)
793 case language_fortran:
794 sym = lookup_symbol ("logical", NULL, VAR_DOMAIN, NULL, NULL);
797 type = SYMBOL_TYPE (sym);
798 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
801 return builtin_type_f_logical_s2;
803 case language_pascal:
804 if (current_language->la_language==language_cplus)
805 {sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);}
807 {sym = lookup_symbol ("boolean", NULL, VAR_DOMAIN, NULL, NULL);}
810 type = SYMBOL_TYPE (sym);
811 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
814 return builtin_type_bool;
816 sym = lookup_symbol ("boolean", NULL, VAR_DOMAIN, NULL, NULL);
819 type = SYMBOL_TYPE (sym);
820 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
823 return java_boolean_type;
825 return builtin_type_int;
829 /* This page contains functions that return info about
830 (struct value) values used in GDB. */
832 /* Returns non-zero if the value VAL represents a true value. */
834 value_true (struct value *val)
836 /* It is possible that we should have some sort of error if a non-boolean
837 value is used in this context. Possibly dependent on some kind of
838 "boolean-checking" option like range checking. But it should probably
839 not depend on the language except insofar as is necessary to identify
840 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
841 should be an error, probably). */
842 return !value_logical_not (val);
845 /* This page contains functions for the printing out of
846 error messages that occur during type- and range-
849 /* These are called when a language fails a type- or range-check. The
850 first argument should be a printf()-style format string, and the
851 rest of the arguments should be its arguments. If
852 [type|range]_check is [type|range]_check_on, an error is printed;
853 if [type|range]_check_warn, a warning; otherwise just the
857 type_error (const char *string,...)
860 va_start (args, string);
864 case type_check_warn:
865 vwarning (string, args);
868 verror (string, args);
871 /* FIXME: cagney/2002-01-30: Should this function print anything
872 when type error is off? */
873 vfprintf_filtered (gdb_stderr, string, args);
874 fprintf_filtered (gdb_stderr, "\n");
877 internal_error (__FILE__, __LINE__, _("bad switch"));
883 range_error (const char *string,...)
886 va_start (args, string);
890 case range_check_warn:
891 vwarning (string, args);
894 verror (string, args);
896 case range_check_off:
897 /* FIXME: cagney/2002-01-30: Should this function print anything
898 when range error is off? */
899 vfprintf_filtered (gdb_stderr, string, args);
900 fprintf_filtered (gdb_stderr, "\n");
903 internal_error (__FILE__, __LINE__, _("bad switch"));
909 /* This page contains miscellaneous functions */
911 /* Return the language enum for a given language string. */
914 language_enum (char *str)
918 for (i = 0; i < languages_size; i++)
919 if (strcmp (languages[i]->la_name, str) == 0)
920 return languages[i]->la_language;
922 return language_unknown;
925 /* Return the language struct for a given language enum. */
927 const struct language_defn *
928 language_def (enum language lang)
932 for (i = 0; i < languages_size; i++)
934 if (languages[i]->la_language == lang)
942 /* Return the language as a string */
944 language_str (enum language lang)
948 for (i = 0; i < languages_size; i++)
950 if (languages[i]->la_language == lang)
952 return languages[i]->la_name;
959 set_check (char *ignore, int from_tty)
962 "\"set check\" must be followed by the name of a check subcommand.\n");
963 help_list (setchecklist, "set check ", -1, gdb_stdout);
967 show_check (char *ignore, int from_tty)
969 cmd_show_list (showchecklist, from_tty, "");
972 /* Add a language to the set of known languages. */
975 add_language (const struct language_defn *lang)
977 if (lang->la_magic != LANG_MAGIC)
979 fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n",
981 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
986 languages_allocsize = DEFAULT_ALLOCSIZE;
987 languages = (const struct language_defn **) xmalloc
988 (languages_allocsize * sizeof (*languages));
990 if (languages_size >= languages_allocsize)
992 languages_allocsize *= 2;
993 languages = (const struct language_defn **) xrealloc ((char *) languages,
994 languages_allocsize * sizeof (*languages));
996 languages[languages_size++] = lang;
999 /* Iterate through all registered languages looking for and calling
1000 any non-NULL struct language_defn.skip_trampoline() functions.
1001 Return the result from the first that returns non-zero, or 0 if all
1004 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
1008 for (i = 0; i < languages_size; i++)
1010 if (languages[i]->skip_trampoline)
1012 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc);
1021 /* Return demangled language symbol, or NULL.
1022 FIXME: Options are only useful for certain languages and ignored
1023 by others, so it would be better to remove them here and have a
1024 more flexible demangler for the languages that need it.
1025 FIXME: Sometimes the demangler is invoked when we don't know the
1026 language, so we can't use this everywhere. */
1028 language_demangle (const struct language_defn *current_language,
1029 const char *mangled, int options)
1031 if (current_language != NULL && current_language->la_demangle)
1032 return current_language->la_demangle (mangled, options);
1036 /* Return class name from physname or NULL. */
1038 language_class_name_from_physname (const struct language_defn *current_language,
1039 const char *physname)
1041 if (current_language != NULL && current_language->la_class_name_from_physname)
1042 return current_language->la_class_name_from_physname (physname);
1046 /* Return non-zero if TYPE should be passed (and returned) by
1047 reference at the language level. */
1049 language_pass_by_reference (struct type *type)
1051 return current_language->la_pass_by_reference (type);
1054 /* Return zero; by default, types are passed by value at the language
1055 level. The target ABI may pass or return some structs by reference
1056 independent of this. */
1058 default_pass_by_reference (struct type *type)
1063 /* Return the default string containing the list of characters
1064 delimiting words. This is a reasonable default value that
1065 most languages should be able to use. */
1068 default_word_break_characters (void)
1070 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1073 /* Print the index of array elements using the C99 syntax. */
1076 default_print_array_index (struct value *index_value, struct ui_file *stream,
1077 int format, enum val_prettyprint pretty)
1079 fprintf_filtered (stream, "[");
1080 LA_VALUE_PRINT (index_value, stream, format, pretty);
1081 fprintf_filtered (stream, "] = ");
1084 /* Define the language that is no language. */
1087 unk_lang_parser (void)
1093 unk_lang_error (char *msg)
1095 error (_("Attempted to parse an expression with unknown language"));
1099 unk_lang_emit_char (int c, struct ui_file *stream, int quoter)
1101 error (_("internal error - unimplemented function unk_lang_emit_char called."));
1105 unk_lang_printchar (int c, struct ui_file *stream)
1107 error (_("internal error - unimplemented function unk_lang_printchar called."));
1111 unk_lang_printstr (struct ui_file *stream, const gdb_byte *string,
1112 unsigned int length, int width, int force_ellipses)
1114 error (_("internal error - unimplemented function unk_lang_printstr called."));
1118 unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream,
1119 int show, int level)
1121 error (_("internal error - unimplemented function unk_lang_print_type called."));
1125 unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
1126 int embedded_offset, CORE_ADDR address,
1127 struct ui_file *stream, int format,
1128 int deref_ref, int recurse, enum val_prettyprint pretty)
1130 error (_("internal error - unimplemented function unk_lang_val_print called."));
1134 unk_lang_value_print (struct value *val, struct ui_file *stream, int format,
1135 enum val_prettyprint pretty)
1137 error (_("internal error - unimplemented function unk_lang_value_print called."));
1140 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
1145 /* Unknown languages just use the cplus demangler. */
1146 static char *unk_lang_demangle (const char *mangled, int options)
1148 return cplus_demangle (mangled, options);
1151 static char *unk_lang_class_name (const char *mangled)
1156 static const struct op_print unk_op_print_tab[] =
1158 {NULL, OP_NULL, PREC_NULL, 0}
1162 unknown_language_arch_info (struct gdbarch *gdbarch,
1163 struct language_arch_info *lai)
1165 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
1166 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
1170 const struct language_defn unknown_language_defn =
1178 &exp_descriptor_standard,
1182 unk_lang_printchar, /* Print character constant */
1185 unk_lang_print_type, /* Print a type using appropriate syntax */
1186 unk_lang_val_print, /* Print a value using appropriate syntax */
1187 unk_lang_value_print, /* Print a top-level value */
1188 unk_lang_trampoline, /* Language specific skip_trampoline */
1189 value_of_this, /* value_of_this */
1190 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1191 basic_lookup_transparent_type,/* lookup_transparent_type */
1192 unk_lang_demangle, /* Language specific symbol demangler */
1193 unk_lang_class_name, /* Language specific class_name_from_physname */
1194 unk_op_print_tab, /* expression operators for printing */
1195 1, /* c-style arrays */
1196 0, /* String lower bound */
1197 default_word_break_characters,
1198 unknown_language_arch_info, /* la_language_arch_info. */
1199 default_print_array_index,
1200 default_pass_by_reference,
1204 /* These two structs define fake entries for the "local" and "auto" options. */
1205 const struct language_defn auto_language_defn =
1213 &exp_descriptor_standard,
1217 unk_lang_printchar, /* Print character constant */
1220 unk_lang_print_type, /* Print a type using appropriate syntax */
1221 unk_lang_val_print, /* Print a value using appropriate syntax */
1222 unk_lang_value_print, /* Print a top-level value */
1223 unk_lang_trampoline, /* Language specific skip_trampoline */
1224 value_of_this, /* value_of_this */
1225 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1226 basic_lookup_transparent_type,/* lookup_transparent_type */
1227 unk_lang_demangle, /* Language specific symbol demangler */
1228 unk_lang_class_name, /* Language specific class_name_from_physname */
1229 unk_op_print_tab, /* expression operators for printing */
1230 1, /* c-style arrays */
1231 0, /* String lower bound */
1232 default_word_break_characters,
1233 unknown_language_arch_info, /* la_language_arch_info. */
1234 default_print_array_index,
1235 default_pass_by_reference,
1239 const struct language_defn local_language_defn =
1247 &exp_descriptor_standard,
1251 unk_lang_printchar, /* Print character constant */
1254 unk_lang_print_type, /* Print a type using appropriate syntax */
1255 unk_lang_val_print, /* Print a value using appropriate syntax */
1256 unk_lang_value_print, /* Print a top-level value */
1257 unk_lang_trampoline, /* Language specific skip_trampoline */
1258 value_of_this, /* value_of_this */
1259 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1260 basic_lookup_transparent_type,/* lookup_transparent_type */
1261 unk_lang_demangle, /* Language specific symbol demangler */
1262 unk_lang_class_name, /* Language specific class_name_from_physname */
1263 unk_op_print_tab, /* expression operators for printing */
1264 1, /* c-style arrays */
1265 0, /* String lower bound */
1266 default_word_break_characters,
1267 unknown_language_arch_info, /* la_language_arch_info. */
1268 default_print_array_index,
1269 default_pass_by_reference,
1273 /* Per-architecture language information. */
1275 static struct gdbarch_data *language_gdbarch_data;
1277 struct language_gdbarch
1279 /* A vector of per-language per-architecture info. Indexed by "enum
1281 struct language_arch_info arch_info[nr_languages];
1285 language_gdbarch_post_init (struct gdbarch *gdbarch)
1287 struct language_gdbarch *l;
1290 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
1291 for (i = 0; i < languages_size; i++)
1293 if (languages[i] != NULL
1294 && languages[i]->la_language_arch_info != NULL)
1295 languages[i]->la_language_arch_info
1296 (gdbarch, l->arch_info + languages[i]->la_language);
1302 language_string_char_type (const struct language_defn *la,
1303 struct gdbarch *gdbarch)
1305 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1306 language_gdbarch_data);
1307 return ld->arch_info[la->la_language].string_char_type;
1311 language_lookup_primitive_type_by_name (const struct language_defn *la,
1312 struct gdbarch *gdbarch,
1315 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1316 language_gdbarch_data);
1317 struct type *const *p;
1318 for (p = ld->arch_info[la->la_language].primitive_type_vector;
1322 if (strcmp (TYPE_NAME (*p), name) == 0)
1328 /* Initialize the language routines */
1331 _initialize_language (void)
1333 struct cmd_list_element *set, *show;
1335 language_gdbarch_data
1336 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1338 /* GDB commands for language specific stuff */
1340 /* FIXME: cagney/2005-02-20: This should be implemented using an
1342 add_setshow_string_noescape_cmd ("language", class_support, &language, _("\
1343 Set the current source language."), _("\
1344 Show the current source language."), NULL,
1345 set_language_command,
1346 show_language_command,
1347 &setlist, &showlist);
1349 add_prefix_cmd ("check", no_class, set_check,
1350 _("Set the status of the type/range checker."),
1351 &setchecklist, "set check ", 0, &setlist);
1352 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1353 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1355 add_prefix_cmd ("check", no_class, show_check,
1356 _("Show the status of the type/range checker."),
1357 &showchecklist, "show check ", 0, &showlist);
1358 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1359 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1361 /* FIXME: cagney/2005-02-20: This should be implemented using an
1363 add_setshow_string_noescape_cmd ("type", class_support, &type, _("\
1364 Set type checking. (on/warn/off/auto)"), _("\
1365 Show type checking. (on/warn/off/auto)"), NULL,
1368 &setchecklist, &showchecklist);
1370 /* FIXME: cagney/2005-02-20: This should be implemented using an
1372 add_setshow_string_noescape_cmd ("range", class_support, &range, _("\
1373 Set range checking. (on/warn/off/auto)"), _("\
1374 Show range checking. (on/warn/off/auto)"), NULL,
1377 &setchecklist, &showchecklist);
1379 /* FIXME: cagney/2005-02-20: This should be implemented using an
1381 add_setshow_string_noescape_cmd ("case-sensitive", class_support,
1382 &case_sensitive, _("\
1383 Set case sensitivity in name search. (on/off/auto)"), _("\
1384 Show case sensitivity in name search. (on/off/auto)"), _("\
1385 For Fortran the default is off; for other languages the default is on."),
1388 &setlist, &showlist);
1390 add_language (&unknown_language_defn);
1391 add_language (&local_language_defn);
1392 add_language (&auto_language_defn);
1394 language = savestring ("auto", strlen ("auto"));
1395 type = savestring ("auto", strlen ("auto"));
1396 range = savestring ("auto", strlen ("auto"));
1397 case_sensitive = savestring ("auto",strlen ("auto"));
1399 /* Have the above take effect */
1400 set_language (language_auto);