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 /* If the value fits in 3 octal digits, print it that
229 way. Otherwise, print it as a hex escape. */
231 sprintf (octal, "\\%.3o", (int) (value & 0777));
233 sprintf (octal, "\\x%lx", (long) value);
234 append_string_as_wide (octal, output);
236 /* If we somehow have extra bytes, print them now. */
240 sprintf (octal, "\\%.3o", orig[i] & 0xff);
241 append_string_as_wide (octal, output);
252 /* Print the character C on STREAM as part of the contents of a literal
253 string whose delimiter is QUOTER. Note that that format for printing
254 characters and strings is language specific. */
257 c_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
259 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
260 struct obstack wchar_buf, output;
261 struct cleanup *cleanups;
262 const char *encoding;
264 struct wchar_iterator *iter;
267 classify_type (type, byte_order, &encoding);
269 buf = alloca (TYPE_LENGTH (type));
270 pack_long (buf, type, c);
272 iter = make_wchar_iterator (buf, TYPE_LENGTH (type), encoding,
274 cleanups = make_cleanup_wchar_iterator (iter);
276 /* This holds the printable form of the wchar_t data. */
277 obstack_init (&wchar_buf);
278 make_cleanup_obstack_free (&wchar_buf);
286 int print_escape = 1;
287 enum wchar_iterate_result result;
289 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
294 /* If all characters are printable, print them. Otherwise,
295 we're going to have to print an escape sequence. We
296 check all characters because we want to print the target
297 bytes in the escape sequence, and we don't know character
302 for (i = 0; i < num_chars; ++i)
303 if (!wchar_printable (chars[i]))
311 for (i = 0; i < num_chars; ++i)
312 print_wchar (chars[i], buf, buflen, TYPE_LENGTH (type),
313 byte_order, &wchar_buf, quoter, &need_escape);
317 /* This handles the NUM_CHARS == 0 case as well. */
319 print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type), byte_order,
320 &wchar_buf, quoter, &need_escape);
323 /* The output in the host encoding. */
324 obstack_init (&output);
325 make_cleanup_obstack_free (&output);
327 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
328 obstack_base (&wchar_buf),
329 obstack_object_size (&wchar_buf),
330 1, &output, translit_char);
331 obstack_1grow (&output, '\0');
333 fputs_filtered (obstack_base (&output), stream);
335 do_cleanups (cleanups);
339 c_printchar (int c, struct type *type, struct ui_file *stream)
341 enum c_string_type str_type;
343 str_type = classify_type (type, BFD_ENDIAN_UNKNOWN, NULL);
349 fputc_filtered ('L', stream);
352 fputc_filtered ('u', stream);
355 fputc_filtered ('U', stream);
359 fputc_filtered ('\'', stream);
360 LA_EMIT_CHAR (c, type, stream, '\'');
361 fputc_filtered ('\'', stream);
364 /* Print the character string STRING, printing at most LENGTH characters.
365 LENGTH is -1 if the string is nul terminated. Each character is WIDTH bytes
366 long. Printing stops early if the number hits print_max; repeat counts are
367 printed as appropriate. Print ellipses at the end if we had to stop before
368 printing LENGTH characters, or if FORCE_ELLIPSES. */
371 c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
372 unsigned int length, int force_ellipses,
373 const struct value_print_options *options)
375 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
377 unsigned int things_printed = 0;
380 int width = TYPE_LENGTH (type);
381 struct obstack wchar_buf, output;
382 struct cleanup *cleanup;
383 enum c_string_type str_type;
384 const char *encoding;
385 struct wchar_iterator *iter;
389 /* If the string was not truncated due to `set print elements', and
390 the last byte of it is a null, we don't print that, in traditional C
394 && (extract_unsigned_integer (string + (length - 1) * width,
395 width, byte_order) == 0))
398 str_type = classify_type (type, byte_order, &encoding) & ~C_CHAR;
404 fputs_filtered ("L", stream);
407 fputs_filtered ("u", stream);
410 fputs_filtered ("U", stream);
416 fputs_filtered ("\"\"", stream);
422 unsigned long current_char = 1;
423 for (i = 0; current_char; ++i)
426 current_char = extract_unsigned_integer (string + i * width,
432 /* Arrange to iterate over the characters, in wchar_t form. */
433 iter = make_wchar_iterator (string, length * width, encoding, width);
434 cleanup = make_cleanup_wchar_iterator (iter);
436 /* WCHAR_BUF is the obstack we use to represent the string in
438 obstack_init (&wchar_buf);
439 make_cleanup_obstack_free (&wchar_buf);
441 while (!finished && things_printed < options->print_max)
444 enum wchar_iterate_result result;
453 obstack_grow_wstr (&wchar_buf, LCST (", "));
457 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
458 /* We only look at repetitions when we were able to convert a
459 single character in isolation. This makes the code simpler
460 and probably does the sensible thing in the majority of
462 while (num_chars == 1)
464 /* Count the number of repetitions. */
465 unsigned int reps = 0;
466 gdb_wchar_t current_char = chars[0];
467 const gdb_byte *orig_buf = buf;
468 int orig_len = buflen;
472 obstack_grow_wstr (&wchar_buf, LCST (", "));
476 while (num_chars == 1 && current_char == chars[0])
478 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
482 /* Emit CURRENT_CHAR according to the repetition count and
484 if (reps > options->repeat_count_threshold)
488 if (options->inspect_it)
489 obstack_grow_wstr (&wchar_buf, LCST ("\\\", "));
491 obstack_grow_wstr (&wchar_buf, LCST ("\", "));
494 obstack_grow_wstr (&wchar_buf, LCST ("'"));
496 print_wchar (current_char, orig_buf, orig_len, width,
497 byte_order, &wchar_buf, '\'', &need_escape);
498 obstack_grow_wstr (&wchar_buf, LCST ("'"));
500 /* Painful gyrations. */
502 char *s = xstrprintf (_(" <repeats %u times>"), reps);
503 for (j = 0; s[j]; ++j)
505 gdb_wchar_t w = gdb_btowc (s[j]);
506 obstack_grow (&wchar_buf, &w, sizeof (gdb_wchar_t));
510 things_printed += options->repeat_count_threshold;
515 /* Saw the character one or more times, but fewer than
516 the repetition threshold. */
519 if (options->inspect_it)
520 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
522 obstack_grow_wstr (&wchar_buf, LCST ("\""));
529 print_wchar (current_char, orig_buf, orig_len, width,
530 byte_order, &wchar_buf, '"', &need_escape);
536 /* NUM_CHARS and the other outputs from wchar_iterate are valid
537 here regardless of which branch was taken above. */
547 case wchar_iterate_invalid:
550 if (options->inspect_it)
551 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
553 obstack_grow_wstr (&wchar_buf, LCST ("\""));
557 print_wchar (gdb_WEOF, buf, buflen, width, byte_order, &wchar_buf,
561 case wchar_iterate_incomplete:
564 if (options->inspect_it)
565 obstack_grow_wstr (&wchar_buf, LCST ("\\\","));
567 obstack_grow_wstr (&wchar_buf, LCST ("\","));
570 obstack_grow_wstr (&wchar_buf, LCST (" <incomplete sequence "));
571 print_wchar (gdb_WEOF, buf, buflen, width, byte_order, &wchar_buf,
573 obstack_grow_wstr (&wchar_buf, LCST (">"));
579 /* Terminate the quotes if necessary. */
582 if (options->inspect_it)
583 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
585 obstack_grow_wstr (&wchar_buf, LCST ("\""));
588 if (force_ellipses || !finished)
589 obstack_grow_wstr (&wchar_buf, LCST ("..."));
591 /* OUTPUT is where we collect `char's for printing. */
592 obstack_init (&output);
593 make_cleanup_obstack_free (&output);
595 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
596 obstack_base (&wchar_buf),
597 obstack_object_size (&wchar_buf),
598 1, &output, translit_char);
599 obstack_1grow (&output, '\0');
601 fputs_filtered (obstack_base (&output), stream);
603 do_cleanups (cleanup);
606 /* Obtain a C string from the inferior storing it in a newly allocated
607 buffer in BUFFER, which should be freed by the caller. If the
608 in- and out-parameter *LENGTH is specified at -1, the string is read
609 until a null character of the appropriate width is found, otherwise
610 the string is read to the length of characters specified.
611 The size of a character is determined by the length of the target
612 type of the pointer or array. If VALUE is an array with a known
613 length, the function will not read past the end of the array.
614 On completion, *LENGTH will be set to the size of the string read in
615 characters. (If a length of -1 is specified, the length returned
616 will not include the null character). CHARSET is always set to the
620 c_get_string (struct value *value, gdb_byte **buffer, int *length,
621 const char **charset)
624 unsigned int fetchlimit;
625 struct type *type = check_typedef (value_type (value));
626 struct type *element_type = TYPE_TARGET_TYPE (type);
627 int req_length = *length;
628 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
630 if (element_type == NULL)
633 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
635 /* If we know the size of the array, we can use it as a limit on the
636 number of characters to be fetched. */
637 if (TYPE_NFIELDS (type) == 1
638 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
640 LONGEST low_bound, high_bound;
642 get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
643 &low_bound, &high_bound);
644 fetchlimit = high_bound - low_bound + 1;
647 fetchlimit = UINT_MAX;
649 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
650 fetchlimit = UINT_MAX;
652 /* We work only with arrays and pointers. */
655 element_type = check_typedef (element_type);
656 if (TYPE_CODE (element_type) != TYPE_CODE_INT
657 && TYPE_CODE (element_type) != TYPE_CODE_CHAR)
658 /* If the elements are not integers or characters, we don't consider it
662 width = TYPE_LENGTH (element_type);
664 /* If the string lives in GDB's memory instead of the inferior's, then we
665 just need to copy it to BUFFER. Also, since such strings are arrays
666 with known size, FETCHLIMIT will hold the size of the array. */
667 if ((VALUE_LVAL (value) == not_lval
668 || VALUE_LVAL (value) == lval_internalvar)
669 && fetchlimit != UINT_MAX)
672 const gdb_byte *contents = value_contents (value);
674 /* If a length is specified, use that. */
678 /* Otherwise, look for a null character. */
679 for (i = 0; i < fetchlimit; i++)
680 if (extract_unsigned_integer (contents + i * width, width,
684 /* I is now either a user-defined length, the number of non-null
685 characters, or FETCHLIMIT. */
687 *buffer = xmalloc (*length);
688 memcpy (*buffer, contents, *length);
693 err = read_string (value_as_address (value), *length, width, fetchlimit,
694 byte_order, buffer, length);
698 error (_("Error reading string from inferior: %s"),
699 safe_strerror (err));
703 /* If the LENGTH is specified at -1, we want to return the string
704 length up to the terminating null character. If an actual length
705 was specified, we want to return the length of exactly what was
707 if (req_length == -1)
708 /* If the last character is null, subtract it from LENGTH. */
710 && extract_unsigned_integer (*buffer + *length - width, width,
714 /* The read_string function will return the number of bytes read.
715 If length returned from read_string was > 0, return the number of
716 characters read by dividing the number of bytes by width. */
718 *length = *length / width;
720 *charset = target_charset ();
728 type_str = type_to_string (type);
731 make_cleanup (xfree, type_str);
732 error (_("Trying to read string with inappropriate type `%s'."),
736 error (_("Trying to read string with inappropriate type."));
741 /* Evaluating C and C++ expressions. */
743 /* Convert a UCN. The digits of the UCN start at P and extend no
744 farther than LIMIT. DEST_CHARSET is the name of the character set
745 into which the UCN should be converted. The results are written to
746 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
747 Returns a pointer to just after the final digit of the UCN. */
750 convert_ucn (char *p, char *limit, const char *dest_charset,
751 struct obstack *output, int length)
753 unsigned long result = 0;
757 for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p)
758 result = (result << 4) + host_hex_value (*p);
760 for (i = 3; i >= 0; --i)
762 data[i] = result & 0xff;
766 convert_between_encodings ("UCS-4BE", dest_charset, data, 4, 4, output,
772 /* Emit a character, VALUE, which was specified numerically, to
773 OUTPUT. TYPE is the target character type. */
776 emit_numeric_character (struct type *type, unsigned long value,
777 struct obstack *output)
781 buffer = alloca (TYPE_LENGTH (type));
782 pack_long (buffer, type, value);
783 obstack_grow (output, buffer, TYPE_LENGTH (type));
786 /* Convert an octal escape sequence. TYPE is the target character
787 type. The digits of the escape sequence begin at P and extend no
788 farther than LIMIT. The result is written to OUTPUT. Returns a
789 pointer to just after the final digit of the escape sequence. */
792 convert_octal (struct type *type, char *p, char *limit, struct obstack *output)
795 unsigned long value = 0;
798 i < 3 && p < limit && isdigit (*p) && *p != '8' && *p != '9';
801 value = 8 * value + host_hex_value (*p);
805 emit_numeric_character (type, value, output);
810 /* Convert a hex escape sequence. TYPE is the target character type.
811 The digits of the escape sequence begin at P and extend no farther
812 than LIMIT. The result is written to OUTPUT. Returns a pointer to
813 just after the final digit of the escape sequence. */
816 convert_hex (struct type *type, char *p, char *limit, struct obstack *output)
818 unsigned long value = 0;
820 while (p < limit && isxdigit (*p))
822 value = 16 * value + host_hex_value (*p);
826 emit_numeric_character (type, value, output);
835 error (_("Malformed escape sequence")); \
838 /* Convert an escape sequence to a target format. TYPE is the target
839 character type to use, and DEST_CHARSET is the name of the target
840 character set. The backslash of the escape sequence is at *P, and
841 the escape sequence will not extend past LIMIT. The results are
842 written to OUTPUT. Returns a pointer to just past the final
843 character of the escape sequence. */
846 convert_escape (struct type *type, const char *dest_charset,
847 char *p, char *limit, struct obstack *output)
849 /* Skip the backslash. */
855 obstack_1grow (output, '\\');
862 error (_("\\x used with no following hex digits."));
863 p = convert_hex (type, p, limit, output);
874 p = convert_octal (type, p, limit, output);
880 int length = *p == 'u' ? 4 : 8;
883 error (_("\\u used with no following hex digits"));
884 p = convert_ucn (p, limit, dest_charset, output, length);
891 /* Given a single string from a (C-specific) OP_STRING list, convert
892 it to a target string, handling escape sequences specially. The
893 output is written to OUTPUT. DATA is the input string, which has
894 length LEN. DEST_CHARSET is the name of the target character set,
895 and TYPE is the type of target character to use. */
898 parse_one_string (struct obstack *output, char *data, int len,
899 const char *dest_charset, struct type *type)
908 /* Look for next escape, or the end of the input. */
909 while (p < limit && *p != '\\')
911 /* If we saw a run of characters, convert them all. */
913 convert_between_encodings (host_charset (), dest_charset,
914 data, p - data, 1, output, translit_none);
915 /* If we saw an escape, convert it. */
917 p = convert_escape (type, dest_charset, p, limit, output);
922 /* Expression evaluator for the C language family. Most operations
923 are delegated to evaluate_subexp_standard; see that function for a
924 description of the arguments. */
926 static struct value *
927 evaluate_subexp_c (struct type *expect_type, struct expression *exp,
928 int *pos, enum noside noside)
930 enum exp_opcode op = exp->elts[*pos].opcode;
938 struct obstack output;
939 struct cleanup *cleanup;
940 struct value *result;
941 enum c_string_type dest_type;
942 const char *dest_charset;
943 enum bfd_endian byte_order;
945 obstack_init (&output);
946 cleanup = make_cleanup_obstack_free (&output);
949 oplen = longest_to_int (exp->elts[*pos].longconst);
952 limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
954 = (enum c_string_type) longest_to_int (exp->elts[*pos].longconst);
955 switch (dest_type & ~C_CHAR)
958 type = language_string_char_type (exp->language_defn,
962 type = lookup_typename (exp->language_defn, exp->gdbarch,
966 type = lookup_typename (exp->language_defn, exp->gdbarch,
967 "char16_t", NULL, 0);
970 type = lookup_typename (exp->language_defn, exp->gdbarch,
971 "char32_t", NULL, 0);
974 internal_error (__FILE__, __LINE__, "unhandled c_string_type");
977 /* Ensure TYPE_LENGTH is valid for TYPE. */
978 check_typedef (type);
980 byte_order = gdbarch_byte_order (exp->gdbarch);
981 dest_charset = charset_for_string_type (dest_type, byte_order);
988 len = longest_to_int (exp->elts[*pos].longconst);
991 if (noside != EVAL_SKIP)
992 parse_one_string (&output, &exp->elts[*pos].string, len,
994 *pos += BYTES_TO_EXP_ELEM (len);
997 /* Skip the trailing length and opcode. */
1000 if (noside == EVAL_SKIP)
1002 /* Return a dummy value of the appropriate type. */
1003 if ((dest_type & C_CHAR) != 0)
1004 result = allocate_value (type);
1006 result = value_cstring ("", 0, type);
1007 do_cleanups (cleanup);
1011 if ((dest_type & C_CHAR) != 0)
1015 if (obstack_object_size (&output) != TYPE_LENGTH (type))
1016 error (_("Could not convert character constant to target character set"));
1017 value = unpack_long (type, obstack_base (&output));
1018 result = value_from_longest (type, value);
1023 /* Write the terminating character. */
1024 for (i = 0; i < TYPE_LENGTH (type); ++i)
1025 obstack_1grow (&output, 0);
1026 result = value_cstring (obstack_base (&output),
1027 obstack_object_size (&output),
1030 do_cleanups (cleanup);
1038 return evaluate_subexp_standard (expect_type, exp, pos, noside);
1043 /* Table mapping opcodes into strings for printing operators
1044 and precedences of the operators. */
1046 const struct op_print c_op_print_tab[] =
1048 {",", BINOP_COMMA, PREC_COMMA, 0},
1049 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1050 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
1051 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
1052 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
1053 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
1054 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
1055 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1056 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1057 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1058 {">=", BINOP_GEQ, PREC_ORDER, 0},
1059 {">", BINOP_GTR, PREC_ORDER, 0},
1060 {"<", BINOP_LESS, PREC_ORDER, 0},
1061 {">>", BINOP_RSH, PREC_SHIFT, 0},
1062 {"<<", BINOP_LSH, PREC_SHIFT, 0},
1063 {"+", BINOP_ADD, PREC_ADD, 0},
1064 {"-", BINOP_SUB, PREC_ADD, 0},
1065 {"*", BINOP_MUL, PREC_MUL, 0},
1066 {"/", BINOP_DIV, PREC_MUL, 0},
1067 {"%", BINOP_REM, PREC_MUL, 0},
1068 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1069 {"-", UNOP_NEG, PREC_PREFIX, 0},
1070 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
1071 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
1072 {"*", UNOP_IND, PREC_PREFIX, 0},
1073 {"&", UNOP_ADDR, PREC_PREFIX, 0},
1074 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
1075 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1076 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
1080 enum c_primitive_types {
1081 c_primitive_type_int,
1082 c_primitive_type_long,
1083 c_primitive_type_short,
1084 c_primitive_type_char,
1085 c_primitive_type_float,
1086 c_primitive_type_double,
1087 c_primitive_type_void,
1088 c_primitive_type_long_long,
1089 c_primitive_type_signed_char,
1090 c_primitive_type_unsigned_char,
1091 c_primitive_type_unsigned_short,
1092 c_primitive_type_unsigned_int,
1093 c_primitive_type_unsigned_long,
1094 c_primitive_type_unsigned_long_long,
1095 c_primitive_type_long_double,
1096 c_primitive_type_complex,
1097 c_primitive_type_double_complex,
1098 c_primitive_type_decfloat,
1099 c_primitive_type_decdouble,
1100 c_primitive_type_declong,
1101 nr_c_primitive_types
1105 c_language_arch_info (struct gdbarch *gdbarch,
1106 struct language_arch_info *lai)
1108 const struct builtin_type *builtin = builtin_type (gdbarch);
1109 lai->string_char_type = builtin->builtin_char;
1110 lai->primitive_type_vector
1111 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
1113 lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int;
1114 lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long;
1115 lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short;
1116 lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char;
1117 lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float;
1118 lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double;
1119 lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void;
1120 lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long;
1121 lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char;
1122 lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char;
1123 lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short;
1124 lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int;
1125 lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long;
1126 lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long;
1127 lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double;
1128 lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex;
1129 lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex;
1130 lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat;
1131 lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble;
1132 lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong;
1134 lai->bool_type_default = builtin->builtin_int;
1137 static const struct exp_descriptor exp_descriptor_c =
1139 print_subexp_standard,
1140 operator_length_standard,
1142 dump_subexp_body_standard,
1146 const struct language_defn c_language_defn =
1148 "c", /* Language name */
1159 c_printchar, /* Print a character constant */
1160 c_printstr, /* Function to print string constant */
1161 c_emit_char, /* Print a single char */
1162 c_print_type, /* Print a type using appropriate syntax */
1163 c_print_typedef, /* Print a typedef using appropriate syntax */
1164 c_val_print, /* Print a value using appropriate syntax */
1165 c_value_print, /* Print a top-level value */
1166 NULL, /* Language specific skip_trampoline */
1167 NULL, /* name_of_this */
1168 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1169 basic_lookup_transparent_type,/* lookup_transparent_type */
1170 NULL, /* Language specific symbol demangler */
1171 NULL, /* Language specific class_name_from_physname */
1172 c_op_print_tab, /* expression operators for printing */
1173 1, /* c-style arrays */
1174 0, /* String lower bound */
1175 default_word_break_characters,
1176 default_make_symbol_completion_list,
1177 c_language_arch_info,
1178 default_print_array_index,
1179 default_pass_by_reference,
1184 enum cplus_primitive_types {
1185 cplus_primitive_type_int,
1186 cplus_primitive_type_long,
1187 cplus_primitive_type_short,
1188 cplus_primitive_type_char,
1189 cplus_primitive_type_float,
1190 cplus_primitive_type_double,
1191 cplus_primitive_type_void,
1192 cplus_primitive_type_long_long,
1193 cplus_primitive_type_signed_char,
1194 cplus_primitive_type_unsigned_char,
1195 cplus_primitive_type_unsigned_short,
1196 cplus_primitive_type_unsigned_int,
1197 cplus_primitive_type_unsigned_long,
1198 cplus_primitive_type_unsigned_long_long,
1199 cplus_primitive_type_long_double,
1200 cplus_primitive_type_complex,
1201 cplus_primitive_type_double_complex,
1202 cplus_primitive_type_bool,
1203 cplus_primitive_type_decfloat,
1204 cplus_primitive_type_decdouble,
1205 cplus_primitive_type_declong,
1206 nr_cplus_primitive_types
1210 cplus_language_arch_info (struct gdbarch *gdbarch,
1211 struct language_arch_info *lai)
1213 const struct builtin_type *builtin = builtin_type (gdbarch);
1214 lai->string_char_type = builtin->builtin_char;
1215 lai->primitive_type_vector
1216 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
1218 lai->primitive_type_vector [cplus_primitive_type_int]
1219 = builtin->builtin_int;
1220 lai->primitive_type_vector [cplus_primitive_type_long]
1221 = builtin->builtin_long;
1222 lai->primitive_type_vector [cplus_primitive_type_short]
1223 = builtin->builtin_short;
1224 lai->primitive_type_vector [cplus_primitive_type_char]
1225 = builtin->builtin_char;
1226 lai->primitive_type_vector [cplus_primitive_type_float]
1227 = builtin->builtin_float;
1228 lai->primitive_type_vector [cplus_primitive_type_double]
1229 = builtin->builtin_double;
1230 lai->primitive_type_vector [cplus_primitive_type_void]
1231 = builtin->builtin_void;
1232 lai->primitive_type_vector [cplus_primitive_type_long_long]
1233 = builtin->builtin_long_long;
1234 lai->primitive_type_vector [cplus_primitive_type_signed_char]
1235 = builtin->builtin_signed_char;
1236 lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
1237 = builtin->builtin_unsigned_char;
1238 lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
1239 = builtin->builtin_unsigned_short;
1240 lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
1241 = builtin->builtin_unsigned_int;
1242 lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
1243 = builtin->builtin_unsigned_long;
1244 lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
1245 = builtin->builtin_unsigned_long_long;
1246 lai->primitive_type_vector [cplus_primitive_type_long_double]
1247 = builtin->builtin_long_double;
1248 lai->primitive_type_vector [cplus_primitive_type_complex]
1249 = builtin->builtin_complex;
1250 lai->primitive_type_vector [cplus_primitive_type_double_complex]
1251 = builtin->builtin_double_complex;
1252 lai->primitive_type_vector [cplus_primitive_type_bool]
1253 = builtin->builtin_bool;
1254 lai->primitive_type_vector [cplus_primitive_type_decfloat]
1255 = builtin->builtin_decfloat;
1256 lai->primitive_type_vector [cplus_primitive_type_decdouble]
1257 = builtin->builtin_decdouble;
1258 lai->primitive_type_vector [cplus_primitive_type_declong]
1259 = builtin->builtin_declong;
1261 lai->bool_type_symbol = "bool";
1262 lai->bool_type_default = builtin->builtin_bool;
1265 const struct language_defn cplus_language_defn =
1267 "c++", /* Language name */
1278 c_printchar, /* Print a character constant */
1279 c_printstr, /* Function to print string constant */
1280 c_emit_char, /* Print a single char */
1281 c_print_type, /* Print a type using appropriate syntax */
1282 c_print_typedef, /* Print a typedef using appropriate syntax */
1283 c_val_print, /* Print a value using appropriate syntax */
1284 c_value_print, /* Print a top-level value */
1285 cplus_skip_trampoline, /* Language specific skip_trampoline */
1286 "this", /* name_of_this */
1287 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1288 cp_lookup_transparent_type, /* lookup_transparent_type */
1289 cplus_demangle, /* Language specific symbol demangler */
1290 cp_class_name_from_physname, /* Language specific class_name_from_physname */
1291 c_op_print_tab, /* expression operators for printing */
1292 1, /* c-style arrays */
1293 0, /* String lower bound */
1294 default_word_break_characters,
1295 default_make_symbol_completion_list,
1296 cplus_language_arch_info,
1297 default_print_array_index,
1298 cp_pass_by_reference,
1303 const struct language_defn asm_language_defn =
1305 "asm", /* Language name */
1316 c_printchar, /* Print a character constant */
1317 c_printstr, /* Function to print string constant */
1318 c_emit_char, /* Print a single char */
1319 c_print_type, /* Print a type using appropriate syntax */
1320 c_print_typedef, /* Print a typedef using appropriate syntax */
1321 c_val_print, /* Print a value using appropriate syntax */
1322 c_value_print, /* Print a top-level value */
1323 NULL, /* Language specific skip_trampoline */
1324 NULL, /* name_of_this */
1325 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1326 basic_lookup_transparent_type,/* lookup_transparent_type */
1327 NULL, /* Language specific symbol demangler */
1328 NULL, /* Language specific class_name_from_physname */
1329 c_op_print_tab, /* expression operators for printing */
1330 1, /* c-style arrays */
1331 0, /* String lower bound */
1332 default_word_break_characters,
1333 default_make_symbol_completion_list,
1334 c_language_arch_info, /* FIXME: la_language_arch_info. */
1335 default_print_array_index,
1336 default_pass_by_reference,
1341 /* The following language_defn does not represent a real language.
1342 It just provides a minimal support a-la-C that should allow users
1343 to do some simple operations when debugging applications that use
1344 a language currently not supported by GDB. */
1346 const struct language_defn minimal_language_defn =
1348 "minimal", /* Language name */
1359 c_printchar, /* Print a character constant */
1360 c_printstr, /* Function to print string constant */
1361 c_emit_char, /* Print a single char */
1362 c_print_type, /* Print a type using appropriate syntax */
1363 c_print_typedef, /* Print a typedef using appropriate syntax */
1364 c_val_print, /* Print a value using appropriate syntax */
1365 c_value_print, /* Print a top-level value */
1366 NULL, /* Language specific skip_trampoline */
1367 NULL, /* name_of_this */
1368 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1369 basic_lookup_transparent_type,/* lookup_transparent_type */
1370 NULL, /* Language specific symbol demangler */
1371 NULL, /* Language specific class_name_from_physname */
1372 c_op_print_tab, /* expression operators for printing */
1373 1, /* c-style arrays */
1374 0, /* String lower bound */
1375 default_word_break_characters,
1376 default_make_symbol_completion_list,
1377 c_language_arch_info,
1378 default_print_array_index,
1379 default_pass_by_reference,
1385 _initialize_c_language (void)
1387 add_language (&c_language_defn);
1388 add_language (&cplus_language_defn);
1389 add_language (&asm_language_defn);
1390 add_language (&minimal_language_defn);