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 void set_range_case (void);
52 /* The current (default at startup) state of type and range checking.
53 (If the modes are set to "auto", though, these are changed based
54 on the default language at startup, and then again based on the
55 language of the first source file. */
57 enum range_mode range_mode
= range_mode_auto
;
58 enum range_check range_check
= range_check_off
;
59 enum case_mode case_mode
= case_mode_auto
;
60 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
62 /* The current language and language_mode (see language.h). */
64 const struct language_defn
*current_language
= nullptr;
65 enum language_mode language_mode
= language_mode_auto
;
67 /* The language that the user expects to be typing in (the language
68 of main(), or the last language we notified them about, or C). */
70 const struct language_defn
*expected_language
;
72 /* Define the array containing all languages. */
74 const struct language_defn
*language_defn::languages
[nr_languages
];
76 /* The current values of the "set language/range/case-sensitive" enum
78 static const char *language
;
79 static const char *range
;
80 static const char *case_sensitive
;
83 const char lang_frame_mismatch_warn
[] =
84 N_("Warning: the current language does not match this frame.");
86 /* This page contains the functions corresponding to GDB commands
89 /* Show command. Display a warning if the language set
90 does not match the frame. */
92 show_language_command (struct ui_file
*file
, int from_tty
,
93 struct cmd_list_element
*c
, const char *value
)
95 enum language flang
; /* The language of the frame. */
97 if (language_mode
== language_mode_auto
)
98 fprintf_filtered (gdb_stdout
,
99 _("The current source language is "
100 "\"auto; currently %s\".\n"),
101 current_language
->la_name
);
103 fprintf_filtered (gdb_stdout
,
104 _("The current source language is \"%s\".\n"),
105 current_language
->la_name
);
107 if (has_stack_frames ())
109 struct frame_info
*frame
;
111 frame
= get_selected_frame (NULL
);
112 flang
= get_frame_language (frame
);
113 if (flang
!= language_unknown
114 && language_mode
== language_mode_manual
115 && current_language
->la_language
!= flang
)
116 printf_filtered ("%s\n", _(lang_frame_mismatch_warn
));
120 /* Set command. Change the current working language. */
122 set_language_command (const char *ignore
,
123 int from_tty
, struct cmd_list_element
*c
)
125 enum language flang
= language_unknown
;
127 /* "local" is a synonym of "auto". */
128 if (strcmp (language
, "local") == 0)
131 /* Search the list of languages for a match. */
132 for (const auto &lang
: language_defn::languages
)
134 if (strcmp (lang
->la_name
, language
) == 0)
136 /* Found it! Go into manual mode, and use this language. */
137 if (lang
->la_language
== language_auto
)
139 /* Enter auto mode. Set to the current frame's language, if
140 known, or fallback to the initial language. */
141 language_mode
= language_mode_auto
;
144 struct frame_info
*frame
;
146 frame
= get_selected_frame (NULL
);
147 flang
= get_frame_language (frame
);
149 catch (const gdb_exception_error
&ex
)
151 flang
= language_unknown
;
154 if (flang
!= language_unknown
)
155 set_language (flang
);
157 set_initial_language ();
158 expected_language
= current_language
;
163 /* Enter manual mode. Set the specified language. */
164 language_mode
= language_mode_manual
;
165 current_language
= lang
;
167 expected_language
= current_language
;
173 internal_error (__FILE__
, __LINE__
,
174 "Couldn't find language `%s' in known languages list.",
178 /* Show command. Display a warning if the range setting does
179 not match the current language. */
181 show_range_command (struct ui_file
*file
, int from_tty
,
182 struct cmd_list_element
*c
, const char *value
)
184 if (range_mode
== range_mode_auto
)
193 case range_check_off
:
196 case range_check_warn
:
200 internal_error (__FILE__
, __LINE__
,
201 "Unrecognized range check setting.");
204 fprintf_filtered (gdb_stdout
,
205 _("Range checking is \"auto; currently %s\".\n"),
209 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
212 if (range_check
!= current_language
->la_range_check
)
213 warning (_("the current range check setting "
214 "does not match the language.\n"));
217 /* Set command. Change the setting for range checking. */
219 set_range_command (const char *ignore
,
220 int from_tty
, struct cmd_list_element
*c
)
222 if (strcmp (range
, "on") == 0)
224 range_check
= range_check_on
;
225 range_mode
= range_mode_manual
;
227 else if (strcmp (range
, "warn") == 0)
229 range_check
= range_check_warn
;
230 range_mode
= range_mode_manual
;
232 else if (strcmp (range
, "off") == 0)
234 range_check
= range_check_off
;
235 range_mode
= range_mode_manual
;
237 else if (strcmp (range
, "auto") == 0)
239 range_mode
= range_mode_auto
;
245 internal_error (__FILE__
, __LINE__
,
246 _("Unrecognized range check setting: \"%s\""), range
);
248 if (range_check
!= current_language
->la_range_check
)
249 warning (_("the current range check setting "
250 "does not match the language.\n"));
253 /* Show command. Display a warning if the case sensitivity setting does
254 not match the current language. */
256 show_case_command (struct ui_file
*file
, int from_tty
,
257 struct cmd_list_element
*c
, const char *value
)
259 if (case_mode
== case_mode_auto
)
261 const char *tmp
= NULL
;
263 switch (case_sensitivity
)
265 case case_sensitive_on
:
268 case case_sensitive_off
:
272 internal_error (__FILE__
, __LINE__
,
273 "Unrecognized case-sensitive setting.");
276 fprintf_filtered (gdb_stdout
,
277 _("Case sensitivity in "
278 "name search is \"auto; currently %s\".\n"),
282 fprintf_filtered (gdb_stdout
,
283 _("Case sensitivity in name search is \"%s\".\n"),
286 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
287 warning (_("the current case sensitivity setting does not match "
291 /* Set command. Change the setting for case sensitivity. */
294 set_case_command (const char *ignore
, int from_tty
, struct cmd_list_element
*c
)
296 if (strcmp (case_sensitive
, "on") == 0)
298 case_sensitivity
= case_sensitive_on
;
299 case_mode
= case_mode_manual
;
301 else if (strcmp (case_sensitive
, "off") == 0)
303 case_sensitivity
= case_sensitive_off
;
304 case_mode
= case_mode_manual
;
306 else if (strcmp (case_sensitive
, "auto") == 0)
308 case_mode
= case_mode_auto
;
314 internal_error (__FILE__
, __LINE__
,
315 "Unrecognized case-sensitive setting: \"%s\"",
319 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
320 warning (_("the current case sensitivity setting does not match "
324 /* Set the status of range and type checking and case sensitivity based on
325 the current modes and the current language.
326 If SHOW is non-zero, then print out the current language,
327 type and range checking status. */
329 set_range_case (void)
331 if (range_mode
== range_mode_auto
)
332 range_check
= current_language
->la_range_check
;
334 if (case_mode
== case_mode_auto
)
335 case_sensitivity
= current_language
->la_case_sensitivity
;
338 /* Set current language to (enum language) LANG. Returns previous
342 set_language (enum language lang
)
344 enum language prev_language
;
346 prev_language
= current_language
->la_language
;
347 current_language
= language_def (lang
);
349 return prev_language
;
353 /* Print out the current language settings: language, range and
354 type checking. If QUIETLY, print only what has changed. */
357 language_info (int quietly
)
359 if (quietly
&& expected_language
== current_language
)
362 expected_language
= current_language
;
363 printf_unfiltered (_("Current language: %s\n"), language
);
364 show_language_command (NULL
, 1, NULL
, NULL
);
368 printf_unfiltered (_("Range checking: %s\n"), range
);
369 show_range_command (NULL
, 1, NULL
, NULL
);
370 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
371 show_case_command (NULL
, 1, NULL
, NULL
);
376 /* Returns non-zero if the value is a pointer type. */
378 pointer_type (struct type
*type
)
380 return type
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
384 /* This page contains functions that return info about
385 (struct value) values used in GDB. */
387 /* Returns non-zero if the value VAL represents a true value. */
389 value_true (struct value
*val
)
391 /* It is possible that we should have some sort of error if a non-boolean
392 value is used in this context. Possibly dependent on some kind of
393 "boolean-checking" option like range checking. But it should probably
394 not depend on the language except insofar as is necessary to identify
395 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
396 should be an error, probably). */
397 return !value_logical_not (val
);
400 /* This page contains functions for the printing out of
401 error messages that occur during type- and range-
404 /* This is called when a language fails a range-check. The
405 first argument should be a printf()-style format string, and the
406 rest of the arguments should be its arguments. If range_check is
407 range_check_on, an error is printed; if range_check_warn, a warning;
408 otherwise just the message. */
411 range_error (const char *string
,...)
415 va_start (args
, string
);
418 case range_check_warn
:
419 vwarning (string
, args
);
422 verror (string
, args
);
424 case range_check_off
:
425 /* FIXME: cagney/2002-01-30: Should this function print anything
426 when range error is off? */
427 vfprintf_filtered (gdb_stderr
, string
, args
);
428 fprintf_filtered (gdb_stderr
, "\n");
431 internal_error (__FILE__
, __LINE__
, _("bad switch"));
437 /* This page contains miscellaneous functions. */
439 /* Return the language enum for a given language string. */
442 language_enum (const char *str
)
444 for (const auto &lang
: language_defn::languages
)
445 if (strcmp (lang
->la_name
, str
) == 0)
446 return lang
->la_language
;
448 if (strcmp (str
, "local") == 0)
449 return language_auto
;
451 return language_unknown
;
454 /* Return the language struct for a given language enum. */
456 const struct language_defn
*
457 language_def (enum language lang
)
459 const struct language_defn
*l
= language_defn::languages
[lang
];
460 gdb_assert (l
!= nullptr);
464 /* Return the language as a string. */
467 language_str (enum language lang
)
469 return language_def (lang
)->la_name
;
474 /* Build and install the "set language LANG" command. */
477 add_set_language_command ()
479 static const char **language_names
;
481 /* Build the language names array, to be used as enumeration in the
482 "set language" enum command. +1 for "local" and +1 for NULL
484 language_names
= new const char *[ARRAY_SIZE (language_defn::languages
) + 2];
486 /* Display "auto", "local" and "unknown" first, and then the rest,
488 const char **language_names_p
= language_names
;
489 *language_names_p
++ = language_def (language_auto
)->la_name
;
490 *language_names_p
++ = "local";
491 *language_names_p
++ = language_def (language_unknown
)->la_name
;
492 const char **sort_begin
= language_names_p
;
493 for (const auto &lang
: language_defn::languages
)
495 /* Already handled above. */
496 if (lang
->la_language
== language_auto
497 || lang
->la_language
== language_unknown
)
499 *language_names_p
++ = lang
->la_name
;
501 *language_names_p
= NULL
;
502 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
504 /* Add the filename extensions. */
505 for (const auto &lang
: language_defn::languages
)
506 if (lang
->la_filename_extensions
!= NULL
)
508 for (size_t i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
509 add_filename_language (lang
->la_filename_extensions
[i
],
513 /* Build the "help set language" docs. */
516 doc
.printf (_("Set the current source language.\n"
517 "The currently understood settings are:\n\nlocal or "
518 "auto Automatic setting based on source file"));
520 for (const auto &lang
: language_defn::languages
)
522 /* Already dealt with these above. */
523 if (lang
->la_language
== language_unknown
524 || lang
->la_language
== language_auto
)
527 /* FIXME: i18n: for now assume that the human-readable name is
528 just a capitalization of the internal name. */
529 /* Note that we add the newline at the front, so we don't wind
530 up with a trailing newline. */
531 doc
.printf ("\n%-16s Use the %c%s language",
533 /* Capitalize first letter of language name. */
534 toupper (lang
->la_name
[0]),
538 add_setshow_enum_cmd ("language", class_support
,
542 _("Show the current source language."),
543 NULL
, set_language_command
,
544 show_language_command
,
545 &setlist
, &showlist
);
548 /* Iterate through all registered languages looking for and calling
549 any non-NULL struct language_defn.skip_trampoline() functions.
550 Return the result from the first that returns non-zero, or 0 if all
553 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
555 for (const auto &lang
: language_defn::languages
)
557 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
566 /* Return demangled language symbol, or NULL.
567 FIXME: Options are only useful for certain languages and ignored
568 by others, so it would be better to remove them here and have a
569 more flexible demangler for the languages that need it.
570 FIXME: Sometimes the demangler is invoked when we don't know the
571 language, so we can't use this everywhere. */
573 language_demangle (const struct language_defn
*current_language
,
574 const char *mangled
, int options
)
576 if (current_language
!= NULL
)
577 return current_language
->demangle (mangled
, options
);
581 /* Return information about whether TYPE should be passed
582 (and returned) by reference at the language level. */
584 struct language_pass_by_ref_info
585 language_pass_by_reference (struct type
*type
)
587 return current_language
->pass_by_reference_info (type
);
590 /* Return the default string containing the list of characters
591 delimiting words. This is a reasonable default value that
592 most languages should be able to use. */
595 default_word_break_characters (void)
597 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
600 /* See language.h. */
603 language_defn::print_array_index (struct type
*index_type
, LONGEST index
,
604 struct ui_file
*stream
,
605 const value_print_options
*options
) const
607 struct value
*index_value
= value_from_longest (index_type
, index
);
609 fprintf_filtered (stream
, "[");
610 LA_VALUE_PRINT (index_value
, stream
, options
);
611 fprintf_filtered (stream
, "] = ");
614 /* See language.h. */
616 gdb::unique_xmalloc_ptr
<char>
617 language_defn::watch_location_expression (struct type
*type
,
618 CORE_ADDR addr
) const
620 /* Generates an expression that assumes a C like syntax is valid. */
621 type
= check_typedef (TYPE_TARGET_TYPE (check_typedef (type
)));
622 std::string name
= type_to_string (type
);
623 return gdb::unique_xmalloc_ptr
<char>
624 (xstrprintf ("* (%s *) %s", name
.c_str (), core_addr_to_string (addr
)));
627 /* See language.h. */
630 language_defn::value_print (struct value
*val
, struct ui_file
*stream
,
631 const struct value_print_options
*options
) const
633 return c_value_print (val
, stream
, options
);
636 /* See language.h. */
639 language_defn::parser (struct parser_state
*ps
) const
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 /* See language.h. */
657 language_defn::emitchar (int ch
, struct type
*chtype
,
658 struct ui_file
* stream
, int quoter
) const
660 c_emit_char (ch
, chtype
, stream
, quoter
);
663 /* See language.h. */
666 language_defn::printchar (int ch
, struct type
*chtype
,
667 struct ui_file
* stream
) const
669 c_printchar (ch
, chtype
, stream
);
672 /* See language.h. */
675 language_defn::printstr (struct ui_file
*stream
, struct type
*elttype
,
676 const gdb_byte
*string
, unsigned int length
,
677 const char *encoding
, int force_ellipses
,
678 const struct value_print_options
*options
) const
680 c_printstr (stream
, elttype
, string
, length
, encoding
, force_ellipses
,
684 /* The default implementation of the get_symbol_name_matcher_inner method
685 from the language_defn class. Matches with strncmp_iw. */
688 default_symbol_name_matcher (const char *symbol_search_name
,
689 const lookup_name_info
&lookup_name
,
690 completion_match_result
*comp_match_res
)
692 gdb::string_view name
= lookup_name
.name ();
693 completion_match_for_lcd
*match_for_lcd
694 = (comp_match_res
!= NULL
? &comp_match_res
->match_for_lcd
: NULL
);
695 strncmp_iw_mode mode
= (lookup_name
.completion_mode ()
696 ? strncmp_iw_mode::NORMAL
697 : strncmp_iw_mode::MATCH_PARAMS
);
699 if (strncmp_iw_with_mode (symbol_search_name
, name
.data (), name
.size (),
700 mode
, language_minimal
, match_for_lcd
) == 0)
702 if (comp_match_res
!= NULL
)
703 comp_match_res
->set_match (symbol_search_name
);
710 /* See language.h. */
712 symbol_name_matcher_ftype
*
713 language_defn::get_symbol_name_matcher
714 (const lookup_name_info
&lookup_name
) const
716 /* If currently in Ada mode, and the lookup name is wrapped in
717 '<...>', hijack all symbol name comparisons using the Ada
718 matcher, which handles the verbatim matching. */
719 if (current_language
->la_language
== language_ada
720 && lookup_name
.ada ().verbatim_p ())
721 return current_language
->get_symbol_name_matcher_inner (lookup_name
);
723 return this->get_symbol_name_matcher_inner (lookup_name
);
726 /* See language.h. */
728 symbol_name_matcher_ftype
*
729 language_defn::get_symbol_name_matcher_inner
730 (const lookup_name_info
&lookup_name
) const
732 return default_symbol_name_matcher
;
735 /* See language.h. */
738 default_is_string_type_p (struct type
*type
)
740 type
= check_typedef (type
);
741 while (type
->code () == TYPE_CODE_REF
)
743 type
= TYPE_TARGET_TYPE (type
);
744 type
= check_typedef (type
);
746 return (type
->code () == TYPE_CODE_STRING
);
749 static const struct op_print unk_op_print_tab
[] =
751 {NULL
, OP_NULL
, PREC_NULL
, 0}
755 unknown_language_arch_info (struct gdbarch
*gdbarch
,
756 struct language_arch_info
*lai
)
758 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
759 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
760 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
764 /* Constant data that describes the unknown language. */
766 extern const struct language_data unknown_language_data
=
776 &exp_descriptor_standard
,
777 default_print_typedef
, /* Print a typedef using appropriate syntax */
778 "this", /* name_of_this */
779 true, /* store_sym_names_in_linkage_form_p */
780 unk_op_print_tab
, /* expression operators for printing */
781 1, /* c-style arrays */
782 0, /* String lower bound */
784 default_is_string_type_p
,
785 "{...}" /* la_struct_too_deep_ellipsis */
788 /* Class representing the unknown language. */
790 class unknown_language
: public language_defn
794 : language_defn (language_unknown
, unknown_language_data
)
797 /* See language.h. */
798 void language_arch_info (struct gdbarch
*gdbarch
,
799 struct language_arch_info
*lai
) const override
801 unknown_language_arch_info (gdbarch
, lai
);
804 /* See language.h. */
806 void print_type (struct type
*type
, const char *varstring
,
807 struct ui_file
*stream
, int show
, int level
,
808 const struct type_print_options
*flags
) const override
810 error (_("unimplemented unknown_language::print_type called"));
813 /* See language.h. */
815 char *demangle (const char *mangled
, int options
) const override
817 /* The unknown language just uses the C++ demangler. */
818 return gdb_demangle (mangled
, options
);
821 /* See language.h. */
823 void value_print (struct value
*val
, struct ui_file
*stream
,
824 const struct value_print_options
*options
) const override
826 error (_("unimplemented unknown_language::value_print called"));
829 /* See language.h. */
831 void value_print_inner
832 (struct value
*val
, struct ui_file
*stream
, int recurse
,
833 const struct value_print_options
*options
) const override
835 error (_("unimplemented unknown_language::value_print_inner called"));
838 /* See language.h. */
840 int parser (struct parser_state
*ps
) const override
842 /* No parsing is done, just claim success. */
846 /* See language.h. */
848 void emitchar (int ch
, struct type
*chtype
,
849 struct ui_file
*stream
, int quoter
) const override
851 error (_("unimplemented unknown_language::emitchar called"));
854 /* See language.h. */
856 void printchar (int ch
, struct type
*chtype
,
857 struct ui_file
*stream
) const override
859 error (_("unimplemented unknown_language::printchar called"));
862 /* See language.h. */
864 void printstr (struct ui_file
*stream
, struct type
*elttype
,
865 const gdb_byte
*string
, unsigned int length
,
866 const char *encoding
, int force_ellipses
,
867 const struct value_print_options
*options
) const override
869 error (_("unimplemented unknown_language::printstr called"));
873 /* Single instance of the unknown language class. */
875 static unknown_language unknown_language_defn
;
877 /* Constant data for the fake "auto" language. */
879 extern const struct language_data auto_language_data
=
889 &exp_descriptor_standard
,
890 default_print_typedef
, /* Print a typedef using appropriate syntax */
891 "this", /* name_of_this */
892 false, /* store_sym_names_in_linkage_form_p */
893 unk_op_print_tab
, /* expression operators for printing */
894 1, /* c-style arrays */
895 0, /* String lower bound */
897 default_is_string_type_p
,
898 "{...}" /* la_struct_too_deep_ellipsis */
901 /* Class representing the fake "auto" language. */
903 class auto_language
: public language_defn
907 : language_defn (language_auto
, auto_language_data
)
910 /* See language.h. */
911 void language_arch_info (struct gdbarch
*gdbarch
,
912 struct language_arch_info
*lai
) const override
914 unknown_language_arch_info (gdbarch
, lai
);
917 /* See language.h. */
919 void print_type (struct type
*type
, const char *varstring
,
920 struct ui_file
*stream
, int show
, int level
,
921 const struct type_print_options
*flags
) const override
923 error (_("unimplemented auto_language::print_type called"));
926 /* See language.h. */
928 char *demangle (const char *mangled
, int options
) const override
930 /* The auto language just uses the C++ demangler. */
931 return gdb_demangle (mangled
, options
);
934 /* See language.h. */
936 void value_print (struct value
*val
, struct ui_file
*stream
,
937 const struct value_print_options
*options
) const override
939 error (_("unimplemented auto_language::value_print called"));
942 /* See language.h. */
944 void value_print_inner
945 (struct value
*val
, struct ui_file
*stream
, int recurse
,
946 const struct value_print_options
*options
) const override
948 error (_("unimplemented auto_language::value_print_inner called"));
951 /* See language.h. */
953 int parser (struct parser_state
*ps
) const override
955 /* No parsing is done, just claim success. */
959 /* See language.h. */
961 void emitchar (int ch
, struct type
*chtype
,
962 struct ui_file
*stream
, int quoter
) const override
964 error (_("unimplemented auto_language::emitchar called"));
967 /* See language.h. */
969 void printchar (int ch
, struct type
*chtype
,
970 struct ui_file
*stream
) const override
972 error (_("unimplemented auto_language::printchar called"));
975 /* See language.h. */
977 void printstr (struct ui_file
*stream
, struct type
*elttype
,
978 const gdb_byte
*string
, unsigned int length
,
979 const char *encoding
, int force_ellipses
,
980 const struct value_print_options
*options
) const override
982 error (_("unimplemented auto_language::printstr called"));
986 /* Single instance of the fake "auto" language. */
988 static auto_language auto_language_defn
;
991 /* Per-architecture language information. */
993 static struct gdbarch_data
*language_gdbarch_data
;
995 struct language_gdbarch
997 /* A vector of per-language per-architecture info. Indexed by "enum
999 struct language_arch_info arch_info
[nr_languages
];
1003 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
1005 struct language_gdbarch
*l
;
1007 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
1008 for (const auto &lang
: language_defn::languages
)
1010 gdb_assert (lang
!= nullptr);
1011 lang
->language_arch_info (gdbarch
,
1012 l
->arch_info
+ lang
->la_language
);
1019 language_string_char_type (const struct language_defn
*la
,
1020 struct gdbarch
*gdbarch
)
1022 struct language_gdbarch
*ld
1023 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1025 return ld
->arch_info
[la
->la_language
].string_char_type
;
1029 language_bool_type (const struct language_defn
*la
,
1030 struct gdbarch
*gdbarch
)
1032 struct language_gdbarch
*ld
1033 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1035 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
1039 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
1040 NULL
, VAR_DOMAIN
, NULL
).symbol
;
1043 struct type
*type
= SYMBOL_TYPE (sym
);
1045 if (type
&& type
->code () == TYPE_CODE_BOOL
)
1050 return ld
->arch_info
[la
->la_language
].bool_type_default
;
1053 /* Helper function for primitive type lookup. */
1055 static struct type
**
1056 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
1061 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
1063 if (strcmp ((*p
)->name (), name
) == 0)
1069 /* See language.h. */
1072 language_lookup_primitive_type (const struct language_defn
*la
,
1073 struct gdbarch
*gdbarch
,
1076 struct language_gdbarch
*ld
=
1077 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1078 struct type
**typep
;
1080 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
1087 /* Helper function for type lookup as a symbol.
1088 Create the symbol corresponding to type TYPE in language LANG. */
1090 static struct symbol
*
1091 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1093 struct symbol
*symbol
;
1094 struct gdbarch
*gdbarch
;
1096 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1098 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1099 symbol
= new (gdbarch_obstack (gdbarch
)) struct symbol ();
1101 symbol
->m_name
= type
->name ();
1102 symbol
->set_language (lang
, nullptr);
1103 symbol
->owner
.arch
= gdbarch
;
1104 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1105 SYMBOL_SECTION (symbol
) = 0;
1106 SYMBOL_TYPE (symbol
) = type
;
1107 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1108 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1113 /* Initialize the primitive type symbols of language LD.
1114 The primitive type vector must have already been initialized. */
1117 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1118 const struct language_defn
*la
,
1119 struct gdbarch
*gdbarch
)
1123 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1125 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1128 lai
->primitive_type_symbols
1129 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1131 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1133 lai
->primitive_type_symbols
[n
]
1134 = language_alloc_type_symbol (la
->la_language
,
1135 lai
->primitive_type_vector
[n
]);
1138 /* Note: The result of symbol lookup is normally a symbol *and* the block
1139 it was found in. Builtin types don't live in blocks. We *could* give
1140 them one, but there is no current need so to keep things simple symbol
1141 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1144 /* See language.h. */
1147 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1148 struct gdbarch
*gdbarch
,
1151 struct language_gdbarch
*ld
1152 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1153 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1154 struct type
**typep
;
1157 if (symbol_lookup_debug
)
1159 fprintf_unfiltered (gdb_stdlog
,
1160 "language_lookup_primitive_type_as_symbol"
1162 la
->la_name
, host_address_to_string (gdbarch
), name
);
1165 typep
= language_lookup_primitive_type_1 (lai
, name
);
1168 if (symbol_lookup_debug
)
1169 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1173 /* The set of symbols is lazily initialized. */
1174 if (lai
->primitive_type_symbols
== NULL
)
1175 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1177 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1179 if (symbol_lookup_debug
)
1180 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1184 /* Initialize the language routines. */
1186 void _initialize_language ();
1188 _initialize_language ()
1190 static const char *const type_or_range_names
[]
1191 = { "on", "off", "warn", "auto", NULL
};
1193 static const char *const case_sensitive_names
[]
1194 = { "on", "off", "auto", NULL
};
1196 language_gdbarch_data
1197 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1199 /* GDB commands for language specific stuff. */
1201 add_basic_prefix_cmd ("check", no_class
,
1202 _("Set the status of the type/range checker."),
1203 &setchecklist
, "set check ", 0, &setlist
);
1204 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1205 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1207 add_show_prefix_cmd ("check", no_class
,
1208 _("Show the status of the type/range checker."),
1209 &showchecklist
, "show check ", 0, &showlist
);
1210 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1211 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1213 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1215 _("Set range checking (on/warn/off/auto)."),
1216 _("Show range checking (on/warn/off/auto)."),
1217 NULL
, set_range_command
,
1219 &setchecklist
, &showchecklist
);
1221 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1222 &case_sensitive
, _("\
1223 Set case sensitivity in name search (on/off/auto)."), _("\
1224 Show case sensitivity in name search (on/off/auto)."), _("\
1225 For Fortran the default is off; for other languages the default is on."),
1228 &setlist
, &showlist
);
1230 /* In order to call SET_LANGUAGE (below) we need to make sure that
1231 CURRENT_LANGUAGE is not NULL. So first set the language to unknown,
1232 then we can change the language to 'auto'. */
1233 current_language
= language_def (language_unknown
);
1235 add_set_language_command ();
1239 case_sensitive
= "auto";
1241 /* Have the above take effect. */
1242 set_language (language_auto
);