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 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
789 unk_op_print_tab
, /* expression operators for printing */
790 1, /* c-style arrays */
791 0, /* String lower bound */
793 default_is_string_type_p
,
794 "{...}" /* la_struct_too_deep_ellipsis */
797 /* Class representing the unknown language. */
799 class unknown_language
: public language_defn
803 : language_defn (language_unknown
, unknown_language_data
)
806 /* See language.h. */
807 void language_arch_info (struct gdbarch
*gdbarch
,
808 struct language_arch_info
*lai
) const override
810 unknown_language_arch_info (gdbarch
, lai
);
813 /* See language.h. */
815 void print_type (struct type
*type
, const char *varstring
,
816 struct ui_file
*stream
, int show
, int level
,
817 const struct type_print_options
*flags
) const override
819 error (_("unimplemented unknown_language::print_type called"));
822 /* See language.h. */
824 char *demangle (const char *mangled
, int options
) const override
826 /* The unknown language just uses the C++ demangler. */
827 return gdb_demangle (mangled
, options
);
830 /* See language.h. */
832 void value_print (struct value
*val
, struct ui_file
*stream
,
833 const struct value_print_options
*options
) const override
835 error (_("unimplemented unknown_language::value_print called"));
838 /* See language.h. */
840 void value_print_inner
841 (struct value
*val
, struct ui_file
*stream
, int recurse
,
842 const struct value_print_options
*options
) const override
844 error (_("unimplemented unknown_language::value_print_inner called"));
848 /* Single instance of the unknown language class. */
850 static unknown_language unknown_language_defn
;
852 /* Constant data for the fake "auto" language. */
854 extern const struct language_data auto_language_data
=
864 &exp_descriptor_standard
,
867 unk_lang_printchar
, /* Print character constant */
870 default_print_typedef
, /* Print a typedef using appropriate syntax */
871 "this", /* name_of_this */
872 false, /* store_sym_names_in_linkage_form_p */
873 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
874 unk_op_print_tab
, /* expression operators for printing */
875 1, /* c-style arrays */
876 0, /* String lower bound */
878 default_is_string_type_p
,
879 "{...}" /* la_struct_too_deep_ellipsis */
882 /* Class representing the fake "auto" language. */
884 class auto_language
: public language_defn
888 : language_defn (language_auto
, auto_language_data
)
891 /* See language.h. */
892 void language_arch_info (struct gdbarch
*gdbarch
,
893 struct language_arch_info
*lai
) const override
895 unknown_language_arch_info (gdbarch
, lai
);
898 /* See language.h. */
900 void print_type (struct type
*type
, const char *varstring
,
901 struct ui_file
*stream
, int show
, int level
,
902 const struct type_print_options
*flags
) const override
904 error (_("unimplemented auto_language::print_type called"));
907 /* See language.h. */
909 char *demangle (const char *mangled
, int options
) const override
911 /* The auto language just uses the C++ demangler. */
912 return gdb_demangle (mangled
, options
);
915 /* See language.h. */
917 void value_print (struct value
*val
, struct ui_file
*stream
,
918 const struct value_print_options
*options
) const override
920 error (_("unimplemented auto_language::value_print called"));
923 /* See language.h. */
925 void value_print_inner
926 (struct value
*val
, struct ui_file
*stream
, int recurse
,
927 const struct value_print_options
*options
) const override
929 error (_("unimplemented auto_language::value_print_inner called"));
933 /* Single instance of the fake "auto" language. */
935 static auto_language auto_language_defn
;
938 /* Per-architecture language information. */
940 static struct gdbarch_data
*language_gdbarch_data
;
942 struct language_gdbarch
944 /* A vector of per-language per-architecture info. Indexed by "enum
946 struct language_arch_info arch_info
[nr_languages
];
950 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
952 struct language_gdbarch
*l
;
954 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
955 for (const auto &lang
: language_defn::languages
)
957 gdb_assert (lang
!= nullptr);
958 lang
->language_arch_info (gdbarch
,
959 l
->arch_info
+ lang
->la_language
);
966 language_string_char_type (const struct language_defn
*la
,
967 struct gdbarch
*gdbarch
)
969 struct language_gdbarch
*ld
970 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
972 return ld
->arch_info
[la
->la_language
].string_char_type
;
976 language_bool_type (const struct language_defn
*la
,
977 struct gdbarch
*gdbarch
)
979 struct language_gdbarch
*ld
980 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
982 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
986 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
987 NULL
, VAR_DOMAIN
, NULL
).symbol
;
990 struct type
*type
= SYMBOL_TYPE (sym
);
992 if (type
&& type
->code () == TYPE_CODE_BOOL
)
997 return ld
->arch_info
[la
->la_language
].bool_type_default
;
1000 /* Helper function for primitive type lookup. */
1002 static struct type
**
1003 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
1008 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
1010 if (strcmp ((*p
)->name (), name
) == 0)
1016 /* See language.h. */
1019 language_lookup_primitive_type (const struct language_defn
*la
,
1020 struct gdbarch
*gdbarch
,
1023 struct language_gdbarch
*ld
=
1024 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1025 struct type
**typep
;
1027 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
1034 /* Helper function for type lookup as a symbol.
1035 Create the symbol corresponding to type TYPE in language LANG. */
1037 static struct symbol
*
1038 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1040 struct symbol
*symbol
;
1041 struct gdbarch
*gdbarch
;
1043 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1045 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1046 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
1048 symbol
->m_name
= type
->name ();
1049 symbol
->set_language (lang
, nullptr);
1050 symbol
->owner
.arch
= gdbarch
;
1051 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1052 SYMBOL_SECTION (symbol
) = 0;
1053 SYMBOL_TYPE (symbol
) = type
;
1054 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1055 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1060 /* Initialize the primitive type symbols of language LD.
1061 The primitive type vector must have already been initialized. */
1064 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1065 const struct language_defn
*la
,
1066 struct gdbarch
*gdbarch
)
1070 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1072 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1075 lai
->primitive_type_symbols
1076 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1078 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1080 lai
->primitive_type_symbols
[n
]
1081 = language_alloc_type_symbol (la
->la_language
,
1082 lai
->primitive_type_vector
[n
]);
1085 /* Note: The result of symbol lookup is normally a symbol *and* the block
1086 it was found in. Builtin types don't live in blocks. We *could* give
1087 them one, but there is no current need so to keep things simple symbol
1088 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1091 /* See language.h. */
1094 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1095 struct gdbarch
*gdbarch
,
1098 struct language_gdbarch
*ld
1099 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1100 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1101 struct type
**typep
;
1104 if (symbol_lookup_debug
)
1106 fprintf_unfiltered (gdb_stdlog
,
1107 "language_lookup_primitive_type_as_symbol"
1109 la
->la_name
, host_address_to_string (gdbarch
), name
);
1112 typep
= language_lookup_primitive_type_1 (lai
, name
);
1115 if (symbol_lookup_debug
)
1116 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1120 /* The set of symbols is lazily initialized. */
1121 if (lai
->primitive_type_symbols
== NULL
)
1122 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1124 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1126 if (symbol_lookup_debug
)
1127 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1131 /* Initialize the language routines. */
1133 void _initialize_language ();
1135 _initialize_language ()
1137 static const char *const type_or_range_names
[]
1138 = { "on", "off", "warn", "auto", NULL
};
1140 static const char *const case_sensitive_names
[]
1141 = { "on", "off", "auto", NULL
};
1143 language_gdbarch_data
1144 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1146 /* GDB commands for language specific stuff. */
1148 add_basic_prefix_cmd ("check", no_class
,
1149 _("Set the status of the type/range checker."),
1150 &setchecklist
, "set check ", 0, &setlist
);
1151 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1152 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1154 add_show_prefix_cmd ("check", no_class
,
1155 _("Show the status of the type/range checker."),
1156 &showchecklist
, "show check ", 0, &showlist
);
1157 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1158 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1160 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1162 _("Set range checking (on/warn/off/auto)."),
1163 _("Show range checking (on/warn/off/auto)."),
1164 NULL
, set_range_command
,
1166 &setchecklist
, &showchecklist
);
1168 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1169 &case_sensitive
, _("\
1170 Set case sensitivity in name search (on/off/auto)."), _("\
1171 Show case sensitivity in name search (on/off/auto)."), _("\
1172 For Fortran the default is off; for other languages the default is on."),
1175 &setlist
, &showlist
);
1177 /* In order to call SET_LANGUAGE (below) we need to make sure that
1178 CURRENT_LANGUAGE is not NULL. So first set the language to unknown,
1179 then we can change the language to 'auto'. */
1180 current_language
= language_def (language_unknown
);
1182 add_set_language_command ();
1186 case_sensitive
= "auto";
1188 /* Have the above take effect. */
1189 set_language (language_auto
);