15796c8dcSSimon Schubert /* Multiple source language support for GDB. 25796c8dcSSimon Schubert 3*a45ae5f8SJohn Marino Copyright (C) 1991-1996, 1998-2005, 2007-2012 Free Software 4*a45ae5f8SJohn Marino Foundation, Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert Contributed by the Department of Computer Science at the State University 75796c8dcSSimon Schubert of New York at Buffalo. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This file is part of GDB. 105796c8dcSSimon Schubert 115796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 125796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 135796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 145796c8dcSSimon Schubert (at your option) any later version. 155796c8dcSSimon Schubert 165796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 175796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 185796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 195796c8dcSSimon Schubert GNU General Public License for more details. 205796c8dcSSimon Schubert 215796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 225796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 235796c8dcSSimon Schubert 245796c8dcSSimon Schubert /* This file contains functions that return things that are specific 255796c8dcSSimon Schubert to languages. Each function should examine current_language if necessary, 265796c8dcSSimon Schubert and return the appropriate result. */ 275796c8dcSSimon Schubert 285796c8dcSSimon Schubert /* FIXME: Most of these would be better organized as macros which 295796c8dcSSimon Schubert return data out of a "language-specific" struct pointer that is set 305796c8dcSSimon Schubert whenever the working language changes. That would be a lot faster. */ 315796c8dcSSimon Schubert 325796c8dcSSimon Schubert #include "defs.h" 335796c8dcSSimon Schubert #include <ctype.h> 345796c8dcSSimon Schubert #include "gdb_string.h" 355796c8dcSSimon Schubert 365796c8dcSSimon Schubert #include "symtab.h" 375796c8dcSSimon Schubert #include "gdbtypes.h" 385796c8dcSSimon Schubert #include "value.h" 395796c8dcSSimon Schubert #include "gdbcmd.h" 405796c8dcSSimon Schubert #include "expression.h" 415796c8dcSSimon Schubert #include "language.h" 425796c8dcSSimon Schubert #include "target.h" 435796c8dcSSimon Schubert #include "parser-defs.h" 445796c8dcSSimon Schubert #include "jv-lang.h" 455796c8dcSSimon Schubert #include "demangle.h" 465796c8dcSSimon Schubert #include "symfile.h" 475796c8dcSSimon Schubert 485796c8dcSSimon Schubert extern void _initialize_language (void); 495796c8dcSSimon Schubert 505796c8dcSSimon Schubert static void unk_lang_error (char *); 515796c8dcSSimon Schubert 525796c8dcSSimon Schubert static int unk_lang_parser (void); 535796c8dcSSimon Schubert 545796c8dcSSimon Schubert static void show_check (char *, int); 555796c8dcSSimon Schubert 565796c8dcSSimon Schubert static void set_check (char *, int); 575796c8dcSSimon Schubert 585796c8dcSSimon Schubert static void set_type_range_case (void); 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert static void unk_lang_emit_char (int c, struct type *type, 615796c8dcSSimon Schubert struct ui_file *stream, int quoter); 625796c8dcSSimon Schubert 635796c8dcSSimon Schubert static void unk_lang_printchar (int c, struct type *type, 645796c8dcSSimon Schubert struct ui_file *stream); 655796c8dcSSimon Schubert 66cf7f2e2dSJohn Marino static void unk_lang_print_type (struct type *, const char *, struct ui_file *, 675796c8dcSSimon Schubert int, int); 685796c8dcSSimon Schubert 695796c8dcSSimon Schubert static int unk_lang_value_print (struct value *, struct ui_file *, 705796c8dcSSimon Schubert const struct value_print_options *); 715796c8dcSSimon Schubert 725796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc); 735796c8dcSSimon Schubert 745796c8dcSSimon Schubert /* Forward declaration */ 755796c8dcSSimon Schubert extern const struct language_defn unknown_language_defn; 765796c8dcSSimon Schubert 775796c8dcSSimon Schubert /* The current (default at startup) state of type and range checking. 785796c8dcSSimon Schubert (If the modes are set to "auto", though, these are changed based 795796c8dcSSimon Schubert on the default language at startup, and then again based on the 805796c8dcSSimon Schubert language of the first source file. */ 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert enum range_mode range_mode = range_mode_auto; 835796c8dcSSimon Schubert enum range_check range_check = range_check_off; 845796c8dcSSimon Schubert enum type_mode type_mode = type_mode_auto; 855796c8dcSSimon Schubert enum type_check type_check = type_check_off; 865796c8dcSSimon Schubert enum case_mode case_mode = case_mode_auto; 875796c8dcSSimon Schubert enum case_sensitivity case_sensitivity = case_sensitive_on; 885796c8dcSSimon Schubert 89c50c785cSJohn Marino /* The current language and language_mode (see language.h). */ 905796c8dcSSimon Schubert 915796c8dcSSimon Schubert const struct language_defn *current_language = &unknown_language_defn; 925796c8dcSSimon Schubert enum language_mode language_mode = language_mode_auto; 935796c8dcSSimon Schubert 945796c8dcSSimon Schubert /* The language that the user expects to be typing in (the language 955796c8dcSSimon Schubert of main(), or the last language we notified them about, or C). */ 965796c8dcSSimon Schubert 975796c8dcSSimon Schubert const struct language_defn *expected_language; 985796c8dcSSimon Schubert 995796c8dcSSimon Schubert /* The list of supported languages. The list itself is malloc'd. */ 1005796c8dcSSimon Schubert 1015796c8dcSSimon Schubert static const struct language_defn **languages; 1025796c8dcSSimon Schubert static unsigned languages_size; 1035796c8dcSSimon Schubert static unsigned languages_allocsize; 1045796c8dcSSimon Schubert #define DEFAULT_ALLOCSIZE 4 1055796c8dcSSimon Schubert 1065796c8dcSSimon Schubert /* The current values of the "set language/type/range" enum 1075796c8dcSSimon Schubert commands. */ 1085796c8dcSSimon Schubert static const char *language; 1095796c8dcSSimon Schubert static const char *type; 1105796c8dcSSimon Schubert static const char *range; 1115796c8dcSSimon Schubert static const char *case_sensitive; 1125796c8dcSSimon Schubert 1135796c8dcSSimon Schubert /* Warning issued when current_language and the language of the current 1145796c8dcSSimon Schubert frame do not match. */ 1155796c8dcSSimon Schubert char lang_frame_mismatch_warn[] = 1165796c8dcSSimon Schubert "Warning: the current language does not match this frame."; 1175796c8dcSSimon Schubert 1185796c8dcSSimon Schubert /* This page contains the functions corresponding to GDB commands 1195796c8dcSSimon Schubert and their helpers. */ 1205796c8dcSSimon Schubert 1215796c8dcSSimon Schubert /* Show command. Display a warning if the language set 1225796c8dcSSimon Schubert does not match the frame. */ 1235796c8dcSSimon Schubert static void 1245796c8dcSSimon Schubert show_language_command (struct ui_file *file, int from_tty, 1255796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1265796c8dcSSimon Schubert { 127c50c785cSJohn Marino enum language flang; /* The language of the current frame. */ 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert if (language_mode == language_mode_auto) 1305796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 1315796c8dcSSimon Schubert _("The current source language is " 1325796c8dcSSimon Schubert "\"auto; currently %s\".\n"), 1335796c8dcSSimon Schubert current_language->la_name); 1345796c8dcSSimon Schubert else 135c50c785cSJohn Marino fprintf_filtered (gdb_stdout, 136c50c785cSJohn Marino _("The current source language is \"%s\".\n"), 1375796c8dcSSimon Schubert current_language->la_name); 1385796c8dcSSimon Schubert 1395796c8dcSSimon Schubert flang = get_frame_language (); 1405796c8dcSSimon Schubert if (flang != language_unknown && 1415796c8dcSSimon Schubert language_mode == language_mode_manual && 1425796c8dcSSimon Schubert current_language->la_language != flang) 1435796c8dcSSimon Schubert printf_filtered ("%s\n", lang_frame_mismatch_warn); 1445796c8dcSSimon Schubert } 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert /* Set command. Change the current working language. */ 1475796c8dcSSimon Schubert static void 1485796c8dcSSimon Schubert set_language_command (char *ignore, int from_tty, struct cmd_list_element *c) 1495796c8dcSSimon Schubert { 1505796c8dcSSimon Schubert int i; 1515796c8dcSSimon Schubert enum language flang; 1525796c8dcSSimon Schubert 1535796c8dcSSimon Schubert /* Search the list of languages for a match. */ 1545796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 1555796c8dcSSimon Schubert { 1565796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, language) == 0) 1575796c8dcSSimon Schubert { 1585796c8dcSSimon Schubert /* Found it! Go into manual mode, and use this language. */ 1595796c8dcSSimon Schubert if (languages[i]->la_language == language_auto) 1605796c8dcSSimon Schubert { 1615796c8dcSSimon Schubert /* Enter auto mode. Set to the current frame's language, if 1625796c8dcSSimon Schubert known, or fallback to the initial language. */ 1635796c8dcSSimon Schubert language_mode = language_mode_auto; 1645796c8dcSSimon Schubert flang = get_frame_language (); 1655796c8dcSSimon Schubert if (flang != language_unknown) 1665796c8dcSSimon Schubert set_language (flang); 1675796c8dcSSimon Schubert else 1685796c8dcSSimon Schubert set_initial_language (); 1695796c8dcSSimon Schubert expected_language = current_language; 1705796c8dcSSimon Schubert return; 1715796c8dcSSimon Schubert } 1725796c8dcSSimon Schubert else 1735796c8dcSSimon Schubert { 1745796c8dcSSimon Schubert /* Enter manual mode. Set the specified language. */ 1755796c8dcSSimon Schubert language_mode = language_mode_manual; 1765796c8dcSSimon Schubert current_language = languages[i]; 1775796c8dcSSimon Schubert set_type_range_case (); 1785796c8dcSSimon Schubert expected_language = current_language; 1795796c8dcSSimon Schubert return; 1805796c8dcSSimon Schubert } 1815796c8dcSSimon Schubert } 1825796c8dcSSimon Schubert } 1835796c8dcSSimon Schubert 1845796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 1855796c8dcSSimon Schubert "Couldn't find language `%s' in known languages list.", 1865796c8dcSSimon Schubert language); 1875796c8dcSSimon Schubert } 1885796c8dcSSimon Schubert 1895796c8dcSSimon Schubert /* Show command. Display a warning if the type setting does 1905796c8dcSSimon Schubert not match the current language. */ 1915796c8dcSSimon Schubert static void 1925796c8dcSSimon Schubert show_type_command (struct ui_file *file, int from_tty, 1935796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1945796c8dcSSimon Schubert { 1955796c8dcSSimon Schubert if (type_mode == type_mode_auto) 1965796c8dcSSimon Schubert { 1975796c8dcSSimon Schubert char *tmp = NULL; 1985796c8dcSSimon Schubert 1995796c8dcSSimon Schubert switch (type_check) 2005796c8dcSSimon Schubert { 2015796c8dcSSimon Schubert case type_check_on: 2025796c8dcSSimon Schubert tmp = "on"; 2035796c8dcSSimon Schubert break; 2045796c8dcSSimon Schubert case type_check_off: 2055796c8dcSSimon Schubert tmp = "off"; 2065796c8dcSSimon Schubert break; 2075796c8dcSSimon Schubert case type_check_warn: 2085796c8dcSSimon Schubert tmp = "warn"; 2095796c8dcSSimon Schubert break; 2105796c8dcSSimon Schubert default: 2115796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 2125796c8dcSSimon Schubert "Unrecognized type check setting."); 2135796c8dcSSimon Schubert } 2145796c8dcSSimon Schubert 2155796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 2165796c8dcSSimon Schubert _("Type checking is \"auto; currently %s\".\n"), 2175796c8dcSSimon Schubert tmp); 2185796c8dcSSimon Schubert } 2195796c8dcSSimon Schubert else 2205796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Type checking is \"%s\".\n"), 2215796c8dcSSimon Schubert value); 2225796c8dcSSimon Schubert 2235796c8dcSSimon Schubert if (type_check != current_language->la_type_check) 2245796c8dcSSimon Schubert warning (_("the current type check setting" 2255796c8dcSSimon Schubert " does not match the language.\n")); 2265796c8dcSSimon Schubert } 2275796c8dcSSimon Schubert 2285796c8dcSSimon Schubert /* Set command. Change the setting for type checking. */ 2295796c8dcSSimon Schubert static void 2305796c8dcSSimon Schubert set_type_command (char *ignore, int from_tty, struct cmd_list_element *c) 2315796c8dcSSimon Schubert { 2325796c8dcSSimon Schubert if (strcmp (type, "on") == 0) 2335796c8dcSSimon Schubert { 2345796c8dcSSimon Schubert type_check = type_check_on; 2355796c8dcSSimon Schubert type_mode = type_mode_manual; 2365796c8dcSSimon Schubert } 2375796c8dcSSimon Schubert else if (strcmp (type, "warn") == 0) 2385796c8dcSSimon Schubert { 2395796c8dcSSimon Schubert type_check = type_check_warn; 2405796c8dcSSimon Schubert type_mode = type_mode_manual; 2415796c8dcSSimon Schubert } 2425796c8dcSSimon Schubert else if (strcmp (type, "off") == 0) 2435796c8dcSSimon Schubert { 2445796c8dcSSimon Schubert type_check = type_check_off; 2455796c8dcSSimon Schubert type_mode = type_mode_manual; 2465796c8dcSSimon Schubert } 2475796c8dcSSimon Schubert else if (strcmp (type, "auto") == 0) 2485796c8dcSSimon Schubert { 2495796c8dcSSimon Schubert type_mode = type_mode_auto; 2505796c8dcSSimon Schubert set_type_range_case (); 2515796c8dcSSimon Schubert return; 2525796c8dcSSimon Schubert } 2535796c8dcSSimon Schubert else 2545796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 2555796c8dcSSimon Schubert _("Unrecognized type check setting: \"%s\""), type); 2565796c8dcSSimon Schubert 2575796c8dcSSimon Schubert if (type_check != current_language->la_type_check) 2585796c8dcSSimon Schubert warning (_("the current type check setting" 2595796c8dcSSimon Schubert " does not match the language.\n")); 2605796c8dcSSimon Schubert } 2615796c8dcSSimon Schubert 2625796c8dcSSimon Schubert /* Show command. Display a warning if the range setting does 2635796c8dcSSimon Schubert not match the current language. */ 2645796c8dcSSimon Schubert static void 2655796c8dcSSimon Schubert show_range_command (struct ui_file *file, int from_tty, 2665796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 2675796c8dcSSimon Schubert { 2685796c8dcSSimon Schubert if (range_mode == range_mode_auto) 2695796c8dcSSimon Schubert { 2705796c8dcSSimon Schubert char *tmp; 2715796c8dcSSimon Schubert 2725796c8dcSSimon Schubert switch (range_check) 2735796c8dcSSimon Schubert { 2745796c8dcSSimon Schubert case range_check_on: 2755796c8dcSSimon Schubert tmp = "on"; 2765796c8dcSSimon Schubert break; 2775796c8dcSSimon Schubert case range_check_off: 2785796c8dcSSimon Schubert tmp = "off"; 2795796c8dcSSimon Schubert break; 2805796c8dcSSimon Schubert case range_check_warn: 2815796c8dcSSimon Schubert tmp = "warn"; 2825796c8dcSSimon Schubert break; 2835796c8dcSSimon Schubert default: 2845796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 2855796c8dcSSimon Schubert "Unrecognized range check setting."); 2865796c8dcSSimon Schubert } 2875796c8dcSSimon Schubert 2885796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 2895796c8dcSSimon Schubert _("Range checking is \"auto; currently %s\".\n"), 2905796c8dcSSimon Schubert tmp); 2915796c8dcSSimon Schubert } 2925796c8dcSSimon Schubert else 2935796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"), 2945796c8dcSSimon Schubert value); 2955796c8dcSSimon Schubert 2965796c8dcSSimon Schubert if (range_check != current_language->la_range_check) 2975796c8dcSSimon Schubert warning (_("the current range check setting " 2985796c8dcSSimon Schubert "does not match the language.\n")); 2995796c8dcSSimon Schubert } 3005796c8dcSSimon Schubert 3015796c8dcSSimon Schubert /* Set command. Change the setting for range checking. */ 3025796c8dcSSimon Schubert static void 3035796c8dcSSimon Schubert set_range_command (char *ignore, int from_tty, struct cmd_list_element *c) 3045796c8dcSSimon Schubert { 3055796c8dcSSimon Schubert if (strcmp (range, "on") == 0) 3065796c8dcSSimon Schubert { 3075796c8dcSSimon Schubert range_check = range_check_on; 3085796c8dcSSimon Schubert range_mode = range_mode_manual; 3095796c8dcSSimon Schubert } 3105796c8dcSSimon Schubert else if (strcmp (range, "warn") == 0) 3115796c8dcSSimon Schubert { 3125796c8dcSSimon Schubert range_check = range_check_warn; 3135796c8dcSSimon Schubert range_mode = range_mode_manual; 3145796c8dcSSimon Schubert } 3155796c8dcSSimon Schubert else if (strcmp (range, "off") == 0) 3165796c8dcSSimon Schubert { 3175796c8dcSSimon Schubert range_check = range_check_off; 3185796c8dcSSimon Schubert range_mode = range_mode_manual; 3195796c8dcSSimon Schubert } 3205796c8dcSSimon Schubert else if (strcmp (range, "auto") == 0) 3215796c8dcSSimon Schubert { 3225796c8dcSSimon Schubert range_mode = range_mode_auto; 3235796c8dcSSimon Schubert set_type_range_case (); 3245796c8dcSSimon Schubert return; 3255796c8dcSSimon Schubert } 3265796c8dcSSimon Schubert else 3275796c8dcSSimon Schubert { 3285796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3295796c8dcSSimon Schubert _("Unrecognized range check setting: \"%s\""), range); 3305796c8dcSSimon Schubert } 3315796c8dcSSimon Schubert if (range_check != current_language->la_range_check) 3325796c8dcSSimon Schubert warning (_("the current range check setting " 3335796c8dcSSimon Schubert "does not match the language.\n")); 3345796c8dcSSimon Schubert } 3355796c8dcSSimon Schubert 3365796c8dcSSimon Schubert /* Show command. Display a warning if the case sensitivity setting does 3375796c8dcSSimon Schubert not match the current language. */ 3385796c8dcSSimon Schubert static void 3395796c8dcSSimon Schubert show_case_command (struct ui_file *file, int from_tty, 3405796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 3415796c8dcSSimon Schubert { 3425796c8dcSSimon Schubert if (case_mode == case_mode_auto) 3435796c8dcSSimon Schubert { 3445796c8dcSSimon Schubert char *tmp = NULL; 3455796c8dcSSimon Schubert 3465796c8dcSSimon Schubert switch (case_sensitivity) 3475796c8dcSSimon Schubert { 3485796c8dcSSimon Schubert case case_sensitive_on: 3495796c8dcSSimon Schubert tmp = "on"; 3505796c8dcSSimon Schubert break; 3515796c8dcSSimon Schubert case case_sensitive_off: 3525796c8dcSSimon Schubert tmp = "off"; 3535796c8dcSSimon Schubert break; 3545796c8dcSSimon Schubert default: 3555796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3565796c8dcSSimon Schubert "Unrecognized case-sensitive setting."); 3575796c8dcSSimon Schubert } 3585796c8dcSSimon Schubert 3595796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 3605796c8dcSSimon Schubert _("Case sensitivity in " 3615796c8dcSSimon Schubert "name search is \"auto; currently %s\".\n"), 3625796c8dcSSimon Schubert tmp); 3635796c8dcSSimon Schubert } 3645796c8dcSSimon Schubert else 365c50c785cSJohn Marino fprintf_filtered (gdb_stdout, 366c50c785cSJohn Marino _("Case sensitivity in name search is \"%s\".\n"), 3675796c8dcSSimon Schubert value); 3685796c8dcSSimon Schubert 3695796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity) 3705796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match " 3715796c8dcSSimon Schubert "the language.\n")); 3725796c8dcSSimon Schubert } 3735796c8dcSSimon Schubert 3745796c8dcSSimon Schubert /* Set command. Change the setting for case sensitivity. */ 3755796c8dcSSimon Schubert 3765796c8dcSSimon Schubert static void 3775796c8dcSSimon Schubert set_case_command (char *ignore, int from_tty, struct cmd_list_element *c) 3785796c8dcSSimon Schubert { 3795796c8dcSSimon Schubert if (strcmp (case_sensitive, "on") == 0) 3805796c8dcSSimon Schubert { 3815796c8dcSSimon Schubert case_sensitivity = case_sensitive_on; 3825796c8dcSSimon Schubert case_mode = case_mode_manual; 3835796c8dcSSimon Schubert } 3845796c8dcSSimon Schubert else if (strcmp (case_sensitive, "off") == 0) 3855796c8dcSSimon Schubert { 3865796c8dcSSimon Schubert case_sensitivity = case_sensitive_off; 3875796c8dcSSimon Schubert case_mode = case_mode_manual; 3885796c8dcSSimon Schubert } 3895796c8dcSSimon Schubert else if (strcmp (case_sensitive, "auto") == 0) 3905796c8dcSSimon Schubert { 3915796c8dcSSimon Schubert case_mode = case_mode_auto; 3925796c8dcSSimon Schubert set_type_range_case (); 3935796c8dcSSimon Schubert return; 3945796c8dcSSimon Schubert } 3955796c8dcSSimon Schubert else 3965796c8dcSSimon Schubert { 3975796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3985796c8dcSSimon Schubert "Unrecognized case-sensitive setting: \"%s\"", 3995796c8dcSSimon Schubert case_sensitive); 4005796c8dcSSimon Schubert } 4015796c8dcSSimon Schubert 4025796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity) 4035796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match " 4045796c8dcSSimon Schubert "the language.\n")); 4055796c8dcSSimon Schubert } 4065796c8dcSSimon Schubert 4075796c8dcSSimon Schubert /* Set the status of range and type checking and case sensitivity based on 4085796c8dcSSimon Schubert the current modes and the current language. 4095796c8dcSSimon Schubert If SHOW is non-zero, then print out the current language, 4105796c8dcSSimon Schubert type and range checking status. */ 4115796c8dcSSimon Schubert static void 4125796c8dcSSimon Schubert set_type_range_case (void) 4135796c8dcSSimon Schubert { 4145796c8dcSSimon Schubert if (range_mode == range_mode_auto) 4155796c8dcSSimon Schubert range_check = current_language->la_range_check; 4165796c8dcSSimon Schubert 4175796c8dcSSimon Schubert if (type_mode == type_mode_auto) 4185796c8dcSSimon Schubert type_check = current_language->la_type_check; 4195796c8dcSSimon Schubert 4205796c8dcSSimon Schubert if (case_mode == case_mode_auto) 4215796c8dcSSimon Schubert case_sensitivity = current_language->la_case_sensitivity; 4225796c8dcSSimon Schubert } 4235796c8dcSSimon Schubert 424c50c785cSJohn Marino /* Set current language to (enum language) LANG. Returns previous 425c50c785cSJohn Marino language. */ 4265796c8dcSSimon Schubert 4275796c8dcSSimon Schubert enum language 4285796c8dcSSimon Schubert set_language (enum language lang) 4295796c8dcSSimon Schubert { 4305796c8dcSSimon Schubert int i; 4315796c8dcSSimon Schubert enum language prev_language; 4325796c8dcSSimon Schubert 4335796c8dcSSimon Schubert prev_language = current_language->la_language; 4345796c8dcSSimon Schubert 4355796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 4365796c8dcSSimon Schubert { 4375796c8dcSSimon Schubert if (languages[i]->la_language == lang) 4385796c8dcSSimon Schubert { 4395796c8dcSSimon Schubert current_language = languages[i]; 4405796c8dcSSimon Schubert set_type_range_case (); 4415796c8dcSSimon Schubert break; 4425796c8dcSSimon Schubert } 4435796c8dcSSimon Schubert } 4445796c8dcSSimon Schubert 4455796c8dcSSimon Schubert return prev_language; 4465796c8dcSSimon Schubert } 4475796c8dcSSimon Schubert 4485796c8dcSSimon Schubert 4495796c8dcSSimon Schubert /* Print out the current language settings: language, range and 4505796c8dcSSimon Schubert type checking. If QUIETLY, print only what has changed. */ 4515796c8dcSSimon Schubert 4525796c8dcSSimon Schubert void 4535796c8dcSSimon Schubert language_info (int quietly) 4545796c8dcSSimon Schubert { 4555796c8dcSSimon Schubert if (quietly && expected_language == current_language) 4565796c8dcSSimon Schubert return; 4575796c8dcSSimon Schubert 4585796c8dcSSimon Schubert expected_language = current_language; 4595796c8dcSSimon Schubert printf_unfiltered (_("Current language: %s\n"), language); 4605796c8dcSSimon Schubert show_language_command (NULL, 1, NULL, NULL); 4615796c8dcSSimon Schubert 4625796c8dcSSimon Schubert if (!quietly) 4635796c8dcSSimon Schubert { 4645796c8dcSSimon Schubert printf_unfiltered (_("Type checking: %s\n"), type); 4655796c8dcSSimon Schubert show_type_command (NULL, 1, NULL, NULL); 4665796c8dcSSimon Schubert printf_unfiltered (_("Range checking: %s\n"), range); 4675796c8dcSSimon Schubert show_range_command (NULL, 1, NULL, NULL); 4685796c8dcSSimon Schubert printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive); 4695796c8dcSSimon Schubert show_case_command (NULL, 1, NULL, NULL); 4705796c8dcSSimon Schubert } 4715796c8dcSSimon Schubert } 4725796c8dcSSimon Schubert 4735796c8dcSSimon Schubert /* Return the result of a binary operation. */ 4745796c8dcSSimon Schubert 4755796c8dcSSimon Schubert #if 0 /* Currently unused */ 4765796c8dcSSimon Schubert 4775796c8dcSSimon Schubert struct type * 4785796c8dcSSimon Schubert binop_result_type (struct value *v1, struct value *v2) 4795796c8dcSSimon Schubert { 4805796c8dcSSimon Schubert int size, uns; 4815796c8dcSSimon Schubert struct type *t1 = check_typedef (VALUE_TYPE (v1)); 4825796c8dcSSimon Schubert struct type *t2 = check_typedef (VALUE_TYPE (v2)); 4835796c8dcSSimon Schubert 4845796c8dcSSimon Schubert int l1 = TYPE_LENGTH (t1); 4855796c8dcSSimon Schubert int l2 = TYPE_LENGTH (t2); 4865796c8dcSSimon Schubert 4875796c8dcSSimon Schubert switch (current_language->la_language) 4885796c8dcSSimon Schubert { 4895796c8dcSSimon Schubert case language_c: 4905796c8dcSSimon Schubert case language_cplus: 491cf7f2e2dSJohn Marino case language_d: 4925796c8dcSSimon Schubert case language_objc: 4935796c8dcSSimon Schubert if (TYPE_CODE (t1) == TYPE_CODE_FLT) 4945796c8dcSSimon Schubert return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ? 4955796c8dcSSimon Schubert VALUE_TYPE (v2) : VALUE_TYPE (v1); 4965796c8dcSSimon Schubert else if (TYPE_CODE (t2) == TYPE_CODE_FLT) 4975796c8dcSSimon Schubert return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ? 4985796c8dcSSimon Schubert VALUE_TYPE (v1) : VALUE_TYPE (v2); 4995796c8dcSSimon Schubert else if (TYPE_UNSIGNED (t1) && l1 > l2) 5005796c8dcSSimon Schubert return VALUE_TYPE (v1); 5015796c8dcSSimon Schubert else if (TYPE_UNSIGNED (t2) && l2 > l1) 5025796c8dcSSimon Schubert return VALUE_TYPE (v2); 503c50c785cSJohn Marino else /* Both are signed. Result is the 504c50c785cSJohn Marino longer type. */ 5055796c8dcSSimon Schubert return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 5065796c8dcSSimon Schubert break; 5075796c8dcSSimon Schubert case language_m2: 5085796c8dcSSimon Schubert /* If we are doing type-checking, l1 should equal l2, so this is 5095796c8dcSSimon Schubert not needed. */ 5105796c8dcSSimon Schubert return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 5115796c8dcSSimon Schubert break; 5125796c8dcSSimon Schubert } 5135796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("failed internal consistency check")); 5145796c8dcSSimon Schubert return (struct type *) 0; /* For lint */ 5155796c8dcSSimon Schubert } 5165796c8dcSSimon Schubert 5175796c8dcSSimon Schubert #endif /* 0 */ 5185796c8dcSSimon Schubert #if 0 5195796c8dcSSimon Schubert /* This page contains functions that are used in type/range checking. 5205796c8dcSSimon Schubert They all return zero if the type/range check fails. 5215796c8dcSSimon Schubert 5225796c8dcSSimon Schubert It is hoped that these will make extending GDB to parse different 5235796c8dcSSimon Schubert languages a little easier. These are primarily used in eval.c when 5245796c8dcSSimon Schubert evaluating expressions and making sure that their types are correct. 5255796c8dcSSimon Schubert Instead of having a mess of conjucted/disjuncted expressions in an "if", 5265796c8dcSSimon Schubert the ideas of type can be wrapped up in the following functions. 5275796c8dcSSimon Schubert 5285796c8dcSSimon Schubert Note that some of them are not currently dependent upon which language 5295796c8dcSSimon Schubert is currently being parsed. For example, floats are the same in 5305796c8dcSSimon Schubert C and Modula-2 (ie. the only floating point type has TYPE_CODE of 5315796c8dcSSimon Schubert TYPE_CODE_FLT), while booleans are different. */ 5325796c8dcSSimon Schubert 5335796c8dcSSimon Schubert /* Returns non-zero if its argument is a simple type. This is the same for 5345796c8dcSSimon Schubert both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur, 5355796c8dcSSimon Schubert and thus will never cause the failure of the test. */ 5365796c8dcSSimon Schubert int 5375796c8dcSSimon Schubert simple_type (struct type *type) 5385796c8dcSSimon Schubert { 5395796c8dcSSimon Schubert CHECK_TYPEDEF (type); 5405796c8dcSSimon Schubert switch (TYPE_CODE (type)) 5415796c8dcSSimon Schubert { 5425796c8dcSSimon Schubert case TYPE_CODE_INT: 5435796c8dcSSimon Schubert case TYPE_CODE_CHAR: 5445796c8dcSSimon Schubert case TYPE_CODE_ENUM: 5455796c8dcSSimon Schubert case TYPE_CODE_FLT: 5465796c8dcSSimon Schubert case TYPE_CODE_RANGE: 5475796c8dcSSimon Schubert case TYPE_CODE_BOOL: 5485796c8dcSSimon Schubert return 1; 5495796c8dcSSimon Schubert 5505796c8dcSSimon Schubert default: 5515796c8dcSSimon Schubert return 0; 5525796c8dcSSimon Schubert } 5535796c8dcSSimon Schubert } 5545796c8dcSSimon Schubert 5555796c8dcSSimon Schubert /* Returns non-zero if its argument is of an ordered type. 5565796c8dcSSimon Schubert An ordered type is one in which the elements can be tested for the 5575796c8dcSSimon Schubert properties of "greater than", "less than", etc, or for which the 5585796c8dcSSimon Schubert operations "increment" or "decrement" make sense. */ 5595796c8dcSSimon Schubert int 5605796c8dcSSimon Schubert ordered_type (struct type *type) 5615796c8dcSSimon Schubert { 5625796c8dcSSimon Schubert CHECK_TYPEDEF (type); 5635796c8dcSSimon Schubert switch (TYPE_CODE (type)) 5645796c8dcSSimon Schubert { 5655796c8dcSSimon Schubert case TYPE_CODE_INT: 5665796c8dcSSimon Schubert case TYPE_CODE_CHAR: 5675796c8dcSSimon Schubert case TYPE_CODE_ENUM: 5685796c8dcSSimon Schubert case TYPE_CODE_FLT: 5695796c8dcSSimon Schubert case TYPE_CODE_RANGE: 5705796c8dcSSimon Schubert return 1; 5715796c8dcSSimon Schubert 5725796c8dcSSimon Schubert default: 5735796c8dcSSimon Schubert return 0; 5745796c8dcSSimon Schubert } 5755796c8dcSSimon Schubert } 5765796c8dcSSimon Schubert 577c50c785cSJohn Marino /* Returns non-zero if the two types are the same. */ 5785796c8dcSSimon Schubert int 5795796c8dcSSimon Schubert same_type (struct type *arg1, struct type *arg2) 5805796c8dcSSimon Schubert { 5815796c8dcSSimon Schubert CHECK_TYPEDEF (type); 582c50c785cSJohn Marino if (structured_type (arg1) 583c50c785cSJohn Marino ? !structured_type (arg2) : structured_type (arg2)) 584c50c785cSJohn Marino /* One is structured and one isn't. */ 5855796c8dcSSimon Schubert return 0; 5865796c8dcSSimon Schubert else if (structured_type (arg1) && structured_type (arg2)) 5875796c8dcSSimon Schubert return arg1 == arg2; 5885796c8dcSSimon Schubert else if (numeric_type (arg1) && numeric_type (arg2)) 5895796c8dcSSimon Schubert return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) && 5905796c8dcSSimon Schubert (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2)) 5915796c8dcSSimon Schubert ? 1 : 0; 5925796c8dcSSimon Schubert else 5935796c8dcSSimon Schubert return arg1 == arg2; 5945796c8dcSSimon Schubert } 5955796c8dcSSimon Schubert 596c50c785cSJohn Marino /* Returns non-zero if the type is integral. */ 5975796c8dcSSimon Schubert int 5985796c8dcSSimon Schubert integral_type (struct type *type) 5995796c8dcSSimon Schubert { 6005796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6015796c8dcSSimon Schubert switch (current_language->la_language) 6025796c8dcSSimon Schubert { 6035796c8dcSSimon Schubert case language_c: 6045796c8dcSSimon Schubert case language_cplus: 605cf7f2e2dSJohn Marino case language_d: 6065796c8dcSSimon Schubert case language_objc: 6075796c8dcSSimon Schubert return (TYPE_CODE (type) != TYPE_CODE_INT) && 6085796c8dcSSimon Schubert (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1; 6095796c8dcSSimon Schubert case language_m2: 6105796c8dcSSimon Schubert case language_pascal: 6115796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1; 6125796c8dcSSimon Schubert default: 6135796c8dcSSimon Schubert error (_("Language not supported.")); 6145796c8dcSSimon Schubert } 6155796c8dcSSimon Schubert } 6165796c8dcSSimon Schubert 617c50c785cSJohn Marino /* Returns non-zero if the value is numeric. */ 6185796c8dcSSimon Schubert int 6195796c8dcSSimon Schubert numeric_type (struct type *type) 6205796c8dcSSimon Schubert { 6215796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6225796c8dcSSimon Schubert switch (TYPE_CODE (type)) 6235796c8dcSSimon Schubert { 6245796c8dcSSimon Schubert case TYPE_CODE_INT: 6255796c8dcSSimon Schubert case TYPE_CODE_FLT: 6265796c8dcSSimon Schubert return 1; 6275796c8dcSSimon Schubert 6285796c8dcSSimon Schubert default: 6295796c8dcSSimon Schubert return 0; 6305796c8dcSSimon Schubert } 6315796c8dcSSimon Schubert } 6325796c8dcSSimon Schubert 633c50c785cSJohn Marino /* Returns non-zero if the value is a character type. */ 6345796c8dcSSimon Schubert int 6355796c8dcSSimon Schubert character_type (struct type *type) 6365796c8dcSSimon Schubert { 6375796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6385796c8dcSSimon Schubert switch (current_language->la_language) 6395796c8dcSSimon Schubert { 6405796c8dcSSimon Schubert case language_m2: 6415796c8dcSSimon Schubert case language_pascal: 6425796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1; 6435796c8dcSSimon Schubert 6445796c8dcSSimon Schubert case language_c: 6455796c8dcSSimon Schubert case language_cplus: 646cf7f2e2dSJohn Marino case language_d: 6475796c8dcSSimon Schubert case language_objc: 6485796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_INT) && 6495796c8dcSSimon Schubert TYPE_LENGTH (type) == sizeof (char) 6505796c8dcSSimon Schubert ? 1 : 0; 6515796c8dcSSimon Schubert default: 6525796c8dcSSimon Schubert return (0); 6535796c8dcSSimon Schubert } 6545796c8dcSSimon Schubert } 6555796c8dcSSimon Schubert 656c50c785cSJohn Marino /* Returns non-zero if the value is a string type. */ 6575796c8dcSSimon Schubert int 6585796c8dcSSimon Schubert string_type (struct type *type) 6595796c8dcSSimon Schubert { 6605796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6615796c8dcSSimon Schubert switch (current_language->la_language) 6625796c8dcSSimon Schubert { 6635796c8dcSSimon Schubert case language_m2: 6645796c8dcSSimon Schubert case language_pascal: 6655796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1; 6665796c8dcSSimon Schubert 6675796c8dcSSimon Schubert case language_c: 6685796c8dcSSimon Schubert case language_cplus: 669cf7f2e2dSJohn Marino case language_d: 6705796c8dcSSimon Schubert case language_objc: 6715796c8dcSSimon Schubert /* C does not have distinct string type. */ 6725796c8dcSSimon Schubert return (0); 6735796c8dcSSimon Schubert default: 6745796c8dcSSimon Schubert return (0); 6755796c8dcSSimon Schubert } 6765796c8dcSSimon Schubert } 6775796c8dcSSimon Schubert 678c50c785cSJohn Marino /* Returns non-zero if the value is a boolean type. */ 6795796c8dcSSimon Schubert int 6805796c8dcSSimon Schubert boolean_type (struct type *type) 6815796c8dcSSimon Schubert { 6825796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6835796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_BOOL) 6845796c8dcSSimon Schubert return 1; 6855796c8dcSSimon Schubert switch (current_language->la_language) 6865796c8dcSSimon Schubert { 6875796c8dcSSimon Schubert case language_c: 6885796c8dcSSimon Schubert case language_cplus: 689cf7f2e2dSJohn Marino case language_d: 6905796c8dcSSimon Schubert case language_objc: 6915796c8dcSSimon Schubert /* Might be more cleanly handled by having a 6925796c8dcSSimon Schubert TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such 6935796c8dcSSimon Schubert languages, or a TYPE_CODE_INT_OR_BOOL for C. */ 6945796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_INT) 6955796c8dcSSimon Schubert return 1; 6965796c8dcSSimon Schubert default: 6975796c8dcSSimon Schubert break; 6985796c8dcSSimon Schubert } 6995796c8dcSSimon Schubert return 0; 7005796c8dcSSimon Schubert } 7015796c8dcSSimon Schubert 702c50c785cSJohn Marino /* Returns non-zero if the value is a floating-point type. */ 7035796c8dcSSimon Schubert int 7045796c8dcSSimon Schubert float_type (struct type *type) 7055796c8dcSSimon Schubert { 7065796c8dcSSimon Schubert CHECK_TYPEDEF (type); 7075796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_FLT; 7085796c8dcSSimon Schubert } 709cf7f2e2dSJohn Marino #endif 7105796c8dcSSimon Schubert 711c50c785cSJohn Marino /* Returns non-zero if the value is a pointer type. */ 7125796c8dcSSimon Schubert int 7135796c8dcSSimon Schubert pointer_type (struct type *type) 7145796c8dcSSimon Schubert { 7155796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_PTR || 7165796c8dcSSimon Schubert TYPE_CODE (type) == TYPE_CODE_REF; 7175796c8dcSSimon Schubert } 7185796c8dcSSimon Schubert 719cf7f2e2dSJohn Marino #if 0 720c50c785cSJohn Marino /* Returns non-zero if the value is a structured type. */ 7215796c8dcSSimon Schubert int 7225796c8dcSSimon Schubert structured_type (struct type *type) 7235796c8dcSSimon Schubert { 7245796c8dcSSimon Schubert CHECK_TYPEDEF (type); 7255796c8dcSSimon Schubert switch (current_language->la_language) 7265796c8dcSSimon Schubert { 7275796c8dcSSimon Schubert case language_c: 7285796c8dcSSimon Schubert case language_cplus: 729cf7f2e2dSJohn Marino case language_d: 7305796c8dcSSimon Schubert case language_objc: 7315796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 7325796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_UNION) || 7335796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_ARRAY); 7345796c8dcSSimon Schubert case language_pascal: 7355796c8dcSSimon Schubert return (TYPE_CODE(type) == TYPE_CODE_STRUCT) || 7365796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_UNION) || 7375796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_SET) || 7385796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_ARRAY); 7395796c8dcSSimon Schubert case language_m2: 7405796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 7415796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_SET) || 7425796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_ARRAY); 7435796c8dcSSimon Schubert default: 7445796c8dcSSimon Schubert return (0); 7455796c8dcSSimon Schubert } 7465796c8dcSSimon Schubert } 7475796c8dcSSimon Schubert #endif 7485796c8dcSSimon Schubert 7495796c8dcSSimon Schubert /* This page contains functions that return info about 7505796c8dcSSimon Schubert (struct value) values used in GDB. */ 7515796c8dcSSimon Schubert 7525796c8dcSSimon Schubert /* Returns non-zero if the value VAL represents a true value. */ 7535796c8dcSSimon Schubert int 7545796c8dcSSimon Schubert value_true (struct value *val) 7555796c8dcSSimon Schubert { 7565796c8dcSSimon Schubert /* It is possible that we should have some sort of error if a non-boolean 7575796c8dcSSimon Schubert value is used in this context. Possibly dependent on some kind of 7585796c8dcSSimon Schubert "boolean-checking" option like range checking. But it should probably 7595796c8dcSSimon Schubert not depend on the language except insofar as is necessary to identify 7605796c8dcSSimon Schubert a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean 7615796c8dcSSimon Schubert should be an error, probably). */ 7625796c8dcSSimon Schubert return !value_logical_not (val); 7635796c8dcSSimon Schubert } 7645796c8dcSSimon Schubert 7655796c8dcSSimon Schubert /* This page contains functions for the printing out of 7665796c8dcSSimon Schubert error messages that occur during type- and range- 7675796c8dcSSimon Schubert checking. */ 7685796c8dcSSimon Schubert 7695796c8dcSSimon Schubert /* These are called when a language fails a type- or range-check. The 7705796c8dcSSimon Schubert first argument should be a printf()-style format string, and the 7715796c8dcSSimon Schubert rest of the arguments should be its arguments. If 7725796c8dcSSimon Schubert [type|range]_check is [type|range]_check_on, an error is printed; 7735796c8dcSSimon Schubert if [type|range]_check_warn, a warning; otherwise just the 7745796c8dcSSimon Schubert message. */ 7755796c8dcSSimon Schubert 7765796c8dcSSimon Schubert void 7775796c8dcSSimon Schubert type_error (const char *string,...) 7785796c8dcSSimon Schubert { 7795796c8dcSSimon Schubert va_list args; 7805796c8dcSSimon Schubert 781cf7f2e2dSJohn Marino va_start (args, string); 7825796c8dcSSimon Schubert switch (type_check) 7835796c8dcSSimon Schubert { 7845796c8dcSSimon Schubert case type_check_warn: 7855796c8dcSSimon Schubert vwarning (string, args); 7865796c8dcSSimon Schubert break; 7875796c8dcSSimon Schubert case type_check_on: 7885796c8dcSSimon Schubert verror (string, args); 7895796c8dcSSimon Schubert break; 7905796c8dcSSimon Schubert case type_check_off: 7915796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything 7925796c8dcSSimon Schubert when type error is off? */ 7935796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args); 7945796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n"); 7955796c8dcSSimon Schubert break; 7965796c8dcSSimon Schubert default: 7975796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 7985796c8dcSSimon Schubert } 7995796c8dcSSimon Schubert va_end (args); 8005796c8dcSSimon Schubert } 8015796c8dcSSimon Schubert 8025796c8dcSSimon Schubert void 8035796c8dcSSimon Schubert range_error (const char *string,...) 8045796c8dcSSimon Schubert { 8055796c8dcSSimon Schubert va_list args; 8065796c8dcSSimon Schubert 807cf7f2e2dSJohn Marino va_start (args, string); 8085796c8dcSSimon Schubert switch (range_check) 8095796c8dcSSimon Schubert { 8105796c8dcSSimon Schubert case range_check_warn: 8115796c8dcSSimon Schubert vwarning (string, args); 8125796c8dcSSimon Schubert break; 8135796c8dcSSimon Schubert case range_check_on: 8145796c8dcSSimon Schubert verror (string, args); 8155796c8dcSSimon Schubert break; 8165796c8dcSSimon Schubert case range_check_off: 8175796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything 8185796c8dcSSimon Schubert when range error is off? */ 8195796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args); 8205796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n"); 8215796c8dcSSimon Schubert break; 8225796c8dcSSimon Schubert default: 8235796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 8245796c8dcSSimon Schubert } 8255796c8dcSSimon Schubert va_end (args); 8265796c8dcSSimon Schubert } 8275796c8dcSSimon Schubert 8285796c8dcSSimon Schubert 829c50c785cSJohn Marino /* This page contains miscellaneous functions. */ 8305796c8dcSSimon Schubert 8315796c8dcSSimon Schubert /* Return the language enum for a given language string. */ 8325796c8dcSSimon Schubert 8335796c8dcSSimon Schubert enum language 8345796c8dcSSimon Schubert language_enum (char *str) 8355796c8dcSSimon Schubert { 8365796c8dcSSimon Schubert int i; 8375796c8dcSSimon Schubert 8385796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8395796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, str) == 0) 8405796c8dcSSimon Schubert return languages[i]->la_language; 8415796c8dcSSimon Schubert 8425796c8dcSSimon Schubert return language_unknown; 8435796c8dcSSimon Schubert } 8445796c8dcSSimon Schubert 8455796c8dcSSimon Schubert /* Return the language struct for a given language enum. */ 8465796c8dcSSimon Schubert 8475796c8dcSSimon Schubert const struct language_defn * 8485796c8dcSSimon Schubert language_def (enum language lang) 8495796c8dcSSimon Schubert { 8505796c8dcSSimon Schubert int i; 8515796c8dcSSimon Schubert 8525796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8535796c8dcSSimon Schubert { 8545796c8dcSSimon Schubert if (languages[i]->la_language == lang) 8555796c8dcSSimon Schubert { 8565796c8dcSSimon Schubert return languages[i]; 8575796c8dcSSimon Schubert } 8585796c8dcSSimon Schubert } 8595796c8dcSSimon Schubert return NULL; 8605796c8dcSSimon Schubert } 8615796c8dcSSimon Schubert 862c50c785cSJohn Marino /* Return the language as a string. */ 8635796c8dcSSimon Schubert char * 8645796c8dcSSimon Schubert language_str (enum language lang) 8655796c8dcSSimon Schubert { 8665796c8dcSSimon Schubert int i; 8675796c8dcSSimon Schubert 8685796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8695796c8dcSSimon Schubert { 8705796c8dcSSimon Schubert if (languages[i]->la_language == lang) 8715796c8dcSSimon Schubert { 8725796c8dcSSimon Schubert return languages[i]->la_name; 8735796c8dcSSimon Schubert } 8745796c8dcSSimon Schubert } 8755796c8dcSSimon Schubert return "Unknown"; 8765796c8dcSSimon Schubert } 8775796c8dcSSimon Schubert 8785796c8dcSSimon Schubert static void 8795796c8dcSSimon Schubert set_check (char *ignore, int from_tty) 8805796c8dcSSimon Schubert { 8815796c8dcSSimon Schubert printf_unfiltered ( 8825796c8dcSSimon Schubert "\"set check\" must be followed by the name of a check subcommand.\n"); 8835796c8dcSSimon Schubert help_list (setchecklist, "set check ", -1, gdb_stdout); 8845796c8dcSSimon Schubert } 8855796c8dcSSimon Schubert 8865796c8dcSSimon Schubert static void 8875796c8dcSSimon Schubert show_check (char *ignore, int from_tty) 8885796c8dcSSimon Schubert { 8895796c8dcSSimon Schubert cmd_show_list (showchecklist, from_tty, ""); 8905796c8dcSSimon Schubert } 8915796c8dcSSimon Schubert 8925796c8dcSSimon Schubert /* Add a language to the set of known languages. */ 8935796c8dcSSimon Schubert 8945796c8dcSSimon Schubert void 8955796c8dcSSimon Schubert add_language (const struct language_defn *lang) 8965796c8dcSSimon Schubert { 8975796c8dcSSimon Schubert /* For the "set language" command. */ 8985796c8dcSSimon Schubert static char **language_names = NULL; 8995796c8dcSSimon Schubert /* For the "help set language" command. */ 9005796c8dcSSimon Schubert char *language_set_doc = NULL; 9015796c8dcSSimon Schubert 9025796c8dcSSimon Schubert int i; 9035796c8dcSSimon Schubert struct ui_file *tmp_stream; 9045796c8dcSSimon Schubert 9055796c8dcSSimon Schubert if (lang->la_magic != LANG_MAGIC) 9065796c8dcSSimon Schubert { 907c50c785cSJohn Marino fprintf_unfiltered (gdb_stderr, 908c50c785cSJohn Marino "Magic number of %s language struct wrong\n", 9095796c8dcSSimon Schubert lang->la_name); 910c50c785cSJohn Marino internal_error (__FILE__, __LINE__, 911c50c785cSJohn Marino _("failed internal consistency check")); 9125796c8dcSSimon Schubert } 9135796c8dcSSimon Schubert 9145796c8dcSSimon Schubert if (!languages) 9155796c8dcSSimon Schubert { 9165796c8dcSSimon Schubert languages_allocsize = DEFAULT_ALLOCSIZE; 9175796c8dcSSimon Schubert languages = (const struct language_defn **) xmalloc 9185796c8dcSSimon Schubert (languages_allocsize * sizeof (*languages)); 9195796c8dcSSimon Schubert } 9205796c8dcSSimon Schubert if (languages_size >= languages_allocsize) 9215796c8dcSSimon Schubert { 9225796c8dcSSimon Schubert languages_allocsize *= 2; 9235796c8dcSSimon Schubert languages = (const struct language_defn **) xrealloc ((char *) languages, 9245796c8dcSSimon Schubert languages_allocsize * sizeof (*languages)); 9255796c8dcSSimon Schubert } 9265796c8dcSSimon Schubert languages[languages_size++] = lang; 9275796c8dcSSimon Schubert 9285796c8dcSSimon Schubert /* Build the language names array, to be used as enumeration in the 9295796c8dcSSimon Schubert set language" enum command. */ 9305796c8dcSSimon Schubert language_names = xrealloc (language_names, 9315796c8dcSSimon Schubert (languages_size + 1) * sizeof (const char *)); 9325796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i) 9335796c8dcSSimon Schubert language_names[i] = languages[i]->la_name; 9345796c8dcSSimon Schubert language_names[i] = NULL; 9355796c8dcSSimon Schubert 9365796c8dcSSimon Schubert /* Build the "help set language" docs. */ 9375796c8dcSSimon Schubert tmp_stream = mem_fileopen (); 9385796c8dcSSimon Schubert 939c50c785cSJohn Marino fprintf_unfiltered (tmp_stream, 940c50c785cSJohn Marino _("Set the current source language.\n" 941c50c785cSJohn Marino "The currently understood settings are:\n\nlocal or " 942c50c785cSJohn Marino "auto Automatic setting based on source file\n")); 9435796c8dcSSimon Schubert 9445796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i) 9455796c8dcSSimon Schubert { 9465796c8dcSSimon Schubert /* Already dealt with these above. */ 9475796c8dcSSimon Schubert if (languages[i]->la_language == language_unknown 9485796c8dcSSimon Schubert || languages[i]->la_language == language_auto) 9495796c8dcSSimon Schubert continue; 9505796c8dcSSimon Schubert 9515796c8dcSSimon Schubert /* FIXME: i18n: for now assume that the human-readable name 9525796c8dcSSimon Schubert is just a capitalization of the internal name. */ 9535796c8dcSSimon Schubert fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n", 9545796c8dcSSimon Schubert languages[i]->la_name, 9555796c8dcSSimon Schubert /* Capitalize first letter of language 9565796c8dcSSimon Schubert name. */ 9575796c8dcSSimon Schubert toupper (languages[i]->la_name[0]), 9585796c8dcSSimon Schubert languages[i]->la_name + 1); 9595796c8dcSSimon Schubert } 9605796c8dcSSimon Schubert 9615796c8dcSSimon Schubert language_set_doc = ui_file_xstrdup (tmp_stream, NULL); 9625796c8dcSSimon Schubert ui_file_delete (tmp_stream); 9635796c8dcSSimon Schubert 9645796c8dcSSimon Schubert add_setshow_enum_cmd ("language", class_support, 9655796c8dcSSimon Schubert (const char **) language_names, 9665796c8dcSSimon Schubert &language, 967c50c785cSJohn Marino language_set_doc, 968c50c785cSJohn Marino _("Show the current source language."), 969c50c785cSJohn Marino NULL, set_language_command, 9705796c8dcSSimon Schubert show_language_command, 9715796c8dcSSimon Schubert &setlist, &showlist); 9725796c8dcSSimon Schubert 9735796c8dcSSimon Schubert xfree (language_set_doc); 9745796c8dcSSimon Schubert } 9755796c8dcSSimon Schubert 9765796c8dcSSimon Schubert /* Iterate through all registered languages looking for and calling 9775796c8dcSSimon Schubert any non-NULL struct language_defn.skip_trampoline() functions. 9785796c8dcSSimon Schubert Return the result from the first that returns non-zero, or 0 if all 9795796c8dcSSimon Schubert `fail'. */ 9805796c8dcSSimon Schubert CORE_ADDR 9815796c8dcSSimon Schubert skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc) 9825796c8dcSSimon Schubert { 9835796c8dcSSimon Schubert int i; 9845796c8dcSSimon Schubert 9855796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 9865796c8dcSSimon Schubert { 9875796c8dcSSimon Schubert if (languages[i]->skip_trampoline) 9885796c8dcSSimon Schubert { 9895796c8dcSSimon Schubert CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc); 990cf7f2e2dSJohn Marino 9915796c8dcSSimon Schubert if (real_pc) 9925796c8dcSSimon Schubert return real_pc; 9935796c8dcSSimon Schubert } 9945796c8dcSSimon Schubert } 9955796c8dcSSimon Schubert 9965796c8dcSSimon Schubert return 0; 9975796c8dcSSimon Schubert } 9985796c8dcSSimon Schubert 9995796c8dcSSimon Schubert /* Return demangled language symbol, or NULL. 10005796c8dcSSimon Schubert FIXME: Options are only useful for certain languages and ignored 10015796c8dcSSimon Schubert by others, so it would be better to remove them here and have a 10025796c8dcSSimon Schubert more flexible demangler for the languages that need it. 10035796c8dcSSimon Schubert FIXME: Sometimes the demangler is invoked when we don't know the 10045796c8dcSSimon Schubert language, so we can't use this everywhere. */ 10055796c8dcSSimon Schubert char * 10065796c8dcSSimon Schubert language_demangle (const struct language_defn *current_language, 10075796c8dcSSimon Schubert const char *mangled, int options) 10085796c8dcSSimon Schubert { 10095796c8dcSSimon Schubert if (current_language != NULL && current_language->la_demangle) 10105796c8dcSSimon Schubert return current_language->la_demangle (mangled, options); 10115796c8dcSSimon Schubert return NULL; 10125796c8dcSSimon Schubert } 10135796c8dcSSimon Schubert 10145796c8dcSSimon Schubert /* Return class name from physname or NULL. */ 10155796c8dcSSimon Schubert char * 1016c50c785cSJohn Marino language_class_name_from_physname (const struct language_defn *lang, 10175796c8dcSSimon Schubert const char *physname) 10185796c8dcSSimon Schubert { 1019c50c785cSJohn Marino if (lang != NULL && lang->la_class_name_from_physname) 1020c50c785cSJohn Marino return lang->la_class_name_from_physname (physname); 10215796c8dcSSimon Schubert return NULL; 10225796c8dcSSimon Schubert } 10235796c8dcSSimon Schubert 10245796c8dcSSimon Schubert /* Return non-zero if TYPE should be passed (and returned) by 10255796c8dcSSimon Schubert reference at the language level. */ 10265796c8dcSSimon Schubert int 10275796c8dcSSimon Schubert language_pass_by_reference (struct type *type) 10285796c8dcSSimon Schubert { 10295796c8dcSSimon Schubert return current_language->la_pass_by_reference (type); 10305796c8dcSSimon Schubert } 10315796c8dcSSimon Schubert 10325796c8dcSSimon Schubert /* Return zero; by default, types are passed by value at the language 10335796c8dcSSimon Schubert level. The target ABI may pass or return some structs by reference 10345796c8dcSSimon Schubert independent of this. */ 10355796c8dcSSimon Schubert int 10365796c8dcSSimon Schubert default_pass_by_reference (struct type *type) 10375796c8dcSSimon Schubert { 10385796c8dcSSimon Schubert return 0; 10395796c8dcSSimon Schubert } 10405796c8dcSSimon Schubert 10415796c8dcSSimon Schubert /* Return the default string containing the list of characters 10425796c8dcSSimon Schubert delimiting words. This is a reasonable default value that 10435796c8dcSSimon Schubert most languages should be able to use. */ 10445796c8dcSSimon Schubert 10455796c8dcSSimon Schubert char * 10465796c8dcSSimon Schubert default_word_break_characters (void) 10475796c8dcSSimon Schubert { 10485796c8dcSSimon Schubert return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; 10495796c8dcSSimon Schubert } 10505796c8dcSSimon Schubert 10515796c8dcSSimon Schubert /* Print the index of array elements using the C99 syntax. */ 10525796c8dcSSimon Schubert 10535796c8dcSSimon Schubert void 10545796c8dcSSimon Schubert default_print_array_index (struct value *index_value, struct ui_file *stream, 10555796c8dcSSimon Schubert const struct value_print_options *options) 10565796c8dcSSimon Schubert { 10575796c8dcSSimon Schubert fprintf_filtered (stream, "["); 10585796c8dcSSimon Schubert LA_VALUE_PRINT (index_value, stream, options); 10595796c8dcSSimon Schubert fprintf_filtered (stream, "] = "); 10605796c8dcSSimon Schubert } 10615796c8dcSSimon Schubert 10625796c8dcSSimon Schubert void 10635796c8dcSSimon Schubert default_get_string (struct value *value, gdb_byte **buffer, int *length, 1064cf7f2e2dSJohn Marino struct type **char_type, const char **charset) 10655796c8dcSSimon Schubert { 10665796c8dcSSimon Schubert error (_("Getting a string is unsupported in this language.")); 10675796c8dcSSimon Schubert } 10685796c8dcSSimon Schubert 10695796c8dcSSimon Schubert /* Define the language that is no language. */ 10705796c8dcSSimon Schubert 10715796c8dcSSimon Schubert static int 10725796c8dcSSimon Schubert unk_lang_parser (void) 10735796c8dcSSimon Schubert { 10745796c8dcSSimon Schubert return 1; 10755796c8dcSSimon Schubert } 10765796c8dcSSimon Schubert 10775796c8dcSSimon Schubert static void 10785796c8dcSSimon Schubert unk_lang_error (char *msg) 10795796c8dcSSimon Schubert { 10805796c8dcSSimon Schubert error (_("Attempted to parse an expression with unknown language")); 10815796c8dcSSimon Schubert } 10825796c8dcSSimon Schubert 10835796c8dcSSimon Schubert static void 10845796c8dcSSimon Schubert unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, 10855796c8dcSSimon Schubert int quoter) 10865796c8dcSSimon Schubert { 1087c50c785cSJohn Marino error (_("internal error - unimplemented " 1088c50c785cSJohn Marino "function unk_lang_emit_char called.")); 10895796c8dcSSimon Schubert } 10905796c8dcSSimon Schubert 10915796c8dcSSimon Schubert static void 10925796c8dcSSimon Schubert unk_lang_printchar (int c, struct type *type, struct ui_file *stream) 10935796c8dcSSimon Schubert { 1094c50c785cSJohn Marino error (_("internal error - unimplemented " 1095c50c785cSJohn Marino "function unk_lang_printchar called.")); 10965796c8dcSSimon Schubert } 10975796c8dcSSimon Schubert 10985796c8dcSSimon Schubert static void 10995796c8dcSSimon Schubert unk_lang_printstr (struct ui_file *stream, struct type *type, 11005796c8dcSSimon Schubert const gdb_byte *string, unsigned int length, 1101cf7f2e2dSJohn Marino const char *encoding, int force_ellipses, 11025796c8dcSSimon Schubert const struct value_print_options *options) 11035796c8dcSSimon Schubert { 1104c50c785cSJohn Marino error (_("internal error - unimplemented " 1105c50c785cSJohn Marino "function unk_lang_printstr called.")); 11065796c8dcSSimon Schubert } 11075796c8dcSSimon Schubert 11085796c8dcSSimon Schubert static void 1109cf7f2e2dSJohn Marino unk_lang_print_type (struct type *type, const char *varstring, 1110cf7f2e2dSJohn Marino struct ui_file *stream, int show, int level) 11115796c8dcSSimon Schubert { 1112c50c785cSJohn Marino error (_("internal error - unimplemented " 1113c50c785cSJohn Marino "function unk_lang_print_type called.")); 11145796c8dcSSimon Schubert } 11155796c8dcSSimon Schubert 11165796c8dcSSimon Schubert static int 11175796c8dcSSimon Schubert unk_lang_val_print (struct type *type, const gdb_byte *valaddr, 11185796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address, 11195796c8dcSSimon Schubert struct ui_file *stream, int recurse, 1120cf7f2e2dSJohn Marino const struct value *val, 11215796c8dcSSimon Schubert const struct value_print_options *options) 11225796c8dcSSimon Schubert { 1123c50c785cSJohn Marino error (_("internal error - unimplemented " 1124c50c785cSJohn Marino "function unk_lang_val_print called.")); 11255796c8dcSSimon Schubert } 11265796c8dcSSimon Schubert 11275796c8dcSSimon Schubert static int 11285796c8dcSSimon Schubert unk_lang_value_print (struct value *val, struct ui_file *stream, 11295796c8dcSSimon Schubert const struct value_print_options *options) 11305796c8dcSSimon Schubert { 1131c50c785cSJohn Marino error (_("internal error - unimplemented " 1132c50c785cSJohn Marino "function unk_lang_value_print called.")); 11335796c8dcSSimon Schubert } 11345796c8dcSSimon Schubert 11355796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) 11365796c8dcSSimon Schubert { 11375796c8dcSSimon Schubert return 0; 11385796c8dcSSimon Schubert } 11395796c8dcSSimon Schubert 11405796c8dcSSimon Schubert /* Unknown languages just use the cplus demangler. */ 11415796c8dcSSimon Schubert static char *unk_lang_demangle (const char *mangled, int options) 11425796c8dcSSimon Schubert { 11435796c8dcSSimon Schubert return cplus_demangle (mangled, options); 11445796c8dcSSimon Schubert } 11455796c8dcSSimon Schubert 11465796c8dcSSimon Schubert static char *unk_lang_class_name (const char *mangled) 11475796c8dcSSimon Schubert { 11485796c8dcSSimon Schubert return NULL; 11495796c8dcSSimon Schubert } 11505796c8dcSSimon Schubert 11515796c8dcSSimon Schubert static const struct op_print unk_op_print_tab[] = 11525796c8dcSSimon Schubert { 11535796c8dcSSimon Schubert {NULL, OP_NULL, PREC_NULL, 0} 11545796c8dcSSimon Schubert }; 11555796c8dcSSimon Schubert 11565796c8dcSSimon Schubert static void 11575796c8dcSSimon Schubert unknown_language_arch_info (struct gdbarch *gdbarch, 11585796c8dcSSimon Schubert struct language_arch_info *lai) 11595796c8dcSSimon Schubert { 11605796c8dcSSimon Schubert lai->string_char_type = builtin_type (gdbarch)->builtin_char; 11615796c8dcSSimon Schubert lai->bool_type_default = builtin_type (gdbarch)->builtin_int; 11625796c8dcSSimon Schubert lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, 11635796c8dcSSimon Schubert struct type *); 11645796c8dcSSimon Schubert } 11655796c8dcSSimon Schubert 11665796c8dcSSimon Schubert const struct language_defn unknown_language_defn = 11675796c8dcSSimon Schubert { 11685796c8dcSSimon Schubert "unknown", 11695796c8dcSSimon Schubert language_unknown, 11705796c8dcSSimon Schubert range_check_off, 11715796c8dcSSimon Schubert type_check_off, 11725796c8dcSSimon Schubert case_sensitive_on, 11735796c8dcSSimon Schubert array_row_major, 11745796c8dcSSimon Schubert macro_expansion_no, 11755796c8dcSSimon Schubert &exp_descriptor_standard, 11765796c8dcSSimon Schubert unk_lang_parser, 11775796c8dcSSimon Schubert unk_lang_error, 11785796c8dcSSimon Schubert null_post_parser, 11795796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 11805796c8dcSSimon Schubert unk_lang_printstr, 11815796c8dcSSimon Schubert unk_lang_emit_char, 11825796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 11835796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 11845796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 11855796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 11865796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 11875796c8dcSSimon Schubert "this", /* name_of_this */ 11885796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 11895796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 11905796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1191c50c785cSJohn Marino unk_lang_class_name, /* Language specific 1192c50c785cSJohn Marino class_name_from_physname */ 11935796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 11945796c8dcSSimon Schubert 1, /* c-style arrays */ 11955796c8dcSSimon Schubert 0, /* String lower bound */ 11965796c8dcSSimon Schubert default_word_break_characters, 11975796c8dcSSimon Schubert default_make_symbol_completion_list, 11985796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 11995796c8dcSSimon Schubert default_print_array_index, 12005796c8dcSSimon Schubert default_pass_by_reference, 12015796c8dcSSimon Schubert default_get_string, 1202*a45ae5f8SJohn Marino strcmp_iw_ordered, 1203*a45ae5f8SJohn Marino iterate_over_symbols, 12045796c8dcSSimon Schubert LANG_MAGIC 12055796c8dcSSimon Schubert }; 12065796c8dcSSimon Schubert 1207c50c785cSJohn Marino /* These two structs define fake entries for the "local" and "auto" 1208c50c785cSJohn Marino options. */ 12095796c8dcSSimon Schubert const struct language_defn auto_language_defn = 12105796c8dcSSimon Schubert { 12115796c8dcSSimon Schubert "auto", 12125796c8dcSSimon Schubert language_auto, 12135796c8dcSSimon Schubert range_check_off, 12145796c8dcSSimon Schubert type_check_off, 12155796c8dcSSimon Schubert case_sensitive_on, 12165796c8dcSSimon Schubert array_row_major, 12175796c8dcSSimon Schubert macro_expansion_no, 12185796c8dcSSimon Schubert &exp_descriptor_standard, 12195796c8dcSSimon Schubert unk_lang_parser, 12205796c8dcSSimon Schubert unk_lang_error, 12215796c8dcSSimon Schubert null_post_parser, 12225796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 12235796c8dcSSimon Schubert unk_lang_printstr, 12245796c8dcSSimon Schubert unk_lang_emit_char, 12255796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 12265796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 12275796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 12285796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 12295796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 12305796c8dcSSimon Schubert "this", /* name_of_this */ 12315796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 12325796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 12335796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1234c50c785cSJohn Marino unk_lang_class_name, /* Language specific 1235c50c785cSJohn Marino class_name_from_physname */ 12365796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 12375796c8dcSSimon Schubert 1, /* c-style arrays */ 12385796c8dcSSimon Schubert 0, /* String lower bound */ 12395796c8dcSSimon Schubert default_word_break_characters, 12405796c8dcSSimon Schubert default_make_symbol_completion_list, 12415796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 12425796c8dcSSimon Schubert default_print_array_index, 12435796c8dcSSimon Schubert default_pass_by_reference, 12445796c8dcSSimon Schubert default_get_string, 1245*a45ae5f8SJohn Marino strcmp_iw_ordered, 1246*a45ae5f8SJohn Marino iterate_over_symbols, 12475796c8dcSSimon Schubert LANG_MAGIC 12485796c8dcSSimon Schubert }; 12495796c8dcSSimon Schubert 12505796c8dcSSimon Schubert const struct language_defn local_language_defn = 12515796c8dcSSimon Schubert { 12525796c8dcSSimon Schubert "local", 12535796c8dcSSimon Schubert language_auto, 12545796c8dcSSimon Schubert range_check_off, 12555796c8dcSSimon Schubert type_check_off, 12565796c8dcSSimon Schubert case_sensitive_on, 12575796c8dcSSimon Schubert array_row_major, 12585796c8dcSSimon Schubert macro_expansion_no, 12595796c8dcSSimon Schubert &exp_descriptor_standard, 12605796c8dcSSimon Schubert unk_lang_parser, 12615796c8dcSSimon Schubert unk_lang_error, 12625796c8dcSSimon Schubert null_post_parser, 12635796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 12645796c8dcSSimon Schubert unk_lang_printstr, 12655796c8dcSSimon Schubert unk_lang_emit_char, 12665796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 12675796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 12685796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 12695796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 12705796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 12715796c8dcSSimon Schubert "this", /* name_of_this */ 12725796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 12735796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 12745796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1275c50c785cSJohn Marino unk_lang_class_name, /* Language specific 1276c50c785cSJohn Marino class_name_from_physname */ 12775796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 12785796c8dcSSimon Schubert 1, /* c-style arrays */ 12795796c8dcSSimon Schubert 0, /* String lower bound */ 12805796c8dcSSimon Schubert default_word_break_characters, 12815796c8dcSSimon Schubert default_make_symbol_completion_list, 12825796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 12835796c8dcSSimon Schubert default_print_array_index, 12845796c8dcSSimon Schubert default_pass_by_reference, 12855796c8dcSSimon Schubert default_get_string, 1286*a45ae5f8SJohn Marino strcmp_iw_ordered, 1287*a45ae5f8SJohn Marino iterate_over_symbols, 12885796c8dcSSimon Schubert LANG_MAGIC 12895796c8dcSSimon Schubert }; 12905796c8dcSSimon Schubert 12915796c8dcSSimon Schubert /* Per-architecture language information. */ 12925796c8dcSSimon Schubert 12935796c8dcSSimon Schubert static struct gdbarch_data *language_gdbarch_data; 12945796c8dcSSimon Schubert 12955796c8dcSSimon Schubert struct language_gdbarch 12965796c8dcSSimon Schubert { 12975796c8dcSSimon Schubert /* A vector of per-language per-architecture info. Indexed by "enum 12985796c8dcSSimon Schubert language". */ 12995796c8dcSSimon Schubert struct language_arch_info arch_info[nr_languages]; 13005796c8dcSSimon Schubert }; 13015796c8dcSSimon Schubert 13025796c8dcSSimon Schubert static void * 13035796c8dcSSimon Schubert language_gdbarch_post_init (struct gdbarch *gdbarch) 13045796c8dcSSimon Schubert { 13055796c8dcSSimon Schubert struct language_gdbarch *l; 13065796c8dcSSimon Schubert int i; 13075796c8dcSSimon Schubert 13085796c8dcSSimon Schubert l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); 13095796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 13105796c8dcSSimon Schubert { 13115796c8dcSSimon Schubert if (languages[i] != NULL 13125796c8dcSSimon Schubert && languages[i]->la_language_arch_info != NULL) 13135796c8dcSSimon Schubert languages[i]->la_language_arch_info 13145796c8dcSSimon Schubert (gdbarch, l->arch_info + languages[i]->la_language); 13155796c8dcSSimon Schubert } 13165796c8dcSSimon Schubert return l; 13175796c8dcSSimon Schubert } 13185796c8dcSSimon Schubert 13195796c8dcSSimon Schubert struct type * 13205796c8dcSSimon Schubert language_string_char_type (const struct language_defn *la, 13215796c8dcSSimon Schubert struct gdbarch *gdbarch) 13225796c8dcSSimon Schubert { 13235796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13245796c8dcSSimon Schubert language_gdbarch_data); 1325cf7f2e2dSJohn Marino 13265796c8dcSSimon Schubert return ld->arch_info[la->la_language].string_char_type; 13275796c8dcSSimon Schubert } 13285796c8dcSSimon Schubert 13295796c8dcSSimon Schubert struct type * 13305796c8dcSSimon Schubert language_bool_type (const struct language_defn *la, 13315796c8dcSSimon Schubert struct gdbarch *gdbarch) 13325796c8dcSSimon Schubert { 13335796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13345796c8dcSSimon Schubert language_gdbarch_data); 13355796c8dcSSimon Schubert 13365796c8dcSSimon Schubert if (ld->arch_info[la->la_language].bool_type_symbol) 13375796c8dcSSimon Schubert { 13385796c8dcSSimon Schubert struct symbol *sym; 1339cf7f2e2dSJohn Marino 13405796c8dcSSimon Schubert sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, 13415796c8dcSSimon Schubert NULL, VAR_DOMAIN, NULL); 13425796c8dcSSimon Schubert if (sym) 13435796c8dcSSimon Schubert { 13445796c8dcSSimon Schubert struct type *type = SYMBOL_TYPE (sym); 1345cf7f2e2dSJohn Marino 13465796c8dcSSimon Schubert if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) 13475796c8dcSSimon Schubert return type; 13485796c8dcSSimon Schubert } 13495796c8dcSSimon Schubert } 13505796c8dcSSimon Schubert 13515796c8dcSSimon Schubert return ld->arch_info[la->la_language].bool_type_default; 13525796c8dcSSimon Schubert } 13535796c8dcSSimon Schubert 13545796c8dcSSimon Schubert struct type * 13555796c8dcSSimon Schubert language_lookup_primitive_type_by_name (const struct language_defn *la, 13565796c8dcSSimon Schubert struct gdbarch *gdbarch, 13575796c8dcSSimon Schubert const char *name) 13585796c8dcSSimon Schubert { 13595796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13605796c8dcSSimon Schubert language_gdbarch_data); 13615796c8dcSSimon Schubert struct type *const *p; 1362cf7f2e2dSJohn Marino 13635796c8dcSSimon Schubert for (p = ld->arch_info[la->la_language].primitive_type_vector; 13645796c8dcSSimon Schubert (*p) != NULL; 13655796c8dcSSimon Schubert p++) 13665796c8dcSSimon Schubert { 13675796c8dcSSimon Schubert if (strcmp (TYPE_NAME (*p), name) == 0) 13685796c8dcSSimon Schubert return (*p); 13695796c8dcSSimon Schubert } 13705796c8dcSSimon Schubert return (NULL); 13715796c8dcSSimon Schubert } 13725796c8dcSSimon Schubert 1373c50c785cSJohn Marino /* Initialize the language routines. */ 13745796c8dcSSimon Schubert 13755796c8dcSSimon Schubert void 13765796c8dcSSimon Schubert _initialize_language (void) 13775796c8dcSSimon Schubert { 13785796c8dcSSimon Schubert static const char *type_or_range_names[] 13795796c8dcSSimon Schubert = { "on", "off", "warn", "auto", NULL }; 13805796c8dcSSimon Schubert 13815796c8dcSSimon Schubert static const char *case_sensitive_names[] 13825796c8dcSSimon Schubert = { "on", "off", "auto", NULL }; 13835796c8dcSSimon Schubert 13845796c8dcSSimon Schubert language_gdbarch_data 13855796c8dcSSimon Schubert = gdbarch_data_register_post_init (language_gdbarch_post_init); 13865796c8dcSSimon Schubert 1387c50c785cSJohn Marino /* GDB commands for language specific stuff. */ 13885796c8dcSSimon Schubert 13895796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, set_check, 13905796c8dcSSimon Schubert _("Set the status of the type/range checker."), 13915796c8dcSSimon Schubert &setchecklist, "set check ", 0, &setlist); 13925796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &setlist); 13935796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &setlist); 13945796c8dcSSimon Schubert 13955796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, show_check, 13965796c8dcSSimon Schubert _("Show the status of the type/range checker."), 13975796c8dcSSimon Schubert &showchecklist, "show check ", 0, &showlist); 13985796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &showlist); 13995796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &showlist); 14005796c8dcSSimon Schubert 1401c50c785cSJohn Marino add_setshow_enum_cmd ("type", class_support, type_or_range_names, &type, 1402c50c785cSJohn Marino _("Set type checking. (on/warn/off/auto)"), 1403c50c785cSJohn Marino _("Show type checking. (on/warn/off/auto)"), 1404c50c785cSJohn Marino NULL, set_type_command, 14055796c8dcSSimon Schubert show_type_command, 14065796c8dcSSimon Schubert &setchecklist, &showchecklist); 14075796c8dcSSimon Schubert 14085796c8dcSSimon Schubert add_setshow_enum_cmd ("range", class_support, type_or_range_names, 1409c50c785cSJohn Marino &range, 1410c50c785cSJohn Marino _("Set range checking. (on/warn/off/auto)"), 1411c50c785cSJohn Marino _("Show range checking. (on/warn/off/auto)"), 1412c50c785cSJohn Marino NULL, set_range_command, 14135796c8dcSSimon Schubert show_range_command, 14145796c8dcSSimon Schubert &setchecklist, &showchecklist); 14155796c8dcSSimon Schubert 14165796c8dcSSimon Schubert add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names, 14175796c8dcSSimon Schubert &case_sensitive, _("\ 14185796c8dcSSimon Schubert Set case sensitivity in name search. (on/off/auto)"), _("\ 14195796c8dcSSimon Schubert Show case sensitivity in name search. (on/off/auto)"), _("\ 14205796c8dcSSimon Schubert For Fortran the default is off; for other languages the default is on."), 14215796c8dcSSimon Schubert set_case_command, 14225796c8dcSSimon Schubert show_case_command, 14235796c8dcSSimon Schubert &setlist, &showlist); 14245796c8dcSSimon Schubert 14255796c8dcSSimon Schubert add_language (&auto_language_defn); 14265796c8dcSSimon Schubert add_language (&local_language_defn); 14275796c8dcSSimon Schubert add_language (&unknown_language_defn); 14285796c8dcSSimon Schubert 14295796c8dcSSimon Schubert language = xstrdup ("auto"); 14305796c8dcSSimon Schubert type = xstrdup ("auto"); 14315796c8dcSSimon Schubert range = xstrdup ("auto"); 14325796c8dcSSimon Schubert case_sensitive = xstrdup ("auto"); 14335796c8dcSSimon Schubert 1434c50c785cSJohn Marino /* Have the above take effect. */ 14355796c8dcSSimon Schubert set_language (language_auto); 14365796c8dcSSimon Schubert } 1437