1 /* Multiple source language support for GDB.
3 Copyright (C) 1991-2017 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"
49 static void unk_lang_error (const char *);
51 static int unk_lang_parser (struct parser_state
*);
53 static void show_check (char *, int);
55 static void set_check (char *, int);
57 static void set_range_case (void);
59 static void unk_lang_emit_char (int c
, struct type
*type
,
60 struct ui_file
*stream
, int quoter
);
62 static void unk_lang_printchar (int c
, struct type
*type
,
63 struct ui_file
*stream
);
65 static void unk_lang_value_print (struct value
*, struct ui_file
*,
66 const struct value_print_options
*);
68 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*, CORE_ADDR pc
);
70 /* Forward declaration */
71 extern const struct language_defn unknown_language_defn
;
73 /* The current (default at startup) state of type and range checking.
74 (If the modes are set to "auto", though, these are changed based
75 on the default language at startup, and then again based on the
76 language of the first source file. */
78 enum range_mode range_mode
= range_mode_auto
;
79 enum range_check range_check
= range_check_off
;
80 enum case_mode case_mode
= case_mode_auto
;
81 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
83 /* The current language and language_mode (see language.h). */
85 const struct language_defn
*current_language
= &unknown_language_defn
;
86 enum language_mode language_mode
= language_mode_auto
;
88 /* The language that the user expects to be typing in (the language
89 of main(), or the last language we notified them about, or C). */
91 const struct language_defn
*expected_language
;
93 /* The list of supported languages. Keep this in the same order as
94 the 'enum language' values. */
96 static const struct language_defn
*languages
[] = {
97 &unknown_language_defn
,
101 &cplus_language_defn
,
107 &pascal_language_defn
,
108 &opencl_language_defn
,
110 &minimal_language_defn
,
114 /* The current values of the "set language/type/range" enum
116 static const char *language
;
117 static const char *type
;
118 static const char *range
;
119 static const char *case_sensitive
;
121 /* Warning issued when current_language and the language of the current
122 frame do not match. */
123 char lang_frame_mismatch_warn
[] =
124 "Warning: the current language does not match this frame.";
126 /* This page contains the functions corresponding to GDB commands
127 and their helpers. */
129 /* Show command. Display a warning if the language set
130 does not match the frame. */
132 show_language_command (struct ui_file
*file
, int from_tty
,
133 struct cmd_list_element
*c
, const char *value
)
135 enum language flang
; /* The language of the frame. */
137 if (language_mode
== language_mode_auto
)
138 fprintf_filtered (gdb_stdout
,
139 _("The current source language is "
140 "\"auto; currently %s\".\n"),
141 current_language
->la_name
);
143 fprintf_filtered (gdb_stdout
,
144 _("The current source language is \"%s\".\n"),
145 current_language
->la_name
);
147 if (has_stack_frames ())
149 struct frame_info
*frame
;
151 frame
= get_selected_frame (NULL
);
152 flang
= get_frame_language (frame
);
153 if (flang
!= language_unknown
154 && language_mode
== language_mode_manual
155 && current_language
->la_language
!= flang
)
156 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
160 /* Set command. Change the current working language. */
162 set_language_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
164 enum language flang
= language_unknown
;
166 /* "local" is a synonym of "auto". */
167 if (strcmp (language
, "local") == 0)
170 /* Search the list of languages for a match. */
171 for (const auto &lang
: languages
)
173 if (strcmp (lang
->la_name
, language
) == 0)
175 /* Found it! Go into manual mode, and use this language. */
176 if (lang
->la_language
== language_auto
)
178 /* Enter auto mode. Set to the current frame's language, if
179 known, or fallback to the initial language. */
180 language_mode
= language_mode_auto
;
183 struct frame_info
*frame
;
185 frame
= get_selected_frame (NULL
);
186 flang
= get_frame_language (frame
);
188 CATCH (ex
, RETURN_MASK_ERROR
)
190 flang
= language_unknown
;
194 if (flang
!= language_unknown
)
195 set_language (flang
);
197 set_initial_language ();
198 expected_language
= current_language
;
203 /* Enter manual mode. Set the specified language. */
204 language_mode
= language_mode_manual
;
205 current_language
= lang
;
207 expected_language
= current_language
;
213 internal_error (__FILE__
, __LINE__
,
214 "Couldn't find language `%s' in known languages list.",
218 /* Show command. Display a warning if the range setting does
219 not match the current language. */
221 show_range_command (struct ui_file
*file
, int from_tty
,
222 struct cmd_list_element
*c
, const char *value
)
224 if (range_mode
== range_mode_auto
)
233 case range_check_off
:
236 case range_check_warn
:
240 internal_error (__FILE__
, __LINE__
,
241 "Unrecognized range check setting.");
244 fprintf_filtered (gdb_stdout
,
245 _("Range checking is \"auto; currently %s\".\n"),
249 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
252 if (range_check
!= current_language
->la_range_check
)
253 warning (_("the current range check setting "
254 "does not match the language.\n"));
257 /* Set command. Change the setting for range checking. */
259 set_range_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
261 if (strcmp (range
, "on") == 0)
263 range_check
= range_check_on
;
264 range_mode
= range_mode_manual
;
266 else if (strcmp (range
, "warn") == 0)
268 range_check
= range_check_warn
;
269 range_mode
= range_mode_manual
;
271 else if (strcmp (range
, "off") == 0)
273 range_check
= range_check_off
;
274 range_mode
= range_mode_manual
;
276 else if (strcmp (range
, "auto") == 0)
278 range_mode
= range_mode_auto
;
284 internal_error (__FILE__
, __LINE__
,
285 _("Unrecognized range check setting: \"%s\""), range
);
287 if (range_check
!= current_language
->la_range_check
)
288 warning (_("the current range check setting "
289 "does not match the language.\n"));
292 /* Show command. Display a warning if the case sensitivity setting does
293 not match the current language. */
295 show_case_command (struct ui_file
*file
, int from_tty
,
296 struct cmd_list_element
*c
, const char *value
)
298 if (case_mode
== case_mode_auto
)
300 const char *tmp
= NULL
;
302 switch (case_sensitivity
)
304 case case_sensitive_on
:
307 case case_sensitive_off
:
311 internal_error (__FILE__
, __LINE__
,
312 "Unrecognized case-sensitive setting.");
315 fprintf_filtered (gdb_stdout
,
316 _("Case sensitivity in "
317 "name search is \"auto; currently %s\".\n"),
321 fprintf_filtered (gdb_stdout
,
322 _("Case sensitivity in name search is \"%s\".\n"),
325 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
326 warning (_("the current case sensitivity setting does not match "
330 /* Set command. Change the setting for case sensitivity. */
333 set_case_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
335 if (strcmp (case_sensitive
, "on") == 0)
337 case_sensitivity
= case_sensitive_on
;
338 case_mode
= case_mode_manual
;
340 else if (strcmp (case_sensitive
, "off") == 0)
342 case_sensitivity
= case_sensitive_off
;
343 case_mode
= case_mode_manual
;
345 else if (strcmp (case_sensitive
, "auto") == 0)
347 case_mode
= case_mode_auto
;
353 internal_error (__FILE__
, __LINE__
,
354 "Unrecognized case-sensitive setting: \"%s\"",
358 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
359 warning (_("the current case sensitivity setting does not match "
363 /* Set the status of range and type checking and case sensitivity based on
364 the current modes and the current language.
365 If SHOW is non-zero, then print out the current language,
366 type and range checking status. */
368 set_range_case (void)
370 if (range_mode
== range_mode_auto
)
371 range_check
= current_language
->la_range_check
;
373 if (case_mode
== case_mode_auto
)
374 case_sensitivity
= current_language
->la_case_sensitivity
;
377 /* Set current language to (enum language) LANG. Returns previous
381 set_language (enum language lang
)
383 enum language prev_language
;
385 prev_language
= current_language
->la_language
;
386 current_language
= languages
[lang
];
388 return prev_language
;
392 /* Print out the current language settings: language, range and
393 type checking. If QUIETLY, print only what has changed. */
396 language_info (int quietly
)
398 if (quietly
&& expected_language
== current_language
)
401 expected_language
= current_language
;
402 printf_unfiltered (_("Current language: %s\n"), language
);
403 show_language_command (NULL
, 1, NULL
, NULL
);
407 printf_unfiltered (_("Range checking: %s\n"), range
);
408 show_range_command (NULL
, 1, NULL
, NULL
);
409 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
410 show_case_command (NULL
, 1, NULL
, NULL
);
415 /* Returns non-zero if the value is a pointer type. */
417 pointer_type (struct type
*type
)
419 return TYPE_CODE (type
) == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
423 /* This page contains functions that return info about
424 (struct value) values used in GDB. */
426 /* Returns non-zero if the value VAL represents a true value. */
428 value_true (struct value
*val
)
430 /* It is possible that we should have some sort of error if a non-boolean
431 value is used in this context. Possibly dependent on some kind of
432 "boolean-checking" option like range checking. But it should probably
433 not depend on the language except insofar as is necessary to identify
434 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
435 should be an error, probably). */
436 return !value_logical_not (val
);
439 /* This page contains functions for the printing out of
440 error messages that occur during type- and range-
443 /* This is called when a language fails a range-check. The
444 first argument should be a printf()-style format string, and the
445 rest of the arguments should be its arguments. If range_check is
446 range_check_on, an error is printed; if range_check_warn, a warning;
447 otherwise just the message. */
450 range_error (const char *string
,...)
454 va_start (args
, string
);
457 case range_check_warn
:
458 vwarning (string
, args
);
461 verror (string
, args
);
463 case range_check_off
:
464 /* FIXME: cagney/2002-01-30: Should this function print anything
465 when range error is off? */
466 vfprintf_filtered (gdb_stderr
, string
, args
);
467 fprintf_filtered (gdb_stderr
, "\n");
470 internal_error (__FILE__
, __LINE__
, _("bad switch"));
476 /* This page contains miscellaneous functions. */
478 /* Return the language enum for a given language string. */
481 language_enum (const char *str
)
483 for (const auto &lang
: languages
)
484 if (strcmp (lang
->la_name
, str
) == 0)
485 return lang
->la_language
;
487 if (strcmp (str
, "local") == 0)
488 return language_auto
;
490 return language_unknown
;
493 /* Return the language struct for a given language enum. */
495 const struct language_defn
*
496 language_def (enum language lang
)
498 return languages
[lang
];
501 /* Return the language as a string. */
504 language_str (enum language lang
)
506 return languages
[lang
]->la_name
;
510 set_check (char *ignore
, int from_tty
)
513 "\"set check\" must be followed by the name of a check subcommand.\n");
514 help_list (setchecklist
, "set check ", all_commands
, gdb_stdout
);
518 show_check (char *ignore
, int from_tty
)
520 cmd_show_list (showchecklist
, from_tty
, "");
524 /* Build and install the "set language LANG" command. */
527 add_set_language_command ()
529 static const char **language_names
;
531 /* Build the language names array, to be used as enumeration in the
532 "set language" enum command. +1 for "local" and +1 for NULL
534 language_names
= new const char *[ARRAY_SIZE (languages
) + 2];
536 /* Display "auto", "local" and "unknown" first, and then the rest,
538 const char **language_names_p
= language_names
;
539 *language_names_p
++ = auto_language_defn
.la_name
;
540 *language_names_p
++ = "local";
541 *language_names_p
++ = unknown_language_defn
.la_name
;
542 const char **sort_begin
= language_names_p
;
543 for (const auto &lang
: languages
)
545 /* Already handled above. */
546 if (lang
->la_language
== language_auto
547 || lang
->la_language
== language_unknown
)
549 *language_names_p
++ = lang
->la_name
;
551 *language_names_p
= NULL
;
552 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
554 /* Add the filename extensions. */
555 for (const auto &lang
: languages
)
556 if (lang
->la_filename_extensions
!= NULL
)
558 for (size_t i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
559 add_filename_language (lang
->la_filename_extensions
[i
],
563 /* Build the "help set language" docs. */
566 doc
.printf (_("Set the current source language.\n"
567 "The currently understood settings are:\n\nlocal or "
568 "auto Automatic setting based on source file\n"));
570 for (const auto &lang
: languages
)
572 /* Already dealt with these above. */
573 if (lang
->la_language
== language_unknown
574 || lang
->la_language
== language_auto
)
577 /* FIXME: i18n: for now assume that the human-readable name is
578 just a capitalization of the internal name. */
579 doc
.printf ("%-16s Use the %c%s language\n",
581 /* Capitalize first letter of language name. */
582 toupper (lang
->la_name
[0]),
586 add_setshow_enum_cmd ("language", class_support
,
590 _("Show the current source language."),
591 NULL
, set_language_command
,
592 show_language_command
,
593 &setlist
, &showlist
);
596 /* Iterate through all registered languages looking for and calling
597 any non-NULL struct language_defn.skip_trampoline() functions.
598 Return the result from the first that returns non-zero, or 0 if all
601 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
603 for (const auto &lang
: languages
)
605 if (lang
->skip_trampoline
!= NULL
)
607 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
617 /* Return demangled language symbol, or NULL.
618 FIXME: Options are only useful for certain languages and ignored
619 by others, so it would be better to remove them here and have a
620 more flexible demangler for the languages that need it.
621 FIXME: Sometimes the demangler is invoked when we don't know the
622 language, so we can't use this everywhere. */
624 language_demangle (const struct language_defn
*current_language
,
625 const char *mangled
, int options
)
627 if (current_language
!= NULL
&& current_language
->la_demangle
)
628 return current_language
->la_demangle (mangled
, options
);
632 /* See langauge.h. */
635 language_sniff_from_mangled_name (const struct language_defn
*lang
,
636 const char *mangled
, char **demangled
)
638 gdb_assert (lang
!= NULL
);
640 if (lang
->la_sniff_from_mangled_name
== NULL
)
646 return lang
->la_sniff_from_mangled_name (mangled
, demangled
);
649 /* Return class name from physname or NULL. */
651 language_class_name_from_physname (const struct language_defn
*lang
,
652 const char *physname
)
654 if (lang
!= NULL
&& lang
->la_class_name_from_physname
)
655 return lang
->la_class_name_from_physname (physname
);
659 /* Return non-zero if TYPE should be passed (and returned) by
660 reference at the language level. */
662 language_pass_by_reference (struct type
*type
)
664 return current_language
->la_pass_by_reference (type
);
667 /* Return zero; by default, types are passed by value at the language
668 level. The target ABI may pass or return some structs by reference
669 independent of this. */
671 default_pass_by_reference (struct type
*type
)
676 /* Return the default string containing the list of characters
677 delimiting words. This is a reasonable default value that
678 most languages should be able to use. */
681 default_word_break_characters (void)
683 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
686 /* Print the index of array elements using the C99 syntax. */
689 default_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
690 const struct value_print_options
*options
)
692 fprintf_filtered (stream
, "[");
693 LA_VALUE_PRINT (index_value
, stream
, options
);
694 fprintf_filtered (stream
, "] = ");
698 default_get_string (struct value
*value
, gdb_byte
**buffer
, int *length
,
699 struct type
**char_type
, const char **charset
)
701 error (_("Getting a string is unsupported in this language."));
704 /* Define the language that is no language. */
707 unk_lang_parser (struct parser_state
*ps
)
713 unk_lang_error (const char *msg
)
715 error (_("Attempted to parse an expression with unknown language"));
719 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
722 error (_("internal error - unimplemented "
723 "function unk_lang_emit_char called."));
727 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
729 error (_("internal error - unimplemented "
730 "function unk_lang_printchar called."));
734 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
735 const gdb_byte
*string
, unsigned int length
,
736 const char *encoding
, int force_ellipses
,
737 const struct value_print_options
*options
)
739 error (_("internal error - unimplemented "
740 "function unk_lang_printstr called."));
744 unk_lang_print_type (struct type
*type
, const char *varstring
,
745 struct ui_file
*stream
, int show
, int level
,
746 const struct type_print_options
*flags
)
748 error (_("internal error - unimplemented "
749 "function unk_lang_print_type called."));
753 unk_lang_val_print (struct type
*type
,
754 int embedded_offset
, CORE_ADDR address
,
755 struct ui_file
*stream
, int recurse
,
757 const struct value_print_options
*options
)
759 error (_("internal error - unimplemented "
760 "function unk_lang_val_print called."));
764 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
765 const struct value_print_options
*options
)
767 error (_("internal error - unimplemented "
768 "function unk_lang_value_print called."));
771 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
776 /* Unknown languages just use the cplus demangler. */
777 static char *unk_lang_demangle (const char *mangled
, int options
)
779 return gdb_demangle (mangled
, options
);
782 static char *unk_lang_class_name (const char *mangled
)
787 static const struct op_print unk_op_print_tab
[] =
789 {NULL
, OP_NULL
, PREC_NULL
, 0}
793 unknown_language_arch_info (struct gdbarch
*gdbarch
,
794 struct language_arch_info
*lai
)
796 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
797 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
798 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
802 const struct language_defn unknown_language_defn
=
812 &exp_descriptor_standard
,
816 unk_lang_printchar
, /* Print character constant */
819 unk_lang_print_type
, /* Print a type using appropriate syntax */
820 default_print_typedef
, /* Print a typedef using appropriate syntax */
821 unk_lang_val_print
, /* Print a value using appropriate syntax */
822 unk_lang_value_print
, /* Print a top-level value */
823 default_read_var_value
, /* la_read_var_value */
824 unk_lang_trampoline
, /* Language specific skip_trampoline */
825 "this", /* name_of_this */
826 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
827 basic_lookup_transparent_type
,/* lookup_transparent_type */
828 unk_lang_demangle
, /* Language specific symbol demangler */
830 unk_lang_class_name
, /* Language specific
831 class_name_from_physname */
832 unk_op_print_tab
, /* expression operators for printing */
833 1, /* c-style arrays */
834 0, /* String lower bound */
835 default_word_break_characters
,
836 default_collect_symbol_completion_matches
,
837 unknown_language_arch_info
, /* la_language_arch_info. */
838 default_print_array_index
,
839 default_pass_by_reference
,
841 c_watch_location_expression
,
842 NULL
, /* la_get_symbol_name_cmp */
843 iterate_over_symbols
,
850 /* These two structs define fake entries for the "local" and "auto"
852 const struct language_defn auto_language_defn
=
862 &exp_descriptor_standard
,
866 unk_lang_printchar
, /* Print character constant */
869 unk_lang_print_type
, /* Print a type using appropriate syntax */
870 default_print_typedef
, /* Print a typedef using appropriate syntax */
871 unk_lang_val_print
, /* Print a value using appropriate syntax */
872 unk_lang_value_print
, /* Print a top-level value */
873 default_read_var_value
, /* la_read_var_value */
874 unk_lang_trampoline
, /* Language specific skip_trampoline */
875 "this", /* name_of_this */
876 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
877 basic_lookup_transparent_type
,/* lookup_transparent_type */
878 unk_lang_demangle
, /* Language specific symbol demangler */
880 unk_lang_class_name
, /* Language specific
881 class_name_from_physname */
882 unk_op_print_tab
, /* expression operators for printing */
883 1, /* c-style arrays */
884 0, /* String lower bound */
885 default_word_break_characters
,
886 default_collect_symbol_completion_matches
,
887 unknown_language_arch_info
, /* la_language_arch_info. */
888 default_print_array_index
,
889 default_pass_by_reference
,
891 c_watch_location_expression
,
892 NULL
, /* la_get_symbol_name_cmp */
893 iterate_over_symbols
,
901 /* Per-architecture language information. */
903 static struct gdbarch_data
*language_gdbarch_data
;
905 struct language_gdbarch
907 /* A vector of per-language per-architecture info. Indexed by "enum
909 struct language_arch_info arch_info
[nr_languages
];
913 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
915 struct language_gdbarch
*l
;
917 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
918 for (const auto &lang
: languages
)
919 if (lang
!= NULL
&& lang
->la_language_arch_info
!= NULL
)
921 lang
->la_language_arch_info (gdbarch
,
922 l
->arch_info
+ lang
->la_language
);
929 language_string_char_type (const struct language_defn
*la
,
930 struct gdbarch
*gdbarch
)
932 struct language_gdbarch
*ld
933 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
935 return ld
->arch_info
[la
->la_language
].string_char_type
;
939 language_bool_type (const struct language_defn
*la
,
940 struct gdbarch
*gdbarch
)
942 struct language_gdbarch
*ld
943 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
945 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
949 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
950 NULL
, VAR_DOMAIN
, NULL
).symbol
;
953 struct type
*type
= SYMBOL_TYPE (sym
);
955 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
960 return ld
->arch_info
[la
->la_language
].bool_type_default
;
963 /* Helper function for primitive type lookup. */
965 static struct type
**
966 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
971 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
973 if (strcmp (TYPE_NAME (*p
), name
) == 0)
979 /* See language.h. */
982 language_lookup_primitive_type (const struct language_defn
*la
,
983 struct gdbarch
*gdbarch
,
986 struct language_gdbarch
*ld
=
987 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
990 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
997 /* Helper function for type lookup as a symbol.
998 Create the symbol corresponding to type TYPE in language LANG. */
1000 static struct symbol
*
1001 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1003 struct symbol
*symbol
;
1004 struct gdbarch
*gdbarch
;
1006 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1008 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1009 symbol
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct symbol
);
1011 symbol
->ginfo
.name
= TYPE_NAME (type
);
1012 symbol
->ginfo
.language
= lang
;
1013 symbol
->owner
.arch
= gdbarch
;
1014 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1015 SYMBOL_TYPE (symbol
) = type
;
1016 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1017 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1022 /* Initialize the primitive type symbols of language LD.
1023 The primitive type vector must have already been initialized. */
1026 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1027 const struct language_defn
*la
,
1028 struct gdbarch
*gdbarch
)
1032 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1034 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1037 lai
->primitive_type_symbols
1038 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1040 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1042 lai
->primitive_type_symbols
[n
]
1043 = language_alloc_type_symbol (la
->la_language
,
1044 lai
->primitive_type_vector
[n
]);
1047 /* Note: The result of symbol lookup is normally a symbol *and* the block
1048 it was found in. Builtin types don't live in blocks. We *could* give
1049 them one, but there is no current need so to keep things simple symbol
1050 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1053 /* See language.h. */
1056 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1057 struct gdbarch
*gdbarch
,
1060 struct language_gdbarch
*ld
1061 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1062 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1063 struct type
**typep
;
1066 if (symbol_lookup_debug
)
1068 fprintf_unfiltered (gdb_stdlog
,
1069 "language_lookup_primitive_type_as_symbol"
1071 la
->la_name
, host_address_to_string (gdbarch
), name
);
1074 typep
= language_lookup_primitive_type_1 (lai
, name
);
1077 if (symbol_lookup_debug
)
1078 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1082 /* The set of symbols is lazily initialized. */
1083 if (lai
->primitive_type_symbols
== NULL
)
1084 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1086 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1088 if (symbol_lookup_debug
)
1089 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1093 /* Initialize the language routines. */
1096 _initialize_language (void)
1098 static const char *const type_or_range_names
[]
1099 = { "on", "off", "warn", "auto", NULL
};
1101 static const char *const case_sensitive_names
[]
1102 = { "on", "off", "auto", NULL
};
1104 language_gdbarch_data
1105 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1107 /* GDB commands for language specific stuff. */
1109 add_prefix_cmd ("check", no_class
, set_check
,
1110 _("Set the status of the type/range checker."),
1111 &setchecklist
, "set check ", 0, &setlist
);
1112 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1113 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1115 add_prefix_cmd ("check", no_class
, show_check
,
1116 _("Show the status of the type/range checker."),
1117 &showchecklist
, "show check ", 0, &showlist
);
1118 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1119 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1121 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1123 _("Set range checking. (on/warn/off/auto)"),
1124 _("Show range checking. (on/warn/off/auto)"),
1125 NULL
, set_range_command
,
1127 &setchecklist
, &showchecklist
);
1129 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1130 &case_sensitive
, _("\
1131 Set case sensitivity in name search. (on/off/auto)"), _("\
1132 Show case sensitivity in name search. (on/off/auto)"), _("\
1133 For Fortran the default is off; for other languages the default is on."),
1136 &setlist
, &showlist
);
1138 add_set_language_command ();
1140 language
= xstrdup ("auto");
1141 type
= xstrdup ("auto");
1142 range
= xstrdup ("auto");
1143 case_sensitive
= xstrdup ("auto");
1145 /* Have the above take effect. */
1146 set_language (language_auto
);