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 extern void _initialize_language (void);
51 static void unk_lang_error (const char *);
53 static int unk_lang_parser (struct parser_state
*);
55 static void show_check (char *, int);
57 static void set_check (char *, int);
59 static void set_range_case (void);
61 static void unk_lang_emit_char (int c
, struct type
*type
,
62 struct ui_file
*stream
, int quoter
);
64 static void unk_lang_printchar (int c
, struct type
*type
,
65 struct ui_file
*stream
);
67 static void unk_lang_value_print (struct value
*, struct ui_file
*,
68 const struct value_print_options
*);
70 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*, CORE_ADDR pc
);
72 /* Forward declaration */
73 extern const struct language_defn unknown_language_defn
;
75 /* The current (default at startup) state of type and range checking.
76 (If the modes are set to "auto", though, these are changed based
77 on the default language at startup, and then again based on the
78 language of the first source file. */
80 enum range_mode range_mode
= range_mode_auto
;
81 enum range_check range_check
= range_check_off
;
82 enum case_mode case_mode
= case_mode_auto
;
83 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
85 /* The current language and language_mode (see language.h). */
87 const struct language_defn
*current_language
= &unknown_language_defn
;
88 enum language_mode language_mode
= language_mode_auto
;
90 /* The language that the user expects to be typing in (the language
91 of main(), or the last language we notified them about, or C). */
93 const struct language_defn
*expected_language
;
95 /* The list of supported languages. Keep this in the same order as
96 the 'enum language' values. */
98 static const struct language_defn
*languages
[] = {
99 &unknown_language_defn
,
103 &cplus_language_defn
,
109 &pascal_language_defn
,
110 &opencl_language_defn
,
112 &minimal_language_defn
,
116 /* The current values of the "set language/type/range" enum
118 static const char *language
;
119 static const char *type
;
120 static const char *range
;
121 static const char *case_sensitive
;
123 /* Warning issued when current_language and the language of the current
124 frame do not match. */
125 char lang_frame_mismatch_warn
[] =
126 "Warning: the current language does not match this frame.";
128 /* This page contains the functions corresponding to GDB commands
129 and their helpers. */
131 /* Show command. Display a warning if the language set
132 does not match the frame. */
134 show_language_command (struct ui_file
*file
, int from_tty
,
135 struct cmd_list_element
*c
, const char *value
)
137 enum language flang
; /* The language of the frame. */
139 if (language_mode
== language_mode_auto
)
140 fprintf_filtered (gdb_stdout
,
141 _("The current source language is "
142 "\"auto; currently %s\".\n"),
143 current_language
->la_name
);
145 fprintf_filtered (gdb_stdout
,
146 _("The current source language is \"%s\".\n"),
147 current_language
->la_name
);
149 if (has_stack_frames ())
151 struct frame_info
*frame
;
153 frame
= get_selected_frame (NULL
);
154 flang
= get_frame_language (frame
);
155 if (flang
!= language_unknown
156 && language_mode
== language_mode_manual
157 && current_language
->la_language
!= flang
)
158 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
162 /* Set command. Change the current working language. */
164 set_language_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
166 enum language flang
= language_unknown
;
168 /* "local" is a synonym of "auto". */
169 if (strcmp (language
, "local") == 0)
172 /* Search the list of languages for a match. */
173 for (const auto &lang
: languages
)
175 if (strcmp (lang
->la_name
, language
) == 0)
177 /* Found it! Go into manual mode, and use this language. */
178 if (lang
->la_language
== language_auto
)
180 /* Enter auto mode. Set to the current frame's language, if
181 known, or fallback to the initial language. */
182 language_mode
= language_mode_auto
;
185 struct frame_info
*frame
;
187 frame
= get_selected_frame (NULL
);
188 flang
= get_frame_language (frame
);
190 CATCH (ex
, RETURN_MASK_ERROR
)
192 flang
= language_unknown
;
196 if (flang
!= language_unknown
)
197 set_language (flang
);
199 set_initial_language ();
200 expected_language
= current_language
;
205 /* Enter manual mode. Set the specified language. */
206 language_mode
= language_mode_manual
;
207 current_language
= lang
;
209 expected_language
= current_language
;
215 internal_error (__FILE__
, __LINE__
,
216 "Couldn't find language `%s' in known languages list.",
220 /* Show command. Display a warning if the range setting does
221 not match the current language. */
223 show_range_command (struct ui_file
*file
, int from_tty
,
224 struct cmd_list_element
*c
, const char *value
)
226 if (range_mode
== range_mode_auto
)
235 case range_check_off
:
238 case range_check_warn
:
242 internal_error (__FILE__
, __LINE__
,
243 "Unrecognized range check setting.");
246 fprintf_filtered (gdb_stdout
,
247 _("Range checking is \"auto; currently %s\".\n"),
251 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
254 if (range_check
!= current_language
->la_range_check
)
255 warning (_("the current range check setting "
256 "does not match the language.\n"));
259 /* Set command. Change the setting for range checking. */
261 set_range_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
263 if (strcmp (range
, "on") == 0)
265 range_check
= range_check_on
;
266 range_mode
= range_mode_manual
;
268 else if (strcmp (range
, "warn") == 0)
270 range_check
= range_check_warn
;
271 range_mode
= range_mode_manual
;
273 else if (strcmp (range
, "off") == 0)
275 range_check
= range_check_off
;
276 range_mode
= range_mode_manual
;
278 else if (strcmp (range
, "auto") == 0)
280 range_mode
= range_mode_auto
;
286 internal_error (__FILE__
, __LINE__
,
287 _("Unrecognized range check setting: \"%s\""), range
);
289 if (range_check
!= current_language
->la_range_check
)
290 warning (_("the current range check setting "
291 "does not match the language.\n"));
294 /* Show command. Display a warning if the case sensitivity setting does
295 not match the current language. */
297 show_case_command (struct ui_file
*file
, int from_tty
,
298 struct cmd_list_element
*c
, const char *value
)
300 if (case_mode
== case_mode_auto
)
302 const char *tmp
= NULL
;
304 switch (case_sensitivity
)
306 case case_sensitive_on
:
309 case case_sensitive_off
:
313 internal_error (__FILE__
, __LINE__
,
314 "Unrecognized case-sensitive setting.");
317 fprintf_filtered (gdb_stdout
,
318 _("Case sensitivity in "
319 "name search is \"auto; currently %s\".\n"),
323 fprintf_filtered (gdb_stdout
,
324 _("Case sensitivity in name search is \"%s\".\n"),
327 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
328 warning (_("the current case sensitivity setting does not match "
332 /* Set command. Change the setting for case sensitivity. */
335 set_case_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
337 if (strcmp (case_sensitive
, "on") == 0)
339 case_sensitivity
= case_sensitive_on
;
340 case_mode
= case_mode_manual
;
342 else if (strcmp (case_sensitive
, "off") == 0)
344 case_sensitivity
= case_sensitive_off
;
345 case_mode
= case_mode_manual
;
347 else if (strcmp (case_sensitive
, "auto") == 0)
349 case_mode
= case_mode_auto
;
355 internal_error (__FILE__
, __LINE__
,
356 "Unrecognized case-sensitive setting: \"%s\"",
360 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
361 warning (_("the current case sensitivity setting does not match "
365 /* Set the status of range and type checking and case sensitivity based on
366 the current modes and the current language.
367 If SHOW is non-zero, then print out the current language,
368 type and range checking status. */
370 set_range_case (void)
372 if (range_mode
== range_mode_auto
)
373 range_check
= current_language
->la_range_check
;
375 if (case_mode
== case_mode_auto
)
376 case_sensitivity
= current_language
->la_case_sensitivity
;
379 /* Set current language to (enum language) LANG. Returns previous
383 set_language (enum language lang
)
385 enum language prev_language
;
387 prev_language
= current_language
->la_language
;
388 current_language
= languages
[lang
];
390 return prev_language
;
394 /* Print out the current language settings: language, range and
395 type checking. If QUIETLY, print only what has changed. */
398 language_info (int quietly
)
400 if (quietly
&& expected_language
== current_language
)
403 expected_language
= current_language
;
404 printf_unfiltered (_("Current language: %s\n"), language
);
405 show_language_command (NULL
, 1, NULL
, NULL
);
409 printf_unfiltered (_("Range checking: %s\n"), range
);
410 show_range_command (NULL
, 1, NULL
, NULL
);
411 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
412 show_case_command (NULL
, 1, NULL
, NULL
);
417 /* Returns non-zero if the value is a pointer type. */
419 pointer_type (struct type
*type
)
421 return TYPE_CODE (type
) == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
425 /* This page contains functions that return info about
426 (struct value) values used in GDB. */
428 /* Returns non-zero if the value VAL represents a true value. */
430 value_true (struct value
*val
)
432 /* It is possible that we should have some sort of error if a non-boolean
433 value is used in this context. Possibly dependent on some kind of
434 "boolean-checking" option like range checking. But it should probably
435 not depend on the language except insofar as is necessary to identify
436 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
437 should be an error, probably). */
438 return !value_logical_not (val
);
441 /* This page contains functions for the printing out of
442 error messages that occur during type- and range-
445 /* This is called when a language fails a range-check. The
446 first argument should be a printf()-style format string, and the
447 rest of the arguments should be its arguments. If range_check is
448 range_check_on, an error is printed; if range_check_warn, a warning;
449 otherwise just the message. */
452 range_error (const char *string
,...)
456 va_start (args
, string
);
459 case range_check_warn
:
460 vwarning (string
, args
);
463 verror (string
, args
);
465 case range_check_off
:
466 /* FIXME: cagney/2002-01-30: Should this function print anything
467 when range error is off? */
468 vfprintf_filtered (gdb_stderr
, string
, args
);
469 fprintf_filtered (gdb_stderr
, "\n");
472 internal_error (__FILE__
, __LINE__
, _("bad switch"));
478 /* This page contains miscellaneous functions. */
480 /* Return the language enum for a given language string. */
483 language_enum (char *str
)
485 for (const auto &lang
: languages
)
486 if (strcmp (lang
->la_name
, str
) == 0)
487 return lang
->la_language
;
489 if (strcmp (str
, "local") == 0)
490 return language_auto
;
492 return language_unknown
;
495 /* Return the language struct for a given language enum. */
497 const struct language_defn
*
498 language_def (enum language lang
)
500 return languages
[lang
];
503 /* Return the language as a string. */
506 language_str (enum language lang
)
508 return languages
[lang
]->la_name
;
512 set_check (char *ignore
, int from_tty
)
515 "\"set check\" must be followed by the name of a check subcommand.\n");
516 help_list (setchecklist
, "set check ", all_commands
, gdb_stdout
);
520 show_check (char *ignore
, int from_tty
)
522 cmd_show_list (showchecklist
, from_tty
, "");
526 /* Build and install the "set language LANG" command. */
529 add_set_language_command ()
531 static const char **language_names
;
533 /* Build the language names array, to be used as enumeration in the
534 "set language" enum command. +1 for "local" and +1 for NULL
536 language_names
= new const char *[ARRAY_SIZE (languages
) + 2];
538 /* Display "auto", "local" and "unknown" first, and then the rest,
540 const char **language_names_p
= language_names
;
541 *language_names_p
++ = auto_language_defn
.la_name
;
542 *language_names_p
++ = "local";
543 *language_names_p
++ = unknown_language_defn
.la_name
;
544 const char **sort_begin
= language_names_p
;
545 for (const auto &lang
: languages
)
547 /* Already handled above. */
548 if (lang
->la_language
== language_auto
549 || lang
->la_language
== language_unknown
)
551 *language_names_p
++ = lang
->la_name
;
553 *language_names_p
= NULL
;
554 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
556 /* Add the filename extensions. */
557 for (const auto &lang
: languages
)
558 if (lang
->la_filename_extensions
!= NULL
)
560 for (size_t i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
561 add_filename_language (lang
->la_filename_extensions
[i
],
565 /* Build the "help set language" docs. */
568 doc
.printf (_("Set the current source language.\n"
569 "The currently understood settings are:\n\nlocal or "
570 "auto Automatic setting based on source file\n"));
572 for (const auto &lang
: languages
)
574 /* Already dealt with these above. */
575 if (lang
->la_language
== language_unknown
576 || lang
->la_language
== language_auto
)
579 /* FIXME: i18n: for now assume that the human-readable name is
580 just a capitalization of the internal name. */
581 doc
.printf ("%-16s Use the %c%s language\n",
583 /* Capitalize first letter of language name. */
584 toupper (lang
->la_name
[0]),
588 add_setshow_enum_cmd ("language", class_support
,
592 _("Show the current source language."),
593 NULL
, set_language_command
,
594 show_language_command
,
595 &setlist
, &showlist
);
598 /* Iterate through all registered languages looking for and calling
599 any non-NULL struct language_defn.skip_trampoline() functions.
600 Return the result from the first that returns non-zero, or 0 if all
603 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
605 for (const auto &lang
: languages
)
607 if (lang
->skip_trampoline
!= NULL
)
609 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
619 /* Return demangled language symbol, or NULL.
620 FIXME: Options are only useful for certain languages and ignored
621 by others, so it would be better to remove them here and have a
622 more flexible demangler for the languages that need it.
623 FIXME: Sometimes the demangler is invoked when we don't know the
624 language, so we can't use this everywhere. */
626 language_demangle (const struct language_defn
*current_language
,
627 const char *mangled
, int options
)
629 if (current_language
!= NULL
&& current_language
->la_demangle
)
630 return current_language
->la_demangle (mangled
, options
);
634 /* See langauge.h. */
637 language_sniff_from_mangled_name (const struct language_defn
*lang
,
638 const char *mangled
, char **demangled
)
640 gdb_assert (lang
!= NULL
);
642 if (lang
->la_sniff_from_mangled_name
== NULL
)
648 return lang
->la_sniff_from_mangled_name (mangled
, demangled
);
651 /* Return class name from physname or NULL. */
653 language_class_name_from_physname (const struct language_defn
*lang
,
654 const char *physname
)
656 if (lang
!= NULL
&& lang
->la_class_name_from_physname
)
657 return lang
->la_class_name_from_physname (physname
);
661 /* Return non-zero if TYPE should be passed (and returned) by
662 reference at the language level. */
664 language_pass_by_reference (struct type
*type
)
666 return current_language
->la_pass_by_reference (type
);
669 /* Return zero; by default, types are passed by value at the language
670 level. The target ABI may pass or return some structs by reference
671 independent of this. */
673 default_pass_by_reference (struct type
*type
)
678 /* Return the default string containing the list of characters
679 delimiting words. This is a reasonable default value that
680 most languages should be able to use. */
683 default_word_break_characters (void)
685 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
688 /* Print the index of array elements using the C99 syntax. */
691 default_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
692 const struct value_print_options
*options
)
694 fprintf_filtered (stream
, "[");
695 LA_VALUE_PRINT (index_value
, stream
, options
);
696 fprintf_filtered (stream
, "] = ");
700 default_get_string (struct value
*value
, gdb_byte
**buffer
, int *length
,
701 struct type
**char_type
, const char **charset
)
703 error (_("Getting a string is unsupported in this language."));
706 /* Define the language that is no language. */
709 unk_lang_parser (struct parser_state
*ps
)
715 unk_lang_error (const char *msg
)
717 error (_("Attempted to parse an expression with unknown language"));
721 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
724 error (_("internal error - unimplemented "
725 "function unk_lang_emit_char called."));
729 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
731 error (_("internal error - unimplemented "
732 "function unk_lang_printchar called."));
736 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
737 const gdb_byte
*string
, unsigned int length
,
738 const char *encoding
, int force_ellipses
,
739 const struct value_print_options
*options
)
741 error (_("internal error - unimplemented "
742 "function unk_lang_printstr called."));
746 unk_lang_print_type (struct type
*type
, const char *varstring
,
747 struct ui_file
*stream
, int show
, int level
,
748 const struct type_print_options
*flags
)
750 error (_("internal error - unimplemented "
751 "function unk_lang_print_type called."));
755 unk_lang_val_print (struct type
*type
,
756 int embedded_offset
, CORE_ADDR address
,
757 struct ui_file
*stream
, int recurse
,
759 const struct value_print_options
*options
)
761 error (_("internal error - unimplemented "
762 "function unk_lang_val_print called."));
766 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
767 const struct value_print_options
*options
)
769 error (_("internal error - unimplemented "
770 "function unk_lang_value_print called."));
773 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
778 /* Unknown languages just use the cplus demangler. */
779 static char *unk_lang_demangle (const char *mangled
, int options
)
781 return gdb_demangle (mangled
, options
);
784 static char *unk_lang_class_name (const char *mangled
)
789 static const struct op_print unk_op_print_tab
[] =
791 {NULL
, OP_NULL
, PREC_NULL
, 0}
795 unknown_language_arch_info (struct gdbarch
*gdbarch
,
796 struct language_arch_info
*lai
)
798 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
799 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
800 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
804 const struct language_defn unknown_language_defn
=
814 &exp_descriptor_standard
,
818 unk_lang_printchar
, /* Print character constant */
821 unk_lang_print_type
, /* Print a type using appropriate syntax */
822 default_print_typedef
, /* Print a typedef using appropriate syntax */
823 unk_lang_val_print
, /* Print a value using appropriate syntax */
824 unk_lang_value_print
, /* Print a top-level value */
825 default_read_var_value
, /* la_read_var_value */
826 unk_lang_trampoline
, /* Language specific skip_trampoline */
827 "this", /* name_of_this */
828 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
829 basic_lookup_transparent_type
,/* lookup_transparent_type */
830 unk_lang_demangle
, /* Language specific symbol demangler */
832 unk_lang_class_name
, /* Language specific
833 class_name_from_physname */
834 unk_op_print_tab
, /* expression operators for printing */
835 1, /* c-style arrays */
836 0, /* String lower bound */
837 default_word_break_characters
,
838 default_collect_symbol_completion_matches
,
839 unknown_language_arch_info
, /* la_language_arch_info. */
840 default_print_array_index
,
841 default_pass_by_reference
,
843 c_watch_location_expression
,
844 NULL
, /* la_get_symbol_name_cmp */
845 iterate_over_symbols
,
852 /* These two structs define fake entries for the "local" and "auto"
854 const struct language_defn auto_language_defn
=
864 &exp_descriptor_standard
,
868 unk_lang_printchar
, /* Print character constant */
871 unk_lang_print_type
, /* Print a type using appropriate syntax */
872 default_print_typedef
, /* Print a typedef using appropriate syntax */
873 unk_lang_val_print
, /* Print a value using appropriate syntax */
874 unk_lang_value_print
, /* Print a top-level value */
875 default_read_var_value
, /* la_read_var_value */
876 unk_lang_trampoline
, /* Language specific skip_trampoline */
877 "this", /* name_of_this */
878 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
879 basic_lookup_transparent_type
,/* lookup_transparent_type */
880 unk_lang_demangle
, /* Language specific symbol demangler */
882 unk_lang_class_name
, /* Language specific
883 class_name_from_physname */
884 unk_op_print_tab
, /* expression operators for printing */
885 1, /* c-style arrays */
886 0, /* String lower bound */
887 default_word_break_characters
,
888 default_collect_symbol_completion_matches
,
889 unknown_language_arch_info
, /* la_language_arch_info. */
890 default_print_array_index
,
891 default_pass_by_reference
,
893 c_watch_location_expression
,
894 NULL
, /* la_get_symbol_name_cmp */
895 iterate_over_symbols
,
903 /* Per-architecture language information. */
905 static struct gdbarch_data
*language_gdbarch_data
;
907 struct language_gdbarch
909 /* A vector of per-language per-architecture info. Indexed by "enum
911 struct language_arch_info arch_info
[nr_languages
];
915 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
917 struct language_gdbarch
*l
;
919 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
920 for (const auto &lang
: languages
)
921 if (lang
!= NULL
&& lang
->la_language_arch_info
!= NULL
)
923 lang
->la_language_arch_info (gdbarch
,
924 l
->arch_info
+ lang
->la_language
);
931 language_string_char_type (const struct language_defn
*la
,
932 struct gdbarch
*gdbarch
)
934 struct language_gdbarch
*ld
935 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
937 return ld
->arch_info
[la
->la_language
].string_char_type
;
941 language_bool_type (const struct language_defn
*la
,
942 struct gdbarch
*gdbarch
)
944 struct language_gdbarch
*ld
945 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
947 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
951 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
952 NULL
, VAR_DOMAIN
, NULL
).symbol
;
955 struct type
*type
= SYMBOL_TYPE (sym
);
957 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
962 return ld
->arch_info
[la
->la_language
].bool_type_default
;
965 /* Helper function for primitive type lookup. */
967 static struct type
**
968 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
973 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
975 if (strcmp (TYPE_NAME (*p
), name
) == 0)
981 /* See language.h. */
984 language_lookup_primitive_type (const struct language_defn
*la
,
985 struct gdbarch
*gdbarch
,
988 struct language_gdbarch
*ld
=
989 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
992 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
999 /* Helper function for type lookup as a symbol.
1000 Create the symbol corresponding to type TYPE in language LANG. */
1002 static struct symbol
*
1003 language_alloc_type_symbol (enum language lang
, struct type
*type
)
1005 struct symbol
*symbol
;
1006 struct gdbarch
*gdbarch
;
1008 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1010 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1011 symbol
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct symbol
);
1013 symbol
->ginfo
.name
= TYPE_NAME (type
);
1014 symbol
->ginfo
.language
= lang
;
1015 symbol
->owner
.arch
= gdbarch
;
1016 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1017 SYMBOL_TYPE (symbol
) = type
;
1018 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1019 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1024 /* Initialize the primitive type symbols of language LD.
1025 The primitive type vector must have already been initialized. */
1028 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1029 const struct language_defn
*la
,
1030 struct gdbarch
*gdbarch
)
1034 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1036 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1039 lai
->primitive_type_symbols
1040 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1042 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1044 lai
->primitive_type_symbols
[n
]
1045 = language_alloc_type_symbol (la
->la_language
,
1046 lai
->primitive_type_vector
[n
]);
1049 /* Note: The result of symbol lookup is normally a symbol *and* the block
1050 it was found in. Builtin types don't live in blocks. We *could* give
1051 them one, but there is no current need so to keep things simple symbol
1052 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1055 /* See language.h. */
1058 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1059 struct gdbarch
*gdbarch
,
1062 struct language_gdbarch
*ld
1063 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1064 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1065 struct type
**typep
;
1068 if (symbol_lookup_debug
)
1070 fprintf_unfiltered (gdb_stdlog
,
1071 "language_lookup_primitive_type_as_symbol"
1073 la
->la_name
, host_address_to_string (gdbarch
), name
);
1076 typep
= language_lookup_primitive_type_1 (lai
, name
);
1079 if (symbol_lookup_debug
)
1080 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1084 /* The set of symbols is lazily initialized. */
1085 if (lai
->primitive_type_symbols
== NULL
)
1086 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1088 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1090 if (symbol_lookup_debug
)
1091 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1095 /* Initialize the language routines. */
1098 _initialize_language (void)
1100 static const char *const type_or_range_names
[]
1101 = { "on", "off", "warn", "auto", NULL
};
1103 static const char *const case_sensitive_names
[]
1104 = { "on", "off", "auto", NULL
};
1106 language_gdbarch_data
1107 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1109 /* GDB commands for language specific stuff. */
1111 add_prefix_cmd ("check", no_class
, set_check
,
1112 _("Set the status of the type/range checker."),
1113 &setchecklist
, "set check ", 0, &setlist
);
1114 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1115 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1117 add_prefix_cmd ("check", no_class
, show_check
,
1118 _("Show the status of the type/range checker."),
1119 &showchecklist
, "show check ", 0, &showlist
);
1120 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1121 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1123 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1125 _("Set range checking. (on/warn/off/auto)"),
1126 _("Show range checking. (on/warn/off/auto)"),
1127 NULL
, set_range_command
,
1129 &setchecklist
, &showchecklist
);
1131 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1132 &case_sensitive
, _("\
1133 Set case sensitivity in name search. (on/off/auto)"), _("\
1134 Show case sensitivity in name search. (on/off/auto)"), _("\
1135 For Fortran the default is off; for other languages the default is on."),
1138 &setlist
, &showlist
);
1140 add_set_language_command ();
1142 language
= xstrdup ("auto");
1143 type
= xstrdup ("auto");
1144 range
= xstrdup ("auto");
1145 case_sensitive
= xstrdup ("auto");
1147 /* Have the above take effect. */
1148 set_language (language_auto
);