15796c8dcSSimon Schubert /* Multiple source language support for GDB. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 4*cf7f2e2dSJohn Marino 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 5*cf7f2e2dSJohn Marino Free Software Foundation, Inc. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert Contributed by the Department of Computer Science at the State University 85796c8dcSSimon Schubert of New York at Buffalo. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This file is part of GDB. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 135796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 145796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 155796c8dcSSimon Schubert (at your option) any later version. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 185796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 195796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 205796c8dcSSimon Schubert GNU General Public License for more details. 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 235796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert /* This file contains functions that return things that are specific 265796c8dcSSimon Schubert to languages. Each function should examine current_language if necessary, 275796c8dcSSimon Schubert and return the appropriate result. */ 285796c8dcSSimon Schubert 295796c8dcSSimon Schubert /* FIXME: Most of these would be better organized as macros which 305796c8dcSSimon Schubert return data out of a "language-specific" struct pointer that is set 315796c8dcSSimon Schubert whenever the working language changes. That would be a lot faster. */ 325796c8dcSSimon Schubert 335796c8dcSSimon Schubert #include "defs.h" 345796c8dcSSimon Schubert #include <ctype.h> 355796c8dcSSimon Schubert #include "gdb_string.h" 365796c8dcSSimon Schubert 375796c8dcSSimon Schubert #include "symtab.h" 385796c8dcSSimon Schubert #include "gdbtypes.h" 395796c8dcSSimon Schubert #include "value.h" 405796c8dcSSimon Schubert #include "gdbcmd.h" 415796c8dcSSimon Schubert #include "expression.h" 425796c8dcSSimon Schubert #include "language.h" 435796c8dcSSimon Schubert #include "target.h" 445796c8dcSSimon Schubert #include "parser-defs.h" 455796c8dcSSimon Schubert #include "jv-lang.h" 465796c8dcSSimon Schubert #include "demangle.h" 475796c8dcSSimon Schubert #include "symfile.h" 485796c8dcSSimon Schubert 495796c8dcSSimon Schubert extern void _initialize_language (void); 505796c8dcSSimon Schubert 515796c8dcSSimon Schubert static void unk_lang_error (char *); 525796c8dcSSimon Schubert 535796c8dcSSimon Schubert static int unk_lang_parser (void); 545796c8dcSSimon Schubert 555796c8dcSSimon Schubert static void show_check (char *, int); 565796c8dcSSimon Schubert 575796c8dcSSimon Schubert static void set_check (char *, int); 585796c8dcSSimon Schubert 595796c8dcSSimon Schubert static void set_type_range_case (void); 605796c8dcSSimon Schubert 615796c8dcSSimon Schubert static void unk_lang_emit_char (int c, struct type *type, 625796c8dcSSimon Schubert struct ui_file *stream, int quoter); 635796c8dcSSimon Schubert 645796c8dcSSimon Schubert static void unk_lang_printchar (int c, struct type *type, 655796c8dcSSimon Schubert struct ui_file *stream); 665796c8dcSSimon Schubert 67*cf7f2e2dSJohn Marino static void unk_lang_print_type (struct type *, const char *, struct ui_file *, 685796c8dcSSimon Schubert int, int); 695796c8dcSSimon Schubert 705796c8dcSSimon Schubert static int unk_lang_value_print (struct value *, struct ui_file *, 715796c8dcSSimon Schubert const struct value_print_options *); 725796c8dcSSimon Schubert 735796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc); 745796c8dcSSimon Schubert 755796c8dcSSimon Schubert /* Forward declaration */ 765796c8dcSSimon Schubert extern const struct language_defn unknown_language_defn; 775796c8dcSSimon Schubert 785796c8dcSSimon Schubert /* The current (default at startup) state of type and range checking. 795796c8dcSSimon Schubert (If the modes are set to "auto", though, these are changed based 805796c8dcSSimon Schubert on the default language at startup, and then again based on the 815796c8dcSSimon Schubert language of the first source file. */ 825796c8dcSSimon Schubert 835796c8dcSSimon Schubert enum range_mode range_mode = range_mode_auto; 845796c8dcSSimon Schubert enum range_check range_check = range_check_off; 855796c8dcSSimon Schubert enum type_mode type_mode = type_mode_auto; 865796c8dcSSimon Schubert enum type_check type_check = type_check_off; 875796c8dcSSimon Schubert enum case_mode case_mode = case_mode_auto; 885796c8dcSSimon Schubert enum case_sensitivity case_sensitivity = case_sensitive_on; 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert /* The current language and language_mode (see language.h) */ 915796c8dcSSimon Schubert 925796c8dcSSimon Schubert const struct language_defn *current_language = &unknown_language_defn; 935796c8dcSSimon Schubert enum language_mode language_mode = language_mode_auto; 945796c8dcSSimon Schubert 955796c8dcSSimon Schubert /* The language that the user expects to be typing in (the language 965796c8dcSSimon Schubert of main(), or the last language we notified them about, or C). */ 975796c8dcSSimon Schubert 985796c8dcSSimon Schubert const struct language_defn *expected_language; 995796c8dcSSimon Schubert 1005796c8dcSSimon Schubert /* The list of supported languages. The list itself is malloc'd. */ 1015796c8dcSSimon Schubert 1025796c8dcSSimon Schubert static const struct language_defn **languages; 1035796c8dcSSimon Schubert static unsigned languages_size; 1045796c8dcSSimon Schubert static unsigned languages_allocsize; 1055796c8dcSSimon Schubert #define DEFAULT_ALLOCSIZE 4 1065796c8dcSSimon Schubert 1075796c8dcSSimon Schubert /* The current values of the "set language/type/range" enum 1085796c8dcSSimon Schubert commands. */ 1095796c8dcSSimon Schubert static const char *language; 1105796c8dcSSimon Schubert static const char *type; 1115796c8dcSSimon Schubert static const char *range; 1125796c8dcSSimon Schubert static const char *case_sensitive; 1135796c8dcSSimon Schubert 1145796c8dcSSimon Schubert /* Warning issued when current_language and the language of the current 1155796c8dcSSimon Schubert frame do not match. */ 1165796c8dcSSimon Schubert char lang_frame_mismatch_warn[] = 1175796c8dcSSimon Schubert "Warning: the current language does not match this frame."; 1185796c8dcSSimon Schubert 1195796c8dcSSimon Schubert /* This page contains the functions corresponding to GDB commands 1205796c8dcSSimon Schubert and their helpers. */ 1215796c8dcSSimon Schubert 1225796c8dcSSimon Schubert /* Show command. Display a warning if the language set 1235796c8dcSSimon Schubert does not match the frame. */ 1245796c8dcSSimon Schubert static void 1255796c8dcSSimon Schubert show_language_command (struct ui_file *file, int from_tty, 1265796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1275796c8dcSSimon Schubert { 1285796c8dcSSimon Schubert enum language flang; /* The language of the current frame */ 1295796c8dcSSimon Schubert 1305796c8dcSSimon Schubert if (language_mode == language_mode_auto) 1315796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 1325796c8dcSSimon Schubert _("The current source language is " 1335796c8dcSSimon Schubert "\"auto; currently %s\".\n"), 1345796c8dcSSimon Schubert current_language->la_name); 1355796c8dcSSimon Schubert else 1365796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("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 3655796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Case sensitivity in name search is \"%s\".\n"), 3665796c8dcSSimon Schubert value); 3675796c8dcSSimon Schubert 3685796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity) 3695796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match " 3705796c8dcSSimon Schubert "the language.\n")); 3715796c8dcSSimon Schubert } 3725796c8dcSSimon Schubert 3735796c8dcSSimon Schubert /* Set command. Change the setting for case sensitivity. */ 3745796c8dcSSimon Schubert 3755796c8dcSSimon Schubert static void 3765796c8dcSSimon Schubert set_case_command (char *ignore, int from_tty, struct cmd_list_element *c) 3775796c8dcSSimon Schubert { 3785796c8dcSSimon Schubert if (strcmp (case_sensitive, "on") == 0) 3795796c8dcSSimon Schubert { 3805796c8dcSSimon Schubert case_sensitivity = case_sensitive_on; 3815796c8dcSSimon Schubert case_mode = case_mode_manual; 3825796c8dcSSimon Schubert } 3835796c8dcSSimon Schubert else if (strcmp (case_sensitive, "off") == 0) 3845796c8dcSSimon Schubert { 3855796c8dcSSimon Schubert case_sensitivity = case_sensitive_off; 3865796c8dcSSimon Schubert case_mode = case_mode_manual; 3875796c8dcSSimon Schubert } 3885796c8dcSSimon Schubert else if (strcmp (case_sensitive, "auto") == 0) 3895796c8dcSSimon Schubert { 3905796c8dcSSimon Schubert case_mode = case_mode_auto; 3915796c8dcSSimon Schubert set_type_range_case (); 3925796c8dcSSimon Schubert return; 3935796c8dcSSimon Schubert } 3945796c8dcSSimon Schubert else 3955796c8dcSSimon Schubert { 3965796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3975796c8dcSSimon Schubert "Unrecognized case-sensitive setting: \"%s\"", 3985796c8dcSSimon Schubert case_sensitive); 3995796c8dcSSimon Schubert } 4005796c8dcSSimon Schubert 4015796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity) 4025796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match " 4035796c8dcSSimon Schubert "the language.\n")); 4045796c8dcSSimon Schubert } 4055796c8dcSSimon Schubert 4065796c8dcSSimon Schubert /* Set the status of range and type checking and case sensitivity based on 4075796c8dcSSimon Schubert the current modes and the current language. 4085796c8dcSSimon Schubert If SHOW is non-zero, then print out the current language, 4095796c8dcSSimon Schubert type and range checking status. */ 4105796c8dcSSimon Schubert static void 4115796c8dcSSimon Schubert set_type_range_case (void) 4125796c8dcSSimon Schubert { 4135796c8dcSSimon Schubert if (range_mode == range_mode_auto) 4145796c8dcSSimon Schubert range_check = current_language->la_range_check; 4155796c8dcSSimon Schubert 4165796c8dcSSimon Schubert if (type_mode == type_mode_auto) 4175796c8dcSSimon Schubert type_check = current_language->la_type_check; 4185796c8dcSSimon Schubert 4195796c8dcSSimon Schubert if (case_mode == case_mode_auto) 4205796c8dcSSimon Schubert case_sensitivity = current_language->la_case_sensitivity; 4215796c8dcSSimon Schubert } 4225796c8dcSSimon Schubert 4235796c8dcSSimon Schubert /* Set current language to (enum language) LANG. Returns previous language. */ 4245796c8dcSSimon Schubert 4255796c8dcSSimon Schubert enum language 4265796c8dcSSimon Schubert set_language (enum language lang) 4275796c8dcSSimon Schubert { 4285796c8dcSSimon Schubert int i; 4295796c8dcSSimon Schubert enum language prev_language; 4305796c8dcSSimon Schubert 4315796c8dcSSimon Schubert prev_language = current_language->la_language; 4325796c8dcSSimon Schubert 4335796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 4345796c8dcSSimon Schubert { 4355796c8dcSSimon Schubert if (languages[i]->la_language == lang) 4365796c8dcSSimon Schubert { 4375796c8dcSSimon Schubert current_language = languages[i]; 4385796c8dcSSimon Schubert set_type_range_case (); 4395796c8dcSSimon Schubert break; 4405796c8dcSSimon Schubert } 4415796c8dcSSimon Schubert } 4425796c8dcSSimon Schubert 4435796c8dcSSimon Schubert return prev_language; 4445796c8dcSSimon Schubert } 4455796c8dcSSimon Schubert 4465796c8dcSSimon Schubert 4475796c8dcSSimon Schubert /* Print out the current language settings: language, range and 4485796c8dcSSimon Schubert type checking. If QUIETLY, print only what has changed. */ 4495796c8dcSSimon Schubert 4505796c8dcSSimon Schubert void 4515796c8dcSSimon Schubert language_info (int quietly) 4525796c8dcSSimon Schubert { 4535796c8dcSSimon Schubert if (quietly && expected_language == current_language) 4545796c8dcSSimon Schubert return; 4555796c8dcSSimon Schubert 4565796c8dcSSimon Schubert expected_language = current_language; 4575796c8dcSSimon Schubert printf_unfiltered (_("Current language: %s\n"), language); 4585796c8dcSSimon Schubert show_language_command (NULL, 1, NULL, NULL); 4595796c8dcSSimon Schubert 4605796c8dcSSimon Schubert if (!quietly) 4615796c8dcSSimon Schubert { 4625796c8dcSSimon Schubert printf_unfiltered (_("Type checking: %s\n"), type); 4635796c8dcSSimon Schubert show_type_command (NULL, 1, NULL, NULL); 4645796c8dcSSimon Schubert printf_unfiltered (_("Range checking: %s\n"), range); 4655796c8dcSSimon Schubert show_range_command (NULL, 1, NULL, NULL); 4665796c8dcSSimon Schubert printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive); 4675796c8dcSSimon Schubert show_case_command (NULL, 1, NULL, NULL); 4685796c8dcSSimon Schubert } 4695796c8dcSSimon Schubert } 4705796c8dcSSimon Schubert 4715796c8dcSSimon Schubert /* Return the result of a binary operation. */ 4725796c8dcSSimon Schubert 4735796c8dcSSimon Schubert #if 0 /* Currently unused */ 4745796c8dcSSimon Schubert 4755796c8dcSSimon Schubert struct type * 4765796c8dcSSimon Schubert binop_result_type (struct value *v1, struct value *v2) 4775796c8dcSSimon Schubert { 4785796c8dcSSimon Schubert int size, uns; 4795796c8dcSSimon Schubert struct type *t1 = check_typedef (VALUE_TYPE (v1)); 4805796c8dcSSimon Schubert struct type *t2 = check_typedef (VALUE_TYPE (v2)); 4815796c8dcSSimon Schubert 4825796c8dcSSimon Schubert int l1 = TYPE_LENGTH (t1); 4835796c8dcSSimon Schubert int l2 = TYPE_LENGTH (t2); 4845796c8dcSSimon Schubert 4855796c8dcSSimon Schubert switch (current_language->la_language) 4865796c8dcSSimon Schubert { 4875796c8dcSSimon Schubert case language_c: 4885796c8dcSSimon Schubert case language_cplus: 489*cf7f2e2dSJohn Marino case language_d: 4905796c8dcSSimon Schubert case language_objc: 4915796c8dcSSimon Schubert if (TYPE_CODE (t1) == TYPE_CODE_FLT) 4925796c8dcSSimon Schubert return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ? 4935796c8dcSSimon Schubert VALUE_TYPE (v2) : VALUE_TYPE (v1); 4945796c8dcSSimon Schubert else if (TYPE_CODE (t2) == TYPE_CODE_FLT) 4955796c8dcSSimon Schubert return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ? 4965796c8dcSSimon Schubert VALUE_TYPE (v1) : VALUE_TYPE (v2); 4975796c8dcSSimon Schubert else if (TYPE_UNSIGNED (t1) && l1 > l2) 4985796c8dcSSimon Schubert return VALUE_TYPE (v1); 4995796c8dcSSimon Schubert else if (TYPE_UNSIGNED (t2) && l2 > l1) 5005796c8dcSSimon Schubert return VALUE_TYPE (v2); 5015796c8dcSSimon Schubert else /* Both are signed. Result is the longer type */ 5025796c8dcSSimon Schubert return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 5035796c8dcSSimon Schubert break; 5045796c8dcSSimon Schubert case language_m2: 5055796c8dcSSimon Schubert /* If we are doing type-checking, l1 should equal l2, so this is 5065796c8dcSSimon Schubert not needed. */ 5075796c8dcSSimon Schubert return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 5085796c8dcSSimon Schubert break; 5095796c8dcSSimon Schubert } 5105796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("failed internal consistency check")); 5115796c8dcSSimon Schubert return (struct type *) 0; /* For lint */ 5125796c8dcSSimon Schubert } 5135796c8dcSSimon Schubert 5145796c8dcSSimon Schubert #endif /* 0 */ 5155796c8dcSSimon Schubert #if 0 5165796c8dcSSimon Schubert /* This page contains functions that are used in type/range checking. 5175796c8dcSSimon Schubert They all return zero if the type/range check fails. 5185796c8dcSSimon Schubert 5195796c8dcSSimon Schubert It is hoped that these will make extending GDB to parse different 5205796c8dcSSimon Schubert languages a little easier. These are primarily used in eval.c when 5215796c8dcSSimon Schubert evaluating expressions and making sure that their types are correct. 5225796c8dcSSimon Schubert Instead of having a mess of conjucted/disjuncted expressions in an "if", 5235796c8dcSSimon Schubert the ideas of type can be wrapped up in the following functions. 5245796c8dcSSimon Schubert 5255796c8dcSSimon Schubert Note that some of them are not currently dependent upon which language 5265796c8dcSSimon Schubert is currently being parsed. For example, floats are the same in 5275796c8dcSSimon Schubert C and Modula-2 (ie. the only floating point type has TYPE_CODE of 5285796c8dcSSimon Schubert TYPE_CODE_FLT), while booleans are different. */ 5295796c8dcSSimon Schubert 5305796c8dcSSimon Schubert /* Returns non-zero if its argument is a simple type. This is the same for 5315796c8dcSSimon Schubert both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur, 5325796c8dcSSimon Schubert and thus will never cause the failure of the test. */ 5335796c8dcSSimon Schubert int 5345796c8dcSSimon Schubert simple_type (struct type *type) 5355796c8dcSSimon Schubert { 5365796c8dcSSimon Schubert CHECK_TYPEDEF (type); 5375796c8dcSSimon Schubert switch (TYPE_CODE (type)) 5385796c8dcSSimon Schubert { 5395796c8dcSSimon Schubert case TYPE_CODE_INT: 5405796c8dcSSimon Schubert case TYPE_CODE_CHAR: 5415796c8dcSSimon Schubert case TYPE_CODE_ENUM: 5425796c8dcSSimon Schubert case TYPE_CODE_FLT: 5435796c8dcSSimon Schubert case TYPE_CODE_RANGE: 5445796c8dcSSimon Schubert case TYPE_CODE_BOOL: 5455796c8dcSSimon Schubert return 1; 5465796c8dcSSimon Schubert 5475796c8dcSSimon Schubert default: 5485796c8dcSSimon Schubert return 0; 5495796c8dcSSimon Schubert } 5505796c8dcSSimon Schubert } 5515796c8dcSSimon Schubert 5525796c8dcSSimon Schubert /* Returns non-zero if its argument is of an ordered type. 5535796c8dcSSimon Schubert An ordered type is one in which the elements can be tested for the 5545796c8dcSSimon Schubert properties of "greater than", "less than", etc, or for which the 5555796c8dcSSimon Schubert operations "increment" or "decrement" make sense. */ 5565796c8dcSSimon Schubert int 5575796c8dcSSimon Schubert ordered_type (struct type *type) 5585796c8dcSSimon Schubert { 5595796c8dcSSimon Schubert CHECK_TYPEDEF (type); 5605796c8dcSSimon Schubert switch (TYPE_CODE (type)) 5615796c8dcSSimon Schubert { 5625796c8dcSSimon Schubert case TYPE_CODE_INT: 5635796c8dcSSimon Schubert case TYPE_CODE_CHAR: 5645796c8dcSSimon Schubert case TYPE_CODE_ENUM: 5655796c8dcSSimon Schubert case TYPE_CODE_FLT: 5665796c8dcSSimon Schubert case TYPE_CODE_RANGE: 5675796c8dcSSimon Schubert return 1; 5685796c8dcSSimon Schubert 5695796c8dcSSimon Schubert default: 5705796c8dcSSimon Schubert return 0; 5715796c8dcSSimon Schubert } 5725796c8dcSSimon Schubert } 5735796c8dcSSimon Schubert 5745796c8dcSSimon Schubert /* Returns non-zero if the two types are the same */ 5755796c8dcSSimon Schubert int 5765796c8dcSSimon Schubert same_type (struct type *arg1, struct type *arg2) 5775796c8dcSSimon Schubert { 5785796c8dcSSimon Schubert CHECK_TYPEDEF (type); 5795796c8dcSSimon Schubert if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2)) 5805796c8dcSSimon Schubert /* One is structured and one isn't */ 5815796c8dcSSimon Schubert return 0; 5825796c8dcSSimon Schubert else if (structured_type (arg1) && structured_type (arg2)) 5835796c8dcSSimon Schubert return arg1 == arg2; 5845796c8dcSSimon Schubert else if (numeric_type (arg1) && numeric_type (arg2)) 5855796c8dcSSimon Schubert return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) && 5865796c8dcSSimon Schubert (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2)) 5875796c8dcSSimon Schubert ? 1 : 0; 5885796c8dcSSimon Schubert else 5895796c8dcSSimon Schubert return arg1 == arg2; 5905796c8dcSSimon Schubert } 5915796c8dcSSimon Schubert 5925796c8dcSSimon Schubert /* Returns non-zero if the type is integral */ 5935796c8dcSSimon Schubert int 5945796c8dcSSimon Schubert integral_type (struct type *type) 5955796c8dcSSimon Schubert { 5965796c8dcSSimon Schubert CHECK_TYPEDEF (type); 5975796c8dcSSimon Schubert switch (current_language->la_language) 5985796c8dcSSimon Schubert { 5995796c8dcSSimon Schubert case language_c: 6005796c8dcSSimon Schubert case language_cplus: 601*cf7f2e2dSJohn Marino case language_d: 6025796c8dcSSimon Schubert case language_objc: 6035796c8dcSSimon Schubert return (TYPE_CODE (type) != TYPE_CODE_INT) && 6045796c8dcSSimon Schubert (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1; 6055796c8dcSSimon Schubert case language_m2: 6065796c8dcSSimon Schubert case language_pascal: 6075796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1; 6085796c8dcSSimon Schubert default: 6095796c8dcSSimon Schubert error (_("Language not supported.")); 6105796c8dcSSimon Schubert } 6115796c8dcSSimon Schubert } 6125796c8dcSSimon Schubert 6135796c8dcSSimon Schubert /* Returns non-zero if the value is numeric */ 6145796c8dcSSimon Schubert int 6155796c8dcSSimon Schubert numeric_type (struct type *type) 6165796c8dcSSimon Schubert { 6175796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6185796c8dcSSimon Schubert switch (TYPE_CODE (type)) 6195796c8dcSSimon Schubert { 6205796c8dcSSimon Schubert case TYPE_CODE_INT: 6215796c8dcSSimon Schubert case TYPE_CODE_FLT: 6225796c8dcSSimon Schubert return 1; 6235796c8dcSSimon Schubert 6245796c8dcSSimon Schubert default: 6255796c8dcSSimon Schubert return 0; 6265796c8dcSSimon Schubert } 6275796c8dcSSimon Schubert } 6285796c8dcSSimon Schubert 6295796c8dcSSimon Schubert /* Returns non-zero if the value is a character type */ 6305796c8dcSSimon Schubert int 6315796c8dcSSimon Schubert character_type (struct type *type) 6325796c8dcSSimon Schubert { 6335796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6345796c8dcSSimon Schubert switch (current_language->la_language) 6355796c8dcSSimon Schubert { 6365796c8dcSSimon Schubert case language_m2: 6375796c8dcSSimon Schubert case language_pascal: 6385796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1; 6395796c8dcSSimon Schubert 6405796c8dcSSimon Schubert case language_c: 6415796c8dcSSimon Schubert case language_cplus: 642*cf7f2e2dSJohn Marino case language_d: 6435796c8dcSSimon Schubert case language_objc: 6445796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_INT) && 6455796c8dcSSimon Schubert TYPE_LENGTH (type) == sizeof (char) 6465796c8dcSSimon Schubert ? 1 : 0; 6475796c8dcSSimon Schubert default: 6485796c8dcSSimon Schubert return (0); 6495796c8dcSSimon Schubert } 6505796c8dcSSimon Schubert } 6515796c8dcSSimon Schubert 6525796c8dcSSimon Schubert /* Returns non-zero if the value is a string type */ 6535796c8dcSSimon Schubert int 6545796c8dcSSimon Schubert string_type (struct type *type) 6555796c8dcSSimon Schubert { 6565796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6575796c8dcSSimon Schubert switch (current_language->la_language) 6585796c8dcSSimon Schubert { 6595796c8dcSSimon Schubert case language_m2: 6605796c8dcSSimon Schubert case language_pascal: 6615796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1; 6625796c8dcSSimon Schubert 6635796c8dcSSimon Schubert case language_c: 6645796c8dcSSimon Schubert case language_cplus: 665*cf7f2e2dSJohn Marino case language_d: 6665796c8dcSSimon Schubert case language_objc: 6675796c8dcSSimon Schubert /* C does not have distinct string type. */ 6685796c8dcSSimon Schubert return (0); 6695796c8dcSSimon Schubert default: 6705796c8dcSSimon Schubert return (0); 6715796c8dcSSimon Schubert } 6725796c8dcSSimon Schubert } 6735796c8dcSSimon Schubert 6745796c8dcSSimon Schubert /* Returns non-zero if the value is a boolean type */ 6755796c8dcSSimon Schubert int 6765796c8dcSSimon Schubert boolean_type (struct type *type) 6775796c8dcSSimon Schubert { 6785796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6795796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_BOOL) 6805796c8dcSSimon Schubert return 1; 6815796c8dcSSimon Schubert switch (current_language->la_language) 6825796c8dcSSimon Schubert { 6835796c8dcSSimon Schubert case language_c: 6845796c8dcSSimon Schubert case language_cplus: 685*cf7f2e2dSJohn Marino case language_d: 6865796c8dcSSimon Schubert case language_objc: 6875796c8dcSSimon Schubert /* Might be more cleanly handled by having a 6885796c8dcSSimon Schubert TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such 6895796c8dcSSimon Schubert languages, or a TYPE_CODE_INT_OR_BOOL for C. */ 6905796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_INT) 6915796c8dcSSimon Schubert return 1; 6925796c8dcSSimon Schubert default: 6935796c8dcSSimon Schubert break; 6945796c8dcSSimon Schubert } 6955796c8dcSSimon Schubert return 0; 6965796c8dcSSimon Schubert } 6975796c8dcSSimon Schubert 6985796c8dcSSimon Schubert /* Returns non-zero if the value is a floating-point type */ 6995796c8dcSSimon Schubert int 7005796c8dcSSimon Schubert float_type (struct type *type) 7015796c8dcSSimon Schubert { 7025796c8dcSSimon Schubert CHECK_TYPEDEF (type); 7035796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_FLT; 7045796c8dcSSimon Schubert } 705*cf7f2e2dSJohn Marino #endif 7065796c8dcSSimon Schubert 7075796c8dcSSimon Schubert /* Returns non-zero if the value is a pointer type */ 7085796c8dcSSimon Schubert int 7095796c8dcSSimon Schubert pointer_type (struct type *type) 7105796c8dcSSimon Schubert { 7115796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_PTR || 7125796c8dcSSimon Schubert TYPE_CODE (type) == TYPE_CODE_REF; 7135796c8dcSSimon Schubert } 7145796c8dcSSimon Schubert 715*cf7f2e2dSJohn Marino #if 0 7165796c8dcSSimon Schubert /* Returns non-zero if the value is a structured type */ 7175796c8dcSSimon Schubert int 7185796c8dcSSimon Schubert structured_type (struct type *type) 7195796c8dcSSimon Schubert { 7205796c8dcSSimon Schubert CHECK_TYPEDEF (type); 7215796c8dcSSimon Schubert switch (current_language->la_language) 7225796c8dcSSimon Schubert { 7235796c8dcSSimon Schubert case language_c: 7245796c8dcSSimon Schubert case language_cplus: 725*cf7f2e2dSJohn Marino case language_d: 7265796c8dcSSimon Schubert case language_objc: 7275796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 7285796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_UNION) || 7295796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_ARRAY); 7305796c8dcSSimon Schubert case language_pascal: 7315796c8dcSSimon Schubert return (TYPE_CODE(type) == TYPE_CODE_STRUCT) || 7325796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_UNION) || 7335796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_SET) || 7345796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_ARRAY); 7355796c8dcSSimon Schubert case language_m2: 7365796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 7375796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_SET) || 7385796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_ARRAY); 7395796c8dcSSimon Schubert default: 7405796c8dcSSimon Schubert return (0); 7415796c8dcSSimon Schubert } 7425796c8dcSSimon Schubert } 7435796c8dcSSimon Schubert #endif 7445796c8dcSSimon Schubert 7455796c8dcSSimon Schubert /* This page contains functions that return info about 7465796c8dcSSimon Schubert (struct value) values used in GDB. */ 7475796c8dcSSimon Schubert 7485796c8dcSSimon Schubert /* Returns non-zero if the value VAL represents a true value. */ 7495796c8dcSSimon Schubert int 7505796c8dcSSimon Schubert value_true (struct value *val) 7515796c8dcSSimon Schubert { 7525796c8dcSSimon Schubert /* It is possible that we should have some sort of error if a non-boolean 7535796c8dcSSimon Schubert value is used in this context. Possibly dependent on some kind of 7545796c8dcSSimon Schubert "boolean-checking" option like range checking. But it should probably 7555796c8dcSSimon Schubert not depend on the language except insofar as is necessary to identify 7565796c8dcSSimon Schubert a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean 7575796c8dcSSimon Schubert should be an error, probably). */ 7585796c8dcSSimon Schubert return !value_logical_not (val); 7595796c8dcSSimon Schubert } 7605796c8dcSSimon Schubert 7615796c8dcSSimon Schubert /* This page contains functions for the printing out of 7625796c8dcSSimon Schubert error messages that occur during type- and range- 7635796c8dcSSimon Schubert checking. */ 7645796c8dcSSimon Schubert 7655796c8dcSSimon Schubert /* These are called when a language fails a type- or range-check. The 7665796c8dcSSimon Schubert first argument should be a printf()-style format string, and the 7675796c8dcSSimon Schubert rest of the arguments should be its arguments. If 7685796c8dcSSimon Schubert [type|range]_check is [type|range]_check_on, an error is printed; 7695796c8dcSSimon Schubert if [type|range]_check_warn, a warning; otherwise just the 7705796c8dcSSimon Schubert message. */ 7715796c8dcSSimon Schubert 7725796c8dcSSimon Schubert void 7735796c8dcSSimon Schubert type_error (const char *string,...) 7745796c8dcSSimon Schubert { 7755796c8dcSSimon Schubert va_list args; 7765796c8dcSSimon Schubert 777*cf7f2e2dSJohn Marino va_start (args, string); 7785796c8dcSSimon Schubert switch (type_check) 7795796c8dcSSimon Schubert { 7805796c8dcSSimon Schubert case type_check_warn: 7815796c8dcSSimon Schubert vwarning (string, args); 7825796c8dcSSimon Schubert break; 7835796c8dcSSimon Schubert case type_check_on: 7845796c8dcSSimon Schubert verror (string, args); 7855796c8dcSSimon Schubert break; 7865796c8dcSSimon Schubert case type_check_off: 7875796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything 7885796c8dcSSimon Schubert when type error is off? */ 7895796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args); 7905796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n"); 7915796c8dcSSimon Schubert break; 7925796c8dcSSimon Schubert default: 7935796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 7945796c8dcSSimon Schubert } 7955796c8dcSSimon Schubert va_end (args); 7965796c8dcSSimon Schubert } 7975796c8dcSSimon Schubert 7985796c8dcSSimon Schubert void 7995796c8dcSSimon Schubert range_error (const char *string,...) 8005796c8dcSSimon Schubert { 8015796c8dcSSimon Schubert va_list args; 8025796c8dcSSimon Schubert 803*cf7f2e2dSJohn Marino va_start (args, string); 8045796c8dcSSimon Schubert switch (range_check) 8055796c8dcSSimon Schubert { 8065796c8dcSSimon Schubert case range_check_warn: 8075796c8dcSSimon Schubert vwarning (string, args); 8085796c8dcSSimon Schubert break; 8095796c8dcSSimon Schubert case range_check_on: 8105796c8dcSSimon Schubert verror (string, args); 8115796c8dcSSimon Schubert break; 8125796c8dcSSimon Schubert case range_check_off: 8135796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything 8145796c8dcSSimon Schubert when range error is off? */ 8155796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args); 8165796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n"); 8175796c8dcSSimon Schubert break; 8185796c8dcSSimon Schubert default: 8195796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 8205796c8dcSSimon Schubert } 8215796c8dcSSimon Schubert va_end (args); 8225796c8dcSSimon Schubert } 8235796c8dcSSimon Schubert 8245796c8dcSSimon Schubert 8255796c8dcSSimon Schubert /* This page contains miscellaneous functions */ 8265796c8dcSSimon Schubert 8275796c8dcSSimon Schubert /* Return the language enum for a given language string. */ 8285796c8dcSSimon Schubert 8295796c8dcSSimon Schubert enum language 8305796c8dcSSimon Schubert language_enum (char *str) 8315796c8dcSSimon Schubert { 8325796c8dcSSimon Schubert int i; 8335796c8dcSSimon Schubert 8345796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8355796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, str) == 0) 8365796c8dcSSimon Schubert return languages[i]->la_language; 8375796c8dcSSimon Schubert 8385796c8dcSSimon Schubert return language_unknown; 8395796c8dcSSimon Schubert } 8405796c8dcSSimon Schubert 8415796c8dcSSimon Schubert /* Return the language struct for a given language enum. */ 8425796c8dcSSimon Schubert 8435796c8dcSSimon Schubert const struct language_defn * 8445796c8dcSSimon Schubert language_def (enum language lang) 8455796c8dcSSimon Schubert { 8465796c8dcSSimon Schubert int i; 8475796c8dcSSimon Schubert 8485796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8495796c8dcSSimon Schubert { 8505796c8dcSSimon Schubert if (languages[i]->la_language == lang) 8515796c8dcSSimon Schubert { 8525796c8dcSSimon Schubert return languages[i]; 8535796c8dcSSimon Schubert } 8545796c8dcSSimon Schubert } 8555796c8dcSSimon Schubert return NULL; 8565796c8dcSSimon Schubert } 8575796c8dcSSimon Schubert 8585796c8dcSSimon Schubert /* Return the language as a string */ 8595796c8dcSSimon Schubert char * 8605796c8dcSSimon Schubert language_str (enum language lang) 8615796c8dcSSimon Schubert { 8625796c8dcSSimon Schubert int i; 8635796c8dcSSimon Schubert 8645796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8655796c8dcSSimon Schubert { 8665796c8dcSSimon Schubert if (languages[i]->la_language == lang) 8675796c8dcSSimon Schubert { 8685796c8dcSSimon Schubert return languages[i]->la_name; 8695796c8dcSSimon Schubert } 8705796c8dcSSimon Schubert } 8715796c8dcSSimon Schubert return "Unknown"; 8725796c8dcSSimon Schubert } 8735796c8dcSSimon Schubert 8745796c8dcSSimon Schubert static void 8755796c8dcSSimon Schubert set_check (char *ignore, int from_tty) 8765796c8dcSSimon Schubert { 8775796c8dcSSimon Schubert printf_unfiltered ( 8785796c8dcSSimon Schubert "\"set check\" must be followed by the name of a check subcommand.\n"); 8795796c8dcSSimon Schubert help_list (setchecklist, "set check ", -1, gdb_stdout); 8805796c8dcSSimon Schubert } 8815796c8dcSSimon Schubert 8825796c8dcSSimon Schubert static void 8835796c8dcSSimon Schubert show_check (char *ignore, int from_tty) 8845796c8dcSSimon Schubert { 8855796c8dcSSimon Schubert cmd_show_list (showchecklist, from_tty, ""); 8865796c8dcSSimon Schubert } 8875796c8dcSSimon Schubert 8885796c8dcSSimon Schubert /* Add a language to the set of known languages. */ 8895796c8dcSSimon Schubert 8905796c8dcSSimon Schubert void 8915796c8dcSSimon Schubert add_language (const struct language_defn *lang) 8925796c8dcSSimon Schubert { 8935796c8dcSSimon Schubert /* For the "set language" command. */ 8945796c8dcSSimon Schubert static char **language_names = NULL; 8955796c8dcSSimon Schubert /* For the "help set language" command. */ 8965796c8dcSSimon Schubert char *language_set_doc = NULL; 8975796c8dcSSimon Schubert 8985796c8dcSSimon Schubert int i; 8995796c8dcSSimon Schubert struct ui_file *tmp_stream; 9005796c8dcSSimon Schubert 9015796c8dcSSimon Schubert if (lang->la_magic != LANG_MAGIC) 9025796c8dcSSimon Schubert { 9035796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n", 9045796c8dcSSimon Schubert lang->la_name); 9055796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("failed internal consistency check")); 9065796c8dcSSimon Schubert } 9075796c8dcSSimon Schubert 9085796c8dcSSimon Schubert if (!languages) 9095796c8dcSSimon Schubert { 9105796c8dcSSimon Schubert languages_allocsize = DEFAULT_ALLOCSIZE; 9115796c8dcSSimon Schubert languages = (const struct language_defn **) xmalloc 9125796c8dcSSimon Schubert (languages_allocsize * sizeof (*languages)); 9135796c8dcSSimon Schubert } 9145796c8dcSSimon Schubert if (languages_size >= languages_allocsize) 9155796c8dcSSimon Schubert { 9165796c8dcSSimon Schubert languages_allocsize *= 2; 9175796c8dcSSimon Schubert languages = (const struct language_defn **) xrealloc ((char *) languages, 9185796c8dcSSimon Schubert languages_allocsize * sizeof (*languages)); 9195796c8dcSSimon Schubert } 9205796c8dcSSimon Schubert languages[languages_size++] = lang; 9215796c8dcSSimon Schubert 9225796c8dcSSimon Schubert /* Build the language names array, to be used as enumeration in the 9235796c8dcSSimon Schubert set language" enum command. */ 9245796c8dcSSimon Schubert language_names = xrealloc (language_names, 9255796c8dcSSimon Schubert (languages_size + 1) * sizeof (const char *)); 9265796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i) 9275796c8dcSSimon Schubert language_names[i] = languages[i]->la_name; 9285796c8dcSSimon Schubert language_names[i] = NULL; 9295796c8dcSSimon Schubert 9305796c8dcSSimon Schubert /* Build the "help set language" docs. */ 9315796c8dcSSimon Schubert tmp_stream = mem_fileopen (); 9325796c8dcSSimon Schubert 9335796c8dcSSimon Schubert fprintf_unfiltered (tmp_stream, _("\ 9345796c8dcSSimon Schubert Set the current source language.\n\ 9355796c8dcSSimon Schubert The currently understood settings are:\n\n\ 9365796c8dcSSimon Schubert local or auto Automatic setting based on source file\n")); 9375796c8dcSSimon Schubert 9385796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i) 9395796c8dcSSimon Schubert { 9405796c8dcSSimon Schubert /* Already dealt with these above. */ 9415796c8dcSSimon Schubert if (languages[i]->la_language == language_unknown 9425796c8dcSSimon Schubert || languages[i]->la_language == language_auto) 9435796c8dcSSimon Schubert continue; 9445796c8dcSSimon Schubert 9455796c8dcSSimon Schubert /* FIXME: i18n: for now assume that the human-readable name 9465796c8dcSSimon Schubert is just a capitalization of the internal name. */ 9475796c8dcSSimon Schubert fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n", 9485796c8dcSSimon Schubert languages[i]->la_name, 9495796c8dcSSimon Schubert /* Capitalize first letter of language 9505796c8dcSSimon Schubert name. */ 9515796c8dcSSimon Schubert toupper (languages[i]->la_name[0]), 9525796c8dcSSimon Schubert languages[i]->la_name + 1); 9535796c8dcSSimon Schubert } 9545796c8dcSSimon Schubert 9555796c8dcSSimon Schubert language_set_doc = ui_file_xstrdup (tmp_stream, NULL); 9565796c8dcSSimon Schubert ui_file_delete (tmp_stream); 9575796c8dcSSimon Schubert 9585796c8dcSSimon Schubert add_setshow_enum_cmd ("language", class_support, 9595796c8dcSSimon Schubert (const char **) language_names, 9605796c8dcSSimon Schubert &language, 9615796c8dcSSimon Schubert language_set_doc, _("\ 9625796c8dcSSimon Schubert Show the current source language."), NULL, 9635796c8dcSSimon Schubert set_language_command, 9645796c8dcSSimon Schubert show_language_command, 9655796c8dcSSimon Schubert &setlist, &showlist); 9665796c8dcSSimon Schubert 9675796c8dcSSimon Schubert xfree (language_set_doc); 9685796c8dcSSimon Schubert } 9695796c8dcSSimon Schubert 9705796c8dcSSimon Schubert /* Iterate through all registered languages looking for and calling 9715796c8dcSSimon Schubert any non-NULL struct language_defn.skip_trampoline() functions. 9725796c8dcSSimon Schubert Return the result from the first that returns non-zero, or 0 if all 9735796c8dcSSimon Schubert `fail'. */ 9745796c8dcSSimon Schubert CORE_ADDR 9755796c8dcSSimon Schubert skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc) 9765796c8dcSSimon Schubert { 9775796c8dcSSimon Schubert int i; 9785796c8dcSSimon Schubert 9795796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 9805796c8dcSSimon Schubert { 9815796c8dcSSimon Schubert if (languages[i]->skip_trampoline) 9825796c8dcSSimon Schubert { 9835796c8dcSSimon Schubert CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc); 984*cf7f2e2dSJohn Marino 9855796c8dcSSimon Schubert if (real_pc) 9865796c8dcSSimon Schubert return real_pc; 9875796c8dcSSimon Schubert } 9885796c8dcSSimon Schubert } 9895796c8dcSSimon Schubert 9905796c8dcSSimon Schubert return 0; 9915796c8dcSSimon Schubert } 9925796c8dcSSimon Schubert 9935796c8dcSSimon Schubert /* Return demangled language symbol, or NULL. 9945796c8dcSSimon Schubert FIXME: Options are only useful for certain languages and ignored 9955796c8dcSSimon Schubert by others, so it would be better to remove them here and have a 9965796c8dcSSimon Schubert more flexible demangler for the languages that need it. 9975796c8dcSSimon Schubert FIXME: Sometimes the demangler is invoked when we don't know the 9985796c8dcSSimon Schubert language, so we can't use this everywhere. */ 9995796c8dcSSimon Schubert char * 10005796c8dcSSimon Schubert language_demangle (const struct language_defn *current_language, 10015796c8dcSSimon Schubert const char *mangled, int options) 10025796c8dcSSimon Schubert { 10035796c8dcSSimon Schubert if (current_language != NULL && current_language->la_demangle) 10045796c8dcSSimon Schubert return current_language->la_demangle (mangled, options); 10055796c8dcSSimon Schubert return NULL; 10065796c8dcSSimon Schubert } 10075796c8dcSSimon Schubert 10085796c8dcSSimon Schubert /* Return class name from physname or NULL. */ 10095796c8dcSSimon Schubert char * 10105796c8dcSSimon Schubert language_class_name_from_physname (const struct language_defn *current_language, 10115796c8dcSSimon Schubert const char *physname) 10125796c8dcSSimon Schubert { 10135796c8dcSSimon Schubert if (current_language != NULL && current_language->la_class_name_from_physname) 10145796c8dcSSimon Schubert return current_language->la_class_name_from_physname (physname); 10155796c8dcSSimon Schubert return NULL; 10165796c8dcSSimon Schubert } 10175796c8dcSSimon Schubert 10185796c8dcSSimon Schubert /* Return non-zero if TYPE should be passed (and returned) by 10195796c8dcSSimon Schubert reference at the language level. */ 10205796c8dcSSimon Schubert int 10215796c8dcSSimon Schubert language_pass_by_reference (struct type *type) 10225796c8dcSSimon Schubert { 10235796c8dcSSimon Schubert return current_language->la_pass_by_reference (type); 10245796c8dcSSimon Schubert } 10255796c8dcSSimon Schubert 10265796c8dcSSimon Schubert /* Return zero; by default, types are passed by value at the language 10275796c8dcSSimon Schubert level. The target ABI may pass or return some structs by reference 10285796c8dcSSimon Schubert independent of this. */ 10295796c8dcSSimon Schubert int 10305796c8dcSSimon Schubert default_pass_by_reference (struct type *type) 10315796c8dcSSimon Schubert { 10325796c8dcSSimon Schubert return 0; 10335796c8dcSSimon Schubert } 10345796c8dcSSimon Schubert 10355796c8dcSSimon Schubert /* Return the default string containing the list of characters 10365796c8dcSSimon Schubert delimiting words. This is a reasonable default value that 10375796c8dcSSimon Schubert most languages should be able to use. */ 10385796c8dcSSimon Schubert 10395796c8dcSSimon Schubert char * 10405796c8dcSSimon Schubert default_word_break_characters (void) 10415796c8dcSSimon Schubert { 10425796c8dcSSimon Schubert return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; 10435796c8dcSSimon Schubert } 10445796c8dcSSimon Schubert 10455796c8dcSSimon Schubert /* Print the index of array elements using the C99 syntax. */ 10465796c8dcSSimon Schubert 10475796c8dcSSimon Schubert void 10485796c8dcSSimon Schubert default_print_array_index (struct value *index_value, struct ui_file *stream, 10495796c8dcSSimon Schubert const struct value_print_options *options) 10505796c8dcSSimon Schubert { 10515796c8dcSSimon Schubert fprintf_filtered (stream, "["); 10525796c8dcSSimon Schubert LA_VALUE_PRINT (index_value, stream, options); 10535796c8dcSSimon Schubert fprintf_filtered (stream, "] = "); 10545796c8dcSSimon Schubert } 10555796c8dcSSimon Schubert 10565796c8dcSSimon Schubert void 10575796c8dcSSimon Schubert default_get_string (struct value *value, gdb_byte **buffer, int *length, 1058*cf7f2e2dSJohn Marino struct type **char_type, const char **charset) 10595796c8dcSSimon Schubert { 10605796c8dcSSimon Schubert error (_("Getting a string is unsupported in this language.")); 10615796c8dcSSimon Schubert } 10625796c8dcSSimon Schubert 10635796c8dcSSimon Schubert /* Define the language that is no language. */ 10645796c8dcSSimon Schubert 10655796c8dcSSimon Schubert static int 10665796c8dcSSimon Schubert unk_lang_parser (void) 10675796c8dcSSimon Schubert { 10685796c8dcSSimon Schubert return 1; 10695796c8dcSSimon Schubert } 10705796c8dcSSimon Schubert 10715796c8dcSSimon Schubert static void 10725796c8dcSSimon Schubert unk_lang_error (char *msg) 10735796c8dcSSimon Schubert { 10745796c8dcSSimon Schubert error (_("Attempted to parse an expression with unknown language")); 10755796c8dcSSimon Schubert } 10765796c8dcSSimon Schubert 10775796c8dcSSimon Schubert static void 10785796c8dcSSimon Schubert unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, 10795796c8dcSSimon Schubert int quoter) 10805796c8dcSSimon Schubert { 10815796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_emit_char called.")); 10825796c8dcSSimon Schubert } 10835796c8dcSSimon Schubert 10845796c8dcSSimon Schubert static void 10855796c8dcSSimon Schubert unk_lang_printchar (int c, struct type *type, struct ui_file *stream) 10865796c8dcSSimon Schubert { 10875796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_printchar called.")); 10885796c8dcSSimon Schubert } 10895796c8dcSSimon Schubert 10905796c8dcSSimon Schubert static void 10915796c8dcSSimon Schubert unk_lang_printstr (struct ui_file *stream, struct type *type, 10925796c8dcSSimon Schubert const gdb_byte *string, unsigned int length, 1093*cf7f2e2dSJohn Marino const char *encoding, int force_ellipses, 10945796c8dcSSimon Schubert const struct value_print_options *options) 10955796c8dcSSimon Schubert { 10965796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_printstr called.")); 10975796c8dcSSimon Schubert } 10985796c8dcSSimon Schubert 10995796c8dcSSimon Schubert static void 1100*cf7f2e2dSJohn Marino unk_lang_print_type (struct type *type, const char *varstring, 1101*cf7f2e2dSJohn Marino struct ui_file *stream, int show, int level) 11025796c8dcSSimon Schubert { 11035796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_print_type called.")); 11045796c8dcSSimon Schubert } 11055796c8dcSSimon Schubert 11065796c8dcSSimon Schubert static int 11075796c8dcSSimon Schubert unk_lang_val_print (struct type *type, const gdb_byte *valaddr, 11085796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address, 11095796c8dcSSimon Schubert struct ui_file *stream, int recurse, 1110*cf7f2e2dSJohn Marino const struct value *val, 11115796c8dcSSimon Schubert const struct value_print_options *options) 11125796c8dcSSimon Schubert { 11135796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_val_print called.")); 11145796c8dcSSimon Schubert } 11155796c8dcSSimon Schubert 11165796c8dcSSimon Schubert static int 11175796c8dcSSimon Schubert unk_lang_value_print (struct value *val, struct ui_file *stream, 11185796c8dcSSimon Schubert const struct value_print_options *options) 11195796c8dcSSimon Schubert { 11205796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_value_print called.")); 11215796c8dcSSimon Schubert } 11225796c8dcSSimon Schubert 11235796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) 11245796c8dcSSimon Schubert { 11255796c8dcSSimon Schubert return 0; 11265796c8dcSSimon Schubert } 11275796c8dcSSimon Schubert 11285796c8dcSSimon Schubert /* Unknown languages just use the cplus demangler. */ 11295796c8dcSSimon Schubert static char *unk_lang_demangle (const char *mangled, int options) 11305796c8dcSSimon Schubert { 11315796c8dcSSimon Schubert return cplus_demangle (mangled, options); 11325796c8dcSSimon Schubert } 11335796c8dcSSimon Schubert 11345796c8dcSSimon Schubert static char *unk_lang_class_name (const char *mangled) 11355796c8dcSSimon Schubert { 11365796c8dcSSimon Schubert return NULL; 11375796c8dcSSimon Schubert } 11385796c8dcSSimon Schubert 11395796c8dcSSimon Schubert static const struct op_print unk_op_print_tab[] = 11405796c8dcSSimon Schubert { 11415796c8dcSSimon Schubert {NULL, OP_NULL, PREC_NULL, 0} 11425796c8dcSSimon Schubert }; 11435796c8dcSSimon Schubert 11445796c8dcSSimon Schubert static void 11455796c8dcSSimon Schubert unknown_language_arch_info (struct gdbarch *gdbarch, 11465796c8dcSSimon Schubert struct language_arch_info *lai) 11475796c8dcSSimon Schubert { 11485796c8dcSSimon Schubert lai->string_char_type = builtin_type (gdbarch)->builtin_char; 11495796c8dcSSimon Schubert lai->bool_type_default = builtin_type (gdbarch)->builtin_int; 11505796c8dcSSimon Schubert lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, 11515796c8dcSSimon Schubert struct type *); 11525796c8dcSSimon Schubert } 11535796c8dcSSimon Schubert 11545796c8dcSSimon Schubert const struct language_defn unknown_language_defn = 11555796c8dcSSimon Schubert { 11565796c8dcSSimon Schubert "unknown", 11575796c8dcSSimon Schubert language_unknown, 11585796c8dcSSimon Schubert range_check_off, 11595796c8dcSSimon Schubert type_check_off, 11605796c8dcSSimon Schubert case_sensitive_on, 11615796c8dcSSimon Schubert array_row_major, 11625796c8dcSSimon Schubert macro_expansion_no, 11635796c8dcSSimon Schubert &exp_descriptor_standard, 11645796c8dcSSimon Schubert unk_lang_parser, 11655796c8dcSSimon Schubert unk_lang_error, 11665796c8dcSSimon Schubert null_post_parser, 11675796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 11685796c8dcSSimon Schubert unk_lang_printstr, 11695796c8dcSSimon Schubert unk_lang_emit_char, 11705796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 11715796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 11725796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 11735796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 11745796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 11755796c8dcSSimon Schubert "this", /* name_of_this */ 11765796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 11775796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 11785796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 11795796c8dcSSimon Schubert unk_lang_class_name, /* Language specific class_name_from_physname */ 11805796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 11815796c8dcSSimon Schubert 1, /* c-style arrays */ 11825796c8dcSSimon Schubert 0, /* String lower bound */ 11835796c8dcSSimon Schubert default_word_break_characters, 11845796c8dcSSimon Schubert default_make_symbol_completion_list, 11855796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 11865796c8dcSSimon Schubert default_print_array_index, 11875796c8dcSSimon Schubert default_pass_by_reference, 11885796c8dcSSimon Schubert default_get_string, 11895796c8dcSSimon Schubert LANG_MAGIC 11905796c8dcSSimon Schubert }; 11915796c8dcSSimon Schubert 11925796c8dcSSimon Schubert /* These two structs define fake entries for the "local" and "auto" options. */ 11935796c8dcSSimon Schubert const struct language_defn auto_language_defn = 11945796c8dcSSimon Schubert { 11955796c8dcSSimon Schubert "auto", 11965796c8dcSSimon Schubert language_auto, 11975796c8dcSSimon Schubert range_check_off, 11985796c8dcSSimon Schubert type_check_off, 11995796c8dcSSimon Schubert case_sensitive_on, 12005796c8dcSSimon Schubert array_row_major, 12015796c8dcSSimon Schubert macro_expansion_no, 12025796c8dcSSimon Schubert &exp_descriptor_standard, 12035796c8dcSSimon Schubert unk_lang_parser, 12045796c8dcSSimon Schubert unk_lang_error, 12055796c8dcSSimon Schubert null_post_parser, 12065796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 12075796c8dcSSimon Schubert unk_lang_printstr, 12085796c8dcSSimon Schubert unk_lang_emit_char, 12095796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 12105796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 12115796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 12125796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 12135796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 12145796c8dcSSimon Schubert "this", /* name_of_this */ 12155796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 12165796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 12175796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 12185796c8dcSSimon Schubert unk_lang_class_name, /* Language specific class_name_from_physname */ 12195796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 12205796c8dcSSimon Schubert 1, /* c-style arrays */ 12215796c8dcSSimon Schubert 0, /* String lower bound */ 12225796c8dcSSimon Schubert default_word_break_characters, 12235796c8dcSSimon Schubert default_make_symbol_completion_list, 12245796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 12255796c8dcSSimon Schubert default_print_array_index, 12265796c8dcSSimon Schubert default_pass_by_reference, 12275796c8dcSSimon Schubert default_get_string, 12285796c8dcSSimon Schubert LANG_MAGIC 12295796c8dcSSimon Schubert }; 12305796c8dcSSimon Schubert 12315796c8dcSSimon Schubert const struct language_defn local_language_defn = 12325796c8dcSSimon Schubert { 12335796c8dcSSimon Schubert "local", 12345796c8dcSSimon Schubert language_auto, 12355796c8dcSSimon Schubert range_check_off, 12365796c8dcSSimon Schubert type_check_off, 12375796c8dcSSimon Schubert case_sensitive_on, 12385796c8dcSSimon Schubert array_row_major, 12395796c8dcSSimon Schubert macro_expansion_no, 12405796c8dcSSimon Schubert &exp_descriptor_standard, 12415796c8dcSSimon Schubert unk_lang_parser, 12425796c8dcSSimon Schubert unk_lang_error, 12435796c8dcSSimon Schubert null_post_parser, 12445796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 12455796c8dcSSimon Schubert unk_lang_printstr, 12465796c8dcSSimon Schubert unk_lang_emit_char, 12475796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 12485796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 12495796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 12505796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 12515796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 12525796c8dcSSimon Schubert "this", /* name_of_this */ 12535796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 12545796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 12555796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 12565796c8dcSSimon Schubert unk_lang_class_name, /* Language specific class_name_from_physname */ 12575796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 12585796c8dcSSimon Schubert 1, /* c-style arrays */ 12595796c8dcSSimon Schubert 0, /* String lower bound */ 12605796c8dcSSimon Schubert default_word_break_characters, 12615796c8dcSSimon Schubert default_make_symbol_completion_list, 12625796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 12635796c8dcSSimon Schubert default_print_array_index, 12645796c8dcSSimon Schubert default_pass_by_reference, 12655796c8dcSSimon Schubert default_get_string, 12665796c8dcSSimon Schubert LANG_MAGIC 12675796c8dcSSimon Schubert }; 12685796c8dcSSimon Schubert 12695796c8dcSSimon Schubert /* Per-architecture language information. */ 12705796c8dcSSimon Schubert 12715796c8dcSSimon Schubert static struct gdbarch_data *language_gdbarch_data; 12725796c8dcSSimon Schubert 12735796c8dcSSimon Schubert struct language_gdbarch 12745796c8dcSSimon Schubert { 12755796c8dcSSimon Schubert /* A vector of per-language per-architecture info. Indexed by "enum 12765796c8dcSSimon Schubert language". */ 12775796c8dcSSimon Schubert struct language_arch_info arch_info[nr_languages]; 12785796c8dcSSimon Schubert }; 12795796c8dcSSimon Schubert 12805796c8dcSSimon Schubert static void * 12815796c8dcSSimon Schubert language_gdbarch_post_init (struct gdbarch *gdbarch) 12825796c8dcSSimon Schubert { 12835796c8dcSSimon Schubert struct language_gdbarch *l; 12845796c8dcSSimon Schubert int i; 12855796c8dcSSimon Schubert 12865796c8dcSSimon Schubert l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); 12875796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 12885796c8dcSSimon Schubert { 12895796c8dcSSimon Schubert if (languages[i] != NULL 12905796c8dcSSimon Schubert && languages[i]->la_language_arch_info != NULL) 12915796c8dcSSimon Schubert languages[i]->la_language_arch_info 12925796c8dcSSimon Schubert (gdbarch, l->arch_info + languages[i]->la_language); 12935796c8dcSSimon Schubert } 12945796c8dcSSimon Schubert return l; 12955796c8dcSSimon Schubert } 12965796c8dcSSimon Schubert 12975796c8dcSSimon Schubert struct type * 12985796c8dcSSimon Schubert language_string_char_type (const struct language_defn *la, 12995796c8dcSSimon Schubert struct gdbarch *gdbarch) 13005796c8dcSSimon Schubert { 13015796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13025796c8dcSSimon Schubert language_gdbarch_data); 1303*cf7f2e2dSJohn Marino 13045796c8dcSSimon Schubert return ld->arch_info[la->la_language].string_char_type; 13055796c8dcSSimon Schubert } 13065796c8dcSSimon Schubert 13075796c8dcSSimon Schubert struct type * 13085796c8dcSSimon Schubert language_bool_type (const struct language_defn *la, 13095796c8dcSSimon Schubert struct gdbarch *gdbarch) 13105796c8dcSSimon Schubert { 13115796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13125796c8dcSSimon Schubert language_gdbarch_data); 13135796c8dcSSimon Schubert 13145796c8dcSSimon Schubert if (ld->arch_info[la->la_language].bool_type_symbol) 13155796c8dcSSimon Schubert { 13165796c8dcSSimon Schubert struct symbol *sym; 1317*cf7f2e2dSJohn Marino 13185796c8dcSSimon Schubert sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, 13195796c8dcSSimon Schubert NULL, VAR_DOMAIN, NULL); 13205796c8dcSSimon Schubert if (sym) 13215796c8dcSSimon Schubert { 13225796c8dcSSimon Schubert struct type *type = SYMBOL_TYPE (sym); 1323*cf7f2e2dSJohn Marino 13245796c8dcSSimon Schubert if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) 13255796c8dcSSimon Schubert return type; 13265796c8dcSSimon Schubert } 13275796c8dcSSimon Schubert } 13285796c8dcSSimon Schubert 13295796c8dcSSimon Schubert return ld->arch_info[la->la_language].bool_type_default; 13305796c8dcSSimon Schubert } 13315796c8dcSSimon Schubert 13325796c8dcSSimon Schubert struct type * 13335796c8dcSSimon Schubert language_lookup_primitive_type_by_name (const struct language_defn *la, 13345796c8dcSSimon Schubert struct gdbarch *gdbarch, 13355796c8dcSSimon Schubert const char *name) 13365796c8dcSSimon Schubert { 13375796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13385796c8dcSSimon Schubert language_gdbarch_data); 13395796c8dcSSimon Schubert struct type *const *p; 1340*cf7f2e2dSJohn Marino 13415796c8dcSSimon Schubert for (p = ld->arch_info[la->la_language].primitive_type_vector; 13425796c8dcSSimon Schubert (*p) != NULL; 13435796c8dcSSimon Schubert p++) 13445796c8dcSSimon Schubert { 13455796c8dcSSimon Schubert if (strcmp (TYPE_NAME (*p), name) == 0) 13465796c8dcSSimon Schubert return (*p); 13475796c8dcSSimon Schubert } 13485796c8dcSSimon Schubert return (NULL); 13495796c8dcSSimon Schubert } 13505796c8dcSSimon Schubert 13515796c8dcSSimon Schubert /* Initialize the language routines */ 13525796c8dcSSimon Schubert 13535796c8dcSSimon Schubert void 13545796c8dcSSimon Schubert _initialize_language (void) 13555796c8dcSSimon Schubert { 13565796c8dcSSimon Schubert static const char *type_or_range_names[] 13575796c8dcSSimon Schubert = { "on", "off", "warn", "auto", NULL }; 13585796c8dcSSimon Schubert 13595796c8dcSSimon Schubert static const char *case_sensitive_names[] 13605796c8dcSSimon Schubert = { "on", "off", "auto", NULL }; 13615796c8dcSSimon Schubert 13625796c8dcSSimon Schubert language_gdbarch_data 13635796c8dcSSimon Schubert = gdbarch_data_register_post_init (language_gdbarch_post_init); 13645796c8dcSSimon Schubert 13655796c8dcSSimon Schubert /* GDB commands for language specific stuff */ 13665796c8dcSSimon Schubert 13675796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, set_check, 13685796c8dcSSimon Schubert _("Set the status of the type/range checker."), 13695796c8dcSSimon Schubert &setchecklist, "set check ", 0, &setlist); 13705796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &setlist); 13715796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &setlist); 13725796c8dcSSimon Schubert 13735796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, show_check, 13745796c8dcSSimon Schubert _("Show the status of the type/range checker."), 13755796c8dcSSimon Schubert &showchecklist, "show check ", 0, &showlist); 13765796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &showlist); 13775796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &showlist); 13785796c8dcSSimon Schubert 13795796c8dcSSimon Schubert add_setshow_enum_cmd ("type", class_support, type_or_range_names, &type, _("\ 13805796c8dcSSimon Schubert Set type checking. (on/warn/off/auto)"), _("\ 13815796c8dcSSimon Schubert Show type checking. (on/warn/off/auto)"), NULL, 13825796c8dcSSimon Schubert set_type_command, 13835796c8dcSSimon Schubert show_type_command, 13845796c8dcSSimon Schubert &setchecklist, &showchecklist); 13855796c8dcSSimon Schubert 13865796c8dcSSimon Schubert add_setshow_enum_cmd ("range", class_support, type_or_range_names, 13875796c8dcSSimon Schubert &range, _("\ 13885796c8dcSSimon Schubert Set range checking. (on/warn/off/auto)"), _("\ 13895796c8dcSSimon Schubert Show range checking. (on/warn/off/auto)"), NULL, 13905796c8dcSSimon Schubert set_range_command, 13915796c8dcSSimon Schubert show_range_command, 13925796c8dcSSimon Schubert &setchecklist, &showchecklist); 13935796c8dcSSimon Schubert 13945796c8dcSSimon Schubert add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names, 13955796c8dcSSimon Schubert &case_sensitive, _("\ 13965796c8dcSSimon Schubert Set case sensitivity in name search. (on/off/auto)"), _("\ 13975796c8dcSSimon Schubert Show case sensitivity in name search. (on/off/auto)"), _("\ 13985796c8dcSSimon Schubert For Fortran the default is off; for other languages the default is on."), 13995796c8dcSSimon Schubert set_case_command, 14005796c8dcSSimon Schubert show_case_command, 14015796c8dcSSimon Schubert &setlist, &showlist); 14025796c8dcSSimon Schubert 14035796c8dcSSimon Schubert add_language (&auto_language_defn); 14045796c8dcSSimon Schubert add_language (&local_language_defn); 14055796c8dcSSimon Schubert add_language (&unknown_language_defn); 14065796c8dcSSimon Schubert 14075796c8dcSSimon Schubert language = xstrdup ("auto"); 14085796c8dcSSimon Schubert type = xstrdup ("auto"); 14095796c8dcSSimon Schubert range = xstrdup ("auto"); 14105796c8dcSSimon Schubert case_sensitive = xstrdup ("auto"); 14115796c8dcSSimon Schubert 14125796c8dcSSimon Schubert /* Have the above take effect */ 14135796c8dcSSimon Schubert set_language (language_auto); 14145796c8dcSSimon Schubert } 1415