1 /* Multiple source language support for GDB.
3 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
4 2001, 2002, 2003, 2004, 2005 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 2 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, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
26 /* This file contains functions that return things that are specific
27 to languages. Each function should examine current_language if necessary,
28 and return the appropriate result. */
30 /* FIXME: Most of these would be better organized as macros which
31 return data out of a "language-specific" struct pointer that is set
32 whenever the working language changes. That would be a lot faster. */
36 #include "gdb_string.h"
42 #include "expression.h"
45 #include "parser-defs.h"
49 extern void _initialize_language (void);
51 static void show_language_command (char *, int);
53 static void set_language_command (char *, int);
55 static void show_type_command (char *, int);
57 static void set_type_command (char *, int);
59 static void show_range_command (char *, int);
61 static void set_range_command (char *, int);
63 static void show_case_command (char *, int);
65 static void set_case_command (char *, int);
67 static void set_case_str (void);
69 static void set_range_str (void);
71 static void set_type_str (void);
73 static void set_lang_str (void);
75 static void unk_lang_error (char *);
77 static int unk_lang_parser (void);
79 static void show_check (char *, int);
81 static void set_check (char *, int);
83 static void set_type_range_case (void);
85 static void unk_lang_emit_char (int c, struct ui_file *stream, int quoter);
87 static void unk_lang_printchar (int c, struct ui_file *stream);
89 static struct type *unk_lang_create_fundamental_type (struct objfile *, int);
91 static void unk_lang_print_type (struct type *, char *, struct ui_file *,
94 static int unk_lang_value_print (struct value *, struct ui_file *, int, enum val_prettyprint);
96 static CORE_ADDR unk_lang_trampoline (CORE_ADDR pc);
98 /* Forward declaration */
99 extern const struct language_defn unknown_language_defn;
101 /* The current (default at startup) state of type and range checking.
102 (If the modes are set to "auto", though, these are changed based
103 on the default language at startup, and then again based on the
104 language of the first source file. */
106 enum range_mode range_mode = range_mode_auto;
107 enum range_check range_check = range_check_off;
108 enum type_mode type_mode = type_mode_auto;
109 enum type_check type_check = type_check_off;
110 enum case_mode case_mode = case_mode_auto;
111 enum case_sensitivity case_sensitivity = case_sensitive_on;
113 /* The current language and language_mode (see language.h) */
115 const struct language_defn *current_language = &unknown_language_defn;
116 enum language_mode language_mode = language_mode_auto;
118 /* The language that the user expects to be typing in (the language
119 of main(), or the last language we notified them about, or C). */
121 const struct language_defn *expected_language;
123 /* The list of supported languages. The list itself is malloc'd. */
125 static const struct language_defn **languages;
126 static unsigned languages_size;
127 static unsigned languages_allocsize;
128 #define DEFAULT_ALLOCSIZE 4
130 /* The "set language/type/range" commands all put stuff in these
131 buffers. This is to make them work as set/show commands. The
132 user's string is copied here, then the set_* commands look at
133 them and update them to something that looks nice when it is
136 static char *language;
139 static char *case_sensitive;
141 /* Warning issued when current_language and the language of the current
142 frame do not match. */
143 char lang_frame_mismatch_warn[] =
144 "Warning: the current language does not match this frame.";
146 /* This page contains the functions corresponding to GDB commands
147 and their helpers. */
149 /* Show command. Display a warning if the language set
150 does not match the frame. */
152 show_language_command (char *ignore, int from_tty)
154 enum language flang; /* The language of the current frame */
156 flang = get_frame_language ();
157 if (flang != language_unknown &&
158 language_mode == language_mode_manual &&
159 current_language->la_language != flang)
160 printf_filtered ("%s\n", lang_frame_mismatch_warn);
163 /* Set command. Change the current working language. */
165 set_language_command (char *ignore, int from_tty)
171 if (!language || !language[0])
173 printf_unfiltered (_("\
174 The currently understood settings are:\n\n\
175 local or auto Automatic setting based on source file\n"));
177 for (i = 0; i < languages_size; ++i)
179 /* Already dealt with these above. */
180 if (languages[i]->la_language == language_unknown
181 || languages[i]->la_language == language_auto)
184 /* FIXME: i18n: for now assume that the human-readable name
185 is just a capitalization of the internal name. */
186 printf_unfiltered ("%-16s Use the %c%s language\n",
187 languages[i]->la_name,
188 /* Capitalize first letter of language
190 toupper (languages[i]->la_name[0]),
191 languages[i]->la_name + 1);
193 /* Restore the silly string. */
194 set_language (current_language->la_language);
198 /* Search the list of languages for a match. */
199 for (i = 0; i < languages_size; i++)
201 if (strcmp (languages[i]->la_name, language) == 0)
203 /* Found it! Go into manual mode, and use this language. */
204 if (languages[i]->la_language == language_auto)
206 /* Enter auto mode. Set to the current frame's language, if known. */
207 language_mode = language_mode_auto;
208 flang = get_frame_language ();
209 if (flang != language_unknown)
210 set_language (flang);
211 expected_language = current_language;
216 /* Enter manual mode. Set the specified language. */
217 language_mode = language_mode_manual;
218 current_language = languages[i];
219 set_type_range_case ();
221 expected_language = current_language;
227 /* Reset the language (esp. the global string "language") to the
229 err_lang = savestring (language, strlen (language));
230 make_cleanup (xfree, err_lang); /* Free it after error */
231 set_language (current_language->la_language);
232 error (_("Unknown language `%s'."), err_lang);
235 /* Show command. Display a warning if the type setting does
236 not match the current language. */
238 show_type_command (char *ignore, int from_tty)
240 if (type_check != current_language->la_type_check)
242 "Warning: the current type check setting does not match the language.\n");
245 /* Set command. Change the setting for type checking. */
247 set_type_command (char *ignore, int from_tty)
249 if (strcmp (type, "on") == 0)
251 type_check = type_check_on;
252 type_mode = type_mode_manual;
254 else if (strcmp (type, "warn") == 0)
256 type_check = type_check_warn;
257 type_mode = type_mode_manual;
259 else if (strcmp (type, "off") == 0)
261 type_check = type_check_off;
262 type_mode = type_mode_manual;
264 else if (strcmp (type, "auto") == 0)
266 type_mode = type_mode_auto;
267 set_type_range_case ();
268 /* Avoid hitting the set_type_str call below. We
269 did it in set_type_range_case. */
274 warning (_("Unrecognized type check setting: \"%s\""), type);
277 show_type_command ((char *) NULL, from_tty);
280 /* Show command. Display a warning if the range setting does
281 not match the current language. */
283 show_range_command (char *ignore, int from_tty)
286 if (range_check != current_language->la_range_check)
288 "Warning: the current range check setting does not match the language.\n");
291 /* Set command. Change the setting for range checking. */
293 set_range_command (char *ignore, int from_tty)
295 if (strcmp (range, "on") == 0)
297 range_check = range_check_on;
298 range_mode = range_mode_manual;
300 else if (strcmp (range, "warn") == 0)
302 range_check = range_check_warn;
303 range_mode = range_mode_manual;
305 else if (strcmp (range, "off") == 0)
307 range_check = range_check_off;
308 range_mode = range_mode_manual;
310 else if (strcmp (range, "auto") == 0)
312 range_mode = range_mode_auto;
313 set_type_range_case ();
314 /* Avoid hitting the set_range_str call below. We
315 did it in set_type_range_case. */
320 warning (_("Unrecognized range check setting: \"%s\""), range);
323 show_range_command ((char *) 0, from_tty);
326 /* Show command. Display a warning if the case sensitivity setting does
327 not match the current language. */
329 show_case_command (char *ignore, int from_tty)
331 if (case_sensitivity != current_language->la_case_sensitivity)
333 "Warning: the current case sensitivity setting does not match the language.\n");
336 /* Set command. Change the setting for case sensitivity. */
338 set_case_command (char *ignore, int from_tty)
340 if (DEPRECATED_STREQ (case_sensitive, "on"))
342 case_sensitivity = case_sensitive_on;
343 case_mode = case_mode_manual;
345 else if (DEPRECATED_STREQ (case_sensitive, "off"))
347 case_sensitivity = case_sensitive_off;
348 case_mode = case_mode_manual;
350 else if (DEPRECATED_STREQ (case_sensitive, "auto"))
352 case_mode = case_mode_auto;
353 set_type_range_case ();
354 /* Avoid hitting the set_case_str call below. We
355 did it in set_type_range_case. */
360 warning (_("Unrecognized case-sensitive setting: \"%s\""), case_sensitive);
363 show_case_command ((char *) NULL, from_tty);
366 /* Set the status of range and type checking and case sensitivity based on
367 the current modes and the current language.
368 If SHOW is non-zero, then print out the current language,
369 type and range checking status. */
371 set_type_range_case (void)
374 if (range_mode == range_mode_auto)
375 range_check = current_language->la_range_check;
377 if (type_mode == type_mode_auto)
378 type_check = current_language->la_type_check;
380 if (case_mode == case_mode_auto)
381 case_sensitivity = current_language->la_case_sensitivity;
388 /* Set current language to (enum language) LANG. Returns previous language. */
391 set_language (enum language lang)
394 enum language prev_language;
396 prev_language = current_language->la_language;
398 for (i = 0; i < languages_size; i++)
400 if (languages[i]->la_language == lang)
402 current_language = languages[i];
403 set_type_range_case ();
409 return prev_language;
412 /* This page contains functions that update the global vars
413 language, type and range. */
421 if (language_mode == language_mode_auto)
422 prefix = "auto; currently ";
424 language = concat (prefix, current_language->la_name, NULL);
430 char *tmp = NULL, *prefix = "";
434 if (type_mode == type_mode_auto)
435 prefix = "auto; currently ";
445 case type_check_warn:
449 error (_("Unrecognized type check setting."));
452 type = concat (prefix, tmp, NULL);
458 char *tmp, *pref = "";
460 if (range_mode == range_mode_auto)
461 pref = "auto; currently ";
468 case range_check_off:
471 case range_check_warn:
475 error (_("Unrecognized range check setting."));
480 range = concat (pref, tmp, NULL);
486 char *tmp = NULL, *prefix = "";
488 if (case_mode==case_mode_auto)
489 prefix = "auto; currently ";
491 switch (case_sensitivity)
493 case case_sensitive_on:
496 case case_sensitive_off:
500 error (_("Unrecognized case-sensitive setting."));
503 xfree (case_sensitive);
504 case_sensitive = concat (prefix, tmp, NULL);
507 /* Print out the current language settings: language, range and
508 type checking. If QUIETLY, print only what has changed. */
511 language_info (int quietly)
513 if (quietly && expected_language == current_language)
516 expected_language = current_language;
517 printf_unfiltered (_("Current language: %s\n"), language);
518 show_language_command ((char *) 0, 1);
522 printf_unfiltered (_("Type checking: %s\n"), type);
523 show_type_command ((char *) 0, 1);
524 printf_unfiltered (_("Range checking: %s\n"), range);
525 show_range_command ((char *) 0, 1);
526 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
527 show_case_command ((char *) 0, 1);
531 /* Return the result of a binary operation. */
533 #if 0 /* Currently unused */
536 binop_result_type (struct value *v1, struct value *v2)
539 struct type *t1 = check_typedef (VALUE_TYPE (v1));
540 struct type *t2 = check_typedef (VALUE_TYPE (v2));
542 int l1 = TYPE_LENGTH (t1);
543 int l2 = TYPE_LENGTH (t2);
545 switch (current_language->la_language)
550 if (TYPE_CODE (t1) == TYPE_CODE_FLT)
551 return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ?
552 VALUE_TYPE (v2) : VALUE_TYPE (v1);
553 else if (TYPE_CODE (t2) == TYPE_CODE_FLT)
554 return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ?
555 VALUE_TYPE (v1) : VALUE_TYPE (v2);
556 else if (TYPE_UNSIGNED (t1) && l1 > l2)
557 return VALUE_TYPE (v1);
558 else if (TYPE_UNSIGNED (t2) && l2 > l1)
559 return VALUE_TYPE (v2);
560 else /* Both are signed. Result is the longer type */
561 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
564 /* If we are doing type-checking, l1 should equal l2, so this is
566 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
569 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
570 return (struct type *) 0; /* For lint */
575 /* This page contains functions that are used in type/range checking.
576 They all return zero if the type/range check fails.
578 It is hoped that these will make extending GDB to parse different
579 languages a little easier. These are primarily used in eval.c when
580 evaluating expressions and making sure that their types are correct.
581 Instead of having a mess of conjucted/disjuncted expressions in an "if",
582 the ideas of type can be wrapped up in the following functions.
584 Note that some of them are not currently dependent upon which language
585 is currently being parsed. For example, floats are the same in
586 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
587 TYPE_CODE_FLT), while booleans are different. */
589 /* Returns non-zero if its argument is a simple type. This is the same for
590 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
591 and thus will never cause the failure of the test. */
593 simple_type (struct type *type)
595 CHECK_TYPEDEF (type);
596 switch (TYPE_CODE (type))
602 case TYPE_CODE_RANGE:
611 /* Returns non-zero if its argument is of an ordered type.
612 An ordered type is one in which the elements can be tested for the
613 properties of "greater than", "less than", etc, or for which the
614 operations "increment" or "decrement" make sense. */
616 ordered_type (struct type *type)
618 CHECK_TYPEDEF (type);
619 switch (TYPE_CODE (type))
625 case TYPE_CODE_RANGE:
633 /* Returns non-zero if the two types are the same */
635 same_type (struct type *arg1, struct type *arg2)
637 CHECK_TYPEDEF (type);
638 if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2))
639 /* One is structured and one isn't */
641 else if (structured_type (arg1) && structured_type (arg2))
643 else if (numeric_type (arg1) && numeric_type (arg2))
644 return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) &&
645 (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2))
651 /* Returns non-zero if the type is integral */
653 integral_type (struct type *type)
655 CHECK_TYPEDEF (type);
656 switch (current_language->la_language)
661 return (TYPE_CODE (type) != TYPE_CODE_INT) &&
662 (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
664 case language_pascal:
665 return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1;
667 error (_("Language not supported."));
671 /* Returns non-zero if the value is numeric */
673 numeric_type (struct type *type)
675 CHECK_TYPEDEF (type);
676 switch (TYPE_CODE (type))
687 /* Returns non-zero if the value is a character type */
689 character_type (struct type *type)
691 CHECK_TYPEDEF (type);
692 switch (current_language->la_language)
695 case language_pascal:
696 return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1;
701 return (TYPE_CODE (type) == TYPE_CODE_INT) &&
702 TYPE_LENGTH (type) == sizeof (char)
709 /* Returns non-zero if the value is a string type */
711 string_type (struct type *type)
713 CHECK_TYPEDEF (type);
714 switch (current_language->la_language)
717 case language_pascal:
718 return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1;
723 /* C does not have distinct string type. */
730 /* Returns non-zero if the value is a boolean type */
732 boolean_type (struct type *type)
734 CHECK_TYPEDEF (type);
735 if (TYPE_CODE (type) == TYPE_CODE_BOOL)
737 switch (current_language->la_language)
742 /* Might be more cleanly handled by having a
743 TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
744 languages, or a TYPE_CODE_INT_OR_BOOL for C. */
745 if (TYPE_CODE (type) == TYPE_CODE_INT)
753 /* Returns non-zero if the value is a floating-point type */
755 float_type (struct type *type)
757 CHECK_TYPEDEF (type);
758 return TYPE_CODE (type) == TYPE_CODE_FLT;
761 /* Returns non-zero if the value is a pointer type */
763 pointer_type (struct type *type)
765 return TYPE_CODE (type) == TYPE_CODE_PTR ||
766 TYPE_CODE (type) == TYPE_CODE_REF;
769 /* Returns non-zero if the value is a structured type */
771 structured_type (struct type *type)
773 CHECK_TYPEDEF (type);
774 switch (current_language->la_language)
779 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
780 (TYPE_CODE (type) == TYPE_CODE_UNION) ||
781 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
782 case language_pascal:
783 return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
784 (TYPE_CODE(type) == TYPE_CODE_UNION) ||
785 (TYPE_CODE(type) == TYPE_CODE_SET) ||
786 (TYPE_CODE(type) == TYPE_CODE_ARRAY);
788 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
789 (TYPE_CODE (type) == TYPE_CODE_SET) ||
790 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
798 lang_bool_type (void)
802 switch (current_language->la_language)
804 case language_fortran:
805 sym = lookup_symbol ("logical", NULL, VAR_DOMAIN, NULL, NULL);
808 type = SYMBOL_TYPE (sym);
809 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
812 return builtin_type_f_logical_s2;
814 case language_pascal:
815 if (current_language->la_language==language_cplus)
816 {sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);}
818 {sym = lookup_symbol ("boolean", NULL, VAR_DOMAIN, NULL, NULL);}
821 type = SYMBOL_TYPE (sym);
822 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
825 return builtin_type_bool;
827 sym = lookup_symbol ("boolean", NULL, VAR_DOMAIN, NULL, NULL);
830 type = SYMBOL_TYPE (sym);
831 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
834 return java_boolean_type;
836 return builtin_type_int;
840 /* This page contains functions that return info about
841 (struct value) values used in GDB. */
843 /* Returns non-zero if the value VAL represents a true value. */
845 value_true (struct value *val)
847 /* It is possible that we should have some sort of error if a non-boolean
848 value is used in this context. Possibly dependent on some kind of
849 "boolean-checking" option like range checking. But it should probably
850 not depend on the language except insofar as is necessary to identify
851 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
852 should be an error, probably). */
853 return !value_logical_not (val);
856 /* This page contains functions for the printing out of
857 error messages that occur during type- and range-
860 /* These are called when a language fails a type- or range-check. The
861 first argument should be a printf()-style format string, and the
862 rest of the arguments should be its arguments. If
863 [type|range]_check is [type|range]_check_on, an error is printed;
864 if [type|range]_check_warn, a warning; otherwise just the
868 type_error (const char *string,...)
871 va_start (args, string);
875 case type_check_warn:
876 vwarning (string, args);
879 verror (string, args);
882 /* FIXME: cagney/2002-01-30: Should this function print anything
883 when type error is off? */
884 vfprintf_filtered (gdb_stderr, string, args);
885 fprintf_filtered (gdb_stderr, "\n");
888 internal_error (__FILE__, __LINE__, _("bad switch"));
894 range_error (const char *string,...)
897 va_start (args, string);
901 case range_check_warn:
902 vwarning (string, args);
905 verror (string, args);
907 case range_check_off:
908 /* FIXME: cagney/2002-01-30: Should this function print anything
909 when range error is off? */
910 vfprintf_filtered (gdb_stderr, string, args);
911 fprintf_filtered (gdb_stderr, "\n");
914 internal_error (__FILE__, __LINE__, _("bad switch"));
920 /* This page contains miscellaneous functions */
922 /* Return the language enum for a given language string. */
925 language_enum (char *str)
929 for (i = 0; i < languages_size; i++)
930 if (DEPRECATED_STREQ (languages[i]->la_name, str))
931 return languages[i]->la_language;
933 return language_unknown;
936 /* Return the language struct for a given language enum. */
938 const struct language_defn *
939 language_def (enum language lang)
943 for (i = 0; i < languages_size; i++)
945 if (languages[i]->la_language == lang)
953 /* Return the language as a string */
955 language_str (enum language lang)
959 for (i = 0; i < languages_size; i++)
961 if (languages[i]->la_language == lang)
963 return languages[i]->la_name;
970 set_check (char *ignore, int from_tty)
973 "\"set check\" must be followed by the name of a check subcommand.\n");
974 help_list (setchecklist, "set check ", -1, gdb_stdout);
978 show_check (char *ignore, int from_tty)
980 cmd_show_list (showchecklist, from_tty, "");
983 /* Add a language to the set of known languages. */
986 add_language (const struct language_defn *lang)
988 if (lang->la_magic != LANG_MAGIC)
990 fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n",
992 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
997 languages_allocsize = DEFAULT_ALLOCSIZE;
998 languages = (const struct language_defn **) xmalloc
999 (languages_allocsize * sizeof (*languages));
1001 if (languages_size >= languages_allocsize)
1003 languages_allocsize *= 2;
1004 languages = (const struct language_defn **) xrealloc ((char *) languages,
1005 languages_allocsize * sizeof (*languages));
1007 languages[languages_size++] = lang;
1010 /* Iterate through all registered languages looking for and calling
1011 any non-NULL struct language_defn.skip_trampoline() functions.
1012 Return the result from the first that returns non-zero, or 0 if all
1015 skip_language_trampoline (CORE_ADDR pc)
1019 for (i = 0; i < languages_size; i++)
1021 if (languages[i]->skip_trampoline)
1023 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (pc);
1032 /* Return demangled language symbol, or NULL.
1033 FIXME: Options are only useful for certain languages and ignored
1034 by others, so it would be better to remove them here and have a
1035 more flexible demangler for the languages that need it.
1036 FIXME: Sometimes the demangler is invoked when we don't know the
1037 language, so we can't use this everywhere. */
1039 language_demangle (const struct language_defn *current_language,
1040 const char *mangled, int options)
1042 if (current_language != NULL && current_language->la_demangle)
1043 return current_language->la_demangle (mangled, options);
1047 /* Return class name from physname or NULL. */
1049 language_class_name_from_physname (const struct language_defn *current_language,
1050 const char *physname)
1052 if (current_language != NULL && current_language->la_class_name_from_physname)
1053 return current_language->la_class_name_from_physname (physname);
1057 /* Return the default string containing the list of characters
1058 delimiting words. This is a reasonable default value that
1059 most languages should be able to use. */
1062 default_word_break_characters (void)
1064 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1067 /* Define the language that is no language. */
1070 unk_lang_parser (void)
1076 unk_lang_error (char *msg)
1078 error (_("Attempted to parse an expression with unknown language"));
1082 unk_lang_emit_char (int c, struct ui_file *stream, int quoter)
1084 error (_("internal error - unimplemented function unk_lang_emit_char called."));
1088 unk_lang_printchar (int c, struct ui_file *stream)
1090 error (_("internal error - unimplemented function unk_lang_printchar called."));
1094 unk_lang_printstr (struct ui_file *stream, const bfd_byte *string,
1095 unsigned int length, int width, int force_ellipses)
1097 error (_("internal error - unimplemented function unk_lang_printstr called."));
1100 static struct type *
1101 unk_lang_create_fundamental_type (struct objfile *objfile, int typeid)
1103 error (_("internal error - unimplemented function unk_lang_create_fundamental_type called."));
1107 unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream,
1108 int show, int level)
1110 error (_("internal error - unimplemented function unk_lang_print_type called."));
1114 unk_lang_val_print (struct type *type, const bfd_byte *valaddr,
1115 int embedded_offset, CORE_ADDR address,
1116 struct ui_file *stream, int format,
1117 int deref_ref, int recurse, enum val_prettyprint pretty)
1119 error (_("internal error - unimplemented function unk_lang_val_print called."));
1123 unk_lang_value_print (struct value *val, struct ui_file *stream, int format,
1124 enum val_prettyprint pretty)
1126 error (_("internal error - unimplemented function unk_lang_value_print called."));
1129 static CORE_ADDR unk_lang_trampoline (CORE_ADDR pc)
1134 /* Unknown languages just use the cplus demangler. */
1135 static char *unk_lang_demangle (const char *mangled, int options)
1137 return cplus_demangle (mangled, options);
1140 static char *unk_lang_class_name (const char *mangled)
1145 static const struct op_print unk_op_print_tab[] =
1147 {NULL, OP_NULL, PREC_NULL, 0}
1151 unknown_language_arch_info (struct gdbarch *gdbarch,
1152 struct language_arch_info *lai)
1154 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
1155 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
1159 const struct language_defn unknown_language_defn =
1168 &exp_descriptor_standard,
1172 unk_lang_printchar, /* Print character constant */
1175 unk_lang_create_fundamental_type,
1176 unk_lang_print_type, /* Print a type using appropriate syntax */
1177 unk_lang_val_print, /* Print a value using appropriate syntax */
1178 unk_lang_value_print, /* Print a top-level value */
1179 unk_lang_trampoline, /* Language specific skip_trampoline */
1180 value_of_this, /* value_of_this */
1181 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1182 basic_lookup_transparent_type,/* lookup_transparent_type */
1183 unk_lang_demangle, /* Language specific symbol demangler */
1184 unk_lang_class_name, /* Language specific class_name_from_physname */
1185 unk_op_print_tab, /* expression operators for printing */
1186 1, /* c-style arrays */
1187 0, /* String lower bound */
1189 default_word_break_characters,
1190 unknown_language_arch_info, /* la_language_arch_info. */
1194 /* These two structs define fake entries for the "local" and "auto" options. */
1195 const struct language_defn auto_language_defn =
1204 &exp_descriptor_standard,
1208 unk_lang_printchar, /* Print character constant */
1211 unk_lang_create_fundamental_type,
1212 unk_lang_print_type, /* Print a type using appropriate syntax */
1213 unk_lang_val_print, /* Print a value using appropriate syntax */
1214 unk_lang_value_print, /* Print a top-level value */
1215 unk_lang_trampoline, /* Language specific skip_trampoline */
1216 value_of_this, /* value_of_this */
1217 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1218 basic_lookup_transparent_type,/* lookup_transparent_type */
1219 unk_lang_demangle, /* Language specific symbol demangler */
1220 unk_lang_class_name, /* Language specific class_name_from_physname */
1221 unk_op_print_tab, /* expression operators for printing */
1222 1, /* c-style arrays */
1223 0, /* String lower bound */
1225 default_word_break_characters,
1226 unknown_language_arch_info, /* la_language_arch_info. */
1230 const struct language_defn local_language_defn =
1239 &exp_descriptor_standard,
1243 unk_lang_printchar, /* Print character constant */
1246 unk_lang_create_fundamental_type,
1247 unk_lang_print_type, /* Print a type using appropriate syntax */
1248 unk_lang_val_print, /* Print a value using appropriate syntax */
1249 unk_lang_value_print, /* Print a top-level value */
1250 unk_lang_trampoline, /* Language specific skip_trampoline */
1251 value_of_this, /* value_of_this */
1252 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1253 basic_lookup_transparent_type,/* lookup_transparent_type */
1254 unk_lang_demangle, /* Language specific symbol demangler */
1255 unk_lang_class_name, /* Language specific class_name_from_physname */
1256 unk_op_print_tab, /* expression operators for printing */
1257 1, /* c-style arrays */
1258 0, /* String lower bound */
1260 default_word_break_characters,
1261 unknown_language_arch_info, /* la_language_arch_info. */
1265 /* Per-architecture language information. */
1267 static struct gdbarch_data *language_gdbarch_data;
1269 struct language_gdbarch
1271 /* A vector of per-language per-architecture info. Indexed by "enum
1273 struct language_arch_info arch_info[nr_languages];
1277 language_gdbarch_post_init (struct gdbarch *gdbarch)
1279 struct language_gdbarch *l;
1282 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
1283 for (i = 0; i < languages_size; i++)
1285 if (languages[i] != NULL
1286 && languages[i]->la_language_arch_info != NULL)
1287 languages[i]->la_language_arch_info
1288 (gdbarch, l->arch_info + languages[i]->la_language);
1294 language_string_char_type (const struct language_defn *la,
1295 struct gdbarch *gdbarch)
1297 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1298 language_gdbarch_data);
1299 if (ld->arch_info[la->la_language].string_char_type != NULL)
1300 return ld->arch_info[la->la_language].string_char_type;
1302 return (*la->string_char_type);
1306 language_lookup_primitive_type_by_name (const struct language_defn *la,
1307 struct gdbarch *gdbarch,
1310 struct language_gdbarch *ld = gdbarch_data (gdbarch,
1311 language_gdbarch_data);
1312 if (ld->arch_info[la->la_language].primitive_type_vector != NULL)
1314 struct type *const *p;
1315 for (p = ld->arch_info[la->la_language].primitive_type_vector;
1319 if (strcmp (TYPE_NAME (*p), name) == 0)
1325 struct type **const *p;
1326 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
1328 if (strcmp (TYPE_NAME (**p), name) == 0)
1335 /* Initialize the language routines */
1338 _initialize_language (void)
1340 struct cmd_list_element *set, *show;
1342 language_gdbarch_data
1343 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1345 /* GDB commands for language specific stuff */
1347 set = add_set_cmd ("language", class_support, var_string_noescape,
1349 "Set the current source language.",
1351 show = deprecated_add_show_from_set (set, &showlist);
1352 set_cmd_cfunc (set, set_language_command);
1353 set_cmd_cfunc (show, show_language_command);
1355 add_prefix_cmd ("check", no_class, set_check,
1356 "Set the status of the type/range checker.",
1357 &setchecklist, "set check ", 0, &setlist);
1358 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1359 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1361 add_prefix_cmd ("check", no_class, show_check,
1362 "Show the status of the type/range checker.",
1363 &showchecklist, "show check ", 0, &showlist);
1364 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1365 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1367 set = add_set_cmd ("type", class_support, var_string_noescape,
1369 "Set type checking. (on/warn/off/auto)",
1371 show = deprecated_add_show_from_set (set, &showchecklist);
1372 set_cmd_cfunc (set, set_type_command);
1373 set_cmd_cfunc (show, show_type_command);
1375 set = add_set_cmd ("range", class_support, var_string_noescape,
1377 "Set range checking. (on/warn/off/auto)",
1379 show = deprecated_add_show_from_set (set, &showchecklist);
1380 set_cmd_cfunc (set, set_range_command);
1381 set_cmd_cfunc (show, show_range_command);
1383 set = add_set_cmd ("case-sensitive", class_support, var_string_noescape,
1384 (char *) &case_sensitive,
1385 "Set case sensitivity in name search. (on/off/auto)\n\
1386 For Fortran the default is off; for other languages the default is on.",
1388 show = deprecated_add_show_from_set (set, &showlist);
1389 set_cmd_cfunc (set, set_case_command);
1390 set_cmd_cfunc (show, show_case_command);
1392 add_language (&unknown_language_defn);
1393 add_language (&local_language_defn);
1394 add_language (&auto_language_defn);
1396 language = savestring ("auto", strlen ("auto"));
1397 type = savestring ("auto", strlen ("auto"));
1398 range = savestring ("auto", strlen ("auto"));
1399 case_sensitive = savestring ("auto",strlen ("auto"));
1401 /* Have the above take effect */
1402 set_language (language_auto);