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 /* The current (default at startup) state of type and range checking.
64 (If the modes are set to "auto", though, these are changed based
65 on the default language at startup, and then again based on the
66 language of the first source file. */
68 enum range_mode range_mode
= range_mode_auto
;
69 enum range_check range_check
= range_check_off
;
70 enum case_mode case_mode
= case_mode_auto
;
71 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
73 /* The current language and language_mode (see language.h). */
75 const struct language_defn
*current_language
= nullptr;
76 enum language_mode language_mode
= language_mode_auto
;
78 /* The language that the user expects to be typing in (the language
79 of main(), or the last language we notified them about, or C). */
81 const struct language_defn
*expected_language
;
83 /* Define the array containing all languages. */
85 const struct language_defn
*language_defn::languages
[nr_languages
];
87 /* The current values of the "set language/range/case-sensitive" enum
89 static const char *language
;
90 static const char *range
;
91 static const char *case_sensitive
;
94 const char lang_frame_mismatch_warn
[] =
95 N_("Warning: the current language does not match this frame.");
97 /* This page contains the functions corresponding to GDB commands
100 /* Show command. Display a warning if the language set
101 does not match the frame. */
103 show_language_command (struct ui_file
*file
, int from_tty
,
104 struct cmd_list_element
*c
, const char *value
)
106 enum language flang
; /* The language of the frame. */
108 if (language_mode
== language_mode_auto
)
109 fprintf_filtered (gdb_stdout
,
110 _("The current source language is "
111 "\"auto; currently %s\".\n"),
112 current_language
->la_name
);
114 fprintf_filtered (gdb_stdout
,
115 _("The current source language is \"%s\".\n"),
116 current_language
->la_name
);
118 if (has_stack_frames ())
120 struct frame_info
*frame
;
122 frame
= get_selected_frame (NULL
);
123 flang
= get_frame_language (frame
);
124 if (flang
!= language_unknown
125 && language_mode
== language_mode_manual
126 && current_language
->la_language
!= flang
)
127 printf_filtered ("%s\n", _(lang_frame_mismatch_warn
));
131 /* Set command. Change the current working language. */
133 set_language_command (const char *ignore
,
134 int from_tty
, struct cmd_list_element
*c
)
136 enum language flang
= language_unknown
;
138 /* "local" is a synonym of "auto". */
139 if (strcmp (language
, "local") == 0)
142 /* Search the list of languages for a match. */
143 for (const auto &lang
: language_defn::languages
)
145 if (strcmp (lang
->la_name
, language
) == 0)
147 /* Found it! Go into manual mode, and use this language. */
148 if (lang
->la_language
== language_auto
)
150 /* Enter auto mode. Set to the current frame's language, if
151 known, or fallback to the initial language. */
152 language_mode
= language_mode_auto
;
155 struct frame_info
*frame
;
157 frame
= get_selected_frame (NULL
);
158 flang
= get_frame_language (frame
);
160 catch (const gdb_exception_error
&ex
)
162 flang
= language_unknown
;
165 if (flang
!= language_unknown
)
166 set_language (flang
);
168 set_initial_language ();
169 expected_language
= current_language
;
174 /* Enter manual mode. Set the specified language. */
175 language_mode
= language_mode_manual
;
176 current_language
= lang
;
178 expected_language
= current_language
;
184 internal_error (__FILE__
, __LINE__
,
185 "Couldn't find language `%s' in known languages list.",
189 /* Show command. Display a warning if the range setting does
190 not match the current language. */
192 show_range_command (struct ui_file
*file
, int from_tty
,
193 struct cmd_list_element
*c
, const char *value
)
195 if (range_mode
== range_mode_auto
)
204 case range_check_off
:
207 case range_check_warn
:
211 internal_error (__FILE__
, __LINE__
,
212 "Unrecognized range check setting.");
215 fprintf_filtered (gdb_stdout
,
216 _("Range checking is \"auto; currently %s\".\n"),
220 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
223 if (range_check
!= current_language
->la_range_check
)
224 warning (_("the current range check setting "
225 "does not match the language.\n"));
228 /* Set command. Change the setting for range checking. */
230 set_range_command (const char *ignore
,
231 int from_tty
, struct cmd_list_element
*c
)
233 if (strcmp (range
, "on") == 0)
235 range_check
= range_check_on
;
236 range_mode
= range_mode_manual
;
238 else if (strcmp (range
, "warn") == 0)
240 range_check
= range_check_warn
;
241 range_mode
= range_mode_manual
;
243 else if (strcmp (range
, "off") == 0)
245 range_check
= range_check_off
;
246 range_mode
= range_mode_manual
;
248 else if (strcmp (range
, "auto") == 0)
250 range_mode
= range_mode_auto
;
256 internal_error (__FILE__
, __LINE__
,
257 _("Unrecognized range check setting: \"%s\""), range
);
259 if (range_check
!= current_language
->la_range_check
)
260 warning (_("the current range check setting "
261 "does not match the language.\n"));
264 /* Show command. Display a warning if the case sensitivity setting does
265 not match the current language. */
267 show_case_command (struct ui_file
*file
, int from_tty
,
268 struct cmd_list_element
*c
, const char *value
)
270 if (case_mode
== case_mode_auto
)
272 const char *tmp
= NULL
;
274 switch (case_sensitivity
)
276 case case_sensitive_on
:
279 case case_sensitive_off
:
283 internal_error (__FILE__
, __LINE__
,
284 "Unrecognized case-sensitive setting.");
287 fprintf_filtered (gdb_stdout
,
288 _("Case sensitivity in "
289 "name search is \"auto; currently %s\".\n"),
293 fprintf_filtered (gdb_stdout
,
294 _("Case sensitivity in name search is \"%s\".\n"),
297 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
298 warning (_("the current case sensitivity setting does not match "
302 /* Set command. Change the setting for case sensitivity. */
305 set_case_command (const char *ignore
, int from_tty
, struct cmd_list_element
*c
)
307 if (strcmp (case_sensitive
, "on") == 0)
309 case_sensitivity
= case_sensitive_on
;
310 case_mode
= case_mode_manual
;
312 else if (strcmp (case_sensitive
, "off") == 0)
314 case_sensitivity
= case_sensitive_off
;
315 case_mode
= case_mode_manual
;
317 else if (strcmp (case_sensitive
, "auto") == 0)
319 case_mode
= case_mode_auto
;
325 internal_error (__FILE__
, __LINE__
,
326 "Unrecognized case-sensitive setting: \"%s\"",
330 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
331 warning (_("the current case sensitivity setting does not match "
335 /* Set the status of range and type checking and case sensitivity based on
336 the current modes and the current language.
337 If SHOW is non-zero, then print out the current language,
338 type and range checking status. */
340 set_range_case (void)
342 if (range_mode
== range_mode_auto
)
343 range_check
= current_language
->la_range_check
;
345 if (case_mode
== case_mode_auto
)
346 case_sensitivity
= current_language
->la_case_sensitivity
;
349 /* Set current language to (enum language) LANG. Returns previous
353 set_language (enum language lang
)
355 enum language prev_language
;
357 prev_language
= current_language
->la_language
;
358 current_language
= language_def (lang
);
360 return prev_language
;
364 /* Print out the current language settings: language, range and
365 type checking. If QUIETLY, print only what has changed. */
368 language_info (int quietly
)
370 if (quietly
&& expected_language
== current_language
)
373 expected_language
= current_language
;
374 printf_unfiltered (_("Current language: %s\n"), language
);
375 show_language_command (NULL
, 1, NULL
, NULL
);
379 printf_unfiltered (_("Range checking: %s\n"), range
);
380 show_range_command (NULL
, 1, NULL
, NULL
);
381 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
382 show_case_command (NULL
, 1, NULL
, NULL
);
387 /* Returns non-zero if the value is a pointer type. */
389 pointer_type (struct type
*type
)
391 return type
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
395 /* This page contains functions that return info about
396 (struct value) values used in GDB. */
398 /* Returns non-zero if the value VAL represents a true value. */
400 value_true (struct value
*val
)
402 /* It is possible that we should have some sort of error if a non-boolean
403 value is used in this context. Possibly dependent on some kind of
404 "boolean-checking" option like range checking. But it should probably
405 not depend on the language except insofar as is necessary to identify
406 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
407 should be an error, probably). */
408 return !value_logical_not (val
);
411 /* This page contains functions for the printing out of
412 error messages that occur during type- and range-
415 /* This is called when a language fails a range-check. The
416 first argument should be a printf()-style format string, and the
417 rest of the arguments should be its arguments. If range_check is
418 range_check_on, an error is printed; if range_check_warn, a warning;
419 otherwise just the message. */
422 range_error (const char *string
,...)
426 va_start (args
, string
);
429 case range_check_warn
:
430 vwarning (string
, args
);
433 verror (string
, args
);
435 case range_check_off
:
436 /* FIXME: cagney/2002-01-30: Should this function print anything
437 when range error is off? */
438 vfprintf_filtered (gdb_stderr
, string
, args
);
439 fprintf_filtered (gdb_stderr
, "\n");
442 internal_error (__FILE__
, __LINE__
, _("bad switch"));
448 /* This page contains miscellaneous functions. */
450 /* Return the language enum for a given language string. */
453 language_enum (const char *str
)
455 for (const auto &lang
: language_defn::languages
)
456 if (strcmp (lang
->la_name
, str
) == 0)
457 return lang
->la_language
;
459 if (strcmp (str
, "local") == 0)
460 return language_auto
;
462 return language_unknown
;
465 /* Return the language struct for a given language enum. */
467 const struct language_defn
*
468 language_def (enum language lang
)
470 const struct language_defn
*l
= language_defn::languages
[lang
];
471 gdb_assert (l
!= nullptr);
475 /* Return the language as a string. */
478 language_str (enum language lang
)
480 return language_def (lang
)->la_name
;
485 /* Build and install the "set language LANG" command. */
488 add_set_language_command ()
490 static const char **language_names
;
492 /* Build the language names array, to be used as enumeration in the
493 "set language" enum command. +1 for "local" and +1 for NULL
495 language_names
= new const char *[ARRAY_SIZE (language_defn::languages
) + 2];
497 /* Display "auto", "local" and "unknown" first, and then the rest,
499 const char **language_names_p
= language_names
;
500 *language_names_p
++ = language_def (language_auto
)->la_name
;
501 *language_names_p
++ = "local";
502 *language_names_p
++ = language_def (language_unknown
)->la_name
;
503 const char **sort_begin
= language_names_p
;
504 for (const auto &lang
: language_defn::languages
)
506 /* Already handled above. */
507 if (lang
->la_language
== language_auto
508 || lang
->la_language
== language_unknown
)
510 *language_names_p
++ = lang
->la_name
;
512 *language_names_p
= NULL
;
513 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
515 /* Add the filename extensions. */
516 for (const auto &lang
: language_defn::languages
)
517 if (lang
->la_filename_extensions
!= NULL
)
519 for (size_t i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
520 add_filename_language (lang
->la_filename_extensions
[i
],
524 /* Build the "help set language" docs. */
527 doc
.printf (_("Set the current source language.\n"
528 "The currently understood settings are:\n\nlocal or "
529 "auto Automatic setting based on source file"));
531 for (const auto &lang
: language_defn::languages
)
533 /* Already dealt with these above. */
534 if (lang
->la_language
== language_unknown
535 || lang
->la_language
== language_auto
)
538 /* FIXME: i18n: for now assume that the human-readable name is
539 just a capitalization of the internal name. */
540 /* Note that we add the newline at the front, so we don't wind
541 up with a trailing newline. */
542 doc
.printf ("\n%-16s Use the %c%s language",
544 /* Capitalize first letter of language name. */
545 toupper (lang
->la_name
[0]),
549 add_setshow_enum_cmd ("language", class_support
,
553 _("Show the current source language."),
554 NULL
, set_language_command
,
555 show_language_command
,
556 &setlist
, &showlist
);
559 /* Iterate through all registered languages looking for and calling
560 any non-NULL struct language_defn.skip_trampoline() functions.
561 Return the result from the first that returns non-zero, or 0 if all
564 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
566 for (const auto &lang
: language_defn::languages
)
568 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
577 /* Return demangled language symbol, or NULL.
578 FIXME: Options are only useful for certain languages and ignored
579 by others, so it would be better to remove them here and have a
580 more flexible demangler for the languages that need it.
581 FIXME: Sometimes the demangler is invoked when we don't know the
582 language, so we can't use this everywhere. */
584 language_demangle (const struct language_defn
*current_language
,
585 const char *mangled
, int options
)
587 if (current_language
!= NULL
)
588 return current_language
->demangle (mangled
, options
);
592 /* Return class name from physname or NULL. */
594 language_class_name_from_physname (const struct language_defn
*lang
,
595 const char *physname
)
597 if (lang
!= NULL
&& lang
->la_class_name_from_physname
)
598 return lang
->la_class_name_from_physname (physname
);
602 /* Return information about whether TYPE should be passed
603 (and returned) by reference at the language level. */
605 struct language_pass_by_ref_info
606 language_pass_by_reference (struct type
*type
)
608 return current_language
->pass_by_reference_info (type
);
611 /* Return the default string containing the list of characters
612 delimiting words. This is a reasonable default value that
613 most languages should be able to use. */
616 default_word_break_characters (void)
618 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
621 /* See language.h. */
624 language_defn::print_array_index (struct type
*index_type
, LONGEST index
,
625 struct ui_file
*stream
,
626 const value_print_options
*options
) const
628 struct value
*index_value
= value_from_longest (index_type
, index
);
630 fprintf_filtered (stream
, "[");
631 LA_VALUE_PRINT (index_value
, stream
, options
);
632 fprintf_filtered (stream
, "] = ");
635 /* See language.h. */
638 default_symbol_name_matcher (const char *symbol_search_name
,
639 const lookup_name_info
&lookup_name
,
640 completion_match_result
*comp_match_res
)
642 gdb::string_view name
= lookup_name
.name ();
643 completion_match_for_lcd
*match_for_lcd
644 = (comp_match_res
!= NULL
? &comp_match_res
->match_for_lcd
: NULL
);
645 strncmp_iw_mode mode
= (lookup_name
.completion_mode ()
646 ? strncmp_iw_mode::NORMAL
647 : strncmp_iw_mode::MATCH_PARAMS
);
649 if (strncmp_iw_with_mode (symbol_search_name
, name
.data (), name
.size (),
650 mode
, language_minimal
, match_for_lcd
) == 0)
652 if (comp_match_res
!= NULL
)
653 comp_match_res
->set_match (symbol_search_name
);
660 /* See language.h. */
663 default_is_string_type_p (struct type
*type
)
665 type
= check_typedef (type
);
666 while (type
->code () == TYPE_CODE_REF
)
668 type
= TYPE_TARGET_TYPE (type
);
669 type
= check_typedef (type
);
671 return (type
->code () == TYPE_CODE_STRING
);
674 /* See language.h. */
676 symbol_name_matcher_ftype
*
677 get_symbol_name_matcher (const language_defn
*lang
,
678 const lookup_name_info
&lookup_name
)
680 /* If currently in Ada mode, and the lookup name is wrapped in
681 '<...>', hijack all symbol name comparisons using the Ada
682 matcher, which handles the verbatim matching. */
683 if (current_language
->la_language
== language_ada
684 && lookup_name
.ada ().verbatim_p ())
685 return current_language
->la_get_symbol_name_matcher (lookup_name
);
687 if (lang
->la_get_symbol_name_matcher
!= nullptr)
688 return lang
->la_get_symbol_name_matcher (lookup_name
);
689 return default_symbol_name_matcher
;
692 /* Define the language that is no language. */
695 unk_lang_parser (struct parser_state
*ps
)
701 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
704 error (_("internal error - unimplemented "
705 "function unk_lang_emit_char called."));
709 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
711 error (_("internal error - unimplemented "
712 "function unk_lang_printchar called."));
716 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
717 const gdb_byte
*string
, unsigned int length
,
718 const char *encoding
, int force_ellipses
,
719 const struct value_print_options
*options
)
721 error (_("internal error - unimplemented "
722 "function unk_lang_printstr called."));
726 unk_lang_value_print_inner (struct value
*val
,
727 struct ui_file
*stream
, int recurse
,
728 const struct value_print_options
*options
)
730 error (_("internal error - unimplemented "
731 "function unk_lang_value_print_inner called."));
735 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
736 const struct value_print_options
*options
)
738 error (_("internal error - unimplemented "
739 "function unk_lang_value_print called."));
742 static char *unk_lang_class_name (const char *mangled
)
747 static const struct op_print unk_op_print_tab
[] =
749 {NULL
, OP_NULL
, PREC_NULL
, 0}
753 unknown_language_arch_info (struct gdbarch
*gdbarch
,
754 struct language_arch_info
*lai
)
756 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
757 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
758 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
762 /* Constant data that describes the unknown language. */
764 extern const struct language_data unknown_language_data
=
774 &exp_descriptor_standard
,
777 unk_lang_printchar
, /* Print character constant */
780 default_print_typedef
, /* Print a typedef using appropriate syntax */
781 unk_lang_value_print_inner
, /* la_value_print_inner */
782 unk_lang_value_print
, /* Print a top-level value */
783 "this", /* name_of_this */
784 true, /* store_sym_names_in_linkage_form_p */
785 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
786 unk_lang_class_name
, /* Language specific
787 class_name_from_physname */
788 unk_op_print_tab
, /* expression operators for printing */
789 1, /* c-style arrays */
790 0, /* String lower bound */
791 default_word_break_characters
,
792 default_collect_symbol_completion_matches
,
793 c_watch_location_expression
,
794 NULL
, /* la_get_symbol_name_matcher */
797 default_is_string_type_p
,
798 "{...}" /* la_struct_too_deep_ellipsis */
801 /* Class representing the unknown language. */
803 class unknown_language
: public language_defn
807 : language_defn (language_unknown
, unknown_language_data
)
810 /* See language.h. */
811 void language_arch_info (struct gdbarch
*gdbarch
,
812 struct language_arch_info
*lai
) const override
814 unknown_language_arch_info (gdbarch
, lai
);
817 /* See language.h. */
819 void print_type (struct type
*type
, const char *varstring
,
820 struct ui_file
*stream
, int show
, int level
,
821 const struct type_print_options
*flags
) const override
823 error (_("unimplemented unknown_language::print_type called"));
826 /* See language.h. */
828 char *demangle (const char *mangled
, int options
) const override
830 /* The unknown language just uses the C++ demangler. */
831 return gdb_demangle (mangled
, options
);
835 /* Single instance of the unknown language class. */
837 static unknown_language unknown_language_defn
;
839 /* Constant data for the fake "auto" language. */
841 extern const struct language_data auto_language_data
=
851 &exp_descriptor_standard
,
854 unk_lang_printchar
, /* Print character constant */
857 default_print_typedef
, /* Print a typedef using appropriate syntax */
858 unk_lang_value_print_inner
, /* la_value_print_inner */
859 unk_lang_value_print
, /* Print a top-level value */
860 "this", /* name_of_this */
861 false, /* store_sym_names_in_linkage_form_p */
862 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
863 unk_lang_class_name
, /* Language specific
864 class_name_from_physname */
865 unk_op_print_tab
, /* expression operators for printing */
866 1, /* c-style arrays */
867 0, /* String lower bound */
868 default_word_break_characters
,
869 default_collect_symbol_completion_matches
,
870 c_watch_location_expression
,
871 NULL
, /* la_get_symbol_name_matcher */
874 default_is_string_type_p
,
875 "{...}" /* la_struct_too_deep_ellipsis */
878 /* Class representing the fake "auto" language. */
880 class auto_language
: public language_defn
884 : language_defn (language_auto
, auto_language_data
)
887 /* See language.h. */
888 void language_arch_info (struct gdbarch
*gdbarch
,
889 struct language_arch_info
*lai
) const override
891 unknown_language_arch_info (gdbarch
, lai
);
894 /* See language.h. */
896 void print_type (struct type
*type
, const char *varstring
,
897 struct ui_file
*stream
, int show
, int level
,
898 const struct type_print_options
*flags
) const override
900 error (_("unimplemented auto_language::print_type called"));
903 /* See language.h. */
905 char *demangle (const char *mangled
, int options
) const override
907 /* The auto language just uses the C++ demangler. */
908 return gdb_demangle (mangled
, options
);
912 /* Single instance of the fake "auto" language. */
914 static auto_language auto_language_defn
;
917 /* Per-architecture language information. */
919 static struct gdbarch_data
*language_gdbarch_data
;
921 struct language_gdbarch
923 /* A vector of per-language per-architecture info. Indexed by "enum
925 struct language_arch_info arch_info
[nr_languages
];
929 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
931 struct language_gdbarch
*l
;
933 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
934 for (const auto &lang
: language_defn::languages
)
936 gdb_assert (lang
!= nullptr);
937 lang
->language_arch_info (gdbarch
,
938 l
->arch_info
+ lang
->la_language
);
945 language_string_char_type (const struct language_defn
*la
,
946 struct gdbarch
*gdbarch
)
948 struct language_gdbarch
*ld
949 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
951 return ld
->arch_info
[la
->la_language
].string_char_type
;
955 language_bool_type (const struct language_defn
*la
,
956 struct gdbarch
*gdbarch
)
958 struct language_gdbarch
*ld
959 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
961 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
965 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
966 NULL
, VAR_DOMAIN
, NULL
).symbol
;
969 struct type
*type
= SYMBOL_TYPE (sym
);
971 if (type
&& type
->code () == TYPE_CODE_BOOL
)
976 return ld
->arch_info
[la
->la_language
].bool_type_default
;
979 /* Helper function for primitive type lookup. */
981 static struct type
**
982 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
987 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
989 if (strcmp ((*p
)->name (), name
) == 0)
995 /* See language.h. */
998 language_lookup_primitive_type (const struct language_defn
*la
,
999 struct gdbarch
*gdbarch
,
1002 struct language_gdbarch
*ld
=
1003 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1004 struct type
**typep
;
1006 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
1013 /* Helper function for type lookup as a symbol.
1014 Create the symbol corresponding to type TYPE in language LANG. */
1016 static struct symbol
*
1017 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1019 struct symbol
*symbol
;
1020 struct gdbarch
*gdbarch
;
1022 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1024 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1025 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
1027 symbol
->m_name
= type
->name ();
1028 symbol
->set_language (lang
, nullptr);
1029 symbol
->owner
.arch
= gdbarch
;
1030 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1031 SYMBOL_SECTION (symbol
) = 0;
1032 SYMBOL_TYPE (symbol
) = type
;
1033 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1034 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1039 /* Initialize the primitive type symbols of language LD.
1040 The primitive type vector must have already been initialized. */
1043 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1044 const struct language_defn
*la
,
1045 struct gdbarch
*gdbarch
)
1049 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1051 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1054 lai
->primitive_type_symbols
1055 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1057 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1059 lai
->primitive_type_symbols
[n
]
1060 = language_alloc_type_symbol (la
->la_language
,
1061 lai
->primitive_type_vector
[n
]);
1064 /* Note: The result of symbol lookup is normally a symbol *and* the block
1065 it was found in. Builtin types don't live in blocks. We *could* give
1066 them one, but there is no current need so to keep things simple symbol
1067 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1070 /* See language.h. */
1073 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1074 struct gdbarch
*gdbarch
,
1077 struct language_gdbarch
*ld
1078 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1079 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1080 struct type
**typep
;
1083 if (symbol_lookup_debug
)
1085 fprintf_unfiltered (gdb_stdlog
,
1086 "language_lookup_primitive_type_as_symbol"
1088 la
->la_name
, host_address_to_string (gdbarch
), name
);
1091 typep
= language_lookup_primitive_type_1 (lai
, name
);
1094 if (symbol_lookup_debug
)
1095 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1099 /* The set of symbols is lazily initialized. */
1100 if (lai
->primitive_type_symbols
== NULL
)
1101 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1103 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1105 if (symbol_lookup_debug
)
1106 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1110 /* Initialize the language routines. */
1112 void _initialize_language ();
1114 _initialize_language ()
1116 static const char *const type_or_range_names
[]
1117 = { "on", "off", "warn", "auto", NULL
};
1119 static const char *const case_sensitive_names
[]
1120 = { "on", "off", "auto", NULL
};
1122 language_gdbarch_data
1123 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1125 /* GDB commands for language specific stuff. */
1127 add_basic_prefix_cmd ("check", no_class
,
1128 _("Set the status of the type/range checker."),
1129 &setchecklist
, "set check ", 0, &setlist
);
1130 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1131 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1133 add_show_prefix_cmd ("check", no_class
,
1134 _("Show the status of the type/range checker."),
1135 &showchecklist
, "show check ", 0, &showlist
);
1136 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1137 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1139 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1141 _("Set range checking (on/warn/off/auto)."),
1142 _("Show range checking (on/warn/off/auto)."),
1143 NULL
, set_range_command
,
1145 &setchecklist
, &showchecklist
);
1147 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1148 &case_sensitive
, _("\
1149 Set case sensitivity in name search (on/off/auto)."), _("\
1150 Show case sensitivity in name search (on/off/auto)."), _("\
1151 For Fortran the default is off; for other languages the default is on."),
1154 &setlist
, &showlist
);
1156 /* In order to call SET_LANGUAGE (below) we need to make sure that
1157 CURRENT_LANGUAGE is not NULL. So first set the language to unknown,
1158 then we can change the language to 'auto'. */
1159 current_language
= language_def (language_unknown
);
1161 add_set_language_command ();
1165 case_sensitive
= "auto";
1167 /* Have the above take effect. */
1168 set_language (language_auto
);