119370Spst/* Multiple source language support for GDB. 2130803Smarcel 3130803Smarcel Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 4130803Smarcel 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 5130803Smarcel 619370Spst Contributed by the Department of Computer Science at the State University 719370Spst of New York at Buffalo. 819370Spst 998944Sobrien This file is part of GDB. 1019370Spst 1198944Sobrien This program is free software; you can redistribute it and/or modify 1298944Sobrien it under the terms of the GNU General Public License as published by 1398944Sobrien the Free Software Foundation; either version 2 of the License, or 1498944Sobrien (at your option) any later version. 1519370Spst 1698944Sobrien This program is distributed in the hope that it will be useful, 1798944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1898944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1998944Sobrien GNU General Public License for more details. 2019370Spst 2198944Sobrien You should have received a copy of the GNU General Public License 2298944Sobrien along with this program; if not, write to the Free Software 2398944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2498944Sobrien Boston, MA 02111-1307, USA. */ 2519370Spst 2619370Spst/* This file contains functions that return things that are specific 2719370Spst to languages. Each function should examine current_language if necessary, 2819370Spst and return the appropriate result. */ 2919370Spst 3019370Spst/* FIXME: Most of these would be better organized as macros which 3119370Spst return data out of a "language-specific" struct pointer that is set 3219370Spst whenever the working language changes. That would be a lot faster. */ 3319370Spst 3419370Spst#include "defs.h" 3519370Spst#include <ctype.h> 3619370Spst#include "gdb_string.h" 3719370Spst 3819370Spst#include "symtab.h" 3919370Spst#include "gdbtypes.h" 4019370Spst#include "value.h" 4119370Spst#include "gdbcmd.h" 4219370Spst#include "expression.h" 4319370Spst#include "language.h" 4419370Spst#include "target.h" 4519370Spst#include "parser-defs.h" 4698944Sobrien#include "jv-lang.h" 47130803Smarcel#include "demangle.h" 4819370Spst 4998944Sobrienextern void _initialize_language (void); 5019370Spst 5198944Sobrienstatic void show_language_command (char *, int); 5219370Spst 5398944Sobrienstatic void set_language_command (char *, int); 5419370Spst 5598944Sobrienstatic void show_type_command (char *, int); 5619370Spst 5798944Sobrienstatic void set_type_command (char *, int); 5819370Spst 5998944Sobrienstatic void show_range_command (char *, int); 6019370Spst 6198944Sobrienstatic void set_range_command (char *, int); 6219370Spst 6398944Sobrienstatic void show_case_command (char *, int); 6419370Spst 6598944Sobrienstatic void set_case_command (char *, int); 6619370Spst 6798944Sobrienstatic void set_case_str (void); 6819370Spst 6998944Sobrienstatic void set_range_str (void); 7019370Spst 7198944Sobrienstatic void set_type_str (void); 7219370Spst 7398944Sobrienstatic void set_lang_str (void); 7419370Spst 7598944Sobrienstatic void unk_lang_error (char *); 7619370Spst 7798944Sobrienstatic int unk_lang_parser (void); 7846283Sdfr 7998944Sobrienstatic void show_check (char *, int); 8046283Sdfr 8198944Sobrienstatic void set_check (char *, int); 8246283Sdfr 8398944Sobrienstatic void set_type_range_case (void); 8446283Sdfr 8598944Sobrienstatic void unk_lang_emit_char (int c, struct ui_file *stream, int quoter); 8646283Sdfr 8798944Sobrienstatic void unk_lang_printchar (int c, struct ui_file *stream); 8846283Sdfr 8998944Sobrienstatic void unk_lang_printstr (struct ui_file * stream, char *string, 9098944Sobrien unsigned int length, int width, 9198944Sobrien int force_ellipses); 9246283Sdfr 9398944Sobrienstatic struct type *unk_lang_create_fundamental_type (struct objfile *, int); 9498944Sobrien 9598944Sobrienstatic void unk_lang_print_type (struct type *, char *, struct ui_file *, 9698944Sobrien int, int); 9798944Sobrien 9898944Sobrienstatic int unk_lang_val_print (struct type *, char *, int, CORE_ADDR, 9998944Sobrien struct ui_file *, int, int, int, 10098944Sobrien enum val_prettyprint); 10198944Sobrien 10298944Sobrienstatic int unk_lang_value_print (struct value *, struct ui_file *, int, enum val_prettyprint); 10398944Sobrien 104130803Smarcelstatic CORE_ADDR unk_lang_trampoline (CORE_ADDR pc); 105130803Smarcel 10619370Spst/* Forward declaration */ 10719370Spstextern const struct language_defn unknown_language_defn; 10898944Sobrien 10919370Spst/* The current (default at startup) state of type and range checking. 11098944Sobrien (If the modes are set to "auto", though, these are changed based 11198944Sobrien on the default language at startup, and then again based on the 11298944Sobrien language of the first source file. */ 11319370Spst 11419370Spstenum range_mode range_mode = range_mode_auto; 11519370Spstenum range_check range_check = range_check_off; 11619370Spstenum type_mode type_mode = type_mode_auto; 11719370Spstenum type_check type_check = type_check_off; 11898944Sobrienenum case_mode case_mode = case_mode_auto; 11998944Sobrienenum case_sensitivity case_sensitivity = case_sensitive_on; 12019370Spst 12119370Spst/* The current language and language_mode (see language.h) */ 12219370Spst 12319370Spstconst struct language_defn *current_language = &unknown_language_defn; 12419370Spstenum language_mode language_mode = language_mode_auto; 12519370Spst 12619370Spst/* The language that the user expects to be typing in (the language 12719370Spst of main(), or the last language we notified them about, or C). */ 12819370Spst 12919370Spstconst struct language_defn *expected_language; 13019370Spst 13119370Spst/* The list of supported languages. The list itself is malloc'd. */ 13219370Spst 13319370Spststatic const struct language_defn **languages; 13419370Spststatic unsigned languages_size; 13519370Spststatic unsigned languages_allocsize; 13619370Spst#define DEFAULT_ALLOCSIZE 4 13719370Spst 13819370Spst/* The "set language/type/range" commands all put stuff in these 13919370Spst buffers. This is to make them work as set/show commands. The 14019370Spst user's string is copied here, then the set_* commands look at 14119370Spst them and update them to something that looks nice when it is 14219370Spst printed out. */ 14319370Spst 14419370Spststatic char *language; 14519370Spststatic char *type; 14619370Spststatic char *range; 14798944Sobrienstatic char *case_sensitive; 14819370Spst 14919370Spst/* Warning issued when current_language and the language of the current 15019370Spst frame do not match. */ 15119370Spstchar lang_frame_mismatch_warn[] = 15298944Sobrien"Warning: the current language does not match this frame."; 15398944Sobrien 15419370Spst/* This page contains the functions corresponding to GDB commands 15519370Spst and their helpers. */ 15619370Spst 15719370Spst/* Show command. Display a warning if the language set 15819370Spst does not match the frame. */ 15919370Spststatic void 16098944Sobrienshow_language_command (char *ignore, int from_tty) 16119370Spst{ 16298944Sobrien enum language flang; /* The language of the current frame */ 16319370Spst 16498944Sobrien flang = get_frame_language (); 16598944Sobrien if (flang != language_unknown && 16698944Sobrien language_mode == language_mode_manual && 16798944Sobrien current_language->la_language != flang) 16898944Sobrien printf_filtered ("%s\n", lang_frame_mismatch_warn); 16919370Spst} 17019370Spst 17119370Spst/* Set command. Change the current working language. */ 17219370Spststatic void 17398944Sobrienset_language_command (char *ignore, int from_tty) 17419370Spst{ 17519370Spst int i; 17619370Spst enum language flang; 17719370Spst char *err_lang; 17819370Spst 17919370Spst if (!language || !language[0]) 18019370Spst { 18198944Sobrien printf_unfiltered ("The currently understood settings are:\n\n"); 18219370Spst printf_unfiltered ("local or auto Automatic setting based on source file\n"); 18319370Spst 18419370Spst for (i = 0; i < languages_size; ++i) 18519370Spst { 18619370Spst /* Already dealt with these above. */ 18719370Spst if (languages[i]->la_language == language_unknown 18819370Spst || languages[i]->la_language == language_auto) 18919370Spst continue; 19019370Spst 19119370Spst /* FIXME for now assume that the human-readable name is just 19219370Spst a capitalization of the internal name. */ 19319370Spst printf_unfiltered ("%-16s Use the %c%s language\n", 19419370Spst languages[i]->la_name, 19598944Sobrien /* Capitalize first letter of language 19698944Sobrien name. */ 19719370Spst toupper (languages[i]->la_name[0]), 19819370Spst languages[i]->la_name + 1); 19919370Spst } 20019370Spst /* Restore the silly string. */ 20198944Sobrien set_language (current_language->la_language); 20219370Spst return; 20319370Spst } 20419370Spst 20519370Spst /* Search the list of languages for a match. */ 20698944Sobrien for (i = 0; i < languages_size; i++) 20798944Sobrien { 208130803Smarcel if (strcmp (languages[i]->la_name, language) == 0) 20998944Sobrien { 21098944Sobrien /* Found it! Go into manual mode, and use this language. */ 21198944Sobrien if (languages[i]->la_language == language_auto) 21298944Sobrien { 21398944Sobrien /* Enter auto mode. Set to the current frame's language, if known. */ 21498944Sobrien language_mode = language_mode_auto; 21598944Sobrien flang = get_frame_language (); 21698944Sobrien if (flang != language_unknown) 21798944Sobrien set_language (flang); 21898944Sobrien expected_language = current_language; 21998944Sobrien return; 22098944Sobrien } 22198944Sobrien else 22298944Sobrien { 22398944Sobrien /* Enter manual mode. Set the specified language. */ 22498944Sobrien language_mode = language_mode_manual; 22598944Sobrien current_language = languages[i]; 22698944Sobrien set_type_range_case (); 22798944Sobrien set_lang_str (); 22898944Sobrien expected_language = current_language; 22998944Sobrien return; 23098944Sobrien } 23198944Sobrien } 23219370Spst } 23319370Spst 23419370Spst /* Reset the language (esp. the global string "language") to the 23519370Spst correct values. */ 23698944Sobrien err_lang = savestring (language, strlen (language)); 23798944Sobrien make_cleanup (xfree, err_lang); /* Free it after error */ 23898944Sobrien set_language (current_language->la_language); 23998944Sobrien error ("Unknown language `%s'.", err_lang); 24019370Spst} 24119370Spst 24219370Spst/* Show command. Display a warning if the type setting does 24319370Spst not match the current language. */ 24419370Spststatic void 24598944Sobrienshow_type_command (char *ignore, int from_tty) 24619370Spst{ 24798944Sobrien if (type_check != current_language->la_type_check) 24898944Sobrien printf_unfiltered ( 24998944Sobrien "Warning: the current type check setting does not match the language.\n"); 25019370Spst} 25119370Spst 25219370Spst/* Set command. Change the setting for type checking. */ 25319370Spststatic void 25498944Sobrienset_type_command (char *ignore, int from_tty) 25519370Spst{ 256130803Smarcel if (strcmp (type, "on") == 0) 25798944Sobrien { 25819370Spst type_check = type_check_on; 25919370Spst type_mode = type_mode_manual; 26098944Sobrien } 261130803Smarcel else if (strcmp (type, "warn") == 0) 26298944Sobrien { 26319370Spst type_check = type_check_warn; 26419370Spst type_mode = type_mode_manual; 26598944Sobrien } 266130803Smarcel else if (strcmp (type, "off") == 0) 26798944Sobrien { 26819370Spst type_check = type_check_off; 26919370Spst type_mode = type_mode_manual; 27098944Sobrien } 271130803Smarcel else if (strcmp (type, "auto") == 0) 27298944Sobrien { 27319370Spst type_mode = type_mode_auto; 27498944Sobrien set_type_range_case (); 27519370Spst /* Avoid hitting the set_type_str call below. We 27698944Sobrien did it in set_type_range_case. */ 27719370Spst return; 27898944Sobrien } 27998944Sobrien else 28098944Sobrien { 28198944Sobrien warning ("Unrecognized type check setting: \"%s\"", type); 28298944Sobrien } 28398944Sobrien set_type_str (); 28498944Sobrien show_type_command ((char *) NULL, from_tty); 28519370Spst} 28619370Spst 28719370Spst/* Show command. Display a warning if the range setting does 28819370Spst not match the current language. */ 28919370Spststatic void 29098944Sobrienshow_range_command (char *ignore, int from_tty) 29119370Spst{ 29219370Spst 29398944Sobrien if (range_check != current_language->la_range_check) 29498944Sobrien printf_unfiltered ( 29598944Sobrien "Warning: the current range check setting does not match the language.\n"); 29619370Spst} 29719370Spst 29819370Spst/* Set command. Change the setting for range checking. */ 29919370Spststatic void 30098944Sobrienset_range_command (char *ignore, int from_tty) 30119370Spst{ 302130803Smarcel if (strcmp (range, "on") == 0) 30398944Sobrien { 30419370Spst range_check = range_check_on; 30519370Spst range_mode = range_mode_manual; 30698944Sobrien } 307130803Smarcel else if (strcmp (range, "warn") == 0) 30898944Sobrien { 30919370Spst range_check = range_check_warn; 31019370Spst range_mode = range_mode_manual; 31198944Sobrien } 312130803Smarcel else if (strcmp (range, "off") == 0) 31398944Sobrien { 31419370Spst range_check = range_check_off; 31519370Spst range_mode = range_mode_manual; 31698944Sobrien } 317130803Smarcel else if (strcmp (range, "auto") == 0) 31898944Sobrien { 31919370Spst range_mode = range_mode_auto; 32098944Sobrien set_type_range_case (); 32119370Spst /* Avoid hitting the set_range_str call below. We 32298944Sobrien did it in set_type_range_case. */ 32319370Spst return; 32498944Sobrien } 32598944Sobrien else 32698944Sobrien { 32798944Sobrien warning ("Unrecognized range check setting: \"%s\"", range); 32898944Sobrien } 32998944Sobrien set_range_str (); 33098944Sobrien show_range_command ((char *) 0, from_tty); 33198944Sobrien} 33298944Sobrien 33398944Sobrien/* Show command. Display a warning if the case sensitivity setting does 33498944Sobrien not match the current language. */ 33598944Sobrienstatic void 33698944Sobrienshow_case_command (char *ignore, int from_tty) 33798944Sobrien{ 33898944Sobrien if (case_sensitivity != current_language->la_case_sensitivity) 33998944Sobrien printf_unfiltered( 34098944Sobrien"Warning: the current case sensitivity setting does not match the language.\n"); 34198944Sobrien} 34298944Sobrien 34398944Sobrien/* Set command. Change the setting for case sensitivity. */ 34498944Sobrienstatic void 34598944Sobrienset_case_command (char *ignore, int from_tty) 34698944Sobrien{ 347130803Smarcel if (DEPRECATED_STREQ (case_sensitive, "on")) 34898944Sobrien { 34998944Sobrien case_sensitivity = case_sensitive_on; 35098944Sobrien case_mode = case_mode_manual; 35119370Spst } 352130803Smarcel else if (DEPRECATED_STREQ (case_sensitive, "off")) 35398944Sobrien { 35498944Sobrien case_sensitivity = case_sensitive_off; 35598944Sobrien case_mode = case_mode_manual; 35698944Sobrien } 357130803Smarcel else if (DEPRECATED_STREQ (case_sensitive, "auto")) 35898944Sobrien { 35998944Sobrien case_mode = case_mode_auto; 36098944Sobrien set_type_range_case (); 36198944Sobrien /* Avoid hitting the set_case_str call below. We 36298944Sobrien did it in set_type_range_case. */ 36398944Sobrien return; 36498944Sobrien } 36598944Sobrien else 36698944Sobrien { 36798944Sobrien warning ("Unrecognized case-sensitive setting: \"%s\"", case_sensitive); 36898944Sobrien } 36998944Sobrien set_case_str(); 37098944Sobrien show_case_command ((char *) NULL, from_tty); 37119370Spst} 37219370Spst 37398944Sobrien/* Set the status of range and type checking and case sensitivity based on 37419370Spst the current modes and the current language. 37519370Spst If SHOW is non-zero, then print out the current language, 37619370Spst type and range checking status. */ 37719370Spststatic void 37898944Sobrienset_type_range_case (void) 37919370Spst{ 38019370Spst 38119370Spst if (range_mode == range_mode_auto) 38219370Spst range_check = current_language->la_range_check; 38319370Spst 38419370Spst if (type_mode == type_mode_auto) 38519370Spst type_check = current_language->la_type_check; 38619370Spst 38798944Sobrien if (case_mode == case_mode_auto) 38898944Sobrien case_sensitivity = current_language->la_case_sensitivity; 38998944Sobrien 39098944Sobrien set_type_str (); 39198944Sobrien set_range_str (); 39298944Sobrien set_case_str (); 39319370Spst} 39419370Spst 39546283Sdfr/* Set current language to (enum language) LANG. Returns previous language. */ 39619370Spst 39746283Sdfrenum language 39898944Sobrienset_language (enum language lang) 39919370Spst{ 40019370Spst int i; 40146283Sdfr enum language prev_language; 40219370Spst 40346283Sdfr prev_language = current_language->la_language; 40446283Sdfr 40598944Sobrien for (i = 0; i < languages_size; i++) 40698944Sobrien { 40798944Sobrien if (languages[i]->la_language == lang) 40898944Sobrien { 40998944Sobrien current_language = languages[i]; 41098944Sobrien set_type_range_case (); 41198944Sobrien set_lang_str (); 41298944Sobrien break; 41398944Sobrien } 41419370Spst } 41546283Sdfr 41646283Sdfr return prev_language; 41719370Spst} 41819370Spst 41919370Spst/* This page contains functions that update the global vars 42019370Spst language, type and range. */ 42119370Spststatic void 42298944Sobrienset_lang_str (void) 42319370Spst{ 42498944Sobrien char *prefix = ""; 42519370Spst 42698944Sobrien if (language) 42798944Sobrien xfree (language); 42898944Sobrien if (language_mode == language_mode_auto) 42998944Sobrien prefix = "auto; currently "; 43019370Spst 43198944Sobrien language = concat (prefix, current_language->la_name, NULL); 43219370Spst} 43319370Spst 43419370Spststatic void 43598944Sobrienset_type_str (void) 43619370Spst{ 43798944Sobrien char *tmp = NULL, *prefix = ""; 43819370Spst 43998944Sobrien if (type) 44098944Sobrien xfree (type); 44198944Sobrien if (type_mode == type_mode_auto) 44298944Sobrien prefix = "auto; currently "; 44319370Spst 44498944Sobrien switch (type_check) 44598944Sobrien { 44698944Sobrien case type_check_on: 44719370Spst tmp = "on"; 44819370Spst break; 44998944Sobrien case type_check_off: 45019370Spst tmp = "off"; 45119370Spst break; 45298944Sobrien case type_check_warn: 45319370Spst tmp = "warn"; 45419370Spst break; 45598944Sobrien default: 45619370Spst error ("Unrecognized type check setting."); 45798944Sobrien } 45819370Spst 45998944Sobrien type = concat (prefix, tmp, NULL); 46019370Spst} 46119370Spst 46219370Spststatic void 46398944Sobrienset_range_str (void) 46419370Spst{ 46598944Sobrien char *tmp, *pref = ""; 46619370Spst 46798944Sobrien if (range_mode == range_mode_auto) 46898944Sobrien pref = "auto; currently "; 46919370Spst 47098944Sobrien switch (range_check) 47198944Sobrien { 47298944Sobrien case range_check_on: 47319370Spst tmp = "on"; 47419370Spst break; 47598944Sobrien case range_check_off: 47619370Spst tmp = "off"; 47719370Spst break; 47898944Sobrien case range_check_warn: 47919370Spst tmp = "warn"; 48019370Spst break; 48198944Sobrien default: 48219370Spst error ("Unrecognized range check setting."); 48398944Sobrien } 48498944Sobrien 48598944Sobrien if (range) 48698944Sobrien xfree (range); 48798944Sobrien range = concat (pref, tmp, NULL); 48898944Sobrien} 48998944Sobrien 49098944Sobrienstatic void 491130803Smarcelset_case_str (void) 49298944Sobrien{ 49398944Sobrien char *tmp = NULL, *prefix = ""; 49498944Sobrien 49598944Sobrien if (case_mode==case_mode_auto) 49698944Sobrien prefix = "auto; currently "; 49798944Sobrien 49898944Sobrien switch (case_sensitivity) 49998944Sobrien { 50098944Sobrien case case_sensitive_on: 50198944Sobrien tmp = "on"; 50298944Sobrien break; 50398944Sobrien case case_sensitive_off: 50498944Sobrien tmp = "off"; 50598944Sobrien break; 50698944Sobrien default: 50798944Sobrien error ("Unrecognized case-sensitive setting."); 50819370Spst } 50919370Spst 51098944Sobrien xfree (case_sensitive); 51198944Sobrien case_sensitive = concat (prefix, tmp, NULL); 51219370Spst} 51319370Spst 51419370Spst/* Print out the current language settings: language, range and 51519370Spst type checking. If QUIETLY, print only what has changed. */ 51619370Spst 51719370Spstvoid 51898944Sobrienlanguage_info (int quietly) 51919370Spst{ 52019370Spst if (quietly && expected_language == current_language) 52119370Spst return; 52219370Spst 52319370Spst expected_language = current_language; 52498944Sobrien printf_unfiltered ("Current language: %s\n", language); 52598944Sobrien show_language_command ((char *) 0, 1); 52619370Spst 52719370Spst if (!quietly) 52819370Spst { 52998944Sobrien printf_unfiltered ("Type checking: %s\n", type); 53098944Sobrien show_type_command ((char *) 0, 1); 53198944Sobrien printf_unfiltered ("Range checking: %s\n", range); 53298944Sobrien show_range_command ((char *) 0, 1); 53398944Sobrien printf_unfiltered ("Case sensitivity: %s\n", case_sensitive); 53498944Sobrien show_case_command ((char *) 0, 1); 53519370Spst } 53619370Spst} 53719370Spst 53819370Spst/* Return the result of a binary operation. */ 53919370Spst 54098944Sobrien#if 0 /* Currently unused */ 54119370Spst 54219370Spststruct type * 54398944Sobrienbinop_result_type (struct value *v1, struct value *v2) 54419370Spst{ 54598944Sobrien int size, uns; 54698944Sobrien struct type *t1 = check_typedef (VALUE_TYPE (v1)); 54798944Sobrien struct type *t2 = check_typedef (VALUE_TYPE (v2)); 54819370Spst 54998944Sobrien int l1 = TYPE_LENGTH (t1); 55098944Sobrien int l2 = TYPE_LENGTH (t2); 55119370Spst 55298944Sobrien switch (current_language->la_language) 55398944Sobrien { 55498944Sobrien case language_c: 55598944Sobrien case language_cplus: 556130803Smarcel case language_objc: 55798944Sobrien if (TYPE_CODE (t1) == TYPE_CODE_FLT) 55898944Sobrien return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ? 55998944Sobrien VALUE_TYPE (v2) : VALUE_TYPE (v1); 56098944Sobrien else if (TYPE_CODE (t2) == TYPE_CODE_FLT) 56198944Sobrien return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ? 56298944Sobrien VALUE_TYPE (v1) : VALUE_TYPE (v2); 56398944Sobrien else if (TYPE_UNSIGNED (t1) && l1 > l2) 56498944Sobrien return VALUE_TYPE (v1); 56598944Sobrien else if (TYPE_UNSIGNED (t2) && l2 > l1) 56698944Sobrien return VALUE_TYPE (v2); 56798944Sobrien else /* Both are signed. Result is the longer type */ 56898944Sobrien return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 56919370Spst break; 57098944Sobrien case language_m2: 57119370Spst /* If we are doing type-checking, l1 should equal l2, so this is 57298944Sobrien not needed. */ 57398944Sobrien return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); 57419370Spst break; 57598944Sobrien } 57698944Sobrien internal_error (__FILE__, __LINE__, "failed internal consistency check"); 57798944Sobrien return (struct type *) 0; /* For lint */ 57819370Spst} 57919370Spst 58098944Sobrien#endif /* 0 */ 58198944Sobrien 58219370Spst 58319370Spst/* This page contains functions that return format strings for 58419370Spst printf for printing out numbers in different formats */ 58519370Spst 58619370Spst/* Returns the appropriate printf format for hexadecimal 58719370Spst numbers. */ 58819370Spstchar * 58998944Sobrienlocal_hex_format_custom (char *pre) 59019370Spst{ 59198944Sobrien static char form[50]; 59219370Spst 59398944Sobrien strcpy (form, local_hex_format_prefix ()); 59498944Sobrien strcat (form, "%"); 59598944Sobrien strcat (form, pre); 59698944Sobrien strcat (form, local_hex_format_specifier ()); 59798944Sobrien strcat (form, local_hex_format_suffix ()); 59898944Sobrien return form; 59919370Spst} 60019370Spst 601130803Smarcel/* Converts a LONGEST to custom hexadecimal and stores it in a static 60219370Spst string. Returns a pointer to this string. */ 60319370Spstchar * 604130803Smarcellocal_hex_string (LONGEST num) 60519370Spst{ 606130803Smarcel return local_hex_string_custom (num, "l"); 60719370Spst} 60819370Spst 60998944Sobrien/* Converts a LONGEST number to custom hexadecimal and stores it in a static 61098944Sobrien string. Returns a pointer to this string. Note that the width parameter 61198944Sobrien should end with "l", e.g. "08l" as with calls to local_hex_string_custom */ 61298944Sobrien 61398944Sobrienchar * 614130803Smarcellocal_hex_string_custom (LONGEST num, char *width) 61598944Sobrien{ 61698944Sobrien#define RESULT_BUF_LEN 50 61798944Sobrien static char res2[RESULT_BUF_LEN]; 61898944Sobrien char format[RESULT_BUF_LEN]; 61998944Sobrien int field_width; 62098944Sobrien int num_len; 62198944Sobrien int num_pad_chars; 62298944Sobrien char *pad_char; /* string with one character */ 62398944Sobrien int pad_on_left; 62498944Sobrien char *parse_ptr; 62598944Sobrien char temp_nbr_buf[RESULT_BUF_LEN]; 62698944Sobrien 62798944Sobrien /* Use phex_nz to print the number into a string, then 62898944Sobrien build the result string from local_hex_format_prefix, padding and 62998944Sobrien the hex representation as indicated by "width". */ 63098944Sobrien strcpy (temp_nbr_buf, phex_nz (num, sizeof (num))); 63198944Sobrien /* parse width */ 63298944Sobrien parse_ptr = width; 63398944Sobrien pad_on_left = 1; 63498944Sobrien pad_char = " "; 63598944Sobrien if (*parse_ptr == '-') 63698944Sobrien { 63798944Sobrien parse_ptr++; 63898944Sobrien pad_on_left = 0; 63998944Sobrien } 64098944Sobrien if (*parse_ptr == '0') 64198944Sobrien { 64298944Sobrien parse_ptr++; 64398944Sobrien if (pad_on_left) 64498944Sobrien pad_char = "0"; /* If padding is on the right, it is blank */ 64598944Sobrien } 64698944Sobrien field_width = atoi (parse_ptr); 64798944Sobrien num_len = strlen (temp_nbr_buf); 64898944Sobrien num_pad_chars = field_width - strlen (temp_nbr_buf); /* possibly negative */ 64998944Sobrien 65098944Sobrien if (strlen (local_hex_format_prefix ()) + num_len + num_pad_chars 65198944Sobrien >= RESULT_BUF_LEN) /* paranoia */ 65298944Sobrien internal_error (__FILE__, __LINE__, 653130803Smarcel "local_hex_string_custom: insufficient space to store result"); 65498944Sobrien 65598944Sobrien strcpy (res2, local_hex_format_prefix ()); 65698944Sobrien if (pad_on_left) 65798944Sobrien { 65898944Sobrien while (num_pad_chars > 0) 65998944Sobrien { 66098944Sobrien strcat (res2, pad_char); 66198944Sobrien num_pad_chars--; 66298944Sobrien } 66398944Sobrien } 66498944Sobrien strcat (res2, temp_nbr_buf); 66598944Sobrien if (!pad_on_left) 66698944Sobrien { 66798944Sobrien while (num_pad_chars > 0) 66898944Sobrien { 66998944Sobrien strcat (res2, pad_char); 67098944Sobrien num_pad_chars--; 67198944Sobrien } 67298944Sobrien } 67398944Sobrien return res2; 67498944Sobrien 675130803Smarcel} /* local_hex_string_custom */ 67698944Sobrien 67719370Spst/* Returns the appropriate printf format for octal 67819370Spst numbers. */ 67919370Spstchar * 68098944Sobrienlocal_octal_format_custom (char *pre) 68119370Spst{ 68298944Sobrien static char form[50]; 68319370Spst 68498944Sobrien strcpy (form, local_octal_format_prefix ()); 68598944Sobrien strcat (form, "%"); 68698944Sobrien strcat (form, pre); 68798944Sobrien strcat (form, local_octal_format_specifier ()); 68898944Sobrien strcat (form, local_octal_format_suffix ()); 68998944Sobrien return form; 69019370Spst} 69119370Spst 69219370Spst/* Returns the appropriate printf format for decimal numbers. */ 69319370Spstchar * 69498944Sobrienlocal_decimal_format_custom (char *pre) 69519370Spst{ 69698944Sobrien static char form[50]; 69719370Spst 69898944Sobrien strcpy (form, local_decimal_format_prefix ()); 69998944Sobrien strcat (form, "%"); 70098944Sobrien strcat (form, pre); 70198944Sobrien strcat (form, local_decimal_format_specifier ()); 70298944Sobrien strcat (form, local_decimal_format_suffix ()); 70398944Sobrien return form; 70419370Spst} 70519370Spst 70619370Spst#if 0 70719370Spst/* This page contains functions that are used in type/range checking. 70819370Spst They all return zero if the type/range check fails. 70919370Spst 71019370Spst It is hoped that these will make extending GDB to parse different 71119370Spst languages a little easier. These are primarily used in eval.c when 71219370Spst evaluating expressions and making sure that their types are correct. 71319370Spst Instead of having a mess of conjucted/disjuncted expressions in an "if", 71419370Spst the ideas of type can be wrapped up in the following functions. 71519370Spst 71619370Spst Note that some of them are not currently dependent upon which language 71719370Spst is currently being parsed. For example, floats are the same in 71819370Spst C and Modula-2 (ie. the only floating point type has TYPE_CODE of 71919370Spst TYPE_CODE_FLT), while booleans are different. */ 72019370Spst 72119370Spst/* Returns non-zero if its argument is a simple type. This is the same for 72219370Spst both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur, 72319370Spst and thus will never cause the failure of the test. */ 72419370Spstint 72598944Sobriensimple_type (struct type *type) 72619370Spst{ 72719370Spst CHECK_TYPEDEF (type); 72898944Sobrien switch (TYPE_CODE (type)) 72998944Sobrien { 73098944Sobrien case TYPE_CODE_INT: 73198944Sobrien case TYPE_CODE_CHAR: 73298944Sobrien case TYPE_CODE_ENUM: 73398944Sobrien case TYPE_CODE_FLT: 73498944Sobrien case TYPE_CODE_RANGE: 73598944Sobrien case TYPE_CODE_BOOL: 73698944Sobrien return 1; 73719370Spst 73898944Sobrien default: 73998944Sobrien return 0; 74098944Sobrien } 74119370Spst} 74219370Spst 74319370Spst/* Returns non-zero if its argument is of an ordered type. 74419370Spst An ordered type is one in which the elements can be tested for the 74519370Spst properties of "greater than", "less than", etc, or for which the 74619370Spst operations "increment" or "decrement" make sense. */ 74719370Spstint 74898944Sobrienordered_type (struct type *type) 74919370Spst{ 75019370Spst CHECK_TYPEDEF (type); 75198944Sobrien switch (TYPE_CODE (type)) 75298944Sobrien { 75398944Sobrien case TYPE_CODE_INT: 75498944Sobrien case TYPE_CODE_CHAR: 75598944Sobrien case TYPE_CODE_ENUM: 75698944Sobrien case TYPE_CODE_FLT: 75798944Sobrien case TYPE_CODE_RANGE: 75898944Sobrien return 1; 75919370Spst 76098944Sobrien default: 76198944Sobrien return 0; 76298944Sobrien } 76319370Spst} 76419370Spst 76519370Spst/* Returns non-zero if the two types are the same */ 76619370Spstint 76798944Sobriensame_type (struct type *arg1, struct type *arg2) 76819370Spst{ 76919370Spst CHECK_TYPEDEF (type); 77098944Sobrien if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2)) 77198944Sobrien /* One is structured and one isn't */ 77298944Sobrien return 0; 77398944Sobrien else if (structured_type (arg1) && structured_type (arg2)) 77498944Sobrien return arg1 == arg2; 77598944Sobrien else if (numeric_type (arg1) && numeric_type (arg2)) 77698944Sobrien return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) && 77798944Sobrien (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2)) 77898944Sobrien ? 1 : 0; 77998944Sobrien else 78098944Sobrien return arg1 == arg2; 78119370Spst} 78219370Spst 78319370Spst/* Returns non-zero if the type is integral */ 78419370Spstint 78598944Sobrienintegral_type (struct type *type) 78619370Spst{ 78719370Spst CHECK_TYPEDEF (type); 78898944Sobrien switch (current_language->la_language) 78998944Sobrien { 79098944Sobrien case language_c: 79198944Sobrien case language_cplus: 792130803Smarcel case language_objc: 79398944Sobrien return (TYPE_CODE (type) != TYPE_CODE_INT) && 79498944Sobrien (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1; 79598944Sobrien case language_m2: 79698944Sobrien case language_pascal: 79798944Sobrien return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1; 79898944Sobrien default: 79919370Spst error ("Language not supported."); 80098944Sobrien } 80119370Spst} 80219370Spst 80319370Spst/* Returns non-zero if the value is numeric */ 80419370Spstint 80598944Sobriennumeric_type (struct type *type) 80619370Spst{ 80719370Spst CHECK_TYPEDEF (type); 80898944Sobrien switch (TYPE_CODE (type)) 80998944Sobrien { 81098944Sobrien case TYPE_CODE_INT: 81198944Sobrien case TYPE_CODE_FLT: 81298944Sobrien return 1; 81319370Spst 81498944Sobrien default: 81598944Sobrien return 0; 81698944Sobrien } 81719370Spst} 81819370Spst 81919370Spst/* Returns non-zero if the value is a character type */ 82019370Spstint 82198944Sobriencharacter_type (struct type *type) 82219370Spst{ 82319370Spst CHECK_TYPEDEF (type); 82498944Sobrien switch (current_language->la_language) 82598944Sobrien { 82698944Sobrien case language_m2: 82798944Sobrien case language_pascal: 82898944Sobrien return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1; 82919370Spst 83098944Sobrien case language_c: 83198944Sobrien case language_cplus: 832130803Smarcel case language_objc: 83398944Sobrien return (TYPE_CODE (type) == TYPE_CODE_INT) && 83498944Sobrien TYPE_LENGTH (type) == sizeof (char) 83598944Sobrien ? 1 : 0; 83698944Sobrien default: 83719370Spst return (0); 83898944Sobrien } 83919370Spst} 84019370Spst 84119370Spst/* Returns non-zero if the value is a string type */ 84219370Spstint 84398944Sobrienstring_type (struct type *type) 84419370Spst{ 84519370Spst CHECK_TYPEDEF (type); 84698944Sobrien switch (current_language->la_language) 84798944Sobrien { 84898944Sobrien case language_m2: 84998944Sobrien case language_pascal: 85098944Sobrien return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1; 85119370Spst 85298944Sobrien case language_c: 85398944Sobrien case language_cplus: 854130803Smarcel case language_objc: 85519370Spst /* C does not have distinct string type. */ 85619370Spst return (0); 85798944Sobrien default: 85819370Spst return (0); 85998944Sobrien } 86019370Spst} 86119370Spst 86219370Spst/* Returns non-zero if the value is a boolean type */ 86319370Spstint 86498944Sobrienboolean_type (struct type *type) 86519370Spst{ 86619370Spst CHECK_TYPEDEF (type); 86719370Spst if (TYPE_CODE (type) == TYPE_CODE_BOOL) 86819370Spst return 1; 86998944Sobrien switch (current_language->la_language) 87019370Spst { 87119370Spst case language_c: 87219370Spst case language_cplus: 873130803Smarcel case language_objc: 874130803Smarcel /* Might be more cleanly handled by having a 875130803Smarcel TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such 876130803Smarcel languages, or a TYPE_CODE_INT_OR_BOOL for C. */ 87719370Spst if (TYPE_CODE (type) == TYPE_CODE_INT) 87819370Spst return 1; 87998944Sobrien default: 88019370Spst break; 88198944Sobrien } 88219370Spst return 0; 88319370Spst} 88419370Spst 88519370Spst/* Returns non-zero if the value is a floating-point type */ 88619370Spstint 88798944Sobrienfloat_type (struct type *type) 88819370Spst{ 88919370Spst CHECK_TYPEDEF (type); 89098944Sobrien return TYPE_CODE (type) == TYPE_CODE_FLT; 89119370Spst} 89219370Spst 89319370Spst/* Returns non-zero if the value is a pointer type */ 89419370Spstint 89598944Sobrienpointer_type (struct type *type) 89619370Spst{ 89798944Sobrien return TYPE_CODE (type) == TYPE_CODE_PTR || 89898944Sobrien TYPE_CODE (type) == TYPE_CODE_REF; 89919370Spst} 90019370Spst 90119370Spst/* Returns non-zero if the value is a structured type */ 90219370Spstint 90398944Sobrienstructured_type (struct type *type) 90419370Spst{ 90519370Spst CHECK_TYPEDEF (type); 90698944Sobrien switch (current_language->la_language) 90798944Sobrien { 90898944Sobrien case language_c: 90998944Sobrien case language_cplus: 910130803Smarcel case language_objc: 91198944Sobrien return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 91298944Sobrien (TYPE_CODE (type) == TYPE_CODE_UNION) || 91398944Sobrien (TYPE_CODE (type) == TYPE_CODE_ARRAY); 91498944Sobrien case language_pascal: 91519370Spst return (TYPE_CODE(type) == TYPE_CODE_STRUCT) || 91619370Spst (TYPE_CODE(type) == TYPE_CODE_UNION) || 91719370Spst (TYPE_CODE(type) == TYPE_CODE_SET) || 91819370Spst (TYPE_CODE(type) == TYPE_CODE_ARRAY); 91998944Sobrien case language_m2: 92098944Sobrien return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || 92198944Sobrien (TYPE_CODE (type) == TYPE_CODE_SET) || 92298944Sobrien (TYPE_CODE (type) == TYPE_CODE_ARRAY); 92398944Sobrien default: 92419370Spst return (0); 92598944Sobrien } 92619370Spst} 92719370Spst#endif 92819370Spst 92919370Spststruct type * 93098944Sobrienlang_bool_type (void) 93119370Spst{ 93219370Spst struct symbol *sym; 93319370Spst struct type *type; 93498944Sobrien switch (current_language->la_language) 93519370Spst { 93619370Spst case language_fortran: 937130803Smarcel sym = lookup_symbol ("logical", NULL, VAR_DOMAIN, NULL, NULL); 93819370Spst if (sym) 93919370Spst { 94019370Spst type = SYMBOL_TYPE (sym); 94119370Spst if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) 94219370Spst return type; 94319370Spst } 94419370Spst return builtin_type_f_logical_s2; 94519370Spst case language_cplus: 94698944Sobrien case language_pascal: 94798944Sobrien if (current_language->la_language==language_cplus) 948130803Smarcel {sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);} 94998944Sobrien else 950130803Smarcel {sym = lookup_symbol ("boolean", NULL, VAR_DOMAIN, NULL, NULL);} 95119370Spst if (sym) 95219370Spst { 95319370Spst type = SYMBOL_TYPE (sym); 95419370Spst if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) 95519370Spst return type; 95619370Spst } 95746283Sdfr return builtin_type_bool; 95898944Sobrien case language_java: 959130803Smarcel sym = lookup_symbol ("boolean", NULL, VAR_DOMAIN, NULL, NULL); 96098944Sobrien if (sym) 96198944Sobrien { 96298944Sobrien type = SYMBOL_TYPE (sym); 96398944Sobrien if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) 96498944Sobrien return type; 96598944Sobrien } 96698944Sobrien return java_boolean_type; 96719370Spst default: 96819370Spst return builtin_type_int; 96919370Spst } 97019370Spst} 97119370Spst 97219370Spst/* This page contains functions that return info about 97319370Spst (struct value) values used in GDB. */ 97419370Spst 97519370Spst/* Returns non-zero if the value VAL represents a true value. */ 97619370Spstint 97798944Sobrienvalue_true (struct value *val) 97819370Spst{ 97919370Spst /* It is possible that we should have some sort of error if a non-boolean 98019370Spst value is used in this context. Possibly dependent on some kind of 98119370Spst "boolean-checking" option like range checking. But it should probably 98219370Spst not depend on the language except insofar as is necessary to identify 98319370Spst a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean 98419370Spst should be an error, probably). */ 98519370Spst return !value_logical_not (val); 98619370Spst} 98719370Spst 98819370Spst/* This page contains functions for the printing out of 98919370Spst error messages that occur during type- and range- 99019370Spst checking. */ 99119370Spst 99298944Sobrien/* These are called when a language fails a type- or range-check. The 99398944Sobrien first argument should be a printf()-style format string, and the 99498944Sobrien rest of the arguments should be its arguments. If 99598944Sobrien [type|range]_check is [type|range]_check_on, an error is printed; 99698944Sobrien if [type|range]_check_warn, a warning; otherwise just the 99798944Sobrien message. */ 99819370Spst 99919370Spstvoid 100098944Sobrientype_error (const char *string,...) 100119370Spst{ 100298944Sobrien va_list args; 100398944Sobrien va_start (args, string); 100419370Spst 100598944Sobrien switch (type_check) 100698944Sobrien { 100798944Sobrien case type_check_warn: 100898944Sobrien vwarning (string, args); 100998944Sobrien break; 101098944Sobrien case type_check_on: 101198944Sobrien verror (string, args); 101298944Sobrien break; 101398944Sobrien case type_check_off: 101498944Sobrien /* FIXME: cagney/2002-01-30: Should this function print anything 101598944Sobrien when type error is off? */ 101698944Sobrien vfprintf_filtered (gdb_stderr, string, args); 101798944Sobrien fprintf_filtered (gdb_stderr, "\n"); 101898944Sobrien break; 101998944Sobrien default: 102098944Sobrien internal_error (__FILE__, __LINE__, "bad switch"); 102198944Sobrien } 102298944Sobrien va_end (args); 102319370Spst} 102419370Spst 102519370Spstvoid 102698944Sobrienrange_error (const char *string,...) 102719370Spst{ 102898944Sobrien va_list args; 102998944Sobrien va_start (args, string); 103019370Spst 103198944Sobrien switch (range_check) 103298944Sobrien { 103398944Sobrien case range_check_warn: 103498944Sobrien vwarning (string, args); 103598944Sobrien break; 103698944Sobrien case range_check_on: 103798944Sobrien verror (string, args); 103898944Sobrien break; 103998944Sobrien case range_check_off: 104098944Sobrien /* FIXME: cagney/2002-01-30: Should this function print anything 104198944Sobrien when range error is off? */ 104298944Sobrien vfprintf_filtered (gdb_stderr, string, args); 104398944Sobrien fprintf_filtered (gdb_stderr, "\n"); 104498944Sobrien break; 104598944Sobrien default: 104698944Sobrien internal_error (__FILE__, __LINE__, "bad switch"); 104798944Sobrien } 104898944Sobrien va_end (args); 104919370Spst} 105098944Sobrien 105119370Spst 105219370Spst/* This page contains miscellaneous functions */ 105319370Spst 105446283Sdfr/* Return the language enum for a given language string. */ 105546283Sdfr 105646283Sdfrenum language 105798944Sobrienlanguage_enum (char *str) 105846283Sdfr{ 105946283Sdfr int i; 106046283Sdfr 106198944Sobrien for (i = 0; i < languages_size; i++) 1062130803Smarcel if (DEPRECATED_STREQ (languages[i]->la_name, str)) 106346283Sdfr return languages[i]->la_language; 106446283Sdfr 106546283Sdfr return language_unknown; 106646283Sdfr} 106746283Sdfr 106819370Spst/* Return the language struct for a given language enum. */ 106919370Spst 107019370Spstconst struct language_defn * 107198944Sobrienlanguage_def (enum language lang) 107219370Spst{ 107319370Spst int i; 107419370Spst 107598944Sobrien for (i = 0; i < languages_size; i++) 107698944Sobrien { 107798944Sobrien if (languages[i]->la_language == lang) 107898944Sobrien { 107998944Sobrien return languages[i]; 108098944Sobrien } 108119370Spst } 108219370Spst return NULL; 108319370Spst} 108419370Spst 108519370Spst/* Return the language as a string */ 108619370Spstchar * 108798944Sobrienlanguage_str (enum language lang) 108819370Spst{ 108919370Spst int i; 109019370Spst 109198944Sobrien for (i = 0; i < languages_size; i++) 109298944Sobrien { 109398944Sobrien if (languages[i]->la_language == lang) 109498944Sobrien { 109598944Sobrien return languages[i]->la_name; 109698944Sobrien } 109719370Spst } 109819370Spst return "Unknown"; 109919370Spst} 110019370Spst 110119370Spststatic void 110298944Sobrienset_check (char *ignore, int from_tty) 110319370Spst{ 110498944Sobrien printf_unfiltered ( 110598944Sobrien "\"set check\" must be followed by the name of a check subcommand.\n"); 110698944Sobrien help_list (setchecklist, "set check ", -1, gdb_stdout); 110719370Spst} 110819370Spst 110919370Spststatic void 111098944Sobrienshow_check (char *ignore, int from_tty) 111119370Spst{ 111298944Sobrien cmd_show_list (showchecklist, from_tty, ""); 111319370Spst} 111419370Spst 111519370Spst/* Add a language to the set of known languages. */ 111619370Spst 111719370Spstvoid 111898944Sobrienadd_language (const struct language_defn *lang) 111919370Spst{ 112019370Spst if (lang->la_magic != LANG_MAGIC) 112119370Spst { 112298944Sobrien fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n", 112398944Sobrien lang->la_name); 112498944Sobrien internal_error (__FILE__, __LINE__, "failed internal consistency check"); 112519370Spst } 112619370Spst 112719370Spst if (!languages) 112819370Spst { 112919370Spst languages_allocsize = DEFAULT_ALLOCSIZE; 113019370Spst languages = (const struct language_defn **) xmalloc 113119370Spst (languages_allocsize * sizeof (*languages)); 113219370Spst } 113319370Spst if (languages_size >= languages_allocsize) 113419370Spst { 113519370Spst languages_allocsize *= 2; 113619370Spst languages = (const struct language_defn **) xrealloc ((char *) languages, 113798944Sobrien languages_allocsize * sizeof (*languages)); 113819370Spst } 113919370Spst languages[languages_size++] = lang; 114019370Spst} 114119370Spst 1142130803Smarcel/* Iterate through all registered languages looking for and calling 1143130803Smarcel any non-NULL struct language_defn.skip_trampoline() functions. 1144130803Smarcel Return the result from the first that returns non-zero, or 0 if all 1145130803Smarcel `fail'. */ 1146130803SmarcelCORE_ADDR 1147130803Smarcelskip_language_trampoline (CORE_ADDR pc) 1148130803Smarcel{ 1149130803Smarcel int i; 1150130803Smarcel 1151130803Smarcel for (i = 0; i < languages_size; i++) 1152130803Smarcel { 1153130803Smarcel if (languages[i]->skip_trampoline) 1154130803Smarcel { 1155130803Smarcel CORE_ADDR real_pc = (languages[i]->skip_trampoline) (pc); 1156130803Smarcel if (real_pc) 1157130803Smarcel return real_pc; 1158130803Smarcel } 1159130803Smarcel } 1160130803Smarcel 1161130803Smarcel return 0; 1162130803Smarcel} 1163130803Smarcel 1164130803Smarcel/* Return demangled language symbol, or NULL. 1165130803Smarcel FIXME: Options are only useful for certain languages and ignored 1166130803Smarcel by others, so it would be better to remove them here and have a 1167130803Smarcel more flexible demangler for the languages that need it. 1168130803Smarcel FIXME: Sometimes the demangler is invoked when we don't know the 1169130803Smarcel language, so we can't use this everywhere. */ 1170130803Smarcelchar * 1171130803Smarcellanguage_demangle (const struct language_defn *current_language, 1172130803Smarcel const char *mangled, int options) 1173130803Smarcel{ 1174130803Smarcel if (current_language != NULL && current_language->la_demangle) 1175130803Smarcel return current_language->la_demangle (mangled, options); 1176130803Smarcel return NULL; 1177130803Smarcel} 1178130803Smarcel 1179130803Smarcel/* Return the default string containing the list of characters 1180130803Smarcel delimiting words. This is a reasonable default value that 1181130803Smarcel most languages should be able to use. */ 1182130803Smarcel 1183130803Smarcelchar * 1184130803Smarceldefault_word_break_characters (void) 1185130803Smarcel{ 1186130803Smarcel return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; 1187130803Smarcel} 1188130803Smarcel 118919370Spst/* Define the language that is no language. */ 119019370Spst 119119370Spststatic int 119298944Sobrienunk_lang_parser (void) 119319370Spst{ 119419370Spst return 1; 119519370Spst} 119619370Spst 119719370Spststatic void 119898944Sobrienunk_lang_error (char *msg) 119919370Spst{ 120019370Spst error ("Attempted to parse an expression with unknown language"); 120119370Spst} 120219370Spst 120319370Spststatic void 1204130803Smarcelunk_lang_emit_char (int c, struct ui_file *stream, int quoter) 120546283Sdfr{ 120646283Sdfr error ("internal error - unimplemented function unk_lang_emit_char called."); 120746283Sdfr} 120846283Sdfr 120946283Sdfrstatic void 1210130803Smarcelunk_lang_printchar (int c, struct ui_file *stream) 121119370Spst{ 121219370Spst error ("internal error - unimplemented function unk_lang_printchar called."); 121319370Spst} 121419370Spst 121519370Spststatic void 121698944Sobrienunk_lang_printstr (struct ui_file *stream, char *string, unsigned int length, 121798944Sobrien int width, int force_ellipses) 121819370Spst{ 121919370Spst error ("internal error - unimplemented function unk_lang_printstr called."); 122019370Spst} 122119370Spst 122219370Spststatic struct type * 122398944Sobrienunk_lang_create_fundamental_type (struct objfile *objfile, int typeid) 122419370Spst{ 122519370Spst error ("internal error - unimplemented function unk_lang_create_fundamental_type called."); 122619370Spst} 122719370Spst 122846283Sdfrstatic void 122998944Sobrienunk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream, 123098944Sobrien int show, int level) 123119370Spst{ 123219370Spst error ("internal error - unimplemented function unk_lang_print_type called."); 123319370Spst} 123419370Spst 123546283Sdfrstatic int 123698944Sobrienunk_lang_val_print (struct type *type, char *valaddr, int embedded_offset, 123798944Sobrien CORE_ADDR address, struct ui_file *stream, int format, 123898944Sobrien int deref_ref, int recurse, enum val_prettyprint pretty) 123919370Spst{ 124019370Spst error ("internal error - unimplemented function unk_lang_val_print called."); 124119370Spst} 124219370Spst 124346283Sdfrstatic int 124498944Sobrienunk_lang_value_print (struct value *val, struct ui_file *stream, int format, 124598944Sobrien enum val_prettyprint pretty) 124619370Spst{ 124719370Spst error ("internal error - unimplemented function unk_lang_value_print called."); 124819370Spst} 124919370Spst 1250130803Smarcelstatic CORE_ADDR unk_lang_trampoline (CORE_ADDR pc) 1251130803Smarcel{ 1252130803Smarcel return 0; 1253130803Smarcel} 1254130803Smarcel 1255130803Smarcel/* Unknown languages just use the cplus demangler. */ 1256130803Smarcelstatic char *unk_lang_demangle (const char *mangled, int options) 1257130803Smarcel{ 1258130803Smarcel return cplus_demangle (mangled, options); 1259130803Smarcel} 1260130803Smarcel 1261130803Smarcel 126298944Sobrienstatic struct type **const (unknown_builtin_types[]) = 126398944Sobrien{ 126498944Sobrien 0 126519370Spst}; 126698944Sobrienstatic const struct op_print unk_op_print_tab[] = 126798944Sobrien{ 126898944Sobrien {NULL, OP_NULL, PREC_NULL, 0} 126998944Sobrien}; 127019370Spst 127198944Sobrienconst struct language_defn unknown_language_defn = 127298944Sobrien{ 127319370Spst "unknown", 127419370Spst language_unknown, 127519370Spst &unknown_builtin_types[0], 127619370Spst range_check_off, 127719370Spst type_check_off, 127898944Sobrien case_sensitive_on, 1279130803Smarcel &exp_descriptor_standard, 128019370Spst unk_lang_parser, 128119370Spst unk_lang_error, 128219370Spst unk_lang_printchar, /* Print character constant */ 128319370Spst unk_lang_printstr, 128446283Sdfr unk_lang_emit_char, 128519370Spst unk_lang_create_fundamental_type, 128619370Spst unk_lang_print_type, /* Print a type using appropriate syntax */ 128719370Spst unk_lang_val_print, /* Print a value using appropriate syntax */ 128819370Spst unk_lang_value_print, /* Print a top-level value */ 1289130803Smarcel unk_lang_trampoline, /* Language specific skip_trampoline */ 1290130803Smarcel value_of_this, /* value_of_this */ 1291130803Smarcel basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 1292130803Smarcel basic_lookup_transparent_type,/* lookup_transparent_type */ 1293130803Smarcel unk_lang_demangle, /* Language specific symbol demangler */ 129498944Sobrien {"", "", "", ""}, /* Binary format info */ 129598944Sobrien {"0%lo", "0", "o", ""}, /* Octal format info */ 129698944Sobrien {"%ld", "", "d", ""}, /* Decimal format info */ 129798944Sobrien {"0x%lx", "0x", "x", ""}, /* Hex format info */ 129819370Spst unk_op_print_tab, /* expression operators for printing */ 129919370Spst 1, /* c-style arrays */ 130019370Spst 0, /* String lower bound */ 130198944Sobrien &builtin_type_char, /* Type of string elements */ 1302130803Smarcel default_word_break_characters, 130319370Spst LANG_MAGIC 130419370Spst}; 130519370Spst 130619370Spst/* These two structs define fake entries for the "local" and "auto" options. */ 130798944Sobrienconst struct language_defn auto_language_defn = 130898944Sobrien{ 130919370Spst "auto", 131019370Spst language_auto, 131119370Spst &unknown_builtin_types[0], 131219370Spst range_check_off, 131319370Spst type_check_off, 131498944Sobrien case_sensitive_on, 1315130803Smarcel &exp_descriptor_standard, 131619370Spst unk_lang_parser, 131719370Spst unk_lang_error, 131819370Spst unk_lang_printchar, /* Print character constant */ 131919370Spst unk_lang_printstr, 132046283Sdfr unk_lang_emit_char, 132119370Spst unk_lang_create_fundamental_type, 132219370Spst unk_lang_print_type, /* Print a type using appropriate syntax */ 132319370Spst unk_lang_val_print, /* Print a value using appropriate syntax */ 132419370Spst unk_lang_value_print, /* Print a top-level value */ 1325130803Smarcel unk_lang_trampoline, /* Language specific skip_trampoline */ 1326130803Smarcel value_of_this, /* value_of_this */ 1327130803Smarcel basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 1328130803Smarcel basic_lookup_transparent_type,/* lookup_transparent_type */ 1329130803Smarcel unk_lang_demangle, /* Language specific symbol demangler */ 133098944Sobrien {"", "", "", ""}, /* Binary format info */ 133198944Sobrien {"0%lo", "0", "o", ""}, /* Octal format info */ 133298944Sobrien {"%ld", "", "d", ""}, /* Decimal format info */ 133398944Sobrien {"0x%lx", "0x", "x", ""}, /* Hex format info */ 133419370Spst unk_op_print_tab, /* expression operators for printing */ 133519370Spst 1, /* c-style arrays */ 133619370Spst 0, /* String lower bound */ 133798944Sobrien &builtin_type_char, /* Type of string elements */ 1338130803Smarcel default_word_break_characters, 133919370Spst LANG_MAGIC 134019370Spst}; 134119370Spst 134298944Sobrienconst struct language_defn local_language_defn = 134398944Sobrien{ 134419370Spst "local", 134519370Spst language_auto, 134619370Spst &unknown_builtin_types[0], 134719370Spst range_check_off, 134819370Spst type_check_off, 134998944Sobrien case_sensitive_on, 1350130803Smarcel &exp_descriptor_standard, 135119370Spst unk_lang_parser, 135219370Spst unk_lang_error, 135319370Spst unk_lang_printchar, /* Print character constant */ 135419370Spst unk_lang_printstr, 135546283Sdfr unk_lang_emit_char, 135619370Spst unk_lang_create_fundamental_type, 135719370Spst unk_lang_print_type, /* Print a type using appropriate syntax */ 135819370Spst unk_lang_val_print, /* Print a value using appropriate syntax */ 135919370Spst unk_lang_value_print, /* Print a top-level value */ 1360130803Smarcel unk_lang_trampoline, /* Language specific skip_trampoline */ 1361130803Smarcel value_of_this, /* value_of_this */ 1362130803Smarcel basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 1363130803Smarcel basic_lookup_transparent_type,/* lookup_transparent_type */ 1364130803Smarcel unk_lang_demangle, /* Language specific symbol demangler */ 136598944Sobrien {"", "", "", ""}, /* Binary format info */ 136698944Sobrien {"0%lo", "0", "o", ""}, /* Octal format info */ 136798944Sobrien {"%ld", "", "d", ""}, /* Decimal format info */ 136898944Sobrien {"0x%lx", "0x", "x", ""}, /* Hex format info */ 136919370Spst unk_op_print_tab, /* expression operators for printing */ 137019370Spst 1, /* c-style arrays */ 137119370Spst 0, /* String lower bound */ 137298944Sobrien &builtin_type_char, /* Type of string elements */ 1373130803Smarcel default_word_break_characters, 137419370Spst LANG_MAGIC 137519370Spst}; 137619370Spst 137719370Spst/* Initialize the language routines */ 137819370Spst 137919370Spstvoid 138098944Sobrien_initialize_language (void) 138119370Spst{ 138298944Sobrien struct cmd_list_element *set, *show; 138319370Spst 138498944Sobrien /* GDB commands for language specific stuff */ 138519370Spst 138698944Sobrien set = add_set_cmd ("language", class_support, var_string_noescape, 138798944Sobrien (char *) &language, 138898944Sobrien "Set the current source language.", 138998944Sobrien &setlist); 139098944Sobrien show = add_show_from_set (set, &showlist); 139198944Sobrien set_cmd_cfunc (set, set_language_command); 139298944Sobrien set_cmd_cfunc (show, show_language_command); 139319370Spst 139498944Sobrien add_prefix_cmd ("check", no_class, set_check, 1395130803Smarcel "Set the status of the type/range checker.", 139698944Sobrien &setchecklist, "set check ", 0, &setlist); 139798944Sobrien add_alias_cmd ("c", "check", no_class, 1, &setlist); 139898944Sobrien add_alias_cmd ("ch", "check", no_class, 1, &setlist); 139919370Spst 140098944Sobrien add_prefix_cmd ("check", no_class, show_check, 1401130803Smarcel "Show the status of the type/range checker.", 140298944Sobrien &showchecklist, "show check ", 0, &showlist); 140398944Sobrien add_alias_cmd ("c", "check", no_class, 1, &showlist); 140498944Sobrien add_alias_cmd ("ch", "check", no_class, 1, &showlist); 140519370Spst 140698944Sobrien set = add_set_cmd ("type", class_support, var_string_noescape, 140798944Sobrien (char *) &type, 140898944Sobrien "Set type checking. (on/warn/off/auto)", 140998944Sobrien &setchecklist); 141098944Sobrien show = add_show_from_set (set, &showchecklist); 141198944Sobrien set_cmd_cfunc (set, set_type_command); 141298944Sobrien set_cmd_cfunc (show, show_type_command); 141319370Spst 141498944Sobrien set = add_set_cmd ("range", class_support, var_string_noescape, 141598944Sobrien (char *) &range, 141698944Sobrien "Set range checking. (on/warn/off/auto)", 141798944Sobrien &setchecklist); 141898944Sobrien show = add_show_from_set (set, &showchecklist); 141998944Sobrien set_cmd_cfunc (set, set_range_command); 142098944Sobrien set_cmd_cfunc (show, show_range_command); 142119370Spst 142298944Sobrien set = add_set_cmd ("case-sensitive", class_support, var_string_noescape, 142398944Sobrien (char *) &case_sensitive, 142498944Sobrien "Set case sensitivity in name search. (on/off/auto)\n\ 142598944SobrienFor Fortran the default is off; for other languages the default is on.", 142698944Sobrien &setlist); 142798944Sobrien show = add_show_from_set (set, &showlist); 142898944Sobrien set_cmd_cfunc (set, set_case_command); 142998944Sobrien set_cmd_cfunc (show, show_case_command); 143019370Spst 143198944Sobrien add_language (&unknown_language_defn); 143298944Sobrien add_language (&local_language_defn); 143398944Sobrien add_language (&auto_language_defn); 143419370Spst 143598944Sobrien language = savestring ("auto", strlen ("auto")); 143698944Sobrien type = savestring ("auto", strlen ("auto")); 143798944Sobrien range = savestring ("auto", strlen ("auto")); 143898944Sobrien case_sensitive = savestring ("auto",strlen ("auto")); 143919370Spst 144098944Sobrien /* Have the above take effect */ 144198944Sobrien set_language (language_auto); 144219370Spst} 1443