1*5796c8dcSSimon Schubert /* Multiple source language support for GDB. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 4*5796c8dcSSimon Schubert 2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. 5*5796c8dcSSimon Schubert 6*5796c8dcSSimon Schubert Contributed by the Department of Computer Science at the State University 7*5796c8dcSSimon Schubert of New York at Buffalo. 8*5796c8dcSSimon Schubert 9*5796c8dcSSimon Schubert This file is part of GDB. 10*5796c8dcSSimon Schubert 11*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 12*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 13*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 14*5796c8dcSSimon Schubert (at your option) any later version. 15*5796c8dcSSimon Schubert 16*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 17*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 18*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19*5796c8dcSSimon Schubert GNU General Public License for more details. 20*5796c8dcSSimon Schubert 21*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 22*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 23*5796c8dcSSimon Schubert 24*5796c8dcSSimon Schubert /* This file contains functions that return things that are specific 25*5796c8dcSSimon Schubert to languages. Each function should examine current_language if necessary, 26*5796c8dcSSimon Schubert and return the appropriate result. */ 27*5796c8dcSSimon Schubert 28*5796c8dcSSimon Schubert /* FIXME: Most of these would be better organized as macros which 29*5796c8dcSSimon Schubert return data out of a "language-specific" struct pointer that is set 30*5796c8dcSSimon Schubert whenever the working language changes. That would be a lot faster. */ 31*5796c8dcSSimon Schubert 32*5796c8dcSSimon Schubert #include "defs.h" 33*5796c8dcSSimon Schubert #include <ctype.h> 34*5796c8dcSSimon Schubert #include "gdb_string.h" 35*5796c8dcSSimon Schubert 36*5796c8dcSSimon Schubert #include "symtab.h" 37*5796c8dcSSimon Schubert #include "gdbtypes.h" 38*5796c8dcSSimon Schubert #include "value.h" 39*5796c8dcSSimon Schubert #include "gdbcmd.h" 40*5796c8dcSSimon Schubert #include "expression.h" 41*5796c8dcSSimon Schubert #include "language.h" 42*5796c8dcSSimon Schubert #include "target.h" 43*5796c8dcSSimon Schubert #include "parser-defs.h" 44*5796c8dcSSimon Schubert #include "jv-lang.h" 45*5796c8dcSSimon Schubert #include "demangle.h" 46*5796c8dcSSimon Schubert #include "symfile.h" 47*5796c8dcSSimon Schubert 48*5796c8dcSSimon Schubert extern void _initialize_language (void); 49*5796c8dcSSimon Schubert 50*5796c8dcSSimon Schubert static void unk_lang_error (char *); 51*5796c8dcSSimon Schubert 52*5796c8dcSSimon Schubert static int unk_lang_parser (void); 53*5796c8dcSSimon Schubert 54*5796c8dcSSimon Schubert static void show_check (char *, int); 55*5796c8dcSSimon Schubert 56*5796c8dcSSimon Schubert static void set_check (char *, int); 57*5796c8dcSSimon Schubert 58*5796c8dcSSimon Schubert static void set_type_range_case (void); 59*5796c8dcSSimon Schubert 60*5796c8dcSSimon Schubert static void unk_lang_emit_char (int c, struct type *type, 61*5796c8dcSSimon Schubert struct ui_file *stream, int quoter); 62*5796c8dcSSimon Schubert 63*5796c8dcSSimon Schubert static void unk_lang_printchar (int c, struct type *type, 64*5796c8dcSSimon Schubert struct ui_file *stream); 65*5796c8dcSSimon Schubert 66*5796c8dcSSimon Schubert static void unk_lang_print_type (struct type *, char *, struct ui_file *, 67*5796c8dcSSimon Schubert int, int); 68*5796c8dcSSimon Schubert 69*5796c8dcSSimon Schubert static int unk_lang_value_print (struct value *, struct ui_file *, 70*5796c8dcSSimon Schubert const struct value_print_options *); 71*5796c8dcSSimon Schubert 72*5796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc); 73*5796c8dcSSimon Schubert 74*5796c8dcSSimon Schubert /* Forward declaration */ 75*5796c8dcSSimon Schubert extern const struct language_defn unknown_language_defn; 76*5796c8dcSSimon Schubert 77*5796c8dcSSimon Schubert /* The current (default at startup) state of type and range checking. 78*5796c8dcSSimon Schubert (If the modes are set to "auto", though, these are changed based 79*5796c8dcSSimon Schubert on the default language at startup, and then again based on the 80*5796c8dcSSimon Schubert language of the first source file. */ 81*5796c8dcSSimon Schubert 82*5796c8dcSSimon Schubert enum range_mode range_mode = range_mode_auto; 83*5796c8dcSSimon Schubert enum range_check range_check = range_check_off; 84*5796c8dcSSimon Schubert enum type_mode type_mode = type_mode_auto; 85*5796c8dcSSimon Schubert enum type_check type_check = type_check_off; 86*5796c8dcSSimon Schubert enum case_mode case_mode = case_mode_auto; 87*5796c8dcSSimon Schubert enum case_sensitivity case_sensitivity = case_sensitive_on; 88*5796c8dcSSimon Schubert 89*5796c8dcSSimon Schubert /* The current language and language_mode (see language.h) */ 90*5796c8dcSSimon Schubert 91*5796c8dcSSimon Schubert const struct language_defn *current_language = &unknown_language_defn; 92*5796c8dcSSimon Schubert enum language_mode language_mode = language_mode_auto; 93*5796c8dcSSimon Schubert 94*5796c8dcSSimon Schubert /* The language that the user expects to be typing in (the language 95*5796c8dcSSimon Schubert of main(), or the last language we notified them about, or C). */ 96*5796c8dcSSimon Schubert 97*5796c8dcSSimon Schubert const struct language_defn *expected_language; 98*5796c8dcSSimon Schubert 99*5796c8dcSSimon Schubert /* The list of supported languages. The list itself is malloc'd. */ 100*5796c8dcSSimon Schubert 101*5796c8dcSSimon Schubert static const struct language_defn **languages; 102*5796c8dcSSimon Schubert static unsigned languages_size; 103*5796c8dcSSimon Schubert static unsigned languages_allocsize; 104*5796c8dcSSimon Schubert #define DEFAULT_ALLOCSIZE 4 105*5796c8dcSSimon Schubert 106*5796c8dcSSimon Schubert /* The current values of the "set language/type/range" enum 107*5796c8dcSSimon Schubert commands. */ 108*5796c8dcSSimon Schubert static const char *language; 109*5796c8dcSSimon Schubert static const char *type; 110*5796c8dcSSimon Schubert static const char *range; 111*5796c8dcSSimon Schubert static const char *case_sensitive; 112*5796c8dcSSimon Schubert 113*5796c8dcSSimon Schubert /* Warning issued when current_language and the language of the current 114*5796c8dcSSimon Schubert frame do not match. */ 115*5796c8dcSSimon Schubert char lang_frame_mismatch_warn[] = 116*5796c8dcSSimon Schubert "Warning: the current language does not match this frame."; 117*5796c8dcSSimon Schubert 118*5796c8dcSSimon Schubert /* This page contains the functions corresponding to GDB commands 119*5796c8dcSSimon Schubert and their helpers. */ 120*5796c8dcSSimon Schubert 121*5796c8dcSSimon Schubert /* Show command. Display a warning if the language set 122*5796c8dcSSimon Schubert does not match the frame. */ 123*5796c8dcSSimon Schubert static void 124*5796c8dcSSimon Schubert show_language_command (struct ui_file *file, int from_tty, 125*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 126*5796c8dcSSimon Schubert { 127*5796c8dcSSimon Schubert enum language flang; /* The language of the current frame */ 128*5796c8dcSSimon Schubert 129*5796c8dcSSimon Schubert if (language_mode == language_mode_auto) 130*5796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 131*5796c8dcSSimon Schubert _("The current source language is " 132*5796c8dcSSimon Schubert "\"auto; currently %s\".\n"), 133*5796c8dcSSimon Schubert current_language->la_name); 134*5796c8dcSSimon Schubert else 135*5796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("The current source language is \"%s\".\n"), 136*5796c8dcSSimon Schubert current_language->la_name); 137*5796c8dcSSimon Schubert 138*5796c8dcSSimon Schubert flang = get_frame_language (); 139*5796c8dcSSimon Schubert if (flang != language_unknown && 140*5796c8dcSSimon Schubert language_mode == language_mode_manual && 141*5796c8dcSSimon Schubert current_language->la_language != flang) 142*5796c8dcSSimon Schubert printf_filtered ("%s\n", lang_frame_mismatch_warn); 143*5796c8dcSSimon Schubert } 144*5796c8dcSSimon Schubert 145*5796c8dcSSimon Schubert /* Set command. Change the current working language. */ 146*5796c8dcSSimon Schubert static void 147*5796c8dcSSimon Schubert set_language_command (char *ignore, int from_tty, struct cmd_list_element *c) 148*5796c8dcSSimon Schubert { 149*5796c8dcSSimon Schubert int i; 150*5796c8dcSSimon Schubert enum language flang; 151*5796c8dcSSimon Schubert 152*5796c8dcSSimon Schubert /* Search the list of languages for a match. */ 153*5796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 154*5796c8dcSSimon Schubert { 155*5796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, language) == 0) 156*5796c8dcSSimon Schubert { 157*5796c8dcSSimon Schubert /* Found it! Go into manual mode, and use this language. */ 158*5796c8dcSSimon Schubert if (languages[i]->la_language == language_auto) 159*5796c8dcSSimon Schubert { 160*5796c8dcSSimon Schubert /* Enter auto mode. Set to the current frame's language, if 161*5796c8dcSSimon Schubert known, or fallback to the initial language. */ 162*5796c8dcSSimon Schubert language_mode = language_mode_auto; 163*5796c8dcSSimon Schubert flang = get_frame_language (); 164*5796c8dcSSimon Schubert if (flang != language_unknown) 165*5796c8dcSSimon Schubert set_language (flang); 166*5796c8dcSSimon Schubert else 167*5796c8dcSSimon Schubert set_initial_language (); 168*5796c8dcSSimon Schubert expected_language = current_language; 169*5796c8dcSSimon Schubert return; 170*5796c8dcSSimon Schubert } 171*5796c8dcSSimon Schubert else 172*5796c8dcSSimon Schubert { 173*5796c8dcSSimon Schubert /* Enter manual mode. Set the specified language. */ 174*5796c8dcSSimon Schubert language_mode = language_mode_manual; 175*5796c8dcSSimon Schubert current_language = languages[i]; 176*5796c8dcSSimon Schubert set_type_range_case (); 177*5796c8dcSSimon Schubert expected_language = current_language; 178*5796c8dcSSimon Schubert return; 179*5796c8dcSSimon Schubert } 180*5796c8dcSSimon Schubert } 181*5796c8dcSSimon Schubert } 182*5796c8dcSSimon Schubert 183*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 184*5796c8dcSSimon Schubert "Couldn't find language `%s' in known languages list.", 185*5796c8dcSSimon Schubert language); 186*5796c8dcSSimon Schubert } 187*5796c8dcSSimon Schubert 188*5796c8dcSSimon Schubert /* Show command. Display a warning if the type setting does 189*5796c8dcSSimon Schubert not match the current language. */ 190*5796c8dcSSimon Schubert static void 191*5796c8dcSSimon Schubert show_type_command (struct ui_file *file, int from_tty, 192*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 193*5796c8dcSSimon Schubert { 194*5796c8dcSSimon Schubert if (type_mode == type_mode_auto) 195*5796c8dcSSimon Schubert { 196*5796c8dcSSimon Schubert char *tmp = NULL; 197*5796c8dcSSimon Schubert 198*5796c8dcSSimon Schubert switch (type_check) 199*5796c8dcSSimon Schubert { 200*5796c8dcSSimon Schubert case type_check_on: 201*5796c8dcSSimon Schubert tmp = "on"; 202*5796c8dcSSimon Schubert break; 203*5796c8dcSSimon Schubert case type_check_off: 204*5796c8dcSSimon Schubert tmp = "off"; 205*5796c8dcSSimon Schubert break; 206*5796c8dcSSimon Schubert case type_check_warn: 207*5796c8dcSSimon Schubert tmp = "warn"; 208*5796c8dcSSimon Schubert break; 209*5796c8dcSSimon Schubert default: 210*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 211*5796c8dcSSimon Schubert "Unrecognized type check setting."); 212*5796c8dcSSimon Schubert } 213*5796c8dcSSimon Schubert 214*5796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 215*5796c8dcSSimon Schubert _("Type checking is \"auto; currently %s\".\n"), 216*5796c8dcSSimon Schubert tmp); 217*5796c8dcSSimon Schubert } 218*5796c8dcSSimon Schubert else 219*5796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Type checking is \"%s\".\n"), 220*5796c8dcSSimon Schubert value); 221*5796c8dcSSimon Schubert 222*5796c8dcSSimon Schubert if (type_check != current_language->la_type_check) 223*5796c8dcSSimon Schubert warning (_("the current type check setting" 224*5796c8dcSSimon Schubert " does not match the language.\n")); 225*5796c8dcSSimon Schubert } 226*5796c8dcSSimon Schubert 227*5796c8dcSSimon Schubert /* Set command. Change the setting for type checking. */ 228*5796c8dcSSimon Schubert static void 229*5796c8dcSSimon Schubert set_type_command (char *ignore, int from_tty, struct cmd_list_element *c) 230*5796c8dcSSimon Schubert { 231*5796c8dcSSimon Schubert if (strcmp (type, "on") == 0) 232*5796c8dcSSimon Schubert { 233*5796c8dcSSimon Schubert type_check = type_check_on; 234*5796c8dcSSimon Schubert type_mode = type_mode_manual; 235*5796c8dcSSimon Schubert } 236*5796c8dcSSimon Schubert else if (strcmp (type, "warn") == 0) 237*5796c8dcSSimon Schubert { 238*5796c8dcSSimon Schubert type_check = type_check_warn; 239*5796c8dcSSimon Schubert type_mode = type_mode_manual; 240*5796c8dcSSimon Schubert } 241*5796c8dcSSimon Schubert else if (strcmp (type, "off") == 0) 242*5796c8dcSSimon Schubert { 243*5796c8dcSSimon Schubert type_check = type_check_off; 244*5796c8dcSSimon Schubert type_mode = type_mode_manual; 245*5796c8dcSSimon Schubert } 246*5796c8dcSSimon Schubert else if (strcmp (type, "auto") == 0) 247*5796c8dcSSimon Schubert { 248*5796c8dcSSimon Schubert type_mode = type_mode_auto; 249*5796c8dcSSimon Schubert set_type_range_case (); 250*5796c8dcSSimon Schubert return; 251*5796c8dcSSimon Schubert } 252*5796c8dcSSimon Schubert else 253*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 254*5796c8dcSSimon Schubert _("Unrecognized type check setting: \"%s\""), type); 255*5796c8dcSSimon Schubert 256*5796c8dcSSimon Schubert if (type_check != current_language->la_type_check) 257*5796c8dcSSimon Schubert warning (_("the current type check setting" 258*5796c8dcSSimon Schubert " does not match the language.\n")); 259*5796c8dcSSimon Schubert } 260*5796c8dcSSimon Schubert 261*5796c8dcSSimon Schubert /* Show command. Display a warning if the range setting does 262*5796c8dcSSimon Schubert not match the current language. */ 263*5796c8dcSSimon Schubert static void 264*5796c8dcSSimon Schubert show_range_command (struct ui_file *file, int from_tty, 265*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 266*5796c8dcSSimon Schubert { 267*5796c8dcSSimon Schubert if (range_mode == range_mode_auto) 268*5796c8dcSSimon Schubert { 269*5796c8dcSSimon Schubert char *tmp; 270*5796c8dcSSimon Schubert 271*5796c8dcSSimon Schubert switch (range_check) 272*5796c8dcSSimon Schubert { 273*5796c8dcSSimon Schubert case range_check_on: 274*5796c8dcSSimon Schubert tmp = "on"; 275*5796c8dcSSimon Schubert break; 276*5796c8dcSSimon Schubert case range_check_off: 277*5796c8dcSSimon Schubert tmp = "off"; 278*5796c8dcSSimon Schubert break; 279*5796c8dcSSimon Schubert case range_check_warn: 280*5796c8dcSSimon Schubert tmp = "warn"; 281*5796c8dcSSimon Schubert break; 282*5796c8dcSSimon Schubert default: 283*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 284*5796c8dcSSimon Schubert "Unrecognized range check setting."); 285*5796c8dcSSimon Schubert } 286*5796c8dcSSimon Schubert 287*5796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 288*5796c8dcSSimon Schubert _("Range checking is \"auto; currently %s\".\n"), 289*5796c8dcSSimon Schubert tmp); 290*5796c8dcSSimon Schubert } 291*5796c8dcSSimon Schubert else 292*5796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"), 293*5796c8dcSSimon Schubert value); 294*5796c8dcSSimon Schubert 295*5796c8dcSSimon Schubert if (range_check != current_language->la_range_check) 296*5796c8dcSSimon Schubert warning (_("the current range check setting " 297*5796c8dcSSimon Schubert "does not match the language.\n")); 298*5796c8dcSSimon Schubert } 299*5796c8dcSSimon Schubert 300*5796c8dcSSimon Schubert /* Set command. Change the setting for range checking. */ 301*5796c8dcSSimon Schubert static void 302*5796c8dcSSimon Schubert set_range_command (char *ignore, int from_tty, struct cmd_list_element *c) 303*5796c8dcSSimon Schubert { 304*5796c8dcSSimon Schubert if (strcmp (range, "on") == 0) 305*5796c8dcSSimon Schubert { 306*5796c8dcSSimon Schubert range_check = range_check_on; 307*5796c8dcSSimon Schubert range_mode = range_mode_manual; 308*5796c8dcSSimon Schubert } 309*5796c8dcSSimon Schubert else if (strcmp (range, "warn") == 0) 310*5796c8dcSSimon Schubert { 311*5796c8dcSSimon Schubert range_check = range_check_warn; 312*5796c8dcSSimon Schubert range_mode = range_mode_manual; 313*5796c8dcSSimon Schubert } 314*5796c8dcSSimon Schubert else if (strcmp (range, "off") == 0) 315*5796c8dcSSimon Schubert { 316*5796c8dcSSimon Schubert range_check = range_check_off; 317*5796c8dcSSimon Schubert range_mode = range_mode_manual; 318*5796c8dcSSimon Schubert } 319*5796c8dcSSimon Schubert else if (strcmp (range, "auto") == 0) 320*5796c8dcSSimon Schubert { 321*5796c8dcSSimon Schubert range_mode = range_mode_auto; 322*5796c8dcSSimon Schubert set_type_range_case (); 323*5796c8dcSSimon Schubert return; 324*5796c8dcSSimon Schubert } 325*5796c8dcSSimon Schubert else 326*5796c8dcSSimon Schubert { 327*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 328*5796c8dcSSimon Schubert _("Unrecognized range check setting: \"%s\""), range); 329*5796c8dcSSimon Schubert } 330*5796c8dcSSimon Schubert if (range_check != current_language->la_range_check) 331*5796c8dcSSimon Schubert warning (_("the current range check setting " 332*5796c8dcSSimon Schubert "does not match the language.\n")); 333*5796c8dcSSimon Schubert } 334*5796c8dcSSimon Schubert 335*5796c8dcSSimon Schubert /* Show command. Display a warning if the case sensitivity setting does 336*5796c8dcSSimon Schubert not match the current language. */ 337*5796c8dcSSimon Schubert static void 338*5796c8dcSSimon Schubert show_case_command (struct ui_file *file, int from_tty, 339*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 340*5796c8dcSSimon Schubert { 341*5796c8dcSSimon Schubert if (case_mode == case_mode_auto) 342*5796c8dcSSimon Schubert { 343*5796c8dcSSimon Schubert char *tmp = NULL; 344*5796c8dcSSimon Schubert 345*5796c8dcSSimon Schubert switch (case_sensitivity) 346*5796c8dcSSimon Schubert { 347*5796c8dcSSimon Schubert case case_sensitive_on: 348*5796c8dcSSimon Schubert tmp = "on"; 349*5796c8dcSSimon Schubert break; 350*5796c8dcSSimon Schubert case case_sensitive_off: 351*5796c8dcSSimon Schubert tmp = "off"; 352*5796c8dcSSimon Schubert break; 353*5796c8dcSSimon Schubert default: 354*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 355*5796c8dcSSimon Schubert "Unrecognized case-sensitive setting."); 356*5796c8dcSSimon Schubert } 357*5796c8dcSSimon Schubert 358*5796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, 359*5796c8dcSSimon Schubert _("Case sensitivity in " 360*5796c8dcSSimon Schubert "name search is \"auto; currently %s\".\n"), 361*5796c8dcSSimon Schubert tmp); 362*5796c8dcSSimon Schubert } 363*5796c8dcSSimon Schubert else 364*5796c8dcSSimon Schubert fprintf_filtered (gdb_stdout, _("Case sensitivity in name search is \"%s\".\n"), 365*5796c8dcSSimon Schubert value); 366*5796c8dcSSimon Schubert 367*5796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity) 368*5796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match " 369*5796c8dcSSimon Schubert "the language.\n")); 370*5796c8dcSSimon Schubert } 371*5796c8dcSSimon Schubert 372*5796c8dcSSimon Schubert /* Set command. Change the setting for case sensitivity. */ 373*5796c8dcSSimon Schubert 374*5796c8dcSSimon Schubert static void 375*5796c8dcSSimon Schubert set_case_command (char *ignore, int from_tty, struct cmd_list_element *c) 376*5796c8dcSSimon Schubert { 377*5796c8dcSSimon Schubert if (strcmp (case_sensitive, "on") == 0) 378*5796c8dcSSimon Schubert { 379*5796c8dcSSimon Schubert case_sensitivity = case_sensitive_on; 380*5796c8dcSSimon Schubert case_mode = case_mode_manual; 381*5796c8dcSSimon Schubert } 382*5796c8dcSSimon Schubert else if (strcmp (case_sensitive, "off") == 0) 383*5796c8dcSSimon Schubert { 384*5796c8dcSSimon Schubert case_sensitivity = case_sensitive_off; 385*5796c8dcSSimon Schubert case_mode = case_mode_manual; 386*5796c8dcSSimon Schubert } 387*5796c8dcSSimon Schubert else if (strcmp (case_sensitive, "auto") == 0) 388*5796c8dcSSimon Schubert { 389*5796c8dcSSimon Schubert case_mode = case_mode_auto; 390*5796c8dcSSimon Schubert set_type_range_case (); 391*5796c8dcSSimon Schubert return; 392*5796c8dcSSimon Schubert } 393*5796c8dcSSimon Schubert else 394*5796c8dcSSimon Schubert { 395*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 396*5796c8dcSSimon Schubert "Unrecognized case-sensitive setting: \"%s\"", 397*5796c8dcSSimon Schubert case_sensitive); 398*5796c8dcSSimon Schubert } 399*5796c8dcSSimon Schubert 400*5796c8dcSSimon Schubert if (case_sensitivity != current_language->la_case_sensitivity) 401*5796c8dcSSimon Schubert warning (_("the current case sensitivity setting does not match " 402*5796c8dcSSimon Schubert "the language.\n")); 403*5796c8dcSSimon Schubert } 404*5796c8dcSSimon Schubert 405*5796c8dcSSimon Schubert /* Set the status of range and type checking and case sensitivity based on 406*5796c8dcSSimon Schubert the current modes and the current language. 407*5796c8dcSSimon Schubert If SHOW is non-zero, then print out the current language, 408*5796c8dcSSimon Schubert type and range checking status. */ 409*5796c8dcSSimon Schubert static void 410*5796c8dcSSimon Schubert set_type_range_case (void) 411*5796c8dcSSimon Schubert { 412*5796c8dcSSimon Schubert if (range_mode == range_mode_auto) 413*5796c8dcSSimon Schubert range_check = current_language->la_range_check; 414*5796c8dcSSimon Schubert 415*5796c8dcSSimon Schubert if (type_mode == type_mode_auto) 416*5796c8dcSSimon Schubert type_check = current_language->la_type_check; 417*5796c8dcSSimon Schubert 418*5796c8dcSSimon Schubert if (case_mode == case_mode_auto) 419*5796c8dcSSimon Schubert case_sensitivity = current_language->la_case_sensitivity; 420*5796c8dcSSimon Schubert } 421*5796c8dcSSimon Schubert 422*5796c8dcSSimon Schubert /* Set current language to (enum language) LANG. Returns previous language. */ 423*5796c8dcSSimon Schubert 424*5796c8dcSSimon Schubert enum language 425*5796c8dcSSimon Schubert set_language (enum language lang) 426*5796c8dcSSimon Schubert { 427*5796c8dcSSimon Schubert int i; 428*5796c8dcSSimon Schubert enum language prev_language; 429*5796c8dcSSimon Schubert 430*5796c8dcSSimon Schubert prev_language = current_language->la_language; 431*5796c8dcSSimon Schubert 432*5796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 433*5796c8dcSSimon Schubert { 434*5796c8dcSSimon Schubert if (languages[i]->la_language == lang) 435*5796c8dcSSimon Schubert { 436*5796c8dcSSimon Schubert current_language = languages[i]; 437*5796c8dcSSimon Schubert set_type_range_case (); 438*5796c8dcSSimon Schubert break; 439*5796c8dcSSimon Schubert } 440*5796c8dcSSimon Schubert } 441*5796c8dcSSimon Schubert 442*5796c8dcSSimon Schubert return prev_language; 443*5796c8dcSSimon Schubert } 444*5796c8dcSSimon Schubert 445*5796c8dcSSimon Schubert 446*5796c8dcSSimon Schubert /* Print out the current language settings: language, range and 447*5796c8dcSSimon Schubert type checking. If QUIETLY, print only what has changed. */ 448*5796c8dcSSimon Schubert 449*5796c8dcSSimon Schubert void 450*5796c8dcSSimon Schubert language_info (int quietly) 451*5796c8dcSSimon Schubert { 452*5796c8dcSSimon Schubert if (quietly && expected_language == current_language) 453*5796c8dcSSimon Schubert return; 454*5796c8dcSSimon Schubert 455*5796c8dcSSimon Schubert expected_language = current_language; 456*5796c8dcSSimon Schubert printf_unfiltered (_("Current language: %s\n"), language); 457*5796c8dcSSimon Schubert show_language_command (NULL, 1, NULL, NULL); 458*5796c8dcSSimon Schubert 459*5796c8dcSSimon Schubert if (!quietly) 460*5796c8dcSSimon Schubert { 461*5796c8dcSSimon Schubert printf_unfiltered (_("Type checking: %s\n"), type); 462*5796c8dcSSimon Schubert show_type_command (NULL, 1, NULL, NULL); 463*5796c8dcSSimon Schubert printf_unfiltered (_("Range checking: %s\n"), range); 464*5796c8dcSSimon Schubert show_range_command (NULL, 1, NULL, NULL); 465*5796c8dcSSimon Schubert printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive); 466*5796c8dcSSimon Schubert show_case_command (NULL, 1, NULL, NULL); 467*5796c8dcSSimon Schubert } 468*5796c8dcSSimon Schubert } 469*5796c8dcSSimon Schubert 470*5796c8dcSSimon Schubert /* Return the result of a binary operation. */ 471*5796c8dcSSimon Schubert 472*5796c8dcSSimon Schubert #if 0 /* Currently unused */ 473*5796c8dcSSimon Schubert 474*5796c8dcSSimon Schubert struct type * 475*5796c8dcSSimon Schubert binop_result_type (struct value *v1, struct value *v2) 476*5796c8dcSSimon Schubert { 477*5796c8dcSSimon Schubert int size, uns; 478*5796c8dcSSimon Schubert struct type *t1 = check_typedef (VALUE_TYPE (v1)); 479*5796c8dcSSimon Schubert struct type *t2 = check_typedef (VALUE_TYPE (v2)); 480*5796c8dcSSimon Schubert 481*5796c8dcSSimon Schubert int l1 = TYPE_LENGTH (t1); 482*5796c8dcSSimon Schubert int l2 = TYPE_LENGTH (t2); 483*5796c8dcSSimon Schubert 484*5796c8dcSSimon Schubert switch (current_language->la_language) 485*5796c8dcSSimon Schubert { 486*5796c8dcSSimon Schubert case language_c: 487*5796c8dcSSimon Schubert case language_cplus: 488*5796c8dcSSimon Schubert case language_objc: 489*5796c8dcSSimon Schubert if (TYPE_CODE (t1) == TYPE_CODE_FLT) 490*5796c8dcSSimon Schubert return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ? 491*5796c8dcSSimon Schubert VALUE_TYPE (v2) : VALUE_TYPE (v1); 492*5796c8dcSSimon Schubert else if (TYPE_CODE (t2) == TYPE_CODE_FLT) 493*5796c8dcSSimon Schubert return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ? 494*5796c8dcSSimon Schubert VALUE_TYPE (v1) : VALUE_TYPE (v2); 495*5796c8dcSSimon Schubert else if (TYPE_UNSIGNED (t1) && l1 > l2) 496*5796c8dcSSimon Schubert return VALUE_TYPE (v1); 497*5796c8dcSSimon Schubert else if (TYPE_UNSIGNED (t2) && l2 > l1) 498*5796c8dcSSimon Schubert return VALUE_TYPE (v2); 499*5796c8dcSSimon Schubert else /* Both are signed. Result is the longer type */ 500*5796c8dcSSimon Schubert return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 501*5796c8dcSSimon Schubert break; 502*5796c8dcSSimon Schubert case language_m2: 503*5796c8dcSSimon Schubert /* If we are doing type-checking, l1 should equal l2, so this is 504*5796c8dcSSimon Schubert not needed. */ 505*5796c8dcSSimon Schubert return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 506*5796c8dcSSimon Schubert break; 507*5796c8dcSSimon Schubert } 508*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("failed internal consistency check")); 509*5796c8dcSSimon Schubert return (struct type *) 0; /* For lint */ 510*5796c8dcSSimon Schubert } 511*5796c8dcSSimon Schubert 512*5796c8dcSSimon Schubert #endif /* 0 */ 513*5796c8dcSSimon Schubert #if 0 514*5796c8dcSSimon Schubert /* This page contains functions that are used in type/range checking. 515*5796c8dcSSimon Schubert They all return zero if the type/range check fails. 516*5796c8dcSSimon Schubert 517*5796c8dcSSimon Schubert It is hoped that these will make extending GDB to parse different 518*5796c8dcSSimon Schubert languages a little easier. These are primarily used in eval.c when 519*5796c8dcSSimon Schubert evaluating expressions and making sure that their types are correct. 520*5796c8dcSSimon Schubert Instead of having a mess of conjucted/disjuncted expressions in an "if", 521*5796c8dcSSimon Schubert the ideas of type can be wrapped up in the following functions. 522*5796c8dcSSimon Schubert 523*5796c8dcSSimon Schubert Note that some of them are not currently dependent upon which language 524*5796c8dcSSimon Schubert is currently being parsed. For example, floats are the same in 525*5796c8dcSSimon Schubert C and Modula-2 (ie. the only floating point type has TYPE_CODE of 526*5796c8dcSSimon Schubert TYPE_CODE_FLT), while booleans are different. */ 527*5796c8dcSSimon Schubert 528*5796c8dcSSimon Schubert /* Returns non-zero if its argument is a simple type. This is the same for 529*5796c8dcSSimon Schubert both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur, 530*5796c8dcSSimon Schubert and thus will never cause the failure of the test. */ 531*5796c8dcSSimon Schubert int 532*5796c8dcSSimon Schubert simple_type (struct type *type) 533*5796c8dcSSimon Schubert { 534*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 535*5796c8dcSSimon Schubert switch (TYPE_CODE (type)) 536*5796c8dcSSimon Schubert { 537*5796c8dcSSimon Schubert case TYPE_CODE_INT: 538*5796c8dcSSimon Schubert case TYPE_CODE_CHAR: 539*5796c8dcSSimon Schubert case TYPE_CODE_ENUM: 540*5796c8dcSSimon Schubert case TYPE_CODE_FLT: 541*5796c8dcSSimon Schubert case TYPE_CODE_RANGE: 542*5796c8dcSSimon Schubert case TYPE_CODE_BOOL: 543*5796c8dcSSimon Schubert return 1; 544*5796c8dcSSimon Schubert 545*5796c8dcSSimon Schubert default: 546*5796c8dcSSimon Schubert return 0; 547*5796c8dcSSimon Schubert } 548*5796c8dcSSimon Schubert } 549*5796c8dcSSimon Schubert 550*5796c8dcSSimon Schubert /* Returns non-zero if its argument is of an ordered type. 551*5796c8dcSSimon Schubert An ordered type is one in which the elements can be tested for the 552*5796c8dcSSimon Schubert properties of "greater than", "less than", etc, or for which the 553*5796c8dcSSimon Schubert operations "increment" or "decrement" make sense. */ 554*5796c8dcSSimon Schubert int 555*5796c8dcSSimon Schubert ordered_type (struct type *type) 556*5796c8dcSSimon Schubert { 557*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 558*5796c8dcSSimon Schubert switch (TYPE_CODE (type)) 559*5796c8dcSSimon Schubert { 560*5796c8dcSSimon Schubert case TYPE_CODE_INT: 561*5796c8dcSSimon Schubert case TYPE_CODE_CHAR: 562*5796c8dcSSimon Schubert case TYPE_CODE_ENUM: 563*5796c8dcSSimon Schubert case TYPE_CODE_FLT: 564*5796c8dcSSimon Schubert case TYPE_CODE_RANGE: 565*5796c8dcSSimon Schubert return 1; 566*5796c8dcSSimon Schubert 567*5796c8dcSSimon Schubert default: 568*5796c8dcSSimon Schubert return 0; 569*5796c8dcSSimon Schubert } 570*5796c8dcSSimon Schubert } 571*5796c8dcSSimon Schubert 572*5796c8dcSSimon Schubert /* Returns non-zero if the two types are the same */ 573*5796c8dcSSimon Schubert int 574*5796c8dcSSimon Schubert same_type (struct type *arg1, struct type *arg2) 575*5796c8dcSSimon Schubert { 576*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 577*5796c8dcSSimon Schubert if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2)) 578*5796c8dcSSimon Schubert /* One is structured and one isn't */ 579*5796c8dcSSimon Schubert return 0; 580*5796c8dcSSimon Schubert else if (structured_type (arg1) && structured_type (arg2)) 581*5796c8dcSSimon Schubert return arg1 == arg2; 582*5796c8dcSSimon Schubert else if (numeric_type (arg1) && numeric_type (arg2)) 583*5796c8dcSSimon Schubert return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) && 584*5796c8dcSSimon Schubert (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2)) 585*5796c8dcSSimon Schubert ? 1 : 0; 586*5796c8dcSSimon Schubert else 587*5796c8dcSSimon Schubert return arg1 == arg2; 588*5796c8dcSSimon Schubert } 589*5796c8dcSSimon Schubert 590*5796c8dcSSimon Schubert /* Returns non-zero if the type is integral */ 591*5796c8dcSSimon Schubert int 592*5796c8dcSSimon Schubert integral_type (struct type *type) 593*5796c8dcSSimon Schubert { 594*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 595*5796c8dcSSimon Schubert switch (current_language->la_language) 596*5796c8dcSSimon Schubert { 597*5796c8dcSSimon Schubert case language_c: 598*5796c8dcSSimon Schubert case language_cplus: 599*5796c8dcSSimon Schubert case language_objc: 600*5796c8dcSSimon Schubert return (TYPE_CODE (type) != TYPE_CODE_INT) && 601*5796c8dcSSimon Schubert (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1; 602*5796c8dcSSimon Schubert case language_m2: 603*5796c8dcSSimon Schubert case language_pascal: 604*5796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1; 605*5796c8dcSSimon Schubert default: 606*5796c8dcSSimon Schubert error (_("Language not supported.")); 607*5796c8dcSSimon Schubert } 608*5796c8dcSSimon Schubert } 609*5796c8dcSSimon Schubert 610*5796c8dcSSimon Schubert /* Returns non-zero if the value is numeric */ 611*5796c8dcSSimon Schubert int 612*5796c8dcSSimon Schubert numeric_type (struct type *type) 613*5796c8dcSSimon Schubert { 614*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 615*5796c8dcSSimon Schubert switch (TYPE_CODE (type)) 616*5796c8dcSSimon Schubert { 617*5796c8dcSSimon Schubert case TYPE_CODE_INT: 618*5796c8dcSSimon Schubert case TYPE_CODE_FLT: 619*5796c8dcSSimon Schubert return 1; 620*5796c8dcSSimon Schubert 621*5796c8dcSSimon Schubert default: 622*5796c8dcSSimon Schubert return 0; 623*5796c8dcSSimon Schubert } 624*5796c8dcSSimon Schubert } 625*5796c8dcSSimon Schubert 626*5796c8dcSSimon Schubert /* Returns non-zero if the value is a character type */ 627*5796c8dcSSimon Schubert int 628*5796c8dcSSimon Schubert character_type (struct type *type) 629*5796c8dcSSimon Schubert { 630*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 631*5796c8dcSSimon Schubert switch (current_language->la_language) 632*5796c8dcSSimon Schubert { 633*5796c8dcSSimon Schubert case language_m2: 634*5796c8dcSSimon Schubert case language_pascal: 635*5796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1; 636*5796c8dcSSimon Schubert 637*5796c8dcSSimon Schubert case language_c: 638*5796c8dcSSimon Schubert case language_cplus: 639*5796c8dcSSimon Schubert case language_objc: 640*5796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_INT) && 641*5796c8dcSSimon Schubert TYPE_LENGTH (type) == sizeof (char) 642*5796c8dcSSimon Schubert ? 1 : 0; 643*5796c8dcSSimon Schubert default: 644*5796c8dcSSimon Schubert return (0); 645*5796c8dcSSimon Schubert } 646*5796c8dcSSimon Schubert } 647*5796c8dcSSimon Schubert 648*5796c8dcSSimon Schubert /* Returns non-zero if the value is a string type */ 649*5796c8dcSSimon Schubert int 650*5796c8dcSSimon Schubert string_type (struct type *type) 651*5796c8dcSSimon Schubert { 652*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 653*5796c8dcSSimon Schubert switch (current_language->la_language) 654*5796c8dcSSimon Schubert { 655*5796c8dcSSimon Schubert case language_m2: 656*5796c8dcSSimon Schubert case language_pascal: 657*5796c8dcSSimon Schubert return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1; 658*5796c8dcSSimon Schubert 659*5796c8dcSSimon Schubert case language_c: 660*5796c8dcSSimon Schubert case language_cplus: 661*5796c8dcSSimon Schubert case language_objc: 662*5796c8dcSSimon Schubert /* C does not have distinct string type. */ 663*5796c8dcSSimon Schubert return (0); 664*5796c8dcSSimon Schubert default: 665*5796c8dcSSimon Schubert return (0); 666*5796c8dcSSimon Schubert } 667*5796c8dcSSimon Schubert } 668*5796c8dcSSimon Schubert 669*5796c8dcSSimon Schubert /* Returns non-zero if the value is a boolean type */ 670*5796c8dcSSimon Schubert int 671*5796c8dcSSimon Schubert boolean_type (struct type *type) 672*5796c8dcSSimon Schubert { 673*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 674*5796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_BOOL) 675*5796c8dcSSimon Schubert return 1; 676*5796c8dcSSimon Schubert switch (current_language->la_language) 677*5796c8dcSSimon Schubert { 678*5796c8dcSSimon Schubert case language_c: 679*5796c8dcSSimon Schubert case language_cplus: 680*5796c8dcSSimon Schubert case language_objc: 681*5796c8dcSSimon Schubert /* Might be more cleanly handled by having a 682*5796c8dcSSimon Schubert TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such 683*5796c8dcSSimon Schubert languages, or a TYPE_CODE_INT_OR_BOOL for C. */ 684*5796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_INT) 685*5796c8dcSSimon Schubert return 1; 686*5796c8dcSSimon Schubert default: 687*5796c8dcSSimon Schubert break; 688*5796c8dcSSimon Schubert } 689*5796c8dcSSimon Schubert return 0; 690*5796c8dcSSimon Schubert } 691*5796c8dcSSimon Schubert 692*5796c8dcSSimon Schubert /* Returns non-zero if the value is a floating-point type */ 693*5796c8dcSSimon Schubert int 694*5796c8dcSSimon Schubert float_type (struct type *type) 695*5796c8dcSSimon Schubert { 696*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 697*5796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_FLT; 698*5796c8dcSSimon Schubert } 699*5796c8dcSSimon Schubert 700*5796c8dcSSimon Schubert /* Returns non-zero if the value is a pointer type */ 701*5796c8dcSSimon Schubert int 702*5796c8dcSSimon Schubert pointer_type (struct type *type) 703*5796c8dcSSimon Schubert { 704*5796c8dcSSimon Schubert return TYPE_CODE (type) == TYPE_CODE_PTR || 705*5796c8dcSSimon Schubert TYPE_CODE (type) == TYPE_CODE_REF; 706*5796c8dcSSimon Schubert } 707*5796c8dcSSimon Schubert 708*5796c8dcSSimon Schubert /* Returns non-zero if the value is a structured type */ 709*5796c8dcSSimon Schubert int 710*5796c8dcSSimon Schubert structured_type (struct type *type) 711*5796c8dcSSimon Schubert { 712*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 713*5796c8dcSSimon Schubert switch (current_language->la_language) 714*5796c8dcSSimon Schubert { 715*5796c8dcSSimon Schubert case language_c: 716*5796c8dcSSimon Schubert case language_cplus: 717*5796c8dcSSimon Schubert case language_objc: 718*5796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 719*5796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_UNION) || 720*5796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_ARRAY); 721*5796c8dcSSimon Schubert case language_pascal: 722*5796c8dcSSimon Schubert return (TYPE_CODE(type) == TYPE_CODE_STRUCT) || 723*5796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_UNION) || 724*5796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_SET) || 725*5796c8dcSSimon Schubert (TYPE_CODE(type) == TYPE_CODE_ARRAY); 726*5796c8dcSSimon Schubert case language_m2: 727*5796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 728*5796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_SET) || 729*5796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_ARRAY); 730*5796c8dcSSimon Schubert default: 731*5796c8dcSSimon Schubert return (0); 732*5796c8dcSSimon Schubert } 733*5796c8dcSSimon Schubert } 734*5796c8dcSSimon Schubert #endif 735*5796c8dcSSimon Schubert 736*5796c8dcSSimon Schubert /* This page contains functions that return info about 737*5796c8dcSSimon Schubert (struct value) values used in GDB. */ 738*5796c8dcSSimon Schubert 739*5796c8dcSSimon Schubert /* Returns non-zero if the value VAL represents a true value. */ 740*5796c8dcSSimon Schubert int 741*5796c8dcSSimon Schubert value_true (struct value *val) 742*5796c8dcSSimon Schubert { 743*5796c8dcSSimon Schubert /* It is possible that we should have some sort of error if a non-boolean 744*5796c8dcSSimon Schubert value is used in this context. Possibly dependent on some kind of 745*5796c8dcSSimon Schubert "boolean-checking" option like range checking. But it should probably 746*5796c8dcSSimon Schubert not depend on the language except insofar as is necessary to identify 747*5796c8dcSSimon Schubert a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean 748*5796c8dcSSimon Schubert should be an error, probably). */ 749*5796c8dcSSimon Schubert return !value_logical_not (val); 750*5796c8dcSSimon Schubert } 751*5796c8dcSSimon Schubert 752*5796c8dcSSimon Schubert /* This page contains functions for the printing out of 753*5796c8dcSSimon Schubert error messages that occur during type- and range- 754*5796c8dcSSimon Schubert checking. */ 755*5796c8dcSSimon Schubert 756*5796c8dcSSimon Schubert /* These are called when a language fails a type- or range-check. The 757*5796c8dcSSimon Schubert first argument should be a printf()-style format string, and the 758*5796c8dcSSimon Schubert rest of the arguments should be its arguments. If 759*5796c8dcSSimon Schubert [type|range]_check is [type|range]_check_on, an error is printed; 760*5796c8dcSSimon Schubert if [type|range]_check_warn, a warning; otherwise just the 761*5796c8dcSSimon Schubert message. */ 762*5796c8dcSSimon Schubert 763*5796c8dcSSimon Schubert void 764*5796c8dcSSimon Schubert type_error (const char *string,...) 765*5796c8dcSSimon Schubert { 766*5796c8dcSSimon Schubert va_list args; 767*5796c8dcSSimon Schubert va_start (args, string); 768*5796c8dcSSimon Schubert 769*5796c8dcSSimon Schubert switch (type_check) 770*5796c8dcSSimon Schubert { 771*5796c8dcSSimon Schubert case type_check_warn: 772*5796c8dcSSimon Schubert vwarning (string, args); 773*5796c8dcSSimon Schubert break; 774*5796c8dcSSimon Schubert case type_check_on: 775*5796c8dcSSimon Schubert verror (string, args); 776*5796c8dcSSimon Schubert break; 777*5796c8dcSSimon Schubert case type_check_off: 778*5796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything 779*5796c8dcSSimon Schubert when type error is off? */ 780*5796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args); 781*5796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n"); 782*5796c8dcSSimon Schubert break; 783*5796c8dcSSimon Schubert default: 784*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 785*5796c8dcSSimon Schubert } 786*5796c8dcSSimon Schubert va_end (args); 787*5796c8dcSSimon Schubert } 788*5796c8dcSSimon Schubert 789*5796c8dcSSimon Schubert void 790*5796c8dcSSimon Schubert range_error (const char *string,...) 791*5796c8dcSSimon Schubert { 792*5796c8dcSSimon Schubert va_list args; 793*5796c8dcSSimon Schubert va_start (args, string); 794*5796c8dcSSimon Schubert 795*5796c8dcSSimon Schubert switch (range_check) 796*5796c8dcSSimon Schubert { 797*5796c8dcSSimon Schubert case range_check_warn: 798*5796c8dcSSimon Schubert vwarning (string, args); 799*5796c8dcSSimon Schubert break; 800*5796c8dcSSimon Schubert case range_check_on: 801*5796c8dcSSimon Schubert verror (string, args); 802*5796c8dcSSimon Schubert break; 803*5796c8dcSSimon Schubert case range_check_off: 804*5796c8dcSSimon Schubert /* FIXME: cagney/2002-01-30: Should this function print anything 805*5796c8dcSSimon Schubert when range error is off? */ 806*5796c8dcSSimon Schubert vfprintf_filtered (gdb_stderr, string, args); 807*5796c8dcSSimon Schubert fprintf_filtered (gdb_stderr, "\n"); 808*5796c8dcSSimon Schubert break; 809*5796c8dcSSimon Schubert default: 810*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("bad switch")); 811*5796c8dcSSimon Schubert } 812*5796c8dcSSimon Schubert va_end (args); 813*5796c8dcSSimon Schubert } 814*5796c8dcSSimon Schubert 815*5796c8dcSSimon Schubert 816*5796c8dcSSimon Schubert /* This page contains miscellaneous functions */ 817*5796c8dcSSimon Schubert 818*5796c8dcSSimon Schubert /* Return the language enum for a given language string. */ 819*5796c8dcSSimon Schubert 820*5796c8dcSSimon Schubert enum language 821*5796c8dcSSimon Schubert language_enum (char *str) 822*5796c8dcSSimon Schubert { 823*5796c8dcSSimon Schubert int i; 824*5796c8dcSSimon Schubert 825*5796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 826*5796c8dcSSimon Schubert if (strcmp (languages[i]->la_name, str) == 0) 827*5796c8dcSSimon Schubert return languages[i]->la_language; 828*5796c8dcSSimon Schubert 829*5796c8dcSSimon Schubert return language_unknown; 830*5796c8dcSSimon Schubert } 831*5796c8dcSSimon Schubert 832*5796c8dcSSimon Schubert /* Return the language struct for a given language enum. */ 833*5796c8dcSSimon Schubert 834*5796c8dcSSimon Schubert const struct language_defn * 835*5796c8dcSSimon Schubert language_def (enum language lang) 836*5796c8dcSSimon Schubert { 837*5796c8dcSSimon Schubert int i; 838*5796c8dcSSimon Schubert 839*5796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 840*5796c8dcSSimon Schubert { 841*5796c8dcSSimon Schubert if (languages[i]->la_language == lang) 842*5796c8dcSSimon Schubert { 843*5796c8dcSSimon Schubert return languages[i]; 844*5796c8dcSSimon Schubert } 845*5796c8dcSSimon Schubert } 846*5796c8dcSSimon Schubert return NULL; 847*5796c8dcSSimon Schubert } 848*5796c8dcSSimon Schubert 849*5796c8dcSSimon Schubert /* Return the language as a string */ 850*5796c8dcSSimon Schubert char * 851*5796c8dcSSimon Schubert language_str (enum language lang) 852*5796c8dcSSimon Schubert { 853*5796c8dcSSimon Schubert int i; 854*5796c8dcSSimon Schubert 855*5796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 856*5796c8dcSSimon Schubert { 857*5796c8dcSSimon Schubert if (languages[i]->la_language == lang) 858*5796c8dcSSimon Schubert { 859*5796c8dcSSimon Schubert return languages[i]->la_name; 860*5796c8dcSSimon Schubert } 861*5796c8dcSSimon Schubert } 862*5796c8dcSSimon Schubert return "Unknown"; 863*5796c8dcSSimon Schubert } 864*5796c8dcSSimon Schubert 865*5796c8dcSSimon Schubert static void 866*5796c8dcSSimon Schubert set_check (char *ignore, int from_tty) 867*5796c8dcSSimon Schubert { 868*5796c8dcSSimon Schubert printf_unfiltered ( 869*5796c8dcSSimon Schubert "\"set check\" must be followed by the name of a check subcommand.\n"); 870*5796c8dcSSimon Schubert help_list (setchecklist, "set check ", -1, gdb_stdout); 871*5796c8dcSSimon Schubert } 872*5796c8dcSSimon Schubert 873*5796c8dcSSimon Schubert static void 874*5796c8dcSSimon Schubert show_check (char *ignore, int from_tty) 875*5796c8dcSSimon Schubert { 876*5796c8dcSSimon Schubert cmd_show_list (showchecklist, from_tty, ""); 877*5796c8dcSSimon Schubert } 878*5796c8dcSSimon Schubert 879*5796c8dcSSimon Schubert /* Add a language to the set of known languages. */ 880*5796c8dcSSimon Schubert 881*5796c8dcSSimon Schubert void 882*5796c8dcSSimon Schubert add_language (const struct language_defn *lang) 883*5796c8dcSSimon Schubert { 884*5796c8dcSSimon Schubert /* For the "set language" command. */ 885*5796c8dcSSimon Schubert static char **language_names = NULL; 886*5796c8dcSSimon Schubert /* For the "help set language" command. */ 887*5796c8dcSSimon Schubert char *language_set_doc = NULL; 888*5796c8dcSSimon Schubert 889*5796c8dcSSimon Schubert int i; 890*5796c8dcSSimon Schubert struct ui_file *tmp_stream; 891*5796c8dcSSimon Schubert 892*5796c8dcSSimon Schubert if (lang->la_magic != LANG_MAGIC) 893*5796c8dcSSimon Schubert { 894*5796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n", 895*5796c8dcSSimon Schubert lang->la_name); 896*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("failed internal consistency check")); 897*5796c8dcSSimon Schubert } 898*5796c8dcSSimon Schubert 899*5796c8dcSSimon Schubert if (!languages) 900*5796c8dcSSimon Schubert { 901*5796c8dcSSimon Schubert languages_allocsize = DEFAULT_ALLOCSIZE; 902*5796c8dcSSimon Schubert languages = (const struct language_defn **) xmalloc 903*5796c8dcSSimon Schubert (languages_allocsize * sizeof (*languages)); 904*5796c8dcSSimon Schubert } 905*5796c8dcSSimon Schubert if (languages_size >= languages_allocsize) 906*5796c8dcSSimon Schubert { 907*5796c8dcSSimon Schubert languages_allocsize *= 2; 908*5796c8dcSSimon Schubert languages = (const struct language_defn **) xrealloc ((char *) languages, 909*5796c8dcSSimon Schubert languages_allocsize * sizeof (*languages)); 910*5796c8dcSSimon Schubert } 911*5796c8dcSSimon Schubert languages[languages_size++] = lang; 912*5796c8dcSSimon Schubert 913*5796c8dcSSimon Schubert /* Build the language names array, to be used as enumeration in the 914*5796c8dcSSimon Schubert set language" enum command. */ 915*5796c8dcSSimon Schubert language_names = xrealloc (language_names, 916*5796c8dcSSimon Schubert (languages_size + 1) * sizeof (const char *)); 917*5796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i) 918*5796c8dcSSimon Schubert language_names[i] = languages[i]->la_name; 919*5796c8dcSSimon Schubert language_names[i] = NULL; 920*5796c8dcSSimon Schubert 921*5796c8dcSSimon Schubert /* Build the "help set language" docs. */ 922*5796c8dcSSimon Schubert tmp_stream = mem_fileopen (); 923*5796c8dcSSimon Schubert 924*5796c8dcSSimon Schubert fprintf_unfiltered (tmp_stream, _("\ 925*5796c8dcSSimon Schubert Set the current source language.\n\ 926*5796c8dcSSimon Schubert The currently understood settings are:\n\n\ 927*5796c8dcSSimon Schubert local or auto Automatic setting based on source file\n")); 928*5796c8dcSSimon Schubert 929*5796c8dcSSimon Schubert for (i = 0; i < languages_size; ++i) 930*5796c8dcSSimon Schubert { 931*5796c8dcSSimon Schubert /* Already dealt with these above. */ 932*5796c8dcSSimon Schubert if (languages[i]->la_language == language_unknown 933*5796c8dcSSimon Schubert || languages[i]->la_language == language_auto) 934*5796c8dcSSimon Schubert continue; 935*5796c8dcSSimon Schubert 936*5796c8dcSSimon Schubert /* FIXME: i18n: for now assume that the human-readable name 937*5796c8dcSSimon Schubert is just a capitalization of the internal name. */ 938*5796c8dcSSimon Schubert fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n", 939*5796c8dcSSimon Schubert languages[i]->la_name, 940*5796c8dcSSimon Schubert /* Capitalize first letter of language 941*5796c8dcSSimon Schubert name. */ 942*5796c8dcSSimon Schubert toupper (languages[i]->la_name[0]), 943*5796c8dcSSimon Schubert languages[i]->la_name + 1); 944*5796c8dcSSimon Schubert } 945*5796c8dcSSimon Schubert 946*5796c8dcSSimon Schubert language_set_doc = ui_file_xstrdup (tmp_stream, NULL); 947*5796c8dcSSimon Schubert ui_file_delete (tmp_stream); 948*5796c8dcSSimon Schubert 949*5796c8dcSSimon Schubert add_setshow_enum_cmd ("language", class_support, 950*5796c8dcSSimon Schubert (const char **) language_names, 951*5796c8dcSSimon Schubert &language, 952*5796c8dcSSimon Schubert language_set_doc, _("\ 953*5796c8dcSSimon Schubert Show the current source language."), NULL, 954*5796c8dcSSimon Schubert set_language_command, 955*5796c8dcSSimon Schubert show_language_command, 956*5796c8dcSSimon Schubert &setlist, &showlist); 957*5796c8dcSSimon Schubert 958*5796c8dcSSimon Schubert xfree (language_set_doc); 959*5796c8dcSSimon Schubert } 960*5796c8dcSSimon Schubert 961*5796c8dcSSimon Schubert /* Iterate through all registered languages looking for and calling 962*5796c8dcSSimon Schubert any non-NULL struct language_defn.skip_trampoline() functions. 963*5796c8dcSSimon Schubert Return the result from the first that returns non-zero, or 0 if all 964*5796c8dcSSimon Schubert `fail'. */ 965*5796c8dcSSimon Schubert CORE_ADDR 966*5796c8dcSSimon Schubert skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc) 967*5796c8dcSSimon Schubert { 968*5796c8dcSSimon Schubert int i; 969*5796c8dcSSimon Schubert 970*5796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 971*5796c8dcSSimon Schubert { 972*5796c8dcSSimon Schubert if (languages[i]->skip_trampoline) 973*5796c8dcSSimon Schubert { 974*5796c8dcSSimon Schubert CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc); 975*5796c8dcSSimon Schubert if (real_pc) 976*5796c8dcSSimon Schubert return real_pc; 977*5796c8dcSSimon Schubert } 978*5796c8dcSSimon Schubert } 979*5796c8dcSSimon Schubert 980*5796c8dcSSimon Schubert return 0; 981*5796c8dcSSimon Schubert } 982*5796c8dcSSimon Schubert 983*5796c8dcSSimon Schubert /* Return demangled language symbol, or NULL. 984*5796c8dcSSimon Schubert FIXME: Options are only useful for certain languages and ignored 985*5796c8dcSSimon Schubert by others, so it would be better to remove them here and have a 986*5796c8dcSSimon Schubert more flexible demangler for the languages that need it. 987*5796c8dcSSimon Schubert FIXME: Sometimes the demangler is invoked when we don't know the 988*5796c8dcSSimon Schubert language, so we can't use this everywhere. */ 989*5796c8dcSSimon Schubert char * 990*5796c8dcSSimon Schubert language_demangle (const struct language_defn *current_language, 991*5796c8dcSSimon Schubert const char *mangled, int options) 992*5796c8dcSSimon Schubert { 993*5796c8dcSSimon Schubert if (current_language != NULL && current_language->la_demangle) 994*5796c8dcSSimon Schubert return current_language->la_demangle (mangled, options); 995*5796c8dcSSimon Schubert return NULL; 996*5796c8dcSSimon Schubert } 997*5796c8dcSSimon Schubert 998*5796c8dcSSimon Schubert /* Return class name from physname or NULL. */ 999*5796c8dcSSimon Schubert char * 1000*5796c8dcSSimon Schubert language_class_name_from_physname (const struct language_defn *current_language, 1001*5796c8dcSSimon Schubert const char *physname) 1002*5796c8dcSSimon Schubert { 1003*5796c8dcSSimon Schubert if (current_language != NULL && current_language->la_class_name_from_physname) 1004*5796c8dcSSimon Schubert return current_language->la_class_name_from_physname (physname); 1005*5796c8dcSSimon Schubert return NULL; 1006*5796c8dcSSimon Schubert } 1007*5796c8dcSSimon Schubert 1008*5796c8dcSSimon Schubert /* Return non-zero if TYPE should be passed (and returned) by 1009*5796c8dcSSimon Schubert reference at the language level. */ 1010*5796c8dcSSimon Schubert int 1011*5796c8dcSSimon Schubert language_pass_by_reference (struct type *type) 1012*5796c8dcSSimon Schubert { 1013*5796c8dcSSimon Schubert return current_language->la_pass_by_reference (type); 1014*5796c8dcSSimon Schubert } 1015*5796c8dcSSimon Schubert 1016*5796c8dcSSimon Schubert /* Return zero; by default, types are passed by value at the language 1017*5796c8dcSSimon Schubert level. The target ABI may pass or return some structs by reference 1018*5796c8dcSSimon Schubert independent of this. */ 1019*5796c8dcSSimon Schubert int 1020*5796c8dcSSimon Schubert default_pass_by_reference (struct type *type) 1021*5796c8dcSSimon Schubert { 1022*5796c8dcSSimon Schubert return 0; 1023*5796c8dcSSimon Schubert } 1024*5796c8dcSSimon Schubert 1025*5796c8dcSSimon Schubert /* Return the default string containing the list of characters 1026*5796c8dcSSimon Schubert delimiting words. This is a reasonable default value that 1027*5796c8dcSSimon Schubert most languages should be able to use. */ 1028*5796c8dcSSimon Schubert 1029*5796c8dcSSimon Schubert char * 1030*5796c8dcSSimon Schubert default_word_break_characters (void) 1031*5796c8dcSSimon Schubert { 1032*5796c8dcSSimon Schubert return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; 1033*5796c8dcSSimon Schubert } 1034*5796c8dcSSimon Schubert 1035*5796c8dcSSimon Schubert /* Print the index of array elements using the C99 syntax. */ 1036*5796c8dcSSimon Schubert 1037*5796c8dcSSimon Schubert void 1038*5796c8dcSSimon Schubert default_print_array_index (struct value *index_value, struct ui_file *stream, 1039*5796c8dcSSimon Schubert const struct value_print_options *options) 1040*5796c8dcSSimon Schubert { 1041*5796c8dcSSimon Schubert fprintf_filtered (stream, "["); 1042*5796c8dcSSimon Schubert LA_VALUE_PRINT (index_value, stream, options); 1043*5796c8dcSSimon Schubert fprintf_filtered (stream, "] = "); 1044*5796c8dcSSimon Schubert } 1045*5796c8dcSSimon Schubert 1046*5796c8dcSSimon Schubert void 1047*5796c8dcSSimon Schubert default_get_string (struct value *value, gdb_byte **buffer, int *length, 1048*5796c8dcSSimon Schubert const char **charset) 1049*5796c8dcSSimon Schubert { 1050*5796c8dcSSimon Schubert error (_("Getting a string is unsupported in this language.")); 1051*5796c8dcSSimon Schubert } 1052*5796c8dcSSimon Schubert 1053*5796c8dcSSimon Schubert /* Define the language that is no language. */ 1054*5796c8dcSSimon Schubert 1055*5796c8dcSSimon Schubert static int 1056*5796c8dcSSimon Schubert unk_lang_parser (void) 1057*5796c8dcSSimon Schubert { 1058*5796c8dcSSimon Schubert return 1; 1059*5796c8dcSSimon Schubert } 1060*5796c8dcSSimon Schubert 1061*5796c8dcSSimon Schubert static void 1062*5796c8dcSSimon Schubert unk_lang_error (char *msg) 1063*5796c8dcSSimon Schubert { 1064*5796c8dcSSimon Schubert error (_("Attempted to parse an expression with unknown language")); 1065*5796c8dcSSimon Schubert } 1066*5796c8dcSSimon Schubert 1067*5796c8dcSSimon Schubert static void 1068*5796c8dcSSimon Schubert unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, 1069*5796c8dcSSimon Schubert int quoter) 1070*5796c8dcSSimon Schubert { 1071*5796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_emit_char called.")); 1072*5796c8dcSSimon Schubert } 1073*5796c8dcSSimon Schubert 1074*5796c8dcSSimon Schubert static void 1075*5796c8dcSSimon Schubert unk_lang_printchar (int c, struct type *type, struct ui_file *stream) 1076*5796c8dcSSimon Schubert { 1077*5796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_printchar called.")); 1078*5796c8dcSSimon Schubert } 1079*5796c8dcSSimon Schubert 1080*5796c8dcSSimon Schubert static void 1081*5796c8dcSSimon Schubert unk_lang_printstr (struct ui_file *stream, struct type *type, 1082*5796c8dcSSimon Schubert const gdb_byte *string, unsigned int length, 1083*5796c8dcSSimon Schubert int force_ellipses, 1084*5796c8dcSSimon Schubert const struct value_print_options *options) 1085*5796c8dcSSimon Schubert { 1086*5796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_printstr called.")); 1087*5796c8dcSSimon Schubert } 1088*5796c8dcSSimon Schubert 1089*5796c8dcSSimon Schubert static void 1090*5796c8dcSSimon Schubert unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream, 1091*5796c8dcSSimon Schubert int show, int level) 1092*5796c8dcSSimon Schubert { 1093*5796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_print_type called.")); 1094*5796c8dcSSimon Schubert } 1095*5796c8dcSSimon Schubert 1096*5796c8dcSSimon Schubert static int 1097*5796c8dcSSimon Schubert unk_lang_val_print (struct type *type, const gdb_byte *valaddr, 1098*5796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address, 1099*5796c8dcSSimon Schubert struct ui_file *stream, int recurse, 1100*5796c8dcSSimon Schubert const struct value_print_options *options) 1101*5796c8dcSSimon Schubert { 1102*5796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_val_print called.")); 1103*5796c8dcSSimon Schubert } 1104*5796c8dcSSimon Schubert 1105*5796c8dcSSimon Schubert static int 1106*5796c8dcSSimon Schubert unk_lang_value_print (struct value *val, struct ui_file *stream, 1107*5796c8dcSSimon Schubert const struct value_print_options *options) 1108*5796c8dcSSimon Schubert { 1109*5796c8dcSSimon Schubert error (_("internal error - unimplemented function unk_lang_value_print called.")); 1110*5796c8dcSSimon Schubert } 1111*5796c8dcSSimon Schubert 1112*5796c8dcSSimon Schubert static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) 1113*5796c8dcSSimon Schubert { 1114*5796c8dcSSimon Schubert return 0; 1115*5796c8dcSSimon Schubert } 1116*5796c8dcSSimon Schubert 1117*5796c8dcSSimon Schubert /* Unknown languages just use the cplus demangler. */ 1118*5796c8dcSSimon Schubert static char *unk_lang_demangle (const char *mangled, int options) 1119*5796c8dcSSimon Schubert { 1120*5796c8dcSSimon Schubert return cplus_demangle (mangled, options); 1121*5796c8dcSSimon Schubert } 1122*5796c8dcSSimon Schubert 1123*5796c8dcSSimon Schubert static char *unk_lang_class_name (const char *mangled) 1124*5796c8dcSSimon Schubert { 1125*5796c8dcSSimon Schubert return NULL; 1126*5796c8dcSSimon Schubert } 1127*5796c8dcSSimon Schubert 1128*5796c8dcSSimon Schubert static const struct op_print unk_op_print_tab[] = 1129*5796c8dcSSimon Schubert { 1130*5796c8dcSSimon Schubert {NULL, OP_NULL, PREC_NULL, 0} 1131*5796c8dcSSimon Schubert }; 1132*5796c8dcSSimon Schubert 1133*5796c8dcSSimon Schubert static void 1134*5796c8dcSSimon Schubert unknown_language_arch_info (struct gdbarch *gdbarch, 1135*5796c8dcSSimon Schubert struct language_arch_info *lai) 1136*5796c8dcSSimon Schubert { 1137*5796c8dcSSimon Schubert lai->string_char_type = builtin_type (gdbarch)->builtin_char; 1138*5796c8dcSSimon Schubert lai->bool_type_default = builtin_type (gdbarch)->builtin_int; 1139*5796c8dcSSimon Schubert lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, 1140*5796c8dcSSimon Schubert struct type *); 1141*5796c8dcSSimon Schubert } 1142*5796c8dcSSimon Schubert 1143*5796c8dcSSimon Schubert const struct language_defn unknown_language_defn = 1144*5796c8dcSSimon Schubert { 1145*5796c8dcSSimon Schubert "unknown", 1146*5796c8dcSSimon Schubert language_unknown, 1147*5796c8dcSSimon Schubert range_check_off, 1148*5796c8dcSSimon Schubert type_check_off, 1149*5796c8dcSSimon Schubert case_sensitive_on, 1150*5796c8dcSSimon Schubert array_row_major, 1151*5796c8dcSSimon Schubert macro_expansion_no, 1152*5796c8dcSSimon Schubert &exp_descriptor_standard, 1153*5796c8dcSSimon Schubert unk_lang_parser, 1154*5796c8dcSSimon Schubert unk_lang_error, 1155*5796c8dcSSimon Schubert null_post_parser, 1156*5796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 1157*5796c8dcSSimon Schubert unk_lang_printstr, 1158*5796c8dcSSimon Schubert unk_lang_emit_char, 1159*5796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 1160*5796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 1161*5796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 1162*5796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 1163*5796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 1164*5796c8dcSSimon Schubert "this", /* name_of_this */ 1165*5796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 1166*5796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 1167*5796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1168*5796c8dcSSimon Schubert unk_lang_class_name, /* Language specific class_name_from_physname */ 1169*5796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 1170*5796c8dcSSimon Schubert 1, /* c-style arrays */ 1171*5796c8dcSSimon Schubert 0, /* String lower bound */ 1172*5796c8dcSSimon Schubert default_word_break_characters, 1173*5796c8dcSSimon Schubert default_make_symbol_completion_list, 1174*5796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 1175*5796c8dcSSimon Schubert default_print_array_index, 1176*5796c8dcSSimon Schubert default_pass_by_reference, 1177*5796c8dcSSimon Schubert default_get_string, 1178*5796c8dcSSimon Schubert LANG_MAGIC 1179*5796c8dcSSimon Schubert }; 1180*5796c8dcSSimon Schubert 1181*5796c8dcSSimon Schubert /* These two structs define fake entries for the "local" and "auto" options. */ 1182*5796c8dcSSimon Schubert const struct language_defn auto_language_defn = 1183*5796c8dcSSimon Schubert { 1184*5796c8dcSSimon Schubert "auto", 1185*5796c8dcSSimon Schubert language_auto, 1186*5796c8dcSSimon Schubert range_check_off, 1187*5796c8dcSSimon Schubert type_check_off, 1188*5796c8dcSSimon Schubert case_sensitive_on, 1189*5796c8dcSSimon Schubert array_row_major, 1190*5796c8dcSSimon Schubert macro_expansion_no, 1191*5796c8dcSSimon Schubert &exp_descriptor_standard, 1192*5796c8dcSSimon Schubert unk_lang_parser, 1193*5796c8dcSSimon Schubert unk_lang_error, 1194*5796c8dcSSimon Schubert null_post_parser, 1195*5796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 1196*5796c8dcSSimon Schubert unk_lang_printstr, 1197*5796c8dcSSimon Schubert unk_lang_emit_char, 1198*5796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 1199*5796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 1200*5796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 1201*5796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 1202*5796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 1203*5796c8dcSSimon Schubert "this", /* name_of_this */ 1204*5796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 1205*5796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 1206*5796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1207*5796c8dcSSimon Schubert unk_lang_class_name, /* Language specific class_name_from_physname */ 1208*5796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 1209*5796c8dcSSimon Schubert 1, /* c-style arrays */ 1210*5796c8dcSSimon Schubert 0, /* String lower bound */ 1211*5796c8dcSSimon Schubert default_word_break_characters, 1212*5796c8dcSSimon Schubert default_make_symbol_completion_list, 1213*5796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 1214*5796c8dcSSimon Schubert default_print_array_index, 1215*5796c8dcSSimon Schubert default_pass_by_reference, 1216*5796c8dcSSimon Schubert default_get_string, 1217*5796c8dcSSimon Schubert LANG_MAGIC 1218*5796c8dcSSimon Schubert }; 1219*5796c8dcSSimon Schubert 1220*5796c8dcSSimon Schubert const struct language_defn local_language_defn = 1221*5796c8dcSSimon Schubert { 1222*5796c8dcSSimon Schubert "local", 1223*5796c8dcSSimon Schubert language_auto, 1224*5796c8dcSSimon Schubert range_check_off, 1225*5796c8dcSSimon Schubert type_check_off, 1226*5796c8dcSSimon Schubert case_sensitive_on, 1227*5796c8dcSSimon Schubert array_row_major, 1228*5796c8dcSSimon Schubert macro_expansion_no, 1229*5796c8dcSSimon Schubert &exp_descriptor_standard, 1230*5796c8dcSSimon Schubert unk_lang_parser, 1231*5796c8dcSSimon Schubert unk_lang_error, 1232*5796c8dcSSimon Schubert null_post_parser, 1233*5796c8dcSSimon Schubert unk_lang_printchar, /* Print character constant */ 1234*5796c8dcSSimon Schubert unk_lang_printstr, 1235*5796c8dcSSimon Schubert unk_lang_emit_char, 1236*5796c8dcSSimon Schubert unk_lang_print_type, /* Print a type using appropriate syntax */ 1237*5796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 1238*5796c8dcSSimon Schubert unk_lang_val_print, /* Print a value using appropriate syntax */ 1239*5796c8dcSSimon Schubert unk_lang_value_print, /* Print a top-level value */ 1240*5796c8dcSSimon Schubert unk_lang_trampoline, /* Language specific skip_trampoline */ 1241*5796c8dcSSimon Schubert "this", /* name_of_this */ 1242*5796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 1243*5796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 1244*5796c8dcSSimon Schubert unk_lang_demangle, /* Language specific symbol demangler */ 1245*5796c8dcSSimon Schubert unk_lang_class_name, /* Language specific class_name_from_physname */ 1246*5796c8dcSSimon Schubert unk_op_print_tab, /* expression operators for printing */ 1247*5796c8dcSSimon Schubert 1, /* c-style arrays */ 1248*5796c8dcSSimon Schubert 0, /* String lower bound */ 1249*5796c8dcSSimon Schubert default_word_break_characters, 1250*5796c8dcSSimon Schubert default_make_symbol_completion_list, 1251*5796c8dcSSimon Schubert unknown_language_arch_info, /* la_language_arch_info. */ 1252*5796c8dcSSimon Schubert default_print_array_index, 1253*5796c8dcSSimon Schubert default_pass_by_reference, 1254*5796c8dcSSimon Schubert default_get_string, 1255*5796c8dcSSimon Schubert LANG_MAGIC 1256*5796c8dcSSimon Schubert }; 1257*5796c8dcSSimon Schubert 1258*5796c8dcSSimon Schubert /* Per-architecture language information. */ 1259*5796c8dcSSimon Schubert 1260*5796c8dcSSimon Schubert static struct gdbarch_data *language_gdbarch_data; 1261*5796c8dcSSimon Schubert 1262*5796c8dcSSimon Schubert struct language_gdbarch 1263*5796c8dcSSimon Schubert { 1264*5796c8dcSSimon Schubert /* A vector of per-language per-architecture info. Indexed by "enum 1265*5796c8dcSSimon Schubert language". */ 1266*5796c8dcSSimon Schubert struct language_arch_info arch_info[nr_languages]; 1267*5796c8dcSSimon Schubert }; 1268*5796c8dcSSimon Schubert 1269*5796c8dcSSimon Schubert static void * 1270*5796c8dcSSimon Schubert language_gdbarch_post_init (struct gdbarch *gdbarch) 1271*5796c8dcSSimon Schubert { 1272*5796c8dcSSimon Schubert struct language_gdbarch *l; 1273*5796c8dcSSimon Schubert int i; 1274*5796c8dcSSimon Schubert 1275*5796c8dcSSimon Schubert l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); 1276*5796c8dcSSimon Schubert for (i = 0; i < languages_size; i++) 1277*5796c8dcSSimon Schubert { 1278*5796c8dcSSimon Schubert if (languages[i] != NULL 1279*5796c8dcSSimon Schubert && languages[i]->la_language_arch_info != NULL) 1280*5796c8dcSSimon Schubert languages[i]->la_language_arch_info 1281*5796c8dcSSimon Schubert (gdbarch, l->arch_info + languages[i]->la_language); 1282*5796c8dcSSimon Schubert } 1283*5796c8dcSSimon Schubert return l; 1284*5796c8dcSSimon Schubert } 1285*5796c8dcSSimon Schubert 1286*5796c8dcSSimon Schubert struct type * 1287*5796c8dcSSimon Schubert language_string_char_type (const struct language_defn *la, 1288*5796c8dcSSimon Schubert struct gdbarch *gdbarch) 1289*5796c8dcSSimon Schubert { 1290*5796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 1291*5796c8dcSSimon Schubert language_gdbarch_data); 1292*5796c8dcSSimon Schubert return ld->arch_info[la->la_language].string_char_type; 1293*5796c8dcSSimon Schubert } 1294*5796c8dcSSimon Schubert 1295*5796c8dcSSimon Schubert struct type * 1296*5796c8dcSSimon Schubert language_bool_type (const struct language_defn *la, 1297*5796c8dcSSimon Schubert struct gdbarch *gdbarch) 1298*5796c8dcSSimon Schubert { 1299*5796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 1300*5796c8dcSSimon Schubert language_gdbarch_data); 1301*5796c8dcSSimon Schubert 1302*5796c8dcSSimon Schubert if (ld->arch_info[la->la_language].bool_type_symbol) 1303*5796c8dcSSimon Schubert { 1304*5796c8dcSSimon Schubert struct symbol *sym; 1305*5796c8dcSSimon Schubert sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, 1306*5796c8dcSSimon Schubert NULL, VAR_DOMAIN, NULL); 1307*5796c8dcSSimon Schubert if (sym) 1308*5796c8dcSSimon Schubert { 1309*5796c8dcSSimon Schubert struct type *type = SYMBOL_TYPE (sym); 1310*5796c8dcSSimon Schubert if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) 1311*5796c8dcSSimon Schubert return type; 1312*5796c8dcSSimon Schubert } 1313*5796c8dcSSimon Schubert } 1314*5796c8dcSSimon Schubert 1315*5796c8dcSSimon Schubert return ld->arch_info[la->la_language].bool_type_default; 1316*5796c8dcSSimon Schubert } 1317*5796c8dcSSimon Schubert 1318*5796c8dcSSimon Schubert struct type * 1319*5796c8dcSSimon Schubert language_lookup_primitive_type_by_name (const struct language_defn *la, 1320*5796c8dcSSimon Schubert struct gdbarch *gdbarch, 1321*5796c8dcSSimon Schubert const char *name) 1322*5796c8dcSSimon Schubert { 1323*5796c8dcSSimon Schubert struct language_gdbarch *ld = gdbarch_data (gdbarch, 1324*5796c8dcSSimon Schubert language_gdbarch_data); 1325*5796c8dcSSimon Schubert struct type *const *p; 1326*5796c8dcSSimon Schubert for (p = ld->arch_info[la->la_language].primitive_type_vector; 1327*5796c8dcSSimon Schubert (*p) != NULL; 1328*5796c8dcSSimon Schubert p++) 1329*5796c8dcSSimon Schubert { 1330*5796c8dcSSimon Schubert if (strcmp (TYPE_NAME (*p), name) == 0) 1331*5796c8dcSSimon Schubert return (*p); 1332*5796c8dcSSimon Schubert } 1333*5796c8dcSSimon Schubert return (NULL); 1334*5796c8dcSSimon Schubert } 1335*5796c8dcSSimon Schubert 1336*5796c8dcSSimon Schubert /* Initialize the language routines */ 1337*5796c8dcSSimon Schubert 1338*5796c8dcSSimon Schubert void 1339*5796c8dcSSimon Schubert _initialize_language (void) 1340*5796c8dcSSimon Schubert { 1341*5796c8dcSSimon Schubert static const char *type_or_range_names[] 1342*5796c8dcSSimon Schubert = { "on", "off", "warn", "auto", NULL }; 1343*5796c8dcSSimon Schubert 1344*5796c8dcSSimon Schubert static const char *case_sensitive_names[] 1345*5796c8dcSSimon Schubert = { "on", "off", "auto", NULL }; 1346*5796c8dcSSimon Schubert 1347*5796c8dcSSimon Schubert language_gdbarch_data 1348*5796c8dcSSimon Schubert = gdbarch_data_register_post_init (language_gdbarch_post_init); 1349*5796c8dcSSimon Schubert 1350*5796c8dcSSimon Schubert /* GDB commands for language specific stuff */ 1351*5796c8dcSSimon Schubert 1352*5796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, set_check, 1353*5796c8dcSSimon Schubert _("Set the status of the type/range checker."), 1354*5796c8dcSSimon Schubert &setchecklist, "set check ", 0, &setlist); 1355*5796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &setlist); 1356*5796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &setlist); 1357*5796c8dcSSimon Schubert 1358*5796c8dcSSimon Schubert add_prefix_cmd ("check", no_class, show_check, 1359*5796c8dcSSimon Schubert _("Show the status of the type/range checker."), 1360*5796c8dcSSimon Schubert &showchecklist, "show check ", 0, &showlist); 1361*5796c8dcSSimon Schubert add_alias_cmd ("c", "check", no_class, 1, &showlist); 1362*5796c8dcSSimon Schubert add_alias_cmd ("ch", "check", no_class, 1, &showlist); 1363*5796c8dcSSimon Schubert 1364*5796c8dcSSimon Schubert add_setshow_enum_cmd ("type", class_support, type_or_range_names, &type, _("\ 1365*5796c8dcSSimon Schubert Set type checking. (on/warn/off/auto)"), _("\ 1366*5796c8dcSSimon Schubert Show type checking. (on/warn/off/auto)"), NULL, 1367*5796c8dcSSimon Schubert set_type_command, 1368*5796c8dcSSimon Schubert show_type_command, 1369*5796c8dcSSimon Schubert &setchecklist, &showchecklist); 1370*5796c8dcSSimon Schubert 1371*5796c8dcSSimon Schubert add_setshow_enum_cmd ("range", class_support, type_or_range_names, 1372*5796c8dcSSimon Schubert &range, _("\ 1373*5796c8dcSSimon Schubert Set range checking. (on/warn/off/auto)"), _("\ 1374*5796c8dcSSimon Schubert Show range checking. (on/warn/off/auto)"), NULL, 1375*5796c8dcSSimon Schubert set_range_command, 1376*5796c8dcSSimon Schubert show_range_command, 1377*5796c8dcSSimon Schubert &setchecklist, &showchecklist); 1378*5796c8dcSSimon Schubert 1379*5796c8dcSSimon Schubert add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names, 1380*5796c8dcSSimon Schubert &case_sensitive, _("\ 1381*5796c8dcSSimon Schubert Set case sensitivity in name search. (on/off/auto)"), _("\ 1382*5796c8dcSSimon Schubert Show case sensitivity in name search. (on/off/auto)"), _("\ 1383*5796c8dcSSimon Schubert For Fortran the default is off; for other languages the default is on."), 1384*5796c8dcSSimon Schubert set_case_command, 1385*5796c8dcSSimon Schubert show_case_command, 1386*5796c8dcSSimon Schubert &setlist, &showlist); 1387*5796c8dcSSimon Schubert 1388*5796c8dcSSimon Schubert add_language (&auto_language_defn); 1389*5796c8dcSSimon Schubert add_language (&local_language_defn); 1390*5796c8dcSSimon Schubert add_language (&unknown_language_defn); 1391*5796c8dcSSimon Schubert 1392*5796c8dcSSimon Schubert language = xstrdup ("auto"); 1393*5796c8dcSSimon Schubert type = xstrdup ("auto"); 1394*5796c8dcSSimon Schubert range = xstrdup ("auto"); 1395*5796c8dcSSimon Schubert case_sensitive = xstrdup ("auto"); 1396*5796c8dcSSimon Schubert 1397*5796c8dcSSimon Schubert /* Have the above take effect */ 1398*5796c8dcSSimon Schubert set_language (language_auto); 1399*5796c8dcSSimon Schubert } 1400