Fix changelog.
[deliverable/binutils-gdb.git] / gdb / c-lang.c
1 /* C language support routines for GDB, the GNU debugger.
2
3 Copyright (C) 1992-2013 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "expression.h"
24 #include "parser-defs.h"
25 #include "language.h"
26 #include "c-lang.h"
27 #include "valprint.h"
28 #include "macroscope.h"
29 #include "gdb_assert.h"
30 #include "charset.h"
31 #include "gdb_string.h"
32 #include "demangle.h"
33 #include "cp-abi.h"
34 #include "cp-support.h"
35 #include "gdb_obstack.h"
36 #include <ctype.h>
37 #include "exceptions.h"
38 #include "gdbcore.h"
39
40 extern void _initialize_c_language (void);
41
42 /* Given a C string type, STR_TYPE, return the corresponding target
43 character set name. */
44
45 static const char *
46 charset_for_string_type (enum c_string_type str_type,
47 struct gdbarch *gdbarch)
48 {
49 switch (str_type & ~C_CHAR)
50 {
51 case C_STRING:
52 return target_charset (gdbarch);
53 case C_WIDE_STRING:
54 return target_wide_charset (gdbarch);
55 case C_STRING_16:
56 /* FIXME: UTF-16 is not always correct. */
57 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
58 return "UTF-16BE";
59 else
60 return "UTF-16LE";
61 case C_STRING_32:
62 /* FIXME: UTF-32 is not always correct. */
63 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
64 return "UTF-32BE";
65 else
66 return "UTF-32LE";
67 }
68 internal_error (__FILE__, __LINE__, _("unhandled c_string_type"));
69 }
70
71 /* Classify ELTTYPE according to what kind of character it is. Return
72 the enum constant representing the character type. Also set
73 *ENCODING to the name of the character set to use when converting
74 characters of this type in target BYTE_ORDER to the host character
75 set. */
76
77 static enum c_string_type
78 classify_type (struct type *elttype, struct gdbarch *gdbarch,
79 const char **encoding)
80 {
81 enum c_string_type result;
82
83 /* We loop because ELTTYPE may be a typedef, and we want to
84 successively peel each typedef until we reach a type we
85 understand. We don't use CHECK_TYPEDEF because that will strip
86 all typedefs at once -- but in C, wchar_t is itself a typedef, so
87 that would do the wrong thing. */
88 while (elttype)
89 {
90 const char *name = TYPE_NAME (elttype);
91
92 if (TYPE_CODE (elttype) == TYPE_CODE_CHAR || !name)
93 {
94 result = C_CHAR;
95 goto done;
96 }
97
98 if (!strcmp (name, "wchar_t"))
99 {
100 result = C_WIDE_CHAR;
101 goto done;
102 }
103
104 if (!strcmp (name, "char16_t"))
105 {
106 result = C_CHAR_16;
107 goto done;
108 }
109
110 if (!strcmp (name, "char32_t"))
111 {
112 result = C_CHAR_32;
113 goto done;
114 }
115
116 if (TYPE_CODE (elttype) != TYPE_CODE_TYPEDEF)
117 break;
118
119 /* Call for side effects. */
120 check_typedef (elttype);
121
122 if (TYPE_TARGET_TYPE (elttype))
123 elttype = TYPE_TARGET_TYPE (elttype);
124 else
125 {
126 /* Perhaps check_typedef did not update the target type. In
127 this case, force the lookup again and hope it works out.
128 It never will for C, but it might for C++. */
129 CHECK_TYPEDEF (elttype);
130 }
131 }
132
133 /* Punt. */
134 result = C_CHAR;
135
136 done:
137 if (encoding)
138 *encoding = charset_for_string_type (result, gdbarch);
139
140 return result;
141 }
142
143 /* Print the character C on STREAM as part of the contents of a
144 literal string whose delimiter is QUOTER. Note that that format
145 for printing characters and strings is language specific. */
146
147 void
148 c_emit_char (int c, struct type *type,
149 struct ui_file *stream, int quoter)
150 {
151 const char *encoding;
152
153 classify_type (type, get_type_arch (type), &encoding);
154 generic_emit_char (c, type, stream, quoter, encoding);
155 }
156
157 void
158 c_printchar (int c, struct type *type, struct ui_file *stream)
159 {
160 enum c_string_type str_type;
161
162 str_type = classify_type (type, get_type_arch (type), NULL);
163 switch (str_type)
164 {
165 case C_CHAR:
166 break;
167 case C_WIDE_CHAR:
168 fputc_filtered ('L', stream);
169 break;
170 case C_CHAR_16:
171 fputc_filtered ('u', stream);
172 break;
173 case C_CHAR_32:
174 fputc_filtered ('U', stream);
175 break;
176 }
177
178 fputc_filtered ('\'', stream);
179 LA_EMIT_CHAR (c, type, stream, '\'');
180 fputc_filtered ('\'', stream);
181 }
182
183 /* Print the character string STRING, printing at most LENGTH
184 characters. LENGTH is -1 if the string is nul terminated. Each
185 character is WIDTH bytes long. Printing stops early if the number
186 hits print_max; repeat counts are printed as appropriate. Print
187 ellipses at the end if we had to stop before printing LENGTH
188 characters, or if FORCE_ELLIPSES. */
189
190 void
191 c_printstr (struct ui_file *stream, struct type *type,
192 const gdb_byte *string, unsigned int length,
193 const char *user_encoding, int force_ellipses,
194 const struct value_print_options *options)
195 {
196 enum c_string_type str_type;
197 const char *type_encoding;
198 const char *encoding;
199
200 str_type = (classify_type (type, get_type_arch (type), &type_encoding)
201 & ~C_CHAR);
202 switch (str_type)
203 {
204 case C_STRING:
205 break;
206 case C_WIDE_STRING:
207 fputs_filtered ("L", stream);
208 break;
209 case C_STRING_16:
210 fputs_filtered ("u", stream);
211 break;
212 case C_STRING_32:
213 fputs_filtered ("U", stream);
214 break;
215 }
216
217 encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding;
218
219 generic_printstr (stream, type, string, length, encoding, force_ellipses,
220 '"', 1, options);
221 }
222
223 /* Obtain a C string from the inferior storing it in a newly allocated
224 buffer in BUFFER, which should be freed by the caller. If the in-
225 and out-parameter *LENGTH is specified at -1, the string is read
226 until a null character of the appropriate width is found, otherwise
227 the string is read to the length of characters specified. The size
228 of a character is determined by the length of the target type of
229 the pointer or array. If VALUE is an array with a known length,
230 the function will not read past the end of the array. On
231 completion, *LENGTH will be set to the size of the string read in
232 characters. (If a length of -1 is specified, the length returned
233 will not include the null character). CHARSET is always set to the
234 target charset. */
235
236 void
237 c_get_string (struct value *value, gdb_byte **buffer,
238 int *length, struct type **char_type,
239 const char **charset)
240 {
241 int err, width;
242 unsigned int fetchlimit;
243 struct type *type = check_typedef (value_type (value));
244 struct type *element_type = TYPE_TARGET_TYPE (type);
245 int req_length = *length;
246 enum bfd_endian byte_order
247 = gdbarch_byte_order (get_type_arch (type));
248
249 if (element_type == NULL)
250 goto error;
251
252 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
253 {
254 /* If we know the size of the array, we can use it as a limit on
255 the number of characters to be fetched. */
256 if (TYPE_NFIELDS (type) == 1
257 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
258 {
259 LONGEST low_bound, high_bound;
260
261 get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
262 &low_bound, &high_bound);
263 fetchlimit = high_bound - low_bound + 1;
264 }
265 else
266 fetchlimit = UINT_MAX;
267 }
268 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
269 fetchlimit = UINT_MAX;
270 else
271 /* We work only with arrays and pointers. */
272 goto error;
273
274 if (! c_textual_element_type (element_type, 0))
275 goto error;
276 classify_type (element_type, get_type_arch (element_type), charset);
277 width = TYPE_LENGTH (element_type);
278
279 /* If the string lives in GDB's memory instead of the inferior's,
280 then we just need to copy it to BUFFER. Also, since such strings
281 are arrays with known size, FETCHLIMIT will hold the size of the
282 array. */
283 if ((VALUE_LVAL (value) == not_lval
284 || VALUE_LVAL (value) == lval_internalvar)
285 && fetchlimit != UINT_MAX)
286 {
287 int i;
288 const gdb_byte *contents = value_contents (value);
289
290 /* If a length is specified, use that. */
291 if (*length >= 0)
292 i = *length;
293 else
294 /* Otherwise, look for a null character. */
295 for (i = 0; i < fetchlimit; i++)
296 if (extract_unsigned_integer (contents + i * width,
297 width, byte_order) == 0)
298 break;
299
300 /* I is now either a user-defined length, the number of non-null
301 characters, or FETCHLIMIT. */
302 *length = i * width;
303 *buffer = xmalloc (*length);
304 memcpy (*buffer, contents, *length);
305 err = 0;
306 }
307 else
308 {
309 CORE_ADDR addr = value_as_address (value);
310
311 err = read_string (addr, *length, width, fetchlimit,
312 byte_order, buffer, length);
313 if (err)
314 {
315 xfree (*buffer);
316 memory_error (err, addr);
317 }
318 }
319
320 /* If the LENGTH is specified at -1, we want to return the string
321 length up to the terminating null character. If an actual length
322 was specified, we want to return the length of exactly what was
323 read. */
324 if (req_length == -1)
325 /* If the last character is null, subtract it from LENGTH. */
326 if (*length > 0
327 && extract_unsigned_integer (*buffer + *length - width,
328 width, byte_order) == 0)
329 *length -= width;
330
331 /* The read_string function will return the number of bytes read.
332 If length returned from read_string was > 0, return the number of
333 characters read by dividing the number of bytes by width. */
334 if (*length != 0)
335 *length = *length / width;
336
337 *char_type = element_type;
338
339 return;
340
341 error:
342 {
343 char *type_str;
344
345 type_str = type_to_string (type);
346 if (type_str)
347 {
348 make_cleanup (xfree, type_str);
349 error (_("Trying to read string with inappropriate type `%s'."),
350 type_str);
351 }
352 else
353 error (_("Trying to read string with inappropriate type."));
354 }
355 }
356
357 \f
358 /* Evaluating C and C++ expressions. */
359
360 /* Convert a UCN. The digits of the UCN start at P and extend no
361 farther than LIMIT. DEST_CHARSET is the name of the character set
362 into which the UCN should be converted. The results are written to
363 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
364 Returns a pointer to just after the final digit of the UCN. */
365
366 static char *
367 convert_ucn (char *p, char *limit, const char *dest_charset,
368 struct obstack *output, int length)
369 {
370 unsigned long result = 0;
371 gdb_byte data[4];
372 int i;
373
374 for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p)
375 result = (result << 4) + host_hex_value (*p);
376
377 for (i = 3; i >= 0; --i)
378 {
379 data[i] = result & 0xff;
380 result >>= 8;
381 }
382
383 convert_between_encodings ("UTF-32BE", dest_charset, data,
384 4, 4, output, translit_none);
385
386 return p;
387 }
388
389 /* Emit a character, VALUE, which was specified numerically, to
390 OUTPUT. TYPE is the target character type. */
391
392 static void
393 emit_numeric_character (struct type *type, unsigned long value,
394 struct obstack *output)
395 {
396 gdb_byte *buffer;
397
398 buffer = alloca (TYPE_LENGTH (type));
399 pack_long (buffer, type, value);
400 obstack_grow (output, buffer, TYPE_LENGTH (type));
401 }
402
403 /* Convert an octal escape sequence. TYPE is the target character
404 type. The digits of the escape sequence begin at P and extend no
405 farther than LIMIT. The result is written to OUTPUT. Returns a
406 pointer to just after the final digit of the escape sequence. */
407
408 static char *
409 convert_octal (struct type *type, char *p,
410 char *limit, struct obstack *output)
411 {
412 int i;
413 unsigned long value = 0;
414
415 for (i = 0;
416 i < 3 && p < limit && isdigit (*p) && *p != '8' && *p != '9';
417 ++i)
418 {
419 value = 8 * value + host_hex_value (*p);
420 ++p;
421 }
422
423 emit_numeric_character (type, value, output);
424
425 return p;
426 }
427
428 /* Convert a hex escape sequence. TYPE is the target character type.
429 The digits of the escape sequence begin at P and extend no farther
430 than LIMIT. The result is written to OUTPUT. Returns a pointer to
431 just after the final digit of the escape sequence. */
432
433 static char *
434 convert_hex (struct type *type, char *p,
435 char *limit, struct obstack *output)
436 {
437 unsigned long value = 0;
438
439 while (p < limit && isxdigit (*p))
440 {
441 value = 16 * value + host_hex_value (*p);
442 ++p;
443 }
444
445 emit_numeric_character (type, value, output);
446
447 return p;
448 }
449
450 #define ADVANCE \
451 do { \
452 ++p; \
453 if (p == limit) \
454 error (_("Malformed escape sequence")); \
455 } while (0)
456
457 /* Convert an escape sequence to a target format. TYPE is the target
458 character type to use, and DEST_CHARSET is the name of the target
459 character set. The backslash of the escape sequence is at *P, and
460 the escape sequence will not extend past LIMIT. The results are
461 written to OUTPUT. Returns a pointer to just past the final
462 character of the escape sequence. */
463
464 static char *
465 convert_escape (struct type *type, const char *dest_charset,
466 char *p, char *limit, struct obstack *output)
467 {
468 /* Skip the backslash. */
469 ADVANCE;
470
471 switch (*p)
472 {
473 case '\\':
474 obstack_1grow (output, '\\');
475 ++p;
476 break;
477
478 case 'x':
479 ADVANCE;
480 if (!isxdigit (*p))
481 error (_("\\x used with no following hex digits."));
482 p = convert_hex (type, p, limit, output);
483 break;
484
485 case '0':
486 case '1':
487 case '2':
488 case '3':
489 case '4':
490 case '5':
491 case '6':
492 case '7':
493 p = convert_octal (type, p, limit, output);
494 break;
495
496 case 'u':
497 case 'U':
498 {
499 int length = *p == 'u' ? 4 : 8;
500
501 ADVANCE;
502 if (!isxdigit (*p))
503 error (_("\\u used with no following hex digits"));
504 p = convert_ucn (p, limit, dest_charset, output, length);
505 }
506 }
507
508 return p;
509 }
510
511 /* Given a single string from a (C-specific) OP_STRING list, convert
512 it to a target string, handling escape sequences specially. The
513 output is written to OUTPUT. DATA is the input string, which has
514 length LEN. DEST_CHARSET is the name of the target character set,
515 and TYPE is the type of target character to use. */
516
517 static void
518 parse_one_string (struct obstack *output, char *data, int len,
519 const char *dest_charset, struct type *type)
520 {
521 char *limit;
522
523 limit = data + len;
524
525 while (data < limit)
526 {
527 char *p = data;
528
529 /* Look for next escape, or the end of the input. */
530 while (p < limit && *p != '\\')
531 ++p;
532 /* If we saw a run of characters, convert them all. */
533 if (p > data)
534 convert_between_encodings (host_charset (), dest_charset,
535 (gdb_byte *) data, p - data, 1,
536 output, translit_none);
537 /* If we saw an escape, convert it. */
538 if (p < limit)
539 p = convert_escape (type, dest_charset, p, limit, output);
540 data = p;
541 }
542 }
543
544 /* Expression evaluator for the C language family. Most operations
545 are delegated to evaluate_subexp_standard; see that function for a
546 description of the arguments. */
547
548 struct value *
549 evaluate_subexp_c (struct type *expect_type, struct expression *exp,
550 int *pos, enum noside noside)
551 {
552 enum exp_opcode op = exp->elts[*pos].opcode;
553
554 switch (op)
555 {
556 case OP_STRING:
557 {
558 int oplen, limit;
559 struct type *type;
560 struct obstack output;
561 struct cleanup *cleanup;
562 struct value *result;
563 enum c_string_type dest_type;
564 const char *dest_charset;
565 int satisfy_expected = 0;
566
567 obstack_init (&output);
568 cleanup = make_cleanup_obstack_free (&output);
569
570 ++*pos;
571 oplen = longest_to_int (exp->elts[*pos].longconst);
572
573 ++*pos;
574 limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
575 dest_type
576 = (enum c_string_type) longest_to_int (exp->elts[*pos].longconst);
577 switch (dest_type & ~C_CHAR)
578 {
579 case C_STRING:
580 type = language_string_char_type (exp->language_defn,
581 exp->gdbarch);
582 break;
583 case C_WIDE_STRING:
584 type = lookup_typename (exp->language_defn, exp->gdbarch,
585 "wchar_t", NULL, 0);
586 break;
587 case C_STRING_16:
588 type = lookup_typename (exp->language_defn, exp->gdbarch,
589 "char16_t", NULL, 0);
590 break;
591 case C_STRING_32:
592 type = lookup_typename (exp->language_defn, exp->gdbarch,
593 "char32_t", NULL, 0);
594 break;
595 default:
596 internal_error (__FILE__, __LINE__, _("unhandled c_string_type"));
597 }
598
599 /* Ensure TYPE_LENGTH is valid for TYPE. */
600 check_typedef (type);
601
602 /* If the caller expects an array of some integral type,
603 satisfy them. If something odder is expected, rely on the
604 caller to cast. */
605 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_ARRAY)
606 {
607 struct type *element_type
608 = check_typedef (TYPE_TARGET_TYPE (expect_type));
609
610 if (TYPE_CODE (element_type) == TYPE_CODE_INT
611 || TYPE_CODE (element_type) == TYPE_CODE_CHAR)
612 {
613 type = element_type;
614 satisfy_expected = 1;
615 }
616 }
617
618 dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
619
620 ++*pos;
621 while (*pos < limit)
622 {
623 int len;
624
625 len = longest_to_int (exp->elts[*pos].longconst);
626
627 ++*pos;
628 if (noside != EVAL_SKIP)
629 parse_one_string (&output, &exp->elts[*pos].string, len,
630 dest_charset, type);
631 *pos += BYTES_TO_EXP_ELEM (len);
632 }
633
634 /* Skip the trailing length and opcode. */
635 *pos += 2;
636
637 if (noside == EVAL_SKIP)
638 {
639 /* Return a dummy value of the appropriate type. */
640 if (expect_type != NULL)
641 result = allocate_value (expect_type);
642 else if ((dest_type & C_CHAR) != 0)
643 result = allocate_value (type);
644 else
645 result = value_cstring ("", 0, type);
646 do_cleanups (cleanup);
647 return result;
648 }
649
650 if ((dest_type & C_CHAR) != 0)
651 {
652 LONGEST value;
653
654 if (obstack_object_size (&output) != TYPE_LENGTH (type))
655 error (_("Could not convert character "
656 "constant to target character set"));
657 value = unpack_long (type, (gdb_byte *) obstack_base (&output));
658 result = value_from_longest (type, value);
659 }
660 else
661 {
662 int i;
663
664 /* Write the terminating character. */
665 for (i = 0; i < TYPE_LENGTH (type); ++i)
666 obstack_1grow (&output, 0);
667
668 if (satisfy_expected)
669 {
670 LONGEST low_bound, high_bound;
671 int element_size = TYPE_LENGTH (type);
672
673 if (get_discrete_bounds (TYPE_INDEX_TYPE (expect_type),
674 &low_bound, &high_bound) < 0)
675 {
676 low_bound = 0;
677 high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1;
678 }
679 if (obstack_object_size (&output) / element_size
680 > (high_bound - low_bound + 1))
681 error (_("Too many array elements"));
682
683 result = allocate_value (expect_type);
684 memcpy (value_contents_raw (result), obstack_base (&output),
685 obstack_object_size (&output));
686 }
687 else
688 result = value_cstring (obstack_base (&output),
689 obstack_object_size (&output),
690 type);
691 }
692 do_cleanups (cleanup);
693 return result;
694 }
695 break;
696
697 default:
698 break;
699 }
700 return evaluate_subexp_standard (expect_type, exp, pos, noside);
701 }
702
703
704 \f
705 /* Table mapping opcodes into strings for printing operators
706 and precedences of the operators. */
707
708 const struct op_print c_op_print_tab[] =
709 {
710 {",", BINOP_COMMA, PREC_COMMA, 0},
711 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
712 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
713 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
714 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
715 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
716 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
717 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
718 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
719 {"<=", BINOP_LEQ, PREC_ORDER, 0},
720 {">=", BINOP_GEQ, PREC_ORDER, 0},
721 {">", BINOP_GTR, PREC_ORDER, 0},
722 {"<", BINOP_LESS, PREC_ORDER, 0},
723 {">>", BINOP_RSH, PREC_SHIFT, 0},
724 {"<<", BINOP_LSH, PREC_SHIFT, 0},
725 {"+", BINOP_ADD, PREC_ADD, 0},
726 {"-", BINOP_SUB, PREC_ADD, 0},
727 {"*", BINOP_MUL, PREC_MUL, 0},
728 {"/", BINOP_DIV, PREC_MUL, 0},
729 {"%", BINOP_REM, PREC_MUL, 0},
730 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
731 {"+", UNOP_PLUS, PREC_PREFIX, 0},
732 {"-", UNOP_NEG, PREC_PREFIX, 0},
733 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
734 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
735 {"*", UNOP_IND, PREC_PREFIX, 0},
736 {"&", UNOP_ADDR, PREC_PREFIX, 0},
737 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
738 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
739 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
740 {NULL, 0, 0, 0}
741 };
742 \f
743 enum c_primitive_types {
744 c_primitive_type_int,
745 c_primitive_type_long,
746 c_primitive_type_short,
747 c_primitive_type_char,
748 c_primitive_type_float,
749 c_primitive_type_double,
750 c_primitive_type_void,
751 c_primitive_type_long_long,
752 c_primitive_type_signed_char,
753 c_primitive_type_unsigned_char,
754 c_primitive_type_unsigned_short,
755 c_primitive_type_unsigned_int,
756 c_primitive_type_unsigned_long,
757 c_primitive_type_unsigned_long_long,
758 c_primitive_type_long_double,
759 c_primitive_type_complex,
760 c_primitive_type_double_complex,
761 c_primitive_type_decfloat,
762 c_primitive_type_decdouble,
763 c_primitive_type_declong,
764 nr_c_primitive_types
765 };
766
767 void
768 c_language_arch_info (struct gdbarch *gdbarch,
769 struct language_arch_info *lai)
770 {
771 const struct builtin_type *builtin = builtin_type (gdbarch);
772
773 lai->string_char_type = builtin->builtin_char;
774 lai->primitive_type_vector
775 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
776 struct type *);
777 lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int;
778 lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long;
779 lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short;
780 lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char;
781 lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float;
782 lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double;
783 lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void;
784 lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long;
785 lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char;
786 lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char;
787 lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short;
788 lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int;
789 lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long;
790 lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long;
791 lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double;
792 lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex;
793 lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex;
794 lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat;
795 lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble;
796 lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong;
797
798 lai->bool_type_default = builtin->builtin_int;
799 }
800
801 const struct exp_descriptor exp_descriptor_c =
802 {
803 print_subexp_standard,
804 operator_length_standard,
805 operator_check_standard,
806 op_name_standard,
807 dump_subexp_body_standard,
808 evaluate_subexp_c
809 };
810
811 const struct language_defn c_language_defn =
812 {
813 "c", /* Language name */
814 language_c,
815 range_check_off,
816 case_sensitive_on,
817 array_row_major,
818 macro_expansion_c,
819 &exp_descriptor_c,
820 c_parse,
821 c_error,
822 null_post_parser,
823 c_printchar, /* Print a character constant */
824 c_printstr, /* Function to print string constant */
825 c_emit_char, /* Print a single char */
826 c_print_type, /* Print a type using appropriate syntax */
827 c_print_typedef, /* Print a typedef using appropriate syntax */
828 c_val_print, /* Print a value using appropriate syntax */
829 c_value_print, /* Print a top-level value */
830 default_read_var_value, /* la_read_var_value */
831 NULL, /* Language specific skip_trampoline */
832 NULL, /* name_of_this */
833 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
834 basic_lookup_transparent_type,/* lookup_transparent_type */
835 NULL, /* Language specific symbol demangler */
836 NULL, /* Language specific
837 class_name_from_physname */
838 c_op_print_tab, /* expression operators for printing */
839 1, /* c-style arrays */
840 0, /* String lower bound */
841 default_word_break_characters,
842 default_make_symbol_completion_list,
843 c_language_arch_info,
844 default_print_array_index,
845 default_pass_by_reference,
846 c_get_string,
847 NULL, /* la_get_symbol_name_cmp */
848 iterate_over_symbols,
849 LANG_MAGIC
850 };
851
852 enum cplus_primitive_types {
853 cplus_primitive_type_int,
854 cplus_primitive_type_long,
855 cplus_primitive_type_short,
856 cplus_primitive_type_char,
857 cplus_primitive_type_float,
858 cplus_primitive_type_double,
859 cplus_primitive_type_void,
860 cplus_primitive_type_long_long,
861 cplus_primitive_type_signed_char,
862 cplus_primitive_type_unsigned_char,
863 cplus_primitive_type_unsigned_short,
864 cplus_primitive_type_unsigned_int,
865 cplus_primitive_type_unsigned_long,
866 cplus_primitive_type_unsigned_long_long,
867 cplus_primitive_type_long_double,
868 cplus_primitive_type_complex,
869 cplus_primitive_type_double_complex,
870 cplus_primitive_type_bool,
871 cplus_primitive_type_decfloat,
872 cplus_primitive_type_decdouble,
873 cplus_primitive_type_declong,
874 nr_cplus_primitive_types
875 };
876
877 static void
878 cplus_language_arch_info (struct gdbarch *gdbarch,
879 struct language_arch_info *lai)
880 {
881 const struct builtin_type *builtin = builtin_type (gdbarch);
882
883 lai->string_char_type = builtin->builtin_char;
884 lai->primitive_type_vector
885 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
886 struct type *);
887 lai->primitive_type_vector [cplus_primitive_type_int]
888 = builtin->builtin_int;
889 lai->primitive_type_vector [cplus_primitive_type_long]
890 = builtin->builtin_long;
891 lai->primitive_type_vector [cplus_primitive_type_short]
892 = builtin->builtin_short;
893 lai->primitive_type_vector [cplus_primitive_type_char]
894 = builtin->builtin_char;
895 lai->primitive_type_vector [cplus_primitive_type_float]
896 = builtin->builtin_float;
897 lai->primitive_type_vector [cplus_primitive_type_double]
898 = builtin->builtin_double;
899 lai->primitive_type_vector [cplus_primitive_type_void]
900 = builtin->builtin_void;
901 lai->primitive_type_vector [cplus_primitive_type_long_long]
902 = builtin->builtin_long_long;
903 lai->primitive_type_vector [cplus_primitive_type_signed_char]
904 = builtin->builtin_signed_char;
905 lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
906 = builtin->builtin_unsigned_char;
907 lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
908 = builtin->builtin_unsigned_short;
909 lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
910 = builtin->builtin_unsigned_int;
911 lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
912 = builtin->builtin_unsigned_long;
913 lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
914 = builtin->builtin_unsigned_long_long;
915 lai->primitive_type_vector [cplus_primitive_type_long_double]
916 = builtin->builtin_long_double;
917 lai->primitive_type_vector [cplus_primitive_type_complex]
918 = builtin->builtin_complex;
919 lai->primitive_type_vector [cplus_primitive_type_double_complex]
920 = builtin->builtin_double_complex;
921 lai->primitive_type_vector [cplus_primitive_type_bool]
922 = builtin->builtin_bool;
923 lai->primitive_type_vector [cplus_primitive_type_decfloat]
924 = builtin->builtin_decfloat;
925 lai->primitive_type_vector [cplus_primitive_type_decdouble]
926 = builtin->builtin_decdouble;
927 lai->primitive_type_vector [cplus_primitive_type_declong]
928 = builtin->builtin_declong;
929
930 lai->bool_type_symbol = "bool";
931 lai->bool_type_default = builtin->builtin_bool;
932 }
933
934 const struct language_defn cplus_language_defn =
935 {
936 "c++", /* Language name */
937 language_cplus,
938 range_check_off,
939 case_sensitive_on,
940 array_row_major,
941 macro_expansion_c,
942 &exp_descriptor_c,
943 c_parse,
944 c_error,
945 null_post_parser,
946 c_printchar, /* Print a character constant */
947 c_printstr, /* Function to print string constant */
948 c_emit_char, /* Print a single char */
949 c_print_type, /* Print a type using appropriate syntax */
950 c_print_typedef, /* Print a typedef using appropriate syntax */
951 c_val_print, /* Print a value using appropriate syntax */
952 c_value_print, /* Print a top-level value */
953 default_read_var_value, /* la_read_var_value */
954 cplus_skip_trampoline, /* Language specific skip_trampoline */
955 "this", /* name_of_this */
956 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
957 cp_lookup_transparent_type, /* lookup_transparent_type */
958 gdb_demangle, /* Language specific symbol demangler */
959 cp_class_name_from_physname, /* Language specific
960 class_name_from_physname */
961 c_op_print_tab, /* expression operators for printing */
962 1, /* c-style arrays */
963 0, /* String lower bound */
964 default_word_break_characters,
965 default_make_symbol_completion_list,
966 cplus_language_arch_info,
967 default_print_array_index,
968 cp_pass_by_reference,
969 c_get_string,
970 NULL, /* la_get_symbol_name_cmp */
971 iterate_over_symbols,
972 LANG_MAGIC
973 };
974
975 const struct language_defn asm_language_defn =
976 {
977 "asm", /* Language name */
978 language_asm,
979 range_check_off,
980 case_sensitive_on,
981 array_row_major,
982 macro_expansion_c,
983 &exp_descriptor_c,
984 c_parse,
985 c_error,
986 null_post_parser,
987 c_printchar, /* Print a character constant */
988 c_printstr, /* Function to print string constant */
989 c_emit_char, /* Print a single char */
990 c_print_type, /* Print a type using appropriate syntax */
991 c_print_typedef, /* Print a typedef using appropriate syntax */
992 c_val_print, /* Print a value using appropriate syntax */
993 c_value_print, /* Print a top-level value */
994 default_read_var_value, /* la_read_var_value */
995 NULL, /* Language specific skip_trampoline */
996 NULL, /* name_of_this */
997 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
998 basic_lookup_transparent_type,/* lookup_transparent_type */
999 NULL, /* Language specific symbol demangler */
1000 NULL, /* Language specific
1001 class_name_from_physname */
1002 c_op_print_tab, /* expression operators for printing */
1003 1, /* c-style arrays */
1004 0, /* String lower bound */
1005 default_word_break_characters,
1006 default_make_symbol_completion_list,
1007 c_language_arch_info, /* FIXME: la_language_arch_info. */
1008 default_print_array_index,
1009 default_pass_by_reference,
1010 c_get_string,
1011 NULL, /* la_get_symbol_name_cmp */
1012 iterate_over_symbols,
1013 LANG_MAGIC
1014 };
1015
1016 /* The following language_defn does not represent a real language.
1017 It just provides a minimal support a-la-C that should allow users
1018 to do some simple operations when debugging applications that use
1019 a language currently not supported by GDB. */
1020
1021 const struct language_defn minimal_language_defn =
1022 {
1023 "minimal", /* Language name */
1024 language_minimal,
1025 range_check_off,
1026 case_sensitive_on,
1027 array_row_major,
1028 macro_expansion_c,
1029 &exp_descriptor_c,
1030 c_parse,
1031 c_error,
1032 null_post_parser,
1033 c_printchar, /* Print a character constant */
1034 c_printstr, /* Function to print string constant */
1035 c_emit_char, /* Print a single char */
1036 c_print_type, /* Print a type using appropriate syntax */
1037 c_print_typedef, /* Print a typedef using appropriate syntax */
1038 c_val_print, /* Print a value using appropriate syntax */
1039 c_value_print, /* Print a top-level value */
1040 default_read_var_value, /* la_read_var_value */
1041 NULL, /* Language specific skip_trampoline */
1042 NULL, /* name_of_this */
1043 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1044 basic_lookup_transparent_type,/* lookup_transparent_type */
1045 NULL, /* Language specific symbol demangler */
1046 NULL, /* Language specific
1047 class_name_from_physname */
1048 c_op_print_tab, /* expression operators for printing */
1049 1, /* c-style arrays */
1050 0, /* String lower bound */
1051 default_word_break_characters,
1052 default_make_symbol_completion_list,
1053 c_language_arch_info,
1054 default_print_array_index,
1055 default_pass_by_reference,
1056 c_get_string,
1057 NULL, /* la_get_symbol_name_cmp */
1058 iterate_over_symbols,
1059 LANG_MAGIC
1060 };
1061
1062 void
1063 _initialize_c_language (void)
1064 {
1065 add_language (&c_language_defn);
1066 add_language (&cplus_language_defn);
1067 add_language (&asm_language_defn);
1068 add_language (&minimal_language_defn);
1069 }
This page took 0.066397 seconds and 4 git commands to generate.