GDB (API)
|
00001 /* Source-language-related definitions for GDB. 00002 00003 Copyright (C) 1991-2013 Free Software Foundation, Inc. 00004 00005 Contributed by the Department of Computer Science at the State University 00006 of New York at Buffalo. 00007 00008 This file is part of GDB. 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00022 00023 #if !defined (LANGUAGE_H) 00024 #define LANGUAGE_H 1 00025 00026 /* Forward decls for prototypes. */ 00027 struct value; 00028 struct objfile; 00029 struct frame_info; 00030 struct expression; 00031 struct ui_file; 00032 struct value_print_options; 00033 struct type_print_options; 00034 00035 #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims. */ 00036 00037 /* range_mode == 00038 range_mode_auto: range_check set automatically to default of language. 00039 range_mode_manual: range_check set manually by user. */ 00040 00041 extern enum range_mode 00042 { 00043 range_mode_auto, range_mode_manual 00044 } 00045 range_mode; 00046 00047 /* range_check == 00048 range_check_on: Ranges are checked in GDB expressions, producing errors. 00049 range_check_warn: Ranges are checked, producing warnings. 00050 range_check_off: Ranges are not checked in GDB expressions. */ 00051 00052 extern enum range_check 00053 { 00054 range_check_off, range_check_warn, range_check_on 00055 } 00056 range_check; 00057 00058 /* case_mode == 00059 case_mode_auto: case_sensitivity set upon selection of scope. 00060 case_mode_manual: case_sensitivity set only by user. */ 00061 00062 extern enum case_mode 00063 { 00064 case_mode_auto, case_mode_manual 00065 } 00066 case_mode; 00067 00068 /* array_ordering == 00069 array_row_major: Arrays are in row major order. 00070 array_column_major: Arrays are in column major order. */ 00071 00072 extern enum array_ordering 00073 { 00074 array_row_major, array_column_major 00075 } 00076 array_ordering; 00077 00078 00079 /* case_sensitivity == 00080 case_sensitive_on: Case sensitivity in name matching is used. 00081 case_sensitive_off: Case sensitivity in name matching is not used. */ 00082 00083 extern enum case_sensitivity 00084 { 00085 case_sensitive_on, case_sensitive_off 00086 } 00087 case_sensitivity; 00088 00089 00090 /* macro_expansion == 00091 macro_expansion_no: No macro expansion is available. 00092 macro_expansion_c: C-like macro expansion is available. */ 00093 00094 enum macro_expansion 00095 { 00096 macro_expansion_no, macro_expansion_c 00097 }; 00098 00099 00100 /* Per architecture (OS/ABI) language information. */ 00101 00102 struct language_arch_info 00103 { 00104 /* Its primitive types. This is a vector ended by a NULL pointer. 00105 These types can be specified by name in parsing types in 00106 expressions, regardless of whether the program being debugged 00107 actually defines such a type. */ 00108 struct type **primitive_type_vector; 00109 /* Type of elements of strings. */ 00110 struct type *string_char_type; 00111 00112 /* Symbol name of type to use as boolean type, if defined. */ 00113 const char *bool_type_symbol; 00114 /* Otherwise, this is the default boolean builtin type. */ 00115 struct type *bool_type_default; 00116 }; 00117 00118 /* A pointer to a function expected to return nonzero if 00119 SYMBOL_SEARCH_NAME matches the given LOOKUP_NAME. 00120 00121 SYMBOL_SEARCH_NAME should be a symbol's "search" name. 00122 LOOKUP_NAME should be the name of an entity after it has been 00123 transformed for lookup. */ 00124 00125 typedef int (*symbol_name_cmp_ftype) (const char *symbol_search_name, 00126 const char *lookup_name); 00127 00128 /* Structure tying together assorted information about a language. */ 00129 00130 struct language_defn 00131 { 00132 /* Name of the language. */ 00133 00134 char *la_name; 00135 00136 /* its symtab language-enum (defs.h). */ 00137 00138 enum language la_language; 00139 00140 /* Default range checking. */ 00141 00142 enum range_check la_range_check; 00143 00144 /* Default case sensitivity. */ 00145 enum case_sensitivity la_case_sensitivity; 00146 00147 /* Multi-dimensional array ordering. */ 00148 enum array_ordering la_array_ordering; 00149 00150 /* Style of macro expansion, if any, supported by this language. */ 00151 enum macro_expansion la_macro_expansion; 00152 00153 /* Definitions related to expression printing, prefixifying, and 00154 dumping. */ 00155 00156 const struct exp_descriptor *la_exp_desc; 00157 00158 /* Parser function. */ 00159 00160 int (*la_parser) (void); 00161 00162 /* Parser error function. */ 00163 00164 void (*la_error) (char *); 00165 00166 /* Given an expression *EXPP created by prefixifying the result of 00167 la_parser, perform any remaining processing necessary to complete 00168 its translation. *EXPP may change; la_post_parser is responsible 00169 for releasing its previous contents, if necessary. If 00170 VOID_CONTEXT_P, then no value is expected from the expression. */ 00171 00172 void (*la_post_parser) (struct expression ** expp, int void_context_p); 00173 00174 void (*la_printchar) (int ch, struct type *chtype, 00175 struct ui_file * stream); 00176 00177 void (*la_printstr) (struct ui_file * stream, struct type *elttype, 00178 const gdb_byte *string, unsigned int length, 00179 const char *encoding, int force_ellipses, 00180 const struct value_print_options *); 00181 00182 void (*la_emitchar) (int ch, struct type *chtype, 00183 struct ui_file * stream, int quoter); 00184 00185 /* Print a type using syntax appropriate for this language. */ 00186 00187 void (*la_print_type) (struct type *, const char *, struct ui_file *, int, 00188 int, const struct type_print_options *); 00189 00190 /* Print a typedef using syntax appropriate for this language. 00191 TYPE is the underlying type. NEW_SYMBOL is the symbol naming 00192 the type. STREAM is the output stream on which to print. */ 00193 00194 void (*la_print_typedef) (struct type *type, struct symbol *new_symbol, 00195 struct ui_file *stream); 00196 00197 /* Print a value using syntax appropriate for this language. 00198 00199 TYPE is the type of the sub-object to be printed. 00200 00201 CONTENTS holds the bits of the value. This holds the entire 00202 enclosing object. 00203 00204 EMBEDDED_OFFSET is the offset into the outermost object of the 00205 sub-object represented by TYPE. This is the object which this 00206 call should print. Note that the enclosing type is not 00207 available. 00208 00209 ADDRESS is the address in the inferior of the enclosing object. 00210 00211 STREAM is the stream on which the value is to be printed. 00212 00213 RECURSE is the recursion depth. It is zero-based. 00214 00215 OPTIONS are the formatting options to be used when 00216 printing. */ 00217 00218 void (*la_val_print) (struct type *type, 00219 const gdb_byte *contents, 00220 int embedded_offset, CORE_ADDR address, 00221 struct ui_file *stream, int recurse, 00222 const struct value *val, 00223 const struct value_print_options *options); 00224 00225 /* Print a top-level value using syntax appropriate for this language. */ 00226 00227 void (*la_value_print) (struct value *, struct ui_file *, 00228 const struct value_print_options *); 00229 00230 /* Given a symbol VAR, and a stack frame id FRAME, read the value 00231 of the variable an return (pointer to a) struct value containing 00232 the value. 00233 00234 Throw an error if the variable cannot be found. */ 00235 00236 struct value *(*la_read_var_value) (struct symbol *var, 00237 struct frame_info *frame); 00238 00239 /* PC is possibly an unknown languages trampoline. 00240 If that PC falls in a trampoline belonging to this language, 00241 return the address of the first pc in the real function, or 0 00242 if it isn't a language tramp for this language. */ 00243 CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR); 00244 00245 /* Now come some hooks for lookup_symbol. */ 00246 00247 /* If this is non-NULL, specifies the name that of the implicit 00248 local variable that refers to the current object instance. */ 00249 00250 char *la_name_of_this; 00251 00252 /* This is a function that lookup_symbol will call when it gets to 00253 the part of symbol lookup where C looks up static and global 00254 variables. */ 00255 00256 struct symbol *(*la_lookup_symbol_nonlocal) (const char *, 00257 const struct block *, 00258 const domain_enum); 00259 00260 /* Find the definition of the type with the given name. */ 00261 struct type *(*la_lookup_transparent_type) (const char *); 00262 00263 /* Return demangled language symbol, or NULL. */ 00264 char *(*la_demangle) (const char *mangled, int options); 00265 00266 /* Return class name of a mangled method name or NULL. */ 00267 char *(*la_class_name_from_physname) (const char *physname); 00268 00269 /* Table for printing expressions. */ 00270 00271 const struct op_print *la_op_print_tab; 00272 00273 /* Zero if the language has first-class arrays. True if there are no 00274 array values, and array objects decay to pointers, as in C. */ 00275 00276 char c_style_arrays; 00277 00278 /* Index to use for extracting the first element of a string. */ 00279 char string_lower_bound; 00280 00281 /* The list of characters forming word boundaries. */ 00282 char *(*la_word_break_characters) (void); 00283 00284 /* Should return a vector of all symbols which are possible 00285 completions for TEXT. WORD is the entire command on which the 00286 completion is being made. If CODE is TYPE_CODE_UNDEF, then all 00287 symbols should be examined; otherwise, only STRUCT_DOMAIN 00288 symbols whose type has a code of CODE should be matched. */ 00289 VEC (char_ptr) *(*la_make_symbol_completion_list) (const char *text, 00290 const char *word, 00291 enum type_code code); 00292 00293 /* The per-architecture (OS/ABI) language information. */ 00294 void (*la_language_arch_info) (struct gdbarch *, 00295 struct language_arch_info *); 00296 00297 /* Print the index of an element of an array. */ 00298 void (*la_print_array_index) (struct value *index_value, 00299 struct ui_file *stream, 00300 const struct value_print_options *options); 00301 00302 /* Return non-zero if TYPE should be passed (and returned) by 00303 reference at the language level. */ 00304 int (*la_pass_by_reference) (struct type *type); 00305 00306 /* Obtain a string from the inferior, storing it in a newly allocated 00307 buffer in BUFFER, which should be freed by the caller. If the 00308 in- and out-parameter *LENGTH is specified at -1, the string is 00309 read until a null character of the appropriate width is found - 00310 otherwise the string is read to the length of characters specified. 00311 On completion, *LENGTH will hold the size of the string in characters. 00312 If a *LENGTH of -1 was specified it will count only actual 00313 characters, excluding any eventual terminating null character. 00314 Otherwise *LENGTH will include all characters - including any nulls. 00315 CHARSET will hold the encoding used in the string. */ 00316 void (*la_get_string) (struct value *value, gdb_byte **buffer, int *length, 00317 struct type **chartype, const char **charset); 00318 00319 /* Return a pointer to the function that should be used to match 00320 a symbol name against LOOKUP_NAME. This is mostly for languages 00321 such as Ada where the matching algorithm depends on LOOKUP_NAME. 00322 00323 This field may be NULL, in which case strcmp_iw will be used 00324 to perform the matching. */ 00325 symbol_name_cmp_ftype (*la_get_symbol_name_cmp) (const char *lookup_name); 00326 00327 /* Find all symbols in the current program space matching NAME in 00328 DOMAIN, according to this language's rules. 00329 00330 The search is done in BLOCK only. 00331 The caller is responsible for iterating up through superblocks 00332 if desired. 00333 00334 For each one, call CALLBACK with the symbol and the DATA 00335 argument. If CALLBACK returns zero, the iteration ends at that 00336 point. 00337 00338 This field may not be NULL. If the language does not need any 00339 special processing here, 'iterate_over_symbols' should be 00340 used as the definition. */ 00341 void (*la_iterate_over_symbols) (const struct block *block, 00342 const char *name, 00343 domain_enum domain, 00344 symbol_found_callback_ftype *callback, 00345 void *data); 00346 00347 /* Add fields above this point, so the magic number is always last. */ 00348 /* Magic number for compat checking. */ 00349 00350 long la_magic; 00351 00352 }; 00353 00354 #define LANG_MAGIC 910823L 00355 00356 /* Pointer to the language_defn for our current language. This pointer 00357 always points to *some* valid struct; it can be used without checking 00358 it for validity. 00359 00360 The current language affects expression parsing and evaluation 00361 (FIXME: it might be cleaner to make the evaluation-related stuff 00362 separate exp_opcodes for each different set of semantics. We 00363 should at least think this through more clearly with respect to 00364 what happens if the language is changed between parsing and 00365 evaluation) and printing of things like types and arrays. It does 00366 *not* affect symbol-reading-- each source file in a symbol-file has 00367 its own language and we should keep track of that regardless of the 00368 language when symbols are read. If we want some manual setting for 00369 the language of symbol files (e.g. detecting when ".c" files are 00370 C++), it should be a separate setting from the current_language. */ 00371 00372 extern const struct language_defn *current_language; 00373 00374 /* Pointer to the language_defn expected by the user, e.g. the language 00375 of main(), or the language we last mentioned in a message, or C. */ 00376 00377 extern const struct language_defn *expected_language; 00378 00379 /* language_mode == 00380 language_mode_auto: current_language automatically set upon selection 00381 of scope (e.g. stack frame) 00382 language_mode_manual: current_language set only by user. */ 00383 00384 extern enum language_mode 00385 { 00386 language_mode_auto, language_mode_manual 00387 } 00388 language_mode; 00389 00390 struct type *language_bool_type (const struct language_defn *l, 00391 struct gdbarch *gdbarch); 00392 00393 struct type *language_string_char_type (const struct language_defn *l, 00394 struct gdbarch *gdbarch); 00395 00396 struct type *language_lookup_primitive_type_by_name (const struct language_defn *l, 00397 struct gdbarch *gdbarch, 00398 const char *name); 00399 00400 00401 /* These macros define the behaviour of the expression 00402 evaluator. */ 00403 00404 /* Should we range check values against the domain of their type? */ 00405 #define RANGE_CHECK (range_check != range_check_off) 00406 00407 /* "cast" really means conversion. */ 00408 /* FIXME -- should be a setting in language_defn. */ 00409 #define CAST_IS_CONVERSION(LANG) ((LANG)->la_language == language_c || \ 00410 (LANG)->la_language == language_cplus || \ 00411 (LANG)->la_language == language_objc) 00412 00413 extern void language_info (int); 00414 00415 extern enum language set_language (enum language); 00416 00417 00418 /* This page contains functions that return things that are 00419 specific to languages. Each of these functions is based on 00420 the current setting of working_lang, which the user sets 00421 with the "set language" command. */ 00422 00423 #define LA_PRINT_TYPE(type,varstring,stream,show,level,flags) \ 00424 (current_language->la_print_type(type,varstring,stream,show,level,flags)) 00425 00426 #define LA_PRINT_TYPEDEF(type,new_symbol,stream) \ 00427 (current_language->la_print_typedef(type,new_symbol,stream)) 00428 00429 #define LA_VAL_PRINT(type,valaddr,offset,addr,stream,val,recurse,options) \ 00430 (current_language->la_val_print(type,valaddr,offset,addr,stream, \ 00431 val,recurse,options)) 00432 #define LA_VALUE_PRINT(val,stream,options) \ 00433 (current_language->la_value_print(val,stream,options)) 00434 00435 #define LA_PRINT_CHAR(ch, type, stream) \ 00436 (current_language->la_printchar(ch, type, stream)) 00437 #define LA_PRINT_STRING(stream, elttype, string, length, encoding, force_ellipses, options) \ 00438 (current_language->la_printstr(stream, elttype, string, length, \ 00439 encoding, force_ellipses,options)) 00440 #define LA_EMIT_CHAR(ch, type, stream, quoter) \ 00441 (current_language->la_emitchar(ch, type, stream, quoter)) 00442 #define LA_GET_STRING(value, buffer, length, chartype, encoding) \ 00443 (current_language->la_get_string(value, buffer, length, chartype, encoding)) 00444 00445 #define LA_PRINT_ARRAY_INDEX(index_value, stream, options) \ 00446 (current_language->la_print_array_index(index_value, stream, options)) 00447 00448 #define LA_ITERATE_OVER_SYMBOLS(BLOCK, NAME, DOMAIN, CALLBACK, DATA) \ 00449 (current_language->la_iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK, \ 00450 DATA)) 00451 00452 /* Test a character to decide whether it can be printed in literal form 00453 or needs to be printed in another representation. For example, 00454 in C the literal form of the character with octal value 141 is 'a' 00455 and the "other representation" is '\141'. The "other representation" 00456 is program language dependent. */ 00457 00458 #define PRINT_LITERAL_FORM(c) \ 00459 ((c) >= 0x20 \ 00460 && ((c) < 0x7F || (c) >= 0xA0) \ 00461 && (!sevenbit_strings || (c) < 0x80)) 00462 00463 /* Type predicates */ 00464 00465 extern int pointer_type (struct type *); 00466 00467 /* Checks Binary and Unary operations for semantic type correctness. */ 00468 /* FIXME: Does not appear to be used. */ 00469 #define unop_type_check(v,o) binop_type_check((v),NULL,(o)) 00470 00471 extern void binop_type_check (struct value *, struct value *, int); 00472 00473 /* Error messages */ 00474 00475 extern void range_error (const char *, ...) ATTRIBUTE_PRINTF (1, 2); 00476 00477 /* Data: Does this value represent "truth" to the current language? */ 00478 00479 extern int value_true (struct value *); 00480 00481 /* Misc: The string representing a particular enum language. */ 00482 00483 extern enum language language_enum (char *str); 00484 00485 extern const struct language_defn *language_def (enum language); 00486 00487 extern char *language_str (enum language); 00488 00489 /* Add a language to the set known by GDB (at initialization time). */ 00490 00491 extern void add_language (const struct language_defn *); 00492 00493 extern enum language get_frame_language (void); /* In stack.c */ 00494 00495 /* Check for a language-specific trampoline. */ 00496 00497 extern CORE_ADDR skip_language_trampoline (struct frame_info *, CORE_ADDR pc); 00498 00499 /* Return demangled language symbol, or NULL. */ 00500 extern char *language_demangle (const struct language_defn *current_language, 00501 const char *mangled, int options); 00502 00503 /* Return class name from physname, or NULL. */ 00504 extern char *language_class_name_from_physname (const struct language_defn *, 00505 const char *physname); 00506 00507 /* Splitting strings into words. */ 00508 extern char *default_word_break_characters (void); 00509 00510 /* Print the index of an array element using the C99 syntax. */ 00511 extern void default_print_array_index (struct value *index_value, 00512 struct ui_file *stream, 00513 const struct value_print_options *options); 00514 00515 /* Return non-zero if TYPE should be passed (and returned) by 00516 reference at the language level. */ 00517 int language_pass_by_reference (struct type *type); 00518 00519 /* Return zero; by default, types are passed by value at the language 00520 level. The target ABI may pass or return some structs by reference 00521 independent of this. */ 00522 int default_pass_by_reference (struct type *type); 00523 00524 /* The default implementation of la_print_typedef. */ 00525 void default_print_typedef (struct type *type, struct symbol *new_symbol, 00526 struct ui_file *stream); 00527 00528 void default_get_string (struct value *value, gdb_byte **buffer, int *length, 00529 struct type **char_type, const char **charset); 00530 00531 void c_get_string (struct value *value, gdb_byte **buffer, int *length, 00532 struct type **char_type, const char **charset); 00533 00534 #endif /* defined (LANGUAGE_H) */