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
)
47 switch (str_type
& ~C_CHAR
)
50 return target_charset ();
52 return target_wide_charset ();
54 /* FIXME: UCS-2 is not always correct. */
55 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
60 /* FIXME: UCS-4 is not always correct. */
61 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
66 internal_error (__FILE__
, __LINE__
, "unhandled c_string_type");
69 /* Classify ELTTYPE according to what kind of character it is. Return
70 the enum constant representing the character type. Also set
71 *ENCODING to the name of the character set to use when converting
72 characters of this type to the host character set. */
74 static enum c_string_type
75 classify_type (struct type
*elttype
, const char **encoding
)
77 struct type
*saved_type
;
78 enum c_string_type result
;
80 /* We loop because ELTTYPE may be a typedef, and we want to
81 successively peel each typedef until we reach a type we
82 understand. We don't use CHECK_TYPEDEF because that will strip
83 all typedefs at once -- but in C, wchar_t is itself a typedef, so
84 that would do the wrong thing. */
87 char *name
= TYPE_NAME (elttype
);
89 if (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
|| !name
)
95 if (!strcmp (name
, "wchar_t"))
101 if (!strcmp (name
, "char16_t"))
107 if (!strcmp (name
, "char32_t"))
113 if (TYPE_CODE (elttype
) != TYPE_CODE_TYPEDEF
)
116 /* Call for side effects. */
117 check_typedef (elttype
);
119 if (TYPE_TARGET_TYPE (elttype
))
120 elttype
= TYPE_TARGET_TYPE (elttype
);
123 /* Perhaps check_typedef did not update the target type. In
124 this case, force the lookup again and hope it works out.
125 It never will for C, but it might for C++. */
126 CHECK_TYPEDEF (elttype
);
134 *encoding
= charset_for_string_type (result
);
138 /* Return true if print_wchar can display W without resorting to a
139 numeric escape, false otherwise. */
142 wchar_printable (gdb_wchar_t w
)
144 return (gdb_iswprint (w
)
145 || w
== LCST ('\a') || w
== LCST ('\b')
146 || w
== LCST ('\f') || w
== LCST ('\n')
147 || w
== LCST ('\r') || w
== LCST ('\t')
148 || w
== LCST ('\v'));
151 /* A helper function that converts the contents of STRING to wide
152 characters and then appends them to OUTPUT. */
155 append_string_as_wide (const char *string
, struct obstack
*output
)
157 for (; *string
; ++string
)
159 gdb_wchar_t w
= gdb_btowc (*string
);
160 obstack_grow (output
, &w
, sizeof (gdb_wchar_t
));
164 /* Print a wide character W to OUTPUT. ORIG is a pointer to the
165 original (target) bytes representing the character, ORIG_LEN is the
166 number of valid bytes. WIDTH is the number of bytes in a base
167 characters of the type. OUTPUT is an obstack to which wide
168 characters are emitted. QUOTER is a (narrow) character indicating
169 the style of quotes surrounding the character to be printed.
170 NEED_ESCAPE is an in/out flag which is used to track numeric
171 escapes across calls. */
174 print_wchar (gdb_wint_t w
, const gdb_byte
*orig
, int orig_len
,
175 int width
, struct obstack
*output
, int quoter
,
178 int need_escape
= *need_escapep
;
180 if (gdb_iswprint (w
) && (!need_escape
|| (!gdb_iswdigit (w
)
182 && w
!= LCST ('9'))))
184 gdb_wchar_t wchar
= w
;
186 if (w
== gdb_btowc (quoter
) || w
== LCST ('\\'))
187 obstack_grow_wstr (output
, LCST ("\\"));
188 obstack_grow (output
, &wchar
, sizeof (gdb_wchar_t
));
195 obstack_grow_wstr (output
, LCST ("\\a"));
198 obstack_grow_wstr (output
, LCST ("\\b"));
201 obstack_grow_wstr (output
, LCST ("\\f"));
204 obstack_grow_wstr (output
, LCST ("\\n"));
207 obstack_grow_wstr (output
, LCST ("\\r"));
210 obstack_grow_wstr (output
, LCST ("\\t"));
213 obstack_grow_wstr (output
, LCST ("\\v"));
219 for (i
= 0; i
+ width
<= orig_len
; i
+= width
)
222 ULONGEST value
= extract_unsigned_integer (&orig
[i
], width
);
223 sprintf (octal
, "\\%lo", (long) value
);
224 append_string_as_wide (octal
, output
);
226 /* If we somehow have extra bytes, print them now. */
230 sprintf (octal
, "\\%.3o", orig
[i
] & 0xff);
231 append_string_as_wide (octal
, output
);
242 /* Print the character C on STREAM as part of the contents of a literal
243 string whose delimiter is QUOTER. Note that that format for printing
244 characters and strings is language specific. */
247 c_emit_char (int c
, struct type
*type
, struct ui_file
*stream
, int quoter
)
249 struct obstack wchar_buf
, output
;
250 struct cleanup
*cleanups
;
251 const char *encoding
;
253 struct wchar_iterator
*iter
;
256 classify_type (type
, &encoding
);
258 buf
= alloca (TYPE_LENGTH (type
));
259 pack_long (buf
, type
, c
);
261 iter
= make_wchar_iterator (buf
, TYPE_LENGTH (type
), encoding
,
263 cleanups
= make_cleanup_wchar_iterator (iter
);
265 /* This holds the printable form of the wchar_t data. */
266 obstack_init (&wchar_buf
);
267 make_cleanup_obstack_free (&wchar_buf
);
275 int print_escape
= 1;
276 enum wchar_iterate_result result
;
278 num_chars
= wchar_iterate (iter
, &result
, &chars
, &buf
, &buflen
);
283 /* If all characters are printable, print them. Otherwise,
284 we're going to have to print an escape sequence. We
285 check all characters because we want to print the target
286 bytes in the escape sequence, and we don't know character
291 for (i
= 0; i
< num_chars
; ++i
)
292 if (!wchar_printable (chars
[i
]))
300 for (i
= 0; i
< num_chars
; ++i
)
301 print_wchar (chars
[i
], buf
, buflen
, TYPE_LENGTH (type
),
302 &wchar_buf
, quoter
, &need_escape
);
306 /* This handles the NUM_CHARS == 0 case as well. */
308 print_wchar (gdb_WEOF
, buf
, buflen
, TYPE_LENGTH (type
), &wchar_buf
,
309 quoter
, &need_escape
);
312 /* The output in the host encoding. */
313 obstack_init (&output
);
314 make_cleanup_obstack_free (&output
);
316 convert_between_encodings (INTERMEDIATE_ENCODING
, host_charset (),
317 obstack_base (&wchar_buf
),
318 obstack_object_size (&wchar_buf
),
319 1, &output
, translit_char
);
320 obstack_1grow (&output
, '\0');
322 fputs_filtered (obstack_base (&output
), stream
);
324 do_cleanups (cleanups
);
328 c_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
330 enum c_string_type str_type
;
331 const char *encoding
;
333 str_type
= classify_type (type
, &encoding
);
339 fputc_filtered ('L', stream
);
342 fputc_filtered ('u', stream
);
345 fputc_filtered ('U', stream
);
349 fputc_filtered ('\'', stream
);
350 LA_EMIT_CHAR (c
, type
, stream
, '\'');
351 fputc_filtered ('\'', stream
);
354 /* Print the character string STRING, printing at most LENGTH characters.
355 LENGTH is -1 if the string is nul terminated. Each character is WIDTH bytes
356 long. Printing stops early if the number hits print_max; repeat counts are
357 printed as appropriate. Print ellipses at the end if we had to stop before
358 printing LENGTH characters, or if FORCE_ELLIPSES. */
361 c_printstr (struct ui_file
*stream
, struct type
*type
, const gdb_byte
*string
,
362 unsigned int length
, int force_ellipses
,
363 const struct value_print_options
*options
)
366 unsigned int things_printed
= 0;
369 int width
= TYPE_LENGTH (type
);
370 struct obstack wchar_buf
, output
;
371 struct cleanup
*cleanup
;
372 enum c_string_type str_type
;
373 const char *encoding
;
374 struct wchar_iterator
*iter
;
378 /* If the string was not truncated due to `set print elements', and
379 the last byte of it is a null, we don't print that, in traditional C
383 && (extract_unsigned_integer (string
+ (length
- 1) * width
, width
) == 0))
386 str_type
= classify_type (type
, &encoding
) & ~C_CHAR
;
392 fputs_filtered ("L", stream
);
395 fputs_filtered ("u", stream
);
398 fputs_filtered ("U", stream
);
404 fputs_filtered ("\"\"", stream
);
410 unsigned long current_char
= 1;
411 for (i
= 0; current_char
; ++i
)
414 current_char
= extract_unsigned_integer (string
+ i
* width
, width
);
419 /* Arrange to iterate over the characters, in wchar_t form. */
420 iter
= make_wchar_iterator (string
, length
* width
, encoding
, width
);
421 cleanup
= make_cleanup_wchar_iterator (iter
);
423 /* WCHAR_BUF is the obstack we use to represent the string in
425 obstack_init (&wchar_buf
);
426 make_cleanup_obstack_free (&wchar_buf
);
428 while (!finished
&& things_printed
< options
->print_max
)
431 enum wchar_iterate_result result
;
440 obstack_grow_wstr (&wchar_buf
, LCST (", "));
444 num_chars
= wchar_iterate (iter
, &result
, &chars
, &buf
, &buflen
);
445 /* We only look at repetitions when we were able to convert a
446 single character in isolation. This makes the code simpler
447 and probably does the sensible thing in the majority of
449 while (num_chars
== 1)
451 /* Count the number of repetitions. */
452 unsigned int reps
= 0;
453 gdb_wchar_t current_char
= chars
[0];
454 const gdb_byte
*orig_buf
= buf
;
455 int orig_len
= buflen
;
459 obstack_grow_wstr (&wchar_buf
, LCST (", "));
463 while (num_chars
== 1 && current_char
== chars
[0])
465 num_chars
= wchar_iterate (iter
, &result
, &chars
, &buf
, &buflen
);
469 /* Emit CURRENT_CHAR according to the repetition count and
471 if (reps
> options
->repeat_count_threshold
)
475 if (options
->inspect_it
)
476 obstack_grow_wstr (&wchar_buf
, LCST ("\\\", "));
478 obstack_grow_wstr (&wchar_buf
, LCST ("\", "));
481 obstack_grow_wstr (&wchar_buf
, LCST ("'"));
483 print_wchar (current_char
, orig_buf
, orig_len
, width
,
484 &wchar_buf
, '\'', &need_escape
);
485 obstack_grow_wstr (&wchar_buf
, LCST ("'"));
487 /* Painful gyrations. */
489 char *s
= xstrprintf (_(" <repeats %u times>"), reps
);
490 for (j
= 0; s
[j
]; ++j
)
492 gdb_wchar_t w
= gdb_btowc (s
[j
]);
493 obstack_grow (&wchar_buf
, &w
, sizeof (gdb_wchar_t
));
497 things_printed
+= options
->repeat_count_threshold
;
502 /* Saw the character one or more times, but fewer than
503 the repetition threshold. */
506 if (options
->inspect_it
)
507 obstack_grow_wstr (&wchar_buf
, LCST ("\\\""));
509 obstack_grow_wstr (&wchar_buf
, LCST ("\""));
516 print_wchar (current_char
, orig_buf
, orig_len
, width
,
517 &wchar_buf
, '"', &need_escape
);
523 /* NUM_CHARS and the other outputs from wchar_iterate are valid
524 here regardless of which branch was taken above. */
534 case wchar_iterate_invalid
:
537 if (options
->inspect_it
)
538 obstack_grow_wstr (&wchar_buf
, LCST ("\\\""));
540 obstack_grow_wstr (&wchar_buf
, LCST ("\""));
544 print_wchar (gdb_WEOF
, buf
, buflen
, width
, &wchar_buf
,
548 case wchar_iterate_incomplete
:
551 if (options
->inspect_it
)
552 obstack_grow_wstr (&wchar_buf
, LCST ("\\\","));
554 obstack_grow_wstr (&wchar_buf
, LCST ("\","));
557 obstack_grow_wstr (&wchar_buf
, LCST (" <incomplete sequence "));
558 print_wchar (gdb_WEOF
, buf
, buflen
, width
, &wchar_buf
,
560 obstack_grow_wstr (&wchar_buf
, LCST (">"));
566 /* Terminate the quotes if necessary. */
569 if (options
->inspect_it
)
570 obstack_grow_wstr (&wchar_buf
, LCST ("\\\""));
572 obstack_grow_wstr (&wchar_buf
, LCST ("\""));
575 if (force_ellipses
|| !finished
)
576 obstack_grow_wstr (&wchar_buf
, LCST ("..."));
578 /* OUTPUT is where we collect `char's for printing. */
579 obstack_init (&output
);
580 make_cleanup_obstack_free (&output
);
582 convert_between_encodings (INTERMEDIATE_ENCODING
, host_charset (),
583 obstack_base (&wchar_buf
),
584 obstack_object_size (&wchar_buf
),
585 1, &output
, translit_char
);
586 obstack_1grow (&output
, '\0');
588 fputs_filtered (obstack_base (&output
), stream
);
590 do_cleanups (cleanup
);
593 /* Obtain a C string from the inferior storing it in a newly allocated
594 buffer in BUFFER, which should be freed by the caller. The string is
595 read until a null character is found. If VALUE is an array with known
596 length, the function will not read past the end of the array. LENGTH
597 will contain the size of the string in bytes (not counting the null
600 Assumes strings are terminated by a null character. The size of a character
601 is determined by the length of the target type of the pointer or array.
602 This means that a null byte present in a multi-byte character will not
603 terminate the string unless the whole character is null.
605 CHARSET is always set to the target charset. */
608 c_get_string (struct value
*value
, gdb_byte
**buffer
, int *length
,
609 const char **charset
)
612 unsigned int fetchlimit
;
613 struct type
*type
= check_typedef (value_type (value
));
614 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
616 if (element_type
== NULL
)
619 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
621 /* If we know the size of the array, we can use it as a limit on the
622 number of characters to be fetched. */
623 if (TYPE_NFIELDS (type
) == 1
624 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_RANGE
)
626 LONGEST low_bound
, high_bound
;
628 get_discrete_bounds (TYPE_FIELD_TYPE (type
, 0),
629 &low_bound
, &high_bound
);
630 fetchlimit
= high_bound
- low_bound
+ 1;
633 fetchlimit
= UINT_MAX
;
635 else if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
636 fetchlimit
= UINT_MAX
;
638 /* We work only with arrays and pointers. */
641 element_type
= check_typedef (element_type
);
642 if (TYPE_CODE (element_type
) != TYPE_CODE_INT
643 && TYPE_CODE (element_type
) != TYPE_CODE_CHAR
)
644 /* If the elements are not integers or characters, we don't consider it
648 width
= TYPE_LENGTH (element_type
);
650 /* If the string lives in GDB's memory intead of the inferior's, then we
651 just need to copy it to BUFFER. Also, since such strings are arrays
652 with known size, FETCHLIMIT will hold the size of the array. */
653 if ((VALUE_LVAL (value
) == not_lval
654 || VALUE_LVAL (value
) == lval_internalvar
)
655 && fetchlimit
!= UINT_MAX
)
658 const gdb_byte
*contents
= value_contents (value
);
660 /* Look for a null character. */
661 for (i
= 0; i
< fetchlimit
; i
++)
662 if (extract_unsigned_integer (contents
+ i
* width
, width
) == 0)
665 /* I is now either the number of non-null characters, or FETCHLIMIT. */
667 *buffer
= xmalloc (*length
);
668 memcpy (*buffer
, contents
, *length
);
673 err
= read_string (value_as_address (value
), -1, width
, fetchlimit
,
678 error (_("Error reading string from inferior: %s"),
679 safe_strerror (err
));
683 /* If the last character is null, subtract it from LENGTH. */
685 && extract_unsigned_integer (*buffer
+ *length
- width
, width
) == 0)
688 *charset
= target_charset ();
696 type_str
= type_to_string (type
);
699 make_cleanup (xfree
, type_str
);
700 error (_("Trying to read string with inappropriate type `%s'."),
704 error (_("Trying to read string with inappropriate type."));
709 /* Evaluating C and C++ expressions. */
711 /* Convert a UCN. The digits of the UCN start at P and extend no
712 farther than LIMIT. DEST_CHARSET is the name of the character set
713 into which the UCN should be converted. The results are written to
714 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
715 Returns a pointer to just after the final digit of the UCN. */
718 convert_ucn (char *p
, char *limit
, const char *dest_charset
,
719 struct obstack
*output
, int length
)
721 unsigned long result
= 0;
725 for (i
= 0; i
< length
&& p
< limit
&& isxdigit (*p
); ++i
, ++p
)
726 result
= (result
<< 4) + host_hex_value (*p
);
728 for (i
= 3; i
>= 0; --i
)
730 data
[i
] = result
& 0xff;
734 convert_between_encodings ("UCS-4BE", dest_charset
, data
, 4, 4, output
,
740 /* Emit a character, VALUE, which was specified numerically, to
741 OUTPUT. TYPE is the target character type. */
744 emit_numeric_character (struct type
*type
, unsigned long value
,
745 struct obstack
*output
)
749 buffer
= alloca (TYPE_LENGTH (type
));
750 pack_long (buffer
, type
, value
);
751 obstack_grow (output
, buffer
, TYPE_LENGTH (type
));
754 /* Convert an octal escape sequence. TYPE is the target character
755 type. The digits of the escape sequence begin at P and extend no
756 farther than LIMIT. The result is written to OUTPUT. Returns a
757 pointer to just after the final digit of the escape sequence. */
760 convert_octal (struct type
*type
, char *p
, char *limit
, struct obstack
*output
)
762 unsigned long value
= 0;
764 while (p
< limit
&& isdigit (*p
) && *p
!= '8' && *p
!= '9')
766 value
= 8 * value
+ host_hex_value (*p
);
770 emit_numeric_character (type
, value
, output
);
775 /* Convert a hex escape sequence. TYPE is the target character type.
776 The digits of the escape sequence begin at P and extend no farther
777 than LIMIT. The result is written to OUTPUT. Returns a pointer to
778 just after the final digit of the escape sequence. */
781 convert_hex (struct type
*type
, char *p
, char *limit
, struct obstack
*output
)
783 unsigned long value
= 0;
785 while (p
< limit
&& isxdigit (*p
))
787 value
= 16 * value
+ host_hex_value (*p
);
791 emit_numeric_character (type
, value
, output
);
800 error (_("Malformed escape sequence")); \
803 /* Convert an escape sequence to a target format. TYPE is the target
804 character type to use, and DEST_CHARSET is the name of the target
805 character set. The backslash of the escape sequence is at *P, and
806 the escape sequence will not extend past LIMIT. The results are
807 written to OUTPUT. Returns a pointer to just past the final
808 character of the escape sequence. */
811 convert_escape (struct type
*type
, const char *dest_charset
,
812 char *p
, char *limit
, struct obstack
*output
)
814 /* Skip the backslash. */
820 obstack_1grow (output
, '\\');
827 error (_("\\x used with no following hex digits."));
828 p
= convert_hex (type
, p
, limit
, output
);
839 p
= convert_octal (type
, p
, limit
, output
);
845 int length
= *p
== 'u' ? 4 : 8;
848 error (_("\\u used with no following hex digits"));
849 p
= convert_ucn (p
, limit
, dest_charset
, output
, length
);
856 /* Given a single string from a (C-specific) OP_STRING list, convert
857 it to a target string, handling escape sequences specially. The
858 output is written to OUTPUT. DATA is the input string, which has
859 length LEN. DEST_CHARSET is the name of the target character set,
860 and TYPE is the type of target character to use. */
863 parse_one_string (struct obstack
*output
, char *data
, int len
,
864 const char *dest_charset
, struct type
*type
)
873 /* Look for next escape, or the end of the input. */
874 while (p
< limit
&& *p
!= '\\')
876 /* If we saw a run of characters, convert them all. */
878 convert_between_encodings (host_charset (), dest_charset
,
879 data
, p
- data
, 1, output
, translit_none
);
880 /* If we saw an escape, convert it. */
882 p
= convert_escape (type
, dest_charset
, p
, limit
, output
);
887 /* Expression evaluator for the C language family. Most operations
888 are delegated to evaluate_subexp_standard; see that function for a
889 description of the arguments. */
891 static struct value
*
892 evaluate_subexp_c (struct type
*expect_type
, struct expression
*exp
,
893 int *pos
, enum noside noside
)
895 enum exp_opcode op
= exp
->elts
[*pos
].opcode
;
903 struct obstack output
;
904 struct cleanup
*cleanup
;
905 struct value
*result
;
906 enum c_string_type dest_type
;
907 const char *dest_charset
;
909 obstack_init (&output
);
910 cleanup
= make_cleanup_obstack_free (&output
);
913 oplen
= longest_to_int (exp
->elts
[*pos
].longconst
);
916 limit
= *pos
+ BYTES_TO_EXP_ELEM (oplen
+ 1);
918 = (enum c_string_type
) longest_to_int (exp
->elts
[*pos
].longconst
);
919 switch (dest_type
& ~C_CHAR
)
922 type
= language_string_char_type (exp
->language_defn
,
926 type
= lookup_typename (exp
->language_defn
, exp
->gdbarch
,
930 type
= lookup_typename (exp
->language_defn
, exp
->gdbarch
,
931 "char16_t", NULL
, 0);
934 type
= lookup_typename (exp
->language_defn
, exp
->gdbarch
,
935 "char32_t", NULL
, 0);
938 internal_error (__FILE__
, __LINE__
, "unhandled c_string_type");
941 /* Ensure TYPE_LENGTH is valid for TYPE. */
942 check_typedef (type
);
944 dest_charset
= charset_for_string_type (dest_type
);
951 len
= longest_to_int (exp
->elts
[*pos
].longconst
);
954 if (noside
!= EVAL_SKIP
)
955 parse_one_string (&output
, &exp
->elts
[*pos
].string
, len
,
957 *pos
+= BYTES_TO_EXP_ELEM (len
);
960 /* Skip the trailing length and opcode. */
963 if (noside
== EVAL_SKIP
)
965 /* Return a dummy value of the appropriate type. */
966 if ((dest_type
& C_CHAR
) != 0)
967 result
= allocate_value (type
);
969 result
= value_cstring ("", 0, type
);
970 do_cleanups (cleanup
);
974 if ((dest_type
& C_CHAR
) != 0)
978 if (obstack_object_size (&output
) != TYPE_LENGTH (type
))
979 error (_("Could not convert character constant to target character set"));
980 value
= unpack_long (type
, obstack_base (&output
));
981 result
= value_from_longest (type
, value
);
986 /* Write the terminating character. */
987 for (i
= 0; i
< TYPE_LENGTH (type
); ++i
)
988 obstack_1grow (&output
, 0);
989 result
= value_cstring (obstack_base (&output
),
990 obstack_object_size (&output
),
993 do_cleanups (cleanup
);
1001 return evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
1006 /* Table mapping opcodes into strings for printing operators
1007 and precedences of the operators. */
1009 const struct op_print c_op_print_tab
[] =
1011 {",", BINOP_COMMA
, PREC_COMMA
, 0},
1012 {"=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
1013 {"||", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
1014 {"&&", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
1015 {"|", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
1016 {"^", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
1017 {"&", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
1018 {"==", BINOP_EQUAL
, PREC_EQUAL
, 0},
1019 {"!=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
1020 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
1021 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
1022 {">", BINOP_GTR
, PREC_ORDER
, 0},
1023 {"<", BINOP_LESS
, PREC_ORDER
, 0},
1024 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
1025 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
1026 {"+", BINOP_ADD
, PREC_ADD
, 0},
1027 {"-", BINOP_SUB
, PREC_ADD
, 0},
1028 {"*", BINOP_MUL
, PREC_MUL
, 0},
1029 {"/", BINOP_DIV
, PREC_MUL
, 0},
1030 {"%", BINOP_REM
, PREC_MUL
, 0},
1031 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
1032 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
1033 {"!", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
1034 {"~", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
1035 {"*", UNOP_IND
, PREC_PREFIX
, 0},
1036 {"&", UNOP_ADDR
, PREC_PREFIX
, 0},
1037 {"sizeof ", UNOP_SIZEOF
, PREC_PREFIX
, 0},
1038 {"++", UNOP_PREINCREMENT
, PREC_PREFIX
, 0},
1039 {"--", UNOP_PREDECREMENT
, PREC_PREFIX
, 0},
1043 enum c_primitive_types
{
1044 c_primitive_type_int
,
1045 c_primitive_type_long
,
1046 c_primitive_type_short
,
1047 c_primitive_type_char
,
1048 c_primitive_type_float
,
1049 c_primitive_type_double
,
1050 c_primitive_type_void
,
1051 c_primitive_type_long_long
,
1052 c_primitive_type_signed_char
,
1053 c_primitive_type_unsigned_char
,
1054 c_primitive_type_unsigned_short
,
1055 c_primitive_type_unsigned_int
,
1056 c_primitive_type_unsigned_long
,
1057 c_primitive_type_unsigned_long_long
,
1058 c_primitive_type_long_double
,
1059 c_primitive_type_complex
,
1060 c_primitive_type_double_complex
,
1061 c_primitive_type_decfloat
,
1062 c_primitive_type_decdouble
,
1063 c_primitive_type_declong
,
1064 nr_c_primitive_types
1068 c_language_arch_info (struct gdbarch
*gdbarch
,
1069 struct language_arch_info
*lai
)
1071 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
1072 lai
->string_char_type
= builtin
->builtin_char
;
1073 lai
->primitive_type_vector
1074 = GDBARCH_OBSTACK_CALLOC (gdbarch
, nr_c_primitive_types
+ 1,
1076 lai
->primitive_type_vector
[c_primitive_type_int
] = builtin
->builtin_int
;
1077 lai
->primitive_type_vector
[c_primitive_type_long
] = builtin
->builtin_long
;
1078 lai
->primitive_type_vector
[c_primitive_type_short
] = builtin
->builtin_short
;
1079 lai
->primitive_type_vector
[c_primitive_type_char
] = builtin
->builtin_char
;
1080 lai
->primitive_type_vector
[c_primitive_type_float
] = builtin
->builtin_float
;
1081 lai
->primitive_type_vector
[c_primitive_type_double
] = builtin
->builtin_double
;
1082 lai
->primitive_type_vector
[c_primitive_type_void
] = builtin
->builtin_void
;
1083 lai
->primitive_type_vector
[c_primitive_type_long_long
] = builtin
->builtin_long_long
;
1084 lai
->primitive_type_vector
[c_primitive_type_signed_char
] = builtin
->builtin_signed_char
;
1085 lai
->primitive_type_vector
[c_primitive_type_unsigned_char
] = builtin
->builtin_unsigned_char
;
1086 lai
->primitive_type_vector
[c_primitive_type_unsigned_short
] = builtin
->builtin_unsigned_short
;
1087 lai
->primitive_type_vector
[c_primitive_type_unsigned_int
] = builtin
->builtin_unsigned_int
;
1088 lai
->primitive_type_vector
[c_primitive_type_unsigned_long
] = builtin
->builtin_unsigned_long
;
1089 lai
->primitive_type_vector
[c_primitive_type_unsigned_long_long
] = builtin
->builtin_unsigned_long_long
;
1090 lai
->primitive_type_vector
[c_primitive_type_long_double
] = builtin
->builtin_long_double
;
1091 lai
->primitive_type_vector
[c_primitive_type_complex
] = builtin
->builtin_complex
;
1092 lai
->primitive_type_vector
[c_primitive_type_double_complex
] = builtin
->builtin_double_complex
;
1093 lai
->primitive_type_vector
[c_primitive_type_decfloat
] = builtin
->builtin_decfloat
;
1094 lai
->primitive_type_vector
[c_primitive_type_decdouble
] = builtin
->builtin_decdouble
;
1095 lai
->primitive_type_vector
[c_primitive_type_declong
] = builtin
->builtin_declong
;
1097 lai
->bool_type_default
= builtin
->builtin_int
;
1100 static const struct exp_descriptor exp_descriptor_c
=
1102 print_subexp_standard
,
1103 operator_length_standard
,
1105 dump_subexp_body_standard
,
1109 const struct language_defn c_language_defn
=
1111 "c", /* Language name */
1122 c_printchar
, /* Print a character constant */
1123 c_printstr
, /* Function to print string constant */
1124 c_emit_char
, /* Print a single char */
1125 c_print_type
, /* Print a type using appropriate syntax */
1126 c_print_typedef
, /* Print a typedef using appropriate syntax */
1127 c_val_print
, /* Print a value using appropriate syntax */
1128 c_value_print
, /* Print a top-level value */
1129 NULL
, /* Language specific skip_trampoline */
1130 NULL
, /* name_of_this */
1131 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1132 basic_lookup_transparent_type
,/* lookup_transparent_type */
1133 NULL
, /* Language specific symbol demangler */
1134 NULL
, /* Language specific class_name_from_physname */
1135 c_op_print_tab
, /* expression operators for printing */
1136 1, /* c-style arrays */
1137 0, /* String lower bound */
1138 default_word_break_characters
,
1139 default_make_symbol_completion_list
,
1140 c_language_arch_info
,
1141 default_print_array_index
,
1142 default_pass_by_reference
,
1147 enum cplus_primitive_types
{
1148 cplus_primitive_type_int
,
1149 cplus_primitive_type_long
,
1150 cplus_primitive_type_short
,
1151 cplus_primitive_type_char
,
1152 cplus_primitive_type_float
,
1153 cplus_primitive_type_double
,
1154 cplus_primitive_type_void
,
1155 cplus_primitive_type_long_long
,
1156 cplus_primitive_type_signed_char
,
1157 cplus_primitive_type_unsigned_char
,
1158 cplus_primitive_type_unsigned_short
,
1159 cplus_primitive_type_unsigned_int
,
1160 cplus_primitive_type_unsigned_long
,
1161 cplus_primitive_type_unsigned_long_long
,
1162 cplus_primitive_type_long_double
,
1163 cplus_primitive_type_complex
,
1164 cplus_primitive_type_double_complex
,
1165 cplus_primitive_type_bool
,
1166 cplus_primitive_type_decfloat
,
1167 cplus_primitive_type_decdouble
,
1168 cplus_primitive_type_declong
,
1169 nr_cplus_primitive_types
1173 cplus_language_arch_info (struct gdbarch
*gdbarch
,
1174 struct language_arch_info
*lai
)
1176 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
1177 lai
->string_char_type
= builtin
->builtin_char
;
1178 lai
->primitive_type_vector
1179 = GDBARCH_OBSTACK_CALLOC (gdbarch
, nr_cplus_primitive_types
+ 1,
1181 lai
->primitive_type_vector
[cplus_primitive_type_int
]
1182 = builtin
->builtin_int
;
1183 lai
->primitive_type_vector
[cplus_primitive_type_long
]
1184 = builtin
->builtin_long
;
1185 lai
->primitive_type_vector
[cplus_primitive_type_short
]
1186 = builtin
->builtin_short
;
1187 lai
->primitive_type_vector
[cplus_primitive_type_char
]
1188 = builtin
->builtin_char
;
1189 lai
->primitive_type_vector
[cplus_primitive_type_float
]
1190 = builtin
->builtin_float
;
1191 lai
->primitive_type_vector
[cplus_primitive_type_double
]
1192 = builtin
->builtin_double
;
1193 lai
->primitive_type_vector
[cplus_primitive_type_void
]
1194 = builtin
->builtin_void
;
1195 lai
->primitive_type_vector
[cplus_primitive_type_long_long
]
1196 = builtin
->builtin_long_long
;
1197 lai
->primitive_type_vector
[cplus_primitive_type_signed_char
]
1198 = builtin
->builtin_signed_char
;
1199 lai
->primitive_type_vector
[cplus_primitive_type_unsigned_char
]
1200 = builtin
->builtin_unsigned_char
;
1201 lai
->primitive_type_vector
[cplus_primitive_type_unsigned_short
]
1202 = builtin
->builtin_unsigned_short
;
1203 lai
->primitive_type_vector
[cplus_primitive_type_unsigned_int
]
1204 = builtin
->builtin_unsigned_int
;
1205 lai
->primitive_type_vector
[cplus_primitive_type_unsigned_long
]
1206 = builtin
->builtin_unsigned_long
;
1207 lai
->primitive_type_vector
[cplus_primitive_type_unsigned_long_long
]
1208 = builtin
->builtin_unsigned_long_long
;
1209 lai
->primitive_type_vector
[cplus_primitive_type_long_double
]
1210 = builtin
->builtin_long_double
;
1211 lai
->primitive_type_vector
[cplus_primitive_type_complex
]
1212 = builtin
->builtin_complex
;
1213 lai
->primitive_type_vector
[cplus_primitive_type_double_complex
]
1214 = builtin
->builtin_double_complex
;
1215 lai
->primitive_type_vector
[cplus_primitive_type_bool
]
1216 = builtin
->builtin_bool
;
1217 lai
->primitive_type_vector
[cplus_primitive_type_decfloat
]
1218 = builtin
->builtin_decfloat
;
1219 lai
->primitive_type_vector
[cplus_primitive_type_decdouble
]
1220 = builtin
->builtin_decdouble
;
1221 lai
->primitive_type_vector
[cplus_primitive_type_declong
]
1222 = builtin
->builtin_declong
;
1224 lai
->bool_type_symbol
= "bool";
1225 lai
->bool_type_default
= builtin
->builtin_bool
;
1228 const struct language_defn cplus_language_defn
=
1230 "c++", /* Language name */
1241 c_printchar
, /* Print a character constant */
1242 c_printstr
, /* Function to print string constant */
1243 c_emit_char
, /* Print a single char */
1244 c_print_type
, /* Print a type using appropriate syntax */
1245 c_print_typedef
, /* Print a typedef using appropriate syntax */
1246 c_val_print
, /* Print a value using appropriate syntax */
1247 c_value_print
, /* Print a top-level value */
1248 cplus_skip_trampoline
, /* Language specific skip_trampoline */
1249 "this", /* name_of_this */
1250 cp_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1251 cp_lookup_transparent_type
, /* lookup_transparent_type */
1252 cplus_demangle
, /* Language specific symbol demangler */
1253 cp_class_name_from_physname
, /* Language specific class_name_from_physname */
1254 c_op_print_tab
, /* expression operators for printing */
1255 1, /* c-style arrays */
1256 0, /* String lower bound */
1257 default_word_break_characters
,
1258 default_make_symbol_completion_list
,
1259 cplus_language_arch_info
,
1260 default_print_array_index
,
1261 cp_pass_by_reference
,
1266 const struct language_defn asm_language_defn
=
1268 "asm", /* Language name */
1279 c_printchar
, /* Print a character constant */
1280 c_printstr
, /* Function to print string constant */
1281 c_emit_char
, /* Print a single char */
1282 c_print_type
, /* Print a type using appropriate syntax */
1283 c_print_typedef
, /* Print a typedef using appropriate syntax */
1284 c_val_print
, /* Print a value using appropriate syntax */
1285 c_value_print
, /* Print a top-level value */
1286 NULL
, /* Language specific skip_trampoline */
1287 NULL
, /* name_of_this */
1288 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1289 basic_lookup_transparent_type
,/* lookup_transparent_type */
1290 NULL
, /* Language specific symbol demangler */
1291 NULL
, /* Language specific class_name_from_physname */
1292 c_op_print_tab
, /* expression operators for printing */
1293 1, /* c-style arrays */
1294 0, /* String lower bound */
1295 default_word_break_characters
,
1296 default_make_symbol_completion_list
,
1297 c_language_arch_info
, /* FIXME: la_language_arch_info. */
1298 default_print_array_index
,
1299 default_pass_by_reference
,
1304 /* The following language_defn does not represent a real language.
1305 It just provides a minimal support a-la-C that should allow users
1306 to do some simple operations when debugging applications that use
1307 a language currently not supported by GDB. */
1309 const struct language_defn minimal_language_defn
=
1311 "minimal", /* Language name */
1322 c_printchar
, /* Print a character constant */
1323 c_printstr
, /* Function to print string constant */
1324 c_emit_char
, /* Print a single char */
1325 c_print_type
, /* Print a type using appropriate syntax */
1326 c_print_typedef
, /* Print a typedef using appropriate syntax */
1327 c_val_print
, /* Print a value using appropriate syntax */
1328 c_value_print
, /* Print a top-level value */
1329 NULL
, /* Language specific skip_trampoline */
1330 NULL
, /* name_of_this */
1331 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1332 basic_lookup_transparent_type
,/* lookup_transparent_type */
1333 NULL
, /* Language specific symbol demangler */
1334 NULL
, /* Language specific class_name_from_physname */
1335 c_op_print_tab
, /* expression operators for printing */
1336 1, /* c-style arrays */
1337 0, /* String lower bound */
1338 default_word_break_characters
,
1339 default_make_symbol_completion_list
,
1340 c_language_arch_info
,
1341 default_print_array_index
,
1342 default_pass_by_reference
,
1348 _initialize_c_language (void)
1350 add_language (&c_language_defn
);
1351 add_language (&cplus_language_defn
);
1352 add_language (&asm_language_defn
);
1353 add_language (&minimal_language_defn
);