1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2020 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 /* The current (default at startup) state of type and range checking.
66 (If the modes are set to "auto", though, these are changed based
67 on the default language at startup, and then again based on the
68 language of the first source file. */
70 enum range_mode range_mode
= range_mode_auto
;
71 enum range_check range_check
= range_check_off
;
72 enum case_mode case_mode
= case_mode_auto
;
73 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
75 /* The current language and language_mode (see language.h). */
77 const struct language_defn
*current_language
= nullptr;
78 enum language_mode language_mode
= language_mode_auto
;
80 /* The language that the user expects to be typing in (the language
81 of main(), or the last language we notified them about, or C). */
83 const struct language_defn
*expected_language
;
85 /* Define the array containing all languages. */
87 const struct language_defn
*language_defn::languages
[nr_languages
];
89 /* The current values of the "set language/range/case-sensitive" enum
91 static const char *language
;
92 static const char *range
;
93 static const char *case_sensitive
;
96 const char lang_frame_mismatch_warn
[] =
97 N_("Warning: the current language does not match this frame.");
99 /* This page contains the functions corresponding to GDB commands
100 and their helpers. */
102 /* Show command. Display a warning if the language set
103 does not match the frame. */
105 show_language_command (struct ui_file
*file
, int from_tty
,
106 struct cmd_list_element
*c
, const char *value
)
108 enum language flang
; /* The language of the frame. */
110 if (language_mode
== language_mode_auto
)
111 fprintf_filtered (gdb_stdout
,
112 _("The current source language is "
113 "\"auto; currently %s\".\n"),
114 current_language
->la_name
);
116 fprintf_filtered (gdb_stdout
,
117 _("The current source language is \"%s\".\n"),
118 current_language
->la_name
);
120 if (has_stack_frames ())
122 struct frame_info
*frame
;
124 frame
= get_selected_frame (NULL
);
125 flang
= get_frame_language (frame
);
126 if (flang
!= language_unknown
127 && language_mode
== language_mode_manual
128 && current_language
->la_language
!= flang
)
129 printf_filtered ("%s\n", _(lang_frame_mismatch_warn
));
133 /* Set command. Change the current working language. */
135 set_language_command (const char *ignore
,
136 int from_tty
, struct cmd_list_element
*c
)
138 enum language flang
= language_unknown
;
140 /* "local" is a synonym of "auto". */
141 if (strcmp (language
, "local") == 0)
144 /* Search the list of languages for a match. */
145 for (const auto &lang
: language_defn::languages
)
147 if (strcmp (lang
->la_name
, language
) == 0)
149 /* Found it! Go into manual mode, and use this language. */
150 if (lang
->la_language
== language_auto
)
152 /* Enter auto mode. Set to the current frame's language, if
153 known, or fallback to the initial language. */
154 language_mode
= language_mode_auto
;
157 struct frame_info
*frame
;
159 frame
= get_selected_frame (NULL
);
160 flang
= get_frame_language (frame
);
162 catch (const gdb_exception_error
&ex
)
164 flang
= language_unknown
;
167 if (flang
!= language_unknown
)
168 set_language (flang
);
170 set_initial_language ();
171 expected_language
= current_language
;
176 /* Enter manual mode. Set the specified language. */
177 language_mode
= language_mode_manual
;
178 current_language
= lang
;
180 expected_language
= current_language
;
186 internal_error (__FILE__
, __LINE__
,
187 "Couldn't find language `%s' in known languages list.",
191 /* Show command. Display a warning if the range setting does
192 not match the current language. */
194 show_range_command (struct ui_file
*file
, int from_tty
,
195 struct cmd_list_element
*c
, const char *value
)
197 if (range_mode
== range_mode_auto
)
206 case range_check_off
:
209 case range_check_warn
:
213 internal_error (__FILE__
, __LINE__
,
214 "Unrecognized range check setting.");
217 fprintf_filtered (gdb_stdout
,
218 _("Range checking is \"auto; currently %s\".\n"),
222 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
225 if (range_check
!= current_language
->la_range_check
)
226 warning (_("the current range check setting "
227 "does not match the language.\n"));
230 /* Set command. Change the setting for range checking. */
232 set_range_command (const char *ignore
,
233 int from_tty
, struct cmd_list_element
*c
)
235 if (strcmp (range
, "on") == 0)
237 range_check
= range_check_on
;
238 range_mode
= range_mode_manual
;
240 else if (strcmp (range
, "warn") == 0)
242 range_check
= range_check_warn
;
243 range_mode
= range_mode_manual
;
245 else if (strcmp (range
, "off") == 0)
247 range_check
= range_check_off
;
248 range_mode
= range_mode_manual
;
250 else if (strcmp (range
, "auto") == 0)
252 range_mode
= range_mode_auto
;
258 internal_error (__FILE__
, __LINE__
,
259 _("Unrecognized range check setting: \"%s\""), range
);
261 if (range_check
!= current_language
->la_range_check
)
262 warning (_("the current range check setting "
263 "does not match the language.\n"));
266 /* Show command. Display a warning if the case sensitivity setting does
267 not match the current language. */
269 show_case_command (struct ui_file
*file
, int from_tty
,
270 struct cmd_list_element
*c
, const char *value
)
272 if (case_mode
== case_mode_auto
)
274 const char *tmp
= NULL
;
276 switch (case_sensitivity
)
278 case case_sensitive_on
:
281 case case_sensitive_off
:
285 internal_error (__FILE__
, __LINE__
,
286 "Unrecognized case-sensitive setting.");
289 fprintf_filtered (gdb_stdout
,
290 _("Case sensitivity in "
291 "name search is \"auto; currently %s\".\n"),
295 fprintf_filtered (gdb_stdout
,
296 _("Case sensitivity in name search is \"%s\".\n"),
299 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
300 warning (_("the current case sensitivity setting does not match "
304 /* Set command. Change the setting for case sensitivity. */
307 set_case_command (const char *ignore
, int from_tty
, struct cmd_list_element
*c
)
309 if (strcmp (case_sensitive
, "on") == 0)
311 case_sensitivity
= case_sensitive_on
;
312 case_mode
= case_mode_manual
;
314 else if (strcmp (case_sensitive
, "off") == 0)
316 case_sensitivity
= case_sensitive_off
;
317 case_mode
= case_mode_manual
;
319 else if (strcmp (case_sensitive
, "auto") == 0)
321 case_mode
= case_mode_auto
;
327 internal_error (__FILE__
, __LINE__
,
328 "Unrecognized case-sensitive setting: \"%s\"",
332 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
333 warning (_("the current case sensitivity setting does not match "
337 /* Set the status of range and type checking and case sensitivity based on
338 the current modes and the current language.
339 If SHOW is non-zero, then print out the current language,
340 type and range checking status. */
342 set_range_case (void)
344 if (range_mode
== range_mode_auto
)
345 range_check
= current_language
->la_range_check
;
347 if (case_mode
== case_mode_auto
)
348 case_sensitivity
= current_language
->la_case_sensitivity
;
351 /* Set current language to (enum language) LANG. Returns previous
355 set_language (enum language lang
)
357 enum language prev_language
;
359 prev_language
= current_language
->la_language
;
360 current_language
= language_def (lang
);
362 return prev_language
;
366 /* Print out the current language settings: language, range and
367 type checking. If QUIETLY, print only what has changed. */
370 language_info (int quietly
)
372 if (quietly
&& expected_language
== current_language
)
375 expected_language
= current_language
;
376 printf_unfiltered (_("Current language: %s\n"), language
);
377 show_language_command (NULL
, 1, NULL
, NULL
);
381 printf_unfiltered (_("Range checking: %s\n"), range
);
382 show_range_command (NULL
, 1, NULL
, NULL
);
383 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
384 show_case_command (NULL
, 1, NULL
, NULL
);
389 /* Returns non-zero if the value is a pointer type. */
391 pointer_type (struct type
*type
)
393 return type
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
397 /* This page contains functions that return info about
398 (struct value) values used in GDB. */
400 /* Returns non-zero if the value VAL represents a true value. */
402 value_true (struct value
*val
)
404 /* It is possible that we should have some sort of error if a non-boolean
405 value is used in this context. Possibly dependent on some kind of
406 "boolean-checking" option like range checking. But it should probably
407 not depend on the language except insofar as is necessary to identify
408 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
409 should be an error, probably). */
410 return !value_logical_not (val
);
413 /* This page contains functions for the printing out of
414 error messages that occur during type- and range-
417 /* This is called when a language fails a range-check. The
418 first argument should be a printf()-style format string, and the
419 rest of the arguments should be its arguments. If range_check is
420 range_check_on, an error is printed; if range_check_warn, a warning;
421 otherwise just the message. */
424 range_error (const char *string
,...)
428 va_start (args
, string
);
431 case range_check_warn
:
432 vwarning (string
, args
);
435 verror (string
, args
);
437 case range_check_off
:
438 /* FIXME: cagney/2002-01-30: Should this function print anything
439 when range error is off? */
440 vfprintf_filtered (gdb_stderr
, string
, args
);
441 fprintf_filtered (gdb_stderr
, "\n");
444 internal_error (__FILE__
, __LINE__
, _("bad switch"));
450 /* This page contains miscellaneous functions. */
452 /* Return the language enum for a given language string. */
455 language_enum (const char *str
)
457 for (const auto &lang
: language_defn::languages
)
458 if (strcmp (lang
->la_name
, str
) == 0)
459 return lang
->la_language
;
461 if (strcmp (str
, "local") == 0)
462 return language_auto
;
464 return language_unknown
;
467 /* Return the language struct for a given language enum. */
469 const struct language_defn
*
470 language_def (enum language lang
)
472 const struct language_defn
*l
= language_defn::languages
[lang
];
473 gdb_assert (l
!= nullptr);
477 /* Return the language as a string. */
480 language_str (enum language lang
)
482 return language_def (lang
)->la_name
;
487 /* Build and install the "set language LANG" command. */
490 add_set_language_command ()
492 static const char **language_names
;
494 /* Build the language names array, to be used as enumeration in the
495 "set language" enum command. +1 for "local" and +1 for NULL
497 language_names
= new const char *[ARRAY_SIZE (language_defn::languages
) + 2];
499 /* Display "auto", "local" and "unknown" first, and then the rest,
501 const char **language_names_p
= language_names
;
502 *language_names_p
++ = language_def (language_auto
)->la_name
;
503 *language_names_p
++ = "local";
504 *language_names_p
++ = language_def (language_unknown
)->la_name
;
505 const char **sort_begin
= language_names_p
;
506 for (const auto &lang
: language_defn::languages
)
508 /* Already handled above. */
509 if (lang
->la_language
== language_auto
510 || lang
->la_language
== language_unknown
)
512 *language_names_p
++ = lang
->la_name
;
514 *language_names_p
= NULL
;
515 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
517 /* Add the filename extensions. */
518 for (const auto &lang
: language_defn::languages
)
519 if (lang
->la_filename_extensions
!= NULL
)
521 for (size_t i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
522 add_filename_language (lang
->la_filename_extensions
[i
],
526 /* Build the "help set language" docs. */
529 doc
.printf (_("Set the current source language.\n"
530 "The currently understood settings are:\n\nlocal or "
531 "auto Automatic setting based on source file"));
533 for (const auto &lang
: language_defn::languages
)
535 /* Already dealt with these above. */
536 if (lang
->la_language
== language_unknown
537 || lang
->la_language
== language_auto
)
540 /* FIXME: i18n: for now assume that the human-readable name is
541 just a capitalization of the internal name. */
542 /* Note that we add the newline at the front, so we don't wind
543 up with a trailing newline. */
544 doc
.printf ("\n%-16s Use the %c%s language",
546 /* Capitalize first letter of language name. */
547 toupper (lang
->la_name
[0]),
551 add_setshow_enum_cmd ("language", class_support
,
555 _("Show the current source language."),
556 NULL
, set_language_command
,
557 show_language_command
,
558 &setlist
, &showlist
);
561 /* Iterate through all registered languages looking for and calling
562 any non-NULL struct language_defn.skip_trampoline() functions.
563 Return the result from the first that returns non-zero, or 0 if all
566 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
568 for (const auto &lang
: language_defn::languages
)
570 if (lang
->skip_trampoline
!= NULL
)
572 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
582 /* Return demangled language symbol, or NULL.
583 FIXME: Options are only useful for certain languages and ignored
584 by others, so it would be better to remove them here and have a
585 more flexible demangler for the languages that need it.
586 FIXME: Sometimes the demangler is invoked when we don't know the
587 language, so we can't use this everywhere. */
589 language_demangle (const struct language_defn
*current_language
,
590 const char *mangled
, int options
)
592 if (current_language
!= NULL
&& current_language
->la_demangle
)
593 return current_language
->la_demangle (mangled
, options
);
597 /* See language.h. */
600 language_sniff_from_mangled_name (const struct language_defn
*lang
,
601 const char *mangled
, char **demangled
)
603 gdb_assert (lang
!= NULL
);
605 if (lang
->la_sniff_from_mangled_name
== NULL
)
611 return lang
->la_sniff_from_mangled_name (mangled
, demangled
);
614 /* Return class name from physname or NULL. */
616 language_class_name_from_physname (const struct language_defn
*lang
,
617 const char *physname
)
619 if (lang
!= NULL
&& lang
->la_class_name_from_physname
)
620 return lang
->la_class_name_from_physname (physname
);
624 /* Return information about whether TYPE should be passed
625 (and returned) by reference at the language level. */
627 struct language_pass_by_ref_info
628 language_pass_by_reference (struct type
*type
)
630 return current_language
->la_pass_by_reference (type
);
633 /* Return a default struct that provides pass-by-reference information
634 about the given TYPE. Languages should update the default values
637 struct language_pass_by_ref_info
638 default_pass_by_reference (struct type
*type
)
643 /* Return the default string containing the list of characters
644 delimiting words. This is a reasonable default value that
645 most languages should be able to use. */
648 default_word_break_characters (void)
650 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
653 /* See language.h. */
656 language_defn::print_array_index (struct type
*index_type
, LONGEST index
,
657 struct ui_file
*stream
,
658 const value_print_options
*options
) const
660 struct value
*index_value
= value_from_longest (index_type
, index
);
662 fprintf_filtered (stream
, "[");
663 LA_VALUE_PRINT (index_value
, stream
, options
);
664 fprintf_filtered (stream
, "] = ");
667 /* See language.h. */
670 default_symbol_name_matcher (const char *symbol_search_name
,
671 const lookup_name_info
&lookup_name
,
672 completion_match_result
*comp_match_res
)
674 gdb::string_view name
= lookup_name
.name ();
675 completion_match_for_lcd
*match_for_lcd
676 = (comp_match_res
!= NULL
? &comp_match_res
->match_for_lcd
: NULL
);
677 strncmp_iw_mode mode
= (lookup_name
.completion_mode ()
678 ? strncmp_iw_mode::NORMAL
679 : strncmp_iw_mode::MATCH_PARAMS
);
681 if (strncmp_iw_with_mode (symbol_search_name
, name
.data (), name
.size (),
682 mode
, language_minimal
, match_for_lcd
) == 0)
684 if (comp_match_res
!= NULL
)
685 comp_match_res
->set_match (symbol_search_name
);
692 /* See language.h. */
695 default_is_string_type_p (struct type
*type
)
697 type
= check_typedef (type
);
698 while (type
->code () == TYPE_CODE_REF
)
700 type
= TYPE_TARGET_TYPE (type
);
701 type
= check_typedef (type
);
703 return (type
->code () == TYPE_CODE_STRING
);
706 /* See language.h. */
708 symbol_name_matcher_ftype
*
709 get_symbol_name_matcher (const language_defn
*lang
,
710 const lookup_name_info
&lookup_name
)
712 /* If currently in Ada mode, and the lookup name is wrapped in
713 '<...>', hijack all symbol name comparisons using the Ada
714 matcher, which handles the verbatim matching. */
715 if (current_language
->la_language
== language_ada
716 && lookup_name
.ada ().verbatim_p ())
717 return current_language
->la_get_symbol_name_matcher (lookup_name
);
719 if (lang
->la_get_symbol_name_matcher
!= nullptr)
720 return lang
->la_get_symbol_name_matcher (lookup_name
);
721 return default_symbol_name_matcher
;
724 /* Define the language that is no language. */
727 unk_lang_parser (struct parser_state
*ps
)
733 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
736 error (_("internal error - unimplemented "
737 "function unk_lang_emit_char called."));
741 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
743 error (_("internal error - unimplemented "
744 "function unk_lang_printchar called."));
748 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
749 const gdb_byte
*string
, unsigned int length
,
750 const char *encoding
, int force_ellipses
,
751 const struct value_print_options
*options
)
753 error (_("internal error - unimplemented "
754 "function unk_lang_printstr called."));
758 unk_lang_print_type (struct type
*type
, const char *varstring
,
759 struct ui_file
*stream
, int show
, int level
,
760 const struct type_print_options
*flags
)
762 error (_("internal error - unimplemented "
763 "function unk_lang_print_type called."));
767 unk_lang_value_print_inner (struct value
*val
,
768 struct ui_file
*stream
, int recurse
,
769 const struct value_print_options
*options
)
771 error (_("internal error - unimplemented "
772 "function unk_lang_value_print_inner called."));
776 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
777 const struct value_print_options
*options
)
779 error (_("internal error - unimplemented "
780 "function unk_lang_value_print called."));
783 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
788 /* Unknown languages just use the cplus demangler. */
789 static char *unk_lang_demangle (const char *mangled
, int options
)
791 return gdb_demangle (mangled
, options
);
794 static char *unk_lang_class_name (const char *mangled
)
799 static const struct op_print unk_op_print_tab
[] =
801 {NULL
, OP_NULL
, PREC_NULL
, 0}
805 unknown_language_arch_info (struct gdbarch
*gdbarch
,
806 struct language_arch_info
*lai
)
808 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
809 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
810 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
814 /* Constant data that describes the unknown language. */
816 extern const struct language_data unknown_language_data
=
826 &exp_descriptor_standard
,
829 unk_lang_printchar
, /* Print character constant */
832 unk_lang_print_type
, /* Print a type using appropriate syntax */
833 default_print_typedef
, /* Print a typedef using appropriate syntax */
834 unk_lang_value_print_inner
, /* la_value_print_inner */
835 unk_lang_value_print
, /* Print a top-level value */
836 unk_lang_trampoline
, /* Language specific skip_trampoline */
837 "this", /* name_of_this */
838 true, /* store_sym_names_in_linkage_form_p */
839 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
840 basic_lookup_transparent_type
,/* lookup_transparent_type */
841 unk_lang_demangle
, /* Language specific symbol demangler */
843 unk_lang_class_name
, /* Language specific
844 class_name_from_physname */
845 unk_op_print_tab
, /* expression operators for printing */
846 1, /* c-style arrays */
847 0, /* String lower bound */
848 default_word_break_characters
,
849 default_collect_symbol_completion_matches
,
850 unknown_language_arch_info
, /* la_language_arch_info. */
851 default_pass_by_reference
,
852 c_watch_location_expression
,
853 NULL
, /* la_get_symbol_name_matcher */
854 iterate_over_symbols
,
855 default_search_name_hash
,
859 default_is_string_type_p
,
860 "{...}" /* la_struct_too_deep_ellipsis */
863 /* Class representing the unknown language. */
865 class unknown_language
: public language_defn
869 : language_defn (language_unknown
, unknown_language_data
)
873 /* Single instance of the unknown language class. */
875 static unknown_language unknown_language_defn
;
877 /* Constant data for the fake "auto" language. */
879 extern const struct language_data auto_language_data
=
889 &exp_descriptor_standard
,
892 unk_lang_printchar
, /* Print character constant */
895 unk_lang_print_type
, /* Print a type using appropriate syntax */
896 default_print_typedef
, /* Print a typedef using appropriate syntax */
897 unk_lang_value_print_inner
, /* la_value_print_inner */
898 unk_lang_value_print
, /* Print a top-level value */
899 unk_lang_trampoline
, /* Language specific skip_trampoline */
900 "this", /* name_of_this */
901 false, /* store_sym_names_in_linkage_form_p */
902 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
903 basic_lookup_transparent_type
,/* lookup_transparent_type */
904 unk_lang_demangle
, /* Language specific symbol demangler */
906 unk_lang_class_name
, /* Language specific
907 class_name_from_physname */
908 unk_op_print_tab
, /* expression operators for printing */
909 1, /* c-style arrays */
910 0, /* String lower bound */
911 default_word_break_characters
,
912 default_collect_symbol_completion_matches
,
913 unknown_language_arch_info
, /* la_language_arch_info. */
914 default_pass_by_reference
,
915 c_watch_location_expression
,
916 NULL
, /* la_get_symbol_name_matcher */
917 iterate_over_symbols
,
918 default_search_name_hash
,
922 default_is_string_type_p
,
923 "{...}" /* la_struct_too_deep_ellipsis */
926 /* Class representing the fake "auto" language. */
928 class auto_language
: public language_defn
932 : language_defn (language_auto
, auto_language_data
)
936 /* Single instance of the fake "auto" language. */
938 static auto_language auto_language_defn
;
941 /* Per-architecture language information. */
943 static struct gdbarch_data
*language_gdbarch_data
;
945 struct language_gdbarch
947 /* A vector of per-language per-architecture info. Indexed by "enum
949 struct language_arch_info arch_info
[nr_languages
];
953 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
955 struct language_gdbarch
*l
;
957 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
958 for (const auto &lang
: language_defn::languages
)
959 if (lang
!= NULL
&& lang
->la_language_arch_info
!= NULL
)
961 lang
->la_language_arch_info (gdbarch
,
962 l
->arch_info
+ lang
->la_language
);
969 language_string_char_type (const struct language_defn
*la
,
970 struct gdbarch
*gdbarch
)
972 struct language_gdbarch
*ld
973 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
975 return ld
->arch_info
[la
->la_language
].string_char_type
;
979 language_bool_type (const struct language_defn
*la
,
980 struct gdbarch
*gdbarch
)
982 struct language_gdbarch
*ld
983 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
985 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
989 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
990 NULL
, VAR_DOMAIN
, NULL
).symbol
;
993 struct type
*type
= SYMBOL_TYPE (sym
);
995 if (type
&& type
->code () == TYPE_CODE_BOOL
)
1000 return ld
->arch_info
[la
->la_language
].bool_type_default
;
1003 /* Helper function for primitive type lookup. */
1005 static struct type
**
1006 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
1011 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
1013 if (strcmp ((*p
)->name (), name
) == 0)
1019 /* See language.h. */
1022 language_lookup_primitive_type (const struct language_defn
*la
,
1023 struct gdbarch
*gdbarch
,
1026 struct language_gdbarch
*ld
=
1027 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1028 struct type
**typep
;
1030 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
1037 /* Helper function for type lookup as a symbol.
1038 Create the symbol corresponding to type TYPE in language LANG. */
1040 static struct symbol
*
1041 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1043 struct symbol
*symbol
;
1044 struct gdbarch
*gdbarch
;
1046 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1048 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1049 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
1051 symbol
->m_name
= type
->name ();
1052 symbol
->set_language (lang
, nullptr);
1053 symbol
->owner
.arch
= gdbarch
;
1054 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1055 SYMBOL_SECTION (symbol
) = 0;
1056 SYMBOL_TYPE (symbol
) = type
;
1057 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1058 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1063 /* Initialize the primitive type symbols of language LD.
1064 The primitive type vector must have already been initialized. */
1067 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1068 const struct language_defn
*la
,
1069 struct gdbarch
*gdbarch
)
1073 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1075 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1078 lai
->primitive_type_symbols
1079 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1081 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1083 lai
->primitive_type_symbols
[n
]
1084 = language_alloc_type_symbol (la
->la_language
,
1085 lai
->primitive_type_vector
[n
]);
1088 /* Note: The result of symbol lookup is normally a symbol *and* the block
1089 it was found in. Builtin types don't live in blocks. We *could* give
1090 them one, but there is no current need so to keep things simple symbol
1091 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1094 /* See language.h. */
1097 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1098 struct gdbarch
*gdbarch
,
1101 struct language_gdbarch
*ld
1102 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1103 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1104 struct type
**typep
;
1107 if (symbol_lookup_debug
)
1109 fprintf_unfiltered (gdb_stdlog
,
1110 "language_lookup_primitive_type_as_symbol"
1112 la
->la_name
, host_address_to_string (gdbarch
), name
);
1115 typep
= language_lookup_primitive_type_1 (lai
, name
);
1118 if (symbol_lookup_debug
)
1119 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1123 /* The set of symbols is lazily initialized. */
1124 if (lai
->primitive_type_symbols
== NULL
)
1125 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1127 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1129 if (symbol_lookup_debug
)
1130 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1134 /* Initialize the language routines. */
1136 void _initialize_language ();
1138 _initialize_language ()
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_basic_prefix_cmd ("check", no_class
,
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_show_prefix_cmd ("check", no_class
,
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 /* In order to call SET_LANGUAGE (below) we need to make sure that
1181 CURRENT_LANGUAGE is not NULL. So first set the language to unknown,
1182 then we can change the language to 'auto'. */
1183 current_language
= language_def (language_unknown
);
1185 add_set_language_command ();
1189 case_sensitive
= "auto";
1191 /* Have the above take effect. */
1192 set_language (language_auto
);