119370Spst/* Source-language-related definitions for GDB. 2130803Smarcel 3130803Smarcel Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2003, 4130803Smarcel 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#if !defined (LANGUAGE_H) 2719370Spst#define LANGUAGE_H 1 2819370Spst 2998944Sobrien/* Forward decls for prototypes */ 3019370Spststruct value; 3119370Spststruct objfile; 3219370Spststruct expression; 33130803Smarcelstruct ui_file; 34130803Smarcel 3598944Sobrien/* enum exp_opcode; ANSI's `wisdom' didn't include forward enum decls. */ 3619370Spst 3719370Spst/* This used to be included to configure GDB for one or more specific 3898944Sobrien languages. Now it is left out to configure for all of them. FIXME. */ 3919370Spst/* #include "lang_def.h" */ 4019370Spst#define _LANG_c 4119370Spst#define _LANG_m2 4298944Sobrien#define _LANG_fortran 4398944Sobrien#define _LANG_pascal 4419370Spst 4598944Sobrien#define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */ 4619370Spst 4719370Spst/* range_mode == 4819370Spst range_mode_auto: range_check set automatically to default of language. 4919370Spst range_mode_manual: range_check set manually by user. */ 5019370Spst 5198944Sobrienextern enum range_mode 5298944Sobrien { 5398944Sobrien range_mode_auto, range_mode_manual 5498944Sobrien } 5598944Sobrienrange_mode; 5619370Spst 5719370Spst/* range_check == 5819370Spst range_check_on: Ranges are checked in GDB expressions, producing errors. 5919370Spst range_check_warn: Ranges are checked, producing warnings. 6019370Spst range_check_off: Ranges are not checked in GDB expressions. */ 6119370Spst 6219370Spstextern enum range_check 6398944Sobrien { 6498944Sobrien range_check_off, range_check_warn, range_check_on 6598944Sobrien } 6698944Sobrienrange_check; 6719370Spst 6819370Spst/* type_mode == 6919370Spst type_mode_auto: type_check set automatically to default of language 7019370Spst type_mode_manual: type_check set manually by user. */ 7119370Spst 7298944Sobrienextern enum type_mode 7398944Sobrien { 7498944Sobrien type_mode_auto, type_mode_manual 7598944Sobrien } 7698944Sobrientype_mode; 7719370Spst 7819370Spst/* type_check == 7919370Spst type_check_on: Types are checked in GDB expressions, producing errors. 8019370Spst type_check_warn: Types are checked, producing warnings. 8119370Spst type_check_off: Types are not checked in GDB expressions. */ 8219370Spst 8319370Spstextern enum type_check 8498944Sobrien { 8598944Sobrien type_check_off, type_check_warn, type_check_on 8698944Sobrien } 8798944Sobrientype_check; 8898944Sobrien 8998944Sobrien/* case_mode == 9098944Sobrien case_mode_auto: case_sensitivity set upon selection of scope 9198944Sobrien case_mode_manual: case_sensitivity set only by user. */ 9298944Sobrien 9398944Sobrienextern enum case_mode 9498944Sobrien { 9598944Sobrien case_mode_auto, case_mode_manual 9698944Sobrien } 9798944Sobriencase_mode; 9898944Sobrien 9998944Sobrien/* case_sensitivity == 10098944Sobrien case_sensitive_on: Case sensitivity in name matching is used 10198944Sobrien case_sensitive_off: Case sensitivity in name matching is not used */ 10298944Sobrien 10398944Sobrienextern enum case_sensitivity 10498944Sobrien { 10598944Sobrien case_sensitive_on, case_sensitive_off 10698944Sobrien } 10798944Sobriencase_sensitivity; 10819370Spst 10919370Spst/* Information for doing language dependent formatting of printed values. */ 11019370Spst 11119370Spststruct language_format_info 11298944Sobrien { 11398944Sobrien /* The format that can be passed directly to standard C printf functions 11498944Sobrien to generate a completely formatted value in the format appropriate for 11598944Sobrien the language. */ 11619370Spst 11798944Sobrien char *la_format; 11819370Spst 11998944Sobrien /* The prefix to be used when directly printing a value, or constructing 12098944Sobrien a standard C printf format. This generally is everything up to the 12198944Sobrien conversion specification (the part introduced by the '%' character 12298944Sobrien and terminated by the conversion specifier character). */ 12319370Spst 12498944Sobrien char *la_format_prefix; 12519370Spst 12698944Sobrien /* The conversion specifier. This is generally everything after the 12798944Sobrien field width and precision, typically only a single character such 12898944Sobrien as 'o' for octal format or 'x' for hexadecimal format. */ 12919370Spst 13098944Sobrien char *la_format_specifier; 13119370Spst 13298944Sobrien /* The suffix to be used when directly printing a value, or constructing 13398944Sobrien a standard C printf format. This generally is everything after the 13498944Sobrien conversion specification (the part introduced by the '%' character 13598944Sobrien and terminated by the conversion specifier character). */ 13619370Spst 13798944Sobrien char *la_format_suffix; /* Suffix for custom format string */ 13898944Sobrien }; 13919370Spst 14019370Spst/* Structure tying together assorted information about a language. */ 14119370Spst 14219370Spststruct language_defn 14398944Sobrien { 14498944Sobrien /* Name of the language */ 14519370Spst 14698944Sobrien char *la_name; 14719370Spst 14898944Sobrien /* its symtab language-enum (defs.h) */ 14919370Spst 15098944Sobrien enum language la_language; 15119370Spst 15298944Sobrien /* Its builtin types. This is a vector ended by a NULL pointer. These 15398944Sobrien types can be specified by name in parsing types in expressions, 15498944Sobrien regardless of whether the program being debugged actually defines 15598944Sobrien such a type. */ 15619370Spst 15798944Sobrien struct type **const *la_builtin_type_vector; 15819370Spst 15998944Sobrien /* Default range checking */ 16019370Spst 16198944Sobrien enum range_check la_range_check; 16219370Spst 16398944Sobrien /* Default type checking */ 16419370Spst 16598944Sobrien enum type_check la_type_check; 16619370Spst 16798944Sobrien /* Default case sensitivity */ 16898944Sobrien enum case_sensitivity la_case_sensitivity; 16919370Spst 170130803Smarcel /* Definitions related to expression printing, prefixifying, and 171130803Smarcel dumping */ 172130803Smarcel 173130803Smarcel const struct exp_descriptor *la_exp_desc; 174130803Smarcel 17598944Sobrien /* Parser function. */ 17619370Spst 17798944Sobrien int (*la_parser) (void); 17819370Spst 17998944Sobrien /* Parser error function */ 18019370Spst 18198944Sobrien void (*la_error) (char *); 18219370Spst 18398944Sobrien void (*la_printchar) (int ch, struct ui_file * stream); 18419370Spst 18598944Sobrien void (*la_printstr) (struct ui_file * stream, char *string, 18698944Sobrien unsigned int length, int width, 18798944Sobrien int force_ellipses); 18819370Spst 18998944Sobrien void (*la_emitchar) (int ch, struct ui_file * stream, int quoter); 19019370Spst 19198944Sobrien struct type *(*la_fund_type) (struct objfile *, int); 19219370Spst 19398944Sobrien /* Print a type using syntax appropriate for this language. */ 19419370Spst 19598944Sobrien void (*la_print_type) (struct type *, char *, struct ui_file *, int, 19698944Sobrien int); 19719370Spst 19898944Sobrien /* Print a value using syntax appropriate for this language. */ 19919370Spst 20098944Sobrien int (*la_val_print) (struct type *, char *, int, CORE_ADDR, 20198944Sobrien struct ui_file *, int, int, int, 20298944Sobrien enum val_prettyprint); 20319370Spst 20498944Sobrien /* Print a top-level value using syntax appropriate for this language. */ 20519370Spst 20698944Sobrien int (*la_value_print) (struct value *, struct ui_file *, 20798944Sobrien int, enum val_prettyprint); 20819370Spst 209130803Smarcel /* PC is possibly an unknown languages trampoline. 210130803Smarcel If that PC falls in a trampoline belonging to this language, 211130803Smarcel return the address of the first pc in the real function, or 0 212130803Smarcel if it isn't a language tramp for this language. */ 213130803Smarcel CORE_ADDR (*skip_trampoline) (CORE_ADDR pc); 214130803Smarcel 215130803Smarcel /* Now come some hooks for lookup_symbol. */ 216130803Smarcel 217130803Smarcel /* If this is non-NULL, lookup_symbol will do the 'field_of_this' 218130803Smarcel check, using this function to find the value of this. */ 219130803Smarcel 220130803Smarcel /* FIXME: carlton/2003-05-19: Audit all the language_defn structs 221130803Smarcel to make sure we're setting this appropriately: I'm sure it 222130803Smarcel could be NULL in more languages. */ 223130803Smarcel 224130803Smarcel struct value *(*la_value_of_this) (int complain); 225130803Smarcel 226130803Smarcel /* This is a function that lookup_symbol will call when it gets to 227130803Smarcel the part of symbol lookup where C looks up static and global 228130803Smarcel variables. */ 229130803Smarcel 230130803Smarcel struct symbol *(*la_lookup_symbol_nonlocal) (const char *, 231130803Smarcel const char *, 232130803Smarcel const struct block *, 233130803Smarcel const domain_enum, 234130803Smarcel struct symtab **); 235130803Smarcel 236130803Smarcel /* Find the definition of the type with the given name. */ 237130803Smarcel struct type *(*la_lookup_transparent_type) (const char *); 238130803Smarcel 239130803Smarcel /* Return demangled language symbol, or NULL. */ 240130803Smarcel char *(*la_demangle) (const char *mangled, int options); 241130803Smarcel 24298944Sobrien /* Base 2 (binary) formats. */ 24319370Spst 24498944Sobrien struct language_format_info la_binary_format; 24519370Spst 24698944Sobrien /* Base 8 (octal) formats. */ 24719370Spst 24898944Sobrien struct language_format_info la_octal_format; 24919370Spst 25098944Sobrien /* Base 10 (decimal) formats */ 25119370Spst 25298944Sobrien struct language_format_info la_decimal_format; 25319370Spst 25498944Sobrien /* Base 16 (hexadecimal) formats */ 25519370Spst 25698944Sobrien struct language_format_info la_hex_format; 25719370Spst 25898944Sobrien /* Table for printing expressions */ 25919370Spst 26098944Sobrien const struct op_print *la_op_print_tab; 26119370Spst 26298944Sobrien /* Zero if the language has first-class arrays. True if there are no 26398944Sobrien array values, and array objects decay to pointers, as in C. */ 26419370Spst 26598944Sobrien char c_style_arrays; 26619370Spst 26798944Sobrien /* Index to use for extracting the first element of a string. */ 26898944Sobrien char string_lower_bound; 26919370Spst 27098944Sobrien /* Type of elements of strings. */ 27198944Sobrien struct type **string_char_type; 27219370Spst 273130803Smarcel /* The list of characters forming word boundaries. */ 274130803Smarcel char *(*la_word_break_characters) (void); 275130803Smarcel 27698944Sobrien /* Add fields above this point, so the magic number is always last. */ 27798944Sobrien /* Magic number for compat checking */ 27898944Sobrien 27998944Sobrien long la_magic; 28098944Sobrien 28198944Sobrien }; 28298944Sobrien 28319370Spst#define LANG_MAGIC 910823L 28419370Spst 28519370Spst/* Pointer to the language_defn for our current language. This pointer 28619370Spst always points to *some* valid struct; it can be used without checking 28719370Spst it for validity. 28819370Spst 28919370Spst The current language affects expression parsing and evaluation 29019370Spst (FIXME: it might be cleaner to make the evaluation-related stuff 29119370Spst separate exp_opcodes for each different set of semantics. We 29219370Spst should at least think this through more clearly with respect to 29319370Spst what happens if the language is changed between parsing and 29419370Spst evaluation) and printing of things like types and arrays. It does 29519370Spst *not* affect symbol-reading-- each source file in a symbol-file has 29619370Spst its own language and we should keep track of that regardless of the 29719370Spst language when symbols are read. If we want some manual setting for 29819370Spst the language of symbol files (e.g. detecting when ".c" files are 29998944Sobrien C++), it should be a separate setting from the current_language. */ 30019370Spst 30119370Spstextern const struct language_defn *current_language; 30219370Spst 30319370Spst/* Pointer to the language_defn expected by the user, e.g. the language 30419370Spst of main(), or the language we last mentioned in a message, or C. */ 30519370Spst 30619370Spstextern const struct language_defn *expected_language; 30719370Spst 30819370Spst/* language_mode == 30919370Spst language_mode_auto: current_language automatically set upon selection 31098944Sobrien of scope (e.g. stack frame) 31119370Spst language_mode_manual: current_language set only by user. */ 31219370Spst 31319370Spstextern enum language_mode 31498944Sobrien { 31598944Sobrien language_mode_auto, language_mode_manual 31698944Sobrien } 31798944Sobrienlanguage_mode; 31819370Spst 31919370Spst/* These macros define the behaviour of the expression 32019370Spst evaluator. */ 32119370Spst 32219370Spst/* Should we strictly type check expressions? */ 32319370Spst#define STRICT_TYPE (type_check != type_check_off) 32419370Spst 32519370Spst/* Should we range check values against the domain of their type? */ 32619370Spst#define RANGE_CHECK (range_check != range_check_off) 32719370Spst 32819370Spst/* "cast" really means conversion */ 32919370Spst/* FIXME -- should be a setting in language_defn */ 33019370Spst#define CAST_IS_CONVERSION (current_language->la_language == language_c || \ 331130803Smarcel current_language->la_language == language_cplus || \ 332130803Smarcel current_language->la_language == language_objc) 33319370Spst 33498944Sobrienextern void language_info (int); 33519370Spst 33698944Sobrienextern enum language set_language (enum language); 33798944Sobrien 33819370Spst 33919370Spst/* This page contains functions that return things that are 34019370Spst specific to languages. Each of these functions is based on 34119370Spst the current setting of working_lang, which the user sets 34219370Spst with the "set language" command. */ 34319370Spst 34419370Spst#define create_fundamental_type(objfile,typeid) \ 34519370Spst (current_language->la_fund_type(objfile, typeid)) 34619370Spst 34719370Spst#define LA_PRINT_TYPE(type,varstring,stream,show,level) \ 34819370Spst (current_language->la_print_type(type,varstring,stream,show,level)) 34919370Spst 35046283Sdfr#define LA_VAL_PRINT(type,valaddr,offset,addr,stream,fmt,deref,recurse,pretty) \ 35146283Sdfr (current_language->la_val_print(type,valaddr,offset,addr,stream,fmt,deref, \ 35219370Spst recurse,pretty)) 35319370Spst#define LA_VALUE_PRINT(val,stream,fmt,pretty) \ 35419370Spst (current_language->la_value_print(val,stream,fmt,pretty)) 35519370Spst 35619370Spst/* Return a format string for printf that will print a number in one of 35719370Spst the local (language-specific) formats. Result is static and is 35819370Spst overwritten by the next call. Takes printf options like "08" or "l" 35919370Spst (to produce e.g. %08x or %lx). */ 36019370Spst 36119370Spst#define local_binary_format() \ 36219370Spst (current_language->la_binary_format.la_format) 36319370Spst#define local_binary_format_prefix() \ 36419370Spst (current_language->la_binary_format.la_format_prefix) 36519370Spst#define local_binary_format_specifier() \ 36619370Spst (current_language->la_binary_format.la_format_specifier) 36719370Spst#define local_binary_format_suffix() \ 36819370Spst (current_language->la_binary_format.la_format_suffix) 36919370Spst 37019370Spst#define local_octal_format() \ 37119370Spst (current_language->la_octal_format.la_format) 37219370Spst#define local_octal_format_prefix() \ 37319370Spst (current_language->la_octal_format.la_format_prefix) 37419370Spst#define local_octal_format_specifier() \ 37519370Spst (current_language->la_octal_format.la_format_specifier) 37619370Spst#define local_octal_format_suffix() \ 37719370Spst (current_language->la_octal_format.la_format_suffix) 37819370Spst 37919370Spst#define local_decimal_format() \ 38019370Spst (current_language->la_decimal_format.la_format) 38119370Spst#define local_decimal_format_prefix() \ 38219370Spst (current_language->la_decimal_format.la_format_prefix) 38319370Spst#define local_decimal_format_specifier() \ 38419370Spst (current_language->la_decimal_format.la_format_specifier) 38519370Spst#define local_decimal_format_suffix() \ 38619370Spst (current_language->la_decimal_format.la_format_suffix) 38719370Spst 38819370Spst#define local_hex_format() \ 38919370Spst (current_language->la_hex_format.la_format) 39019370Spst#define local_hex_format_prefix() \ 39119370Spst (current_language->la_hex_format.la_format_prefix) 39219370Spst#define local_hex_format_specifier() \ 39319370Spst (current_language->la_hex_format.la_format_specifier) 39419370Spst#define local_hex_format_suffix() \ 39519370Spst (current_language->la_hex_format.la_format_suffix) 39619370Spst 39719370Spst#define LA_PRINT_CHAR(ch, stream) \ 39819370Spst (current_language->la_printchar(ch, stream)) 39946283Sdfr#define LA_PRINT_STRING(stream, string, length, width, force_ellipses) \ 40046283Sdfr (current_language->la_printstr(stream, string, length, width, force_ellipses)) 40146283Sdfr#define LA_EMIT_CHAR(ch, stream, quoter) \ 40246283Sdfr (current_language->la_emitchar(ch, stream, quoter)) 40319370Spst 40419370Spst/* Test a character to decide whether it can be printed in literal form 40519370Spst or needs to be printed in another representation. For example, 40619370Spst in C the literal form of the character with octal value 141 is 'a' 40719370Spst and the "other representation" is '\141'. The "other representation" 40819370Spst is program language dependent. */ 40919370Spst 41046283Sdfr#define PRINT_LITERAL_FORM(c) \ 41146283Sdfr ((c) >= 0x20 \ 41246283Sdfr && ((c) < 0x7F || (c) >= 0xA0) \ 41346283Sdfr && (!sevenbit_strings || (c) < 0x80)) 41419370Spst 41519370Spst/* Return a format string for printf that will print a number in one of 41619370Spst the local (language-specific) formats. Result is static and is 41719370Spst overwritten by the next call. Takes printf options like "08" or "l" 41819370Spst (to produce e.g. %08x or %lx). */ 41919370Spst 42098944Sobrienextern char *local_decimal_format_custom (char *); /* language.c */ 42119370Spst 42298944Sobrienextern char *local_octal_format_custom (char *); /* language.c */ 42319370Spst 42498944Sobrienextern char *local_hex_format_custom (char *); /* language.c */ 42519370Spst 42698944Sobrien#if 0 42798944Sobrien/* FIXME: cagney/2000-03-04: This function does not appear to be used. 42898944Sobrien It can be deleted once 5.0 has been released. */ 42998944Sobrien/* Return a string that contains the hex digits of the number. No preceeding 43098944Sobrien "0x" */ 43198944Sobrien 43298944Sobrienextern char *longest_raw_hex_string (LONGEST); 43398944Sobrien#endif 43498944Sobrien 43519370Spst/* Return a string that contains a number formatted in one of the local 43619370Spst (language-specific) formats. Result is static and is overwritten by 43798944Sobrien the next call. Takes printf options like "08l" or "l". */ 43819370Spst 439130803Smarcelextern char *local_hex_string (LONGEST); /* language.c */ 44019370Spst 441130803Smarcelextern char *local_hex_string_custom (LONGEST, char *); /* language.c */ 44219370Spst 44319370Spst/* Type predicates */ 44419370Spst 44598944Sobrienextern int simple_type (struct type *); 44619370Spst 44798944Sobrienextern int ordered_type (struct type *); 44819370Spst 44998944Sobrienextern int same_type (struct type *, struct type *); 45019370Spst 45198944Sobrienextern int integral_type (struct type *); 45219370Spst 45398944Sobrienextern int numeric_type (struct type *); 45419370Spst 45598944Sobrienextern int character_type (struct type *); 45619370Spst 45798944Sobrienextern int boolean_type (struct type *); 45819370Spst 45998944Sobrienextern int float_type (struct type *); 46019370Spst 46198944Sobrienextern int pointer_type (struct type *); 46219370Spst 46398944Sobrienextern int structured_type (struct type *); 46419370Spst 46519370Spst/* Checks Binary and Unary operations for semantic type correctness */ 46619370Spst/* FIXME: Does not appear to be used */ 46719370Spst#define unop_type_check(v,o) binop_type_check((v),NULL,(o)) 46819370Spst 46998944Sobrienextern void binop_type_check (struct value *, struct value *, int); 47019370Spst 47119370Spst/* Error messages */ 47219370Spst 473130803Smarcelextern void op_error (const char *lhs, enum exp_opcode, 474130803Smarcel const char *rhs); 47519370Spst 47698944Sobrienextern void type_error (const char *, ...) ATTR_FORMAT (printf, 1, 2); 47719370Spst 47898944Sobrienextern void range_error (const char *, ...) ATTR_FORMAT (printf, 1, 2); 47919370Spst 48019370Spst/* Data: Does this value represent "truth" to the current language? */ 48119370Spst 48298944Sobrienextern int value_true (struct value *); 48319370Spst 48498944Sobrienextern struct type *lang_bool_type (void); 48519370Spst 48619370Spst/* The type used for Boolean values in the current language. */ 48719370Spst#define LA_BOOL_TYPE lang_bool_type () 48819370Spst 48919370Spst/* Misc: The string representing a particular enum language. */ 49019370Spst 49198944Sobrienextern enum language language_enum (char *str); 49219370Spst 49398944Sobrienextern const struct language_defn *language_def (enum language); 49419370Spst 49598944Sobrienextern char *language_str (enum language); 49698944Sobrien 49719370Spst/* Add a language to the set known by GDB (at initialization time). */ 49819370Spst 49998944Sobrienextern void add_language (const struct language_defn *); 50019370Spst 50198944Sobrienextern enum language get_frame_language (void); /* In stack.c */ 50219370Spst 503130803Smarcel/* Check for a language-specific trampoline. */ 504130803Smarcel 505130803Smarcelextern CORE_ADDR skip_language_trampoline (CORE_ADDR pc); 506130803Smarcel 507130803Smarcel/* Return demangled language symbol, or NULL. */ 508130803Smarcelextern char *language_demangle (const struct language_defn *current_language, 509130803Smarcel const char *mangled, int options); 510130803Smarcel 511130803Smarcel/* Splitting strings into words. */ 512130803Smarcelextern char *default_word_break_characters (void); 513130803Smarcel 51498944Sobrien#endif /* defined (LANGUAGE_H) */ 515