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 /* The current (default at startup) state of type and range checking.
61 (If the modes are set to "auto", though, these are changed based
62 on the default language at startup, and then again based on the
63 language of the first source file. */
65 enum range_mode range_mode
= range_mode_auto
;
66 enum range_check range_check
= range_check_off
;
67 enum case_mode case_mode
= case_mode_auto
;
68 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
70 /* The current language and language_mode (see language.h). */
72 const struct language_defn
*current_language
= nullptr;
73 enum language_mode language_mode
= language_mode_auto
;
75 /* The language that the user expects to be typing in (the language
76 of main(), or the last language we notified them about, or C). */
78 const struct language_defn
*expected_language
;
80 /* Define the array containing all languages. */
82 const struct language_defn
*language_defn::languages
[nr_languages
];
84 /* The current values of the "set language/range/case-sensitive" enum
86 static const char *language
;
87 static const char *range
;
88 static const char *case_sensitive
;
91 const char lang_frame_mismatch_warn
[] =
92 N_("Warning: the current language does not match this frame.");
94 /* This page contains the functions corresponding to GDB commands
97 /* Show command. Display a warning if the language set
98 does not match the frame. */
100 show_language_command (struct ui_file
*file
, int from_tty
,
101 struct cmd_list_element
*c
, const char *value
)
103 enum language flang
; /* The language of the frame. */
105 if (language_mode
== language_mode_auto
)
106 fprintf_filtered (gdb_stdout
,
107 _("The current source language is "
108 "\"auto; currently %s\".\n"),
109 current_language
->la_name
);
111 fprintf_filtered (gdb_stdout
,
112 _("The current source language is \"%s\".\n"),
113 current_language
->la_name
);
115 if (has_stack_frames ())
117 struct frame_info
*frame
;
119 frame
= get_selected_frame (NULL
);
120 flang
= get_frame_language (frame
);
121 if (flang
!= language_unknown
122 && language_mode
== language_mode_manual
123 && current_language
->la_language
!= flang
)
124 printf_filtered ("%s\n", _(lang_frame_mismatch_warn
));
128 /* Set command. Change the current working language. */
130 set_language_command (const char *ignore
,
131 int from_tty
, struct cmd_list_element
*c
)
133 enum language flang
= language_unknown
;
135 /* "local" is a synonym of "auto". */
136 if (strcmp (language
, "local") == 0)
139 /* Search the list of languages for a match. */
140 for (const auto &lang
: language_defn::languages
)
142 if (strcmp (lang
->la_name
, language
) == 0)
144 /* Found it! Go into manual mode, and use this language. */
145 if (lang
->la_language
== language_auto
)
147 /* Enter auto mode. Set to the current frame's language, if
148 known, or fallback to the initial language. */
149 language_mode
= language_mode_auto
;
152 struct frame_info
*frame
;
154 frame
= get_selected_frame (NULL
);
155 flang
= get_frame_language (frame
);
157 catch (const gdb_exception_error
&ex
)
159 flang
= language_unknown
;
162 if (flang
!= language_unknown
)
163 set_language (flang
);
165 set_initial_language ();
166 expected_language
= current_language
;
171 /* Enter manual mode. Set the specified language. */
172 language_mode
= language_mode_manual
;
173 current_language
= lang
;
175 expected_language
= current_language
;
181 internal_error (__FILE__
, __LINE__
,
182 "Couldn't find language `%s' in known languages list.",
186 /* Show command. Display a warning if the range setting does
187 not match the current language. */
189 show_range_command (struct ui_file
*file
, int from_tty
,
190 struct cmd_list_element
*c
, const char *value
)
192 if (range_mode
== range_mode_auto
)
201 case range_check_off
:
204 case range_check_warn
:
208 internal_error (__FILE__
, __LINE__
,
209 "Unrecognized range check setting.");
212 fprintf_filtered (gdb_stdout
,
213 _("Range checking is \"auto; currently %s\".\n"),
217 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
220 if (range_check
!= current_language
->la_range_check
)
221 warning (_("the current range check setting "
222 "does not match the language.\n"));
225 /* Set command. Change the setting for range checking. */
227 set_range_command (const char *ignore
,
228 int from_tty
, struct cmd_list_element
*c
)
230 if (strcmp (range
, "on") == 0)
232 range_check
= range_check_on
;
233 range_mode
= range_mode_manual
;
235 else if (strcmp (range
, "warn") == 0)
237 range_check
= range_check_warn
;
238 range_mode
= range_mode_manual
;
240 else if (strcmp (range
, "off") == 0)
242 range_check
= range_check_off
;
243 range_mode
= range_mode_manual
;
245 else if (strcmp (range
, "auto") == 0)
247 range_mode
= range_mode_auto
;
253 internal_error (__FILE__
, __LINE__
,
254 _("Unrecognized range check setting: \"%s\""), range
);
256 if (range_check
!= current_language
->la_range_check
)
257 warning (_("the current range check setting "
258 "does not match the language.\n"));
261 /* Show command. Display a warning if the case sensitivity setting does
262 not match the current language. */
264 show_case_command (struct ui_file
*file
, int from_tty
,
265 struct cmd_list_element
*c
, const char *value
)
267 if (case_mode
== case_mode_auto
)
269 const char *tmp
= NULL
;
271 switch (case_sensitivity
)
273 case case_sensitive_on
:
276 case case_sensitive_off
:
280 internal_error (__FILE__
, __LINE__
,
281 "Unrecognized case-sensitive setting.");
284 fprintf_filtered (gdb_stdout
,
285 _("Case sensitivity in "
286 "name search is \"auto; currently %s\".\n"),
290 fprintf_filtered (gdb_stdout
,
291 _("Case sensitivity in name search is \"%s\".\n"),
294 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
295 warning (_("the current case sensitivity setting does not match "
299 /* Set command. Change the setting for case sensitivity. */
302 set_case_command (const char *ignore
, int from_tty
, struct cmd_list_element
*c
)
304 if (strcmp (case_sensitive
, "on") == 0)
306 case_sensitivity
= case_sensitive_on
;
307 case_mode
= case_mode_manual
;
309 else if (strcmp (case_sensitive
, "off") == 0)
311 case_sensitivity
= case_sensitive_off
;
312 case_mode
= case_mode_manual
;
314 else if (strcmp (case_sensitive
, "auto") == 0)
316 case_mode
= case_mode_auto
;
322 internal_error (__FILE__
, __LINE__
,
323 "Unrecognized case-sensitive setting: \"%s\"",
327 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
328 warning (_("the current case sensitivity setting does not match "
332 /* Set the status of range and type checking and case sensitivity based on
333 the current modes and the current language.
334 If SHOW is non-zero, then print out the current language,
335 type and range checking status. */
337 set_range_case (void)
339 if (range_mode
== range_mode_auto
)
340 range_check
= current_language
->la_range_check
;
342 if (case_mode
== case_mode_auto
)
343 case_sensitivity
= current_language
->la_case_sensitivity
;
346 /* Set current language to (enum language) LANG. Returns previous
350 set_language (enum language lang
)
352 enum language prev_language
;
354 prev_language
= current_language
->la_language
;
355 current_language
= language_def (lang
);
357 return prev_language
;
361 /* Print out the current language settings: language, range and
362 type checking. If QUIETLY, print only what has changed. */
365 language_info (int quietly
)
367 if (quietly
&& expected_language
== current_language
)
370 expected_language
= current_language
;
371 printf_unfiltered (_("Current language: %s\n"), language
);
372 show_language_command (NULL
, 1, NULL
, NULL
);
376 printf_unfiltered (_("Range checking: %s\n"), range
);
377 show_range_command (NULL
, 1, NULL
, NULL
);
378 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
379 show_case_command (NULL
, 1, NULL
, NULL
);
384 /* Returns non-zero if the value is a pointer type. */
386 pointer_type (struct type
*type
)
388 return type
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
392 /* This page contains functions that return info about
393 (struct value) values used in GDB. */
395 /* Returns non-zero if the value VAL represents a true value. */
397 value_true (struct value
*val
)
399 /* It is possible that we should have some sort of error if a non-boolean
400 value is used in this context. Possibly dependent on some kind of
401 "boolean-checking" option like range checking. But it should probably
402 not depend on the language except insofar as is necessary to identify
403 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
404 should be an error, probably). */
405 return !value_logical_not (val
);
408 /* This page contains functions for the printing out of
409 error messages that occur during type- and range-
412 /* This is called when a language fails a range-check. The
413 first argument should be a printf()-style format string, and the
414 rest of the arguments should be its arguments. If range_check is
415 range_check_on, an error is printed; if range_check_warn, a warning;
416 otherwise just the message. */
419 range_error (const char *string
,...)
423 va_start (args
, string
);
426 case range_check_warn
:
427 vwarning (string
, args
);
430 verror (string
, args
);
432 case range_check_off
:
433 /* FIXME: cagney/2002-01-30: Should this function print anything
434 when range error is off? */
435 vfprintf_filtered (gdb_stderr
, string
, args
);
436 fprintf_filtered (gdb_stderr
, "\n");
439 internal_error (__FILE__
, __LINE__
, _("bad switch"));
445 /* This page contains miscellaneous functions. */
447 /* Return the language enum for a given language string. */
450 language_enum (const char *str
)
452 for (const auto &lang
: language_defn::languages
)
453 if (strcmp (lang
->la_name
, str
) == 0)
454 return lang
->la_language
;
456 if (strcmp (str
, "local") == 0)
457 return language_auto
;
459 return language_unknown
;
462 /* Return the language struct for a given language enum. */
464 const struct language_defn
*
465 language_def (enum language lang
)
467 const struct language_defn
*l
= language_defn::languages
[lang
];
468 gdb_assert (l
!= nullptr);
472 /* Return the language as a string. */
475 language_str (enum language lang
)
477 return language_def (lang
)->la_name
;
482 /* Build and install the "set language LANG" command. */
485 add_set_language_command ()
487 static const char **language_names
;
489 /* Build the language names array, to be used as enumeration in the
490 "set language" enum command. +1 for "local" and +1 for NULL
492 language_names
= new const char *[ARRAY_SIZE (language_defn::languages
) + 2];
494 /* Display "auto", "local" and "unknown" first, and then the rest,
496 const char **language_names_p
= language_names
;
497 *language_names_p
++ = language_def (language_auto
)->la_name
;
498 *language_names_p
++ = "local";
499 *language_names_p
++ = language_def (language_unknown
)->la_name
;
500 const char **sort_begin
= language_names_p
;
501 for (const auto &lang
: language_defn::languages
)
503 /* Already handled above. */
504 if (lang
->la_language
== language_auto
505 || lang
->la_language
== language_unknown
)
507 *language_names_p
++ = lang
->la_name
;
509 *language_names_p
= NULL
;
510 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
512 /* Add the filename extensions. */
513 for (const auto &lang
: language_defn::languages
)
514 if (lang
->la_filename_extensions
!= NULL
)
516 for (size_t i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
517 add_filename_language (lang
->la_filename_extensions
[i
],
521 /* Build the "help set language" docs. */
524 doc
.printf (_("Set the current source language.\n"
525 "The currently understood settings are:\n\nlocal or "
526 "auto Automatic setting based on source file"));
528 for (const auto &lang
: language_defn::languages
)
530 /* Already dealt with these above. */
531 if (lang
->la_language
== language_unknown
532 || lang
->la_language
== language_auto
)
535 /* FIXME: i18n: for now assume that the human-readable name is
536 just a capitalization of the internal name. */
537 /* Note that we add the newline at the front, so we don't wind
538 up with a trailing newline. */
539 doc
.printf ("\n%-16s Use the %c%s language",
541 /* Capitalize first letter of language name. */
542 toupper (lang
->la_name
[0]),
546 add_setshow_enum_cmd ("language", class_support
,
550 _("Show the current source language."),
551 NULL
, set_language_command
,
552 show_language_command
,
553 &setlist
, &showlist
);
556 /* Iterate through all registered languages looking for and calling
557 any non-NULL struct language_defn.skip_trampoline() functions.
558 Return the result from the first that returns non-zero, or 0 if all
561 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
563 for (const auto &lang
: language_defn::languages
)
565 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
574 /* Return demangled language symbol, or NULL.
575 FIXME: Options are only useful for certain languages and ignored
576 by others, so it would be better to remove them here and have a
577 more flexible demangler for the languages that need it.
578 FIXME: Sometimes the demangler is invoked when we don't know the
579 language, so we can't use this everywhere. */
581 language_demangle (const struct language_defn
*current_language
,
582 const char *mangled
, int options
)
584 if (current_language
!= NULL
)
585 return current_language
->demangle (mangled
, options
);
589 /* Return information about whether TYPE should be passed
590 (and returned) by reference at the language level. */
592 struct language_pass_by_ref_info
593 language_pass_by_reference (struct type
*type
)
595 return current_language
->pass_by_reference_info (type
);
598 /* Return the default string containing the list of characters
599 delimiting words. This is a reasonable default value that
600 most languages should be able to use. */
603 default_word_break_characters (void)
605 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
608 /* See language.h. */
611 language_defn::print_array_index (struct type
*index_type
, LONGEST index
,
612 struct ui_file
*stream
,
613 const value_print_options
*options
) const
615 struct value
*index_value
= value_from_longest (index_type
, index
);
617 fprintf_filtered (stream
, "[");
618 LA_VALUE_PRINT (index_value
, stream
, options
);
619 fprintf_filtered (stream
, "] = ");
622 /* See language.h. */
624 gdb::unique_xmalloc_ptr
<char>
625 language_defn::watch_location_expression (struct type
*type
,
626 CORE_ADDR addr
) const
628 /* Generates an expression that assumes a C like syntax is valid. */
629 type
= check_typedef (TYPE_TARGET_TYPE (check_typedef (type
)));
630 std::string name
= type_to_string (type
);
631 return gdb::unique_xmalloc_ptr
<char>
632 (xstrprintf ("* (%s *) %s", name
.c_str (), core_addr_to_string (addr
)));
635 /* See language.h. */
638 language_defn::value_print (struct value
*val
, struct ui_file
*stream
,
639 const struct value_print_options
*options
) const
641 return c_value_print (val
, stream
, options
);
644 /* See language.h. */
647 language_defn::value_print_inner
648 (struct value
*val
, struct ui_file
*stream
, int recurse
,
649 const struct value_print_options
*options
) const
651 return c_value_print_inner (val
, stream
, recurse
, options
);
654 /* The default implementation of the get_symbol_name_matcher_inner method
655 from the language_defn class. Matches with strncmp_iw. */
658 default_symbol_name_matcher (const char *symbol_search_name
,
659 const lookup_name_info
&lookup_name
,
660 completion_match_result
*comp_match_res
)
662 gdb::string_view name
= lookup_name
.name ();
663 completion_match_for_lcd
*match_for_lcd
664 = (comp_match_res
!= NULL
? &comp_match_res
->match_for_lcd
: NULL
);
665 strncmp_iw_mode mode
= (lookup_name
.completion_mode ()
666 ? strncmp_iw_mode::NORMAL
667 : strncmp_iw_mode::MATCH_PARAMS
);
669 if (strncmp_iw_with_mode (symbol_search_name
, name
.data (), name
.size (),
670 mode
, language_minimal
, match_for_lcd
) == 0)
672 if (comp_match_res
!= NULL
)
673 comp_match_res
->set_match (symbol_search_name
);
680 /* See language.h. */
682 symbol_name_matcher_ftype
*
683 language_defn::get_symbol_name_matcher
684 (const lookup_name_info
&lookup_name
) const
686 /* If currently in Ada mode, and the lookup name is wrapped in
687 '<...>', hijack all symbol name comparisons using the Ada
688 matcher, which handles the verbatim matching. */
689 if (current_language
->la_language
== language_ada
690 && lookup_name
.ada ().verbatim_p ())
691 return current_language
->get_symbol_name_matcher_inner (lookup_name
);
693 return this->get_symbol_name_matcher_inner (lookup_name
);
696 /* See language.h. */
698 symbol_name_matcher_ftype
*
699 language_defn::get_symbol_name_matcher_inner
700 (const lookup_name_info
&lookup_name
) const
702 return default_symbol_name_matcher
;
705 /* See language.h. */
708 default_is_string_type_p (struct type
*type
)
710 type
= check_typedef (type
);
711 while (type
->code () == TYPE_CODE_REF
)
713 type
= TYPE_TARGET_TYPE (type
);
714 type
= check_typedef (type
);
716 return (type
->code () == TYPE_CODE_STRING
);
719 /* Define the language that is no language. */
722 unk_lang_parser (struct parser_state
*ps
)
728 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
731 error (_("internal error - unimplemented "
732 "function unk_lang_emit_char called."));
736 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
738 error (_("internal error - unimplemented "
739 "function unk_lang_printchar called."));
743 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
744 const gdb_byte
*string
, unsigned int length
,
745 const char *encoding
, int force_ellipses
,
746 const struct value_print_options
*options
)
748 error (_("internal error - unimplemented "
749 "function unk_lang_printstr called."));
752 static const struct op_print unk_op_print_tab
[] =
754 {NULL
, OP_NULL
, PREC_NULL
, 0}
758 unknown_language_arch_info (struct gdbarch
*gdbarch
,
759 struct language_arch_info
*lai
)
761 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
762 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
763 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
767 /* Constant data that describes the unknown language. */
769 extern const struct language_data unknown_language_data
=
779 &exp_descriptor_standard
,
782 unk_lang_printchar
, /* Print character constant */
785 default_print_typedef
, /* Print a typedef using appropriate syntax */
786 "this", /* name_of_this */
787 true, /* store_sym_names_in_linkage_form_p */
788 unk_op_print_tab
, /* expression operators for printing */
789 1, /* c-style arrays */
790 0, /* String lower bound */
792 default_is_string_type_p
,
793 "{...}" /* la_struct_too_deep_ellipsis */
796 /* Class representing the unknown language. */
798 class unknown_language
: public language_defn
802 : language_defn (language_unknown
, unknown_language_data
)
805 /* See language.h. */
806 void language_arch_info (struct gdbarch
*gdbarch
,
807 struct language_arch_info
*lai
) const override
809 unknown_language_arch_info (gdbarch
, lai
);
812 /* See language.h. */
814 void print_type (struct type
*type
, const char *varstring
,
815 struct ui_file
*stream
, int show
, int level
,
816 const struct type_print_options
*flags
) const override
818 error (_("unimplemented unknown_language::print_type called"));
821 /* See language.h. */
823 char *demangle (const char *mangled
, int options
) const override
825 /* The unknown language just uses the C++ demangler. */
826 return gdb_demangle (mangled
, options
);
829 /* See language.h. */
831 void value_print (struct value
*val
, struct ui_file
*stream
,
832 const struct value_print_options
*options
) const override
834 error (_("unimplemented unknown_language::value_print called"));
837 /* See language.h. */
839 void value_print_inner
840 (struct value
*val
, struct ui_file
*stream
, int recurse
,
841 const struct value_print_options
*options
) const override
843 error (_("unimplemented unknown_language::value_print_inner called"));
847 /* Single instance of the unknown language class. */
849 static unknown_language unknown_language_defn
;
851 /* Constant data for the fake "auto" language. */
853 extern const struct language_data auto_language_data
=
863 &exp_descriptor_standard
,
866 unk_lang_printchar
, /* Print character constant */
869 default_print_typedef
, /* Print a typedef using appropriate syntax */
870 "this", /* name_of_this */
871 false, /* store_sym_names_in_linkage_form_p */
872 unk_op_print_tab
, /* expression operators for printing */
873 1, /* c-style arrays */
874 0, /* String lower bound */
876 default_is_string_type_p
,
877 "{...}" /* la_struct_too_deep_ellipsis */
880 /* Class representing the fake "auto" language. */
882 class auto_language
: public language_defn
886 : language_defn (language_auto
, auto_language_data
)
889 /* See language.h. */
890 void language_arch_info (struct gdbarch
*gdbarch
,
891 struct language_arch_info
*lai
) const override
893 unknown_language_arch_info (gdbarch
, lai
);
896 /* See language.h. */
898 void print_type (struct type
*type
, const char *varstring
,
899 struct ui_file
*stream
, int show
, int level
,
900 const struct type_print_options
*flags
) const override
902 error (_("unimplemented auto_language::print_type called"));
905 /* See language.h. */
907 char *demangle (const char *mangled
, int options
) const override
909 /* The auto language just uses the C++ demangler. */
910 return gdb_demangle (mangled
, options
);
913 /* See language.h. */
915 void value_print (struct value
*val
, struct ui_file
*stream
,
916 const struct value_print_options
*options
) const override
918 error (_("unimplemented auto_language::value_print called"));
921 /* See language.h. */
923 void value_print_inner
924 (struct value
*val
, struct ui_file
*stream
, int recurse
,
925 const struct value_print_options
*options
) const override
927 error (_("unimplemented auto_language::value_print_inner called"));
931 /* Single instance of the fake "auto" language. */
933 static auto_language auto_language_defn
;
936 /* Per-architecture language information. */
938 static struct gdbarch_data
*language_gdbarch_data
;
940 struct language_gdbarch
942 /* A vector of per-language per-architecture info. Indexed by "enum
944 struct language_arch_info arch_info
[nr_languages
];
948 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
950 struct language_gdbarch
*l
;
952 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
953 for (const auto &lang
: language_defn::languages
)
955 gdb_assert (lang
!= nullptr);
956 lang
->language_arch_info (gdbarch
,
957 l
->arch_info
+ lang
->la_language
);
964 language_string_char_type (const struct language_defn
*la
,
965 struct gdbarch
*gdbarch
)
967 struct language_gdbarch
*ld
968 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
970 return ld
->arch_info
[la
->la_language
].string_char_type
;
974 language_bool_type (const struct language_defn
*la
,
975 struct gdbarch
*gdbarch
)
977 struct language_gdbarch
*ld
978 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
980 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
984 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
985 NULL
, VAR_DOMAIN
, NULL
).symbol
;
988 struct type
*type
= SYMBOL_TYPE (sym
);
990 if (type
&& type
->code () == TYPE_CODE_BOOL
)
995 return ld
->arch_info
[la
->la_language
].bool_type_default
;
998 /* Helper function for primitive type lookup. */
1000 static struct type
**
1001 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
1006 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
1008 if (strcmp ((*p
)->name (), name
) == 0)
1014 /* See language.h. */
1017 language_lookup_primitive_type (const struct language_defn
*la
,
1018 struct gdbarch
*gdbarch
,
1021 struct language_gdbarch
*ld
=
1022 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1023 struct type
**typep
;
1025 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
1032 /* Helper function for type lookup as a symbol.
1033 Create the symbol corresponding to type TYPE in language LANG. */
1035 static struct symbol
*
1036 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1038 struct symbol
*symbol
;
1039 struct gdbarch
*gdbarch
;
1041 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1043 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1044 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
1046 symbol
->m_name
= type
->name ();
1047 symbol
->set_language (lang
, nullptr);
1048 symbol
->owner
.arch
= gdbarch
;
1049 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1050 SYMBOL_SECTION (symbol
) = 0;
1051 SYMBOL_TYPE (symbol
) = type
;
1052 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1053 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1058 /* Initialize the primitive type symbols of language LD.
1059 The primitive type vector must have already been initialized. */
1062 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1063 const struct language_defn
*la
,
1064 struct gdbarch
*gdbarch
)
1068 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1070 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1073 lai
->primitive_type_symbols
1074 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1076 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1078 lai
->primitive_type_symbols
[n
]
1079 = language_alloc_type_symbol (la
->la_language
,
1080 lai
->primitive_type_vector
[n
]);
1083 /* Note: The result of symbol lookup is normally a symbol *and* the block
1084 it was found in. Builtin types don't live in blocks. We *could* give
1085 them one, but there is no current need so to keep things simple symbol
1086 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1089 /* See language.h. */
1092 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1093 struct gdbarch
*gdbarch
,
1096 struct language_gdbarch
*ld
1097 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1098 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1099 struct type
**typep
;
1102 if (symbol_lookup_debug
)
1104 fprintf_unfiltered (gdb_stdlog
,
1105 "language_lookup_primitive_type_as_symbol"
1107 la
->la_name
, host_address_to_string (gdbarch
), name
);
1110 typep
= language_lookup_primitive_type_1 (lai
, name
);
1113 if (symbol_lookup_debug
)
1114 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1118 /* The set of symbols is lazily initialized. */
1119 if (lai
->primitive_type_symbols
== NULL
)
1120 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1122 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1124 if (symbol_lookup_debug
)
1125 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1129 /* Initialize the language routines. */
1131 void _initialize_language ();
1133 _initialize_language ()
1135 static const char *const type_or_range_names
[]
1136 = { "on", "off", "warn", "auto", NULL
};
1138 static const char *const case_sensitive_names
[]
1139 = { "on", "off", "auto", NULL
};
1141 language_gdbarch_data
1142 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1144 /* GDB commands for language specific stuff. */
1146 add_basic_prefix_cmd ("check", no_class
,
1147 _("Set the status of the type/range checker."),
1148 &setchecklist
, "set check ", 0, &setlist
);
1149 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1150 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1152 add_show_prefix_cmd ("check", no_class
,
1153 _("Show the status of the type/range checker."),
1154 &showchecklist
, "show check ", 0, &showlist
);
1155 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1156 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1158 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1160 _("Set range checking (on/warn/off/auto)."),
1161 _("Show range checking (on/warn/off/auto)."),
1162 NULL
, set_range_command
,
1164 &setchecklist
, &showchecklist
);
1166 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1167 &case_sensitive
, _("\
1168 Set case sensitivity in name search (on/off/auto)."), _("\
1169 Show case sensitivity in name search (on/off/auto)."), _("\
1170 For Fortran the default is off; for other languages the default is on."),
1173 &setlist
, &showlist
);
1175 /* In order to call SET_LANGUAGE (below) we need to make sure that
1176 CURRENT_LANGUAGE is not NULL. So first set the language to unknown,
1177 then we can change the language to 'auto'. */
1178 current_language
= language_def (language_unknown
);
1180 add_set_language_command ();
1184 case_sensitive
= "auto";
1186 /* Have the above take effect. */
1187 set_language (language_auto
);