1 /* C language support routines for GDB, the GNU debugger.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003,
4 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
25 #include "parser-defs.h"
29 #include "macroscope.h"
30 #include "gdb_assert.h"
32 #include "gdb_string.h"
35 #include "cp-support.h"
36 #include "gdb_obstack.h"
39 extern void _initialize_c_language (void);
41 /* Given a C string type, STR_TYPE, return the corresponding target
42 character set name. */
45 charset_for_string_type (enum c_string_type str_type,
46 enum bfd_endian byte_order)
48 switch (str_type & ~C_CHAR)
51 return target_charset ();
53 return target_wide_charset (byte_order);
55 /* FIXME: UCS-2 is not always correct. */
56 if (byte_order == BFD_ENDIAN_BIG)
61 /* FIXME: UCS-4 is not always correct. */
62 if (byte_order == BFD_ENDIAN_BIG)
67 internal_error (__FILE__, __LINE__, "unhandled c_string_type");
70 /* Classify ELTTYPE according to what kind of character it is. Return
71 the enum constant representing the character type. Also set
72 *ENCODING to the name of the character set to use when converting
73 characters of this type in target BYTE_ORDER to the host character set. */
75 static enum c_string_type
76 classify_type (struct type *elttype, enum bfd_endian byte_order,
77 const char **encoding)
79 struct type *saved_type;
80 enum c_string_type result;
82 /* We loop because ELTTYPE may be a typedef, and we want to
83 successively peel each typedef until we reach a type we
84 understand. We don't use CHECK_TYPEDEF because that will strip
85 all typedefs at once -- but in C, wchar_t is itself a typedef, so
86 that would do the wrong thing. */
89 char *name = TYPE_NAME (elttype);
91 if (TYPE_CODE (elttype) == TYPE_CODE_CHAR || !name)
97 if (!strcmp (name, "wchar_t"))
103 if (!strcmp (name, "char16_t"))
109 if (!strcmp (name, "char32_t"))
115 if (TYPE_CODE (elttype) != TYPE_CODE_TYPEDEF)
118 /* Call for side effects. */
119 check_typedef (elttype);
121 if (TYPE_TARGET_TYPE (elttype))
122 elttype = TYPE_TARGET_TYPE (elttype);
125 /* Perhaps check_typedef did not update the target type. In
126 this case, force the lookup again and hope it works out.
127 It never will for C, but it might for C++. */
128 CHECK_TYPEDEF (elttype);
137 *encoding = charset_for_string_type (result, byte_order);
142 /* Return true if print_wchar can display W without resorting to a
143 numeric escape, false otherwise. */
146 wchar_printable (gdb_wchar_t w)
148 return (gdb_iswprint (w)
149 || w == LCST ('\a') || w == LCST ('\b')
150 || w == LCST ('\f') || w == LCST ('\n')
151 || w == LCST ('\r') || w == LCST ('\t')
152 || w == LCST ('\v'));
155 /* A helper function that converts the contents of STRING to wide
156 characters and then appends them to OUTPUT. */
159 append_string_as_wide (const char *string, struct obstack *output)
161 for (; *string; ++string)
163 gdb_wchar_t w = gdb_btowc (*string);
164 obstack_grow (output, &w, sizeof (gdb_wchar_t));
168 /* Print a wide character W to OUTPUT. ORIG is a pointer to the
169 original (target) bytes representing the character, ORIG_LEN is the
170 number of valid bytes. WIDTH is the number of bytes in a base
171 characters of the type. OUTPUT is an obstack to which wide
172 characters are emitted. QUOTER is a (narrow) character indicating
173 the style of quotes surrounding the character to be printed.
174 NEED_ESCAPE is an in/out flag which is used to track numeric
175 escapes across calls. */
178 print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len,
179 int width, enum bfd_endian byte_order, struct obstack *output,
180 int quoter, int *need_escapep)
182 int need_escape = *need_escapep;
184 if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
186 && w != LCST ('9'))))
188 gdb_wchar_t wchar = w;
190 if (w == gdb_btowc (quoter) || w == LCST ('\\'))
191 obstack_grow_wstr (output, LCST ("\\"));
192 obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
199 obstack_grow_wstr (output, LCST ("\\a"));
202 obstack_grow_wstr (output, LCST ("\\b"));
205 obstack_grow_wstr (output, LCST ("\\f"));
208 obstack_grow_wstr (output, LCST ("\\n"));
211 obstack_grow_wstr (output, LCST ("\\r"));
214 obstack_grow_wstr (output, LCST ("\\t"));
217 obstack_grow_wstr (output, LCST ("\\v"));
223 for (i = 0; i + width <= orig_len; i += width)
227 value = extract_unsigned_integer (&orig[i], width, byte_order);
228 sprintf (octal, "\\%lo", (long) value);
229 append_string_as_wide (octal, output);
231 /* If we somehow have extra bytes, print them now. */
235 sprintf (octal, "\\%.3o", orig[i] & 0xff);
236 append_string_as_wide (octal, output);
247 /* Print the character C on STREAM as part of the contents of a literal
248 string whose delimiter is QUOTER. Note that that format for printing
249 characters and strings is language specific. */
252 c_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
254 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
255 struct obstack wchar_buf, output;
256 struct cleanup *cleanups;
257 const char *encoding;
259 struct wchar_iterator *iter;
262 classify_type (type, byte_order, &encoding);
264 buf = alloca (TYPE_LENGTH (type));
265 pack_long (buf, type, c);
267 iter = make_wchar_iterator (buf, TYPE_LENGTH (type), encoding,
269 cleanups = make_cleanup_wchar_iterator (iter);
271 /* This holds the printable form of the wchar_t data. */
272 obstack_init (&wchar_buf);
273 make_cleanup_obstack_free (&wchar_buf);
281 int print_escape = 1;
282 enum wchar_iterate_result result;
284 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
289 /* If all characters are printable, print them. Otherwise,
290 we're going to have to print an escape sequence. We
291 check all characters because we want to print the target
292 bytes in the escape sequence, and we don't know character
297 for (i = 0; i < num_chars; ++i)
298 if (!wchar_printable (chars[i]))
306 for (i = 0; i < num_chars; ++i)
307 print_wchar (chars[i], buf, buflen, TYPE_LENGTH (type),
308 byte_order, &wchar_buf, quoter, &need_escape);
312 /* This handles the NUM_CHARS == 0 case as well. */
314 print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type), byte_order,
315 &wchar_buf, quoter, &need_escape);
318 /* The output in the host encoding. */
319 obstack_init (&output);
320 make_cleanup_obstack_free (&output);
322 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
323 obstack_base (&wchar_buf),
324 obstack_object_size (&wchar_buf),
325 1, &output, translit_char);
326 obstack_1grow (&output, '\0');
328 fputs_filtered (obstack_base (&output), stream);
330 do_cleanups (cleanups);
334 c_printchar (int c, struct type *type, struct ui_file *stream)
336 enum c_string_type str_type;
338 str_type = classify_type (type, BFD_ENDIAN_UNKNOWN, NULL);
344 fputc_filtered ('L', stream);
347 fputc_filtered ('u', stream);
350 fputc_filtered ('U', stream);
354 fputc_filtered ('\'', stream);
355 LA_EMIT_CHAR (c, type, stream, '\'');
356 fputc_filtered ('\'', stream);
359 /* Print the character string STRING, printing at most LENGTH characters.
360 LENGTH is -1 if the string is nul terminated. Each character is WIDTH bytes
361 long. Printing stops early if the number hits print_max; repeat counts are
362 printed as appropriate. Print ellipses at the end if we had to stop before
363 printing LENGTH characters, or if FORCE_ELLIPSES. */
366 c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
367 unsigned int length, int force_ellipses,
368 const struct value_print_options *options)
370 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
372 unsigned int things_printed = 0;
375 int width = TYPE_LENGTH (type);
376 struct obstack wchar_buf, output;
377 struct cleanup *cleanup;
378 enum c_string_type str_type;
379 const char *encoding;
380 struct wchar_iterator *iter;
384 /* If the string was not truncated due to `set print elements', and
385 the last byte of it is a null, we don't print that, in traditional C
389 && (extract_unsigned_integer (string + (length - 1) * width,
390 width, byte_order) == 0))
393 str_type = classify_type (type, byte_order, &encoding) & ~C_CHAR;
399 fputs_filtered ("L", stream);
402 fputs_filtered ("u", stream);
405 fputs_filtered ("U", stream);
411 fputs_filtered ("\"\"", stream);
417 unsigned long current_char = 1;
418 for (i = 0; current_char; ++i)
421 current_char = extract_unsigned_integer (string + i * width,
427 /* Arrange to iterate over the characters, in wchar_t form. */
428 iter = make_wchar_iterator (string, length * width, encoding, width);
429 cleanup = make_cleanup_wchar_iterator (iter);
431 /* WCHAR_BUF is the obstack we use to represent the string in
433 obstack_init (&wchar_buf);
434 make_cleanup_obstack_free (&wchar_buf);
436 while (!finished && things_printed < options->print_max)
439 enum wchar_iterate_result result;
448 obstack_grow_wstr (&wchar_buf, LCST (", "));
452 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
453 /* We only look at repetitions when we were able to convert a
454 single character in isolation. This makes the code simpler
455 and probably does the sensible thing in the majority of
457 while (num_chars == 1)
459 /* Count the number of repetitions. */
460 unsigned int reps = 0;
461 gdb_wchar_t current_char = chars[0];
462 const gdb_byte *orig_buf = buf;
463 int orig_len = buflen;
467 obstack_grow_wstr (&wchar_buf, LCST (", "));
471 while (num_chars == 1 && current_char == chars[0])
473 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
477 /* Emit CURRENT_CHAR according to the repetition count and
479 if (reps > options->repeat_count_threshold)
483 if (options->inspect_it)
484 obstack_grow_wstr (&wchar_buf, LCST ("\\\", "));
486 obstack_grow_wstr (&wchar_buf, LCST ("\", "));
489 obstack_grow_wstr (&wchar_buf, LCST ("'"));
491 print_wchar (current_char, orig_buf, orig_len, width,
492 byte_order, &wchar_buf, '\'', &need_escape);
493 obstack_grow_wstr (&wchar_buf, LCST ("'"));
495 /* Painful gyrations. */
497 char *s = xstrprintf (_(" <repeats %u times>"), reps);
498 for (j = 0; s[j]; ++j)
500 gdb_wchar_t w = gdb_btowc (s[j]);
501 obstack_grow (&wchar_buf, &w, sizeof (gdb_wchar_t));
505 things_printed += options->repeat_count_threshold;
510 /* Saw the character one or more times, but fewer than
511 the repetition threshold. */
514 if (options->inspect_it)
515 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
517 obstack_grow_wstr (&wchar_buf, LCST ("\""));
524 print_wchar (current_char, orig_buf, orig_len, width,
525 byte_order, &wchar_buf, '"', &need_escape);
531 /* NUM_CHARS and the other outputs from wchar_iterate are valid
532 here regardless of which branch was taken above. */
542 case wchar_iterate_invalid:
545 if (options->inspect_it)
546 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
548 obstack_grow_wstr (&wchar_buf, LCST ("\""));
552 print_wchar (gdb_WEOF, buf, buflen, width, byte_order, &wchar_buf,
556 case wchar_iterate_incomplete:
559 if (options->inspect_it)
560 obstack_grow_wstr (&wchar_buf, LCST ("\\\","));
562 obstack_grow_wstr (&wchar_buf, LCST ("\","));
565 obstack_grow_wstr (&wchar_buf, LCST (" <incomplete sequence "));
566 print_wchar (gdb_WEOF, buf, buflen, width, byte_order, &wchar_buf,
568 obstack_grow_wstr (&wchar_buf, LCST (">"));
574 /* Terminate the quotes if necessary. */
577 if (options->inspect_it)
578 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
580 obstack_grow_wstr (&wchar_buf, LCST ("\""));
583 if (force_ellipses || !finished)
584 obstack_grow_wstr (&wchar_buf, LCST ("..."));
586 /* OUTPUT is where we collect `char's for printing. */
587 obstack_init (&output);
588 make_cleanup_obstack_free (&output);
590 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
591 obstack_base (&wchar_buf),
592 obstack_object_size (&wchar_buf),
593 1, &output, translit_char);
594 obstack_1grow (&output, '\0');
596 fputs_filtered (obstack_base (&output), stream);
598 do_cleanups (cleanup);
601 /* Obtain a C string from the inferior storing it in a newly allocated
602 buffer in BUFFER, which should be freed by the caller. The string is
603 read until a null character is found. If VALUE is an array with known
604 length, the function will not read past the end of the array. LENGTH
605 will contain the size of the string in bytes (not counting the null
608 Assumes strings are terminated by a null character. The size of a character
609 is determined by the length of the target type of the pointer or array.
610 This means that a null byte present in a multi-byte character will not
611 terminate the string unless the whole character is null.
613 CHARSET is always set to the target charset. */
616 c_get_string (struct value *value, gdb_byte **buffer, int *length,
617 const char **charset)
620 unsigned int fetchlimit;
621 struct type *type = check_typedef (value_type (value));
622 struct type *element_type = TYPE_TARGET_TYPE (type);
623 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
625 if (element_type == NULL)
628 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
630 /* If we know the size of the array, we can use it as a limit on the
631 number of characters to be fetched. */
632 if (TYPE_NFIELDS (type) == 1
633 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
635 LONGEST low_bound, high_bound;
637 get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
638 &low_bound, &high_bound);
639 fetchlimit = high_bound - low_bound + 1;
642 fetchlimit = UINT_MAX;
644 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
645 fetchlimit = UINT_MAX;
647 /* We work only with arrays and pointers. */
650 element_type = check_typedef (element_type);
651 if (TYPE_CODE (element_type) != TYPE_CODE_INT
652 && TYPE_CODE (element_type) != TYPE_CODE_CHAR)
653 /* If the elements are not integers or characters, we don't consider it
657 width = TYPE_LENGTH (element_type);
659 /* If the string lives in GDB's memory intead of the inferior's, then we
660 just need to copy it to BUFFER. Also, since such strings are arrays
661 with known size, FETCHLIMIT will hold the size of the array. */
662 if ((VALUE_LVAL (value) == not_lval
663 || VALUE_LVAL (value) == lval_internalvar)
664 && fetchlimit != UINT_MAX)
667 const gdb_byte *contents = value_contents (value);
669 /* Look for a null character. */
670 for (i = 0; i < fetchlimit; i++)
671 if (extract_unsigned_integer (contents + i * width, width,
675 /* I is now either the number of non-null characters, or FETCHLIMIT. */
677 *buffer = xmalloc (*length);
678 memcpy (*buffer, contents, *length);
683 err = read_string (value_as_address (value), -1, width, fetchlimit,
684 byte_order, buffer, length);
688 error (_("Error reading string from inferior: %s"),
689 safe_strerror (err));
693 /* If the last character is null, subtract it from LENGTH. */
695 && extract_unsigned_integer (*buffer + *length - width, width,
699 *charset = target_charset ();
707 type_str = type_to_string (type);
710 make_cleanup (xfree, type_str);
711 error (_("Trying to read string with inappropriate type `%s'."),
715 error (_("Trying to read string with inappropriate type."));
720 /* Evaluating C and C++ expressions. */
722 /* Convert a UCN. The digits of the UCN start at P and extend no
723 farther than LIMIT. DEST_CHARSET is the name of the character set
724 into which the UCN should be converted. The results are written to
725 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
726 Returns a pointer to just after the final digit of the UCN. */
729 convert_ucn (char *p, char *limit, const char *dest_charset,
730 struct obstack *output, int length)
732 unsigned long result = 0;
736 for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p)
737 result = (result << 4) + host_hex_value (*p);
739 for (i = 3; i >= 0; --i)
741 data[i] = result & 0xff;
745 convert_between_encodings ("UCS-4BE", dest_charset, data, 4, 4, output,
751 /* Emit a character, VALUE, which was specified numerically, to
752 OUTPUT. TYPE is the target character type. */
755 emit_numeric_character (struct type *type, unsigned long value,
756 struct obstack *output)
760 buffer = alloca (TYPE_LENGTH (type));
761 pack_long (buffer, type, value);
762 obstack_grow (output, buffer, TYPE_LENGTH (type));
765 /* Convert an octal escape sequence. TYPE is the target character
766 type. The digits of the escape sequence begin at P and extend no
767 farther than LIMIT. The result is written to OUTPUT. Returns a
768 pointer to just after the final digit of the escape sequence. */
771 convert_octal (struct type *type, char *p, char *limit, struct obstack *output)
773 unsigned long value = 0;
775 while (p < limit && isdigit (*p) && *p != '8' && *p != '9')
777 value = 8 * value + host_hex_value (*p);
781 emit_numeric_character (type, value, output);
786 /* Convert a hex escape sequence. TYPE is the target character type.
787 The digits of the escape sequence begin at P and extend no farther
788 than LIMIT. The result is written to OUTPUT. Returns a pointer to
789 just after the final digit of the escape sequence. */
792 convert_hex (struct type *type, char *p, char *limit, struct obstack *output)
794 unsigned long value = 0;
796 while (p < limit && isxdigit (*p))
798 value = 16 * value + host_hex_value (*p);
802 emit_numeric_character (type, value, output);
811 error (_("Malformed escape sequence")); \
814 /* Convert an escape sequence to a target format. TYPE is the target
815 character type to use, and DEST_CHARSET is the name of the target
816 character set. The backslash of the escape sequence is at *P, and
817 the escape sequence will not extend past LIMIT. The results are
818 written to OUTPUT. Returns a pointer to just past the final
819 character of the escape sequence. */
822 convert_escape (struct type *type, const char *dest_charset,
823 char *p, char *limit, struct obstack *output)
825 /* Skip the backslash. */
831 obstack_1grow (output, '\\');
838 error (_("\\x used with no following hex digits."));
839 p = convert_hex (type, p, limit, output);
850 p = convert_octal (type, p, limit, output);
856 int length = *p == 'u' ? 4 : 8;
859 error (_("\\u used with no following hex digits"));
860 p = convert_ucn (p, limit, dest_charset, output, length);
867 /* Given a single string from a (C-specific) OP_STRING list, convert
868 it to a target string, handling escape sequences specially. The
869 output is written to OUTPUT. DATA is the input string, which has
870 length LEN. DEST_CHARSET is the name of the target character set,
871 and TYPE is the type of target character to use. */
874 parse_one_string (struct obstack *output, char *data, int len,
875 const char *dest_charset, struct type *type)
884 /* Look for next escape, or the end of the input. */
885 while (p < limit && *p != '\\')
887 /* If we saw a run of characters, convert them all. */
889 convert_between_encodings (host_charset (), dest_charset,
890 data, p - data, 1, output, translit_none);
891 /* If we saw an escape, convert it. */
893 p = convert_escape (type, dest_charset, p, limit, output);
898 /* Expression evaluator for the C language family. Most operations
899 are delegated to evaluate_subexp_standard; see that function for a
900 description of the arguments. */
902 static struct value *
903 evaluate_subexp_c (struct type *expect_type, struct expression *exp,
904 int *pos, enum noside noside)
906 enum exp_opcode op = exp->elts[*pos].opcode;
914 struct obstack output;
915 struct cleanup *cleanup;
916 struct value *result;
917 enum c_string_type dest_type;
918 const char *dest_charset;
919 enum bfd_endian byte_order;
921 obstack_init (&output);
922 cleanup = make_cleanup_obstack_free (&output);
925 oplen = longest_to_int (exp->elts[*pos].longconst);
928 limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
930 = (enum c_string_type) longest_to_int (exp->elts[*pos].longconst);
931 switch (dest_type & ~C_CHAR)
934 type = language_string_char_type (exp->language_defn,
938 type = lookup_typename (exp->language_defn, exp->gdbarch,
942 type = lookup_typename (exp->language_defn, exp->gdbarch,
943 "char16_t", NULL, 0);
946 type = lookup_typename (exp->language_defn, exp->gdbarch,
947 "char32_t", NULL, 0);
950 internal_error (__FILE__, __LINE__, "unhandled c_string_type");
953 /* Ensure TYPE_LENGTH is valid for TYPE. */
954 check_typedef (type);
956 byte_order = gdbarch_byte_order (exp->gdbarch);
957 dest_charset = charset_for_string_type (dest_type, byte_order);
964 len = longest_to_int (exp->elts[*pos].longconst);
967 if (noside != EVAL_SKIP)
968 parse_one_string (&output, &exp->elts[*pos].string, len,
970 *pos += BYTES_TO_EXP_ELEM (len);
973 /* Skip the trailing length and opcode. */
976 if (noside == EVAL_SKIP)
978 /* Return a dummy value of the appropriate type. */
979 if ((dest_type & C_CHAR) != 0)
980 result = allocate_value (type);
982 result = value_cstring ("", 0, type);
983 do_cleanups (cleanup);
987 if ((dest_type & C_CHAR) != 0)
991 if (obstack_object_size (&output) != TYPE_LENGTH (type))
992 error (_("Could not convert character constant to target character set"));
993 value = unpack_long (type, obstack_base (&output));
994 result = value_from_longest (type, value);
999 /* Write the terminating character. */
1000 for (i = 0; i < TYPE_LENGTH (type); ++i)
1001 obstack_1grow (&output, 0);
1002 result = value_cstring (obstack_base (&output),
1003 obstack_object_size (&output),
1006 do_cleanups (cleanup);
1014 return evaluate_subexp_standard (expect_type, exp, pos, noside);
1019 /* Table mapping opcodes into strings for printing operators
1020 and precedences of the operators. */
1022 const struct op_print c_op_print_tab[] =
1024 {",", BINOP_COMMA, PREC_COMMA, 0},
1025 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1026 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
1027 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
1028 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
1029 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
1030 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
1031 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1032 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1033 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1034 {">=", BINOP_GEQ, PREC_ORDER, 0},
1035 {">", BINOP_GTR, PREC_ORDER, 0},
1036 {"<", BINOP_LESS, PREC_ORDER, 0},
1037 {">>", BINOP_RSH, PREC_SHIFT, 0},
1038 {"<<", BINOP_LSH, PREC_SHIFT, 0},
1039 {"+", BINOP_ADD, PREC_ADD, 0},
1040 {"-", BINOP_SUB, PREC_ADD, 0},
1041 {"*", BINOP_MUL, PREC_MUL, 0},
1042 {"/", BINOP_DIV, PREC_MUL, 0},
1043 {"%", BINOP_REM, PREC_MUL, 0},
1044 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1045 {"-", UNOP_NEG, PREC_PREFIX, 0},
1046 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
1047 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
1048 {"*", UNOP_IND, PREC_PREFIX, 0},
1049 {"&", UNOP_ADDR, PREC_PREFIX, 0},
1050 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
1051 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1052 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
1056 enum c_primitive_types {
1057 c_primitive_type_int,
1058 c_primitive_type_long,
1059 c_primitive_type_short,
1060 c_primitive_type_char,
1061 c_primitive_type_float,
1062 c_primitive_type_double,
1063 c_primitive_type_void,
1064 c_primitive_type_long_long,
1065 c_primitive_type_signed_char,
1066 c_primitive_type_unsigned_char,
1067 c_primitive_type_unsigned_short,
1068 c_primitive_type_unsigned_int,
1069 c_primitive_type_unsigned_long,
1070 c_primitive_type_unsigned_long_long,
1071 c_primitive_type_long_double,
1072 c_primitive_type_complex,
1073 c_primitive_type_double_complex,
1074 c_primitive_type_decfloat,
1075 c_primitive_type_decdouble,
1076 c_primitive_type_declong,
1077 nr_c_primitive_types
1081 c_language_arch_info (struct gdbarch *gdbarch,
1082 struct language_arch_info *lai)
1084 const struct builtin_type *builtin = builtin_type (gdbarch);
1085 lai->string_char_type = builtin->builtin_char;
1086 lai->primitive_type_vector
1087 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
1089 lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int;
1090 lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long;
1091 lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short;
1092 lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char;
1093 lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float;
1094 lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double;
1095 lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void;
1096 lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long;
1097 lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char;
1098 lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char;
1099 lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short;
1100 lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int;
1101 lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long;
1102 lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long;
1103 lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double;
1104 lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex;
1105 lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex;
1106 lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat;
1107 lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble;
1108 lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong;
1110 lai->bool_type_default = builtin->builtin_int;
1113 static const struct exp_descriptor exp_descriptor_c =
1115 print_subexp_standard,
1116 operator_length_standard,
1118 dump_subexp_body_standard,
1122 const struct language_defn c_language_defn =
1124 "c", /* Language name */
1135 c_printchar, /* Print a character constant */
1136 c_printstr, /* Function to print string constant */
1137 c_emit_char, /* Print a single char */
1138 c_print_type, /* Print a type using appropriate syntax */
1139 c_print_typedef, /* Print a typedef using appropriate syntax */
1140 c_val_print, /* Print a value using appropriate syntax */
1141 c_value_print, /* Print a top-level value */
1142 NULL, /* Language specific skip_trampoline */
1143 NULL, /* name_of_this */
1144 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1145 basic_lookup_transparent_type,/* lookup_transparent_type */
1146 NULL, /* Language specific symbol demangler */
1147 NULL, /* Language specific class_name_from_physname */
1148 c_op_print_tab, /* expression operators for printing */
1149 1, /* c-style arrays */
1150 0, /* String lower bound */
1151 default_word_break_characters,
1152 default_make_symbol_completion_list,
1153 c_language_arch_info,
1154 default_print_array_index,
1155 default_pass_by_reference,
1160 enum cplus_primitive_types {
1161 cplus_primitive_type_int,
1162 cplus_primitive_type_long,
1163 cplus_primitive_type_short,
1164 cplus_primitive_type_char,
1165 cplus_primitive_type_float,
1166 cplus_primitive_type_double,
1167 cplus_primitive_type_void,
1168 cplus_primitive_type_long_long,
1169 cplus_primitive_type_signed_char,
1170 cplus_primitive_type_unsigned_char,
1171 cplus_primitive_type_unsigned_short,
1172 cplus_primitive_type_unsigned_int,
1173 cplus_primitive_type_unsigned_long,
1174 cplus_primitive_type_unsigned_long_long,
1175 cplus_primitive_type_long_double,
1176 cplus_primitive_type_complex,
1177 cplus_primitive_type_double_complex,
1178 cplus_primitive_type_bool,
1179 cplus_primitive_type_decfloat,
1180 cplus_primitive_type_decdouble,
1181 cplus_primitive_type_declong,
1182 nr_cplus_primitive_types
1186 cplus_language_arch_info (struct gdbarch *gdbarch,
1187 struct language_arch_info *lai)
1189 const struct builtin_type *builtin = builtin_type (gdbarch);
1190 lai->string_char_type = builtin->builtin_char;
1191 lai->primitive_type_vector
1192 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
1194 lai->primitive_type_vector [cplus_primitive_type_int]
1195 = builtin->builtin_int;
1196 lai->primitive_type_vector [cplus_primitive_type_long]
1197 = builtin->builtin_long;
1198 lai->primitive_type_vector [cplus_primitive_type_short]
1199 = builtin->builtin_short;
1200 lai->primitive_type_vector [cplus_primitive_type_char]
1201 = builtin->builtin_char;
1202 lai->primitive_type_vector [cplus_primitive_type_float]
1203 = builtin->builtin_float;
1204 lai->primitive_type_vector [cplus_primitive_type_double]
1205 = builtin->builtin_double;
1206 lai->primitive_type_vector [cplus_primitive_type_void]
1207 = builtin->builtin_void;
1208 lai->primitive_type_vector [cplus_primitive_type_long_long]
1209 = builtin->builtin_long_long;
1210 lai->primitive_type_vector [cplus_primitive_type_signed_char]
1211 = builtin->builtin_signed_char;
1212 lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
1213 = builtin->builtin_unsigned_char;
1214 lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
1215 = builtin->builtin_unsigned_short;
1216 lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
1217 = builtin->builtin_unsigned_int;
1218 lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
1219 = builtin->builtin_unsigned_long;
1220 lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
1221 = builtin->builtin_unsigned_long_long;
1222 lai->primitive_type_vector [cplus_primitive_type_long_double]
1223 = builtin->builtin_long_double;
1224 lai->primitive_type_vector [cplus_primitive_type_complex]
1225 = builtin->builtin_complex;
1226 lai->primitive_type_vector [cplus_primitive_type_double_complex]
1227 = builtin->builtin_double_complex;
1228 lai->primitive_type_vector [cplus_primitive_type_bool]
1229 = builtin->builtin_bool;
1230 lai->primitive_type_vector [cplus_primitive_type_decfloat]
1231 = builtin->builtin_decfloat;
1232 lai->primitive_type_vector [cplus_primitive_type_decdouble]
1233 = builtin->builtin_decdouble;
1234 lai->primitive_type_vector [cplus_primitive_type_declong]
1235 = builtin->builtin_declong;
1237 lai->bool_type_symbol = "bool";
1238 lai->bool_type_default = builtin->builtin_bool;
1241 const struct language_defn cplus_language_defn =
1243 "c++", /* Language name */
1254 c_printchar, /* Print a character constant */
1255 c_printstr, /* Function to print string constant */
1256 c_emit_char, /* Print a single char */
1257 c_print_type, /* Print a type using appropriate syntax */
1258 c_print_typedef, /* Print a typedef using appropriate syntax */
1259 c_val_print, /* Print a value using appropriate syntax */
1260 c_value_print, /* Print a top-level value */
1261 cplus_skip_trampoline, /* Language specific skip_trampoline */
1262 "this", /* name_of_this */
1263 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1264 cp_lookup_transparent_type, /* lookup_transparent_type */
1265 cplus_demangle, /* Language specific symbol demangler */
1266 cp_class_name_from_physname, /* Language specific class_name_from_physname */
1267 c_op_print_tab, /* expression operators for printing */
1268 1, /* c-style arrays */
1269 0, /* String lower bound */
1270 default_word_break_characters,
1271 default_make_symbol_completion_list,
1272 cplus_language_arch_info,
1273 default_print_array_index,
1274 cp_pass_by_reference,
1279 const struct language_defn asm_language_defn =
1281 "asm", /* Language name */
1292 c_printchar, /* Print a character constant */
1293 c_printstr, /* Function to print string constant */
1294 c_emit_char, /* Print a single char */
1295 c_print_type, /* Print a type using appropriate syntax */
1296 c_print_typedef, /* Print a typedef using appropriate syntax */
1297 c_val_print, /* Print a value using appropriate syntax */
1298 c_value_print, /* Print a top-level value */
1299 NULL, /* Language specific skip_trampoline */
1300 NULL, /* name_of_this */
1301 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1302 basic_lookup_transparent_type,/* lookup_transparent_type */
1303 NULL, /* Language specific symbol demangler */
1304 NULL, /* Language specific class_name_from_physname */
1305 c_op_print_tab, /* expression operators for printing */
1306 1, /* c-style arrays */
1307 0, /* String lower bound */
1308 default_word_break_characters,
1309 default_make_symbol_completion_list,
1310 c_language_arch_info, /* FIXME: la_language_arch_info. */
1311 default_print_array_index,
1312 default_pass_by_reference,
1317 /* The following language_defn does not represent a real language.
1318 It just provides a minimal support a-la-C that should allow users
1319 to do some simple operations when debugging applications that use
1320 a language currently not supported by GDB. */
1322 const struct language_defn minimal_language_defn =
1324 "minimal", /* Language name */
1335 c_printchar, /* Print a character constant */
1336 c_printstr, /* Function to print string constant */
1337 c_emit_char, /* Print a single char */
1338 c_print_type, /* Print a type using appropriate syntax */
1339 c_print_typedef, /* Print a typedef using appropriate syntax */
1340 c_val_print, /* Print a value using appropriate syntax */
1341 c_value_print, /* Print a top-level value */
1342 NULL, /* Language specific skip_trampoline */
1343 NULL, /* name_of_this */
1344 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1345 basic_lookup_transparent_type,/* lookup_transparent_type */
1346 NULL, /* Language specific symbol demangler */
1347 NULL, /* Language specific class_name_from_physname */
1348 c_op_print_tab, /* expression operators for printing */
1349 1, /* c-style arrays */
1350 0, /* String lower bound */
1351 default_word_break_characters,
1352 default_make_symbol_completion_list,
1353 c_language_arch_info,
1354 default_print_array_index,
1355 default_pass_by_reference,
1361 _initialize_c_language (void)
1363 add_language (&c_language_defn);
1364 add_language (&cplus_language_defn);
1365 add_language (&asm_language_defn);
1366 add_language (&minimal_language_defn);