GDB (API)
|
00001 /* C language support routines for GDB, the GNU debugger. 00002 00003 Copyright (C) 1992-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "symtab.h" 00022 #include "gdbtypes.h" 00023 #include "expression.h" 00024 #include "parser-defs.h" 00025 #include "language.h" 00026 #include "c-lang.h" 00027 #include "valprint.h" 00028 #include "macroscope.h" 00029 #include "gdb_assert.h" 00030 #include "charset.h" 00031 #include "gdb_string.h" 00032 #include "demangle.h" 00033 #include "cp-abi.h" 00034 #include "cp-support.h" 00035 #include "gdb_obstack.h" 00036 #include <ctype.h> 00037 #include "exceptions.h" 00038 #include "gdbcore.h" 00039 00040 extern void _initialize_c_language (void); 00041 00042 /* Given a C string type, STR_TYPE, return the corresponding target 00043 character set name. */ 00044 00045 static const char * 00046 charset_for_string_type (enum c_string_type str_type, 00047 struct gdbarch *gdbarch) 00048 { 00049 switch (str_type & ~C_CHAR) 00050 { 00051 case C_STRING: 00052 return target_charset (gdbarch); 00053 case C_WIDE_STRING: 00054 return target_wide_charset (gdbarch); 00055 case C_STRING_16: 00056 /* FIXME: UTF-16 is not always correct. */ 00057 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 00058 return "UTF-16BE"; 00059 else 00060 return "UTF-16LE"; 00061 case C_STRING_32: 00062 /* FIXME: UTF-32 is not always correct. */ 00063 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 00064 return "UTF-32BE"; 00065 else 00066 return "UTF-32LE"; 00067 } 00068 internal_error (__FILE__, __LINE__, _("unhandled c_string_type")); 00069 } 00070 00071 /* Classify ELTTYPE according to what kind of character it is. Return 00072 the enum constant representing the character type. Also set 00073 *ENCODING to the name of the character set to use when converting 00074 characters of this type in target BYTE_ORDER to the host character 00075 set. */ 00076 00077 static enum c_string_type 00078 classify_type (struct type *elttype, struct gdbarch *gdbarch, 00079 const char **encoding) 00080 { 00081 enum c_string_type result; 00082 00083 /* We loop because ELTTYPE may be a typedef, and we want to 00084 successively peel each typedef until we reach a type we 00085 understand. We don't use CHECK_TYPEDEF because that will strip 00086 all typedefs at once -- but in C, wchar_t is itself a typedef, so 00087 that would do the wrong thing. */ 00088 while (elttype) 00089 { 00090 const char *name = TYPE_NAME (elttype); 00091 00092 if (TYPE_CODE (elttype) == TYPE_CODE_CHAR || !name) 00093 { 00094 result = C_CHAR; 00095 goto done; 00096 } 00097 00098 if (!strcmp (name, "wchar_t")) 00099 { 00100 result = C_WIDE_CHAR; 00101 goto done; 00102 } 00103 00104 if (!strcmp (name, "char16_t")) 00105 { 00106 result = C_CHAR_16; 00107 goto done; 00108 } 00109 00110 if (!strcmp (name, "char32_t")) 00111 { 00112 result = C_CHAR_32; 00113 goto done; 00114 } 00115 00116 if (TYPE_CODE (elttype) != TYPE_CODE_TYPEDEF) 00117 break; 00118 00119 /* Call for side effects. */ 00120 check_typedef (elttype); 00121 00122 if (TYPE_TARGET_TYPE (elttype)) 00123 elttype = TYPE_TARGET_TYPE (elttype); 00124 else 00125 { 00126 /* Perhaps check_typedef did not update the target type. In 00127 this case, force the lookup again and hope it works out. 00128 It never will for C, but it might for C++. */ 00129 CHECK_TYPEDEF (elttype); 00130 } 00131 } 00132 00133 /* Punt. */ 00134 result = C_CHAR; 00135 00136 done: 00137 if (encoding) 00138 *encoding = charset_for_string_type (result, gdbarch); 00139 00140 return result; 00141 } 00142 00143 /* Print the character C on STREAM as part of the contents of a 00144 literal string whose delimiter is QUOTER. Note that that format 00145 for printing characters and strings is language specific. */ 00146 00147 void 00148 c_emit_char (int c, struct type *type, 00149 struct ui_file *stream, int quoter) 00150 { 00151 const char *encoding; 00152 00153 classify_type (type, get_type_arch (type), &encoding); 00154 generic_emit_char (c, type, stream, quoter, encoding); 00155 } 00156 00157 void 00158 c_printchar (int c, struct type *type, struct ui_file *stream) 00159 { 00160 enum c_string_type str_type; 00161 00162 str_type = classify_type (type, get_type_arch (type), NULL); 00163 switch (str_type) 00164 { 00165 case C_CHAR: 00166 break; 00167 case C_WIDE_CHAR: 00168 fputc_filtered ('L', stream); 00169 break; 00170 case C_CHAR_16: 00171 fputc_filtered ('u', stream); 00172 break; 00173 case C_CHAR_32: 00174 fputc_filtered ('U', stream); 00175 break; 00176 } 00177 00178 fputc_filtered ('\'', stream); 00179 LA_EMIT_CHAR (c, type, stream, '\''); 00180 fputc_filtered ('\'', stream); 00181 } 00182 00183 /* Print the character string STRING, printing at most LENGTH 00184 characters. LENGTH is -1 if the string is nul terminated. Each 00185 character is WIDTH bytes long. Printing stops early if the number 00186 hits print_max; repeat counts are printed as appropriate. Print 00187 ellipses at the end if we had to stop before printing LENGTH 00188 characters, or if FORCE_ELLIPSES. */ 00189 00190 void 00191 c_printstr (struct ui_file *stream, struct type *type, 00192 const gdb_byte *string, unsigned int length, 00193 const char *user_encoding, int force_ellipses, 00194 const struct value_print_options *options) 00195 { 00196 enum c_string_type str_type; 00197 const char *type_encoding; 00198 const char *encoding; 00199 00200 str_type = (classify_type (type, get_type_arch (type), &type_encoding) 00201 & ~C_CHAR); 00202 switch (str_type) 00203 { 00204 case C_STRING: 00205 break; 00206 case C_WIDE_STRING: 00207 fputs_filtered ("L", stream); 00208 break; 00209 case C_STRING_16: 00210 fputs_filtered ("u", stream); 00211 break; 00212 case C_STRING_32: 00213 fputs_filtered ("U", stream); 00214 break; 00215 } 00216 00217 encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding; 00218 00219 generic_printstr (stream, type, string, length, encoding, force_ellipses, 00220 '"', 1, options); 00221 } 00222 00223 /* Obtain a C string from the inferior storing it in a newly allocated 00224 buffer in BUFFER, which should be freed by the caller. If the in- 00225 and out-parameter *LENGTH is specified at -1, the string is read 00226 until a null character of the appropriate width is found, otherwise 00227 the string is read to the length of characters specified. The size 00228 of a character is determined by the length of the target type of 00229 the pointer or array. If VALUE is an array with a known length, 00230 the function will not read past the end of the array. On 00231 completion, *LENGTH will be set to the size of the string read in 00232 characters. (If a length of -1 is specified, the length returned 00233 will not include the null character). CHARSET is always set to the 00234 target charset. */ 00235 00236 void 00237 c_get_string (struct value *value, gdb_byte **buffer, 00238 int *length, struct type **char_type, 00239 const char **charset) 00240 { 00241 int err, width; 00242 unsigned int fetchlimit; 00243 struct type *type = check_typedef (value_type (value)); 00244 struct type *element_type = TYPE_TARGET_TYPE (type); 00245 int req_length = *length; 00246 enum bfd_endian byte_order 00247 = gdbarch_byte_order (get_type_arch (type)); 00248 00249 if (element_type == NULL) 00250 goto error; 00251 00252 if (TYPE_CODE (type) == TYPE_CODE_ARRAY) 00253 { 00254 /* If we know the size of the array, we can use it as a limit on 00255 the number of characters to be fetched. */ 00256 if (TYPE_NFIELDS (type) == 1 00257 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE) 00258 { 00259 LONGEST low_bound, high_bound; 00260 00261 get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), 00262 &low_bound, &high_bound); 00263 fetchlimit = high_bound - low_bound + 1; 00264 } 00265 else 00266 fetchlimit = UINT_MAX; 00267 } 00268 else if (TYPE_CODE (type) == TYPE_CODE_PTR) 00269 fetchlimit = UINT_MAX; 00270 else 00271 /* We work only with arrays and pointers. */ 00272 goto error; 00273 00274 if (! c_textual_element_type (element_type, 0)) 00275 goto error; 00276 classify_type (element_type, get_type_arch (element_type), charset); 00277 width = TYPE_LENGTH (element_type); 00278 00279 /* If the string lives in GDB's memory instead of the inferior's, 00280 then we just need to copy it to BUFFER. Also, since such strings 00281 are arrays with known size, FETCHLIMIT will hold the size of the 00282 array. */ 00283 if ((VALUE_LVAL (value) == not_lval 00284 || VALUE_LVAL (value) == lval_internalvar) 00285 && fetchlimit != UINT_MAX) 00286 { 00287 int i; 00288 const gdb_byte *contents = value_contents (value); 00289 00290 /* If a length is specified, use that. */ 00291 if (*length >= 0) 00292 i = *length; 00293 else 00294 /* Otherwise, look for a null character. */ 00295 for (i = 0; i < fetchlimit; i++) 00296 if (extract_unsigned_integer (contents + i * width, 00297 width, byte_order) == 0) 00298 break; 00299 00300 /* I is now either a user-defined length, the number of non-null 00301 characters, or FETCHLIMIT. */ 00302 *length = i * width; 00303 *buffer = xmalloc (*length); 00304 memcpy (*buffer, contents, *length); 00305 err = 0; 00306 } 00307 else 00308 { 00309 CORE_ADDR addr = value_as_address (value); 00310 00311 err = read_string (addr, *length, width, fetchlimit, 00312 byte_order, buffer, length); 00313 if (err) 00314 { 00315 xfree (*buffer); 00316 memory_error (err, addr); 00317 } 00318 } 00319 00320 /* If the LENGTH is specified at -1, we want to return the string 00321 length up to the terminating null character. If an actual length 00322 was specified, we want to return the length of exactly what was 00323 read. */ 00324 if (req_length == -1) 00325 /* If the last character is null, subtract it from LENGTH. */ 00326 if (*length > 0 00327 && extract_unsigned_integer (*buffer + *length - width, 00328 width, byte_order) == 0) 00329 *length -= width; 00330 00331 /* The read_string function will return the number of bytes read. 00332 If length returned from read_string was > 0, return the number of 00333 characters read by dividing the number of bytes by width. */ 00334 if (*length != 0) 00335 *length = *length / width; 00336 00337 *char_type = element_type; 00338 00339 return; 00340 00341 error: 00342 { 00343 char *type_str; 00344 00345 type_str = type_to_string (type); 00346 if (type_str) 00347 { 00348 make_cleanup (xfree, type_str); 00349 error (_("Trying to read string with inappropriate type `%s'."), 00350 type_str); 00351 } 00352 else 00353 error (_("Trying to read string with inappropriate type.")); 00354 } 00355 } 00356 00357 00358 /* Evaluating C and C++ expressions. */ 00359 00360 /* Convert a UCN. The digits of the UCN start at P and extend no 00361 farther than LIMIT. DEST_CHARSET is the name of the character set 00362 into which the UCN should be converted. The results are written to 00363 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8. 00364 Returns a pointer to just after the final digit of the UCN. */ 00365 00366 static char * 00367 convert_ucn (char *p, char *limit, const char *dest_charset, 00368 struct obstack *output, int length) 00369 { 00370 unsigned long result = 0; 00371 gdb_byte data[4]; 00372 int i; 00373 00374 for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p) 00375 result = (result << 4) + host_hex_value (*p); 00376 00377 for (i = 3; i >= 0; --i) 00378 { 00379 data[i] = result & 0xff; 00380 result >>= 8; 00381 } 00382 00383 convert_between_encodings ("UTF-32BE", dest_charset, data, 00384 4, 4, output, translit_none); 00385 00386 return p; 00387 } 00388 00389 /* Emit a character, VALUE, which was specified numerically, to 00390 OUTPUT. TYPE is the target character type. */ 00391 00392 static void 00393 emit_numeric_character (struct type *type, unsigned long value, 00394 struct obstack *output) 00395 { 00396 gdb_byte *buffer; 00397 00398 buffer = alloca (TYPE_LENGTH (type)); 00399 pack_long (buffer, type, value); 00400 obstack_grow (output, buffer, TYPE_LENGTH (type)); 00401 } 00402 00403 /* Convert an octal escape sequence. TYPE is the target character 00404 type. The digits of the escape sequence begin at P and extend no 00405 farther than LIMIT. The result is written to OUTPUT. Returns a 00406 pointer to just after the final digit of the escape sequence. */ 00407 00408 static char * 00409 convert_octal (struct type *type, char *p, 00410 char *limit, struct obstack *output) 00411 { 00412 int i; 00413 unsigned long value = 0; 00414 00415 for (i = 0; 00416 i < 3 && p < limit && isdigit (*p) && *p != '8' && *p != '9'; 00417 ++i) 00418 { 00419 value = 8 * value + host_hex_value (*p); 00420 ++p; 00421 } 00422 00423 emit_numeric_character (type, value, output); 00424 00425 return p; 00426 } 00427 00428 /* Convert a hex escape sequence. TYPE is the target character type. 00429 The digits of the escape sequence begin at P and extend no farther 00430 than LIMIT. The result is written to OUTPUT. Returns a pointer to 00431 just after the final digit of the escape sequence. */ 00432 00433 static char * 00434 convert_hex (struct type *type, char *p, 00435 char *limit, struct obstack *output) 00436 { 00437 unsigned long value = 0; 00438 00439 while (p < limit && isxdigit (*p)) 00440 { 00441 value = 16 * value + host_hex_value (*p); 00442 ++p; 00443 } 00444 00445 emit_numeric_character (type, value, output); 00446 00447 return p; 00448 } 00449 00450 #define ADVANCE \ 00451 do { \ 00452 ++p; \ 00453 if (p == limit) \ 00454 error (_("Malformed escape sequence")); \ 00455 } while (0) 00456 00457 /* Convert an escape sequence to a target format. TYPE is the target 00458 character type to use, and DEST_CHARSET is the name of the target 00459 character set. The backslash of the escape sequence is at *P, and 00460 the escape sequence will not extend past LIMIT. The results are 00461 written to OUTPUT. Returns a pointer to just past the final 00462 character of the escape sequence. */ 00463 00464 static char * 00465 convert_escape (struct type *type, const char *dest_charset, 00466 char *p, char *limit, struct obstack *output) 00467 { 00468 /* Skip the backslash. */ 00469 ADVANCE; 00470 00471 switch (*p) 00472 { 00473 case '\\': 00474 obstack_1grow (output, '\\'); 00475 ++p; 00476 break; 00477 00478 case 'x': 00479 ADVANCE; 00480 if (!isxdigit (*p)) 00481 error (_("\\x used with no following hex digits.")); 00482 p = convert_hex (type, p, limit, output); 00483 break; 00484 00485 case '0': 00486 case '1': 00487 case '2': 00488 case '3': 00489 case '4': 00490 case '5': 00491 case '6': 00492 case '7': 00493 p = convert_octal (type, p, limit, output); 00494 break; 00495 00496 case 'u': 00497 case 'U': 00498 { 00499 int length = *p == 'u' ? 4 : 8; 00500 00501 ADVANCE; 00502 if (!isxdigit (*p)) 00503 error (_("\\u used with no following hex digits")); 00504 p = convert_ucn (p, limit, dest_charset, output, length); 00505 } 00506 } 00507 00508 return p; 00509 } 00510 00511 /* Given a single string from a (C-specific) OP_STRING list, convert 00512 it to a target string, handling escape sequences specially. The 00513 output is written to OUTPUT. DATA is the input string, which has 00514 length LEN. DEST_CHARSET is the name of the target character set, 00515 and TYPE is the type of target character to use. */ 00516 00517 static void 00518 parse_one_string (struct obstack *output, char *data, int len, 00519 const char *dest_charset, struct type *type) 00520 { 00521 char *limit; 00522 00523 limit = data + len; 00524 00525 while (data < limit) 00526 { 00527 char *p = data; 00528 00529 /* Look for next escape, or the end of the input. */ 00530 while (p < limit && *p != '\\') 00531 ++p; 00532 /* If we saw a run of characters, convert them all. */ 00533 if (p > data) 00534 convert_between_encodings (host_charset (), dest_charset, 00535 (gdb_byte *) data, p - data, 1, 00536 output, translit_none); 00537 /* If we saw an escape, convert it. */ 00538 if (p < limit) 00539 p = convert_escape (type, dest_charset, p, limit, output); 00540 data = p; 00541 } 00542 } 00543 00544 /* Expression evaluator for the C language family. Most operations 00545 are delegated to evaluate_subexp_standard; see that function for a 00546 description of the arguments. */ 00547 00548 struct value * 00549 evaluate_subexp_c (struct type *expect_type, struct expression *exp, 00550 int *pos, enum noside noside) 00551 { 00552 enum exp_opcode op = exp->elts[*pos].opcode; 00553 00554 switch (op) 00555 { 00556 case OP_STRING: 00557 { 00558 int oplen, limit; 00559 struct type *type; 00560 struct obstack output; 00561 struct cleanup *cleanup; 00562 struct value *result; 00563 enum c_string_type dest_type; 00564 const char *dest_charset; 00565 int satisfy_expected = 0; 00566 00567 obstack_init (&output); 00568 cleanup = make_cleanup_obstack_free (&output); 00569 00570 ++*pos; 00571 oplen = longest_to_int (exp->elts[*pos].longconst); 00572 00573 ++*pos; 00574 limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1); 00575 dest_type 00576 = (enum c_string_type) longest_to_int (exp->elts[*pos].longconst); 00577 switch (dest_type & ~C_CHAR) 00578 { 00579 case C_STRING: 00580 type = language_string_char_type (exp->language_defn, 00581 exp->gdbarch); 00582 break; 00583 case C_WIDE_STRING: 00584 type = lookup_typename (exp->language_defn, exp->gdbarch, 00585 "wchar_t", NULL, 0); 00586 break; 00587 case C_STRING_16: 00588 type = lookup_typename (exp->language_defn, exp->gdbarch, 00589 "char16_t", NULL, 0); 00590 break; 00591 case C_STRING_32: 00592 type = lookup_typename (exp->language_defn, exp->gdbarch, 00593 "char32_t", NULL, 0); 00594 break; 00595 default: 00596 internal_error (__FILE__, __LINE__, _("unhandled c_string_type")); 00597 } 00598 00599 /* Ensure TYPE_LENGTH is valid for TYPE. */ 00600 check_typedef (type); 00601 00602 /* If the caller expects an array of some integral type, 00603 satisfy them. If something odder is expected, rely on the 00604 caller to cast. */ 00605 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_ARRAY) 00606 { 00607 struct type *element_type 00608 = check_typedef (TYPE_TARGET_TYPE (expect_type)); 00609 00610 if (TYPE_CODE (element_type) == TYPE_CODE_INT 00611 || TYPE_CODE (element_type) == TYPE_CODE_CHAR) 00612 { 00613 type = element_type; 00614 satisfy_expected = 1; 00615 } 00616 } 00617 00618 dest_charset = charset_for_string_type (dest_type, exp->gdbarch); 00619 00620 ++*pos; 00621 while (*pos < limit) 00622 { 00623 int len; 00624 00625 len = longest_to_int (exp->elts[*pos].longconst); 00626 00627 ++*pos; 00628 if (noside != EVAL_SKIP) 00629 parse_one_string (&output, &exp->elts[*pos].string, len, 00630 dest_charset, type); 00631 *pos += BYTES_TO_EXP_ELEM (len); 00632 } 00633 00634 /* Skip the trailing length and opcode. */ 00635 *pos += 2; 00636 00637 if (noside == EVAL_SKIP) 00638 { 00639 /* Return a dummy value of the appropriate type. */ 00640 if (expect_type != NULL) 00641 result = allocate_value (expect_type); 00642 else if ((dest_type & C_CHAR) != 0) 00643 result = allocate_value (type); 00644 else 00645 result = value_cstring ("", 0, type); 00646 do_cleanups (cleanup); 00647 return result; 00648 } 00649 00650 if ((dest_type & C_CHAR) != 0) 00651 { 00652 LONGEST value; 00653 00654 if (obstack_object_size (&output) != TYPE_LENGTH (type)) 00655 error (_("Could not convert character " 00656 "constant to target character set")); 00657 value = unpack_long (type, (gdb_byte *) obstack_base (&output)); 00658 result = value_from_longest (type, value); 00659 } 00660 else 00661 { 00662 int i; 00663 00664 /* Write the terminating character. */ 00665 for (i = 0; i < TYPE_LENGTH (type); ++i) 00666 obstack_1grow (&output, 0); 00667 00668 if (satisfy_expected) 00669 { 00670 LONGEST low_bound, high_bound; 00671 int element_size = TYPE_LENGTH (type); 00672 00673 if (get_discrete_bounds (TYPE_INDEX_TYPE (expect_type), 00674 &low_bound, &high_bound) < 0) 00675 { 00676 low_bound = 0; 00677 high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1; 00678 } 00679 if (obstack_object_size (&output) / element_size 00680 > (high_bound - low_bound + 1)) 00681 error (_("Too many array elements")); 00682 00683 result = allocate_value (expect_type); 00684 memcpy (value_contents_raw (result), obstack_base (&output), 00685 obstack_object_size (&output)); 00686 } 00687 else 00688 result = value_cstring (obstack_base (&output), 00689 obstack_object_size (&output), 00690 type); 00691 } 00692 do_cleanups (cleanup); 00693 return result; 00694 } 00695 break; 00696 00697 default: 00698 break; 00699 } 00700 return evaluate_subexp_standard (expect_type, exp, pos, noside); 00701 } 00702 00703 00704 00705 /* Table mapping opcodes into strings for printing operators 00706 and precedences of the operators. */ 00707 00708 const struct op_print c_op_print_tab[] = 00709 { 00710 {",", BINOP_COMMA, PREC_COMMA, 0}, 00711 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1}, 00712 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, 00713 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, 00714 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0}, 00715 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0}, 00716 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0}, 00717 {"==", BINOP_EQUAL, PREC_EQUAL, 0}, 00718 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, 00719 {"<=", BINOP_LEQ, PREC_ORDER, 0}, 00720 {">=", BINOP_GEQ, PREC_ORDER, 0}, 00721 {">", BINOP_GTR, PREC_ORDER, 0}, 00722 {"<", BINOP_LESS, PREC_ORDER, 0}, 00723 {">>", BINOP_RSH, PREC_SHIFT, 0}, 00724 {"<<", BINOP_LSH, PREC_SHIFT, 0}, 00725 {"+", BINOP_ADD, PREC_ADD, 0}, 00726 {"-", BINOP_SUB, PREC_ADD, 0}, 00727 {"*", BINOP_MUL, PREC_MUL, 0}, 00728 {"/", BINOP_DIV, PREC_MUL, 0}, 00729 {"%", BINOP_REM, PREC_MUL, 0}, 00730 {"@", BINOP_REPEAT, PREC_REPEAT, 0}, 00731 {"+", UNOP_PLUS, PREC_PREFIX, 0}, 00732 {"-", UNOP_NEG, PREC_PREFIX, 0}, 00733 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, 00734 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0}, 00735 {"*", UNOP_IND, PREC_PREFIX, 0}, 00736 {"&", UNOP_ADDR, PREC_PREFIX, 0}, 00737 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0}, 00738 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0}, 00739 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0}, 00740 {NULL, 0, 0, 0} 00741 }; 00742 00743 enum c_primitive_types { 00744 c_primitive_type_int, 00745 c_primitive_type_long, 00746 c_primitive_type_short, 00747 c_primitive_type_char, 00748 c_primitive_type_float, 00749 c_primitive_type_double, 00750 c_primitive_type_void, 00751 c_primitive_type_long_long, 00752 c_primitive_type_signed_char, 00753 c_primitive_type_unsigned_char, 00754 c_primitive_type_unsigned_short, 00755 c_primitive_type_unsigned_int, 00756 c_primitive_type_unsigned_long, 00757 c_primitive_type_unsigned_long_long, 00758 c_primitive_type_long_double, 00759 c_primitive_type_complex, 00760 c_primitive_type_double_complex, 00761 c_primitive_type_decfloat, 00762 c_primitive_type_decdouble, 00763 c_primitive_type_declong, 00764 nr_c_primitive_types 00765 }; 00766 00767 void 00768 c_language_arch_info (struct gdbarch *gdbarch, 00769 struct language_arch_info *lai) 00770 { 00771 const struct builtin_type *builtin = builtin_type (gdbarch); 00772 00773 lai->string_char_type = builtin->builtin_char; 00774 lai->primitive_type_vector 00775 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1, 00776 struct type *); 00777 lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int; 00778 lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long; 00779 lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short; 00780 lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char; 00781 lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float; 00782 lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double; 00783 lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void; 00784 lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long; 00785 lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char; 00786 lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char; 00787 lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short; 00788 lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int; 00789 lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long; 00790 lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long; 00791 lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double; 00792 lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex; 00793 lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex; 00794 lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat; 00795 lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble; 00796 lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong; 00797 00798 lai->bool_type_default = builtin->builtin_int; 00799 } 00800 00801 const struct exp_descriptor exp_descriptor_c = 00802 { 00803 print_subexp_standard, 00804 operator_length_standard, 00805 operator_check_standard, 00806 op_name_standard, 00807 dump_subexp_body_standard, 00808 evaluate_subexp_c 00809 }; 00810 00811 const struct language_defn c_language_defn = 00812 { 00813 "c", /* Language name */ 00814 language_c, 00815 range_check_off, 00816 case_sensitive_on, 00817 array_row_major, 00818 macro_expansion_c, 00819 &exp_descriptor_c, 00820 c_parse, 00821 c_error, 00822 null_post_parser, 00823 c_printchar, /* Print a character constant */ 00824 c_printstr, /* Function to print string constant */ 00825 c_emit_char, /* Print a single char */ 00826 c_print_type, /* Print a type using appropriate syntax */ 00827 c_print_typedef, /* Print a typedef using appropriate syntax */ 00828 c_val_print, /* Print a value using appropriate syntax */ 00829 c_value_print, /* Print a top-level value */ 00830 default_read_var_value, /* la_read_var_value */ 00831 NULL, /* Language specific skip_trampoline */ 00832 NULL, /* name_of_this */ 00833 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 00834 basic_lookup_transparent_type,/* lookup_transparent_type */ 00835 NULL, /* Language specific symbol demangler */ 00836 NULL, /* Language specific 00837 class_name_from_physname */ 00838 c_op_print_tab, /* expression operators for printing */ 00839 1, /* c-style arrays */ 00840 0, /* String lower bound */ 00841 default_word_break_characters, 00842 default_make_symbol_completion_list, 00843 c_language_arch_info, 00844 default_print_array_index, 00845 default_pass_by_reference, 00846 c_get_string, 00847 NULL, /* la_get_symbol_name_cmp */ 00848 iterate_over_symbols, 00849 LANG_MAGIC 00850 }; 00851 00852 enum cplus_primitive_types { 00853 cplus_primitive_type_int, 00854 cplus_primitive_type_long, 00855 cplus_primitive_type_short, 00856 cplus_primitive_type_char, 00857 cplus_primitive_type_float, 00858 cplus_primitive_type_double, 00859 cplus_primitive_type_void, 00860 cplus_primitive_type_long_long, 00861 cplus_primitive_type_signed_char, 00862 cplus_primitive_type_unsigned_char, 00863 cplus_primitive_type_unsigned_short, 00864 cplus_primitive_type_unsigned_int, 00865 cplus_primitive_type_unsigned_long, 00866 cplus_primitive_type_unsigned_long_long, 00867 cplus_primitive_type_long_double, 00868 cplus_primitive_type_complex, 00869 cplus_primitive_type_double_complex, 00870 cplus_primitive_type_bool, 00871 cplus_primitive_type_decfloat, 00872 cplus_primitive_type_decdouble, 00873 cplus_primitive_type_declong, 00874 nr_cplus_primitive_types 00875 }; 00876 00877 static void 00878 cplus_language_arch_info (struct gdbarch *gdbarch, 00879 struct language_arch_info *lai) 00880 { 00881 const struct builtin_type *builtin = builtin_type (gdbarch); 00882 00883 lai->string_char_type = builtin->builtin_char; 00884 lai->primitive_type_vector 00885 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1, 00886 struct type *); 00887 lai->primitive_type_vector [cplus_primitive_type_int] 00888 = builtin->builtin_int; 00889 lai->primitive_type_vector [cplus_primitive_type_long] 00890 = builtin->builtin_long; 00891 lai->primitive_type_vector [cplus_primitive_type_short] 00892 = builtin->builtin_short; 00893 lai->primitive_type_vector [cplus_primitive_type_char] 00894 = builtin->builtin_char; 00895 lai->primitive_type_vector [cplus_primitive_type_float] 00896 = builtin->builtin_float; 00897 lai->primitive_type_vector [cplus_primitive_type_double] 00898 = builtin->builtin_double; 00899 lai->primitive_type_vector [cplus_primitive_type_void] 00900 = builtin->builtin_void; 00901 lai->primitive_type_vector [cplus_primitive_type_long_long] 00902 = builtin->builtin_long_long; 00903 lai->primitive_type_vector [cplus_primitive_type_signed_char] 00904 = builtin->builtin_signed_char; 00905 lai->primitive_type_vector [cplus_primitive_type_unsigned_char] 00906 = builtin->builtin_unsigned_char; 00907 lai->primitive_type_vector [cplus_primitive_type_unsigned_short] 00908 = builtin->builtin_unsigned_short; 00909 lai->primitive_type_vector [cplus_primitive_type_unsigned_int] 00910 = builtin->builtin_unsigned_int; 00911 lai->primitive_type_vector [cplus_primitive_type_unsigned_long] 00912 = builtin->builtin_unsigned_long; 00913 lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long] 00914 = builtin->builtin_unsigned_long_long; 00915 lai->primitive_type_vector [cplus_primitive_type_long_double] 00916 = builtin->builtin_long_double; 00917 lai->primitive_type_vector [cplus_primitive_type_complex] 00918 = builtin->builtin_complex; 00919 lai->primitive_type_vector [cplus_primitive_type_double_complex] 00920 = builtin->builtin_double_complex; 00921 lai->primitive_type_vector [cplus_primitive_type_bool] 00922 = builtin->builtin_bool; 00923 lai->primitive_type_vector [cplus_primitive_type_decfloat] 00924 = builtin->builtin_decfloat; 00925 lai->primitive_type_vector [cplus_primitive_type_decdouble] 00926 = builtin->builtin_decdouble; 00927 lai->primitive_type_vector [cplus_primitive_type_declong] 00928 = builtin->builtin_declong; 00929 00930 lai->bool_type_symbol = "bool"; 00931 lai->bool_type_default = builtin->builtin_bool; 00932 } 00933 00934 const struct language_defn cplus_language_defn = 00935 { 00936 "c++", /* Language name */ 00937 language_cplus, 00938 range_check_off, 00939 case_sensitive_on, 00940 array_row_major, 00941 macro_expansion_c, 00942 &exp_descriptor_c, 00943 c_parse, 00944 c_error, 00945 null_post_parser, 00946 c_printchar, /* Print a character constant */ 00947 c_printstr, /* Function to print string constant */ 00948 c_emit_char, /* Print a single char */ 00949 c_print_type, /* Print a type using appropriate syntax */ 00950 c_print_typedef, /* Print a typedef using appropriate syntax */ 00951 c_val_print, /* Print a value using appropriate syntax */ 00952 c_value_print, /* Print a top-level value */ 00953 default_read_var_value, /* la_read_var_value */ 00954 cplus_skip_trampoline, /* Language specific skip_trampoline */ 00955 "this", /* name_of_this */ 00956 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 00957 cp_lookup_transparent_type, /* lookup_transparent_type */ 00958 gdb_demangle, /* Language specific symbol demangler */ 00959 cp_class_name_from_physname, /* Language specific 00960 class_name_from_physname */ 00961 c_op_print_tab, /* expression operators for printing */ 00962 1, /* c-style arrays */ 00963 0, /* String lower bound */ 00964 default_word_break_characters, 00965 default_make_symbol_completion_list, 00966 cplus_language_arch_info, 00967 default_print_array_index, 00968 cp_pass_by_reference, 00969 c_get_string, 00970 NULL, /* la_get_symbol_name_cmp */ 00971 iterate_over_symbols, 00972 LANG_MAGIC 00973 }; 00974 00975 const struct language_defn asm_language_defn = 00976 { 00977 "asm", /* Language name */ 00978 language_asm, 00979 range_check_off, 00980 case_sensitive_on, 00981 array_row_major, 00982 macro_expansion_c, 00983 &exp_descriptor_c, 00984 c_parse, 00985 c_error, 00986 null_post_parser, 00987 c_printchar, /* Print a character constant */ 00988 c_printstr, /* Function to print string constant */ 00989 c_emit_char, /* Print a single char */ 00990 c_print_type, /* Print a type using appropriate syntax */ 00991 c_print_typedef, /* Print a typedef using appropriate syntax */ 00992 c_val_print, /* Print a value using appropriate syntax */ 00993 c_value_print, /* Print a top-level value */ 00994 default_read_var_value, /* la_read_var_value */ 00995 NULL, /* Language specific skip_trampoline */ 00996 NULL, /* name_of_this */ 00997 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 00998 basic_lookup_transparent_type,/* lookup_transparent_type */ 00999 NULL, /* Language specific symbol demangler */ 01000 NULL, /* Language specific 01001 class_name_from_physname */ 01002 c_op_print_tab, /* expression operators for printing */ 01003 1, /* c-style arrays */ 01004 0, /* String lower bound */ 01005 default_word_break_characters, 01006 default_make_symbol_completion_list, 01007 c_language_arch_info, /* FIXME: la_language_arch_info. */ 01008 default_print_array_index, 01009 default_pass_by_reference, 01010 c_get_string, 01011 NULL, /* la_get_symbol_name_cmp */ 01012 iterate_over_symbols, 01013 LANG_MAGIC 01014 }; 01015 01016 /* The following language_defn does not represent a real language. 01017 It just provides a minimal support a-la-C that should allow users 01018 to do some simple operations when debugging applications that use 01019 a language currently not supported by GDB. */ 01020 01021 const struct language_defn minimal_language_defn = 01022 { 01023 "minimal", /* Language name */ 01024 language_minimal, 01025 range_check_off, 01026 case_sensitive_on, 01027 array_row_major, 01028 macro_expansion_c, 01029 &exp_descriptor_c, 01030 c_parse, 01031 c_error, 01032 null_post_parser, 01033 c_printchar, /* Print a character constant */ 01034 c_printstr, /* Function to print string constant */ 01035 c_emit_char, /* Print a single char */ 01036 c_print_type, /* Print a type using appropriate syntax */ 01037 c_print_typedef, /* Print a typedef using appropriate syntax */ 01038 c_val_print, /* Print a value using appropriate syntax */ 01039 c_value_print, /* Print a top-level value */ 01040 default_read_var_value, /* la_read_var_value */ 01041 NULL, /* Language specific skip_trampoline */ 01042 NULL, /* name_of_this */ 01043 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 01044 basic_lookup_transparent_type,/* lookup_transparent_type */ 01045 NULL, /* Language specific symbol demangler */ 01046 NULL, /* Language specific 01047 class_name_from_physname */ 01048 c_op_print_tab, /* expression operators for printing */ 01049 1, /* c-style arrays */ 01050 0, /* String lower bound */ 01051 default_word_break_characters, 01052 default_make_symbol_completion_list, 01053 c_language_arch_info, 01054 default_print_array_index, 01055 default_pass_by_reference, 01056 c_get_string, 01057 NULL, /* la_get_symbol_name_cmp */ 01058 iterate_over_symbols, 01059 LANG_MAGIC 01060 }; 01061 01062 void 01063 _initialize_c_language (void) 01064 { 01065 add_language (&c_language_defn); 01066 add_language (&cplus_language_defn); 01067 add_language (&asm_language_defn); 01068 add_language (&minimal_language_defn); 01069 }