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 set_range_case (void);
55 static void unk_lang_emit_char (int c
, struct type
*type
,
56 struct ui_file
*stream
, int quoter
);
58 static void unk_lang_printchar (int c
, struct type
*type
,
59 struct ui_file
*stream
);
61 static void unk_lang_value_print (struct value
*, struct ui_file
*,
62 const struct value_print_options
*);
64 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*, CORE_ADDR pc
);
66 /* Forward declaration */
67 extern const struct language_defn unknown_language_defn
;
69 /* The current (default at startup) state of type and range checking.
70 (If the modes are set to "auto", though, these are changed based
71 on the default language at startup, and then again based on the
72 language of the first source file. */
74 enum range_mode range_mode
= range_mode_auto
;
75 enum range_check range_check
= range_check_off
;
76 enum case_mode case_mode
= case_mode_auto
;
77 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
79 /* The current language and language_mode (see language.h). */
81 const struct language_defn
*current_language
= &unknown_language_defn
;
82 enum language_mode language_mode
= language_mode_auto
;
84 /* The language that the user expects to be typing in (the language
85 of main(), or the last language we notified them about, or C). */
87 const struct language_defn
*expected_language
;
89 /* The list of supported languages. Keep this in the same order as
90 the 'enum language' values. */
92 static const struct language_defn
*languages
[] = {
93 &unknown_language_defn
,
103 &pascal_language_defn
,
104 &opencl_language_defn
,
106 &minimal_language_defn
,
110 /* The current values of the "set language/type/range" enum
112 static const char *language
;
113 static const char *type
;
114 static const char *range
;
115 static const char *case_sensitive
;
117 /* Warning issued when current_language and the language of the current
118 frame do not match. */
119 char lang_frame_mismatch_warn
[] =
120 "Warning: the current language does not match this frame.";
122 /* This page contains the functions corresponding to GDB commands
123 and their helpers. */
125 /* Show command. Display a warning if the language set
126 does not match the frame. */
128 show_language_command (struct ui_file
*file
, int from_tty
,
129 struct cmd_list_element
*c
, const char *value
)
131 enum language flang
; /* The language of the frame. */
133 if (language_mode
== language_mode_auto
)
134 fprintf_filtered (gdb_stdout
,
135 _("The current source language is "
136 "\"auto; currently %s\".\n"),
137 current_language
->la_name
);
139 fprintf_filtered (gdb_stdout
,
140 _("The current source language is \"%s\".\n"),
141 current_language
->la_name
);
143 if (has_stack_frames ())
145 struct frame_info
*frame
;
147 frame
= get_selected_frame (NULL
);
148 flang
= get_frame_language (frame
);
149 if (flang
!= language_unknown
150 && language_mode
== language_mode_manual
151 && current_language
->la_language
!= flang
)
152 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
156 /* Set command. Change the current working language. */
158 set_language_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
160 enum language flang
= language_unknown
;
162 /* "local" is a synonym of "auto". */
163 if (strcmp (language
, "local") == 0)
166 /* Search the list of languages for a match. */
167 for (const auto &lang
: languages
)
169 if (strcmp (lang
->la_name
, language
) == 0)
171 /* Found it! Go into manual mode, and use this language. */
172 if (lang
->la_language
== language_auto
)
174 /* Enter auto mode. Set to the current frame's language, if
175 known, or fallback to the initial language. */
176 language_mode
= language_mode_auto
;
179 struct frame_info
*frame
;
181 frame
= get_selected_frame (NULL
);
182 flang
= get_frame_language (frame
);
184 CATCH (ex
, RETURN_MASK_ERROR
)
186 flang
= language_unknown
;
190 if (flang
!= language_unknown
)
191 set_language (flang
);
193 set_initial_language ();
194 expected_language
= current_language
;
199 /* Enter manual mode. Set the specified language. */
200 language_mode
= language_mode_manual
;
201 current_language
= lang
;
203 expected_language
= current_language
;
209 internal_error (__FILE__
, __LINE__
,
210 "Couldn't find language `%s' in known languages list.",
214 /* Show command. Display a warning if the range setting does
215 not match the current language. */
217 show_range_command (struct ui_file
*file
, int from_tty
,
218 struct cmd_list_element
*c
, const char *value
)
220 if (range_mode
== range_mode_auto
)
229 case range_check_off
:
232 case range_check_warn
:
236 internal_error (__FILE__
, __LINE__
,
237 "Unrecognized range check setting.");
240 fprintf_filtered (gdb_stdout
,
241 _("Range checking is \"auto; currently %s\".\n"),
245 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
248 if (range_check
!= current_language
->la_range_check
)
249 warning (_("the current range check setting "
250 "does not match the language.\n"));
253 /* Set command. Change the setting for range checking. */
255 set_range_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
257 if (strcmp (range
, "on") == 0)
259 range_check
= range_check_on
;
260 range_mode
= range_mode_manual
;
262 else if (strcmp (range
, "warn") == 0)
264 range_check
= range_check_warn
;
265 range_mode
= range_mode_manual
;
267 else if (strcmp (range
, "off") == 0)
269 range_check
= range_check_off
;
270 range_mode
= range_mode_manual
;
272 else if (strcmp (range
, "auto") == 0)
274 range_mode
= range_mode_auto
;
280 internal_error (__FILE__
, __LINE__
,
281 _("Unrecognized range check setting: \"%s\""), range
);
283 if (range_check
!= current_language
->la_range_check
)
284 warning (_("the current range check setting "
285 "does not match the language.\n"));
288 /* Show command. Display a warning if the case sensitivity setting does
289 not match the current language. */
291 show_case_command (struct ui_file
*file
, int from_tty
,
292 struct cmd_list_element
*c
, const char *value
)
294 if (case_mode
== case_mode_auto
)
296 const char *tmp
= NULL
;
298 switch (case_sensitivity
)
300 case case_sensitive_on
:
303 case case_sensitive_off
:
307 internal_error (__FILE__
, __LINE__
,
308 "Unrecognized case-sensitive setting.");
311 fprintf_filtered (gdb_stdout
,
312 _("Case sensitivity in "
313 "name search is \"auto; currently %s\".\n"),
317 fprintf_filtered (gdb_stdout
,
318 _("Case sensitivity in name search is \"%s\".\n"),
321 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
322 warning (_("the current case sensitivity setting does not match "
326 /* Set command. Change the setting for case sensitivity. */
329 set_case_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
331 if (strcmp (case_sensitive
, "on") == 0)
333 case_sensitivity
= case_sensitive_on
;
334 case_mode
= case_mode_manual
;
336 else if (strcmp (case_sensitive
, "off") == 0)
338 case_sensitivity
= case_sensitive_off
;
339 case_mode
= case_mode_manual
;
341 else if (strcmp (case_sensitive
, "auto") == 0)
343 case_mode
= case_mode_auto
;
349 internal_error (__FILE__
, __LINE__
,
350 "Unrecognized case-sensitive setting: \"%s\"",
354 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
355 warning (_("the current case sensitivity setting does not match "
359 /* Set the status of range and type checking and case sensitivity based on
360 the current modes and the current language.
361 If SHOW is non-zero, then print out the current language,
362 type and range checking status. */
364 set_range_case (void)
366 if (range_mode
== range_mode_auto
)
367 range_check
= current_language
->la_range_check
;
369 if (case_mode
== case_mode_auto
)
370 case_sensitivity
= current_language
->la_case_sensitivity
;
373 /* Set current language to (enum language) LANG. Returns previous
377 set_language (enum language lang
)
379 enum language prev_language
;
381 prev_language
= current_language
->la_language
;
382 current_language
= languages
[lang
];
384 return prev_language
;
388 /* Print out the current language settings: language, range and
389 type checking. If QUIETLY, print only what has changed. */
392 language_info (int quietly
)
394 if (quietly
&& expected_language
== current_language
)
397 expected_language
= current_language
;
398 printf_unfiltered (_("Current language: %s\n"), language
);
399 show_language_command (NULL
, 1, NULL
, NULL
);
403 printf_unfiltered (_("Range checking: %s\n"), range
);
404 show_range_command (NULL
, 1, NULL
, NULL
);
405 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
406 show_case_command (NULL
, 1, NULL
, NULL
);
411 /* Returns non-zero if the value is a pointer type. */
413 pointer_type (struct type
*type
)
415 return TYPE_CODE (type
) == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (type
);
419 /* This page contains functions that return info about
420 (struct value) values used in GDB. */
422 /* Returns non-zero if the value VAL represents a true value. */
424 value_true (struct value
*val
)
426 /* It is possible that we should have some sort of error if a non-boolean
427 value is used in this context. Possibly dependent on some kind of
428 "boolean-checking" option like range checking. But it should probably
429 not depend on the language except insofar as is necessary to identify
430 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
431 should be an error, probably). */
432 return !value_logical_not (val
);
435 /* This page contains functions for the printing out of
436 error messages that occur during type- and range-
439 /* This is called when a language fails a range-check. The
440 first argument should be a printf()-style format string, and the
441 rest of the arguments should be its arguments. If range_check is
442 range_check_on, an error is printed; if range_check_warn, a warning;
443 otherwise just the message. */
446 range_error (const char *string
,...)
450 va_start (args
, string
);
453 case range_check_warn
:
454 vwarning (string
, args
);
457 verror (string
, args
);
459 case range_check_off
:
460 /* FIXME: cagney/2002-01-30: Should this function print anything
461 when range error is off? */
462 vfprintf_filtered (gdb_stderr
, string
, args
);
463 fprintf_filtered (gdb_stderr
, "\n");
466 internal_error (__FILE__
, __LINE__
, _("bad switch"));
472 /* This page contains miscellaneous functions. */
474 /* Return the language enum for a given language string. */
477 language_enum (const char *str
)
479 for (const auto &lang
: languages
)
480 if (strcmp (lang
->la_name
, str
) == 0)
481 return lang
->la_language
;
483 if (strcmp (str
, "local") == 0)
484 return language_auto
;
486 return language_unknown
;
489 /* Return the language struct for a given language enum. */
491 const struct language_defn
*
492 language_def (enum language lang
)
494 return languages
[lang
];
497 /* Return the language as a string. */
500 language_str (enum language lang
)
502 return languages
[lang
]->la_name
;
506 set_check (const char *ignore
, int from_tty
)
509 "\"set check\" must be followed by the name of a check subcommand.\n");
510 help_list (setchecklist
, "set check ", all_commands
, gdb_stdout
);
514 show_check (const char *ignore
, int from_tty
)
516 cmd_show_list (showchecklist
, from_tty
, "");
520 /* Build and install the "set language LANG" command. */
523 add_set_language_command ()
525 static const char **language_names
;
527 /* Build the language names array, to be used as enumeration in the
528 "set language" enum command. +1 for "local" and +1 for NULL
530 language_names
= new const char *[ARRAY_SIZE (languages
) + 2];
532 /* Display "auto", "local" and "unknown" first, and then the rest,
534 const char **language_names_p
= language_names
;
535 *language_names_p
++ = auto_language_defn
.la_name
;
536 *language_names_p
++ = "local";
537 *language_names_p
++ = unknown_language_defn
.la_name
;
538 const char **sort_begin
= language_names_p
;
539 for (const auto &lang
: languages
)
541 /* Already handled above. */
542 if (lang
->la_language
== language_auto
543 || lang
->la_language
== language_unknown
)
545 *language_names_p
++ = lang
->la_name
;
547 *language_names_p
= NULL
;
548 std::sort (sort_begin
, language_names_p
, compare_cstrings
);
550 /* Add the filename extensions. */
551 for (const auto &lang
: languages
)
552 if (lang
->la_filename_extensions
!= NULL
)
554 for (size_t i
= 0; lang
->la_filename_extensions
[i
] != NULL
; ++i
)
555 add_filename_language (lang
->la_filename_extensions
[i
],
559 /* Build the "help set language" docs. */
562 doc
.printf (_("Set the current source language.\n"
563 "The currently understood settings are:\n\nlocal or "
564 "auto Automatic setting based on source file\n"));
566 for (const auto &lang
: languages
)
568 /* Already dealt with these above. */
569 if (lang
->la_language
== language_unknown
570 || lang
->la_language
== language_auto
)
573 /* FIXME: i18n: for now assume that the human-readable name is
574 just a capitalization of the internal name. */
575 doc
.printf ("%-16s Use the %c%s language\n",
577 /* Capitalize first letter of language name. */
578 toupper (lang
->la_name
[0]),
582 add_setshow_enum_cmd ("language", class_support
,
586 _("Show the current source language."),
587 NULL
, set_language_command
,
588 show_language_command
,
589 &setlist
, &showlist
);
592 /* Iterate through all registered languages looking for and calling
593 any non-NULL struct language_defn.skip_trampoline() functions.
594 Return the result from the first that returns non-zero, or 0 if all
597 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
599 for (const auto &lang
: languages
)
601 if (lang
->skip_trampoline
!= NULL
)
603 CORE_ADDR real_pc
= lang
->skip_trampoline (frame
, pc
);
613 /* Return demangled language symbol, or NULL.
614 FIXME: Options are only useful for certain languages and ignored
615 by others, so it would be better to remove them here and have a
616 more flexible demangler for the languages that need it.
617 FIXME: Sometimes the demangler is invoked when we don't know the
618 language, so we can't use this everywhere. */
620 language_demangle (const struct language_defn
*current_language
,
621 const char *mangled
, int options
)
623 if (current_language
!= NULL
&& current_language
->la_demangle
)
624 return current_language
->la_demangle (mangled
, options
);
628 /* See langauge.h. */
631 language_sniff_from_mangled_name (const struct language_defn
*lang
,
632 const char *mangled
, char **demangled
)
634 gdb_assert (lang
!= NULL
);
636 if (lang
->la_sniff_from_mangled_name
== NULL
)
642 return lang
->la_sniff_from_mangled_name (mangled
, demangled
);
645 /* Return class name from physname or NULL. */
647 language_class_name_from_physname (const struct language_defn
*lang
,
648 const char *physname
)
650 if (lang
!= NULL
&& lang
->la_class_name_from_physname
)
651 return lang
->la_class_name_from_physname (physname
);
655 /* Return non-zero if TYPE should be passed (and returned) by
656 reference at the language level. */
658 language_pass_by_reference (struct type
*type
)
660 return current_language
->la_pass_by_reference (type
);
663 /* Return zero; by default, types are passed by value at the language
664 level. The target ABI may pass or return some structs by reference
665 independent of this. */
667 default_pass_by_reference (struct type
*type
)
672 /* Return the default string containing the list of characters
673 delimiting words. This is a reasonable default value that
674 most languages should be able to use. */
677 default_word_break_characters (void)
679 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
682 /* Print the index of array elements using the C99 syntax. */
685 default_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
686 const struct value_print_options
*options
)
688 fprintf_filtered (stream
, "[");
689 LA_VALUE_PRINT (index_value
, stream
, options
);
690 fprintf_filtered (stream
, "] = ");
694 default_get_string (struct value
*value
, gdb_byte
**buffer
, int *length
,
695 struct type
**char_type
, const char **charset
)
697 error (_("Getting a string is unsupported in this language."));
700 /* Define the language that is no language. */
703 unk_lang_parser (struct parser_state
*ps
)
709 unk_lang_error (const char *msg
)
711 error (_("Attempted to parse an expression with unknown language"));
715 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
718 error (_("internal error - unimplemented "
719 "function unk_lang_emit_char called."));
723 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
725 error (_("internal error - unimplemented "
726 "function unk_lang_printchar called."));
730 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
731 const gdb_byte
*string
, unsigned int length
,
732 const char *encoding
, int force_ellipses
,
733 const struct value_print_options
*options
)
735 error (_("internal error - unimplemented "
736 "function unk_lang_printstr called."));
740 unk_lang_print_type (struct type
*type
, const char *varstring
,
741 struct ui_file
*stream
, int show
, int level
,
742 const struct type_print_options
*flags
)
744 error (_("internal error - unimplemented "
745 "function unk_lang_print_type called."));
749 unk_lang_val_print (struct type
*type
,
750 int embedded_offset
, CORE_ADDR address
,
751 struct ui_file
*stream
, int recurse
,
753 const struct value_print_options
*options
)
755 error (_("internal error - unimplemented "
756 "function unk_lang_val_print called."));
760 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
761 const struct value_print_options
*options
)
763 error (_("internal error - unimplemented "
764 "function unk_lang_value_print called."));
767 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
772 /* Unknown languages just use the cplus demangler. */
773 static char *unk_lang_demangle (const char *mangled
, int options
)
775 return gdb_demangle (mangled
, options
);
778 static char *unk_lang_class_name (const char *mangled
)
783 static const struct op_print unk_op_print_tab
[] =
785 {NULL
, OP_NULL
, PREC_NULL
, 0}
789 unknown_language_arch_info (struct gdbarch
*gdbarch
,
790 struct language_arch_info
*lai
)
792 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
793 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
794 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
798 const struct language_defn unknown_language_defn
=
808 &exp_descriptor_standard
,
812 unk_lang_printchar
, /* Print character constant */
815 unk_lang_print_type
, /* Print a type using appropriate syntax */
816 default_print_typedef
, /* Print a typedef using appropriate syntax */
817 unk_lang_val_print
, /* Print a value using appropriate syntax */
818 unk_lang_value_print
, /* Print a top-level value */
819 default_read_var_value
, /* la_read_var_value */
820 unk_lang_trampoline
, /* Language specific skip_trampoline */
821 "this", /* name_of_this */
822 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
823 basic_lookup_transparent_type
,/* lookup_transparent_type */
824 unk_lang_demangle
, /* Language specific symbol demangler */
826 unk_lang_class_name
, /* Language specific
827 class_name_from_physname */
828 unk_op_print_tab
, /* expression operators for printing */
829 1, /* c-style arrays */
830 0, /* String lower bound */
831 default_word_break_characters
,
832 default_collect_symbol_completion_matches
,
833 unknown_language_arch_info
, /* la_language_arch_info. */
834 default_print_array_index
,
835 default_pass_by_reference
,
837 c_watch_location_expression
,
838 NULL
, /* la_get_symbol_name_cmp */
839 iterate_over_symbols
,
846 /* These two structs define fake entries for the "local" and "auto"
848 const struct language_defn auto_language_defn
=
858 &exp_descriptor_standard
,
862 unk_lang_printchar
, /* Print character constant */
865 unk_lang_print_type
, /* Print a type using appropriate syntax */
866 default_print_typedef
, /* Print a typedef using appropriate syntax */
867 unk_lang_val_print
, /* Print a value using appropriate syntax */
868 unk_lang_value_print
, /* Print a top-level value */
869 default_read_var_value
, /* la_read_var_value */
870 unk_lang_trampoline
, /* Language specific skip_trampoline */
871 "this", /* name_of_this */
872 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
873 basic_lookup_transparent_type
,/* lookup_transparent_type */
874 unk_lang_demangle
, /* Language specific symbol demangler */
876 unk_lang_class_name
, /* Language specific
877 class_name_from_physname */
878 unk_op_print_tab
, /* expression operators for printing */
879 1, /* c-style arrays */
880 0, /* String lower bound */
881 default_word_break_characters
,
882 default_collect_symbol_completion_matches
,
883 unknown_language_arch_info
, /* la_language_arch_info. */
884 default_print_array_index
,
885 default_pass_by_reference
,
887 c_watch_location_expression
,
888 NULL
, /* la_get_symbol_name_cmp */
889 iterate_over_symbols
,
897 /* Per-architecture language information. */
899 static struct gdbarch_data
*language_gdbarch_data
;
901 struct language_gdbarch
903 /* A vector of per-language per-architecture info. Indexed by "enum
905 struct language_arch_info arch_info
[nr_languages
];
909 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
911 struct language_gdbarch
*l
;
913 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
914 for (const auto &lang
: languages
)
915 if (lang
!= NULL
&& lang
->la_language_arch_info
!= NULL
)
917 lang
->la_language_arch_info (gdbarch
,
918 l
->arch_info
+ lang
->la_language
);
925 language_string_char_type (const struct language_defn
*la
,
926 struct gdbarch
*gdbarch
)
928 struct language_gdbarch
*ld
929 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
931 return ld
->arch_info
[la
->la_language
].string_char_type
;
935 language_bool_type (const struct language_defn
*la
,
936 struct gdbarch
*gdbarch
)
938 struct language_gdbarch
*ld
939 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
941 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
945 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
946 NULL
, VAR_DOMAIN
, NULL
).symbol
;
949 struct type
*type
= SYMBOL_TYPE (sym
);
951 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
956 return ld
->arch_info
[la
->la_language
].bool_type_default
;
959 /* Helper function for primitive type lookup. */
961 static struct type
**
962 language_lookup_primitive_type_1 (const struct language_arch_info
*lai
,
967 for (p
= lai
->primitive_type_vector
; (*p
) != NULL
; p
++)
969 if (strcmp (TYPE_NAME (*p
), name
) == 0)
975 /* See language.h. */
978 language_lookup_primitive_type (const struct language_defn
*la
,
979 struct gdbarch
*gdbarch
,
982 struct language_gdbarch
*ld
=
983 (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
986 typep
= language_lookup_primitive_type_1 (&ld
->arch_info
[la
->la_language
],
993 /* Helper function for type lookup as a symbol.
994 Create the symbol corresponding to type TYPE in language LANG. */
996 static struct symbol
*
997 language_alloc_type_symbol (enum language lang
, struct type
*type
)
999 struct symbol
*symbol
;
1000 struct gdbarch
*gdbarch
;
1002 gdb_assert (!TYPE_OBJFILE_OWNED (type
));
1004 gdbarch
= TYPE_OWNER (type
).gdbarch
;
1005 symbol
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct symbol
);
1007 symbol
->ginfo
.name
= TYPE_NAME (type
);
1008 symbol
->ginfo
.language
= lang
;
1009 symbol
->owner
.arch
= gdbarch
;
1010 SYMBOL_OBJFILE_OWNED (symbol
) = 0;
1011 SYMBOL_TYPE (symbol
) = type
;
1012 SYMBOL_DOMAIN (symbol
) = VAR_DOMAIN
;
1013 SYMBOL_ACLASS_INDEX (symbol
) = LOC_TYPEDEF
;
1018 /* Initialize the primitive type symbols of language LD.
1019 The primitive type vector must have already been initialized. */
1022 language_init_primitive_type_symbols (struct language_arch_info
*lai
,
1023 const struct language_defn
*la
,
1024 struct gdbarch
*gdbarch
)
1028 gdb_assert (lai
->primitive_type_vector
!= NULL
);
1030 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1033 lai
->primitive_type_symbols
1034 = GDBARCH_OBSTACK_CALLOC (gdbarch
, n
+ 1, struct symbol
*);
1036 for (n
= 0; lai
->primitive_type_vector
[n
] != NULL
; ++n
)
1038 lai
->primitive_type_symbols
[n
]
1039 = language_alloc_type_symbol (la
->la_language
,
1040 lai
->primitive_type_vector
[n
]);
1043 /* Note: The result of symbol lookup is normally a symbol *and* the block
1044 it was found in. Builtin types don't live in blocks. We *could* give
1045 them one, but there is no current need so to keep things simple symbol
1046 lookup is extended to allow for BLOCK_FOUND to be NULL. */
1049 /* See language.h. */
1052 language_lookup_primitive_type_as_symbol (const struct language_defn
*la
,
1053 struct gdbarch
*gdbarch
,
1056 struct language_gdbarch
*ld
1057 = (struct language_gdbarch
*) gdbarch_data (gdbarch
, language_gdbarch_data
);
1058 struct language_arch_info
*lai
= &ld
->arch_info
[la
->la_language
];
1059 struct type
**typep
;
1062 if (symbol_lookup_debug
)
1064 fprintf_unfiltered (gdb_stdlog
,
1065 "language_lookup_primitive_type_as_symbol"
1067 la
->la_name
, host_address_to_string (gdbarch
), name
);
1070 typep
= language_lookup_primitive_type_1 (lai
, name
);
1073 if (symbol_lookup_debug
)
1074 fprintf_unfiltered (gdb_stdlog
, " = NULL\n");
1078 /* The set of symbols is lazily initialized. */
1079 if (lai
->primitive_type_symbols
== NULL
)
1080 language_init_primitive_type_symbols (lai
, la
, gdbarch
);
1082 sym
= lai
->primitive_type_symbols
[typep
- lai
->primitive_type_vector
];
1084 if (symbol_lookup_debug
)
1085 fprintf_unfiltered (gdb_stdlog
, " = %s\n", host_address_to_string (sym
));
1089 /* Initialize the language routines. */
1092 _initialize_language (void)
1094 static const char *const type_or_range_names
[]
1095 = { "on", "off", "warn", "auto", NULL
};
1097 static const char *const case_sensitive_names
[]
1098 = { "on", "off", "auto", NULL
};
1100 language_gdbarch_data
1101 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1103 /* GDB commands for language specific stuff. */
1105 add_prefix_cmd ("check", no_class
, set_check
,
1106 _("Set the status of the type/range checker."),
1107 &setchecklist
, "set check ", 0, &setlist
);
1108 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1109 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1111 add_prefix_cmd ("check", no_class
, show_check
,
1112 _("Show the status of the type/range checker."),
1113 &showchecklist
, "show check ", 0, &showlist
);
1114 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1115 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1117 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1119 _("Set range checking. (on/warn/off/auto)"),
1120 _("Show range checking. (on/warn/off/auto)"),
1121 NULL
, set_range_command
,
1123 &setchecklist
, &showchecklist
);
1125 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1126 &case_sensitive
, _("\
1127 Set case sensitivity in name search. (on/off/auto)"), _("\
1128 Show case sensitivity in name search. (on/off/auto)"), _("\
1129 For Fortran the default is off; for other languages the default is on."),
1132 &setlist
, &showlist
);
1134 add_set_language_command ();
1136 language
= xstrdup ("auto");
1137 type
= xstrdup ("auto");
1138 range
= xstrdup ("auto");
1139 case_sensitive
= xstrdup ("auto");
1141 /* Have the above take effect. */
1142 set_language (language_auto
);