GDB (API)
|
00001 /* Multiple source language support 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 /* This file contains functions that return things that are specific 00024 to languages. Each function should examine current_language if necessary, 00025 and return the appropriate result. */ 00026 00027 /* FIXME: Most of these would be better organized as macros which 00028 return data out of a "language-specific" struct pointer that is set 00029 whenever the working language changes. That would be a lot faster. */ 00030 00031 #include "defs.h" 00032 #include <ctype.h> 00033 #include "gdb_string.h" 00034 00035 #include "symtab.h" 00036 #include "gdbtypes.h" 00037 #include "value.h" 00038 #include "gdbcmd.h" 00039 #include "expression.h" 00040 #include "language.h" 00041 #include "target.h" 00042 #include "parser-defs.h" 00043 #include "jv-lang.h" 00044 #include "demangle.h" 00045 #include "symfile.h" 00046 #include "cp-support.h" 00047 00048 extern void _initialize_language (void); 00049 00050 static void unk_lang_error (char *); 00051 00052 static int unk_lang_parser (void); 00053 00054 static void show_check (char *, int); 00055 00056 static void set_check (char *, int); 00057 00058 static void set_range_case (void); 00059 00060 static void unk_lang_emit_char (int c, struct type *type, 00061 struct ui_file *stream, int quoter); 00062 00063 static void unk_lang_printchar (int c, struct type *type, 00064 struct ui_file *stream); 00065 00066 static void unk_lang_value_print (struct value *, struct ui_file *, 00067 const struct value_print_options *); 00068 00069 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc); 00070 00071 /* Forward declaration */ 00072 extern const struct language_defn unknown_language_defn; 00073 00074 /* The current (default at startup) state of type and range checking. 00075 (If the modes are set to "auto", though, these are changed based 00076 on the default language at startup, and then again based on the 00077 language of the first source file. */ 00078 00079 enum range_mode range_mode = range_mode_auto; 00080 enum range_check range_check = range_check_off; 00081 enum case_mode case_mode = case_mode_auto; 00082 enum case_sensitivity case_sensitivity = case_sensitive_on; 00083 00084 /* The current language and language_mode (see language.h). */ 00085 00086 const struct language_defn *current_language = &unknown_language_defn; 00087 enum language_mode language_mode = language_mode_auto; 00088 00089 /* The language that the user expects to be typing in (the language 00090 of main(), or the last language we notified them about, or C). */ 00091 00092 const struct language_defn *expected_language; 00093 00094 /* The list of supported languages. The list itself is malloc'd. */ 00095 00096 static const struct language_defn **languages; 00097 static unsigned languages_size; 00098 static unsigned languages_allocsize; 00099 #define DEFAULT_ALLOCSIZE 4 00100 00101 /* The current values of the "set language/type/range" enum 00102 commands. */ 00103 static const char *language; 00104 static const char *type; 00105 static const char *range; 00106 static const char *case_sensitive; 00107 00108 /* Warning issued when current_language and the language of the current 00109 frame do not match. */ 00110 char lang_frame_mismatch_warn[] = 00111 "Warning: the current language does not match this frame."; 00112 00113 /* This page contains the functions corresponding to GDB commands 00114 and their helpers. */ 00115 00116 /* Show command. Display a warning if the language set 00117 does not match the frame. */ 00118 static void 00119 show_language_command (struct ui_file *file, int from_tty, 00120 struct cmd_list_element *c, const char *value) 00121 { 00122 enum language flang; /* The language of the current frame. */ 00123 00124 if (language_mode == language_mode_auto) 00125 fprintf_filtered (gdb_stdout, 00126 _("The current source language is " 00127 "\"auto; currently %s\".\n"), 00128 current_language->la_name); 00129 else 00130 fprintf_filtered (gdb_stdout, 00131 _("The current source language is \"%s\".\n"), 00132 current_language->la_name); 00133 00134 flang = get_frame_language (); 00135 if (flang != language_unknown && 00136 language_mode == language_mode_manual && 00137 current_language->la_language != flang) 00138 printf_filtered ("%s\n", lang_frame_mismatch_warn); 00139 } 00140 00141 /* Set command. Change the current working language. */ 00142 static void 00143 set_language_command (char *ignore, int from_tty, struct cmd_list_element *c) 00144 { 00145 int i; 00146 enum language flang; 00147 00148 /* Search the list of languages for a match. */ 00149 for (i = 0; i < languages_size; i++) 00150 { 00151 if (strcmp (languages[i]->la_name, language) == 0) 00152 { 00153 /* Found it! Go into manual mode, and use this language. */ 00154 if (languages[i]->la_language == language_auto) 00155 { 00156 /* Enter auto mode. Set to the current frame's language, if 00157 known, or fallback to the initial language. */ 00158 language_mode = language_mode_auto; 00159 flang = get_frame_language (); 00160 if (flang != language_unknown) 00161 set_language (flang); 00162 else 00163 set_initial_language (); 00164 expected_language = current_language; 00165 return; 00166 } 00167 else 00168 { 00169 /* Enter manual mode. Set the specified language. */ 00170 language_mode = language_mode_manual; 00171 current_language = languages[i]; 00172 set_range_case (); 00173 expected_language = current_language; 00174 return; 00175 } 00176 } 00177 } 00178 00179 internal_error (__FILE__, __LINE__, 00180 "Couldn't find language `%s' in known languages list.", 00181 language); 00182 } 00183 00184 /* Show command. Display a warning if the range setting does 00185 not match the current language. */ 00186 static void 00187 show_range_command (struct ui_file *file, int from_tty, 00188 struct cmd_list_element *c, const char *value) 00189 { 00190 if (range_mode == range_mode_auto) 00191 { 00192 char *tmp; 00193 00194 switch (range_check) 00195 { 00196 case range_check_on: 00197 tmp = "on"; 00198 break; 00199 case range_check_off: 00200 tmp = "off"; 00201 break; 00202 case range_check_warn: 00203 tmp = "warn"; 00204 break; 00205 default: 00206 internal_error (__FILE__, __LINE__, 00207 "Unrecognized range check setting."); 00208 } 00209 00210 fprintf_filtered (gdb_stdout, 00211 _("Range checking is \"auto; currently %s\".\n"), 00212 tmp); 00213 } 00214 else 00215 fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"), 00216 value); 00217 00218 if (range_check != current_language->la_range_check) 00219 warning (_("the current range check setting " 00220 "does not match the language.\n")); 00221 } 00222 00223 /* Set command. Change the setting for range checking. */ 00224 static void 00225 set_range_command (char *ignore, int from_tty, struct cmd_list_element *c) 00226 { 00227 if (strcmp (range, "on") == 0) 00228 { 00229 range_check = range_check_on; 00230 range_mode = range_mode_manual; 00231 } 00232 else if (strcmp (range, "warn") == 0) 00233 { 00234 range_check = range_check_warn; 00235 range_mode = range_mode_manual; 00236 } 00237 else if (strcmp (range, "off") == 0) 00238 { 00239 range_check = range_check_off; 00240 range_mode = range_mode_manual; 00241 } 00242 else if (strcmp (range, "auto") == 0) 00243 { 00244 range_mode = range_mode_auto; 00245 set_range_case (); 00246 return; 00247 } 00248 else 00249 { 00250 internal_error (__FILE__, __LINE__, 00251 _("Unrecognized range check setting: \"%s\""), range); 00252 } 00253 if (range_check != current_language->la_range_check) 00254 warning (_("the current range check setting " 00255 "does not match the language.\n")); 00256 } 00257 00258 /* Show command. Display a warning if the case sensitivity setting does 00259 not match the current language. */ 00260 static void 00261 show_case_command (struct ui_file *file, int from_tty, 00262 struct cmd_list_element *c, const char *value) 00263 { 00264 if (case_mode == case_mode_auto) 00265 { 00266 char *tmp = NULL; 00267 00268 switch (case_sensitivity) 00269 { 00270 case case_sensitive_on: 00271 tmp = "on"; 00272 break; 00273 case case_sensitive_off: 00274 tmp = "off"; 00275 break; 00276 default: 00277 internal_error (__FILE__, __LINE__, 00278 "Unrecognized case-sensitive setting."); 00279 } 00280 00281 fprintf_filtered (gdb_stdout, 00282 _("Case sensitivity in " 00283 "name search is \"auto; currently %s\".\n"), 00284 tmp); 00285 } 00286 else 00287 fprintf_filtered (gdb_stdout, 00288 _("Case sensitivity in name search is \"%s\".\n"), 00289 value); 00290 00291 if (case_sensitivity != current_language->la_case_sensitivity) 00292 warning (_("the current case sensitivity setting does not match " 00293 "the language.\n")); 00294 } 00295 00296 /* Set command. Change the setting for case sensitivity. */ 00297 00298 static void 00299 set_case_command (char *ignore, int from_tty, struct cmd_list_element *c) 00300 { 00301 if (strcmp (case_sensitive, "on") == 0) 00302 { 00303 case_sensitivity = case_sensitive_on; 00304 case_mode = case_mode_manual; 00305 } 00306 else if (strcmp (case_sensitive, "off") == 0) 00307 { 00308 case_sensitivity = case_sensitive_off; 00309 case_mode = case_mode_manual; 00310 } 00311 else if (strcmp (case_sensitive, "auto") == 0) 00312 { 00313 case_mode = case_mode_auto; 00314 set_range_case (); 00315 return; 00316 } 00317 else 00318 { 00319 internal_error (__FILE__, __LINE__, 00320 "Unrecognized case-sensitive setting: \"%s\"", 00321 case_sensitive); 00322 } 00323 00324 if (case_sensitivity != current_language->la_case_sensitivity) 00325 warning (_("the current case sensitivity setting does not match " 00326 "the language.\n")); 00327 } 00328 00329 /* Set the status of range and type checking and case sensitivity based on 00330 the current modes and the current language. 00331 If SHOW is non-zero, then print out the current language, 00332 type and range checking status. */ 00333 static void 00334 set_range_case (void) 00335 { 00336 if (range_mode == range_mode_auto) 00337 range_check = current_language->la_range_check; 00338 00339 if (case_mode == case_mode_auto) 00340 case_sensitivity = current_language->la_case_sensitivity; 00341 } 00342 00343 /* Set current language to (enum language) LANG. Returns previous 00344 language. */ 00345 00346 enum language 00347 set_language (enum language lang) 00348 { 00349 int i; 00350 enum language prev_language; 00351 00352 prev_language = current_language->la_language; 00353 00354 for (i = 0; i < languages_size; i++) 00355 { 00356 if (languages[i]->la_language == lang) 00357 { 00358 current_language = languages[i]; 00359 set_range_case (); 00360 break; 00361 } 00362 } 00363 00364 return prev_language; 00365 } 00366 00367 00368 /* Print out the current language settings: language, range and 00369 type checking. If QUIETLY, print only what has changed. */ 00370 00371 void 00372 language_info (int quietly) 00373 { 00374 if (quietly && expected_language == current_language) 00375 return; 00376 00377 expected_language = current_language; 00378 printf_unfiltered (_("Current language: %s\n"), language); 00379 show_language_command (NULL, 1, NULL, NULL); 00380 00381 if (!quietly) 00382 { 00383 printf_unfiltered (_("Range checking: %s\n"), range); 00384 show_range_command (NULL, 1, NULL, NULL); 00385 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive); 00386 show_case_command (NULL, 1, NULL, NULL); 00387 } 00388 } 00389 00390 00391 /* Returns non-zero if the value is a pointer type. */ 00392 int 00393 pointer_type (struct type *type) 00394 { 00395 return TYPE_CODE (type) == TYPE_CODE_PTR || 00396 TYPE_CODE (type) == TYPE_CODE_REF; 00397 } 00398 00399 00400 /* This page contains functions that return info about 00401 (struct value) values used in GDB. */ 00402 00403 /* Returns non-zero if the value VAL represents a true value. */ 00404 int 00405 value_true (struct value *val) 00406 { 00407 /* It is possible that we should have some sort of error if a non-boolean 00408 value is used in this context. Possibly dependent on some kind of 00409 "boolean-checking" option like range checking. But it should probably 00410 not depend on the language except insofar as is necessary to identify 00411 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean 00412 should be an error, probably). */ 00413 return !value_logical_not (val); 00414 } 00415 00416 /* This page contains functions for the printing out of 00417 error messages that occur during type- and range- 00418 checking. */ 00419 00420 /* This is called when a language fails a range-check. The 00421 first argument should be a printf()-style format string, and the 00422 rest of the arguments should be its arguments. If range_check is 00423 range_check_on, an error is printed; if range_check_warn, a warning; 00424 otherwise just the message. */ 00425 00426 void 00427 range_error (const char *string,...) 00428 { 00429 va_list args; 00430 00431 va_start (args, string); 00432 switch (range_check) 00433 { 00434 case range_check_warn: 00435 vwarning (string, args); 00436 break; 00437 case range_check_on: 00438 verror (string, args); 00439 break; 00440 case range_check_off: 00441 /* FIXME: cagney/2002-01-30: Should this function print anything 00442 when range error is off? */ 00443 vfprintf_filtered (gdb_stderr, string, args); 00444 fprintf_filtered (gdb_stderr, "\n"); 00445 break; 00446 default: 00447 internal_error (__FILE__, __LINE__, _("bad switch")); 00448 } 00449 va_end (args); 00450 } 00451 00452 00453 /* This page contains miscellaneous functions. */ 00454 00455 /* Return the language enum for a given language string. */ 00456 00457 enum language 00458 language_enum (char *str) 00459 { 00460 int i; 00461 00462 for (i = 0; i < languages_size; i++) 00463 if (strcmp (languages[i]->la_name, str) == 0) 00464 return languages[i]->la_language; 00465 00466 return language_unknown; 00467 } 00468 00469 /* Return the language struct for a given language enum. */ 00470 00471 const struct language_defn * 00472 language_def (enum language lang) 00473 { 00474 int i; 00475 00476 for (i = 0; i < languages_size; i++) 00477 { 00478 if (languages[i]->la_language == lang) 00479 { 00480 return languages[i]; 00481 } 00482 } 00483 return NULL; 00484 } 00485 00486 /* Return the language as a string. */ 00487 char * 00488 language_str (enum language lang) 00489 { 00490 int i; 00491 00492 for (i = 0; i < languages_size; i++) 00493 { 00494 if (languages[i]->la_language == lang) 00495 { 00496 return languages[i]->la_name; 00497 } 00498 } 00499 return "Unknown"; 00500 } 00501 00502 static void 00503 set_check (char *ignore, int from_tty) 00504 { 00505 printf_unfiltered ( 00506 "\"set check\" must be followed by the name of a check subcommand.\n"); 00507 help_list (setchecklist, "set check ", -1, gdb_stdout); 00508 } 00509 00510 static void 00511 show_check (char *ignore, int from_tty) 00512 { 00513 cmd_show_list (showchecklist, from_tty, ""); 00514 } 00515 00516 /* Add a language to the set of known languages. */ 00517 00518 void 00519 add_language (const struct language_defn *lang) 00520 { 00521 /* For the "set language" command. */ 00522 static char **language_names = NULL; 00523 /* For the "help set language" command. */ 00524 char *language_set_doc = NULL; 00525 00526 int i; 00527 struct ui_file *tmp_stream; 00528 00529 if (lang->la_magic != LANG_MAGIC) 00530 { 00531 fprintf_unfiltered (gdb_stderr, 00532 "Magic number of %s language struct wrong\n", 00533 lang->la_name); 00534 internal_error (__FILE__, __LINE__, 00535 _("failed internal consistency check")); 00536 } 00537 00538 if (!languages) 00539 { 00540 languages_allocsize = DEFAULT_ALLOCSIZE; 00541 languages = (const struct language_defn **) xmalloc 00542 (languages_allocsize * sizeof (*languages)); 00543 } 00544 if (languages_size >= languages_allocsize) 00545 { 00546 languages_allocsize *= 2; 00547 languages = (const struct language_defn **) xrealloc ((char *) languages, 00548 languages_allocsize * sizeof (*languages)); 00549 } 00550 languages[languages_size++] = lang; 00551 00552 /* Build the language names array, to be used as enumeration in the 00553 set language" enum command. */ 00554 language_names = xrealloc (language_names, 00555 (languages_size + 1) * sizeof (const char *)); 00556 for (i = 0; i < languages_size; ++i) 00557 language_names[i] = languages[i]->la_name; 00558 language_names[i] = NULL; 00559 00560 /* Build the "help set language" docs. */ 00561 tmp_stream = mem_fileopen (); 00562 00563 fprintf_unfiltered (tmp_stream, 00564 _("Set the current source language.\n" 00565 "The currently understood settings are:\n\nlocal or " 00566 "auto Automatic setting based on source file\n")); 00567 00568 for (i = 0; i < languages_size; ++i) 00569 { 00570 /* Already dealt with these above. */ 00571 if (languages[i]->la_language == language_unknown 00572 || languages[i]->la_language == language_auto) 00573 continue; 00574 00575 /* FIXME: i18n: for now assume that the human-readable name 00576 is just a capitalization of the internal name. */ 00577 fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n", 00578 languages[i]->la_name, 00579 /* Capitalize first letter of language 00580 name. */ 00581 toupper (languages[i]->la_name[0]), 00582 languages[i]->la_name + 1); 00583 } 00584 00585 language_set_doc = ui_file_xstrdup (tmp_stream, NULL); 00586 ui_file_delete (tmp_stream); 00587 00588 add_setshow_enum_cmd ("language", class_support, 00589 (const char **) language_names, 00590 &language, 00591 language_set_doc, 00592 _("Show the current source language."), 00593 NULL, set_language_command, 00594 show_language_command, 00595 &setlist, &showlist); 00596 00597 xfree (language_set_doc); 00598 } 00599 00600 /* Iterate through all registered languages looking for and calling 00601 any non-NULL struct language_defn.skip_trampoline() functions. 00602 Return the result from the first that returns non-zero, or 0 if all 00603 `fail'. */ 00604 CORE_ADDR 00605 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc) 00606 { 00607 int i; 00608 00609 for (i = 0; i < languages_size; i++) 00610 { 00611 if (languages[i]->skip_trampoline) 00612 { 00613 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc); 00614 00615 if (real_pc) 00616 return real_pc; 00617 } 00618 } 00619 00620 return 0; 00621 } 00622 00623 /* Return demangled language symbol, or NULL. 00624 FIXME: Options are only useful for certain languages and ignored 00625 by others, so it would be better to remove them here and have a 00626 more flexible demangler for the languages that need it. 00627 FIXME: Sometimes the demangler is invoked when we don't know the 00628 language, so we can't use this everywhere. */ 00629 char * 00630 language_demangle (const struct language_defn *current_language, 00631 const char *mangled, int options) 00632 { 00633 if (current_language != NULL && current_language->la_demangle) 00634 return current_language->la_demangle (mangled, options); 00635 return NULL; 00636 } 00637 00638 /* Return class name from physname or NULL. */ 00639 char * 00640 language_class_name_from_physname (const struct language_defn *lang, 00641 const char *physname) 00642 { 00643 if (lang != NULL && lang->la_class_name_from_physname) 00644 return lang->la_class_name_from_physname (physname); 00645 return NULL; 00646 } 00647 00648 /* Return non-zero if TYPE should be passed (and returned) by 00649 reference at the language level. */ 00650 int 00651 language_pass_by_reference (struct type *type) 00652 { 00653 return current_language->la_pass_by_reference (type); 00654 } 00655 00656 /* Return zero; by default, types are passed by value at the language 00657 level. The target ABI may pass or return some structs by reference 00658 independent of this. */ 00659 int 00660 default_pass_by_reference (struct type *type) 00661 { 00662 return 0; 00663 } 00664 00665 /* Return the default string containing the list of characters 00666 delimiting words. This is a reasonable default value that 00667 most languages should be able to use. */ 00668 00669 char * 00670 default_word_break_characters (void) 00671 { 00672 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; 00673 } 00674 00675 /* Print the index of array elements using the C99 syntax. */ 00676 00677 void 00678 default_print_array_index (struct value *index_value, struct ui_file *stream, 00679 const struct value_print_options *options) 00680 { 00681 fprintf_filtered (stream, "["); 00682 LA_VALUE_PRINT (index_value, stream, options); 00683 fprintf_filtered (stream, "] = "); 00684 } 00685 00686 void 00687 default_get_string (struct value *value, gdb_byte **buffer, int *length, 00688 struct type **char_type, const char **charset) 00689 { 00690 error (_("Getting a string is unsupported in this language.")); 00691 } 00692 00693 /* Define the language that is no language. */ 00694 00695 static int 00696 unk_lang_parser (void) 00697 { 00698 return 1; 00699 } 00700 00701 static void 00702 unk_lang_error (char *msg) 00703 { 00704 error (_("Attempted to parse an expression with unknown language")); 00705 } 00706 00707 static void 00708 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, 00709 int quoter) 00710 { 00711 error (_("internal error - unimplemented " 00712 "function unk_lang_emit_char called.")); 00713 } 00714 00715 static void 00716 unk_lang_printchar (int c, struct type *type, struct ui_file *stream) 00717 { 00718 error (_("internal error - unimplemented " 00719 "function unk_lang_printchar called.")); 00720 } 00721 00722 static void 00723 unk_lang_printstr (struct ui_file *stream, struct type *type, 00724 const gdb_byte *string, unsigned int length, 00725 const char *encoding, int force_ellipses, 00726 const struct value_print_options *options) 00727 { 00728 error (_("internal error - unimplemented " 00729 "function unk_lang_printstr called.")); 00730 } 00731 00732 static void 00733 unk_lang_print_type (struct type *type, const char *varstring, 00734 struct ui_file *stream, int show, int level, 00735 const struct type_print_options *flags) 00736 { 00737 error (_("internal error - unimplemented " 00738 "function unk_lang_print_type called.")); 00739 } 00740 00741 static void 00742 unk_lang_val_print (struct type *type, const gdb_byte *valaddr, 00743 int embedded_offset, CORE_ADDR address, 00744 struct ui_file *stream, int recurse, 00745 const struct value *val, 00746 const struct value_print_options *options) 00747 { 00748 error (_("internal error - unimplemented " 00749 "function unk_lang_val_print called.")); 00750 } 00751 00752 static void 00753 unk_lang_value_print (struct value *val, struct ui_file *stream, 00754 const struct value_print_options *options) 00755 { 00756 error (_("internal error - unimplemented " 00757 "function unk_lang_value_print called.")); 00758 } 00759 00760 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) 00761 { 00762 return 0; 00763 } 00764 00765 /* Unknown languages just use the cplus demangler. */ 00766 static char *unk_lang_demangle (const char *mangled, int options) 00767 { 00768 return gdb_demangle (mangled, options); 00769 } 00770 00771 static char *unk_lang_class_name (const char *mangled) 00772 { 00773 return NULL; 00774 } 00775 00776 static const struct op_print unk_op_print_tab[] = 00777 { 00778 {NULL, OP_NULL, PREC_NULL, 0} 00779 }; 00780 00781 static void 00782 unknown_language_arch_info (struct gdbarch *gdbarch, 00783 struct language_arch_info *lai) 00784 { 00785 lai->string_char_type = builtin_type (gdbarch)->builtin_char; 00786 lai->bool_type_default = builtin_type (gdbarch)->builtin_int; 00787 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, 00788 struct type *); 00789 } 00790 00791 const struct language_defn unknown_language_defn = 00792 { 00793 "unknown", 00794 language_unknown, 00795 range_check_off, 00796 case_sensitive_on, 00797 array_row_major, 00798 macro_expansion_no, 00799 &exp_descriptor_standard, 00800 unk_lang_parser, 00801 unk_lang_error, 00802 null_post_parser, 00803 unk_lang_printchar, /* Print character constant */ 00804 unk_lang_printstr, 00805 unk_lang_emit_char, 00806 unk_lang_print_type, /* Print a type using appropriate syntax */ 00807 default_print_typedef, /* Print a typedef using appropriate syntax */ 00808 unk_lang_val_print, /* Print a value using appropriate syntax */ 00809 unk_lang_value_print, /* Print a top-level value */ 00810 default_read_var_value, /* la_read_var_value */ 00811 unk_lang_trampoline, /* Language specific skip_trampoline */ 00812 "this", /* name_of_this */ 00813 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 00814 basic_lookup_transparent_type,/* lookup_transparent_type */ 00815 unk_lang_demangle, /* Language specific symbol demangler */ 00816 unk_lang_class_name, /* Language specific 00817 class_name_from_physname */ 00818 unk_op_print_tab, /* expression operators for printing */ 00819 1, /* c-style arrays */ 00820 0, /* String lower bound */ 00821 default_word_break_characters, 00822 default_make_symbol_completion_list, 00823 unknown_language_arch_info, /* la_language_arch_info. */ 00824 default_print_array_index, 00825 default_pass_by_reference, 00826 default_get_string, 00827 NULL, /* la_get_symbol_name_cmp */ 00828 iterate_over_symbols, 00829 LANG_MAGIC 00830 }; 00831 00832 /* These two structs define fake entries for the "local" and "auto" 00833 options. */ 00834 const struct language_defn auto_language_defn = 00835 { 00836 "auto", 00837 language_auto, 00838 range_check_off, 00839 case_sensitive_on, 00840 array_row_major, 00841 macro_expansion_no, 00842 &exp_descriptor_standard, 00843 unk_lang_parser, 00844 unk_lang_error, 00845 null_post_parser, 00846 unk_lang_printchar, /* Print character constant */ 00847 unk_lang_printstr, 00848 unk_lang_emit_char, 00849 unk_lang_print_type, /* Print a type using appropriate syntax */ 00850 default_print_typedef, /* Print a typedef using appropriate syntax */ 00851 unk_lang_val_print, /* Print a value using appropriate syntax */ 00852 unk_lang_value_print, /* Print a top-level value */ 00853 default_read_var_value, /* la_read_var_value */ 00854 unk_lang_trampoline, /* Language specific skip_trampoline */ 00855 "this", /* name_of_this */ 00856 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 00857 basic_lookup_transparent_type,/* lookup_transparent_type */ 00858 unk_lang_demangle, /* Language specific symbol demangler */ 00859 unk_lang_class_name, /* Language specific 00860 class_name_from_physname */ 00861 unk_op_print_tab, /* expression operators for printing */ 00862 1, /* c-style arrays */ 00863 0, /* String lower bound */ 00864 default_word_break_characters, 00865 default_make_symbol_completion_list, 00866 unknown_language_arch_info, /* la_language_arch_info. */ 00867 default_print_array_index, 00868 default_pass_by_reference, 00869 default_get_string, 00870 NULL, /* la_get_symbol_name_cmp */ 00871 iterate_over_symbols, 00872 LANG_MAGIC 00873 }; 00874 00875 const struct language_defn local_language_defn = 00876 { 00877 "local", 00878 language_auto, 00879 range_check_off, 00880 case_sensitive_on, 00881 array_row_major, 00882 macro_expansion_no, 00883 &exp_descriptor_standard, 00884 unk_lang_parser, 00885 unk_lang_error, 00886 null_post_parser, 00887 unk_lang_printchar, /* Print character constant */ 00888 unk_lang_printstr, 00889 unk_lang_emit_char, 00890 unk_lang_print_type, /* Print a type using appropriate syntax */ 00891 default_print_typedef, /* Print a typedef using appropriate syntax */ 00892 unk_lang_val_print, /* Print a value using appropriate syntax */ 00893 unk_lang_value_print, /* Print a top-level value */ 00894 default_read_var_value, /* la_read_var_value */ 00895 unk_lang_trampoline, /* Language specific skip_trampoline */ 00896 "this", /* name_of_this */ 00897 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 00898 basic_lookup_transparent_type,/* lookup_transparent_type */ 00899 unk_lang_demangle, /* Language specific symbol demangler */ 00900 unk_lang_class_name, /* Language specific 00901 class_name_from_physname */ 00902 unk_op_print_tab, /* expression operators for printing */ 00903 1, /* c-style arrays */ 00904 0, /* String lower bound */ 00905 default_word_break_characters, 00906 default_make_symbol_completion_list, 00907 unknown_language_arch_info, /* la_language_arch_info. */ 00908 default_print_array_index, 00909 default_pass_by_reference, 00910 default_get_string, 00911 NULL, /* la_get_symbol_name_cmp */ 00912 iterate_over_symbols, 00913 LANG_MAGIC 00914 }; 00915 00916 /* Per-architecture language information. */ 00917 00918 static struct gdbarch_data *language_gdbarch_data; 00919 00920 struct language_gdbarch 00921 { 00922 /* A vector of per-language per-architecture info. Indexed by "enum 00923 language". */ 00924 struct language_arch_info arch_info[nr_languages]; 00925 }; 00926 00927 static void * 00928 language_gdbarch_post_init (struct gdbarch *gdbarch) 00929 { 00930 struct language_gdbarch *l; 00931 int i; 00932 00933 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); 00934 for (i = 0; i < languages_size; i++) 00935 { 00936 if (languages[i] != NULL 00937 && languages[i]->la_language_arch_info != NULL) 00938 languages[i]->la_language_arch_info 00939 (gdbarch, l->arch_info + languages[i]->la_language); 00940 } 00941 return l; 00942 } 00943 00944 struct type * 00945 language_string_char_type (const struct language_defn *la, 00946 struct gdbarch *gdbarch) 00947 { 00948 struct language_gdbarch *ld = gdbarch_data (gdbarch, 00949 language_gdbarch_data); 00950 00951 return ld->arch_info[la->la_language].string_char_type; 00952 } 00953 00954 struct type * 00955 language_bool_type (const struct language_defn *la, 00956 struct gdbarch *gdbarch) 00957 { 00958 struct language_gdbarch *ld = gdbarch_data (gdbarch, 00959 language_gdbarch_data); 00960 00961 if (ld->arch_info[la->la_language].bool_type_symbol) 00962 { 00963 struct symbol *sym; 00964 00965 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, 00966 NULL, VAR_DOMAIN, NULL); 00967 if (sym) 00968 { 00969 struct type *type = SYMBOL_TYPE (sym); 00970 00971 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) 00972 return type; 00973 } 00974 } 00975 00976 return ld->arch_info[la->la_language].bool_type_default; 00977 } 00978 00979 struct type * 00980 language_lookup_primitive_type_by_name (const struct language_defn *la, 00981 struct gdbarch *gdbarch, 00982 const char *name) 00983 { 00984 struct language_gdbarch *ld = gdbarch_data (gdbarch, 00985 language_gdbarch_data); 00986 struct type *const *p; 00987 00988 for (p = ld->arch_info[la->la_language].primitive_type_vector; 00989 (*p) != NULL; 00990 p++) 00991 { 00992 if (strcmp (TYPE_NAME (*p), name) == 0) 00993 return (*p); 00994 } 00995 return (NULL); 00996 } 00997 00998 /* Initialize the language routines. */ 00999 01000 void 01001 _initialize_language (void) 01002 { 01003 static const char *const type_or_range_names[] 01004 = { "on", "off", "warn", "auto", NULL }; 01005 01006 static const char *const case_sensitive_names[] 01007 = { "on", "off", "auto", NULL }; 01008 01009 language_gdbarch_data 01010 = gdbarch_data_register_post_init (language_gdbarch_post_init); 01011 01012 /* GDB commands for language specific stuff. */ 01013 01014 add_prefix_cmd ("check", no_class, set_check, 01015 _("Set the status of the type/range checker."), 01016 &setchecklist, "set check ", 0, &setlist); 01017 add_alias_cmd ("c", "check", no_class, 1, &setlist); 01018 add_alias_cmd ("ch", "check", no_class, 1, &setlist); 01019 01020 add_prefix_cmd ("check", no_class, show_check, 01021 _("Show the status of the type/range checker."), 01022 &showchecklist, "show check ", 0, &showlist); 01023 add_alias_cmd ("c", "check", no_class, 1, &showlist); 01024 add_alias_cmd ("ch", "check", no_class, 1, &showlist); 01025 01026 add_setshow_enum_cmd ("range", class_support, type_or_range_names, 01027 &range, 01028 _("Set range checking. (on/warn/off/auto)"), 01029 _("Show range checking. (on/warn/off/auto)"), 01030 NULL, set_range_command, 01031 show_range_command, 01032 &setchecklist, &showchecklist); 01033 01034 add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names, 01035 &case_sensitive, _("\ 01036 Set case sensitivity in name search. (on/off/auto)"), _("\ 01037 Show case sensitivity in name search. (on/off/auto)"), _("\ 01038 For Fortran the default is off; for other languages the default is on."), 01039 set_case_command, 01040 show_case_command, 01041 &setlist, &showlist); 01042 01043 add_language (&auto_language_defn); 01044 add_language (&local_language_defn); 01045 add_language (&unknown_language_defn); 01046 01047 language = xstrdup ("auto"); 01048 type = xstrdup ("auto"); 01049 range = xstrdup ("auto"); 01050 case_sensitive = xstrdup ("auto"); 01051 01052 /* Have the above take effect. */ 01053 set_language (language_auto); 01054 }