binutils/
[binutils-gdb.git] / gdb / language.c
blob10073e1a932c978fbd82132aa79725575416986d
1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2013 Free Software Foundation, Inc.
5 Contributed by the Department of Computer Science at the State University
6 of New York at Buffalo.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* This file contains functions that return things that are specific
24 to languages. Each function should examine current_language if necessary,
25 and return the appropriate result. */
27 /* FIXME: Most of these would be better organized as macros which
28 return data out of a "language-specific" struct pointer that is set
29 whenever the working language changes. That would be a lot faster. */
31 #include "defs.h"
32 #include <ctype.h>
33 #include "gdb_string.h"
35 #include "symtab.h"
36 #include "gdbtypes.h"
37 #include "value.h"
38 #include "gdbcmd.h"
39 #include "expression.h"
40 #include "language.h"
41 #include "target.h"
42 #include "parser-defs.h"
43 #include "jv-lang.h"
44 #include "demangle.h"
45 #include "symfile.h"
46 #include "cp-support.h"
48 extern void _initialize_language (void);
50 static void unk_lang_error (char *);
52 static int unk_lang_parser (void);
54 static void show_check (char *, int);
56 static void set_check (char *, int);
58 static void set_range_case (void);
60 static void unk_lang_emit_char (int c, struct type *type,
61 struct ui_file *stream, int quoter);
63 static void unk_lang_printchar (int c, struct type *type,
64 struct ui_file *stream);
66 static void unk_lang_value_print (struct value *, struct ui_file *,
67 const struct value_print_options *);
69 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
71 /* Forward declaration */
72 extern const struct language_defn unknown_language_defn;
74 /* The current (default at startup) state of type and range checking.
75 (If the modes are set to "auto", though, these are changed based
76 on the default language at startup, and then again based on the
77 language of the first source file. */
79 enum range_mode range_mode = range_mode_auto;
80 enum range_check range_check = range_check_off;
81 enum case_mode case_mode = case_mode_auto;
82 enum case_sensitivity case_sensitivity = case_sensitive_on;
84 /* The current language and language_mode (see language.h). */
86 const struct language_defn *current_language = &unknown_language_defn;
87 enum language_mode language_mode = language_mode_auto;
89 /* The language that the user expects to be typing in (the language
90 of main(), or the last language we notified them about, or C). */
92 const struct language_defn *expected_language;
94 /* The list of supported languages. The list itself is malloc'd. */
96 static const struct language_defn **languages;
97 static unsigned languages_size;
98 static unsigned languages_allocsize;
99 #define DEFAULT_ALLOCSIZE 4
101 /* The current values of the "set language/type/range" enum
102 commands. */
103 static const char *language;
104 static const char *type;
105 static const char *range;
106 static const char *case_sensitive;
108 /* Warning issued when current_language and the language of the current
109 frame do not match. */
110 char lang_frame_mismatch_warn[] =
111 "Warning: the current language does not match this frame.";
113 /* This page contains the functions corresponding to GDB commands
114 and their helpers. */
116 /* Show command. Display a warning if the language set
117 does not match the frame. */
118 static void
119 show_language_command (struct ui_file *file, int from_tty,
120 struct cmd_list_element *c, const char *value)
122 enum language flang; /* The language of the current frame. */
124 if (language_mode == language_mode_auto)
125 fprintf_filtered (gdb_stdout,
126 _("The current source language is "
127 "\"auto; currently %s\".\n"),
128 current_language->la_name);
129 else
130 fprintf_filtered (gdb_stdout,
131 _("The current source language is \"%s\".\n"),
132 current_language->la_name);
134 flang = get_frame_language ();
135 if (flang != language_unknown &&
136 language_mode == language_mode_manual &&
137 current_language->la_language != flang)
138 printf_filtered ("%s\n", lang_frame_mismatch_warn);
141 /* Set command. Change the current working language. */
142 static void
143 set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
145 int i;
146 enum language flang;
148 /* Search the list of languages for a match. */
149 for (i = 0; i < languages_size; i++)
151 if (strcmp (languages[i]->la_name, language) == 0)
153 /* Found it! Go into manual mode, and use this language. */
154 if (languages[i]->la_language == language_auto)
156 /* Enter auto mode. Set to the current frame's language, if
157 known, or fallback to the initial language. */
158 language_mode = language_mode_auto;
159 flang = get_frame_language ();
160 if (flang != language_unknown)
161 set_language (flang);
162 else
163 set_initial_language ();
164 expected_language = current_language;
165 return;
167 else
169 /* Enter manual mode. Set the specified language. */
170 language_mode = language_mode_manual;
171 current_language = languages[i];
172 set_range_case ();
173 expected_language = current_language;
174 return;
179 internal_error (__FILE__, __LINE__,
180 "Couldn't find language `%s' in known languages list.",
181 language);
184 /* Show command. Display a warning if the range setting does
185 not match the current language. */
186 static void
187 show_range_command (struct ui_file *file, int from_tty,
188 struct cmd_list_element *c, const char *value)
190 if (range_mode == range_mode_auto)
192 char *tmp;
194 switch (range_check)
196 case range_check_on:
197 tmp = "on";
198 break;
199 case range_check_off:
200 tmp = "off";
201 break;
202 case range_check_warn:
203 tmp = "warn";
204 break;
205 default:
206 internal_error (__FILE__, __LINE__,
207 "Unrecognized range check setting.");
210 fprintf_filtered (gdb_stdout,
211 _("Range checking is \"auto; currently %s\".\n"),
212 tmp);
214 else
215 fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"),
216 value);
218 if (range_check != current_language->la_range_check)
219 warning (_("the current range check setting "
220 "does not match the language.\n"));
223 /* Set command. Change the setting for range checking. */
224 static void
225 set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
227 if (strcmp (range, "on") == 0)
229 range_check = range_check_on;
230 range_mode = range_mode_manual;
232 else if (strcmp (range, "warn") == 0)
234 range_check = range_check_warn;
235 range_mode = range_mode_manual;
237 else if (strcmp (range, "off") == 0)
239 range_check = range_check_off;
240 range_mode = range_mode_manual;
242 else if (strcmp (range, "auto") == 0)
244 range_mode = range_mode_auto;
245 set_range_case ();
246 return;
248 else
250 internal_error (__FILE__, __LINE__,
251 _("Unrecognized range check setting: \"%s\""), range);
253 if (range_check != current_language->la_range_check)
254 warning (_("the current range check setting "
255 "does not match the language.\n"));
258 /* Show command. Display a warning if the case sensitivity setting does
259 not match the current language. */
260 static void
261 show_case_command (struct ui_file *file, int from_tty,
262 struct cmd_list_element *c, const char *value)
264 if (case_mode == case_mode_auto)
266 char *tmp = NULL;
268 switch (case_sensitivity)
270 case case_sensitive_on:
271 tmp = "on";
272 break;
273 case case_sensitive_off:
274 tmp = "off";
275 break;
276 default:
277 internal_error (__FILE__, __LINE__,
278 "Unrecognized case-sensitive setting.");
281 fprintf_filtered (gdb_stdout,
282 _("Case sensitivity in "
283 "name search is \"auto; currently %s\".\n"),
284 tmp);
286 else
287 fprintf_filtered (gdb_stdout,
288 _("Case sensitivity in name search is \"%s\".\n"),
289 value);
291 if (case_sensitivity != current_language->la_case_sensitivity)
292 warning (_("the current case sensitivity setting does not match "
293 "the language.\n"));
296 /* Set command. Change the setting for case sensitivity. */
298 static void
299 set_case_command (char *ignore, int from_tty, struct cmd_list_element *c)
301 if (strcmp (case_sensitive, "on") == 0)
303 case_sensitivity = case_sensitive_on;
304 case_mode = case_mode_manual;
306 else if (strcmp (case_sensitive, "off") == 0)
308 case_sensitivity = case_sensitive_off;
309 case_mode = case_mode_manual;
311 else if (strcmp (case_sensitive, "auto") == 0)
313 case_mode = case_mode_auto;
314 set_range_case ();
315 return;
317 else
319 internal_error (__FILE__, __LINE__,
320 "Unrecognized case-sensitive setting: \"%s\"",
321 case_sensitive);
324 if (case_sensitivity != current_language->la_case_sensitivity)
325 warning (_("the current case sensitivity setting does not match "
326 "the language.\n"));
329 /* Set the status of range and type checking and case sensitivity based on
330 the current modes and the current language.
331 If SHOW is non-zero, then print out the current language,
332 type and range checking status. */
333 static void
334 set_range_case (void)
336 if (range_mode == range_mode_auto)
337 range_check = current_language->la_range_check;
339 if (case_mode == case_mode_auto)
340 case_sensitivity = current_language->la_case_sensitivity;
343 /* Set current language to (enum language) LANG. Returns previous
344 language. */
346 enum language
347 set_language (enum language lang)
349 int i;
350 enum language prev_language;
352 prev_language = current_language->la_language;
354 for (i = 0; i < languages_size; i++)
356 if (languages[i]->la_language == lang)
358 current_language = languages[i];
359 set_range_case ();
360 break;
364 return prev_language;
368 /* Print out the current language settings: language, range and
369 type checking. If QUIETLY, print only what has changed. */
371 void
372 language_info (int quietly)
374 if (quietly && expected_language == current_language)
375 return;
377 expected_language = current_language;
378 printf_unfiltered (_("Current language: %s\n"), language);
379 show_language_command (NULL, 1, NULL, NULL);
381 if (!quietly)
383 printf_unfiltered (_("Range checking: %s\n"), range);
384 show_range_command (NULL, 1, NULL, NULL);
385 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
386 show_case_command (NULL, 1, NULL, NULL);
391 /* Returns non-zero if the value is a pointer type. */
393 pointer_type (struct type *type)
395 return TYPE_CODE (type) == TYPE_CODE_PTR ||
396 TYPE_CODE (type) == TYPE_CODE_REF;
400 /* This page contains functions that return info about
401 (struct value) values used in GDB. */
403 /* Returns non-zero if the value VAL represents a true value. */
405 value_true (struct value *val)
407 /* It is possible that we should have some sort of error if a non-boolean
408 value is used in this context. Possibly dependent on some kind of
409 "boolean-checking" option like range checking. But it should probably
410 not depend on the language except insofar as is necessary to identify
411 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
412 should be an error, probably). */
413 return !value_logical_not (val);
416 /* This page contains functions for the printing out of
417 error messages that occur during type- and range-
418 checking. */
420 /* This is called when a language fails a range-check. The
421 first argument should be a printf()-style format string, and the
422 rest of the arguments should be its arguments. If range_check is
423 range_check_on, an error is printed; if range_check_warn, a warning;
424 otherwise just the message. */
426 void
427 range_error (const char *string,...)
429 va_list args;
431 va_start (args, string);
432 switch (range_check)
434 case range_check_warn:
435 vwarning (string, args);
436 break;
437 case range_check_on:
438 verror (string, args);
439 break;
440 case range_check_off:
441 /* FIXME: cagney/2002-01-30: Should this function print anything
442 when range error is off? */
443 vfprintf_filtered (gdb_stderr, string, args);
444 fprintf_filtered (gdb_stderr, "\n");
445 break;
446 default:
447 internal_error (__FILE__, __LINE__, _("bad switch"));
449 va_end (args);
453 /* This page contains miscellaneous functions. */
455 /* Return the language enum for a given language string. */
457 enum language
458 language_enum (char *str)
460 int i;
462 for (i = 0; i < languages_size; i++)
463 if (strcmp (languages[i]->la_name, str) == 0)
464 return languages[i]->la_language;
466 return language_unknown;
469 /* Return the language struct for a given language enum. */
471 const struct language_defn *
472 language_def (enum language lang)
474 int i;
476 for (i = 0; i < languages_size; i++)
478 if (languages[i]->la_language == lang)
480 return languages[i];
483 return NULL;
486 /* Return the language as a string. */
487 char *
488 language_str (enum language lang)
490 int i;
492 for (i = 0; i < languages_size; i++)
494 if (languages[i]->la_language == lang)
496 return languages[i]->la_name;
499 return "Unknown";
502 static void
503 set_check (char *ignore, int from_tty)
505 printf_unfiltered (
506 "\"set check\" must be followed by the name of a check subcommand.\n");
507 help_list (setchecklist, "set check ", -1, gdb_stdout);
510 static void
511 show_check (char *ignore, int from_tty)
513 cmd_show_list (showchecklist, from_tty, "");
516 /* Add a language to the set of known languages. */
518 void
519 add_language (const struct language_defn *lang)
521 /* For the "set language" command. */
522 static char **language_names = NULL;
523 /* For the "help set language" command. */
524 char *language_set_doc = NULL;
526 int i;
527 struct ui_file *tmp_stream;
529 if (lang->la_magic != LANG_MAGIC)
531 fprintf_unfiltered (gdb_stderr,
532 "Magic number of %s language struct wrong\n",
533 lang->la_name);
534 internal_error (__FILE__, __LINE__,
535 _("failed internal consistency check"));
538 if (!languages)
540 languages_allocsize = DEFAULT_ALLOCSIZE;
541 languages = (const struct language_defn **) xmalloc
542 (languages_allocsize * sizeof (*languages));
544 if (languages_size >= languages_allocsize)
546 languages_allocsize *= 2;
547 languages = (const struct language_defn **) xrealloc ((char *) languages,
548 languages_allocsize * sizeof (*languages));
550 languages[languages_size++] = lang;
552 /* Build the language names array, to be used as enumeration in the
553 set language" enum command. */
554 language_names = xrealloc (language_names,
555 (languages_size + 1) * sizeof (const char *));
556 for (i = 0; i < languages_size; ++i)
557 language_names[i] = languages[i]->la_name;
558 language_names[i] = NULL;
560 /* Build the "help set language" docs. */
561 tmp_stream = mem_fileopen ();
563 fprintf_unfiltered (tmp_stream,
564 _("Set the current source language.\n"
565 "The currently understood settings are:\n\nlocal or "
566 "auto Automatic setting based on source file\n"));
568 for (i = 0; i < languages_size; ++i)
570 /* Already dealt with these above. */
571 if (languages[i]->la_language == language_unknown
572 || languages[i]->la_language == language_auto)
573 continue;
575 /* FIXME: i18n: for now assume that the human-readable name
576 is just a capitalization of the internal name. */
577 fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n",
578 languages[i]->la_name,
579 /* Capitalize first letter of language
580 name. */
581 toupper (languages[i]->la_name[0]),
582 languages[i]->la_name + 1);
585 language_set_doc = ui_file_xstrdup (tmp_stream, NULL);
586 ui_file_delete (tmp_stream);
588 add_setshow_enum_cmd ("language", class_support,
589 (const char **) language_names,
590 &language,
591 language_set_doc,
592 _("Show the current source language."),
593 NULL, set_language_command,
594 show_language_command,
595 &setlist, &showlist);
597 xfree (language_set_doc);
600 /* Iterate through all registered languages looking for and calling
601 any non-NULL struct language_defn.skip_trampoline() functions.
602 Return the result from the first that returns non-zero, or 0 if all
603 `fail'. */
604 CORE_ADDR
605 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
607 int i;
609 for (i = 0; i < languages_size; i++)
611 if (languages[i]->skip_trampoline)
613 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc);
615 if (real_pc)
616 return real_pc;
620 return 0;
623 /* Return demangled language symbol, or NULL.
624 FIXME: Options are only useful for certain languages and ignored
625 by others, so it would be better to remove them here and have a
626 more flexible demangler for the languages that need it.
627 FIXME: Sometimes the demangler is invoked when we don't know the
628 language, so we can't use this everywhere. */
629 char *
630 language_demangle (const struct language_defn *current_language,
631 const char *mangled, int options)
633 if (current_language != NULL && current_language->la_demangle)
634 return current_language->la_demangle (mangled, options);
635 return NULL;
638 /* Return class name from physname or NULL. */
639 char *
640 language_class_name_from_physname (const struct language_defn *lang,
641 const char *physname)
643 if (lang != NULL && lang->la_class_name_from_physname)
644 return lang->la_class_name_from_physname (physname);
645 return NULL;
648 /* Return non-zero if TYPE should be passed (and returned) by
649 reference at the language level. */
651 language_pass_by_reference (struct type *type)
653 return current_language->la_pass_by_reference (type);
656 /* Return zero; by default, types are passed by value at the language
657 level. The target ABI may pass or return some structs by reference
658 independent of this. */
660 default_pass_by_reference (struct type *type)
662 return 0;
665 /* Return the default string containing the list of characters
666 delimiting words. This is a reasonable default value that
667 most languages should be able to use. */
669 char *
670 default_word_break_characters (void)
672 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
675 /* Print the index of array elements using the C99 syntax. */
677 void
678 default_print_array_index (struct value *index_value, struct ui_file *stream,
679 const struct value_print_options *options)
681 fprintf_filtered (stream, "[");
682 LA_VALUE_PRINT (index_value, stream, options);
683 fprintf_filtered (stream, "] = ");
686 void
687 default_get_string (struct value *value, gdb_byte **buffer, int *length,
688 struct type **char_type, const char **charset)
690 error (_("Getting a string is unsupported in this language."));
693 /* Define the language that is no language. */
695 static int
696 unk_lang_parser (void)
698 return 1;
701 static void
702 unk_lang_error (char *msg)
704 error (_("Attempted to parse an expression with unknown language"));
707 static void
708 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
709 int quoter)
711 error (_("internal error - unimplemented "
712 "function unk_lang_emit_char called."));
715 static void
716 unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
718 error (_("internal error - unimplemented "
719 "function unk_lang_printchar called."));
722 static void
723 unk_lang_printstr (struct ui_file *stream, struct type *type,
724 const gdb_byte *string, unsigned int length,
725 const char *encoding, int force_ellipses,
726 const struct value_print_options *options)
728 error (_("internal error - unimplemented "
729 "function unk_lang_printstr called."));
732 static void
733 unk_lang_print_type (struct type *type, const char *varstring,
734 struct ui_file *stream, int show, int level,
735 const struct type_print_options *flags)
737 error (_("internal error - unimplemented "
738 "function unk_lang_print_type called."));
741 static void
742 unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
743 int embedded_offset, CORE_ADDR address,
744 struct ui_file *stream, int recurse,
745 const struct value *val,
746 const struct value_print_options *options)
748 error (_("internal error - unimplemented "
749 "function unk_lang_val_print called."));
752 static void
753 unk_lang_value_print (struct value *val, struct ui_file *stream,
754 const struct value_print_options *options)
756 error (_("internal error - unimplemented "
757 "function unk_lang_value_print called."));
760 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
762 return 0;
765 /* Unknown languages just use the cplus demangler. */
766 static char *unk_lang_demangle (const char *mangled, int options)
768 return gdb_demangle (mangled, options);
771 static char *unk_lang_class_name (const char *mangled)
773 return NULL;
776 static const struct op_print unk_op_print_tab[] =
778 {NULL, OP_NULL, PREC_NULL, 0}
781 static void
782 unknown_language_arch_info (struct gdbarch *gdbarch,
783 struct language_arch_info *lai)
785 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
786 lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
787 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
788 struct type *);
791 const struct language_defn unknown_language_defn =
793 "unknown",
794 language_unknown,
795 range_check_off,
796 case_sensitive_on,
797 array_row_major,
798 macro_expansion_no,
799 &exp_descriptor_standard,
800 unk_lang_parser,
801 unk_lang_error,
802 null_post_parser,
803 unk_lang_printchar, /* Print character constant */
804 unk_lang_printstr,
805 unk_lang_emit_char,
806 unk_lang_print_type, /* Print a type using appropriate syntax */
807 default_print_typedef, /* Print a typedef using appropriate syntax */
808 unk_lang_val_print, /* Print a value using appropriate syntax */
809 unk_lang_value_print, /* Print a top-level value */
810 default_read_var_value, /* la_read_var_value */
811 unk_lang_trampoline, /* Language specific skip_trampoline */
812 "this", /* name_of_this */
813 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
814 basic_lookup_transparent_type,/* lookup_transparent_type */
815 unk_lang_demangle, /* Language specific symbol demangler */
816 unk_lang_class_name, /* Language specific
817 class_name_from_physname */
818 unk_op_print_tab, /* expression operators for printing */
819 1, /* c-style arrays */
820 0, /* String lower bound */
821 default_word_break_characters,
822 default_make_symbol_completion_list,
823 unknown_language_arch_info, /* la_language_arch_info. */
824 default_print_array_index,
825 default_pass_by_reference,
826 default_get_string,
827 NULL, /* la_get_symbol_name_cmp */
828 iterate_over_symbols,
829 LANG_MAGIC
832 /* These two structs define fake entries for the "local" and "auto"
833 options. */
834 const struct language_defn auto_language_defn =
836 "auto",
837 language_auto,
838 range_check_off,
839 case_sensitive_on,
840 array_row_major,
841 macro_expansion_no,
842 &exp_descriptor_standard,
843 unk_lang_parser,
844 unk_lang_error,
845 null_post_parser,
846 unk_lang_printchar, /* Print character constant */
847 unk_lang_printstr,
848 unk_lang_emit_char,
849 unk_lang_print_type, /* Print a type using appropriate syntax */
850 default_print_typedef, /* Print a typedef using appropriate syntax */
851 unk_lang_val_print, /* Print a value using appropriate syntax */
852 unk_lang_value_print, /* Print a top-level value */
853 default_read_var_value, /* la_read_var_value */
854 unk_lang_trampoline, /* Language specific skip_trampoline */
855 "this", /* name_of_this */
856 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
857 basic_lookup_transparent_type,/* lookup_transparent_type */
858 unk_lang_demangle, /* Language specific symbol demangler */
859 unk_lang_class_name, /* Language specific
860 class_name_from_physname */
861 unk_op_print_tab, /* expression operators for printing */
862 1, /* c-style arrays */
863 0, /* String lower bound */
864 default_word_break_characters,
865 default_make_symbol_completion_list,
866 unknown_language_arch_info, /* la_language_arch_info. */
867 default_print_array_index,
868 default_pass_by_reference,
869 default_get_string,
870 NULL, /* la_get_symbol_name_cmp */
871 iterate_over_symbols,
872 LANG_MAGIC
875 const struct language_defn local_language_defn =
877 "local",
878 language_auto,
879 range_check_off,
880 case_sensitive_on,
881 array_row_major,
882 macro_expansion_no,
883 &exp_descriptor_standard,
884 unk_lang_parser,
885 unk_lang_error,
886 null_post_parser,
887 unk_lang_printchar, /* Print character constant */
888 unk_lang_printstr,
889 unk_lang_emit_char,
890 unk_lang_print_type, /* Print a type using appropriate syntax */
891 default_print_typedef, /* Print a typedef using appropriate syntax */
892 unk_lang_val_print, /* Print a value using appropriate syntax */
893 unk_lang_value_print, /* Print a top-level value */
894 default_read_var_value, /* la_read_var_value */
895 unk_lang_trampoline, /* Language specific skip_trampoline */
896 "this", /* name_of_this */
897 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
898 basic_lookup_transparent_type,/* lookup_transparent_type */
899 unk_lang_demangle, /* Language specific symbol demangler */
900 unk_lang_class_name, /* Language specific
901 class_name_from_physname */
902 unk_op_print_tab, /* expression operators for printing */
903 1, /* c-style arrays */
904 0, /* String lower bound */
905 default_word_break_characters,
906 default_make_symbol_completion_list,
907 unknown_language_arch_info, /* la_language_arch_info. */
908 default_print_array_index,
909 default_pass_by_reference,
910 default_get_string,
911 NULL, /* la_get_symbol_name_cmp */
912 iterate_over_symbols,
913 LANG_MAGIC
916 /* Per-architecture language information. */
918 static struct gdbarch_data *language_gdbarch_data;
920 struct language_gdbarch
922 /* A vector of per-language per-architecture info. Indexed by "enum
923 language". */
924 struct language_arch_info arch_info[nr_languages];
927 static void *
928 language_gdbarch_post_init (struct gdbarch *gdbarch)
930 struct language_gdbarch *l;
931 int i;
933 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
934 for (i = 0; i < languages_size; i++)
936 if (languages[i] != NULL
937 && languages[i]->la_language_arch_info != NULL)
938 languages[i]->la_language_arch_info
939 (gdbarch, l->arch_info + languages[i]->la_language);
941 return l;
944 struct type *
945 language_string_char_type (const struct language_defn *la,
946 struct gdbarch *gdbarch)
948 struct language_gdbarch *ld = gdbarch_data (gdbarch,
949 language_gdbarch_data);
951 return ld->arch_info[la->la_language].string_char_type;
954 struct type *
955 language_bool_type (const struct language_defn *la,
956 struct gdbarch *gdbarch)
958 struct language_gdbarch *ld = gdbarch_data (gdbarch,
959 language_gdbarch_data);
961 if (ld->arch_info[la->la_language].bool_type_symbol)
963 struct symbol *sym;
965 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
966 NULL, VAR_DOMAIN, NULL);
967 if (sym)
969 struct type *type = SYMBOL_TYPE (sym);
971 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
972 return type;
976 return ld->arch_info[la->la_language].bool_type_default;
979 struct type *
980 language_lookup_primitive_type_by_name (const struct language_defn *la,
981 struct gdbarch *gdbarch,
982 const char *name)
984 struct language_gdbarch *ld = gdbarch_data (gdbarch,
985 language_gdbarch_data);
986 struct type *const *p;
988 for (p = ld->arch_info[la->la_language].primitive_type_vector;
989 (*p) != NULL;
990 p++)
992 if (strcmp (TYPE_NAME (*p), name) == 0)
993 return (*p);
995 return (NULL);
998 /* Initialize the language routines. */
1000 void
1001 _initialize_language (void)
1003 static const char *const type_or_range_names[]
1004 = { "on", "off", "warn", "auto", NULL };
1006 static const char *const case_sensitive_names[]
1007 = { "on", "off", "auto", NULL };
1009 language_gdbarch_data
1010 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1012 /* GDB commands for language specific stuff. */
1014 add_prefix_cmd ("check", no_class, set_check,
1015 _("Set the status of the type/range checker."),
1016 &setchecklist, "set check ", 0, &setlist);
1017 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1018 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1020 add_prefix_cmd ("check", no_class, show_check,
1021 _("Show the status of the type/range checker."),
1022 &showchecklist, "show check ", 0, &showlist);
1023 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1024 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1026 add_setshow_enum_cmd ("range", class_support, type_or_range_names,
1027 &range,
1028 _("Set range checking. (on/warn/off/auto)"),
1029 _("Show range checking. (on/warn/off/auto)"),
1030 NULL, set_range_command,
1031 show_range_command,
1032 &setchecklist, &showchecklist);
1034 add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names,
1035 &case_sensitive, _("\
1036 Set case sensitivity in name search. (on/off/auto)"), _("\
1037 Show case sensitivity in name search. (on/off/auto)"), _("\
1038 For Fortran the default is off; for other languages the default is on."),
1039 set_case_command,
1040 show_case_command,
1041 &setlist, &showlist);
1043 add_language (&auto_language_defn);
1044 add_language (&local_language_defn);
1045 add_language (&unknown_language_defn);
1047 language = xstrdup ("auto");
1048 type = xstrdup ("auto");
1049 range = xstrdup ("auto");
1050 case_sensitive = xstrdup ("auto");
1052 /* Have the above take effect. */
1053 set_language (language_auto);