1 /* C language support routines for GDB, the GNU debugger.
3 Copyright (C) 1992-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "expression.h"
24 #include "parser-defs.h"
29 #include "macroscope.h"
33 #include "cp-support.h"
34 #include "gdb_obstack.h"
38 extern void _initialize_c_language (void);
40 /* Given a C string type, STR_TYPE, return the corresponding target
41 character set name. */
44 charset_for_string_type (enum c_string_type str_type,
45 struct gdbarch *gdbarch)
47 switch (str_type & ~C_CHAR)
50 return target_charset (gdbarch);
52 return target_wide_charset (gdbarch);
54 /* FIXME: UTF-16 is not always correct. */
55 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
60 /* FIXME: UTF-32 is not always correct. */
61 if (gdbarch_byte_order (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 in target BYTE_ORDER to the host character
75 static enum c_string_type
76 classify_type (struct type *elttype, struct gdbarch *gdbarch,
77 const char **encoding)
79 enum c_string_type result;
81 /* We loop because ELTTYPE may be a typedef, and we want to
82 successively peel each typedef until we reach a type we
83 understand. We don't use CHECK_TYPEDEF because that will strip
84 all typedefs at once -- but in C, wchar_t is itself a typedef, so
85 that would do the wrong thing. */
88 const char *name = TYPE_NAME (elttype);
90 if (TYPE_CODE (elttype) == TYPE_CODE_CHAR || !name)
96 if (!strcmp (name, "wchar_t"))
102 if (!strcmp (name, "char16_t"))
108 if (!strcmp (name, "char32_t"))
114 if (TYPE_CODE (elttype) != TYPE_CODE_TYPEDEF)
117 /* Call for side effects. */
118 check_typedef (elttype);
120 if (TYPE_TARGET_TYPE (elttype))
121 elttype = TYPE_TARGET_TYPE (elttype);
124 /* Perhaps check_typedef did not update the target type. In
125 this case, force the lookup again and hope it works out.
126 It never will for C, but it might for C++. */
127 CHECK_TYPEDEF (elttype);
136 *encoding = charset_for_string_type (result, gdbarch);
141 /* Print the character C on STREAM as part of the contents of a
142 literal string whose delimiter is QUOTER. Note that that format
143 for printing characters and strings is language specific. */
146 c_emit_char (int c, struct type *type,
147 struct ui_file *stream, int quoter)
149 const char *encoding;
151 classify_type (type, get_type_arch (type), &encoding);
152 generic_emit_char (c, type, stream, quoter, encoding);
156 c_printchar (int c, struct type *type, struct ui_file *stream)
158 enum c_string_type str_type;
160 str_type = classify_type (type, get_type_arch (type), NULL);
166 fputc_filtered ('L', stream);
169 fputc_filtered ('u', stream);
172 fputc_filtered ('U', stream);
176 fputc_filtered ('\'', stream);
177 LA_EMIT_CHAR (c, type, stream, '\'');
178 fputc_filtered ('\'', stream);
181 /* Print the character string STRING, printing at most LENGTH
182 characters. LENGTH is -1 if the string is nul terminated. Each
183 character is WIDTH bytes long. Printing stops early if the number
184 hits print_max; repeat counts are printed as appropriate. Print
185 ellipses at the end if we had to stop before printing LENGTH
186 characters, or if FORCE_ELLIPSES. */
189 c_printstr (struct ui_file *stream, struct type *type,
190 const gdb_byte *string, unsigned int length,
191 const char *user_encoding, int force_ellipses,
192 const struct value_print_options *options)
194 enum c_string_type str_type;
195 const char *type_encoding;
196 const char *encoding;
198 str_type = (classify_type (type, get_type_arch (type), &type_encoding)
205 fputs_filtered ("L", stream);
208 fputs_filtered ("u", stream);
211 fputs_filtered ("U", stream);
215 encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding;
217 generic_printstr (stream, type, string, length, encoding, force_ellipses,
221 /* Obtain a C string from the inferior storing it in a newly allocated
222 buffer in BUFFER, which should be freed by the caller. If the in-
223 and out-parameter *LENGTH is specified at -1, the string is read
224 until a null character of the appropriate width is found, otherwise
225 the string is read to the length of characters specified. The size
226 of a character is determined by the length of the target type of
227 the pointer or array.
229 If VALUE is an array with a known length, and *LENGTH is -1,
230 the function will not read past the end of the array. However, any
231 declared size of the array is ignored if *LENGTH > 0.
233 On completion, *LENGTH will be set to the size of the string read in
234 characters. (If a length of -1 is specified, the length returned
235 will not include the null character). CHARSET is always set to the
239 c_get_string (struct value *value, gdb_byte **buffer,
240 int *length, struct type **char_type,
241 const char **charset)
244 unsigned int fetchlimit;
245 struct type *type = check_typedef (value_type (value));
246 struct type *element_type = TYPE_TARGET_TYPE (type);
247 int req_length = *length;
248 enum bfd_endian byte_order
249 = gdbarch_byte_order (get_type_arch (type));
251 if (element_type == NULL)
254 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
256 /* If we know the size of the array, we can use it as a limit on
257 the number of characters to be fetched. */
258 if (TYPE_NFIELDS (type) == 1
259 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
261 LONGEST low_bound, high_bound;
263 get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
264 &low_bound, &high_bound);
265 fetchlimit = high_bound - low_bound + 1;
268 fetchlimit = UINT_MAX;
270 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
271 fetchlimit = UINT_MAX;
273 /* We work only with arrays and pointers. */
276 if (! c_textual_element_type (element_type, 0))
278 classify_type (element_type, get_type_arch (element_type), charset);
279 width = TYPE_LENGTH (element_type);
281 /* If the string lives in GDB's memory instead of the inferior's,
282 then we just need to copy it to BUFFER. Also, since such strings
283 are arrays with known size, FETCHLIMIT will hold the size of the
285 if ((VALUE_LVAL (value) == not_lval
286 || VALUE_LVAL (value) == lval_internalvar)
287 && fetchlimit != UINT_MAX)
290 const gdb_byte *contents = value_contents (value);
292 /* If a length is specified, use that. */
296 /* Otherwise, look for a null character. */
297 for (i = 0; i < fetchlimit; i++)
298 if (extract_unsigned_integer (contents + i * width,
299 width, byte_order) == 0)
302 /* I is now either a user-defined length, the number of non-null
303 characters, or FETCHLIMIT. */
305 *buffer = xmalloc (*length);
306 memcpy (*buffer, contents, *length);
311 CORE_ADDR addr = value_as_address (value);
313 /* Prior to the fix for PR 16196 read_string would ignore fetchlimit
314 if length > 0. The old "broken" behaviour is the behaviour we want:
315 The caller may want to fetch 100 bytes from a variable length array
316 implemented using the common idiom of having an array of length 1 at
317 the end of a struct. In this case we want to ignore the declared
318 size of the array. However, it's counterintuitive to implement that
319 behaviour in read_string: what does fetchlimit otherwise mean if
320 length > 0. Therefore we implement the behaviour we want here:
321 If *length > 0, don't specify a fetchlimit. This preserves the
322 previous behaviour. We could move this check above where we know
323 whether the array is declared with a fixed size, but we only want
324 to apply this behaviour when calling read_string. PR 16286. */
326 fetchlimit = UINT_MAX;
328 err = read_string (addr, *length, width, fetchlimit,
329 byte_order, buffer, length);
333 memory_error (err, addr);
337 /* If the LENGTH is specified at -1, we want to return the string
338 length up to the terminating null character. If an actual length
339 was specified, we want to return the length of exactly what was
341 if (req_length == -1)
342 /* If the last character is null, subtract it from LENGTH. */
344 && extract_unsigned_integer (*buffer + *length - width,
345 width, byte_order) == 0)
348 /* The read_string function will return the number of bytes read.
349 If length returned from read_string was > 0, return the number of
350 characters read by dividing the number of bytes by width. */
352 *length = *length / width;
354 *char_type = element_type;
362 type_str = type_to_string (type);
365 make_cleanup (xfree, type_str);
366 error (_("Trying to read string with inappropriate type `%s'."),
370 error (_("Trying to read string with inappropriate type."));
375 /* Evaluating C and C++ expressions. */
377 /* Convert a UCN. The digits of the UCN start at P and extend no
378 farther than LIMIT. DEST_CHARSET is the name of the character set
379 into which the UCN should be converted. The results are written to
380 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
381 Returns a pointer to just after the final digit of the UCN. */
384 convert_ucn (char *p, char *limit, const char *dest_charset,
385 struct obstack *output, int length)
387 unsigned long result = 0;
391 for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p)
392 result = (result << 4) + host_hex_value (*p);
394 for (i = 3; i >= 0; --i)
396 data[i] = result & 0xff;
400 convert_between_encodings ("UTF-32BE", dest_charset, data,
401 4, 4, output, translit_none);
406 /* Emit a character, VALUE, which was specified numerically, to
407 OUTPUT. TYPE is the target character type. */
410 emit_numeric_character (struct type *type, unsigned long value,
411 struct obstack *output)
415 buffer = alloca (TYPE_LENGTH (type));
416 pack_long (buffer, type, value);
417 obstack_grow (output, buffer, TYPE_LENGTH (type));
420 /* Convert an octal escape sequence. TYPE is the target character
421 type. The digits of the escape sequence begin at P and extend no
422 farther than LIMIT. The result is written to OUTPUT. Returns a
423 pointer to just after the final digit of the escape sequence. */
426 convert_octal (struct type *type, char *p,
427 char *limit, struct obstack *output)
430 unsigned long value = 0;
433 i < 3 && p < limit && isdigit (*p) && *p != '8' && *p != '9';
436 value = 8 * value + host_hex_value (*p);
440 emit_numeric_character (type, value, output);
445 /* Convert a hex escape sequence. TYPE is the target character type.
446 The digits of the escape sequence begin at P and extend no farther
447 than LIMIT. The result is written to OUTPUT. Returns a pointer to
448 just after the final digit of the escape sequence. */
451 convert_hex (struct type *type, char *p,
452 char *limit, struct obstack *output)
454 unsigned long value = 0;
456 while (p < limit && isxdigit (*p))
458 value = 16 * value + host_hex_value (*p);
462 emit_numeric_character (type, value, output);
471 error (_("Malformed escape sequence")); \
474 /* Convert an escape sequence to a target format. TYPE is the target
475 character type to use, and DEST_CHARSET is the name of the target
476 character set. The backslash of the escape sequence is at *P, and
477 the escape sequence will not extend past LIMIT. The results are
478 written to OUTPUT. Returns a pointer to just past the final
479 character of the escape sequence. */
482 convert_escape (struct type *type, const char *dest_charset,
483 char *p, char *limit, struct obstack *output)
485 /* Skip the backslash. */
491 obstack_1grow (output, '\\');
498 error (_("\\x used with no following hex digits."));
499 p = convert_hex (type, p, limit, output);
510 p = convert_octal (type, p, limit, output);
516 int length = *p == 'u' ? 4 : 8;
520 error (_("\\u used with no following hex digits"));
521 p = convert_ucn (p, limit, dest_charset, output, length);
528 /* Given a single string from a (C-specific) OP_STRING list, convert
529 it to a target string, handling escape sequences specially. The
530 output is written to OUTPUT. DATA is the input string, which has
531 length LEN. DEST_CHARSET is the name of the target character set,
532 and TYPE is the type of target character to use. */
535 parse_one_string (struct obstack *output, char *data, int len,
536 const char *dest_charset, struct type *type)
546 /* Look for next escape, or the end of the input. */
547 while (p < limit && *p != '\\')
549 /* If we saw a run of characters, convert them all. */
551 convert_between_encodings (host_charset (), dest_charset,
552 (gdb_byte *) data, p - data, 1,
553 output, translit_none);
554 /* If we saw an escape, convert it. */
556 p = convert_escape (type, dest_charset, p, limit, output);
561 /* Expression evaluator for the C language family. Most operations
562 are delegated to evaluate_subexp_standard; see that function for a
563 description of the arguments. */
566 evaluate_subexp_c (struct type *expect_type, struct expression *exp,
567 int *pos, enum noside noside)
569 enum exp_opcode op = exp->elts[*pos].opcode;
577 struct obstack output;
578 struct cleanup *cleanup;
579 struct value *result;
580 enum c_string_type dest_type;
581 const char *dest_charset;
582 int satisfy_expected = 0;
584 obstack_init (&output);
585 cleanup = make_cleanup_obstack_free (&output);
588 oplen = longest_to_int (exp->elts[*pos].longconst);
591 limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
593 = (enum c_string_type) longest_to_int (exp->elts[*pos].longconst);
594 switch (dest_type & ~C_CHAR)
597 type = language_string_char_type (exp->language_defn,
601 type = lookup_typename (exp->language_defn, exp->gdbarch,
605 type = lookup_typename (exp->language_defn, exp->gdbarch,
606 "char16_t", NULL, 0);
609 type = lookup_typename (exp->language_defn, exp->gdbarch,
610 "char32_t", NULL, 0);
613 internal_error (__FILE__, __LINE__, _("unhandled c_string_type"));
616 /* Ensure TYPE_LENGTH is valid for TYPE. */
617 check_typedef (type);
619 /* If the caller expects an array of some integral type,
620 satisfy them. If something odder is expected, rely on the
622 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_ARRAY)
624 struct type *element_type
625 = check_typedef (TYPE_TARGET_TYPE (expect_type));
627 if (TYPE_CODE (element_type) == TYPE_CODE_INT
628 || TYPE_CODE (element_type) == TYPE_CODE_CHAR)
631 satisfy_expected = 1;
635 dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
642 len = longest_to_int (exp->elts[*pos].longconst);
645 if (noside != EVAL_SKIP)
646 parse_one_string (&output, &exp->elts[*pos].string, len,
648 *pos += BYTES_TO_EXP_ELEM (len);
651 /* Skip the trailing length and opcode. */
654 if (noside == EVAL_SKIP)
656 /* Return a dummy value of the appropriate type. */
657 if (expect_type != NULL)
658 result = allocate_value (expect_type);
659 else if ((dest_type & C_CHAR) != 0)
660 result = allocate_value (type);
662 result = value_cstring ("", 0, type);
663 do_cleanups (cleanup);
667 if ((dest_type & C_CHAR) != 0)
671 if (obstack_object_size (&output) != TYPE_LENGTH (type))
672 error (_("Could not convert character "
673 "constant to target character set"));
674 value = unpack_long (type, (gdb_byte *) obstack_base (&output));
675 result = value_from_longest (type, value);
681 /* Write the terminating character. */
682 for (i = 0; i < TYPE_LENGTH (type); ++i)
683 obstack_1grow (&output, 0);
685 if (satisfy_expected)
687 LONGEST low_bound, high_bound;
688 int element_size = TYPE_LENGTH (type);
690 if (get_discrete_bounds (TYPE_INDEX_TYPE (expect_type),
691 &low_bound, &high_bound) < 0)
694 high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1;
696 if (obstack_object_size (&output) / element_size
697 > (high_bound - low_bound + 1))
698 error (_("Too many array elements"));
700 result = allocate_value (expect_type);
701 memcpy (value_contents_raw (result), obstack_base (&output),
702 obstack_object_size (&output));
705 result = value_cstring (obstack_base (&output),
706 obstack_object_size (&output),
709 do_cleanups (cleanup);
717 return evaluate_subexp_standard (expect_type, exp, pos, noside);
722 /* Table mapping opcodes into strings for printing operators
723 and precedences of the operators. */
725 const struct op_print c_op_print_tab[] =
727 {",", BINOP_COMMA, PREC_COMMA, 0},
728 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
729 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
730 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
731 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
732 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
733 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
734 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
735 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
736 {"<=", BINOP_LEQ, PREC_ORDER, 0},
737 {">=", BINOP_GEQ, PREC_ORDER, 0},
738 {">", BINOP_GTR, PREC_ORDER, 0},
739 {"<", BINOP_LESS, PREC_ORDER, 0},
740 {">>", BINOP_RSH, PREC_SHIFT, 0},
741 {"<<", BINOP_LSH, PREC_SHIFT, 0},
742 {"+", BINOP_ADD, PREC_ADD, 0},
743 {"-", BINOP_SUB, PREC_ADD, 0},
744 {"*", BINOP_MUL, PREC_MUL, 0},
745 {"/", BINOP_DIV, PREC_MUL, 0},
746 {"%", BINOP_REM, PREC_MUL, 0},
747 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
748 {"+", UNOP_PLUS, PREC_PREFIX, 0},
749 {"-", UNOP_NEG, PREC_PREFIX, 0},
750 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
751 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
752 {"*", UNOP_IND, PREC_PREFIX, 0},
753 {"&", UNOP_ADDR, PREC_PREFIX, 0},
754 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
755 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
756 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
760 enum c_primitive_types {
761 c_primitive_type_int,
762 c_primitive_type_long,
763 c_primitive_type_short,
764 c_primitive_type_char,
765 c_primitive_type_float,
766 c_primitive_type_double,
767 c_primitive_type_void,
768 c_primitive_type_long_long,
769 c_primitive_type_signed_char,
770 c_primitive_type_unsigned_char,
771 c_primitive_type_unsigned_short,
772 c_primitive_type_unsigned_int,
773 c_primitive_type_unsigned_long,
774 c_primitive_type_unsigned_long_long,
775 c_primitive_type_long_double,
776 c_primitive_type_complex,
777 c_primitive_type_double_complex,
778 c_primitive_type_decfloat,
779 c_primitive_type_decdouble,
780 c_primitive_type_declong,
785 c_language_arch_info (struct gdbarch *gdbarch,
786 struct language_arch_info *lai)
788 const struct builtin_type *builtin = builtin_type (gdbarch);
790 lai->string_char_type = builtin->builtin_char;
791 lai->primitive_type_vector
792 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
794 lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int;
795 lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long;
796 lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short;
797 lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char;
798 lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float;
799 lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double;
800 lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void;
801 lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long;
802 lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char;
803 lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char;
804 lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short;
805 lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int;
806 lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long;
807 lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long;
808 lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double;
809 lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex;
810 lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex;
811 lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat;
812 lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble;
813 lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong;
815 lai->bool_type_default = builtin->builtin_int;
818 const struct exp_descriptor exp_descriptor_c =
820 print_subexp_standard,
821 operator_length_standard,
822 operator_check_standard,
824 dump_subexp_body_standard,
828 const struct language_defn c_language_defn =
830 "c", /* Language name */
841 c_printchar, /* Print a character constant */
842 c_printstr, /* Function to print string constant */
843 c_emit_char, /* Print a single char */
844 c_print_type, /* Print a type using appropriate syntax */
845 c_print_typedef, /* Print a typedef using appropriate syntax */
846 c_val_print, /* Print a value using appropriate syntax */
847 c_value_print, /* Print a top-level value */
848 default_read_var_value, /* la_read_var_value */
849 NULL, /* Language specific skip_trampoline */
850 NULL, /* name_of_this */
851 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
852 basic_lookup_transparent_type,/* lookup_transparent_type */
853 NULL, /* Language specific symbol demangler */
854 NULL, /* Language specific
855 class_name_from_physname */
856 c_op_print_tab, /* expression operators for printing */
857 1, /* c-style arrays */
858 0, /* String lower bound */
859 default_word_break_characters,
860 default_make_symbol_completion_list,
861 c_language_arch_info,
862 default_print_array_index,
863 default_pass_by_reference,
865 NULL, /* la_get_symbol_name_cmp */
866 iterate_over_symbols,
871 enum cplus_primitive_types {
872 cplus_primitive_type_int,
873 cplus_primitive_type_long,
874 cplus_primitive_type_short,
875 cplus_primitive_type_char,
876 cplus_primitive_type_float,
877 cplus_primitive_type_double,
878 cplus_primitive_type_void,
879 cplus_primitive_type_long_long,
880 cplus_primitive_type_signed_char,
881 cplus_primitive_type_unsigned_char,
882 cplus_primitive_type_unsigned_short,
883 cplus_primitive_type_unsigned_int,
884 cplus_primitive_type_unsigned_long,
885 cplus_primitive_type_unsigned_long_long,
886 cplus_primitive_type_long_double,
887 cplus_primitive_type_complex,
888 cplus_primitive_type_double_complex,
889 cplus_primitive_type_bool,
890 cplus_primitive_type_decfloat,
891 cplus_primitive_type_decdouble,
892 cplus_primitive_type_declong,
893 nr_cplus_primitive_types
897 cplus_language_arch_info (struct gdbarch *gdbarch,
898 struct language_arch_info *lai)
900 const struct builtin_type *builtin = builtin_type (gdbarch);
902 lai->string_char_type = builtin->builtin_char;
903 lai->primitive_type_vector
904 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
906 lai->primitive_type_vector [cplus_primitive_type_int]
907 = builtin->builtin_int;
908 lai->primitive_type_vector [cplus_primitive_type_long]
909 = builtin->builtin_long;
910 lai->primitive_type_vector [cplus_primitive_type_short]
911 = builtin->builtin_short;
912 lai->primitive_type_vector [cplus_primitive_type_char]
913 = builtin->builtin_char;
914 lai->primitive_type_vector [cplus_primitive_type_float]
915 = builtin->builtin_float;
916 lai->primitive_type_vector [cplus_primitive_type_double]
917 = builtin->builtin_double;
918 lai->primitive_type_vector [cplus_primitive_type_void]
919 = builtin->builtin_void;
920 lai->primitive_type_vector [cplus_primitive_type_long_long]
921 = builtin->builtin_long_long;
922 lai->primitive_type_vector [cplus_primitive_type_signed_char]
923 = builtin->builtin_signed_char;
924 lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
925 = builtin->builtin_unsigned_char;
926 lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
927 = builtin->builtin_unsigned_short;
928 lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
929 = builtin->builtin_unsigned_int;
930 lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
931 = builtin->builtin_unsigned_long;
932 lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
933 = builtin->builtin_unsigned_long_long;
934 lai->primitive_type_vector [cplus_primitive_type_long_double]
935 = builtin->builtin_long_double;
936 lai->primitive_type_vector [cplus_primitive_type_complex]
937 = builtin->builtin_complex;
938 lai->primitive_type_vector [cplus_primitive_type_double_complex]
939 = builtin->builtin_double_complex;
940 lai->primitive_type_vector [cplus_primitive_type_bool]
941 = builtin->builtin_bool;
942 lai->primitive_type_vector [cplus_primitive_type_decfloat]
943 = builtin->builtin_decfloat;
944 lai->primitive_type_vector [cplus_primitive_type_decdouble]
945 = builtin->builtin_decdouble;
946 lai->primitive_type_vector [cplus_primitive_type_declong]
947 = builtin->builtin_declong;
949 lai->bool_type_symbol = "bool";
950 lai->bool_type_default = builtin->builtin_bool;
953 const struct language_defn cplus_language_defn =
955 "c++", /* Language name */
966 c_printchar, /* Print a character constant */
967 c_printstr, /* Function to print string constant */
968 c_emit_char, /* Print a single char */
969 c_print_type, /* Print a type using appropriate syntax */
970 c_print_typedef, /* Print a typedef using appropriate syntax */
971 c_val_print, /* Print a value using appropriate syntax */
972 c_value_print, /* Print a top-level value */
973 default_read_var_value, /* la_read_var_value */
974 cplus_skip_trampoline, /* Language specific skip_trampoline */
975 "this", /* name_of_this */
976 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
977 cp_lookup_transparent_type, /* lookup_transparent_type */
978 gdb_demangle, /* Language specific symbol demangler */
979 cp_class_name_from_physname, /* Language specific
980 class_name_from_physname */
981 c_op_print_tab, /* expression operators for printing */
982 1, /* c-style arrays */
983 0, /* String lower bound */
984 default_word_break_characters,
985 default_make_symbol_completion_list,
986 cplus_language_arch_info,
987 default_print_array_index,
988 cp_pass_by_reference,
990 NULL, /* la_get_symbol_name_cmp */
991 iterate_over_symbols,
996 const struct language_defn asm_language_defn =
998 "asm", /* Language name */
1009 c_printchar, /* Print a character constant */
1010 c_printstr, /* Function to print string constant */
1011 c_emit_char, /* Print a single char */
1012 c_print_type, /* Print a type using appropriate syntax */
1013 c_print_typedef, /* Print a typedef using appropriate syntax */
1014 c_val_print, /* Print a value using appropriate syntax */
1015 c_value_print, /* Print a top-level value */
1016 default_read_var_value, /* la_read_var_value */
1017 NULL, /* Language specific skip_trampoline */
1018 NULL, /* name_of_this */
1019 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1020 basic_lookup_transparent_type,/* lookup_transparent_type */
1021 NULL, /* Language specific symbol demangler */
1022 NULL, /* Language specific
1023 class_name_from_physname */
1024 c_op_print_tab, /* expression operators for printing */
1025 1, /* c-style arrays */
1026 0, /* String lower bound */
1027 default_word_break_characters,
1028 default_make_symbol_completion_list,
1029 c_language_arch_info, /* FIXME: la_language_arch_info. */
1030 default_print_array_index,
1031 default_pass_by_reference,
1033 NULL, /* la_get_symbol_name_cmp */
1034 iterate_over_symbols,
1035 &default_varobj_ops,
1039 /* The following language_defn does not represent a real language.
1040 It just provides a minimal support a-la-C that should allow users
1041 to do some simple operations when debugging applications that use
1042 a language currently not supported by GDB. */
1044 const struct language_defn minimal_language_defn =
1046 "minimal", /* Language name */
1057 c_printchar, /* Print a character constant */
1058 c_printstr, /* Function to print string constant */
1059 c_emit_char, /* Print a single char */
1060 c_print_type, /* Print a type using appropriate syntax */
1061 c_print_typedef, /* Print a typedef using appropriate syntax */
1062 c_val_print, /* Print a value using appropriate syntax */
1063 c_value_print, /* Print a top-level value */
1064 default_read_var_value, /* la_read_var_value */
1065 NULL, /* Language specific skip_trampoline */
1066 NULL, /* name_of_this */
1067 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1068 basic_lookup_transparent_type,/* lookup_transparent_type */
1069 NULL, /* Language specific symbol demangler */
1070 NULL, /* Language specific
1071 class_name_from_physname */
1072 c_op_print_tab, /* expression operators for printing */
1073 1, /* c-style arrays */
1074 0, /* String lower bound */
1075 default_word_break_characters,
1076 default_make_symbol_completion_list,
1077 c_language_arch_info,
1078 default_print_array_index,
1079 default_pass_by_reference,
1081 NULL, /* la_get_symbol_name_cmp */
1082 iterate_over_symbols,
1083 &default_varobj_ops,
1088 _initialize_c_language (void)
1090 add_language (&c_language_defn);
1091 add_language (&cplus_language_defn);
1092 add_language (&asm_language_defn);
1093 add_language (&minimal_language_defn);