15796c8dcSSimon Schubert /* Multiple source language support for GDB.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1991-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert Contributed by the Department of Computer Science at the State University
65796c8dcSSimon Schubert of New York at Buffalo.
75796c8dcSSimon Schubert
85796c8dcSSimon Schubert This file is part of GDB.
95796c8dcSSimon Schubert
105796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
115796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
125796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
135796c8dcSSimon Schubert (at your option) any later version.
145796c8dcSSimon Schubert
155796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
165796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
175796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185796c8dcSSimon Schubert GNU General Public License for more details.
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
215796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
225796c8dcSSimon Schubert
235796c8dcSSimon Schubert /* This file contains functions that return things that are specific
245796c8dcSSimon Schubert to languages. Each function should examine current_language if necessary,
255796c8dcSSimon Schubert and return the appropriate result. */
265796c8dcSSimon Schubert
275796c8dcSSimon Schubert /* FIXME: Most of these would be better organized as macros which
285796c8dcSSimon Schubert return data out of a "language-specific" struct pointer that is set
295796c8dcSSimon Schubert whenever the working language changes. That would be a lot faster. */
305796c8dcSSimon Schubert
315796c8dcSSimon Schubert #include "defs.h"
325796c8dcSSimon Schubert #include <ctype.h>
335796c8dcSSimon Schubert #include "gdb_string.h"
345796c8dcSSimon Schubert
355796c8dcSSimon Schubert #include "symtab.h"
365796c8dcSSimon Schubert #include "gdbtypes.h"
375796c8dcSSimon Schubert #include "value.h"
385796c8dcSSimon Schubert #include "gdbcmd.h"
395796c8dcSSimon Schubert #include "expression.h"
405796c8dcSSimon Schubert #include "language.h"
415796c8dcSSimon Schubert #include "target.h"
425796c8dcSSimon Schubert #include "parser-defs.h"
435796c8dcSSimon Schubert #include "jv-lang.h"
445796c8dcSSimon Schubert #include "demangle.h"
455796c8dcSSimon Schubert #include "symfile.h"
465796c8dcSSimon Schubert
475796c8dcSSimon Schubert extern void _initialize_language (void);
485796c8dcSSimon Schubert
495796c8dcSSimon Schubert static void unk_lang_error (char *);
505796c8dcSSimon Schubert
515796c8dcSSimon Schubert static int unk_lang_parser (void);
525796c8dcSSimon Schubert
535796c8dcSSimon Schubert static void show_check (char *, int);
545796c8dcSSimon Schubert
555796c8dcSSimon Schubert static void set_check (char *, int);
565796c8dcSSimon Schubert
57*ef5ccd6cSJohn Marino static void set_range_case (void);
585796c8dcSSimon Schubert
595796c8dcSSimon Schubert static void unk_lang_emit_char (int c, struct type *type,
605796c8dcSSimon Schubert struct ui_file *stream, int quoter);
615796c8dcSSimon Schubert
625796c8dcSSimon Schubert static void unk_lang_printchar (int c, struct type *type,
635796c8dcSSimon Schubert struct ui_file *stream);
645796c8dcSSimon Schubert
65*ef5ccd6cSJohn Marino static void unk_lang_value_print (struct value *, struct ui_file *,
665796c8dcSSimon Schubert const struct value_print_options *);
675796c8dcSSimon Schubert
685796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
695796c8dcSSimon Schubert
705796c8dcSSimon Schubert /* Forward declaration */
715796c8dcSSimon Schubert extern const struct language_defn unknown_language_defn;
725796c8dcSSimon Schubert
735796c8dcSSimon Schubert /* The current (default at startup) state of type and range checking.
745796c8dcSSimon Schubert (If the modes are set to "auto", though, these are changed based
755796c8dcSSimon Schubert on the default language at startup, and then again based on the
765796c8dcSSimon Schubert language of the first source file. */
775796c8dcSSimon Schubert
785796c8dcSSimon Schubert enum range_mode range_mode = range_mode_auto;
795796c8dcSSimon Schubert enum range_check range_check = range_check_off;
805796c8dcSSimon Schubert enum case_mode case_mode = case_mode_auto;
815796c8dcSSimon Schubert enum case_sensitivity case_sensitivity = case_sensitive_on;
825796c8dcSSimon Schubert
83c50c785cSJohn Marino /* The current language and language_mode (see language.h). */
845796c8dcSSimon Schubert
855796c8dcSSimon Schubert const struct language_defn *current_language = &unknown_language_defn;
865796c8dcSSimon Schubert enum language_mode language_mode = language_mode_auto;
875796c8dcSSimon Schubert
885796c8dcSSimon Schubert /* The language that the user expects to be typing in (the language
895796c8dcSSimon Schubert of main(), or the last language we notified them about, or C). */
905796c8dcSSimon Schubert
915796c8dcSSimon Schubert const struct language_defn *expected_language;
925796c8dcSSimon Schubert
935796c8dcSSimon Schubert /* The list of supported languages. The list itself is malloc'd. */
945796c8dcSSimon Schubert
955796c8dcSSimon Schubert static const struct language_defn **languages;
965796c8dcSSimon Schubert static unsigned languages_size;
975796c8dcSSimon Schubert static unsigned languages_allocsize;
985796c8dcSSimon Schubert #define DEFAULT_ALLOCSIZE 4
995796c8dcSSimon Schubert
1005796c8dcSSimon Schubert /* The current values of the "set language/type/range" enum
1015796c8dcSSimon Schubert commands. */
1025796c8dcSSimon Schubert static const char *language;
1035796c8dcSSimon Schubert static const char *type;
1045796c8dcSSimon Schubert static const char *range;
1055796c8dcSSimon Schubert static const char *case_sensitive;
1065796c8dcSSimon Schubert
1075796c8dcSSimon Schubert /* Warning issued when current_language and the language of the current
1085796c8dcSSimon Schubert frame do not match. */
1095796c8dcSSimon Schubert char lang_frame_mismatch_warn[] =
1105796c8dcSSimon Schubert "Warning: the current language does not match this frame.";
1115796c8dcSSimon Schubert
1125796c8dcSSimon Schubert /* This page contains the functions corresponding to GDB commands
1135796c8dcSSimon Schubert and their helpers. */
1145796c8dcSSimon Schubert
1155796c8dcSSimon Schubert /* Show command. Display a warning if the language set
1165796c8dcSSimon Schubert does not match the frame. */
1175796c8dcSSimon Schubert static void
show_language_command(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)1185796c8dcSSimon Schubert show_language_command (struct ui_file *file, int from_tty,
1195796c8dcSSimon Schubert struct cmd_list_element *c, const char *value)
1205796c8dcSSimon Schubert {
121c50c785cSJohn Marino enum language flang; /* The language of the current frame. */
1225796c8dcSSimon Schubert
1235796c8dcSSimon Schubert if (language_mode == language_mode_auto)
1245796c8dcSSimon Schubert fprintf_filtered (gdb_stdout,
1255796c8dcSSimon Schubert _("The current source language is "
1265796c8dcSSimon Schubert "\"auto; currently %s\".\n"),
1275796c8dcSSimon Schubert current_language->la_name);
1285796c8dcSSimon Schubert else
129c50c785cSJohn Marino fprintf_filtered (gdb_stdout,
130c50c785cSJohn Marino _("The current source language is \"%s\".\n"),
1315796c8dcSSimon Schubert current_language->la_name);
1325796c8dcSSimon Schubert
1335796c8dcSSimon Schubert flang = get_frame_language ();
1345796c8dcSSimon Schubert if (flang != language_unknown &&
1355796c8dcSSimon Schubert language_mode == language_mode_manual &&
1365796c8dcSSimon Schubert current_language->la_language != flang)
1375796c8dcSSimon Schubert printf_filtered ("%s\n", lang_frame_mismatch_warn);
1385796c8dcSSimon Schubert }
1395796c8dcSSimon Schubert
1405796c8dcSSimon Schubert /* Set command. Change the current working language. */
1415796c8dcSSimon Schubert static void
set_language_command(char * ignore,int from_tty,struct cmd_list_element * c)1425796c8dcSSimon Schubert set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
1435796c8dcSSimon Schubert {
1445796c8dcSSimon Schubert int i;
1455796c8dcSSimon Schubert enum language flang;
1465796c8dcSSimon Schubert
1475796c8dcSSimon Schubert /* Search the list of languages for a match. */
1485796c8dcSSimon Schubert for (i = 0; i < languages_size; i++)
1495796c8dcSSimon Schubert {
1505796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, language) == 0)
1515796c8dcSSimon Schubert {
1525796c8dcSSimon Schubert /* Found it! Go into manual mode, and use this language. */
1535796c8dcSSimon Schubert if (languages[i]->la_language == language_auto)
1545796c8dcSSimon Schubert {
1555796c8dcSSimon Schubert /* Enter auto mode. Set to the current frame's language, if
1565796c8dcSSimon Schubert known, or fallback to the initial language. */
1575796c8dcSSimon Schubert language_mode = language_mode_auto;
1585796c8dcSSimon Schubert flang = get_frame_language ();
1595796c8dcSSimon Schubert if (flang != language_unknown)
1605796c8dcSSimon Schubert set_language (flang);
1615796c8dcSSimon Schubert else
1625796c8dcSSimon Schubert set_initial_language ();
1635796c8dcSSimon Schubert expected_language = current_language;
1645796c8dcSSimon Schubert return;
1655796c8dcSSimon Schubert }
1665796c8dcSSimon Schubert else
1675796c8dcSSimon Schubert {
1685796c8dcSSimon Schubert /* Enter manual mode. Set the specified language. */
1695796c8dcSSimon Schubert language_mode = language_mode_manual;
1705796c8dcSSimon Schubert current_language = languages[i];
171*ef5ccd6cSJohn Marino set_range_case ();
1725796c8dcSSimon Schubert expected_language = current_language;
1735796c8dcSSimon Schubert return;
1745796c8dcSSimon Schubert }
1755796c8dcSSimon Schubert }
1765796c8dcSSimon Schubert }
1775796c8dcSSimon Schubert
1785796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
1795796c8dcSSimon Schubert "Couldn't find language `%s' in known languages list.",
1805796c8dcSSimon Schubert language);
1815796c8dcSSimon Schubert }
1825796c8dcSSimon Schubert
1835796c8dcSSimon Schubert /* Show command. Display a warning if the range setting does
1845796c8dcSSimon Schubert not match the current language. */
1855796c8dcSSimon Schubert static void
show_range_command(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)1865796c8dcSSimon Schubert show_range_command (struct ui_file *file, int from_tty,
1875796c8dcSSimon Schubert struct cmd_list_element *c, const char *value)
1885796c8dcSSimon Schubert {
1895796c8dcSSimon Schubert if (range_mode == range_mode_auto)
1905796c8dcSSimon Schubert {
1915796c8dcSSimon Schubert char *tmp;
1925796c8dcSSimon Schubert
1935796c8dcSSimon Schubert switch (range_check)
1945796c8dcSSimon Schubert {
1955796c8dcSSimon Schubert case range_check_on:
1965796c8dcSSimon Schubert tmp = "on";
1975796c8dcSSimon Schubert break;
1985796c8dcSSimon Schubert case range_check_off:
1995796c8dcSSimon Schubert tmp = "off";
2005796c8dcSSimon Schubert break;
2015796c8dcSSimon Schubert case range_check_warn:
2025796c8dcSSimon Schubert tmp = "warn";
2035796c8dcSSimon Schubert break;
2045796c8dcSSimon Schubert default:
2055796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
2065796c8dcSSimon Schubert "Unrecognized range check setting.");
2075796c8dcSSimon Schubert }
2085796c8dcSSimon Schubert
2095796c8dcSSimon Schubert fprintf_filtered (gdb_stdout,
2105796c8dcSSimon Schubert _("Range checking is \"auto; currently %s\".\n"),
2115796c8dcSSimon Schubert tmp);
2125796c8dcSSimon Schubert }
2135796c8dcSSimon Schubert else
2145796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"),
2155796c8dcSSimon Schubert value);
2165796c8dcSSimon Schubert
2175796c8dcSSimon Schubert if (range_check != current_language->la_range_check)
2185796c8dcSSimon Schubert warning (_("the current range check setting "
2195796c8dcSSimon Schubert "does not match the language.\n"));
2205796c8dcSSimon Schubert }
2215796c8dcSSimon Schubert
2225796c8dcSSimon Schubert /* Set command. Change the setting for range checking. */
2235796c8dcSSimon Schubert static void
set_range_command(char * ignore,int from_tty,struct cmd_list_element * c)2245796c8dcSSimon Schubert set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
2255796c8dcSSimon Schubert {
2265796c8dcSSimon Schubert if (strcmp (range, "on") == 0)
2275796c8dcSSimon Schubert {
2285796c8dcSSimon Schubert range_check = range_check_on;
2295796c8dcSSimon Schubert range_mode = range_mode_manual;
2305796c8dcSSimon Schubert }
2315796c8dcSSimon Schubert else if (strcmp (range, "warn") == 0)
2325796c8dcSSimon Schubert {
2335796c8dcSSimon Schubert range_check = range_check_warn;
2345796c8dcSSimon Schubert range_mode = range_mode_manual;
2355796c8dcSSimon Schubert }
2365796c8dcSSimon Schubert else if (strcmp (range, "off") == 0)
2375796c8dcSSimon Schubert {
2385796c8dcSSimon Schubert range_check = range_check_off;
2395796c8dcSSimon Schubert range_mode = range_mode_manual;
2405796c8dcSSimon Schubert }
2415796c8dcSSimon Schubert else if (strcmp (range, "auto") == 0)
2425796c8dcSSimon Schubert {
2435796c8dcSSimon Schubert range_mode = range_mode_auto;
244*ef5ccd6cSJohn Marino set_range_case ();
2455796c8dcSSimon Schubert return;
2465796c8dcSSimon Schubert }
2475796c8dcSSimon Schubert else
2485796c8dcSSimon Schubert {
2495796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
2505796c8dcSSimon Schubert _("Unrecognized range check setting: \"%s\""), range);
2515796c8dcSSimon Schubert }
2525796c8dcSSimon Schubert if (range_check != current_language->la_range_check)
2535796c8dcSSimon Schubert warning (_("the current range check setting "
2545796c8dcSSimon Schubert "does not match the language.\n"));
2555796c8dcSSimon Schubert }
2565796c8dcSSimon Schubert
2575796c8dcSSimon Schubert /* Show command. Display a warning if the case sensitivity setting does
2585796c8dcSSimon Schubert not match the current language. */
2595796c8dcSSimon Schubert static void
show_case_command(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)2605796c8dcSSimon Schubert show_case_command (struct ui_file *file, int from_tty,
2615796c8dcSSimon Schubert struct cmd_list_element *c, const char *value)
2625796c8dcSSimon Schubert {
2635796c8dcSSimon Schubert if (case_mode == case_mode_auto)
2645796c8dcSSimon Schubert {
2655796c8dcSSimon Schubert char *tmp = NULL;
2665796c8dcSSimon Schubert
2675796c8dcSSimon Schubert switch (case_sensitivity)
2685796c8dcSSimon Schubert {
2695796c8dcSSimon Schubert case case_sensitive_on:
2705796c8dcSSimon Schubert tmp = "on";
2715796c8dcSSimon Schubert break;
2725796c8dcSSimon Schubert case case_sensitive_off:
2735796c8dcSSimon Schubert tmp = "off";
2745796c8dcSSimon Schubert break;
2755796c8dcSSimon Schubert default:
2765796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
2775796c8dcSSimon Schubert "Unrecognized case-sensitive setting.");
2785796c8dcSSimon Schubert }
2795796c8dcSSimon Schubert
2805796c8dcSSimon Schubert fprintf_filtered (gdb_stdout,
2815796c8dcSSimon Schubert _("Case sensitivity in "
2825796c8dcSSimon Schubert "name search is \"auto; currently %s\".\n"),
2835796c8dcSSimon Schubert tmp);
2845796c8dcSSimon Schubert }
2855796c8dcSSimon Schubert else
286c50c785cSJohn Marino fprintf_filtered (gdb_stdout,
287c50c785cSJohn Marino _("Case sensitivity in name search is \"%s\".\n"),
2885796c8dcSSimon Schubert value);
2895796c8dcSSimon Schubert
2905796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity)
2915796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match "
2925796c8dcSSimon Schubert "the language.\n"));
2935796c8dcSSimon Schubert }
2945796c8dcSSimon Schubert
2955796c8dcSSimon Schubert /* Set command. Change the setting for case sensitivity. */
2965796c8dcSSimon Schubert
2975796c8dcSSimon Schubert static void
set_case_command(char * ignore,int from_tty,struct cmd_list_element * c)2985796c8dcSSimon Schubert set_case_command (char *ignore, int from_tty, struct cmd_list_element *c)
2995796c8dcSSimon Schubert {
3005796c8dcSSimon Schubert if (strcmp (case_sensitive, "on") == 0)
3015796c8dcSSimon Schubert {
3025796c8dcSSimon Schubert case_sensitivity = case_sensitive_on;
3035796c8dcSSimon Schubert case_mode = case_mode_manual;
3045796c8dcSSimon Schubert }
3055796c8dcSSimon Schubert else if (strcmp (case_sensitive, "off") == 0)
3065796c8dcSSimon Schubert {
3075796c8dcSSimon Schubert case_sensitivity = case_sensitive_off;
3085796c8dcSSimon Schubert case_mode = case_mode_manual;
3095796c8dcSSimon Schubert }
3105796c8dcSSimon Schubert else if (strcmp (case_sensitive, "auto") == 0)
3115796c8dcSSimon Schubert {
3125796c8dcSSimon Schubert case_mode = case_mode_auto;
313*ef5ccd6cSJohn Marino set_range_case ();
3145796c8dcSSimon Schubert return;
3155796c8dcSSimon Schubert }
3165796c8dcSSimon Schubert else
3175796c8dcSSimon Schubert {
3185796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3195796c8dcSSimon Schubert "Unrecognized case-sensitive setting: \"%s\"",
3205796c8dcSSimon Schubert case_sensitive);
3215796c8dcSSimon Schubert }
3225796c8dcSSimon Schubert
3235796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity)
3245796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match "
3255796c8dcSSimon Schubert "the language.\n"));
3265796c8dcSSimon Schubert }
3275796c8dcSSimon Schubert
3285796c8dcSSimon Schubert /* Set the status of range and type checking and case sensitivity based on
3295796c8dcSSimon Schubert the current modes and the current language.
3305796c8dcSSimon Schubert If SHOW is non-zero, then print out the current language,
3315796c8dcSSimon Schubert type and range checking status. */
3325796c8dcSSimon Schubert static void
set_range_case(void)333*ef5ccd6cSJohn Marino set_range_case (void)
3345796c8dcSSimon Schubert {
3355796c8dcSSimon Schubert if (range_mode == range_mode_auto)
3365796c8dcSSimon Schubert range_check = current_language->la_range_check;
3375796c8dcSSimon Schubert
3385796c8dcSSimon Schubert if (case_mode == case_mode_auto)
3395796c8dcSSimon Schubert case_sensitivity = current_language->la_case_sensitivity;
3405796c8dcSSimon Schubert }
3415796c8dcSSimon Schubert
342c50c785cSJohn Marino /* Set current language to (enum language) LANG. Returns previous
343c50c785cSJohn Marino language. */
3445796c8dcSSimon Schubert
3455796c8dcSSimon Schubert enum language
set_language(enum language lang)3465796c8dcSSimon Schubert set_language (enum language lang)
3475796c8dcSSimon Schubert {
3485796c8dcSSimon Schubert int i;
3495796c8dcSSimon Schubert enum language prev_language;
3505796c8dcSSimon Schubert
3515796c8dcSSimon Schubert prev_language = current_language->la_language;
3525796c8dcSSimon Schubert
3535796c8dcSSimon Schubert for (i = 0; i < languages_size; i++)
3545796c8dcSSimon Schubert {
3555796c8dcSSimon Schubert if (languages[i]->la_language == lang)
3565796c8dcSSimon Schubert {
3575796c8dcSSimon Schubert current_language = languages[i];
358*ef5ccd6cSJohn Marino set_range_case ();
3595796c8dcSSimon Schubert break;
3605796c8dcSSimon Schubert }
3615796c8dcSSimon Schubert }
3625796c8dcSSimon Schubert
3635796c8dcSSimon Schubert return prev_language;
3645796c8dcSSimon Schubert }
3655796c8dcSSimon Schubert
3665796c8dcSSimon Schubert
3675796c8dcSSimon Schubert /* Print out the current language settings: language, range and
3685796c8dcSSimon Schubert type checking. If QUIETLY, print only what has changed. */
3695796c8dcSSimon Schubert
3705796c8dcSSimon Schubert void
language_info(int quietly)3715796c8dcSSimon Schubert language_info (int quietly)
3725796c8dcSSimon Schubert {
3735796c8dcSSimon Schubert if (quietly && expected_language == current_language)
3745796c8dcSSimon Schubert return;
3755796c8dcSSimon Schubert
3765796c8dcSSimon Schubert expected_language = current_language;
3775796c8dcSSimon Schubert printf_unfiltered (_("Current language: %s\n"), language);
3785796c8dcSSimon Schubert show_language_command (NULL, 1, NULL, NULL);
3795796c8dcSSimon Schubert
3805796c8dcSSimon Schubert if (!quietly)
3815796c8dcSSimon Schubert {
3825796c8dcSSimon Schubert printf_unfiltered (_("Range checking: %s\n"), range);
3835796c8dcSSimon Schubert show_range_command (NULL, 1, NULL, NULL);
3845796c8dcSSimon Schubert printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
3855796c8dcSSimon Schubert show_case_command (NULL, 1, NULL, NULL);
3865796c8dcSSimon Schubert }
3875796c8dcSSimon Schubert }
3885796c8dcSSimon Schubert
3895796c8dcSSimon Schubert
390c50c785cSJohn Marino /* Returns non-zero if the value is a pointer type. */
3915796c8dcSSimon Schubert int
pointer_type(struct type * type)3925796c8dcSSimon Schubert pointer_type (struct type *type)
3935796c8dcSSimon Schubert {
3945796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_PTR ||
3955796c8dcSSimon Schubert TYPE_CODE (type) == TYPE_CODE_REF;
3965796c8dcSSimon Schubert }
3975796c8dcSSimon Schubert
3985796c8dcSSimon Schubert
3995796c8dcSSimon Schubert /* This page contains functions that return info about
4005796c8dcSSimon Schubert (struct value) values used in GDB. */
4015796c8dcSSimon Schubert
4025796c8dcSSimon Schubert /* Returns non-zero if the value VAL represents a true value. */
4035796c8dcSSimon Schubert int
value_true(struct value * val)4045796c8dcSSimon Schubert value_true (struct value *val)
4055796c8dcSSimon Schubert {
4065796c8dcSSimon Schubert /* It is possible that we should have some sort of error if a non-boolean
4075796c8dcSSimon Schubert value is used in this context. Possibly dependent on some kind of
4085796c8dcSSimon Schubert "boolean-checking" option like range checking. But it should probably
4095796c8dcSSimon Schubert not depend on the language except insofar as is necessary to identify
4105796c8dcSSimon Schubert a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
4115796c8dcSSimon Schubert should be an error, probably). */
4125796c8dcSSimon Schubert return !value_logical_not (val);
4135796c8dcSSimon Schubert }
4145796c8dcSSimon Schubert
4155796c8dcSSimon Schubert /* This page contains functions for the printing out of
4165796c8dcSSimon Schubert error messages that occur during type- and range-
4175796c8dcSSimon Schubert checking. */
4185796c8dcSSimon Schubert
419*ef5ccd6cSJohn Marino /* This is called when a language fails a range-check. The
4205796c8dcSSimon Schubert first argument should be a printf()-style format string, and the
421*ef5ccd6cSJohn Marino rest of the arguments should be its arguments. If range_check is
422*ef5ccd6cSJohn Marino range_check_on, an error is printed; if range_check_warn, a warning;
423*ef5ccd6cSJohn Marino otherwise just the message. */
4245796c8dcSSimon Schubert
4255796c8dcSSimon Schubert void
range_error(const char * string,...)4265796c8dcSSimon Schubert range_error (const char *string,...)
4275796c8dcSSimon Schubert {
4285796c8dcSSimon Schubert va_list args;
4295796c8dcSSimon Schubert
430cf7f2e2dSJohn Marino va_start (args, string);
4315796c8dcSSimon Schubert switch (range_check)
4325796c8dcSSimon Schubert {
4335796c8dcSSimon Schubert case range_check_warn:
4345796c8dcSSimon Schubert vwarning (string, args);
4355796c8dcSSimon Schubert break;
4365796c8dcSSimon Schubert case range_check_on:
4375796c8dcSSimon Schubert verror (string, args);
4385796c8dcSSimon Schubert break;
4395796c8dcSSimon Schubert case range_check_off:
4405796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything
4415796c8dcSSimon Schubert when range error is off? */
4425796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args);
4435796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n");
4445796c8dcSSimon Schubert break;
4455796c8dcSSimon Schubert default:
4465796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch"));
4475796c8dcSSimon Schubert }
4485796c8dcSSimon Schubert va_end (args);
4495796c8dcSSimon Schubert }
4505796c8dcSSimon Schubert
4515796c8dcSSimon Schubert
452c50c785cSJohn Marino /* This page contains miscellaneous functions. */
4535796c8dcSSimon Schubert
4545796c8dcSSimon Schubert /* Return the language enum for a given language string. */
4555796c8dcSSimon Schubert
4565796c8dcSSimon Schubert enum language
language_enum(char * str)4575796c8dcSSimon Schubert language_enum (char *str)
4585796c8dcSSimon Schubert {
4595796c8dcSSimon Schubert int i;
4605796c8dcSSimon Schubert
4615796c8dcSSimon Schubert for (i = 0; i < languages_size; i++)
4625796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, str) == 0)
4635796c8dcSSimon Schubert return languages[i]->la_language;
4645796c8dcSSimon Schubert
4655796c8dcSSimon Schubert return language_unknown;
4665796c8dcSSimon Schubert }
4675796c8dcSSimon Schubert
4685796c8dcSSimon Schubert /* Return the language struct for a given language enum. */
4695796c8dcSSimon Schubert
4705796c8dcSSimon Schubert const struct language_defn *
language_def(enum language lang)4715796c8dcSSimon Schubert language_def (enum language lang)
4725796c8dcSSimon Schubert {
4735796c8dcSSimon Schubert int i;
4745796c8dcSSimon Schubert
4755796c8dcSSimon Schubert for (i = 0; i < languages_size; i++)
4765796c8dcSSimon Schubert {
4775796c8dcSSimon Schubert if (languages[i]->la_language == lang)
4785796c8dcSSimon Schubert {
4795796c8dcSSimon Schubert return languages[i];
4805796c8dcSSimon Schubert }
4815796c8dcSSimon Schubert }
4825796c8dcSSimon Schubert return NULL;
4835796c8dcSSimon Schubert }
4845796c8dcSSimon Schubert
485c50c785cSJohn Marino /* Return the language as a string. */
4865796c8dcSSimon Schubert char *
language_str(enum language lang)4875796c8dcSSimon Schubert language_str (enum language lang)
4885796c8dcSSimon Schubert {
4895796c8dcSSimon Schubert int i;
4905796c8dcSSimon Schubert
4915796c8dcSSimon Schubert for (i = 0; i < languages_size; i++)
4925796c8dcSSimon Schubert {
4935796c8dcSSimon Schubert if (languages[i]->la_language == lang)
4945796c8dcSSimon Schubert {
4955796c8dcSSimon Schubert return languages[i]->la_name;
4965796c8dcSSimon Schubert }
4975796c8dcSSimon Schubert }
4985796c8dcSSimon Schubert return "Unknown";
4995796c8dcSSimon Schubert }
5005796c8dcSSimon Schubert
5015796c8dcSSimon Schubert static void
set_check(char * ignore,int from_tty)5025796c8dcSSimon Schubert set_check (char *ignore, int from_tty)
5035796c8dcSSimon Schubert {
5045796c8dcSSimon Schubert printf_unfiltered (
5055796c8dcSSimon Schubert "\"set check\" must be followed by the name of a check subcommand.\n");
5065796c8dcSSimon Schubert help_list (setchecklist, "set check ", -1, gdb_stdout);
5075796c8dcSSimon Schubert }
5085796c8dcSSimon Schubert
5095796c8dcSSimon Schubert static void
show_check(char * ignore,int from_tty)5105796c8dcSSimon Schubert show_check (char *ignore, int from_tty)
5115796c8dcSSimon Schubert {
5125796c8dcSSimon Schubert cmd_show_list (showchecklist, from_tty, "");
5135796c8dcSSimon Schubert }
5145796c8dcSSimon Schubert
5155796c8dcSSimon Schubert /* Add a language to the set of known languages. */
5165796c8dcSSimon Schubert
5175796c8dcSSimon Schubert void
add_language(const struct language_defn * lang)5185796c8dcSSimon Schubert add_language (const struct language_defn *lang)
5195796c8dcSSimon Schubert {
5205796c8dcSSimon Schubert /* For the "set language" command. */
5215796c8dcSSimon Schubert static char **language_names = NULL;
5225796c8dcSSimon Schubert /* For the "help set language" command. */
5235796c8dcSSimon Schubert char *language_set_doc = NULL;
5245796c8dcSSimon Schubert
5255796c8dcSSimon Schubert int i;
5265796c8dcSSimon Schubert struct ui_file *tmp_stream;
5275796c8dcSSimon Schubert
5285796c8dcSSimon Schubert if (lang->la_magic != LANG_MAGIC)
5295796c8dcSSimon Schubert {
530c50c785cSJohn Marino fprintf_unfiltered (gdb_stderr,
531c50c785cSJohn Marino "Magic number of %s language struct wrong\n",
5325796c8dcSSimon Schubert lang->la_name);
533c50c785cSJohn Marino internal_error (__FILE__, __LINE__,
534c50c785cSJohn Marino _("failed internal consistency check"));
5355796c8dcSSimon Schubert }
5365796c8dcSSimon Schubert
5375796c8dcSSimon Schubert if (!languages)
5385796c8dcSSimon Schubert {
5395796c8dcSSimon Schubert languages_allocsize = DEFAULT_ALLOCSIZE;
5405796c8dcSSimon Schubert languages = (const struct language_defn **) xmalloc
5415796c8dcSSimon Schubert (languages_allocsize * sizeof (*languages));
5425796c8dcSSimon Schubert }
5435796c8dcSSimon Schubert if (languages_size >= languages_allocsize)
5445796c8dcSSimon Schubert {
5455796c8dcSSimon Schubert languages_allocsize *= 2;
5465796c8dcSSimon Schubert languages = (const struct language_defn **) xrealloc ((char *) languages,
5475796c8dcSSimon Schubert languages_allocsize * sizeof (*languages));
5485796c8dcSSimon Schubert }
5495796c8dcSSimon Schubert languages[languages_size++] = lang;
5505796c8dcSSimon Schubert
5515796c8dcSSimon Schubert /* Build the language names array, to be used as enumeration in the
5525796c8dcSSimon Schubert set language" enum command. */
5535796c8dcSSimon Schubert language_names = xrealloc (language_names,
5545796c8dcSSimon Schubert (languages_size + 1) * sizeof (const char *));
5555796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i)
5565796c8dcSSimon Schubert language_names[i] = languages[i]->la_name;
5575796c8dcSSimon Schubert language_names[i] = NULL;
5585796c8dcSSimon Schubert
5595796c8dcSSimon Schubert /* Build the "help set language" docs. */
5605796c8dcSSimon Schubert tmp_stream = mem_fileopen ();
5615796c8dcSSimon Schubert
562c50c785cSJohn Marino fprintf_unfiltered (tmp_stream,
563c50c785cSJohn Marino _("Set the current source language.\n"
564c50c785cSJohn Marino "The currently understood settings are:\n\nlocal or "
565c50c785cSJohn Marino "auto Automatic setting based on source file\n"));
5665796c8dcSSimon Schubert
5675796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i)
5685796c8dcSSimon Schubert {
5695796c8dcSSimon Schubert /* Already dealt with these above. */
5705796c8dcSSimon Schubert if (languages[i]->la_language == language_unknown
5715796c8dcSSimon Schubert || languages[i]->la_language == language_auto)
5725796c8dcSSimon Schubert continue;
5735796c8dcSSimon Schubert
5745796c8dcSSimon Schubert /* FIXME: i18n: for now assume that the human-readable name
5755796c8dcSSimon Schubert is just a capitalization of the internal name. */
5765796c8dcSSimon Schubert fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n",
5775796c8dcSSimon Schubert languages[i]->la_name,
5785796c8dcSSimon Schubert /* Capitalize first letter of language
5795796c8dcSSimon Schubert name. */
5805796c8dcSSimon Schubert toupper (languages[i]->la_name[0]),
5815796c8dcSSimon Schubert languages[i]->la_name + 1);
5825796c8dcSSimon Schubert }
5835796c8dcSSimon Schubert
5845796c8dcSSimon Schubert language_set_doc = ui_file_xstrdup (tmp_stream, NULL);
5855796c8dcSSimon Schubert ui_file_delete (tmp_stream);
5865796c8dcSSimon Schubert
5875796c8dcSSimon Schubert add_setshow_enum_cmd ("language", class_support,
5885796c8dcSSimon Schubert (const char **) language_names,
5895796c8dcSSimon Schubert &language,
590c50c785cSJohn Marino language_set_doc,
591c50c785cSJohn Marino _("Show the current source language."),
592c50c785cSJohn Marino NULL, set_language_command,
5935796c8dcSSimon Schubert show_language_command,
5945796c8dcSSimon Schubert &setlist, &showlist);
5955796c8dcSSimon Schubert
5965796c8dcSSimon Schubert xfree (language_set_doc);
5975796c8dcSSimon Schubert }
5985796c8dcSSimon Schubert
5995796c8dcSSimon Schubert /* Iterate through all registered languages looking for and calling
6005796c8dcSSimon Schubert any non-NULL struct language_defn.skip_trampoline() functions.
6015796c8dcSSimon Schubert Return the result from the first that returns non-zero, or 0 if all
6025796c8dcSSimon Schubert `fail'. */
6035796c8dcSSimon Schubert CORE_ADDR
skip_language_trampoline(struct frame_info * frame,CORE_ADDR pc)6045796c8dcSSimon Schubert skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
6055796c8dcSSimon Schubert {
6065796c8dcSSimon Schubert int i;
6075796c8dcSSimon Schubert
6085796c8dcSSimon Schubert for (i = 0; i < languages_size; i++)
6095796c8dcSSimon Schubert {
6105796c8dcSSimon Schubert if (languages[i]->skip_trampoline)
6115796c8dcSSimon Schubert {
6125796c8dcSSimon Schubert CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc);
613cf7f2e2dSJohn Marino
6145796c8dcSSimon Schubert if (real_pc)
6155796c8dcSSimon Schubert return real_pc;
6165796c8dcSSimon Schubert }
6175796c8dcSSimon Schubert }
6185796c8dcSSimon Schubert
6195796c8dcSSimon Schubert return 0;
6205796c8dcSSimon Schubert }
6215796c8dcSSimon Schubert
6225796c8dcSSimon Schubert /* Return demangled language symbol, or NULL.
6235796c8dcSSimon Schubert FIXME: Options are only useful for certain languages and ignored
6245796c8dcSSimon Schubert by others, so it would be better to remove them here and have a
6255796c8dcSSimon Schubert more flexible demangler for the languages that need it.
6265796c8dcSSimon Schubert FIXME: Sometimes the demangler is invoked when we don't know the
6275796c8dcSSimon Schubert language, so we can't use this everywhere. */
6285796c8dcSSimon Schubert char *
language_demangle(const struct language_defn * current_language,const char * mangled,int options)6295796c8dcSSimon Schubert language_demangle (const struct language_defn *current_language,
6305796c8dcSSimon Schubert const char *mangled, int options)
6315796c8dcSSimon Schubert {
6325796c8dcSSimon Schubert if (current_language != NULL && current_language->la_demangle)
6335796c8dcSSimon Schubert return current_language->la_demangle (mangled, options);
6345796c8dcSSimon Schubert return NULL;
6355796c8dcSSimon Schubert }
6365796c8dcSSimon Schubert
6375796c8dcSSimon Schubert /* Return class name from physname or NULL. */
6385796c8dcSSimon Schubert char *
language_class_name_from_physname(const struct language_defn * lang,const char * physname)639c50c785cSJohn Marino language_class_name_from_physname (const struct language_defn *lang,
6405796c8dcSSimon Schubert const char *physname)
6415796c8dcSSimon Schubert {
642c50c785cSJohn Marino if (lang != NULL && lang->la_class_name_from_physname)
643c50c785cSJohn Marino return lang->la_class_name_from_physname (physname);
6445796c8dcSSimon Schubert return NULL;
6455796c8dcSSimon Schubert }
6465796c8dcSSimon Schubert
6475796c8dcSSimon Schubert /* Return non-zero if TYPE should be passed (and returned) by
6485796c8dcSSimon Schubert reference at the language level. */
6495796c8dcSSimon Schubert int
language_pass_by_reference(struct type * type)6505796c8dcSSimon Schubert language_pass_by_reference (struct type *type)
6515796c8dcSSimon Schubert {
6525796c8dcSSimon Schubert return current_language->la_pass_by_reference (type);
6535796c8dcSSimon Schubert }
6545796c8dcSSimon Schubert
6555796c8dcSSimon Schubert /* Return zero; by default, types are passed by value at the language
6565796c8dcSSimon Schubert level. The target ABI may pass or return some structs by reference
6575796c8dcSSimon Schubert independent of this. */
6585796c8dcSSimon Schubert int
default_pass_by_reference(struct type * type)6595796c8dcSSimon Schubert default_pass_by_reference (struct type *type)
6605796c8dcSSimon Schubert {
6615796c8dcSSimon Schubert return 0;
6625796c8dcSSimon Schubert }
6635796c8dcSSimon Schubert
6645796c8dcSSimon Schubert /* Return the default string containing the list of characters
6655796c8dcSSimon Schubert delimiting words. This is a reasonable default value that
6665796c8dcSSimon Schubert most languages should be able to use. */
6675796c8dcSSimon Schubert
6685796c8dcSSimon Schubert char *
default_word_break_characters(void)6695796c8dcSSimon Schubert default_word_break_characters (void)
6705796c8dcSSimon Schubert {
6715796c8dcSSimon Schubert return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
6725796c8dcSSimon Schubert }
6735796c8dcSSimon Schubert
6745796c8dcSSimon Schubert /* Print the index of array elements using the C99 syntax. */
6755796c8dcSSimon Schubert
6765796c8dcSSimon Schubert void
default_print_array_index(struct value * index_value,struct ui_file * stream,const struct value_print_options * options)6775796c8dcSSimon Schubert default_print_array_index (struct value *index_value, struct ui_file *stream,
6785796c8dcSSimon Schubert const struct value_print_options *options)
6795796c8dcSSimon Schubert {
6805796c8dcSSimon Schubert fprintf_filtered (stream, "[");
6815796c8dcSSimon Schubert LA_VALUE_PRINT (index_value, stream, options);
6825796c8dcSSimon Schubert fprintf_filtered (stream, "] = ");
6835796c8dcSSimon Schubert }
6845796c8dcSSimon Schubert
6855796c8dcSSimon Schubert void
default_get_string(struct value * value,gdb_byte ** buffer,int * length,struct type ** char_type,const char ** charset)6865796c8dcSSimon Schubert default_get_string (struct value *value, gdb_byte **buffer, int *length,
687cf7f2e2dSJohn Marino struct type **char_type, const char **charset)
6885796c8dcSSimon Schubert {
6895796c8dcSSimon Schubert error (_("Getting a string is unsupported in this language."));
6905796c8dcSSimon Schubert }
6915796c8dcSSimon Schubert
6925796c8dcSSimon Schubert /* Define the language that is no language. */
6935796c8dcSSimon Schubert
6945796c8dcSSimon Schubert static int
unk_lang_parser(void)6955796c8dcSSimon Schubert unk_lang_parser (void)
6965796c8dcSSimon Schubert {
6975796c8dcSSimon Schubert return 1;
6985796c8dcSSimon Schubert }
6995796c8dcSSimon Schubert
7005796c8dcSSimon Schubert static void
unk_lang_error(char * msg)7015796c8dcSSimon Schubert unk_lang_error (char *msg)
7025796c8dcSSimon Schubert {
7035796c8dcSSimon Schubert error (_("Attempted to parse an expression with unknown language"));
7045796c8dcSSimon Schubert }
7055796c8dcSSimon Schubert
7065796c8dcSSimon Schubert static void
unk_lang_emit_char(int c,struct type * type,struct ui_file * stream,int quoter)7075796c8dcSSimon Schubert unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
7085796c8dcSSimon Schubert int quoter)
7095796c8dcSSimon Schubert {
710c50c785cSJohn Marino error (_("internal error - unimplemented "
711c50c785cSJohn Marino "function unk_lang_emit_char called."));
7125796c8dcSSimon Schubert }
7135796c8dcSSimon Schubert
7145796c8dcSSimon Schubert static void
unk_lang_printchar(int c,struct type * type,struct ui_file * stream)7155796c8dcSSimon Schubert unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
7165796c8dcSSimon Schubert {
717c50c785cSJohn Marino error (_("internal error - unimplemented "
718c50c785cSJohn Marino "function unk_lang_printchar called."));
7195796c8dcSSimon Schubert }
7205796c8dcSSimon Schubert
7215796c8dcSSimon Schubert static void
unk_lang_printstr(struct ui_file * stream,struct type * type,const gdb_byte * string,unsigned int length,const char * encoding,int force_ellipses,const struct value_print_options * options)7225796c8dcSSimon Schubert unk_lang_printstr (struct ui_file *stream, struct type *type,
7235796c8dcSSimon Schubert const gdb_byte *string, unsigned int length,
724cf7f2e2dSJohn Marino const char *encoding, int force_ellipses,
7255796c8dcSSimon Schubert const struct value_print_options *options)
7265796c8dcSSimon Schubert {
727c50c785cSJohn Marino error (_("internal error - unimplemented "
728c50c785cSJohn Marino "function unk_lang_printstr called."));
7295796c8dcSSimon Schubert }
7305796c8dcSSimon Schubert
7315796c8dcSSimon Schubert static void
unk_lang_print_type(struct type * type,const char * varstring,struct ui_file * stream,int show,int level,const struct type_print_options * flags)732cf7f2e2dSJohn Marino unk_lang_print_type (struct type *type, const char *varstring,
733*ef5ccd6cSJohn Marino struct ui_file *stream, int show, int level,
734*ef5ccd6cSJohn Marino const struct type_print_options *flags)
7355796c8dcSSimon Schubert {
736c50c785cSJohn Marino error (_("internal error - unimplemented "
737c50c785cSJohn Marino "function unk_lang_print_type called."));
7385796c8dcSSimon Schubert }
7395796c8dcSSimon Schubert
740*ef5ccd6cSJohn Marino static void
unk_lang_val_print(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * val,const struct value_print_options * options)7415796c8dcSSimon Schubert unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
7425796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address,
7435796c8dcSSimon Schubert struct ui_file *stream, int recurse,
744cf7f2e2dSJohn Marino const struct value *val,
7455796c8dcSSimon Schubert const struct value_print_options *options)
7465796c8dcSSimon Schubert {
747c50c785cSJohn Marino error (_("internal error - unimplemented "
748c50c785cSJohn Marino "function unk_lang_val_print called."));
7495796c8dcSSimon Schubert }
7505796c8dcSSimon Schubert
751*ef5ccd6cSJohn Marino static void
unk_lang_value_print(struct value * val,struct ui_file * stream,const struct value_print_options * options)7525796c8dcSSimon Schubert unk_lang_value_print (struct value *val, struct ui_file *stream,
7535796c8dcSSimon Schubert const struct value_print_options *options)
7545796c8dcSSimon Schubert {
755c50c785cSJohn Marino error (_("internal error - unimplemented "
756c50c785cSJohn Marino "function unk_lang_value_print called."));
7575796c8dcSSimon Schubert }
7585796c8dcSSimon Schubert
unk_lang_trampoline(struct frame_info * frame,CORE_ADDR pc)7595796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
7605796c8dcSSimon Schubert {
7615796c8dcSSimon Schubert return 0;
7625796c8dcSSimon Schubert }
7635796c8dcSSimon Schubert
7645796c8dcSSimon Schubert /* Unknown languages just use the cplus demangler. */
unk_lang_demangle(const char * mangled,int options)7655796c8dcSSimon Schubert static char *unk_lang_demangle (const char *mangled, int options)
7665796c8dcSSimon Schubert {
7675796c8dcSSimon Schubert return cplus_demangle (mangled, options);
7685796c8dcSSimon Schubert }
7695796c8dcSSimon Schubert
unk_lang_class_name(const char * mangled)7705796c8dcSSimon Schubert static char *unk_lang_class_name (const char *mangled)
7715796c8dcSSimon Schubert {
7725796c8dcSSimon Schubert return NULL;
7735796c8dcSSimon Schubert }
7745796c8dcSSimon Schubert
7755796c8dcSSimon Schubert static const struct op_print unk_op_print_tab[] =
7765796c8dcSSimon Schubert {
7775796c8dcSSimon Schubert {NULL, OP_NULL, PREC_NULL, 0}
7785796c8dcSSimon Schubert };
7795796c8dcSSimon Schubert
7805796c8dcSSimon Schubert static void
unknown_language_arch_info(struct gdbarch * gdbarch,struct language_arch_info * lai)7815796c8dcSSimon Schubert unknown_language_arch_info (struct gdbarch *gdbarch,
7825796c8dcSSimon Schubert struct language_arch_info *lai)
7835796c8dcSSimon Schubert {
7845796c8dcSSimon Schubert lai->string_char_type = builtin_type (gdbarch)->builtin_char;
7855796c8dcSSimon Schubert lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
7865796c8dcSSimon Schubert lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
7875796c8dcSSimon Schubert struct type *);
7885796c8dcSSimon Schubert }
7895796c8dcSSimon Schubert
7905796c8dcSSimon Schubert const struct language_defn unknown_language_defn =
7915796c8dcSSimon Schubert {
7925796c8dcSSimon Schubert "unknown",
7935796c8dcSSimon Schubert language_unknown,
7945796c8dcSSimon Schubert range_check_off,
7955796c8dcSSimon Schubert case_sensitive_on,
7965796c8dcSSimon Schubert array_row_major,
7975796c8dcSSimon Schubert macro_expansion_no,
7985796c8dcSSimon Schubert &exp_descriptor_standard,
7995796c8dcSSimon Schubert unk_lang_parser,
8005796c8dcSSimon Schubert unk_lang_error,
8015796c8dcSSimon Schubert null_post_parser,
8025796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */
8035796c8dcSSimon Schubert unk_lang_printstr,
8045796c8dcSSimon Schubert unk_lang_emit_char,
8055796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */
8065796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */
8075796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */
8085796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */
809*ef5ccd6cSJohn Marino default_read_var_value, /* la_read_var_value */
8105796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */
8115796c8dcSSimon Schubert "this", /* name_of_this */
8125796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
8135796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */
8145796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */
815c50c785cSJohn Marino unk_lang_class_name, /* Language specific
816c50c785cSJohn Marino class_name_from_physname */
8175796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */
8185796c8dcSSimon Schubert 1, /* c-style arrays */
8195796c8dcSSimon Schubert 0, /* String lower bound */
8205796c8dcSSimon Schubert default_word_break_characters,
8215796c8dcSSimon Schubert default_make_symbol_completion_list,
8225796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */
8235796c8dcSSimon Schubert default_print_array_index,
8245796c8dcSSimon Schubert default_pass_by_reference,
8255796c8dcSSimon Schubert default_get_string,
826*ef5ccd6cSJohn Marino NULL, /* la_get_symbol_name_cmp */
827a45ae5f8SJohn Marino iterate_over_symbols,
8285796c8dcSSimon Schubert LANG_MAGIC
8295796c8dcSSimon Schubert };
8305796c8dcSSimon Schubert
831c50c785cSJohn Marino /* These two structs define fake entries for the "local" and "auto"
832c50c785cSJohn Marino options. */
8335796c8dcSSimon Schubert const struct language_defn auto_language_defn =
8345796c8dcSSimon Schubert {
8355796c8dcSSimon Schubert "auto",
8365796c8dcSSimon Schubert language_auto,
8375796c8dcSSimon Schubert range_check_off,
8385796c8dcSSimon Schubert case_sensitive_on,
8395796c8dcSSimon Schubert array_row_major,
8405796c8dcSSimon Schubert macro_expansion_no,
8415796c8dcSSimon Schubert &exp_descriptor_standard,
8425796c8dcSSimon Schubert unk_lang_parser,
8435796c8dcSSimon Schubert unk_lang_error,
8445796c8dcSSimon Schubert null_post_parser,
8455796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */
8465796c8dcSSimon Schubert unk_lang_printstr,
8475796c8dcSSimon Schubert unk_lang_emit_char,
8485796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */
8495796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */
8505796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */
8515796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */
852*ef5ccd6cSJohn Marino default_read_var_value, /* la_read_var_value */
8535796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */
8545796c8dcSSimon Schubert "this", /* name_of_this */
8555796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
8565796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */
8575796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */
858c50c785cSJohn Marino unk_lang_class_name, /* Language specific
859c50c785cSJohn Marino class_name_from_physname */
8605796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */
8615796c8dcSSimon Schubert 1, /* c-style arrays */
8625796c8dcSSimon Schubert 0, /* String lower bound */
8635796c8dcSSimon Schubert default_word_break_characters,
8645796c8dcSSimon Schubert default_make_symbol_completion_list,
8655796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */
8665796c8dcSSimon Schubert default_print_array_index,
8675796c8dcSSimon Schubert default_pass_by_reference,
8685796c8dcSSimon Schubert default_get_string,
869*ef5ccd6cSJohn Marino NULL, /* la_get_symbol_name_cmp */
870a45ae5f8SJohn Marino iterate_over_symbols,
8715796c8dcSSimon Schubert LANG_MAGIC
8725796c8dcSSimon Schubert };
8735796c8dcSSimon Schubert
8745796c8dcSSimon Schubert const struct language_defn local_language_defn =
8755796c8dcSSimon Schubert {
8765796c8dcSSimon Schubert "local",
8775796c8dcSSimon Schubert language_auto,
8785796c8dcSSimon Schubert range_check_off,
8795796c8dcSSimon Schubert case_sensitive_on,
8805796c8dcSSimon Schubert array_row_major,
8815796c8dcSSimon Schubert macro_expansion_no,
8825796c8dcSSimon Schubert &exp_descriptor_standard,
8835796c8dcSSimon Schubert unk_lang_parser,
8845796c8dcSSimon Schubert unk_lang_error,
8855796c8dcSSimon Schubert null_post_parser,
8865796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */
8875796c8dcSSimon Schubert unk_lang_printstr,
8885796c8dcSSimon Schubert unk_lang_emit_char,
8895796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */
8905796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */
8915796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */
8925796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */
893*ef5ccd6cSJohn Marino default_read_var_value, /* la_read_var_value */
8945796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */
8955796c8dcSSimon Schubert "this", /* name_of_this */
8965796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
8975796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */
8985796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */
899c50c785cSJohn Marino unk_lang_class_name, /* Language specific
900c50c785cSJohn Marino class_name_from_physname */
9015796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */
9025796c8dcSSimon Schubert 1, /* c-style arrays */
9035796c8dcSSimon Schubert 0, /* String lower bound */
9045796c8dcSSimon Schubert default_word_break_characters,
9055796c8dcSSimon Schubert default_make_symbol_completion_list,
9065796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */
9075796c8dcSSimon Schubert default_print_array_index,
9085796c8dcSSimon Schubert default_pass_by_reference,
9095796c8dcSSimon Schubert default_get_string,
910*ef5ccd6cSJohn Marino NULL, /* la_get_symbol_name_cmp */
911a45ae5f8SJohn Marino iterate_over_symbols,
9125796c8dcSSimon Schubert LANG_MAGIC
9135796c8dcSSimon Schubert };
9145796c8dcSSimon Schubert
9155796c8dcSSimon Schubert /* Per-architecture language information. */
9165796c8dcSSimon Schubert
9175796c8dcSSimon Schubert static struct gdbarch_data *language_gdbarch_data;
9185796c8dcSSimon Schubert
9195796c8dcSSimon Schubert struct language_gdbarch
9205796c8dcSSimon Schubert {
9215796c8dcSSimon Schubert /* A vector of per-language per-architecture info. Indexed by "enum
9225796c8dcSSimon Schubert language". */
9235796c8dcSSimon Schubert struct language_arch_info arch_info[nr_languages];
9245796c8dcSSimon Schubert };
9255796c8dcSSimon Schubert
9265796c8dcSSimon Schubert static void *
language_gdbarch_post_init(struct gdbarch * gdbarch)9275796c8dcSSimon Schubert language_gdbarch_post_init (struct gdbarch *gdbarch)
9285796c8dcSSimon Schubert {
9295796c8dcSSimon Schubert struct language_gdbarch *l;
9305796c8dcSSimon Schubert int i;
9315796c8dcSSimon Schubert
9325796c8dcSSimon Schubert l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
9335796c8dcSSimon Schubert for (i = 0; i < languages_size; i++)
9345796c8dcSSimon Schubert {
9355796c8dcSSimon Schubert if (languages[i] != NULL
9365796c8dcSSimon Schubert && languages[i]->la_language_arch_info != NULL)
9375796c8dcSSimon Schubert languages[i]->la_language_arch_info
9385796c8dcSSimon Schubert (gdbarch, l->arch_info + languages[i]->la_language);
9395796c8dcSSimon Schubert }
9405796c8dcSSimon Schubert return l;
9415796c8dcSSimon Schubert }
9425796c8dcSSimon Schubert
9435796c8dcSSimon Schubert struct type *
language_string_char_type(const struct language_defn * la,struct gdbarch * gdbarch)9445796c8dcSSimon Schubert language_string_char_type (const struct language_defn *la,
9455796c8dcSSimon Schubert struct gdbarch *gdbarch)
9465796c8dcSSimon Schubert {
9475796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch,
9485796c8dcSSimon Schubert language_gdbarch_data);
949cf7f2e2dSJohn Marino
9505796c8dcSSimon Schubert return ld->arch_info[la->la_language].string_char_type;
9515796c8dcSSimon Schubert }
9525796c8dcSSimon Schubert
9535796c8dcSSimon Schubert struct type *
language_bool_type(const struct language_defn * la,struct gdbarch * gdbarch)9545796c8dcSSimon Schubert language_bool_type (const struct language_defn *la,
9555796c8dcSSimon Schubert struct gdbarch *gdbarch)
9565796c8dcSSimon Schubert {
9575796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch,
9585796c8dcSSimon Schubert language_gdbarch_data);
9595796c8dcSSimon Schubert
9605796c8dcSSimon Schubert if (ld->arch_info[la->la_language].bool_type_symbol)
9615796c8dcSSimon Schubert {
9625796c8dcSSimon Schubert struct symbol *sym;
963cf7f2e2dSJohn Marino
9645796c8dcSSimon Schubert sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
9655796c8dcSSimon Schubert NULL, VAR_DOMAIN, NULL);
9665796c8dcSSimon Schubert if (sym)
9675796c8dcSSimon Schubert {
9685796c8dcSSimon Schubert struct type *type = SYMBOL_TYPE (sym);
969cf7f2e2dSJohn Marino
9705796c8dcSSimon Schubert if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
9715796c8dcSSimon Schubert return type;
9725796c8dcSSimon Schubert }
9735796c8dcSSimon Schubert }
9745796c8dcSSimon Schubert
9755796c8dcSSimon Schubert return ld->arch_info[la->la_language].bool_type_default;
9765796c8dcSSimon Schubert }
9775796c8dcSSimon Schubert
9785796c8dcSSimon Schubert struct type *
language_lookup_primitive_type_by_name(const struct language_defn * la,struct gdbarch * gdbarch,const char * name)9795796c8dcSSimon Schubert language_lookup_primitive_type_by_name (const struct language_defn *la,
9805796c8dcSSimon Schubert struct gdbarch *gdbarch,
9815796c8dcSSimon Schubert const char *name)
9825796c8dcSSimon Schubert {
9835796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch,
9845796c8dcSSimon Schubert language_gdbarch_data);
9855796c8dcSSimon Schubert struct type *const *p;
986cf7f2e2dSJohn Marino
9875796c8dcSSimon Schubert for (p = ld->arch_info[la->la_language].primitive_type_vector;
9885796c8dcSSimon Schubert (*p) != NULL;
9895796c8dcSSimon Schubert p++)
9905796c8dcSSimon Schubert {
9915796c8dcSSimon Schubert if (strcmp (TYPE_NAME (*p), name) == 0)
9925796c8dcSSimon Schubert return (*p);
9935796c8dcSSimon Schubert }
9945796c8dcSSimon Schubert return (NULL);
9955796c8dcSSimon Schubert }
9965796c8dcSSimon Schubert
997c50c785cSJohn Marino /* Initialize the language routines. */
9985796c8dcSSimon Schubert
9995796c8dcSSimon Schubert void
_initialize_language(void)10005796c8dcSSimon Schubert _initialize_language (void)
10015796c8dcSSimon Schubert {
1002*ef5ccd6cSJohn Marino static const char *const type_or_range_names[]
10035796c8dcSSimon Schubert = { "on", "off", "warn", "auto", NULL };
10045796c8dcSSimon Schubert
1005*ef5ccd6cSJohn Marino static const char *const case_sensitive_names[]
10065796c8dcSSimon Schubert = { "on", "off", "auto", NULL };
10075796c8dcSSimon Schubert
10085796c8dcSSimon Schubert language_gdbarch_data
10095796c8dcSSimon Schubert = gdbarch_data_register_post_init (language_gdbarch_post_init);
10105796c8dcSSimon Schubert
1011c50c785cSJohn Marino /* GDB commands for language specific stuff. */
10125796c8dcSSimon Schubert
10135796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, set_check,
10145796c8dcSSimon Schubert _("Set the status of the type/range checker."),
10155796c8dcSSimon Schubert &setchecklist, "set check ", 0, &setlist);
10165796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &setlist);
10175796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &setlist);
10185796c8dcSSimon Schubert
10195796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, show_check,
10205796c8dcSSimon Schubert _("Show the status of the type/range checker."),
10215796c8dcSSimon Schubert &showchecklist, "show check ", 0, &showlist);
10225796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &showlist);
10235796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &showlist);
10245796c8dcSSimon Schubert
10255796c8dcSSimon Schubert add_setshow_enum_cmd ("range", class_support, type_or_range_names,
1026c50c785cSJohn Marino &range,
1027c50c785cSJohn Marino _("Set range checking. (on/warn/off/auto)"),
1028c50c785cSJohn Marino _("Show range checking. (on/warn/off/auto)"),
1029c50c785cSJohn Marino NULL, set_range_command,
10305796c8dcSSimon Schubert show_range_command,
10315796c8dcSSimon Schubert &setchecklist, &showchecklist);
10325796c8dcSSimon Schubert
10335796c8dcSSimon Schubert add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names,
10345796c8dcSSimon Schubert &case_sensitive, _("\
10355796c8dcSSimon Schubert Set case sensitivity in name search. (on/off/auto)"), _("\
10365796c8dcSSimon Schubert Show case sensitivity in name search. (on/off/auto)"), _("\
10375796c8dcSSimon Schubert For Fortran the default is off; for other languages the default is on."),
10385796c8dcSSimon Schubert set_case_command,
10395796c8dcSSimon Schubert show_case_command,
10405796c8dcSSimon Schubert &setlist, &showlist);
10415796c8dcSSimon Schubert
10425796c8dcSSimon Schubert add_language (&auto_language_defn);
10435796c8dcSSimon Schubert add_language (&local_language_defn);
10445796c8dcSSimon Schubert add_language (&unknown_language_defn);
10455796c8dcSSimon Schubert
10465796c8dcSSimon Schubert language = xstrdup ("auto");
10475796c8dcSSimon Schubert type = xstrdup ("auto");
10485796c8dcSSimon Schubert range = xstrdup ("auto");
10495796c8dcSSimon Schubert case_sensitive = xstrdup ("auto");
10505796c8dcSSimon Schubert
1051c50c785cSJohn Marino /* Have the above take effect. */
10525796c8dcSSimon Schubert set_language (language_auto);
10535796c8dcSSimon Schubert }
1054