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*c50c785cSJohn Marino 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011 5cf7f2e2dSJohn 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 67cf7f2e2dSJohn 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 90*c50c785cSJohn Marino /* 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 { 128*c50c785cSJohn Marino 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 136*c50c785cSJohn Marino fprintf_filtered (gdb_stdout, 137*c50c785cSJohn Marino _("The current source language is \"%s\".\n"), 1385796c8dcSSimon Schubert current_language->la_name); 1395796c8dcSSimon Schubert 1405796c8dcSSimon Schubert flang = get_frame_language (); 1415796c8dcSSimon Schubert if (flang != language_unknown && 1425796c8dcSSimon Schubert language_mode == language_mode_manual && 1435796c8dcSSimon Schubert current_language->la_language != flang) 1445796c8dcSSimon Schubert printf_filtered ("%s\n", lang_frame_mismatch_warn); 1455796c8dcSSimon Schubert } 1465796c8dcSSimon Schubert 1475796c8dcSSimon Schubert /* Set command. Change the current working language. */ 1485796c8dcSSimon Schubert static void 1495796c8dcSSimon Schubert set_language_command (char *ignore, int from_tty, struct cmd_list_element *c) 1505796c8dcSSimon Schubert { 1515796c8dcSSimon Schubert int i; 1525796c8dcSSimon Schubert enum language flang; 1535796c8dcSSimon Schubert 1545796c8dcSSimon Schubert /* Search the list of languages for a match. */ 1555796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 1565796c8dcSSimon Schubert { 1575796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, language) == 0) 1585796c8dcSSimon Schubert { 1595796c8dcSSimon Schubert /* Found it! Go into manual mode, and use this language. */ 1605796c8dcSSimon Schubert if (languages[i]->la_language == language_auto) 1615796c8dcSSimon Schubert { 1625796c8dcSSimon Schubert /* Enter auto mode. Set to the current frame's language, if 1635796c8dcSSimon Schubert known, or fallback to the initial language. */ 1645796c8dcSSimon Schubert language_mode = language_mode_auto; 1655796c8dcSSimon Schubert flang = get_frame_language (); 1665796c8dcSSimon Schubert if (flang != language_unknown) 1675796c8dcSSimon Schubert set_language (flang); 1685796c8dcSSimon Schubert else 1695796c8dcSSimon Schubert set_initial_language (); 1705796c8dcSSimon Schubert expected_language = current_language; 1715796c8dcSSimon Schubert return; 1725796c8dcSSimon Schubert } 1735796c8dcSSimon Schubert else 1745796c8dcSSimon Schubert { 1755796c8dcSSimon Schubert /* Enter manual mode. Set the specified language. */ 1765796c8dcSSimon Schubert language_mode = language_mode_manual; 1775796c8dcSSimon Schubert current_language = languages[i]; 1785796c8dcSSimon Schubert set_type_range_case (); 1795796c8dcSSimon Schubert expected_language = current_language; 1805796c8dcSSimon Schubert return; 1815796c8dcSSimon Schubert } 1825796c8dcSSimon Schubert } 1835796c8dcSSimon Schubert } 1845796c8dcSSimon Schubert 1855796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 1865796c8dcSSimon Schubert "Couldn't find language `%s' in known languages list.", 1875796c8dcSSimon Schubert language); 1885796c8dcSSimon Schubert } 1895796c8dcSSimon Schubert 1905796c8dcSSimon Schubert /* Show command. Display a warning if the type setting does 1915796c8dcSSimon Schubert not match the current language. */ 1925796c8dcSSimon Schubert static void 1935796c8dcSSimon Schubert show_type_command (struct ui_file *file, int from_tty, 1945796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1955796c8dcSSimon Schubert { 1965796c8dcSSimon Schubert if (type_mode == type_mode_auto) 1975796c8dcSSimon Schubert { 1985796c8dcSSimon Schubert char *tmp = NULL; 1995796c8dcSSimon Schubert 2005796c8dcSSimon Schubert switch (type_check) 2015796c8dcSSimon Schubert { 2025796c8dcSSimon Schubert case type_check_on: 2035796c8dcSSimon Schubert tmp = "on"; 2045796c8dcSSimon Schubert break; 2055796c8dcSSimon Schubert case type_check_off: 2065796c8dcSSimon Schubert tmp = "off"; 2075796c8dcSSimon Schubert break; 2085796c8dcSSimon Schubert case type_check_warn: 2095796c8dcSSimon Schubert tmp = "warn"; 2105796c8dcSSimon Schubert break; 2115796c8dcSSimon Schubert default: 2125796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 2135796c8dcSSimon Schubert "Unrecognized type check setting."); 2145796c8dcSSimon Schubert } 2155796c8dcSSimon Schubert 2165796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 2175796c8dcSSimon Schubert _("Type checking is \"auto; currently %s\".\n"), 2185796c8dcSSimon Schubert tmp); 2195796c8dcSSimon Schubert } 2205796c8dcSSimon Schubert else 2215796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Type checking is \"%s\".\n"), 2225796c8dcSSimon Schubert value); 2235796c8dcSSimon Schubert 2245796c8dcSSimon Schubert if (type_check != current_language->la_type_check) 2255796c8dcSSimon Schubert warning (_("the current type check setting" 2265796c8dcSSimon Schubert " does not match the language.\n")); 2275796c8dcSSimon Schubert } 2285796c8dcSSimon Schubert 2295796c8dcSSimon Schubert /* Set command. Change the setting for type checking. */ 2305796c8dcSSimon Schubert static void 2315796c8dcSSimon Schubert set_type_command (char *ignore, int from_tty, struct cmd_list_element *c) 2325796c8dcSSimon Schubert { 2335796c8dcSSimon Schubert if (strcmp (type, "on") == 0) 2345796c8dcSSimon Schubert { 2355796c8dcSSimon Schubert type_check = type_check_on; 2365796c8dcSSimon Schubert type_mode = type_mode_manual; 2375796c8dcSSimon Schubert } 2385796c8dcSSimon Schubert else if (strcmp (type, "warn") == 0) 2395796c8dcSSimon Schubert { 2405796c8dcSSimon Schubert type_check = type_check_warn; 2415796c8dcSSimon Schubert type_mode = type_mode_manual; 2425796c8dcSSimon Schubert } 2435796c8dcSSimon Schubert else if (strcmp (type, "off") == 0) 2445796c8dcSSimon Schubert { 2455796c8dcSSimon Schubert type_check = type_check_off; 2465796c8dcSSimon Schubert type_mode = type_mode_manual; 2475796c8dcSSimon Schubert } 2485796c8dcSSimon Schubert else if (strcmp (type, "auto") == 0) 2495796c8dcSSimon Schubert { 2505796c8dcSSimon Schubert type_mode = type_mode_auto; 2515796c8dcSSimon Schubert set_type_range_case (); 2525796c8dcSSimon Schubert return; 2535796c8dcSSimon Schubert } 2545796c8dcSSimon Schubert else 2555796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 2565796c8dcSSimon Schubert _("Unrecognized type check setting: \"%s\""), type); 2575796c8dcSSimon Schubert 2585796c8dcSSimon Schubert if (type_check != current_language->la_type_check) 2595796c8dcSSimon Schubert warning (_("the current type check setting" 2605796c8dcSSimon Schubert " does not match the language.\n")); 2615796c8dcSSimon Schubert } 2625796c8dcSSimon Schubert 2635796c8dcSSimon Schubert /* Show command. Display a warning if the range setting does 2645796c8dcSSimon Schubert not match the current language. */ 2655796c8dcSSimon Schubert static void 2665796c8dcSSimon Schubert show_range_command (struct ui_file *file, int from_tty, 2675796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 2685796c8dcSSimon Schubert { 2695796c8dcSSimon Schubert if (range_mode == range_mode_auto) 2705796c8dcSSimon Schubert { 2715796c8dcSSimon Schubert char *tmp; 2725796c8dcSSimon Schubert 2735796c8dcSSimon Schubert switch (range_check) 2745796c8dcSSimon Schubert { 2755796c8dcSSimon Schubert case range_check_on: 2765796c8dcSSimon Schubert tmp = "on"; 2775796c8dcSSimon Schubert break; 2785796c8dcSSimon Schubert case range_check_off: 2795796c8dcSSimon Schubert tmp = "off"; 2805796c8dcSSimon Schubert break; 2815796c8dcSSimon Schubert case range_check_warn: 2825796c8dcSSimon Schubert tmp = "warn"; 2835796c8dcSSimon Schubert break; 2845796c8dcSSimon Schubert default: 2855796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 2865796c8dcSSimon Schubert "Unrecognized range check setting."); 2875796c8dcSSimon Schubert } 2885796c8dcSSimon Schubert 2895796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 2905796c8dcSSimon Schubert _("Range checking is \"auto; currently %s\".\n"), 2915796c8dcSSimon Schubert tmp); 2925796c8dcSSimon Schubert } 2935796c8dcSSimon Schubert else 2945796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"), 2955796c8dcSSimon Schubert value); 2965796c8dcSSimon Schubert 2975796c8dcSSimon Schubert if (range_check != current_language->la_range_check) 2985796c8dcSSimon Schubert warning (_("the current range check setting " 2995796c8dcSSimon Schubert "does not match the language.\n")); 3005796c8dcSSimon Schubert } 3015796c8dcSSimon Schubert 3025796c8dcSSimon Schubert /* Set command. Change the setting for range checking. */ 3035796c8dcSSimon Schubert static void 3045796c8dcSSimon Schubert set_range_command (char *ignore, int from_tty, struct cmd_list_element *c) 3055796c8dcSSimon Schubert { 3065796c8dcSSimon Schubert if (strcmp (range, "on") == 0) 3075796c8dcSSimon Schubert { 3085796c8dcSSimon Schubert range_check = range_check_on; 3095796c8dcSSimon Schubert range_mode = range_mode_manual; 3105796c8dcSSimon Schubert } 3115796c8dcSSimon Schubert else if (strcmp (range, "warn") == 0) 3125796c8dcSSimon Schubert { 3135796c8dcSSimon Schubert range_check = range_check_warn; 3145796c8dcSSimon Schubert range_mode = range_mode_manual; 3155796c8dcSSimon Schubert } 3165796c8dcSSimon Schubert else if (strcmp (range, "off") == 0) 3175796c8dcSSimon Schubert { 3185796c8dcSSimon Schubert range_check = range_check_off; 3195796c8dcSSimon Schubert range_mode = range_mode_manual; 3205796c8dcSSimon Schubert } 3215796c8dcSSimon Schubert else if (strcmp (range, "auto") == 0) 3225796c8dcSSimon Schubert { 3235796c8dcSSimon Schubert range_mode = range_mode_auto; 3245796c8dcSSimon Schubert set_type_range_case (); 3255796c8dcSSimon Schubert return; 3265796c8dcSSimon Schubert } 3275796c8dcSSimon Schubert else 3285796c8dcSSimon Schubert { 3295796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3305796c8dcSSimon Schubert _("Unrecognized range check setting: \"%s\""), range); 3315796c8dcSSimon Schubert } 3325796c8dcSSimon Schubert if (range_check != current_language->la_range_check) 3335796c8dcSSimon Schubert warning (_("the current range check setting " 3345796c8dcSSimon Schubert "does not match the language.\n")); 3355796c8dcSSimon Schubert } 3365796c8dcSSimon Schubert 3375796c8dcSSimon Schubert /* Show command. Display a warning if the case sensitivity setting does 3385796c8dcSSimon Schubert not match the current language. */ 3395796c8dcSSimon Schubert static void 3405796c8dcSSimon Schubert show_case_command (struct ui_file *file, int from_tty, 3415796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 3425796c8dcSSimon Schubert { 3435796c8dcSSimon Schubert if (case_mode == case_mode_auto) 3445796c8dcSSimon Schubert { 3455796c8dcSSimon Schubert char *tmp = NULL; 3465796c8dcSSimon Schubert 3475796c8dcSSimon Schubert switch (case_sensitivity) 3485796c8dcSSimon Schubert { 3495796c8dcSSimon Schubert case case_sensitive_on: 3505796c8dcSSimon Schubert tmp = "on"; 3515796c8dcSSimon Schubert break; 3525796c8dcSSimon Schubert case case_sensitive_off: 3535796c8dcSSimon Schubert tmp = "off"; 3545796c8dcSSimon Schubert break; 3555796c8dcSSimon Schubert default: 3565796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3575796c8dcSSimon Schubert "Unrecognized case-sensitive setting."); 3585796c8dcSSimon Schubert } 3595796c8dcSSimon Schubert 3605796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 3615796c8dcSSimon Schubert _("Case sensitivity in " 3625796c8dcSSimon Schubert "name search is \"auto; currently %s\".\n"), 3635796c8dcSSimon Schubert tmp); 3645796c8dcSSimon Schubert } 3655796c8dcSSimon Schubert else 366*c50c785cSJohn Marino fprintf_filtered (gdb_stdout, 367*c50c785cSJohn Marino _("Case sensitivity in name search is \"%s\".\n"), 3685796c8dcSSimon Schubert value); 3695796c8dcSSimon Schubert 3705796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity) 3715796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match " 3725796c8dcSSimon Schubert "the language.\n")); 3735796c8dcSSimon Schubert } 3745796c8dcSSimon Schubert 3755796c8dcSSimon Schubert /* Set command. Change the setting for case sensitivity. */ 3765796c8dcSSimon Schubert 3775796c8dcSSimon Schubert static void 3785796c8dcSSimon Schubert set_case_command (char *ignore, int from_tty, struct cmd_list_element *c) 3795796c8dcSSimon Schubert { 3805796c8dcSSimon Schubert if (strcmp (case_sensitive, "on") == 0) 3815796c8dcSSimon Schubert { 3825796c8dcSSimon Schubert case_sensitivity = case_sensitive_on; 3835796c8dcSSimon Schubert case_mode = case_mode_manual; 3845796c8dcSSimon Schubert } 3855796c8dcSSimon Schubert else if (strcmp (case_sensitive, "off") == 0) 3865796c8dcSSimon Schubert { 3875796c8dcSSimon Schubert case_sensitivity = case_sensitive_off; 3885796c8dcSSimon Schubert case_mode = case_mode_manual; 3895796c8dcSSimon Schubert } 3905796c8dcSSimon Schubert else if (strcmp (case_sensitive, "auto") == 0) 3915796c8dcSSimon Schubert { 3925796c8dcSSimon Schubert case_mode = case_mode_auto; 3935796c8dcSSimon Schubert set_type_range_case (); 3945796c8dcSSimon Schubert return; 3955796c8dcSSimon Schubert } 3965796c8dcSSimon Schubert else 3975796c8dcSSimon Schubert { 3985796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3995796c8dcSSimon Schubert "Unrecognized case-sensitive setting: \"%s\"", 4005796c8dcSSimon Schubert case_sensitive); 4015796c8dcSSimon Schubert } 4025796c8dcSSimon Schubert 4035796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity) 4045796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match " 4055796c8dcSSimon Schubert "the language.\n")); 4065796c8dcSSimon Schubert } 4075796c8dcSSimon Schubert 4085796c8dcSSimon Schubert /* Set the status of range and type checking and case sensitivity based on 4095796c8dcSSimon Schubert the current modes and the current language. 4105796c8dcSSimon Schubert If SHOW is non-zero, then print out the current language, 4115796c8dcSSimon Schubert type and range checking status. */ 4125796c8dcSSimon Schubert static void 4135796c8dcSSimon Schubert set_type_range_case (void) 4145796c8dcSSimon Schubert { 4155796c8dcSSimon Schubert if (range_mode == range_mode_auto) 4165796c8dcSSimon Schubert range_check = current_language->la_range_check; 4175796c8dcSSimon Schubert 4185796c8dcSSimon Schubert if (type_mode == type_mode_auto) 4195796c8dcSSimon Schubert type_check = current_language->la_type_check; 4205796c8dcSSimon Schubert 4215796c8dcSSimon Schubert if (case_mode == case_mode_auto) 4225796c8dcSSimon Schubert case_sensitivity = current_language->la_case_sensitivity; 4235796c8dcSSimon Schubert } 4245796c8dcSSimon Schubert 425*c50c785cSJohn Marino /* Set current language to (enum language) LANG. Returns previous 426*c50c785cSJohn Marino language. */ 4275796c8dcSSimon Schubert 4285796c8dcSSimon Schubert enum language 4295796c8dcSSimon Schubert set_language (enum language lang) 4305796c8dcSSimon Schubert { 4315796c8dcSSimon Schubert int i; 4325796c8dcSSimon Schubert enum language prev_language; 4335796c8dcSSimon Schubert 4345796c8dcSSimon Schubert prev_language = current_language->la_language; 4355796c8dcSSimon Schubert 4365796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 4375796c8dcSSimon Schubert { 4385796c8dcSSimon Schubert if (languages[i]->la_language == lang) 4395796c8dcSSimon Schubert { 4405796c8dcSSimon Schubert current_language = languages[i]; 4415796c8dcSSimon Schubert set_type_range_case (); 4425796c8dcSSimon Schubert break; 4435796c8dcSSimon Schubert } 4445796c8dcSSimon Schubert } 4455796c8dcSSimon Schubert 4465796c8dcSSimon Schubert return prev_language; 4475796c8dcSSimon Schubert } 4485796c8dcSSimon Schubert 4495796c8dcSSimon Schubert 4505796c8dcSSimon Schubert /* Print out the current language settings: language, range and 4515796c8dcSSimon Schubert type checking. If QUIETLY, print only what has changed. */ 4525796c8dcSSimon Schubert 4535796c8dcSSimon Schubert void 4545796c8dcSSimon Schubert language_info (int quietly) 4555796c8dcSSimon Schubert { 4565796c8dcSSimon Schubert if (quietly && expected_language == current_language) 4575796c8dcSSimon Schubert return; 4585796c8dcSSimon Schubert 4595796c8dcSSimon Schubert expected_language = current_language; 4605796c8dcSSimon Schubert printf_unfiltered (_("Current language: %s\n"), language); 4615796c8dcSSimon Schubert show_language_command (NULL, 1, NULL, NULL); 4625796c8dcSSimon Schubert 4635796c8dcSSimon Schubert if (!quietly) 4645796c8dcSSimon Schubert { 4655796c8dcSSimon Schubert printf_unfiltered (_("Type checking: %s\n"), type); 4665796c8dcSSimon Schubert show_type_command (NULL, 1, NULL, NULL); 4675796c8dcSSimon Schubert printf_unfiltered (_("Range checking: %s\n"), range); 4685796c8dcSSimon Schubert show_range_command (NULL, 1, NULL, NULL); 4695796c8dcSSimon Schubert printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive); 4705796c8dcSSimon Schubert show_case_command (NULL, 1, NULL, NULL); 4715796c8dcSSimon Schubert } 4725796c8dcSSimon Schubert } 4735796c8dcSSimon Schubert 4745796c8dcSSimon Schubert /* Return the result of a binary operation. */ 4755796c8dcSSimon Schubert 4765796c8dcSSimon Schubert #if 0 /* Currently unused */ 4775796c8dcSSimon Schubert 4785796c8dcSSimon Schubert struct type * 4795796c8dcSSimon Schubert binop_result_type (struct value *v1, struct value *v2) 4805796c8dcSSimon Schubert { 4815796c8dcSSimon Schubert int size, uns; 4825796c8dcSSimon Schubert struct type *t1 = check_typedef (VALUE_TYPE (v1)); 4835796c8dcSSimon Schubert struct type *t2 = check_typedef (VALUE_TYPE (v2)); 4845796c8dcSSimon Schubert 4855796c8dcSSimon Schubert int l1 = TYPE_LENGTH (t1); 4865796c8dcSSimon Schubert int l2 = TYPE_LENGTH (t2); 4875796c8dcSSimon Schubert 4885796c8dcSSimon Schubert switch (current_language->la_language) 4895796c8dcSSimon Schubert { 4905796c8dcSSimon Schubert case language_c: 4915796c8dcSSimon Schubert case language_cplus: 492cf7f2e2dSJohn Marino case language_d: 4935796c8dcSSimon Schubert case language_objc: 4945796c8dcSSimon Schubert if (TYPE_CODE (t1) == TYPE_CODE_FLT) 4955796c8dcSSimon Schubert return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ? 4965796c8dcSSimon Schubert VALUE_TYPE (v2) : VALUE_TYPE (v1); 4975796c8dcSSimon Schubert else if (TYPE_CODE (t2) == TYPE_CODE_FLT) 4985796c8dcSSimon Schubert return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ? 4995796c8dcSSimon Schubert VALUE_TYPE (v1) : VALUE_TYPE (v2); 5005796c8dcSSimon Schubert else if (TYPE_UNSIGNED (t1) && l1 > l2) 5015796c8dcSSimon Schubert return VALUE_TYPE (v1); 5025796c8dcSSimon Schubert else if (TYPE_UNSIGNED (t2) && l2 > l1) 5035796c8dcSSimon Schubert return VALUE_TYPE (v2); 504*c50c785cSJohn Marino else /* Both are signed. Result is the 505*c50c785cSJohn Marino longer type. */ 5065796c8dcSSimon Schubert return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 5075796c8dcSSimon Schubert break; 5085796c8dcSSimon Schubert case language_m2: 5095796c8dcSSimon Schubert /* If we are doing type-checking, l1 should equal l2, so this is 5105796c8dcSSimon Schubert not needed. */ 5115796c8dcSSimon Schubert return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 5125796c8dcSSimon Schubert break; 5135796c8dcSSimon Schubert } 5145796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("failed internal consistency check")); 5155796c8dcSSimon Schubert return (struct type *) 0; /* For lint */ 5165796c8dcSSimon Schubert } 5175796c8dcSSimon Schubert 5185796c8dcSSimon Schubert #endif /* 0 */ 5195796c8dcSSimon Schubert #if 0 5205796c8dcSSimon Schubert /* This page contains functions that are used in type/range checking. 5215796c8dcSSimon Schubert They all return zero if the type/range check fails. 5225796c8dcSSimon Schubert 5235796c8dcSSimon Schubert It is hoped that these will make extending GDB to parse different 5245796c8dcSSimon Schubert languages a little easier. These are primarily used in eval.c when 5255796c8dcSSimon Schubert evaluating expressions and making sure that their types are correct. 5265796c8dcSSimon Schubert Instead of having a mess of conjucted/disjuncted expressions in an "if", 5275796c8dcSSimon Schubert the ideas of type can be wrapped up in the following functions. 5285796c8dcSSimon Schubert 5295796c8dcSSimon Schubert Note that some of them are not currently dependent upon which language 5305796c8dcSSimon Schubert is currently being parsed. For example, floats are the same in 5315796c8dcSSimon Schubert C and Modula-2 (ie. the only floating point type has TYPE_CODE of 5325796c8dcSSimon Schubert TYPE_CODE_FLT), while booleans are different. */ 5335796c8dcSSimon Schubert 5345796c8dcSSimon Schubert /* Returns non-zero if its argument is a simple type. This is the same for 5355796c8dcSSimon Schubert both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur, 5365796c8dcSSimon Schubert and thus will never cause the failure of the test. */ 5375796c8dcSSimon Schubert int 5385796c8dcSSimon Schubert simple_type (struct type *type) 5395796c8dcSSimon Schubert { 5405796c8dcSSimon Schubert CHECK_TYPEDEF (type); 5415796c8dcSSimon Schubert switch (TYPE_CODE (type)) 5425796c8dcSSimon Schubert { 5435796c8dcSSimon Schubert case TYPE_CODE_INT: 5445796c8dcSSimon Schubert case TYPE_CODE_CHAR: 5455796c8dcSSimon Schubert case TYPE_CODE_ENUM: 5465796c8dcSSimon Schubert case TYPE_CODE_FLT: 5475796c8dcSSimon Schubert case TYPE_CODE_RANGE: 5485796c8dcSSimon Schubert case TYPE_CODE_BOOL: 5495796c8dcSSimon Schubert return 1; 5505796c8dcSSimon Schubert 5515796c8dcSSimon Schubert default: 5525796c8dcSSimon Schubert return 0; 5535796c8dcSSimon Schubert } 5545796c8dcSSimon Schubert } 5555796c8dcSSimon Schubert 5565796c8dcSSimon Schubert /* Returns non-zero if its argument is of an ordered type. 5575796c8dcSSimon Schubert An ordered type is one in which the elements can be tested for the 5585796c8dcSSimon Schubert properties of "greater than", "less than", etc, or for which the 5595796c8dcSSimon Schubert operations "increment" or "decrement" make sense. */ 5605796c8dcSSimon Schubert int 5615796c8dcSSimon Schubert ordered_type (struct type *type) 5625796c8dcSSimon Schubert { 5635796c8dcSSimon Schubert CHECK_TYPEDEF (type); 5645796c8dcSSimon Schubert switch (TYPE_CODE (type)) 5655796c8dcSSimon Schubert { 5665796c8dcSSimon Schubert case TYPE_CODE_INT: 5675796c8dcSSimon Schubert case TYPE_CODE_CHAR: 5685796c8dcSSimon Schubert case TYPE_CODE_ENUM: 5695796c8dcSSimon Schubert case TYPE_CODE_FLT: 5705796c8dcSSimon Schubert case TYPE_CODE_RANGE: 5715796c8dcSSimon Schubert return 1; 5725796c8dcSSimon Schubert 5735796c8dcSSimon Schubert default: 5745796c8dcSSimon Schubert return 0; 5755796c8dcSSimon Schubert } 5765796c8dcSSimon Schubert } 5775796c8dcSSimon Schubert 578*c50c785cSJohn Marino /* Returns non-zero if the two types are the same. */ 5795796c8dcSSimon Schubert int 5805796c8dcSSimon Schubert same_type (struct type *arg1, struct type *arg2) 5815796c8dcSSimon Schubert { 5825796c8dcSSimon Schubert CHECK_TYPEDEF (type); 583*c50c785cSJohn Marino if (structured_type (arg1) 584*c50c785cSJohn Marino ? !structured_type (arg2) : structured_type (arg2)) 585*c50c785cSJohn Marino /* One is structured and one isn't. */ 5865796c8dcSSimon Schubert return 0; 5875796c8dcSSimon Schubert else if (structured_type (arg1) && structured_type (arg2)) 5885796c8dcSSimon Schubert return arg1 == arg2; 5895796c8dcSSimon Schubert else if (numeric_type (arg1) && numeric_type (arg2)) 5905796c8dcSSimon Schubert return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) && 5915796c8dcSSimon Schubert (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2)) 5925796c8dcSSimon Schubert ? 1 : 0; 5935796c8dcSSimon Schubert else 5945796c8dcSSimon Schubert return arg1 == arg2; 5955796c8dcSSimon Schubert } 5965796c8dcSSimon Schubert 597*c50c785cSJohn Marino /* Returns non-zero if the type is integral. */ 5985796c8dcSSimon Schubert int 5995796c8dcSSimon Schubert integral_type (struct type *type) 6005796c8dcSSimon Schubert { 6015796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6025796c8dcSSimon Schubert switch (current_language->la_language) 6035796c8dcSSimon Schubert { 6045796c8dcSSimon Schubert case language_c: 6055796c8dcSSimon Schubert case language_cplus: 606cf7f2e2dSJohn Marino case language_d: 6075796c8dcSSimon Schubert case language_objc: 6085796c8dcSSimon Schubert return (TYPE_CODE (type) != TYPE_CODE_INT) && 6095796c8dcSSimon Schubert (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1; 6105796c8dcSSimon Schubert case language_m2: 6115796c8dcSSimon Schubert case language_pascal: 6125796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1; 6135796c8dcSSimon Schubert default: 6145796c8dcSSimon Schubert error (_("Language not supported.")); 6155796c8dcSSimon Schubert } 6165796c8dcSSimon Schubert } 6175796c8dcSSimon Schubert 618*c50c785cSJohn Marino /* Returns non-zero if the value is numeric. */ 6195796c8dcSSimon Schubert int 6205796c8dcSSimon Schubert numeric_type (struct type *type) 6215796c8dcSSimon Schubert { 6225796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6235796c8dcSSimon Schubert switch (TYPE_CODE (type)) 6245796c8dcSSimon Schubert { 6255796c8dcSSimon Schubert case TYPE_CODE_INT: 6265796c8dcSSimon Schubert case TYPE_CODE_FLT: 6275796c8dcSSimon Schubert return 1; 6285796c8dcSSimon Schubert 6295796c8dcSSimon Schubert default: 6305796c8dcSSimon Schubert return 0; 6315796c8dcSSimon Schubert } 6325796c8dcSSimon Schubert } 6335796c8dcSSimon Schubert 634*c50c785cSJohn Marino /* Returns non-zero if the value is a character type. */ 6355796c8dcSSimon Schubert int 6365796c8dcSSimon Schubert character_type (struct type *type) 6375796c8dcSSimon Schubert { 6385796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6395796c8dcSSimon Schubert switch (current_language->la_language) 6405796c8dcSSimon Schubert { 6415796c8dcSSimon Schubert case language_m2: 6425796c8dcSSimon Schubert case language_pascal: 6435796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1; 6445796c8dcSSimon Schubert 6455796c8dcSSimon Schubert case language_c: 6465796c8dcSSimon Schubert case language_cplus: 647cf7f2e2dSJohn Marino case language_d: 6485796c8dcSSimon Schubert case language_objc: 6495796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_INT) && 6505796c8dcSSimon Schubert TYPE_LENGTH (type) == sizeof (char) 6515796c8dcSSimon Schubert ? 1 : 0; 6525796c8dcSSimon Schubert default: 6535796c8dcSSimon Schubert return (0); 6545796c8dcSSimon Schubert } 6555796c8dcSSimon Schubert } 6565796c8dcSSimon Schubert 657*c50c785cSJohn Marino /* Returns non-zero if the value is a string type. */ 6585796c8dcSSimon Schubert int 6595796c8dcSSimon Schubert string_type (struct type *type) 6605796c8dcSSimon Schubert { 6615796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6625796c8dcSSimon Schubert switch (current_language->la_language) 6635796c8dcSSimon Schubert { 6645796c8dcSSimon Schubert case language_m2: 6655796c8dcSSimon Schubert case language_pascal: 6665796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1; 6675796c8dcSSimon Schubert 6685796c8dcSSimon Schubert case language_c: 6695796c8dcSSimon Schubert case language_cplus: 670cf7f2e2dSJohn Marino case language_d: 6715796c8dcSSimon Schubert case language_objc: 6725796c8dcSSimon Schubert /* C does not have distinct string type. */ 6735796c8dcSSimon Schubert return (0); 6745796c8dcSSimon Schubert default: 6755796c8dcSSimon Schubert return (0); 6765796c8dcSSimon Schubert } 6775796c8dcSSimon Schubert } 6785796c8dcSSimon Schubert 679*c50c785cSJohn Marino /* Returns non-zero if the value is a boolean type. */ 6805796c8dcSSimon Schubert int 6815796c8dcSSimon Schubert boolean_type (struct type *type) 6825796c8dcSSimon Schubert { 6835796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6845796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_BOOL) 6855796c8dcSSimon Schubert return 1; 6865796c8dcSSimon Schubert switch (current_language->la_language) 6875796c8dcSSimon Schubert { 6885796c8dcSSimon Schubert case language_c: 6895796c8dcSSimon Schubert case language_cplus: 690cf7f2e2dSJohn Marino case language_d: 6915796c8dcSSimon Schubert case language_objc: 6925796c8dcSSimon Schubert /* Might be more cleanly handled by having a 6935796c8dcSSimon Schubert TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such 6945796c8dcSSimon Schubert languages, or a TYPE_CODE_INT_OR_BOOL for C. */ 6955796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_INT) 6965796c8dcSSimon Schubert return 1; 6975796c8dcSSimon Schubert default: 6985796c8dcSSimon Schubert break; 6995796c8dcSSimon Schubert } 7005796c8dcSSimon Schubert return 0; 7015796c8dcSSimon Schubert } 7025796c8dcSSimon Schubert 703*c50c785cSJohn Marino /* Returns non-zero if the value is a floating-point type. */ 7045796c8dcSSimon Schubert int 7055796c8dcSSimon Schubert float_type (struct type *type) 7065796c8dcSSimon Schubert { 7075796c8dcSSimon Schubert CHECK_TYPEDEF (type); 7085796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_FLT; 7095796c8dcSSimon Schubert } 710cf7f2e2dSJohn Marino #endif 7115796c8dcSSimon Schubert 712*c50c785cSJohn Marino /* Returns non-zero if the value is a pointer type. */ 7135796c8dcSSimon Schubert int 7145796c8dcSSimon Schubert pointer_type (struct type *type) 7155796c8dcSSimon Schubert { 7165796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_PTR || 7175796c8dcSSimon Schubert TYPE_CODE (type) == TYPE_CODE_REF; 7185796c8dcSSimon Schubert } 7195796c8dcSSimon Schubert 720cf7f2e2dSJohn Marino #if 0 721*c50c785cSJohn Marino /* Returns non-zero if the value is a structured type. */ 7225796c8dcSSimon Schubert int 7235796c8dcSSimon Schubert structured_type (struct type *type) 7245796c8dcSSimon Schubert { 7255796c8dcSSimon Schubert CHECK_TYPEDEF (type); 7265796c8dcSSimon Schubert switch (current_language->la_language) 7275796c8dcSSimon Schubert { 7285796c8dcSSimon Schubert case language_c: 7295796c8dcSSimon Schubert case language_cplus: 730cf7f2e2dSJohn Marino case language_d: 7315796c8dcSSimon Schubert case language_objc: 7325796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 7335796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_UNION) || 7345796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_ARRAY); 7355796c8dcSSimon Schubert case language_pascal: 7365796c8dcSSimon Schubert return (TYPE_CODE(type) == TYPE_CODE_STRUCT) || 7375796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_UNION) || 7385796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_SET) || 7395796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_ARRAY); 7405796c8dcSSimon Schubert case language_m2: 7415796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 7425796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_SET) || 7435796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_ARRAY); 7445796c8dcSSimon Schubert default: 7455796c8dcSSimon Schubert return (0); 7465796c8dcSSimon Schubert } 7475796c8dcSSimon Schubert } 7485796c8dcSSimon Schubert #endif 7495796c8dcSSimon Schubert 7505796c8dcSSimon Schubert /* This page contains functions that return info about 7515796c8dcSSimon Schubert (struct value) values used in GDB. */ 7525796c8dcSSimon Schubert 7535796c8dcSSimon Schubert /* Returns non-zero if the value VAL represents a true value. */ 7545796c8dcSSimon Schubert int 7555796c8dcSSimon Schubert value_true (struct value *val) 7565796c8dcSSimon Schubert { 7575796c8dcSSimon Schubert /* It is possible that we should have some sort of error if a non-boolean 7585796c8dcSSimon Schubert value is used in this context. Possibly dependent on some kind of 7595796c8dcSSimon Schubert "boolean-checking" option like range checking. But it should probably 7605796c8dcSSimon Schubert not depend on the language except insofar as is necessary to identify 7615796c8dcSSimon Schubert a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean 7625796c8dcSSimon Schubert should be an error, probably). */ 7635796c8dcSSimon Schubert return !value_logical_not (val); 7645796c8dcSSimon Schubert } 7655796c8dcSSimon Schubert 7665796c8dcSSimon Schubert /* This page contains functions for the printing out of 7675796c8dcSSimon Schubert error messages that occur during type- and range- 7685796c8dcSSimon Schubert checking. */ 7695796c8dcSSimon Schubert 7705796c8dcSSimon Schubert /* These are called when a language fails a type- or range-check. The 7715796c8dcSSimon Schubert first argument should be a printf()-style format string, and the 7725796c8dcSSimon Schubert rest of the arguments should be its arguments. If 7735796c8dcSSimon Schubert [type|range]_check is [type|range]_check_on, an error is printed; 7745796c8dcSSimon Schubert if [type|range]_check_warn, a warning; otherwise just the 7755796c8dcSSimon Schubert message. */ 7765796c8dcSSimon Schubert 7775796c8dcSSimon Schubert void 7785796c8dcSSimon Schubert type_error (const char *string,...) 7795796c8dcSSimon Schubert { 7805796c8dcSSimon Schubert va_list args; 7815796c8dcSSimon Schubert 782cf7f2e2dSJohn Marino va_start (args, string); 7835796c8dcSSimon Schubert switch (type_check) 7845796c8dcSSimon Schubert { 7855796c8dcSSimon Schubert case type_check_warn: 7865796c8dcSSimon Schubert vwarning (string, args); 7875796c8dcSSimon Schubert break; 7885796c8dcSSimon Schubert case type_check_on: 7895796c8dcSSimon Schubert verror (string, args); 7905796c8dcSSimon Schubert break; 7915796c8dcSSimon Schubert case type_check_off: 7925796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything 7935796c8dcSSimon Schubert when type error is off? */ 7945796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args); 7955796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n"); 7965796c8dcSSimon Schubert break; 7975796c8dcSSimon Schubert default: 7985796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 7995796c8dcSSimon Schubert } 8005796c8dcSSimon Schubert va_end (args); 8015796c8dcSSimon Schubert } 8025796c8dcSSimon Schubert 8035796c8dcSSimon Schubert void 8045796c8dcSSimon Schubert range_error (const char *string,...) 8055796c8dcSSimon Schubert { 8065796c8dcSSimon Schubert va_list args; 8075796c8dcSSimon Schubert 808cf7f2e2dSJohn Marino va_start (args, string); 8095796c8dcSSimon Schubert switch (range_check) 8105796c8dcSSimon Schubert { 8115796c8dcSSimon Schubert case range_check_warn: 8125796c8dcSSimon Schubert vwarning (string, args); 8135796c8dcSSimon Schubert break; 8145796c8dcSSimon Schubert case range_check_on: 8155796c8dcSSimon Schubert verror (string, args); 8165796c8dcSSimon Schubert break; 8175796c8dcSSimon Schubert case range_check_off: 8185796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything 8195796c8dcSSimon Schubert when range error is off? */ 8205796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args); 8215796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n"); 8225796c8dcSSimon Schubert break; 8235796c8dcSSimon Schubert default: 8245796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 8255796c8dcSSimon Schubert } 8265796c8dcSSimon Schubert va_end (args); 8275796c8dcSSimon Schubert } 8285796c8dcSSimon Schubert 8295796c8dcSSimon Schubert 830*c50c785cSJohn Marino /* This page contains miscellaneous functions. */ 8315796c8dcSSimon Schubert 8325796c8dcSSimon Schubert /* Return the language enum for a given language string. */ 8335796c8dcSSimon Schubert 8345796c8dcSSimon Schubert enum language 8355796c8dcSSimon Schubert language_enum (char *str) 8365796c8dcSSimon Schubert { 8375796c8dcSSimon Schubert int i; 8385796c8dcSSimon Schubert 8395796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8405796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, str) == 0) 8415796c8dcSSimon Schubert return languages[i]->la_language; 8425796c8dcSSimon Schubert 8435796c8dcSSimon Schubert return language_unknown; 8445796c8dcSSimon Schubert } 8455796c8dcSSimon Schubert 8465796c8dcSSimon Schubert /* Return the language struct for a given language enum. */ 8475796c8dcSSimon Schubert 8485796c8dcSSimon Schubert const struct language_defn * 8495796c8dcSSimon Schubert language_def (enum language lang) 8505796c8dcSSimon Schubert { 8515796c8dcSSimon Schubert int i; 8525796c8dcSSimon Schubert 8535796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8545796c8dcSSimon Schubert { 8555796c8dcSSimon Schubert if (languages[i]->la_language == lang) 8565796c8dcSSimon Schubert { 8575796c8dcSSimon Schubert return languages[i]; 8585796c8dcSSimon Schubert } 8595796c8dcSSimon Schubert } 8605796c8dcSSimon Schubert return NULL; 8615796c8dcSSimon Schubert } 8625796c8dcSSimon Schubert 863*c50c785cSJohn Marino /* Return the language as a string. */ 8645796c8dcSSimon Schubert char * 8655796c8dcSSimon Schubert language_str (enum language lang) 8665796c8dcSSimon Schubert { 8675796c8dcSSimon Schubert int i; 8685796c8dcSSimon Schubert 8695796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 8705796c8dcSSimon Schubert { 8715796c8dcSSimon Schubert if (languages[i]->la_language == lang) 8725796c8dcSSimon Schubert { 8735796c8dcSSimon Schubert return languages[i]->la_name; 8745796c8dcSSimon Schubert } 8755796c8dcSSimon Schubert } 8765796c8dcSSimon Schubert return "Unknown"; 8775796c8dcSSimon Schubert } 8785796c8dcSSimon Schubert 8795796c8dcSSimon Schubert static void 8805796c8dcSSimon Schubert set_check (char *ignore, int from_tty) 8815796c8dcSSimon Schubert { 8825796c8dcSSimon Schubert printf_unfiltered ( 8835796c8dcSSimon Schubert "\"set check\" must be followed by the name of a check subcommand.\n"); 8845796c8dcSSimon Schubert help_list (setchecklist, "set check ", -1, gdb_stdout); 8855796c8dcSSimon Schubert } 8865796c8dcSSimon Schubert 8875796c8dcSSimon Schubert static void 8885796c8dcSSimon Schubert show_check (char *ignore, int from_tty) 8895796c8dcSSimon Schubert { 8905796c8dcSSimon Schubert cmd_show_list (showchecklist, from_tty, ""); 8915796c8dcSSimon Schubert } 8925796c8dcSSimon Schubert 8935796c8dcSSimon Schubert /* Add a language to the set of known languages. */ 8945796c8dcSSimon Schubert 8955796c8dcSSimon Schubert void 8965796c8dcSSimon Schubert add_language (const struct language_defn *lang) 8975796c8dcSSimon Schubert { 8985796c8dcSSimon Schubert /* For the "set language" command. */ 8995796c8dcSSimon Schubert static char **language_names = NULL; 9005796c8dcSSimon Schubert /* For the "help set language" command. */ 9015796c8dcSSimon Schubert char *language_set_doc = NULL; 9025796c8dcSSimon Schubert 9035796c8dcSSimon Schubert int i; 9045796c8dcSSimon Schubert struct ui_file *tmp_stream; 9055796c8dcSSimon Schubert 9065796c8dcSSimon Schubert if (lang->la_magic != LANG_MAGIC) 9075796c8dcSSimon Schubert { 908*c50c785cSJohn Marino fprintf_unfiltered (gdb_stderr, 909*c50c785cSJohn Marino "Magic number of %s language struct wrong\n", 9105796c8dcSSimon Schubert lang->la_name); 911*c50c785cSJohn Marino internal_error (__FILE__, __LINE__, 912*c50c785cSJohn Marino _("failed internal consistency check")); 9135796c8dcSSimon Schubert } 9145796c8dcSSimon Schubert 9155796c8dcSSimon Schubert if (!languages) 9165796c8dcSSimon Schubert { 9175796c8dcSSimon Schubert languages_allocsize = DEFAULT_ALLOCSIZE; 9185796c8dcSSimon Schubert languages = (const struct language_defn **) xmalloc 9195796c8dcSSimon Schubert (languages_allocsize * sizeof (*languages)); 9205796c8dcSSimon Schubert } 9215796c8dcSSimon Schubert if (languages_size >= languages_allocsize) 9225796c8dcSSimon Schubert { 9235796c8dcSSimon Schubert languages_allocsize *= 2; 9245796c8dcSSimon Schubert languages = (const struct language_defn **) xrealloc ((char *) languages, 9255796c8dcSSimon Schubert languages_allocsize * sizeof (*languages)); 9265796c8dcSSimon Schubert } 9275796c8dcSSimon Schubert languages[languages_size++] = lang; 9285796c8dcSSimon Schubert 9295796c8dcSSimon Schubert /* Build the language names array, to be used as enumeration in the 9305796c8dcSSimon Schubert set language" enum command. */ 9315796c8dcSSimon Schubert language_names = xrealloc (language_names, 9325796c8dcSSimon Schubert (languages_size + 1) * sizeof (const char *)); 9335796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i) 9345796c8dcSSimon Schubert language_names[i] = languages[i]->la_name; 9355796c8dcSSimon Schubert language_names[i] = NULL; 9365796c8dcSSimon Schubert 9375796c8dcSSimon Schubert /* Build the "help set language" docs. */ 9385796c8dcSSimon Schubert tmp_stream = mem_fileopen (); 9395796c8dcSSimon Schubert 940*c50c785cSJohn Marino fprintf_unfiltered (tmp_stream, 941*c50c785cSJohn Marino _("Set the current source language.\n" 942*c50c785cSJohn Marino "The currently understood settings are:\n\nlocal or " 943*c50c785cSJohn Marino "auto Automatic setting based on source file\n")); 9445796c8dcSSimon Schubert 9455796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i) 9465796c8dcSSimon Schubert { 9475796c8dcSSimon Schubert /* Already dealt with these above. */ 9485796c8dcSSimon Schubert if (languages[i]->la_language == language_unknown 9495796c8dcSSimon Schubert || languages[i]->la_language == language_auto) 9505796c8dcSSimon Schubert continue; 9515796c8dcSSimon Schubert 9525796c8dcSSimon Schubert /* FIXME: i18n: for now assume that the human-readable name 9535796c8dcSSimon Schubert is just a capitalization of the internal name. */ 9545796c8dcSSimon Schubert fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n", 9555796c8dcSSimon Schubert languages[i]->la_name, 9565796c8dcSSimon Schubert /* Capitalize first letter of language 9575796c8dcSSimon Schubert name. */ 9585796c8dcSSimon Schubert toupper (languages[i]->la_name[0]), 9595796c8dcSSimon Schubert languages[i]->la_name + 1); 9605796c8dcSSimon Schubert } 9615796c8dcSSimon Schubert 9625796c8dcSSimon Schubert language_set_doc = ui_file_xstrdup (tmp_stream, NULL); 9635796c8dcSSimon Schubert ui_file_delete (tmp_stream); 9645796c8dcSSimon Schubert 9655796c8dcSSimon Schubert add_setshow_enum_cmd ("language", class_support, 9665796c8dcSSimon Schubert (const char **) language_names, 9675796c8dcSSimon Schubert &language, 968*c50c785cSJohn Marino language_set_doc, 969*c50c785cSJohn Marino _("Show the current source language."), 970*c50c785cSJohn Marino NULL, set_language_command, 9715796c8dcSSimon Schubert show_language_command, 9725796c8dcSSimon Schubert &setlist, &showlist); 9735796c8dcSSimon Schubert 9745796c8dcSSimon Schubert xfree (language_set_doc); 9755796c8dcSSimon Schubert } 9765796c8dcSSimon Schubert 9775796c8dcSSimon Schubert /* Iterate through all registered languages looking for and calling 9785796c8dcSSimon Schubert any non-NULL struct language_defn.skip_trampoline() functions. 9795796c8dcSSimon Schubert Return the result from the first that returns non-zero, or 0 if all 9805796c8dcSSimon Schubert `fail'. */ 9815796c8dcSSimon Schubert CORE_ADDR 9825796c8dcSSimon Schubert skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc) 9835796c8dcSSimon Schubert { 9845796c8dcSSimon Schubert int i; 9855796c8dcSSimon Schubert 9865796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 9875796c8dcSSimon Schubert { 9885796c8dcSSimon Schubert if (languages[i]->skip_trampoline) 9895796c8dcSSimon Schubert { 9905796c8dcSSimon Schubert CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc); 991cf7f2e2dSJohn Marino 9925796c8dcSSimon Schubert if (real_pc) 9935796c8dcSSimon Schubert return real_pc; 9945796c8dcSSimon Schubert } 9955796c8dcSSimon Schubert } 9965796c8dcSSimon Schubert 9975796c8dcSSimon Schubert return 0; 9985796c8dcSSimon Schubert } 9995796c8dcSSimon Schubert 10005796c8dcSSimon Schubert /* Return demangled language symbol, or NULL. 10015796c8dcSSimon Schubert FIXME: Options are only useful for certain languages and ignored 10025796c8dcSSimon Schubert by others, so it would be better to remove them here and have a 10035796c8dcSSimon Schubert more flexible demangler for the languages that need it. 10045796c8dcSSimon Schubert FIXME: Sometimes the demangler is invoked when we don't know the 10055796c8dcSSimon Schubert language, so we can't use this everywhere. */ 10065796c8dcSSimon Schubert char * 10075796c8dcSSimon Schubert language_demangle (const struct language_defn *current_language, 10085796c8dcSSimon Schubert const char *mangled, int options) 10095796c8dcSSimon Schubert { 10105796c8dcSSimon Schubert if (current_language != NULL && current_language->la_demangle) 10115796c8dcSSimon Schubert return current_language->la_demangle (mangled, options); 10125796c8dcSSimon Schubert return NULL; 10135796c8dcSSimon Schubert } 10145796c8dcSSimon Schubert 10155796c8dcSSimon Schubert /* Return class name from physname or NULL. */ 10165796c8dcSSimon Schubert char * 1017*c50c785cSJohn Marino language_class_name_from_physname (const struct language_defn *lang, 10185796c8dcSSimon Schubert const char *physname) 10195796c8dcSSimon Schubert { 1020*c50c785cSJohn Marino if (lang != NULL && lang->la_class_name_from_physname) 1021*c50c785cSJohn Marino return lang->la_class_name_from_physname (physname); 10225796c8dcSSimon Schubert return NULL; 10235796c8dcSSimon Schubert } 10245796c8dcSSimon Schubert 10255796c8dcSSimon Schubert /* Return non-zero if TYPE should be passed (and returned) by 10265796c8dcSSimon Schubert reference at the language level. */ 10275796c8dcSSimon Schubert int 10285796c8dcSSimon Schubert language_pass_by_reference (struct type *type) 10295796c8dcSSimon Schubert { 10305796c8dcSSimon Schubert return current_language->la_pass_by_reference (type); 10315796c8dcSSimon Schubert } 10325796c8dcSSimon Schubert 10335796c8dcSSimon Schubert /* Return zero; by default, types are passed by value at the language 10345796c8dcSSimon Schubert level. The target ABI may pass or return some structs by reference 10355796c8dcSSimon Schubert independent of this. */ 10365796c8dcSSimon Schubert int 10375796c8dcSSimon Schubert default_pass_by_reference (struct type *type) 10385796c8dcSSimon Schubert { 10395796c8dcSSimon Schubert return 0; 10405796c8dcSSimon Schubert } 10415796c8dcSSimon Schubert 10425796c8dcSSimon Schubert /* Return the default string containing the list of characters 10435796c8dcSSimon Schubert delimiting words. This is a reasonable default value that 10445796c8dcSSimon Schubert most languages should be able to use. */ 10455796c8dcSSimon Schubert 10465796c8dcSSimon Schubert char * 10475796c8dcSSimon Schubert default_word_break_characters (void) 10485796c8dcSSimon Schubert { 10495796c8dcSSimon Schubert return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; 10505796c8dcSSimon Schubert } 10515796c8dcSSimon Schubert 10525796c8dcSSimon Schubert /* Print the index of array elements using the C99 syntax. */ 10535796c8dcSSimon Schubert 10545796c8dcSSimon Schubert void 10555796c8dcSSimon Schubert default_print_array_index (struct value *index_value, struct ui_file *stream, 10565796c8dcSSimon Schubert const struct value_print_options *options) 10575796c8dcSSimon Schubert { 10585796c8dcSSimon Schubert fprintf_filtered (stream, "["); 10595796c8dcSSimon Schubert LA_VALUE_PRINT (index_value, stream, options); 10605796c8dcSSimon Schubert fprintf_filtered (stream, "] = "); 10615796c8dcSSimon Schubert } 10625796c8dcSSimon Schubert 10635796c8dcSSimon Schubert void 10645796c8dcSSimon Schubert default_get_string (struct value *value, gdb_byte **buffer, int *length, 1065cf7f2e2dSJohn Marino struct type **char_type, const char **charset) 10665796c8dcSSimon Schubert { 10675796c8dcSSimon Schubert error (_("Getting a string is unsupported in this language.")); 10685796c8dcSSimon Schubert } 10695796c8dcSSimon Schubert 10705796c8dcSSimon Schubert /* Define the language that is no language. */ 10715796c8dcSSimon Schubert 10725796c8dcSSimon Schubert static int 10735796c8dcSSimon Schubert unk_lang_parser (void) 10745796c8dcSSimon Schubert { 10755796c8dcSSimon Schubert return 1; 10765796c8dcSSimon Schubert } 10775796c8dcSSimon Schubert 10785796c8dcSSimon Schubert static void 10795796c8dcSSimon Schubert unk_lang_error (char *msg) 10805796c8dcSSimon Schubert { 10815796c8dcSSimon Schubert error (_("Attempted to parse an expression with unknown language")); 10825796c8dcSSimon Schubert } 10835796c8dcSSimon Schubert 10845796c8dcSSimon Schubert static void 10855796c8dcSSimon Schubert unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, 10865796c8dcSSimon Schubert int quoter) 10875796c8dcSSimon Schubert { 1088*c50c785cSJohn Marino error (_("internal error - unimplemented " 1089*c50c785cSJohn Marino "function unk_lang_emit_char called.")); 10905796c8dcSSimon Schubert } 10915796c8dcSSimon Schubert 10925796c8dcSSimon Schubert static void 10935796c8dcSSimon Schubert unk_lang_printchar (int c, struct type *type, struct ui_file *stream) 10945796c8dcSSimon Schubert { 1095*c50c785cSJohn Marino error (_("internal error - unimplemented " 1096*c50c785cSJohn Marino "function unk_lang_printchar called.")); 10975796c8dcSSimon Schubert } 10985796c8dcSSimon Schubert 10995796c8dcSSimon Schubert static void 11005796c8dcSSimon Schubert unk_lang_printstr (struct ui_file *stream, struct type *type, 11015796c8dcSSimon Schubert const gdb_byte *string, unsigned int length, 1102cf7f2e2dSJohn Marino const char *encoding, int force_ellipses, 11035796c8dcSSimon Schubert const struct value_print_options *options) 11045796c8dcSSimon Schubert { 1105*c50c785cSJohn Marino error (_("internal error - unimplemented " 1106*c50c785cSJohn Marino "function unk_lang_printstr called.")); 11075796c8dcSSimon Schubert } 11085796c8dcSSimon Schubert 11095796c8dcSSimon Schubert static void 1110cf7f2e2dSJohn Marino unk_lang_print_type (struct type *type, const char *varstring, 1111cf7f2e2dSJohn Marino struct ui_file *stream, int show, int level) 11125796c8dcSSimon Schubert { 1113*c50c785cSJohn Marino error (_("internal error - unimplemented " 1114*c50c785cSJohn Marino "function unk_lang_print_type called.")); 11155796c8dcSSimon Schubert } 11165796c8dcSSimon Schubert 11175796c8dcSSimon Schubert static int 11185796c8dcSSimon Schubert unk_lang_val_print (struct type *type, const gdb_byte *valaddr, 11195796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address, 11205796c8dcSSimon Schubert struct ui_file *stream, int recurse, 1121cf7f2e2dSJohn Marino const struct value *val, 11225796c8dcSSimon Schubert const struct value_print_options *options) 11235796c8dcSSimon Schubert { 1124*c50c785cSJohn Marino error (_("internal error - unimplemented " 1125*c50c785cSJohn Marino "function unk_lang_val_print called.")); 11265796c8dcSSimon Schubert } 11275796c8dcSSimon Schubert 11285796c8dcSSimon Schubert static int 11295796c8dcSSimon Schubert unk_lang_value_print (struct value *val, struct ui_file *stream, 11305796c8dcSSimon Schubert const struct value_print_options *options) 11315796c8dcSSimon Schubert { 1132*c50c785cSJohn Marino error (_("internal error - unimplemented " 1133*c50c785cSJohn Marino "function unk_lang_value_print called.")); 11345796c8dcSSimon Schubert } 11355796c8dcSSimon Schubert 11365796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) 11375796c8dcSSimon Schubert { 11385796c8dcSSimon Schubert return 0; 11395796c8dcSSimon Schubert } 11405796c8dcSSimon Schubert 11415796c8dcSSimon Schubert /* Unknown languages just use the cplus demangler. */ 11425796c8dcSSimon Schubert static char *unk_lang_demangle (const char *mangled, int options) 11435796c8dcSSimon Schubert { 11445796c8dcSSimon Schubert return cplus_demangle (mangled, options); 11455796c8dcSSimon Schubert } 11465796c8dcSSimon Schubert 11475796c8dcSSimon Schubert static char *unk_lang_class_name (const char *mangled) 11485796c8dcSSimon Schubert { 11495796c8dcSSimon Schubert return NULL; 11505796c8dcSSimon Schubert } 11515796c8dcSSimon Schubert 11525796c8dcSSimon Schubert static const struct op_print unk_op_print_tab[] = 11535796c8dcSSimon Schubert { 11545796c8dcSSimon Schubert {NULL, OP_NULL, PREC_NULL, 0} 11555796c8dcSSimon Schubert }; 11565796c8dcSSimon Schubert 11575796c8dcSSimon Schubert static void 11585796c8dcSSimon Schubert unknown_language_arch_info (struct gdbarch *gdbarch, 11595796c8dcSSimon Schubert struct language_arch_info *lai) 11605796c8dcSSimon Schubert { 11615796c8dcSSimon Schubert lai->string_char_type = builtin_type (gdbarch)->builtin_char; 11625796c8dcSSimon Schubert lai->bool_type_default = builtin_type (gdbarch)->builtin_int; 11635796c8dcSSimon Schubert lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, 11645796c8dcSSimon Schubert struct type *); 11655796c8dcSSimon Schubert } 11665796c8dcSSimon Schubert 11675796c8dcSSimon Schubert const struct language_defn unknown_language_defn = 11685796c8dcSSimon Schubert { 11695796c8dcSSimon Schubert "unknown", 11705796c8dcSSimon Schubert language_unknown, 11715796c8dcSSimon Schubert range_check_off, 11725796c8dcSSimon Schubert type_check_off, 11735796c8dcSSimon Schubert case_sensitive_on, 11745796c8dcSSimon Schubert array_row_major, 11755796c8dcSSimon Schubert macro_expansion_no, 11765796c8dcSSimon Schubert &exp_descriptor_standard, 11775796c8dcSSimon Schubert unk_lang_parser, 11785796c8dcSSimon Schubert unk_lang_error, 11795796c8dcSSimon Schubert null_post_parser, 11805796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 11815796c8dcSSimon Schubert unk_lang_printstr, 11825796c8dcSSimon Schubert unk_lang_emit_char, 11835796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 11845796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 11855796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 11865796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 11875796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 11885796c8dcSSimon Schubert "this", /* name_of_this */ 11895796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 11905796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 11915796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1192*c50c785cSJohn Marino unk_lang_class_name, /* Language specific 1193*c50c785cSJohn Marino class_name_from_physname */ 11945796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 11955796c8dcSSimon Schubert 1, /* c-style arrays */ 11965796c8dcSSimon Schubert 0, /* String lower bound */ 11975796c8dcSSimon Schubert default_word_break_characters, 11985796c8dcSSimon Schubert default_make_symbol_completion_list, 11995796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 12005796c8dcSSimon Schubert default_print_array_index, 12015796c8dcSSimon Schubert default_pass_by_reference, 12025796c8dcSSimon Schubert default_get_string, 12035796c8dcSSimon Schubert LANG_MAGIC 12045796c8dcSSimon Schubert }; 12055796c8dcSSimon Schubert 1206*c50c785cSJohn Marino /* These two structs define fake entries for the "local" and "auto" 1207*c50c785cSJohn Marino options. */ 12085796c8dcSSimon Schubert const struct language_defn auto_language_defn = 12095796c8dcSSimon Schubert { 12105796c8dcSSimon Schubert "auto", 12115796c8dcSSimon Schubert language_auto, 12125796c8dcSSimon Schubert range_check_off, 12135796c8dcSSimon Schubert type_check_off, 12145796c8dcSSimon Schubert case_sensitive_on, 12155796c8dcSSimon Schubert array_row_major, 12165796c8dcSSimon Schubert macro_expansion_no, 12175796c8dcSSimon Schubert &exp_descriptor_standard, 12185796c8dcSSimon Schubert unk_lang_parser, 12195796c8dcSSimon Schubert unk_lang_error, 12205796c8dcSSimon Schubert null_post_parser, 12215796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 12225796c8dcSSimon Schubert unk_lang_printstr, 12235796c8dcSSimon Schubert unk_lang_emit_char, 12245796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 12255796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 12265796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 12275796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 12285796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 12295796c8dcSSimon Schubert "this", /* name_of_this */ 12305796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 12315796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 12325796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1233*c50c785cSJohn Marino unk_lang_class_name, /* Language specific 1234*c50c785cSJohn Marino class_name_from_physname */ 12355796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 12365796c8dcSSimon Schubert 1, /* c-style arrays */ 12375796c8dcSSimon Schubert 0, /* String lower bound */ 12385796c8dcSSimon Schubert default_word_break_characters, 12395796c8dcSSimon Schubert default_make_symbol_completion_list, 12405796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 12415796c8dcSSimon Schubert default_print_array_index, 12425796c8dcSSimon Schubert default_pass_by_reference, 12435796c8dcSSimon Schubert default_get_string, 12445796c8dcSSimon Schubert LANG_MAGIC 12455796c8dcSSimon Schubert }; 12465796c8dcSSimon Schubert 12475796c8dcSSimon Schubert const struct language_defn local_language_defn = 12485796c8dcSSimon Schubert { 12495796c8dcSSimon Schubert "local", 12505796c8dcSSimon Schubert language_auto, 12515796c8dcSSimon Schubert range_check_off, 12525796c8dcSSimon Schubert type_check_off, 12535796c8dcSSimon Schubert case_sensitive_on, 12545796c8dcSSimon Schubert array_row_major, 12555796c8dcSSimon Schubert macro_expansion_no, 12565796c8dcSSimon Schubert &exp_descriptor_standard, 12575796c8dcSSimon Schubert unk_lang_parser, 12585796c8dcSSimon Schubert unk_lang_error, 12595796c8dcSSimon Schubert null_post_parser, 12605796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 12615796c8dcSSimon Schubert unk_lang_printstr, 12625796c8dcSSimon Schubert unk_lang_emit_char, 12635796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 12645796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 12655796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 12665796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 12675796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 12685796c8dcSSimon Schubert "this", /* name_of_this */ 12695796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 12705796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 12715796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1272*c50c785cSJohn Marino unk_lang_class_name, /* Language specific 1273*c50c785cSJohn Marino class_name_from_physname */ 12745796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 12755796c8dcSSimon Schubert 1, /* c-style arrays */ 12765796c8dcSSimon Schubert 0, /* String lower bound */ 12775796c8dcSSimon Schubert default_word_break_characters, 12785796c8dcSSimon Schubert default_make_symbol_completion_list, 12795796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 12805796c8dcSSimon Schubert default_print_array_index, 12815796c8dcSSimon Schubert default_pass_by_reference, 12825796c8dcSSimon Schubert default_get_string, 12835796c8dcSSimon Schubert LANG_MAGIC 12845796c8dcSSimon Schubert }; 12855796c8dcSSimon Schubert 12865796c8dcSSimon Schubert /* Per-architecture language information. */ 12875796c8dcSSimon Schubert 12885796c8dcSSimon Schubert static struct gdbarch_data *language_gdbarch_data; 12895796c8dcSSimon Schubert 12905796c8dcSSimon Schubert struct language_gdbarch 12915796c8dcSSimon Schubert { 12925796c8dcSSimon Schubert /* A vector of per-language per-architecture info. Indexed by "enum 12935796c8dcSSimon Schubert language". */ 12945796c8dcSSimon Schubert struct language_arch_info arch_info[nr_languages]; 12955796c8dcSSimon Schubert }; 12965796c8dcSSimon Schubert 12975796c8dcSSimon Schubert static void * 12985796c8dcSSimon Schubert language_gdbarch_post_init (struct gdbarch *gdbarch) 12995796c8dcSSimon Schubert { 13005796c8dcSSimon Schubert struct language_gdbarch *l; 13015796c8dcSSimon Schubert int i; 13025796c8dcSSimon Schubert 13035796c8dcSSimon Schubert l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); 13045796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 13055796c8dcSSimon Schubert { 13065796c8dcSSimon Schubert if (languages[i] != NULL 13075796c8dcSSimon Schubert && languages[i]->la_language_arch_info != NULL) 13085796c8dcSSimon Schubert languages[i]->la_language_arch_info 13095796c8dcSSimon Schubert (gdbarch, l->arch_info + languages[i]->la_language); 13105796c8dcSSimon Schubert } 13115796c8dcSSimon Schubert return l; 13125796c8dcSSimon Schubert } 13135796c8dcSSimon Schubert 13145796c8dcSSimon Schubert struct type * 13155796c8dcSSimon Schubert language_string_char_type (const struct language_defn *la, 13165796c8dcSSimon Schubert struct gdbarch *gdbarch) 13175796c8dcSSimon Schubert { 13185796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13195796c8dcSSimon Schubert language_gdbarch_data); 1320cf7f2e2dSJohn Marino 13215796c8dcSSimon Schubert return ld->arch_info[la->la_language].string_char_type; 13225796c8dcSSimon Schubert } 13235796c8dcSSimon Schubert 13245796c8dcSSimon Schubert struct type * 13255796c8dcSSimon Schubert language_bool_type (const struct language_defn *la, 13265796c8dcSSimon Schubert struct gdbarch *gdbarch) 13275796c8dcSSimon Schubert { 13285796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13295796c8dcSSimon Schubert language_gdbarch_data); 13305796c8dcSSimon Schubert 13315796c8dcSSimon Schubert if (ld->arch_info[la->la_language].bool_type_symbol) 13325796c8dcSSimon Schubert { 13335796c8dcSSimon Schubert struct symbol *sym; 1334cf7f2e2dSJohn Marino 13355796c8dcSSimon Schubert sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, 13365796c8dcSSimon Schubert NULL, VAR_DOMAIN, NULL); 13375796c8dcSSimon Schubert if (sym) 13385796c8dcSSimon Schubert { 13395796c8dcSSimon Schubert struct type *type = SYMBOL_TYPE (sym); 1340cf7f2e2dSJohn Marino 13415796c8dcSSimon Schubert if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) 13425796c8dcSSimon Schubert return type; 13435796c8dcSSimon Schubert } 13445796c8dcSSimon Schubert } 13455796c8dcSSimon Schubert 13465796c8dcSSimon Schubert return ld->arch_info[la->la_language].bool_type_default; 13475796c8dcSSimon Schubert } 13485796c8dcSSimon Schubert 13495796c8dcSSimon Schubert struct type * 13505796c8dcSSimon Schubert language_lookup_primitive_type_by_name (const struct language_defn *la, 13515796c8dcSSimon Schubert struct gdbarch *gdbarch, 13525796c8dcSSimon Schubert const char *name) 13535796c8dcSSimon Schubert { 13545796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 13555796c8dcSSimon Schubert language_gdbarch_data); 13565796c8dcSSimon Schubert struct type *const *p; 1357cf7f2e2dSJohn Marino 13585796c8dcSSimon Schubert for (p = ld->arch_info[la->la_language].primitive_type_vector; 13595796c8dcSSimon Schubert (*p) != NULL; 13605796c8dcSSimon Schubert p++) 13615796c8dcSSimon Schubert { 13625796c8dcSSimon Schubert if (strcmp (TYPE_NAME (*p), name) == 0) 13635796c8dcSSimon Schubert return (*p); 13645796c8dcSSimon Schubert } 13655796c8dcSSimon Schubert return (NULL); 13665796c8dcSSimon Schubert } 13675796c8dcSSimon Schubert 1368*c50c785cSJohn Marino /* Initialize the language routines. */ 13695796c8dcSSimon Schubert 13705796c8dcSSimon Schubert void 13715796c8dcSSimon Schubert _initialize_language (void) 13725796c8dcSSimon Schubert { 13735796c8dcSSimon Schubert static const char *type_or_range_names[] 13745796c8dcSSimon Schubert = { "on", "off", "warn", "auto", NULL }; 13755796c8dcSSimon Schubert 13765796c8dcSSimon Schubert static const char *case_sensitive_names[] 13775796c8dcSSimon Schubert = { "on", "off", "auto", NULL }; 13785796c8dcSSimon Schubert 13795796c8dcSSimon Schubert language_gdbarch_data 13805796c8dcSSimon Schubert = gdbarch_data_register_post_init (language_gdbarch_post_init); 13815796c8dcSSimon Schubert 1382*c50c785cSJohn Marino /* GDB commands for language specific stuff. */ 13835796c8dcSSimon Schubert 13845796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, set_check, 13855796c8dcSSimon Schubert _("Set the status of the type/range checker."), 13865796c8dcSSimon Schubert &setchecklist, "set check ", 0, &setlist); 13875796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &setlist); 13885796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &setlist); 13895796c8dcSSimon Schubert 13905796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, show_check, 13915796c8dcSSimon Schubert _("Show the status of the type/range checker."), 13925796c8dcSSimon Schubert &showchecklist, "show check ", 0, &showlist); 13935796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &showlist); 13945796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &showlist); 13955796c8dcSSimon Schubert 1396*c50c785cSJohn Marino add_setshow_enum_cmd ("type", class_support, type_or_range_names, &type, 1397*c50c785cSJohn Marino _("Set type checking. (on/warn/off/auto)"), 1398*c50c785cSJohn Marino _("Show type checking. (on/warn/off/auto)"), 1399*c50c785cSJohn Marino NULL, set_type_command, 14005796c8dcSSimon Schubert show_type_command, 14015796c8dcSSimon Schubert &setchecklist, &showchecklist); 14025796c8dcSSimon Schubert 14035796c8dcSSimon Schubert add_setshow_enum_cmd ("range", class_support, type_or_range_names, 1404*c50c785cSJohn Marino &range, 1405*c50c785cSJohn Marino _("Set range checking. (on/warn/off/auto)"), 1406*c50c785cSJohn Marino _("Show range checking. (on/warn/off/auto)"), 1407*c50c785cSJohn Marino NULL, set_range_command, 14085796c8dcSSimon Schubert show_range_command, 14095796c8dcSSimon Schubert &setchecklist, &showchecklist); 14105796c8dcSSimon Schubert 14115796c8dcSSimon Schubert add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names, 14125796c8dcSSimon Schubert &case_sensitive, _("\ 14135796c8dcSSimon Schubert Set case sensitivity in name search. (on/off/auto)"), _("\ 14145796c8dcSSimon Schubert Show case sensitivity in name search. (on/off/auto)"), _("\ 14155796c8dcSSimon Schubert For Fortran the default is off; for other languages the default is on."), 14165796c8dcSSimon Schubert set_case_command, 14175796c8dcSSimon Schubert show_case_command, 14185796c8dcSSimon Schubert &setlist, &showlist); 14195796c8dcSSimon Schubert 14205796c8dcSSimon Schubert add_language (&auto_language_defn); 14215796c8dcSSimon Schubert add_language (&local_language_defn); 14225796c8dcSSimon Schubert add_language (&unknown_language_defn); 14235796c8dcSSimon Schubert 14245796c8dcSSimon Schubert language = xstrdup ("auto"); 14255796c8dcSSimon Schubert type = xstrdup ("auto"); 14265796c8dcSSimon Schubert range = xstrdup ("auto"); 14275796c8dcSSimon Schubert case_sensitive = xstrdup ("auto"); 14285796c8dcSSimon Schubert 1429*c50c785cSJohn Marino /* Have the above take effect. */ 14305796c8dcSSimon Schubert set_language (language_auto); 14315796c8dcSSimon Schubert } 1432