1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2016 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. */
37 #include "expression.h"
41 #include "parser-defs.h"
44 #include "cp-support.h"
47 extern void _initialize_language (void);
49 static void unk_lang_error (char *);
51 static int unk_lang_parser (struct parser_state
*);
53 static void show_check (char *, int);
55 static void set_check (char *, int);
57 static void set_range_case (void);
59 static void unk_lang_emit_char (int c
, struct type
*type
,
60 struct ui_file
*stream
, int quoter
);
62 static void unk_lang_printchar (int c
, struct type
*type
,
63 struct ui_file
*stream
);
65 static void unk_lang_value_print (struct value
*, struct ui_file
*,
66 const struct value_print_options
*);
68 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*, CORE_ADDR pc
);
70 /* Forward declaration */
71 extern const struct language_defn unknown_language_defn
;
73 /* The current (default at startup) state of type and range checking.
74 (If the modes are set to "auto", though, these are changed based
75 on the default language at startup, and then again based on the
76 language of the first source file. */
78 enum range_mode range_mode
= range_mode_auto
;
79 enum range_check range_check
= range_check_off
;
80 enum case_mode case_mode
= case_mode_auto
;
81 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
83 /* The current language and language_mode (see language.h). */
85 const struct language_defn
*current_language
= &unknown_language_defn
;
86 enum language_mode language_mode
= language_mode_auto
;
88 /* The language that the user expects to be typing in (the language
89 of main(), or the last language we notified them about, or C). */
91 const struct language_defn
*expected_language
;
93 /* The list of supported languages. The list itself is malloc'd. */
95 static const struct language_defn
**languages
;
96 static unsigned languages_size
;
97 static unsigned languages_allocsize
;
98 #define DEFAULT_ALLOCSIZE 4
100 /* The current values of the "set language/type/range" enum
102 static const char *language
;
103 static const char *type
;
104 static const char *range
;
105 static const char *case_sensitive
;
107 /* Warning issued when current_language and the language of the current
108 frame do not match. */
109 char lang_frame_mismatch_warn
[] =
110 "Warning: the current language does not match this frame.";
112 /* This page contains the functions corresponding to GDB commands
113 and their helpers. */
115 /* Show command. Display a warning if the language set
116 does not match the frame. */
118 show_language_command (struct ui_file
*file
, int from_tty
,
119 struct cmd_list_element
*c
, const char *value
)
121 enum language flang
; /* The language of the frame. */
123 if (language_mode
== language_mode_auto
)
124 fprintf_filtered (gdb_stdout
,
125 _("The current source language is "
126 "\"auto; currently %s\".\n"),
127 current_language
->la_name
);
129 fprintf_filtered (gdb_stdout
,
130 _("The current source language is \"%s\".\n"),
131 current_language
->la_name
);
133 if (has_stack_frames ())
135 struct frame_info
*frame
;
137 frame
= get_selected_frame (NULL
);
138 flang
= get_frame_language (frame
);
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
);
146 /* Set command. Change the current working language. */
148 set_language_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
151 enum language flang
= language_unknown
;
153 /* Search the list of languages for a match. */
154 for (i
= 0; i
< languages_size
; i
++)
156 if (strcmp (languages
[i
]->la_name
, language
) == 0)
158 /* Found it! Go into manual mode, and use this language. */
159 if (languages
[i
]->la_language
== language_auto
)
161 /* Enter auto mode. Set to the current frame's language, if
162 known, or fallback to the initial language. */
163 language_mode
= language_mode_auto
;
166 struct frame_info
*frame
;
168 frame
= get_selected_frame (NULL
);
169 flang
= get_frame_language (frame
);
171 CATCH (ex
, RETURN_MASK_ERROR
)
173 flang
= language_unknown
;
177 if (flang
!= language_unknown
)
178 set_language (flang
);
180 set_initial_language ();
181 expected_language
= current_language
;
186 /* Enter manual mode. Set the specified language. */
187 language_mode
= language_mode_manual
;
188 current_language
= languages
[i
];
190 expected_language
= current_language
;
196 internal_error (__FILE__
, __LINE__
,
197 "Couldn't find language `%s' in known languages list.",
201 /* Show command. Display a warning if the range setting does
202 not match the current language. */
204 show_range_command (struct ui_file
*file
, int from_tty
,
205 struct cmd_list_element
*c
, const char *value
)
207 if (range_mode
== range_mode_auto
)
216 case range_check_off
:
219 case range_check_warn
:
223 internal_error (__FILE__
, __LINE__
,
224 "Unrecognized range check setting.");
227 fprintf_filtered (gdb_stdout
,
228 _("Range checking is \"auto; currently %s\".\n"),
232 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
235 if (range_check
!= current_language
->la_range_check
)
236 warning (_("the current range check setting "
237 "does not match the language.\n"));
240 /* Set command. Change the setting for range checking. */
242 set_range_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
244 if (strcmp (range
, "on") == 0)
246 range_check
= range_check_on
;
247 range_mode
= range_mode_manual
;
249 else if (strcmp (range
, "warn") == 0)
251 range_check
= range_check_warn
;
252 range_mode
= range_mode_manual
;
254 else if (strcmp (range
, "off") == 0)
256 range_check
= range_check_off
;
257 range_mode
= range_mode_manual
;
259 else if (strcmp (range
, "auto") == 0)
261 range_mode
= range_mode_auto
;
267 internal_error (__FILE__
, __LINE__
,
268 _("Unrecognized range check setting: \"%s\""), range
);
270 if (range_check
!= current_language
->la_range_check
)
271 warning (_("the current range check setting "
272 "does not match the language.\n"));
275 /* Show command. Display a warning if the case sensitivity setting does
276 not match the current language. */
278 show_case_command (struct ui_file
*file
, int from_tty
,
279 struct cmd_list_element
*c
, const char *value
)
281 if (case_mode
== case_mode_auto
)
285 switch (case_sensitivity
)
287 case case_sensitive_on
:
290 case case_sensitive_off
:
294 internal_error (__FILE__
, __LINE__
,
295 "Unrecognized case-sensitive setting.");
298 fprintf_filtered (gdb_stdout
,
299 _("Case sensitivity in "
300 "name search is \"auto; currently %s\".\n"),
304 fprintf_filtered (gdb_stdout
,
305 _("Case sensitivity in name search is \"%s\".\n"),
308 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
309 warning (_("the current case sensitivity setting does not match "
313 /* Set command. Change the setting for case sensitivity. */
316 set_case_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
318 if (strcmp (case_sensitive
, "on") == 0)
320 case_sensitivity
= case_sensitive_on
;
321 case_mode
= case_mode_manual
;
323 else if (strcmp (case_sensitive
, "off") == 0)
325 case_sensitivity
= case_sensitive_off
;
326 case_mode
= case_mode_manual
;
328 else if (strcmp (case_sensitive
, "auto") == 0)
330 case_mode
= case_mode_auto
;
336 internal_error (__FILE__
, __LINE__
,
337 "Unrecognized case-sensitive setting: \"%s\"",
341 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
342 warning (_("the current case sensitivity setting does not match "
346 /* Set the status of range and type checking and case sensitivity based on
347 the current modes and the current language.
348 If SHOW is non-zero, then print out the current language,
349 type and range checking status. */
351 set_range_case (void)
353 if (range_mode
== range_mode_auto
)
354 range_check
= current_language
->la_range_check
;
356 if (case_mode
== case_mode_auto
)
357 case_sensitivity
= current_language
->la_case_sensitivity
;
360 /* Set current language to (enum language) LANG. Returns previous
364 set_language (enum language lang
)
367 enum language prev_language
;
369 prev_language
= current_language
->la_language
;
371 for (i
= 0; i
< languages_size
; i
++)
373 if (languages
[i
]->la_language
== lang
)
375 current_language
= languages
[i
];
381 return prev_language
;
385 /* Print out the current language settings: language, range and
386 type checking. If QUIETLY, print only what has changed. */
389 language_info (int quietly
)
391 if (quietly
&& expected_language
== current_language
)
394 expected_language
= current_language
;
395 printf_unfiltered (_("Current language: %s\n"), language
);
396 show_language_command (NULL
, 1, NULL
, NULL
);
400 printf_unfiltered (_("Range checking: %s\n"), range
);
401 show_range_command (NULL
, 1, NULL
, NULL
);
402 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
403 show_case_command (NULL
, 1, NULL
, NULL
);
408 /* Returns non-zero if the value is a pointer type. */
410 pointer_type (struct type
*type
)
412 return TYPE_CODE (type
) == TYPE_CODE_PTR
||
413 TYPE_CODE (type
) == TYPE_CODE_REF
;
417 /* This page contains functions that return info about
418 (struct value) values used in GDB. */
420 /* Returns non-zero if the value VAL represents a true value. */
422 value_true (struct value
*val
)
424 /* It is possible that we should have some sort of error if a non-boolean
425 value is used in this context. Possibly dependent on some kind of
426 "boolean-checking" option like range checking. But it should probably
427 not depend on the language except insofar as is necessary to identify
428 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
429 should be an error, probably). */
430 return !value_logical_not (val
);
433 /* This page contains functions for the printing out of
434 error messages that occur during type- and range-
437 /* This is called when a language fails a range-check. The
438 first argument should be a printf()-style format string, and the
439 rest of the arguments should be its arguments. If range_check is
440 range_check_on, an error is printed; if range_check_warn, a warning;
441 otherwise just the message. */
444 range_error (const char *string
,...)
448 va_start (args
, string
);
451 case range_check_warn
:
452 vwarning (string
, args
);
455 verror (string
, args
);
457 case range_check_off
:
458 /* FIXME: cagney/2002-01-30: Should this function print anything
459 when range error is off? */
460 vfprintf_filtered (gdb_stderr
, string
, args
);
461 fprintf_filtered (gdb_stderr
, "\n");
464 internal_error (__FILE__
, __LINE__
, _("bad switch"));
470 /* This page contains miscellaneous functions. */
472 /* Return the language enum for a given language string. */
475 language_enum (char *str
)
479 for (i
= 0; i
< languages_size
; i
++)
480 if (strcmp (languages
[i
]->la_name
, str
) == 0)
481 return languages
[i
]->la_language
;
483 return language_unknown
;
486 /* Return the language struct for a given language enum. */
488 const struct language_defn
*
489 language_def (enum language lang
)
493 for (i
= 0; i
< languages_size
; i
++)
495 if (languages
[i
]->la_language
== lang
)
503 /* Return the language as a string. */
505 language_str (enum language lang
)
509 for (i
= 0; i
< languages_size
; i
++)
511 if (languages
[i
]->la_language
== lang
)
513 return languages
[i
]->la_name
;
520 set_check (char *ignore
, int from_tty
)
523 "\"set check\" must be followed by the name of a check subcommand.\n");
524 help_list (setchecklist
, "set check ", all_commands
, gdb_stdout
);
528 show_check (char *ignore
, int from_tty
)
530 cmd_show_list (showchecklist
, from_tty
, "");
533 /* Add a language to the set of known languages. */
536 add_language (const struct language_defn
*lang
)
538 /* For the "set language" command. */
539 static const char **language_names
= NULL
;
540 /* For the "help set language" command. */
543 struct ui_file
*tmp_stream
;
545 if (lang
->la_magic
!= LANG_MAGIC
)
547 fprintf_unfiltered (gdb_stderr
,
548 "Magic number of %s language struct wrong\n",
550 internal_error (__FILE__
, __LINE__
,
551 _("failed internal consistency check"));
556 languages_allocsize
= DEFAULT_ALLOCSIZE
;
557 languages
= XNEWVEC (const struct language_defn
*, languages_allocsize
);
559 if (languages_size
>= languages_allocsize
)
561 languages_allocsize
*= 2;
562 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
563 languages_allocsize
* sizeof (*languages
));
565 languages
[languages_size
++] = lang
;
567 /* Build the language names array, to be used as enumeration in the
568 set language" enum command. */
569 language_names
= XRESIZEVEC (const char *, language_names
,
572 for (i
= 0; i
< languages_size
; ++i
)
573 language_names
[i
] = languages
[i
]->la_name
;
574 language_names
[i
] = NULL
;
576 /* Add the filename extensions. */
577 if (lang
->la_filename_extensions
!= NULL
)
581 for (i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
582 add_filename_language (lang
->la_filename_extensions
[i
],
586 /* Build the "help set language" docs. */
587 tmp_stream
= mem_fileopen ();
589 fprintf_unfiltered (tmp_stream
,
590 _("Set the current source language.\n"
591 "The currently understood settings are:\n\nlocal or "
592 "auto Automatic setting based on source file\n"));
594 for (i
= 0; i
< languages_size
; ++i
)
596 /* Already dealt with these above. */
597 if (languages
[i
]->la_language
== language_unknown
598 || languages
[i
]->la_language
== language_auto
)
601 /* FIXME: i18n: for now assume that the human-readable name
602 is just a capitalization of the internal name. */
603 fprintf_unfiltered (tmp_stream
, "%-16s Use the %c%s language\n",
604 languages
[i
]->la_name
,
605 /* Capitalize first letter of language
607 toupper (languages
[i
]->la_name
[0]),
608 languages
[i
]->la_name
+ 1);
611 std::string language_set_doc
= ui_file_as_string (tmp_stream
);
612 ui_file_delete (tmp_stream
);
614 add_setshow_enum_cmd ("language", class_support
,
615 (const char **) language_names
,
617 language_set_doc
.c_str (),
618 _("Show the current source language."),
619 NULL
, set_language_command
,
620 show_language_command
,
621 &setlist
, &showlist
);
624 /* Iterate through all registered languages looking for and calling
625 any non-NULL struct language_defn.skip_trampoline() functions.
626 Return the result from the first that returns non-zero, or 0 if all
629 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
633 for (i
= 0; i
< languages_size
; i
++)
635 if (languages
[i
]->skip_trampoline
)
637 CORE_ADDR real_pc
= (languages
[i
]->skip_trampoline
) (frame
, pc
);
647 /* Return demangled language symbol, or NULL.
648 FIXME: Options are only useful for certain languages and ignored
649 by others, so it would be better to remove them here and have a
650 more flexible demangler for the languages that need it.
651 FIXME: Sometimes the demangler is invoked when we don't know the
652 language, so we can't use this everywhere. */
654 language_demangle (const struct language_defn
*current_language
,
655 const char *mangled
, int options
)
657 if (current_language
!= NULL
&& current_language
->la_demangle
)
658 return current_language
->la_demangle (mangled
, options
);
662 /* See langauge.h. */
665 language_sniff_from_mangled_name (const struct language_defn
*lang
,
666 const char *mangled
, char **demangled
)
668 gdb_assert (lang
!= NULL
);
670 if (lang
->la_sniff_from_mangled_name
== NULL
)
676 return lang
->la_sniff_from_mangled_name (mangled
, demangled
);
679 /* Return class name from physname or NULL. */
681 language_class_name_from_physname (const struct language_defn
*lang
,
682 const char *physname
)
684 if (lang
!= NULL
&& lang
->la_class_name_from_physname
)
685 return lang
->la_class_name_from_physname (physname
);
689 /* Return non-zero if TYPE should be passed (and returned) by
690 reference at the language level. */
692 language_pass_by_reference (struct type
*type
)
694 return current_language
->la_pass_by_reference (type
);
697 /* Return zero; by default, types are passed by value at the language
698 level. The target ABI may pass or return some structs by reference
699 independent of this. */
701 default_pass_by_reference (struct type
*type
)
706 /* Return the default string containing the list of characters
707 delimiting words. This is a reasonable default value that
708 most languages should be able to use. */
711 default_word_break_characters (void)
713 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
716 /* Print the index of array elements using the C99 syntax. */
719 default_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
720 const struct value_print_options
*options
)
722 fprintf_filtered (stream
, "[");
723 LA_VALUE_PRINT (index_value
, stream
, options
);
724 fprintf_filtered (stream
, "] = ");
728 default_get_string (struct value
*value
, gdb_byte
**buffer
, int *length
,
729 struct type
**char_type
, const char **charset
)
731 error (_("Getting a string is unsupported in this language."));
734 /* Define the language that is no language. */
737 unk_lang_parser (struct parser_state
*ps
)
743 unk_lang_error (char *msg
)
745 error (_("Attempted to parse an expression with unknown language"));
749 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
752 error (_("internal error - unimplemented "
753 "function unk_lang_emit_char called."));
757 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
759 error (_("internal error - unimplemented "
760 "function unk_lang_printchar called."));
764 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
765 const gdb_byte
*string
, unsigned int length
,
766 const char *encoding
, int force_ellipses
,
767 const struct value_print_options
*options
)
769 error (_("internal error - unimplemented "
770 "function unk_lang_printstr called."));
774 unk_lang_print_type (struct type
*type
, const char *varstring
,
775 struct ui_file
*stream
, int show
, int level
,
776 const struct type_print_options
*flags
)
778 error (_("internal error - unimplemented "
779 "function unk_lang_print_type called."));
783 unk_lang_val_print (struct type
*type
,
784 int embedded_offset
, CORE_ADDR address
,
785 struct ui_file
*stream
, int recurse
,
787 const struct value_print_options
*options
)
789 error (_("internal error - unimplemented "
790 "function unk_lang_val_print called."));
794 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
795 const struct value_print_options
*options
)
797 error (_("internal error - unimplemented "
798 "function unk_lang_value_print called."));
801 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
806 /* Unknown languages just use the cplus demangler. */
807 static char *unk_lang_demangle (const char *mangled
, int options
)
809 return gdb_demangle (mangled
, options
);
812 static char *unk_lang_class_name (const char *mangled
)
817 static const struct op_print unk_op_print_tab
[] =
819 {NULL
, OP_NULL
, PREC_NULL
, 0}
823 unknown_language_arch_info (struct gdbarch
*gdbarch
,
824 struct language_arch_info
*lai
)
826 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
827 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
828 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
832 const struct language_defn unknown_language_defn
=
842 &exp_descriptor_standard
,
846 unk_lang_printchar
, /* Print character constant */
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 */
860 unk_lang_class_name
, /* Language specific
861 class_name_from_physname */
862 unk_op_print_tab
, /* expression operators for printing */
863 1, /* c-style arrays */
864 0, /* String lower bound */
865 default_word_break_characters
,
866 default_make_symbol_completion_list
,
867 unknown_language_arch_info
, /* la_language_arch_info. */
868 default_print_array_index
,
869 default_pass_by_reference
,
871 NULL
, /* la_get_symbol_name_cmp */
872 iterate_over_symbols
,
879 /* These two structs define fake entries for the "local" and "auto"
881 const struct language_defn auto_language_defn
=
891 &exp_descriptor_standard
,
895 unk_lang_printchar
, /* Print character constant */
898 unk_lang_print_type
, /* Print a type using appropriate syntax */
899 default_print_typedef
, /* Print a typedef using appropriate syntax */
900 unk_lang_val_print
, /* Print a value using appropriate syntax */
901 unk_lang_value_print
, /* Print a top-level value */
902 default_read_var_value
, /* la_read_var_value */
903 unk_lang_trampoline
, /* Language specific skip_trampoline */
904 "this", /* name_of_this */
905 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
906 basic_lookup_transparent_type
,/* lookup_transparent_type */
907 unk_lang_demangle
, /* Language specific symbol demangler */
909 unk_lang_class_name
, /* Language specific
910 class_name_from_physname */
911 unk_op_print_tab
, /* expression operators for printing */
912 1, /* c-style arrays */
913 0, /* String lower bound */
914 default_word_break_characters
,
915 default_make_symbol_completion_list
,
916 unknown_language_arch_info
, /* la_language_arch_info. */
917 default_print_array_index
,
918 default_pass_by_reference
,
920 NULL
, /* la_get_symbol_name_cmp */
921 iterate_over_symbols
,
928 const struct language_defn local_language_defn
=
938 &exp_descriptor_standard
,
942 unk_lang_printchar
, /* Print character constant */
945 unk_lang_print_type
, /* Print a type using appropriate syntax */
946 default_print_typedef
, /* Print a typedef using appropriate syntax */
947 unk_lang_val_print
, /* Print a value using appropriate syntax */
948 unk_lang_value_print
, /* Print a top-level value */
949 default_read_var_value
, /* la_read_var_value */
950 unk_lang_trampoline
, /* Language specific skip_trampoline */
951 "this", /* name_of_this */
952 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
953 basic_lookup_transparent_type
,/* lookup_transparent_type */
954 unk_lang_demangle
, /* Language specific symbol demangler */
956 unk_lang_class_name
, /* Language specific
957 class_name_from_physname */
958 unk_op_print_tab
, /* expression operators for printing */
959 1, /* c-style arrays */
960 0, /* String lower bound */
961 default_word_break_characters
,
962 default_make_symbol_completion_list
,
963 unknown_language_arch_info
, /* la_language_arch_info. */
964 default_print_array_index
,
965 default_pass_by_reference
,
967 NULL
, /* la_get_symbol_name_cmp */
968 iterate_over_symbols
,
975 /* Per-architecture language information. */
977 static struct gdbarch_data
*language_gdbarch_data
;
979 struct language_gdbarch
981 /* A vector of per-language per-architecture info. Indexed by "enum
983 struct language_arch_info arch_info
[nr_languages
];
987 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
989 struct language_gdbarch
*l
;
992 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
993 for (i
= 0; i
< languages_size
; i
++)
995 if (languages
[i
] != NULL
996 && languages
[i
]->la_language_arch_info
!= NULL
)
997 languages
[i
]->la_language_arch_info
998 (gdbarch
, l
->arch_info
+ languages
[i
]->la_language
);
1004 language_string_char_type (const struct language_defn
*la
,
1005 struct gdbarch
*gdbarch
)
1007 struct language_gdbarch
*ld
1008 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1010 return ld
->arch_info
[la
->la_language
].string_char_type
;
1014 language_bool_type (const struct language_defn
*la
,
1015 struct gdbarch
*gdbarch
)
1017 struct language_gdbarch
*ld
1018 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1020 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
1024 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
1025 NULL
, VAR_DOMAIN
, NULL
).symbol
;
1028 struct type
*type
= SYMBOL_TYPE (sym
);
1030 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
1035 return ld
->arch_info
[la
->la_language
].bool_type_default
;
1038 /* Helper function for primitive type lookup. */
1040 static struct type
**
1041 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
1046 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
1048 if (strcmp (TYPE_NAME (*p
), name
) == 0)
1054 /* See language.h. */
1057 language_lookup_primitive_type (const struct language_defn
*la
,
1058 struct gdbarch
*gdbarch
,
1061 struct language_gdbarch
*ld
=
1062 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1063 struct type
**typep
;
1065 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
1072 /* Helper function for type lookup as a symbol.
1073 Create the symbol corresponding to type TYPE in language LANG. */
1075 static struct symbol
*
1076 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1078 struct symbol
*symbol
;
1079 struct gdbarch
*gdbarch
;
1081 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1083 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1084 symbol
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct symbol
);
1086 symbol
->ginfo
.name
= TYPE_NAME (type
);
1087 symbol
->ginfo
.language
= lang
;
1088 symbol
->owner
.arch
= gdbarch
;
1089 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1090 SYMBOL_TYPE (symbol
) = type
;
1091 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1092 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1097 /* Initialize the primitive type symbols of language LD.
1098 The primitive type vector must have already been initialized. */
1101 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1102 const struct language_defn
*la
,
1103 struct gdbarch
*gdbarch
)
1107 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1109 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1112 lai
->primitive_type_symbols
1113 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1115 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1117 lai
->primitive_type_symbols
[n
]
1118 = language_alloc_type_symbol (la
->la_language
,
1119 lai
->primitive_type_vector
[n
]);
1122 /* Note: The result of symbol lookup is normally a symbol *and* the block
1123 it was found in. Builtin types don't live in blocks. We *could* give
1124 them one, but there is no current need so to keep things simple symbol
1125 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1128 /* See language.h. */
1131 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1132 struct gdbarch
*gdbarch
,
1135 struct language_gdbarch
*ld
1136 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1137 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1138 struct type
**typep
;
1141 if (symbol_lookup_debug
)
1143 fprintf_unfiltered (gdb_stdlog
,
1144 "language_lookup_primitive_type_as_symbol"
1146 la
->la_name
, host_address_to_string (gdbarch
), name
);
1149 typep
= language_lookup_primitive_type_1 (lai
, name
);
1152 if (symbol_lookup_debug
)
1153 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1157 /* The set of symbols is lazily initialized. */
1158 if (lai
->primitive_type_symbols
== NULL
)
1159 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1161 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1163 if (symbol_lookup_debug
)
1164 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1168 /* Initialize the language routines. */
1171 _initialize_language (void)
1173 static const char *const type_or_range_names
[]
1174 = { "on", "off", "warn", "auto", NULL
};
1176 static const char *const case_sensitive_names
[]
1177 = { "on", "off", "auto", NULL
};
1179 language_gdbarch_data
1180 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1182 /* GDB commands for language specific stuff. */
1184 add_prefix_cmd ("check", no_class
, set_check
,
1185 _("Set the status of the type/range checker."),
1186 &setchecklist
, "set check ", 0, &setlist
);
1187 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1188 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1190 add_prefix_cmd ("check", no_class
, show_check
,
1191 _("Show the status of the type/range checker."),
1192 &showchecklist
, "show check ", 0, &showlist
);
1193 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1194 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1196 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1198 _("Set range checking. (on/warn/off/auto)"),
1199 _("Show range checking. (on/warn/off/auto)"),
1200 NULL
, set_range_command
,
1202 &setchecklist
, &showchecklist
);
1204 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1205 &case_sensitive
, _("\
1206 Set case sensitivity in name search. (on/off/auto)"), _("\
1207 Show case sensitivity in name search. (on/off/auto)"), _("\
1208 For Fortran the default is off; for other languages the default is on."),
1211 &setlist
, &showlist
);
1213 add_language (&auto_language_defn
);
1214 add_language (&local_language_defn
);
1215 add_language (&unknown_language_defn
);
1217 language
= xstrdup ("auto");
1218 type
= xstrdup ("auto");
1219 range
= xstrdup ("auto");
1220 case_sensitive
= xstrdup ("auto");
1222 /* Have the above take effect. */
1223 set_language (language_auto
);