1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2019 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"
50 static int unk_lang_parser (struct parser_state
*);
52 static void set_range_case (void);
54 static void unk_lang_emit_char (int c
, struct type
*type
,
55 struct ui_file
*stream
, int quoter
);
57 static void unk_lang_printchar (int c
, struct type
*type
,
58 struct ui_file
*stream
);
60 static void unk_lang_value_print (struct value
*, struct ui_file
*,
61 const struct value_print_options
*);
63 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*, CORE_ADDR pc
);
65 /* Forward declaration */
66 extern const struct language_defn unknown_language_defn
;
68 /* The current (default at startup) state of type and range checking.
69 (If the modes are set to "auto", though, these are changed based
70 on the default language at startup, and then again based on the
71 language of the first source file. */
73 enum range_mode range_mode
= range_mode_auto
;
74 enum range_check range_check
= range_check_off
;
75 enum case_mode case_mode
= case_mode_auto
;
76 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
78 /* The current language and language_mode (see language.h). */
80 const struct language_defn
*current_language
= &unknown_language_defn
;
81 enum language_mode language_mode
= language_mode_auto
;
83 /* The language that the user expects to be typing in (the language
84 of main(), or the last language we notified them about, or C). */
86 const struct language_defn
*expected_language
;
88 /* The list of supported languages. Keep this in the same order as
89 the 'enum language' values. */
91 static const struct language_defn
*languages
[] = {
92 &unknown_language_defn
,
102 &pascal_language_defn
,
103 &opencl_language_defn
,
105 &minimal_language_defn
,
109 /* The current values of the "set language/range/case-sensitive" enum
111 static const char *language
;
112 static const char *range
;
113 static const char *case_sensitive
;
115 /* See language.h. */
116 const char lang_frame_mismatch_warn
[] =
117 N_("Warning: the current language does not match this frame.");
119 /* This page contains the functions corresponding to GDB commands
120 and their helpers. */
122 /* Show command. Display a warning if the language set
123 does not match the frame. */
125 show_language_command (struct ui_file
*file
, int from_tty
,
126 struct cmd_list_element
*c
, const char *value
)
128 enum language flang
; /* The language of the frame. */
130 if (language_mode
== language_mode_auto
)
131 fprintf_filtered (gdb_stdout
,
132 _("The current source language is "
133 "\"auto; currently %s\".\n"),
134 current_language
->la_name
);
136 fprintf_filtered (gdb_stdout
,
137 _("The current source language is \"%s\".\n"),
138 current_language
->la_name
);
140 if (has_stack_frames ())
142 struct frame_info
*frame
;
144 frame
= get_selected_frame (NULL
);
145 flang
= get_frame_language (frame
);
146 if (flang
!= language_unknown
147 && language_mode
== language_mode_manual
148 && current_language
->la_language
!= flang
)
149 printf_filtered ("%s\n", _(lang_frame_mismatch_warn
));
153 /* Set command. Change the current working language. */
155 set_language_command (const char *ignore
,
156 int from_tty
, struct cmd_list_element
*c
)
158 enum language flang
= language_unknown
;
160 /* "local" is a synonym of "auto". */
161 if (strcmp (language
, "local") == 0)
164 /* Search the list of languages for a match. */
165 for (const auto &lang
: languages
)
167 if (strcmp (lang
->la_name
, language
) == 0)
169 /* Found it! Go into manual mode, and use this language. */
170 if (lang
->la_language
== language_auto
)
172 /* Enter auto mode. Set to the current frame's language, if
173 known, or fallback to the initial language. */
174 language_mode
= language_mode_auto
;
177 struct frame_info
*frame
;
179 frame
= get_selected_frame (NULL
);
180 flang
= get_frame_language (frame
);
182 catch (const gdb_exception_error
&ex
)
184 flang
= language_unknown
;
187 if (flang
!= language_unknown
)
188 set_language (flang
);
190 set_initial_language ();
191 expected_language
= current_language
;
196 /* Enter manual mode. Set the specified language. */
197 language_mode
= language_mode_manual
;
198 current_language
= lang
;
200 expected_language
= current_language
;
206 internal_error (__FILE__
, __LINE__
,
207 "Couldn't find language `%s' in known languages list.",
211 /* Show command. Display a warning if the range setting does
212 not match the current language. */
214 show_range_command (struct ui_file
*file
, int from_tty
,
215 struct cmd_list_element
*c
, const char *value
)
217 if (range_mode
== range_mode_auto
)
226 case range_check_off
:
229 case range_check_warn
:
233 internal_error (__FILE__
, __LINE__
,
234 "Unrecognized range check setting.");
237 fprintf_filtered (gdb_stdout
,
238 _("Range checking is \"auto; currently %s\".\n"),
242 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
245 if (range_check
!= current_language
->la_range_check
)
246 warning (_("the current range check setting "
247 "does not match the language.\n"));
250 /* Set command. Change the setting for range checking. */
252 set_range_command (const char *ignore
,
253 int from_tty
, struct cmd_list_element
*c
)
255 if (strcmp (range
, "on") == 0)
257 range_check
= range_check_on
;
258 range_mode
= range_mode_manual
;
260 else if (strcmp (range
, "warn") == 0)
262 range_check
= range_check_warn
;
263 range_mode
= range_mode_manual
;
265 else if (strcmp (range
, "off") == 0)
267 range_check
= range_check_off
;
268 range_mode
= range_mode_manual
;
270 else if (strcmp (range
, "auto") == 0)
272 range_mode
= range_mode_auto
;
278 internal_error (__FILE__
, __LINE__
,
279 _("Unrecognized range check setting: \"%s\""), range
);
281 if (range_check
!= current_language
->la_range_check
)
282 warning (_("the current range check setting "
283 "does not match the language.\n"));
286 /* Show command. Display a warning if the case sensitivity setting does
287 not match the current language. */
289 show_case_command (struct ui_file
*file
, int from_tty
,
290 struct cmd_list_element
*c
, const char *value
)
292 if (case_mode
== case_mode_auto
)
294 const char *tmp
= NULL
;
296 switch (case_sensitivity
)
298 case case_sensitive_on
:
301 case case_sensitive_off
:
305 internal_error (__FILE__
, __LINE__
,
306 "Unrecognized case-sensitive setting.");
309 fprintf_filtered (gdb_stdout
,
310 _("Case sensitivity in "
311 "name search is \"auto; currently %s\".\n"),
315 fprintf_filtered (gdb_stdout
,
316 _("Case sensitivity in name search is \"%s\".\n"),
319 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
320 warning (_("the current case sensitivity setting does not match "
324 /* Set command. Change the setting for case sensitivity. */
327 set_case_command (const char *ignore
, int from_tty
, struct cmd_list_element
*c
)
329 if (strcmp (case_sensitive
, "on") == 0)
331 case_sensitivity
= case_sensitive_on
;
332 case_mode
= case_mode_manual
;
334 else if (strcmp (case_sensitive
, "off") == 0)
336 case_sensitivity
= case_sensitive_off
;
337 case_mode
= case_mode_manual
;
339 else if (strcmp (case_sensitive
, "auto") == 0)
341 case_mode
= case_mode_auto
;
347 internal_error (__FILE__
, __LINE__
,
348 "Unrecognized case-sensitive setting: \"%s\"",
352 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
353 warning (_("the current case sensitivity setting does not match "
357 /* Set the status of range and type checking and case sensitivity based on
358 the current modes and the current language.
359 If SHOW is non-zero, then print out the current language,
360 type and range checking status. */
362 set_range_case (void)
364 if (range_mode
== range_mode_auto
)
365 range_check
= current_language
->la_range_check
;
367 if (case_mode
== case_mode_auto
)
368 case_sensitivity
= current_language
->la_case_sensitivity
;
371 /* Set current language to (enum language) LANG. Returns previous
375 set_language (enum language lang
)
377 enum language prev_language
;
379 prev_language
= current_language
->la_language
;
380 current_language
= languages
[lang
];
382 return prev_language
;
386 /* Print out the current language settings: language, range and
387 type checking. If QUIETLY, print only what has changed. */
390 language_info (int quietly
)
392 if (quietly
&& expected_language
== current_language
)
395 expected_language
= current_language
;
396 printf_unfiltered (_("Current language: %s\n"), language
);
397 show_language_command (NULL
, 1, NULL
, NULL
);
401 printf_unfiltered (_("Range checking: %s\n"), range
);
402 show_range_command (NULL
, 1, NULL
, NULL
);
403 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
404 show_case_command (NULL
, 1, NULL
, NULL
);
409 /* Returns non-zero if the value is a pointer type. */
411 pointer_type (struct type
*type
)
413 return TYPE_CODE (type
) == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
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 (const char *str
)
477 for (const auto &lang
: languages
)
478 if (strcmp (lang
->la_name
, str
) == 0)
479 return lang
->la_language
;
481 if (strcmp (str
, "local") == 0)
482 return language_auto
;
484 return language_unknown
;
487 /* Return the language struct for a given language enum. */
489 const struct language_defn
*
490 language_def (enum language lang
)
492 return languages
[lang
];
495 /* Return the language as a string. */
498 language_str (enum language lang
)
500 return languages
[lang
]->la_name
;
504 set_check (const char *ignore
, int from_tty
)
507 "\"set check\" must be followed by the name of a check subcommand.\n");
508 help_list (setchecklist
, "set check ", all_commands
, gdb_stdout
);
512 show_check (const char *ignore
, int from_tty
)
514 cmd_show_list (showchecklist
, from_tty
, "");
518 /* Build and install the "set language LANG" command. */
521 add_set_language_command ()
523 static const char **language_names
;
525 /* Build the language names array, to be used as enumeration in the
526 "set language" enum command. +1 for "local" and +1 for NULL
528 language_names
= new const char *[ARRAY_SIZE (languages
) + 2];
530 /* Display "auto", "local" and "unknown" first, and then the rest,
532 const char **language_names_p
= language_names
;
533 *language_names_p
++ = auto_language_defn
.la_name
;
534 *language_names_p
++ = "local";
535 *language_names_p
++ = unknown_language_defn
.la_name
;
536 const char **sort_begin
= language_names_p
;
537 for (const auto &lang
: languages
)
539 /* Already handled above. */
540 if (lang
->la_language
== language_auto
541 || lang
->la_language
== language_unknown
)
543 *language_names_p
++ = lang
->la_name
;
545 *language_names_p
= NULL
;
546 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
548 /* Add the filename extensions. */
549 for (const auto &lang
: languages
)
550 if (lang
->la_filename_extensions
!= NULL
)
552 for (size_t i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
553 add_filename_language (lang
->la_filename_extensions
[i
],
557 /* Build the "help set language" docs. */
560 doc
.printf (_("Set the current source language.\n"
561 "The currently understood settings are:\n\nlocal or "
562 "auto Automatic setting based on source file"));
564 for (const auto &lang
: languages
)
566 /* Already dealt with these above. */
567 if (lang
->la_language
== language_unknown
568 || lang
->la_language
== language_auto
)
571 /* FIXME: i18n: for now assume that the human-readable name is
572 just a capitalization of the internal name. */
573 /* Note that we add the newline at the front, so we don't wind
574 up with a trailing newline. */
575 doc
.printf ("\n%-16s Use the %c%s language",
577 /* Capitalize first letter of language name. */
578 toupper (lang
->la_name
[0]),
582 add_setshow_enum_cmd ("language", class_support
,
586 _("Show the current source language."),
587 NULL
, set_language_command
,
588 show_language_command
,
589 &setlist
, &showlist
);
592 /* Iterate through all registered languages looking for and calling
593 any non-NULL struct language_defn.skip_trampoline() functions.
594 Return the result from the first that returns non-zero, or 0 if all
597 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
599 for (const auto &lang
: languages
)
601 if (lang
->skip_trampoline
!= NULL
)
603 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
613 /* Return demangled language symbol, or NULL.
614 FIXME: Options are only useful for certain languages and ignored
615 by others, so it would be better to remove them here and have a
616 more flexible demangler for the languages that need it.
617 FIXME: Sometimes the demangler is invoked when we don't know the
618 language, so we can't use this everywhere. */
620 language_demangle (const struct language_defn
*current_language
,
621 const char *mangled
, int options
)
623 if (current_language
!= NULL
&& current_language
->la_demangle
)
624 return current_language
->la_demangle (mangled
, options
);
628 /* See language.h. */
631 language_sniff_from_mangled_name (const struct language_defn
*lang
,
632 const char *mangled
, char **demangled
)
634 gdb_assert (lang
!= NULL
);
636 if (lang
->la_sniff_from_mangled_name
== NULL
)
642 return lang
->la_sniff_from_mangled_name (mangled
, demangled
);
645 /* Return class name from physname or NULL. */
647 language_class_name_from_physname (const struct language_defn
*lang
,
648 const char *physname
)
650 if (lang
!= NULL
&& lang
->la_class_name_from_physname
)
651 return lang
->la_class_name_from_physname (physname
);
655 /* Return non-zero if TYPE should be passed (and returned) by
656 reference at the language level. */
658 language_pass_by_reference (struct type
*type
)
660 return current_language
->la_pass_by_reference (type
);
663 /* Return zero; by default, types are passed by value at the language
664 level. The target ABI may pass or return some structs by reference
665 independent of this. */
667 default_pass_by_reference (struct type
*type
)
672 /* Return the default string containing the list of characters
673 delimiting words. This is a reasonable default value that
674 most languages should be able to use. */
677 default_word_break_characters (void)
679 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
682 /* Print the index of array elements using the C99 syntax. */
685 default_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
686 const struct value_print_options
*options
)
688 fprintf_filtered (stream
, "[");
689 LA_VALUE_PRINT (index_value
, stream
, options
);
690 fprintf_filtered (stream
, "] = ");
693 /* See language.h. */
696 default_symbol_name_matcher (const char *symbol_search_name
,
697 const lookup_name_info
&lookup_name
,
698 completion_match_result
*comp_match_res
)
700 const std::string
&name
= lookup_name
.name ();
701 completion_match_for_lcd
*match_for_lcd
702 = (comp_match_res
!= NULL
? &comp_match_res
->match_for_lcd
: NULL
);
703 strncmp_iw_mode mode
= (lookup_name
.completion_mode ()
704 ? strncmp_iw_mode::NORMAL
705 : strncmp_iw_mode::MATCH_PARAMS
);
707 if (strncmp_iw_with_mode (symbol_search_name
, name
.c_str (), name
.size (),
708 mode
, language_minimal
, match_for_lcd
) == 0)
710 if (comp_match_res
!= NULL
)
711 comp_match_res
->set_match (symbol_search_name
);
718 /* See language.h. */
721 default_is_string_type_p (struct type
*type
)
723 type
= check_typedef (type
);
724 while (TYPE_CODE (type
) == TYPE_CODE_REF
)
726 type
= TYPE_TARGET_TYPE (type
);
727 type
= check_typedef (type
);
729 return (TYPE_CODE (type
) == TYPE_CODE_STRING
);
732 /* See language.h. */
734 symbol_name_matcher_ftype
*
735 get_symbol_name_matcher (const language_defn
*lang
,
736 const lookup_name_info
&lookup_name
)
738 /* If currently in Ada mode, and the lookup name is wrapped in
739 '<...>', hijack all symbol name comparisons using the Ada
740 matcher, which handles the verbatim matching. */
741 if (current_language
->la_language
== language_ada
742 && lookup_name
.ada ().verbatim_p ())
743 return current_language
->la_get_symbol_name_matcher (lookup_name
);
745 if (lang
->la_get_symbol_name_matcher
!= nullptr)
746 return lang
->la_get_symbol_name_matcher (lookup_name
);
747 return default_symbol_name_matcher
;
750 /* Define the language that is no language. */
753 unk_lang_parser (struct parser_state
*ps
)
759 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
762 error (_("internal error - unimplemented "
763 "function unk_lang_emit_char called."));
767 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
769 error (_("internal error - unimplemented "
770 "function unk_lang_printchar called."));
774 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
775 const gdb_byte
*string
, unsigned int length
,
776 const char *encoding
, int force_ellipses
,
777 const struct value_print_options
*options
)
779 error (_("internal error - unimplemented "
780 "function unk_lang_printstr called."));
784 unk_lang_print_type (struct type
*type
, const char *varstring
,
785 struct ui_file
*stream
, int show
, int level
,
786 const struct type_print_options
*flags
)
788 error (_("internal error - unimplemented "
789 "function unk_lang_print_type called."));
793 unk_lang_val_print (struct type
*type
,
794 int embedded_offset
, CORE_ADDR address
,
795 struct ui_file
*stream
, int recurse
,
797 const struct value_print_options
*options
)
799 error (_("internal error - unimplemented "
800 "function unk_lang_val_print called."));
804 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
805 const struct value_print_options
*options
)
807 error (_("internal error - unimplemented "
808 "function unk_lang_value_print called."));
811 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
816 /* Unknown languages just use the cplus demangler. */
817 static char *unk_lang_demangle (const char *mangled
, int options
)
819 return gdb_demangle (mangled
, options
);
822 static char *unk_lang_class_name (const char *mangled
)
827 static const struct op_print unk_op_print_tab
[] =
829 {NULL
, OP_NULL
, PREC_NULL
, 0}
833 unknown_language_arch_info (struct gdbarch
*gdbarch
,
834 struct language_arch_info
*lai
)
836 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
837 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
838 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
842 const struct language_defn unknown_language_defn
=
852 &exp_descriptor_standard
,
855 unk_lang_printchar
, /* Print character constant */
858 unk_lang_print_type
, /* Print a type using appropriate syntax */
859 default_print_typedef
, /* Print a typedef using appropriate syntax */
860 unk_lang_val_print
, /* Print a value using appropriate syntax */
861 unk_lang_value_print
, /* Print a top-level value */
862 default_read_var_value
, /* la_read_var_value */
863 unk_lang_trampoline
, /* Language specific skip_trampoline */
864 "this", /* name_of_this */
865 true, /* store_sym_names_in_linkage_form_p */
866 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
867 basic_lookup_transparent_type
,/* lookup_transparent_type */
868 unk_lang_demangle
, /* Language specific symbol demangler */
870 unk_lang_class_name
, /* Language specific
871 class_name_from_physname */
872 unk_op_print_tab
, /* expression operators for printing */
873 1, /* c-style arrays */
874 0, /* String lower bound */
875 default_word_break_characters
,
876 default_collect_symbol_completion_matches
,
877 unknown_language_arch_info
, /* la_language_arch_info. */
878 default_print_array_index
,
879 default_pass_by_reference
,
880 c_watch_location_expression
,
881 NULL
, /* la_get_symbol_name_matcher */
882 iterate_over_symbols
,
883 default_search_name_hash
,
887 default_is_string_type_p
,
888 "{...}" /* la_struct_too_deep_ellipsis */
891 /* These two structs define fake entries for the "local" and "auto"
893 const struct language_defn auto_language_defn
=
903 &exp_descriptor_standard
,
906 unk_lang_printchar
, /* Print character constant */
909 unk_lang_print_type
, /* Print a type using appropriate syntax */
910 default_print_typedef
, /* Print a typedef using appropriate syntax */
911 unk_lang_val_print
, /* Print a value using appropriate syntax */
912 unk_lang_value_print
, /* Print a top-level value */
913 default_read_var_value
, /* la_read_var_value */
914 unk_lang_trampoline
, /* Language specific skip_trampoline */
915 "this", /* name_of_this */
916 false, /* store_sym_names_in_linkage_form_p */
917 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
918 basic_lookup_transparent_type
,/* lookup_transparent_type */
919 unk_lang_demangle
, /* Language specific symbol demangler */
921 unk_lang_class_name
, /* Language specific
922 class_name_from_physname */
923 unk_op_print_tab
, /* expression operators for printing */
924 1, /* c-style arrays */
925 0, /* String lower bound */
926 default_word_break_characters
,
927 default_collect_symbol_completion_matches
,
928 unknown_language_arch_info
, /* la_language_arch_info. */
929 default_print_array_index
,
930 default_pass_by_reference
,
931 c_watch_location_expression
,
932 NULL
, /* la_get_symbol_name_matcher */
933 iterate_over_symbols
,
934 default_search_name_hash
,
938 default_is_string_type_p
,
939 "{...}" /* la_struct_too_deep_ellipsis */
943 /* Per-architecture language information. */
945 static struct gdbarch_data
*language_gdbarch_data
;
947 struct language_gdbarch
949 /* A vector of per-language per-architecture info. Indexed by "enum
951 struct language_arch_info arch_info
[nr_languages
];
955 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
957 struct language_gdbarch
*l
;
959 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
960 for (const auto &lang
: languages
)
961 if (lang
!= NULL
&& lang
->la_language_arch_info
!= NULL
)
963 lang
->la_language_arch_info (gdbarch
,
964 l
->arch_info
+ lang
->la_language
);
971 language_string_char_type (const struct language_defn
*la
,
972 struct gdbarch
*gdbarch
)
974 struct language_gdbarch
*ld
975 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
977 return ld
->arch_info
[la
->la_language
].string_char_type
;
981 language_bool_type (const struct language_defn
*la
,
982 struct gdbarch
*gdbarch
)
984 struct language_gdbarch
*ld
985 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
987 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
991 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
992 NULL
, VAR_DOMAIN
, NULL
).symbol
;
995 struct type
*type
= SYMBOL_TYPE (sym
);
997 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
1002 return ld
->arch_info
[la
->la_language
].bool_type_default
;
1005 /* Helper function for primitive type lookup. */
1007 static struct type
**
1008 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
1013 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
1015 if (strcmp (TYPE_NAME (*p
), name
) == 0)
1021 /* See language.h. */
1024 language_lookup_primitive_type (const struct language_defn
*la
,
1025 struct gdbarch
*gdbarch
,
1028 struct language_gdbarch
*ld
=
1029 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1030 struct type
**typep
;
1032 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
1039 /* Helper function for type lookup as a symbol.
1040 Create the symbol corresponding to type TYPE in language LANG. */
1042 static struct symbol
*
1043 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1045 struct symbol
*symbol
;
1046 struct gdbarch
*gdbarch
;
1048 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1050 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1051 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
1053 symbol
->name
= TYPE_NAME (type
);
1054 symbol
->set_language (lang
, nullptr);
1055 symbol
->owner
.arch
= gdbarch
;
1056 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1057 SYMBOL_TYPE (symbol
) = type
;
1058 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1059 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1064 /* Initialize the primitive type symbols of language LD.
1065 The primitive type vector must have already been initialized. */
1068 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1069 const struct language_defn
*la
,
1070 struct gdbarch
*gdbarch
)
1074 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1076 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1079 lai
->primitive_type_symbols
1080 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1082 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1084 lai
->primitive_type_symbols
[n
]
1085 = language_alloc_type_symbol (la
->la_language
,
1086 lai
->primitive_type_vector
[n
]);
1089 /* Note: The result of symbol lookup is normally a symbol *and* the block
1090 it was found in. Builtin types don't live in blocks. We *could* give
1091 them one, but there is no current need so to keep things simple symbol
1092 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1095 /* See language.h. */
1098 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1099 struct gdbarch
*gdbarch
,
1102 struct language_gdbarch
*ld
1103 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1104 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1105 struct type
**typep
;
1108 if (symbol_lookup_debug
)
1110 fprintf_unfiltered (gdb_stdlog
,
1111 "language_lookup_primitive_type_as_symbol"
1113 la
->la_name
, host_address_to_string (gdbarch
), name
);
1116 typep
= language_lookup_primitive_type_1 (lai
, name
);
1119 if (symbol_lookup_debug
)
1120 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1124 /* The set of symbols is lazily initialized. */
1125 if (lai
->primitive_type_symbols
== NULL
)
1126 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1128 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1130 if (symbol_lookup_debug
)
1131 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1135 /* Initialize the language routines. */
1138 _initialize_language (void)
1140 static const char *const type_or_range_names
[]
1141 = { "on", "off", "warn", "auto", NULL
};
1143 static const char *const case_sensitive_names
[]
1144 = { "on", "off", "auto", NULL
};
1146 language_gdbarch_data
1147 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1149 /* GDB commands for language specific stuff. */
1151 add_prefix_cmd ("check", no_class
, set_check
,
1152 _("Set the status of the type/range checker."),
1153 &setchecklist
, "set check ", 0, &setlist
);
1154 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1155 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1157 add_prefix_cmd ("check", no_class
, show_check
,
1158 _("Show the status of the type/range checker."),
1159 &showchecklist
, "show check ", 0, &showlist
);
1160 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1161 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1163 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1165 _("Set range checking (on/warn/off/auto)."),
1166 _("Show range checking (on/warn/off/auto)."),
1167 NULL
, set_range_command
,
1169 &setchecklist
, &showchecklist
);
1171 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1172 &case_sensitive
, _("\
1173 Set case sensitivity in name search (on/off/auto)."), _("\
1174 Show case sensitivity in name search (on/off/auto)."), _("\
1175 For Fortran the default is off; for other languages the default is on."),
1178 &setlist
, &showlist
);
1180 add_set_language_command ();
1184 case_sensitive
= "auto";
1186 /* Have the above take effect. */
1187 set_language (language_auto
);