gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / c-lang.c
CommitLineData
c906108c 1/* C language support routines for GDB, the GNU debugger.
ce27fb25 2
6aba47ca 3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003,
4c38e0a4 4 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
c5aa993b 11 (at your option) any later version.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b 18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21#include "defs.h"
22#include "symtab.h"
23#include "gdbtypes.h"
24#include "expression.h"
25#include "parser-defs.h"
26#include "language.h"
27#include "c-lang.h"
745b8ca0 28#include "valprint.h"
84f0252a
JB
29#include "macroscope.h"
30#include "gdb_assert.h"
234b45d4 31#include "charset.h"
a15ef5f5 32#include "gdb_string.h"
9a3d7dfd 33#include "demangle.h"
b18be20d 34#include "cp-abi.h"
1fcb5155 35#include "cp-support.h"
6c7a06a3
TT
36#include "gdb_obstack.h"
37#include <ctype.h>
621c8364 38#include "exceptions.h"
c906108c 39
a14ed312 40extern void _initialize_c_language (void);
6c7a06a3
TT
41
42/* Given a C string type, STR_TYPE, return the corresponding target
43 character set name. */
44
45static const char *
e17a4113 46charset_for_string_type (enum c_string_type str_type,
f870a310 47 struct gdbarch *gdbarch)
6c7a06a3
TT
48{
49 switch (str_type & ~C_CHAR)
50 {
51 case C_STRING:
f870a310 52 return target_charset (gdbarch);
6c7a06a3 53 case C_WIDE_STRING:
f870a310 54 return target_wide_charset (gdbarch);
6c7a06a3 55 case C_STRING_16:
b8899f2b 56 /* FIXME: UTF-16 is not always correct. */
f870a310 57 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
b8899f2b 58 return "UTF-16BE";
6c7a06a3 59 else
b8899f2b 60 return "UTF-16LE";
6c7a06a3 61 case C_STRING_32:
b8899f2b 62 /* FIXME: UTF-32 is not always correct. */
f870a310 63 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
b8899f2b 64 return "UTF-32BE";
6c7a06a3 65 else
b8899f2b 66 return "UTF-32LE";
6c7a06a3
TT
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
e17a4113 74 characters of this type in target BYTE_ORDER to the host character set. */
6c7a06a3
TT
75
76static enum c_string_type
f870a310 77classify_type (struct type *elttype, struct gdbarch *gdbarch,
e17a4113 78 const char **encoding)
6c7a06a3 79{
6c7a06a3
TT
80 enum c_string_type result;
81
85e306ed
TT
82 /* We loop because ELTTYPE may be a typedef, and we want to
83 successively peel each typedef until we reach a type we
84 understand. We don't use CHECK_TYPEDEF because that will strip
85 all typedefs at once -- but in C, wchar_t is itself a typedef, so
86 that would do the wrong thing. */
87 while (elttype)
6c7a06a3
TT
88 {
89 char *name = TYPE_NAME (elttype);
90
91 if (TYPE_CODE (elttype) == TYPE_CODE_CHAR || !name)
92 {
93 result = C_CHAR;
94 goto done;
95 }
96
97 if (!strcmp (name, "wchar_t"))
98 {
99 result = C_WIDE_CHAR;
100 goto done;
101 }
102
103 if (!strcmp (name, "char16_t"))
104 {
105 result = C_CHAR_16;
106 goto done;
107 }
108
109 if (!strcmp (name, "char32_t"))
110 {
111 result = C_CHAR_32;
112 goto done;
113 }
114
85e306ed
TT
115 if (TYPE_CODE (elttype) != TYPE_CODE_TYPEDEF)
116 break;
117
118 /* Call for side effects. */
119 check_typedef (elttype);
120
121 if (TYPE_TARGET_TYPE (elttype))
122 elttype = TYPE_TARGET_TYPE (elttype);
123 else
124 {
125 /* Perhaps check_typedef did not update the target type. In
126 this case, force the lookup again and hope it works out.
127 It never will for C, but it might for C++. */
128 CHECK_TYPEDEF (elttype);
129 }
6c7a06a3 130 }
6c7a06a3
TT
131
132 /* Punt. */
133 result = C_CHAR;
134
135 done:
e17a4113 136 if (encoding)
f870a310 137 *encoding = charset_for_string_type (result, gdbarch);
e17a4113 138
6c7a06a3
TT
139 return result;
140}
141
142/* Return true if print_wchar can display W without resorting to a
143 numeric escape, false otherwise. */
144
145static int
146wchar_printable (gdb_wchar_t w)
147{
148 return (gdb_iswprint (w)
149 || w == LCST ('\a') || w == LCST ('\b')
150 || w == LCST ('\f') || w == LCST ('\n')
151 || w == LCST ('\r') || w == LCST ('\t')
152 || w == LCST ('\v'));
153}
154
155/* A helper function that converts the contents of STRING to wide
156 characters and then appends them to OUTPUT. */
157
158static void
159append_string_as_wide (const char *string, struct obstack *output)
160{
161 for (; *string; ++string)
162 {
163 gdb_wchar_t w = gdb_btowc (*string);
164 obstack_grow (output, &w, sizeof (gdb_wchar_t));
165 }
166}
167
168/* Print a wide character W to OUTPUT. ORIG is a pointer to the
169 original (target) bytes representing the character, ORIG_LEN is the
170 number of valid bytes. WIDTH is the number of bytes in a base
171 characters of the type. OUTPUT is an obstack to which wide
172 characters are emitted. QUOTER is a (narrow) character indicating
173 the style of quotes surrounding the character to be printed.
174 NEED_ESCAPE is an in/out flag which is used to track numeric
175 escapes across calls. */
176
177static void
178print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len,
e17a4113
UW
179 int width, enum bfd_endian byte_order, struct obstack *output,
180 int quoter, int *need_escapep)
6c7a06a3
TT
181{
182 int need_escape = *need_escapep;
c5504eaf 183
6c7a06a3
TT
184 *need_escapep = 0;
185 if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
186 && w != LCST ('8')
187 && w != LCST ('9'))))
188 {
3f7f5fe4 189 gdb_wchar_t wchar = w;
2d90c72a 190
6c7a06a3
TT
191 if (w == gdb_btowc (quoter) || w == LCST ('\\'))
192 obstack_grow_wstr (output, LCST ("\\"));
2d90c72a 193 obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
6c7a06a3
TT
194 }
195 else
196 {
197 switch (w)
198 {
199 case LCST ('\a'):
200 obstack_grow_wstr (output, LCST ("\\a"));
201 break;
202 case LCST ('\b'):
203 obstack_grow_wstr (output, LCST ("\\b"));
204 break;
205 case LCST ('\f'):
206 obstack_grow_wstr (output, LCST ("\\f"));
207 break;
208 case LCST ('\n'):
209 obstack_grow_wstr (output, LCST ("\\n"));
210 break;
211 case LCST ('\r'):
212 obstack_grow_wstr (output, LCST ("\\r"));
213 break;
214 case LCST ('\t'):
215 obstack_grow_wstr (output, LCST ("\\t"));
216 break;
217 case LCST ('\v'):
218 obstack_grow_wstr (output, LCST ("\\v"));
219 break;
220 default:
221 {
222 int i;
223
224 for (i = 0; i + width <= orig_len; i += width)
225 {
226 char octal[30];
e17a4113 227 ULONGEST value;
c5504eaf 228
e17a4113 229 value = extract_unsigned_integer (&orig[i], width, byte_order);
30b66ecc
TT
230 /* If the value fits in 3 octal digits, print it that
231 way. Otherwise, print it as a hex escape. */
232 if (value <= 0777)
233 sprintf (octal, "\\%.3o", (int) (value & 0777));
234 else
235 sprintf (octal, "\\x%lx", (long) value);
6c7a06a3
TT
236 append_string_as_wide (octal, output);
237 }
238 /* If we somehow have extra bytes, print them now. */
239 while (i < orig_len)
240 {
241 char octal[5];
c5504eaf 242
6c7a06a3
TT
243 sprintf (octal, "\\%.3o", orig[i] & 0xff);
244 append_string_as_wide (octal, output);
245 ++i;
246 }
247
248 *need_escapep = 1;
249 }
250 break;
251 }
252 }
253}
c906108c
SS
254
255/* Print the character C on STREAM as part of the contents of a literal
256 string whose delimiter is QUOTER. Note that that format for printing
257 characters and strings is language specific. */
258
6aecb9c2
JB
259void
260c_emit_char (int c, struct type *type,
261 struct ui_file *stream, int quoter)
c906108c 262{
e17a4113 263 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
6c7a06a3
TT
264 struct obstack wchar_buf, output;
265 struct cleanup *cleanups;
266 const char *encoding;
267 gdb_byte *buf;
268 struct wchar_iterator *iter;
269 int need_escape = 0;
234b45d4 270
f870a310 271 classify_type (type, get_type_arch (type), &encoding);
c906108c 272
6c7a06a3
TT
273 buf = alloca (TYPE_LENGTH (type));
274 pack_long (buf, type, c);
275
276 iter = make_wchar_iterator (buf, TYPE_LENGTH (type), encoding,
277 TYPE_LENGTH (type));
278 cleanups = make_cleanup_wchar_iterator (iter);
279
280 /* This holds the printable form of the wchar_t data. */
281 obstack_init (&wchar_buf);
282 make_cleanup_obstack_free (&wchar_buf);
283
284 while (1)
c906108c 285 {
6c7a06a3
TT
286 int num_chars;
287 gdb_wchar_t *chars;
288 const gdb_byte *buf;
289 size_t buflen;
290 int print_escape = 1;
291 enum wchar_iterate_result result;
292
293 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
294 if (num_chars < 0)
295 break;
296 if (num_chars > 0)
297 {
298 /* If all characters are printable, print them. Otherwise,
299 we're going to have to print an escape sequence. We
300 check all characters because we want to print the target
301 bytes in the escape sequence, and we don't know character
302 boundaries there. */
303 int i;
304
305 print_escape = 0;
306 for (i = 0; i < num_chars; ++i)
307 if (!wchar_printable (chars[i]))
308 {
309 print_escape = 1;
310 break;
311 }
312
313 if (!print_escape)
314 {
315 for (i = 0; i < num_chars; ++i)
316 print_wchar (chars[i], buf, buflen, TYPE_LENGTH (type),
e17a4113 317 byte_order, &wchar_buf, quoter, &need_escape);
6c7a06a3
TT
318 }
319 }
320
321 /* This handles the NUM_CHARS == 0 case as well. */
322 if (print_escape)
e17a4113
UW
323 print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type), byte_order,
324 &wchar_buf, quoter, &need_escape);
c906108c 325 }
6c7a06a3
TT
326
327 /* The output in the host encoding. */
328 obstack_init (&output);
329 make_cleanup_obstack_free (&output);
330
732f6a93 331 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
6c7a06a3
TT
332 obstack_base (&wchar_buf),
333 obstack_object_size (&wchar_buf),
334 1, &output, translit_char);
335 obstack_1grow (&output, '\0');
336
337 fputs_filtered (obstack_base (&output), stream);
338
339 do_cleanups (cleanups);
c906108c
SS
340}
341
342void
6c7a06a3 343c_printchar (int c, struct type *type, struct ui_file *stream)
c906108c 344{
6c7a06a3 345 enum c_string_type str_type;
6c7a06a3 346
f870a310 347 str_type = classify_type (type, get_type_arch (type), NULL);
6c7a06a3
TT
348 switch (str_type)
349 {
350 case C_CHAR:
351 break;
352 case C_WIDE_CHAR:
353 fputc_filtered ('L', stream);
354 break;
355 case C_CHAR_16:
356 fputc_filtered ('u', stream);
357 break;
358 case C_CHAR_32:
359 fputc_filtered ('U', stream);
360 break;
361 }
362
c906108c 363 fputc_filtered ('\'', stream);
6c7a06a3 364 LA_EMIT_CHAR (c, type, stream, '\'');
c906108c
SS
365 fputc_filtered ('\'', stream);
366}
367
368/* Print the character string STRING, printing at most LENGTH characters.
369 LENGTH is -1 if the string is nul terminated. Each character is WIDTH bytes
370 long. Printing stops early if the number hits print_max; repeat counts are
371 printed as appropriate. Print ellipses at the end if we had to stop before
372 printing LENGTH characters, or if FORCE_ELLIPSES. */
373
374void
6c7a06a3 375c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
be759fcf 376 unsigned int length, const char *user_encoding, int force_ellipses,
79a45b7d 377 const struct value_print_options *options)
c906108c 378{
e17a4113 379 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
f86f5ca3 380 unsigned int i;
c906108c
SS
381 unsigned int things_printed = 0;
382 int in_quotes = 0;
383 int need_comma = 0;
6c7a06a3
TT
384 int width = TYPE_LENGTH (type);
385 struct obstack wchar_buf, output;
386 struct cleanup *cleanup;
387 enum c_string_type str_type;
be759fcf 388 const char *type_encoding;
6c7a06a3
TT
389 const char *encoding;
390 struct wchar_iterator *iter;
391 int finished = 0;
392 int need_escape = 0;
c906108c 393
3872d37d
AS
394 if (length == -1)
395 {
396 unsigned long current_char = 1;
397
398 for (i = 0; current_char; ++i)
399 {
400 QUIT;
401 current_char = extract_unsigned_integer (string + i * width,
402 width, byte_order);
403 }
404 length = i;
405 }
406
c906108c
SS
407 /* If the string was not truncated due to `set print elements', and
408 the last byte of it is a null, we don't print that, in traditional C
409 style. */
410 if (!force_ellipses
411 && length > 0
e17a4113
UW
412 && (extract_unsigned_integer (string + (length - 1) * width,
413 width, byte_order) == 0))
c906108c
SS
414 length--;
415
f870a310
TT
416 str_type = (classify_type (type, get_type_arch (type), &type_encoding)
417 & ~C_CHAR);
6c7a06a3
TT
418 switch (str_type)
419 {
420 case C_STRING:
421 break;
422 case C_WIDE_STRING:
423 fputs_filtered ("L", stream);
424 break;
425 case C_STRING_16:
426 fputs_filtered ("u", stream);
427 break;
428 case C_STRING_32:
429 fputs_filtered ("U", stream);
430 break;
431 }
432
be759fcf
PM
433 encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding;
434
c906108c
SS
435 if (length == 0)
436 {
437 fputs_filtered ("\"\"", stream);
438 return;
439 }
440
6c7a06a3
TT
441 /* Arrange to iterate over the characters, in wchar_t form. */
442 iter = make_wchar_iterator (string, length * width, encoding, width);
443 cleanup = make_cleanup_wchar_iterator (iter);
444
445 /* WCHAR_BUF is the obstack we use to represent the string in
446 wchar_t form. */
447 obstack_init (&wchar_buf);
448 make_cleanup_obstack_free (&wchar_buf);
449
450 while (!finished && things_printed < options->print_max)
c906108c 451 {
6c7a06a3
TT
452 int num_chars;
453 enum wchar_iterate_result result;
454 gdb_wchar_t *chars;
455 const gdb_byte *buf;
456 size_t buflen;
c906108c
SS
457
458 QUIT;
459
460 if (need_comma)
461 {
6c7a06a3 462 obstack_grow_wstr (&wchar_buf, LCST (", "));
c906108c
SS
463 need_comma = 0;
464 }
465
6c7a06a3
TT
466 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
467 /* We only look at repetitions when we were able to convert a
468 single character in isolation. This makes the code simpler
469 and probably does the sensible thing in the majority of
470 cases. */
7a9fe101 471 while (num_chars == 1 && things_printed < options->print_max)
6c7a06a3
TT
472 {
473 /* Count the number of repetitions. */
474 unsigned int reps = 0;
475 gdb_wchar_t current_char = chars[0];
476 const gdb_byte *orig_buf = buf;
477 int orig_len = buflen;
c906108c 478
6c7a06a3
TT
479 if (need_comma)
480 {
481 obstack_grow_wstr (&wchar_buf, LCST (", "));
482 need_comma = 0;
483 }
484
485 while (num_chars == 1 && current_char == chars[0])
486 {
487 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
488 ++reps;
489 }
490
491 /* Emit CURRENT_CHAR according to the repetition count and
492 options. */
493 if (reps > options->repeat_count_threshold)
494 {
495 if (in_quotes)
496 {
497 if (options->inspect_it)
498 obstack_grow_wstr (&wchar_buf, LCST ("\\\", "));
499 else
500 obstack_grow_wstr (&wchar_buf, LCST ("\", "));
501 in_quotes = 0;
502 }
503 obstack_grow_wstr (&wchar_buf, LCST ("'"));
504 need_escape = 0;
505 print_wchar (current_char, orig_buf, orig_len, width,
e17a4113 506 byte_order, &wchar_buf, '\'', &need_escape);
6c7a06a3
TT
507 obstack_grow_wstr (&wchar_buf, LCST ("'"));
508 {
509 /* Painful gyrations. */
510 int j;
511 char *s = xstrprintf (_(" <repeats %u times>"), reps);
c5504eaf 512
6c7a06a3
TT
513 for (j = 0; s[j]; ++j)
514 {
515 gdb_wchar_t w = gdb_btowc (s[j]);
516 obstack_grow (&wchar_buf, &w, sizeof (gdb_wchar_t));
517 }
518 xfree (s);
519 }
520 things_printed += options->repeat_count_threshold;
521 need_comma = 1;
522 }
523 else
524 {
525 /* Saw the character one or more times, but fewer than
526 the repetition threshold. */
527 if (!in_quotes)
528 {
529 if (options->inspect_it)
530 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
531 else
532 obstack_grow_wstr (&wchar_buf, LCST ("\""));
533 in_quotes = 1;
534 need_escape = 0;
535 }
536
537 while (reps-- > 0)
538 {
539 print_wchar (current_char, orig_buf, orig_len, width,
e17a4113 540 byte_order, &wchar_buf, '"', &need_escape);
6c7a06a3
TT
541 ++things_printed;
542 }
543 }
544 }
545
546 /* NUM_CHARS and the other outputs from wchar_iterate are valid
547 here regardless of which branch was taken above. */
548 if (num_chars < 0)
c906108c 549 {
6c7a06a3
TT
550 /* Hit EOF. */
551 finished = 1;
552 break;
c906108c
SS
553 }
554
6c7a06a3 555 switch (result)
c906108c 556 {
6c7a06a3
TT
557 case wchar_iterate_invalid:
558 if (!in_quotes)
c906108c 559 {
79a45b7d 560 if (options->inspect_it)
6c7a06a3 561 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
c906108c 562 else
6c7a06a3
TT
563 obstack_grow_wstr (&wchar_buf, LCST ("\""));
564 in_quotes = 1;
c906108c 565 }
6c7a06a3 566 need_escape = 0;
e17a4113 567 print_wchar (gdb_WEOF, buf, buflen, width, byte_order, &wchar_buf,
6c7a06a3
TT
568 '"', &need_escape);
569 break;
570
571 case wchar_iterate_incomplete:
572 if (in_quotes)
c906108c 573 {
79a45b7d 574 if (options->inspect_it)
6c7a06a3 575 obstack_grow_wstr (&wchar_buf, LCST ("\\\","));
c906108c 576 else
6c7a06a3
TT
577 obstack_grow_wstr (&wchar_buf, LCST ("\","));
578 in_quotes = 0;
c906108c 579 }
6c7a06a3 580 obstack_grow_wstr (&wchar_buf, LCST (" <incomplete sequence "));
e17a4113 581 print_wchar (gdb_WEOF, buf, buflen, width, byte_order, &wchar_buf,
6c7a06a3
TT
582 0, &need_escape);
583 obstack_grow_wstr (&wchar_buf, LCST (">"));
584 finished = 1;
585 break;
c906108c
SS
586 }
587 }
588
589 /* Terminate the quotes if necessary. */
590 if (in_quotes)
591 {
79a45b7d 592 if (options->inspect_it)
6c7a06a3 593 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
c906108c 594 else
6c7a06a3 595 obstack_grow_wstr (&wchar_buf, LCST ("\""));
c906108c
SS
596 }
597
6c7a06a3
TT
598 if (force_ellipses || !finished)
599 obstack_grow_wstr (&wchar_buf, LCST ("..."));
600
601 /* OUTPUT is where we collect `char's for printing. */
602 obstack_init (&output);
603 make_cleanup_obstack_free (&output);
604
732f6a93 605 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
6c7a06a3
TT
606 obstack_base (&wchar_buf),
607 obstack_object_size (&wchar_buf),
608 1, &output, translit_char);
609 obstack_1grow (&output, '\0');
610
611 fputs_filtered (obstack_base (&output), stream);
612
613 do_cleanups (cleanup);
c906108c 614}
ae6a3a4c
TJB
615
616/* Obtain a C string from the inferior storing it in a newly allocated
fbb8f299
PM
617 buffer in BUFFER, which should be freed by the caller. If the
618 in- and out-parameter *LENGTH is specified at -1, the string is read
619 until a null character of the appropriate width is found, otherwise
620 the string is read to the length of characters specified.
621 The size of a character is determined by the length of the target
622 type of the pointer or array. If VALUE is an array with a known
623 length, the function will not read past the end of the array.
624 On completion, *LENGTH will be set to the size of the string read in
625 characters. (If a length of -1 is specified, the length returned
626 will not include the null character). CHARSET is always set to the
627 target charset. */
ae6a3a4c
TJB
628
629void
630c_get_string (struct value *value, gdb_byte **buffer, int *length,
96c07c5b 631 struct type **char_type, const char **charset)
ae6a3a4c
TJB
632{
633 int err, width;
634 unsigned int fetchlimit;
635 struct type *type = check_typedef (value_type (value));
636 struct type *element_type = TYPE_TARGET_TYPE (type);
fbb8f299 637 int req_length = *length;
e17a4113 638 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
96c07c5b 639 enum c_string_type kind;
ae6a3a4c
TJB
640
641 if (element_type == NULL)
642 goto error;
643
644 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
645 {
646 /* If we know the size of the array, we can use it as a limit on the
647 number of characters to be fetched. */
648 if (TYPE_NFIELDS (type) == 1
649 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
650 {
651 LONGEST low_bound, high_bound;
652
653 get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
654 &low_bound, &high_bound);
655 fetchlimit = high_bound - low_bound + 1;
656 }
657 else
658 fetchlimit = UINT_MAX;
659 }
660 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
661 fetchlimit = UINT_MAX;
662 else
663 /* We work only with arrays and pointers. */
664 goto error;
665
96c07c5b 666 if (! c_textual_element_type (element_type, 0))
ae6a3a4c 667 goto error;
96c07c5b 668 kind = classify_type (element_type,
f870a310 669 get_type_arch (element_type),
96c07c5b 670 charset);
ae6a3a4c
TJB
671 width = TYPE_LENGTH (element_type);
672
fbb8f299 673 /* If the string lives in GDB's memory instead of the inferior's, then we
ae6a3a4c
TJB
674 just need to copy it to BUFFER. Also, since such strings are arrays
675 with known size, FETCHLIMIT will hold the size of the array. */
676 if ((VALUE_LVAL (value) == not_lval
677 || VALUE_LVAL (value) == lval_internalvar)
678 && fetchlimit != UINT_MAX)
679 {
680 int i;
681 const gdb_byte *contents = value_contents (value);
682
fbb8f299
PM
683 /* If a length is specified, use that. */
684 if (*length >= 0)
685 i = *length;
686 else
687 /* Otherwise, look for a null character. */
688 for (i = 0; i < fetchlimit; i++)
689 if (extract_unsigned_integer (contents + i * width, width,
690 byte_order) == 0)
691 break;
692
693 /* I is now either a user-defined length, the number of non-null
694 characters, or FETCHLIMIT. */
ae6a3a4c
TJB
695 *length = i * width;
696 *buffer = xmalloc (*length);
697 memcpy (*buffer, contents, *length);
698 err = 0;
699 }
700 else
701 {
621c8364
TT
702 CORE_ADDR addr = value_as_address (value);
703
704 err = read_string (addr, *length, width, fetchlimit,
705 byte_order, buffer, length);
ae6a3a4c
TJB
706 if (err)
707 {
8ea5dfdf 708 xfree (*buffer);
621c8364
TT
709 if (err == EIO)
710 throw_error (MEMORY_ERROR, "Address %s out of bounds",
711 paddress (get_type_arch (type), addr));
712 else
713 error (_("Error reading string from inferior: %s"),
714 safe_strerror (err));
ae6a3a4c
TJB
715 }
716 }
717
fbb8f299
PM
718 /* If the LENGTH is specified at -1, we want to return the string
719 length up to the terminating null character. If an actual length
720 was specified, we want to return the length of exactly what was
721 read. */
722 if (req_length == -1)
723 /* If the last character is null, subtract it from LENGTH. */
724 if (*length > 0
725 && extract_unsigned_integer (*buffer + *length - width, width,
726 byte_order) == 0)
727 *length -= width;
728
729 /* The read_string function will return the number of bytes read.
730 If length returned from read_string was > 0, return the number of
731 characters read by dividing the number of bytes by width. */
732 if (*length != 0)
733 *length = *length / width;
ae6a3a4c 734
96c07c5b 735 *char_type = element_type;
ae6a3a4c
TJB
736
737 return;
738
739 error:
740 {
741 char *type_str;
742
743 type_str = type_to_string (type);
744 if (type_str)
745 {
746 make_cleanup (xfree, type_str);
747 error (_("Trying to read string with inappropriate type `%s'."),
748 type_str);
749 }
750 else
751 error (_("Trying to read string with inappropriate type."));
752 }
753}
754
c906108c 755\f
6c7a06a3
TT
756/* Evaluating C and C++ expressions. */
757
758/* Convert a UCN. The digits of the UCN start at P and extend no
759 farther than LIMIT. DEST_CHARSET is the name of the character set
760 into which the UCN should be converted. The results are written to
761 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
762 Returns a pointer to just after the final digit of the UCN. */
763
764static char *
765convert_ucn (char *p, char *limit, const char *dest_charset,
766 struct obstack *output, int length)
767{
768 unsigned long result = 0;
769 gdb_byte data[4];
770 int i;
771
772 for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p)
773 result = (result << 4) + host_hex_value (*p);
774
775 for (i = 3; i >= 0; --i)
776 {
777 data[i] = result & 0xff;
778 result >>= 8;
779 }
780
b8899f2b 781 convert_between_encodings ("UTF-32BE", dest_charset, data, 4, 4, output,
6c7a06a3
TT
782 translit_none);
783
784 return p;
785}
786
787/* Emit a character, VALUE, which was specified numerically, to
788 OUTPUT. TYPE is the target character type. */
789
790static void
791emit_numeric_character (struct type *type, unsigned long value,
792 struct obstack *output)
793{
794 gdb_byte *buffer;
795
796 buffer = alloca (TYPE_LENGTH (type));
797 pack_long (buffer, type, value);
798 obstack_grow (output, buffer, TYPE_LENGTH (type));
799}
800
801/* Convert an octal escape sequence. TYPE is the target character
802 type. The digits of the escape sequence begin at P and extend no
803 farther than LIMIT. The result is written to OUTPUT. Returns a
804 pointer to just after the final digit of the escape sequence. */
805
806static char *
807convert_octal (struct type *type, char *p, char *limit, struct obstack *output)
808{
30b66ecc 809 int i;
6c7a06a3
TT
810 unsigned long value = 0;
811
30b66ecc
TT
812 for (i = 0;
813 i < 3 && p < limit && isdigit (*p) && *p != '8' && *p != '9';
814 ++i)
6c7a06a3
TT
815 {
816 value = 8 * value + host_hex_value (*p);
817 ++p;
818 }
819
820 emit_numeric_character (type, value, output);
821
822 return p;
823}
824
825/* Convert a hex escape sequence. TYPE is the target character type.
826 The digits of the escape sequence begin at P and extend no farther
827 than LIMIT. The result is written to OUTPUT. Returns a pointer to
828 just after the final digit of the escape sequence. */
829
830static char *
831convert_hex (struct type *type, char *p, char *limit, struct obstack *output)
832{
833 unsigned long value = 0;
834
835 while (p < limit && isxdigit (*p))
836 {
837 value = 16 * value + host_hex_value (*p);
838 ++p;
839 }
840
841 emit_numeric_character (type, value, output);
842
843 return p;
844}
845
846#define ADVANCE \
847 do { \
848 ++p; \
849 if (p == limit) \
850 error (_("Malformed escape sequence")); \
851 } while (0)
852
853/* Convert an escape sequence to a target format. TYPE is the target
854 character type to use, and DEST_CHARSET is the name of the target
855 character set. The backslash of the escape sequence is at *P, and
856 the escape sequence will not extend past LIMIT. The results are
857 written to OUTPUT. Returns a pointer to just past the final
858 character of the escape sequence. */
859
860static char *
861convert_escape (struct type *type, const char *dest_charset,
862 char *p, char *limit, struct obstack *output)
863{
864 /* Skip the backslash. */
865 ADVANCE;
866
867 switch (*p)
868 {
869 case '\\':
870 obstack_1grow (output, '\\');
871 ++p;
872 break;
873
874 case 'x':
875 ADVANCE;
876 if (!isxdigit (*p))
877 error (_("\\x used with no following hex digits."));
878 p = convert_hex (type, p, limit, output);
879 break;
880
881 case '0':
882 case '1':
883 case '2':
884 case '3':
885 case '4':
886 case '5':
887 case '6':
888 case '7':
889 p = convert_octal (type, p, limit, output);
890 break;
891
892 case 'u':
893 case 'U':
894 {
895 int length = *p == 'u' ? 4 : 8;
c5504eaf 896
6c7a06a3
TT
897 ADVANCE;
898 if (!isxdigit (*p))
899 error (_("\\u used with no following hex digits"));
900 p = convert_ucn (p, limit, dest_charset, output, length);
901 }
902 }
903
904 return p;
905}
906
907/* Given a single string from a (C-specific) OP_STRING list, convert
908 it to a target string, handling escape sequences specially. The
909 output is written to OUTPUT. DATA is the input string, which has
910 length LEN. DEST_CHARSET is the name of the target character set,
911 and TYPE is the type of target character to use. */
912
913static void
914parse_one_string (struct obstack *output, char *data, int len,
915 const char *dest_charset, struct type *type)
916{
917 char *limit;
918
919 limit = data + len;
920
921 while (data < limit)
922 {
923 char *p = data;
c5504eaf 924
6c7a06a3
TT
925 /* Look for next escape, or the end of the input. */
926 while (p < limit && *p != '\\')
927 ++p;
928 /* If we saw a run of characters, convert them all. */
929 if (p > data)
930 convert_between_encodings (host_charset (), dest_charset,
931 data, p - data, 1, output, translit_none);
932 /* If we saw an escape, convert it. */
933 if (p < limit)
934 p = convert_escape (type, dest_charset, p, limit, output);
935 data = p;
936 }
937}
938
939/* Expression evaluator for the C language family. Most operations
940 are delegated to evaluate_subexp_standard; see that function for a
941 description of the arguments. */
942
f4b8a18d 943struct value *
6c7a06a3
TT
944evaluate_subexp_c (struct type *expect_type, struct expression *exp,
945 int *pos, enum noside noside)
946{
947 enum exp_opcode op = exp->elts[*pos].opcode;
948
949 switch (op)
950 {
951 case OP_STRING:
952 {
953 int oplen, limit;
954 struct type *type;
955 struct obstack output;
956 struct cleanup *cleanup;
957 struct value *result;
958 enum c_string_type dest_type;
959 const char *dest_charset;
960
961 obstack_init (&output);
962 cleanup = make_cleanup_obstack_free (&output);
963
964 ++*pos;
965 oplen = longest_to_int (exp->elts[*pos].longconst);
966
967 ++*pos;
968 limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
969 dest_type
970 = (enum c_string_type) longest_to_int (exp->elts[*pos].longconst);
971 switch (dest_type & ~C_CHAR)
972 {
973 case C_STRING:
d80b854b
UW
974 type = language_string_char_type (exp->language_defn,
975 exp->gdbarch);
6c7a06a3
TT
976 break;
977 case C_WIDE_STRING:
e6c014f2
UW
978 type = lookup_typename (exp->language_defn, exp->gdbarch,
979 "wchar_t", NULL, 0);
6c7a06a3
TT
980 break;
981 case C_STRING_16:
e6c014f2
UW
982 type = lookup_typename (exp->language_defn, exp->gdbarch,
983 "char16_t", NULL, 0);
6c7a06a3
TT
984 break;
985 case C_STRING_32:
e6c014f2
UW
986 type = lookup_typename (exp->language_defn, exp->gdbarch,
987 "char32_t", NULL, 0);
6c7a06a3
TT
988 break;
989 default:
990 internal_error (__FILE__, __LINE__, "unhandled c_string_type");
991 }
546e879e
TT
992
993 /* Ensure TYPE_LENGTH is valid for TYPE. */
994 check_typedef (type);
995
f870a310 996 dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
6c7a06a3
TT
997
998 ++*pos;
999 while (*pos < limit)
1000 {
1001 int len;
1002
1003 len = longest_to_int (exp->elts[*pos].longconst);
1004
1005 ++*pos;
1006 if (noside != EVAL_SKIP)
1007 parse_one_string (&output, &exp->elts[*pos].string, len,
1008 dest_charset, type);
1009 *pos += BYTES_TO_EXP_ELEM (len);
1010 }
1011
1012 /* Skip the trailing length and opcode. */
1013 *pos += 2;
1014
1015 if (noside == EVAL_SKIP)
334cc82d
TT
1016 {
1017 /* Return a dummy value of the appropriate type. */
1018 if ((dest_type & C_CHAR) != 0)
1019 result = allocate_value (type);
1020 else
3b7538c0 1021 result = value_cstring ("", 0, type);
334cc82d
TT
1022 do_cleanups (cleanup);
1023 return result;
1024 }
6c7a06a3
TT
1025
1026 if ((dest_type & C_CHAR) != 0)
1027 {
1028 LONGEST value;
1029
1030 if (obstack_object_size (&output) != TYPE_LENGTH (type))
1031 error (_("Could not convert character constant to target character set"));
1032 value = unpack_long (type, obstack_base (&output));
1033 result = value_from_longest (type, value);
1034 }
1035 else
1036 {
1037 int i;
c5504eaf 1038
6c7a06a3
TT
1039 /* Write the terminating character. */
1040 for (i = 0; i < TYPE_LENGTH (type); ++i)
1041 obstack_1grow (&output, 0);
3b7538c0
UW
1042 result = value_cstring (obstack_base (&output),
1043 obstack_object_size (&output),
1044 type);
6c7a06a3
TT
1045 }
1046 do_cleanups (cleanup);
1047 return result;
1048 }
1049 break;
1050
1051 default:
1052 break;
1053 }
1054 return evaluate_subexp_standard (expect_type, exp, pos, noside);
1055}
c5aa993b 1056
84f0252a 1057
84f0252a 1058\f
c906108c
SS
1059/* Table mapping opcodes into strings for printing operators
1060 and precedences of the operators. */
1061
1062const struct op_print c_op_print_tab[] =
c5aa993b
JM
1063{
1064 {",", BINOP_COMMA, PREC_COMMA, 0},
1065 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1066 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
1067 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
1068 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
1069 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
1070 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
1071 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1072 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1073 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1074 {">=", BINOP_GEQ, PREC_ORDER, 0},
1075 {">", BINOP_GTR, PREC_ORDER, 0},
1076 {"<", BINOP_LESS, PREC_ORDER, 0},
1077 {">>", BINOP_RSH, PREC_SHIFT, 0},
1078 {"<<", BINOP_LSH, PREC_SHIFT, 0},
1079 {"+", BINOP_ADD, PREC_ADD, 0},
1080 {"-", BINOP_SUB, PREC_ADD, 0},
1081 {"*", BINOP_MUL, PREC_MUL, 0},
1082 {"/", BINOP_DIV, PREC_MUL, 0},
1083 {"%", BINOP_REM, PREC_MUL, 0},
1084 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1085 {"-", UNOP_NEG, PREC_PREFIX, 0},
1086 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
1087 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
1088 {"*", UNOP_IND, PREC_PREFIX, 0},
1089 {"&", UNOP_ADDR, PREC_PREFIX, 0},
1090 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
1091 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1092 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
c5aa993b 1093 {NULL, 0, 0, 0}
c906108c
SS
1094};
1095\f
685419e2
AC
1096enum c_primitive_types {
1097 c_primitive_type_int,
1098 c_primitive_type_long,
1099 c_primitive_type_short,
1100 c_primitive_type_char,
1101 c_primitive_type_float,
1102 c_primitive_type_double,
1103 c_primitive_type_void,
1104 c_primitive_type_long_long,
1105 c_primitive_type_signed_char,
1106 c_primitive_type_unsigned_char,
1107 c_primitive_type_unsigned_short,
1108 c_primitive_type_unsigned_int,
1109 c_primitive_type_unsigned_long,
1110 c_primitive_type_unsigned_long_long,
1111 c_primitive_type_long_double,
1112 c_primitive_type_complex,
1113 c_primitive_type_double_complex,
213e4dc2
TJB
1114 c_primitive_type_decfloat,
1115 c_primitive_type_decdouble,
1116 c_primitive_type_declong,
685419e2
AC
1117 nr_c_primitive_types
1118};
1119
e9667a65 1120void
685419e2
AC
1121c_language_arch_info (struct gdbarch *gdbarch,
1122 struct language_arch_info *lai)
1123{
1124 const struct builtin_type *builtin = builtin_type (gdbarch);
c5504eaf 1125
e9667a65 1126 lai->string_char_type = builtin->builtin_char;
685419e2
AC
1127 lai->primitive_type_vector
1128 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
1129 struct type *);
1130 lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int;
1131 lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long;
1132 lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short;
1133 lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char;
1134 lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float;
1135 lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double;
1136 lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void;
1137 lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long;
1138 lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char;
1139 lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char;
1140 lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short;
1141 lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int;
1142 lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long;
1143 lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long;
1144 lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double;
1145 lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex;
1146 lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex;
213e4dc2
TJB
1147 lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat;
1148 lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble;
1149 lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong;
fbb06eb1
UW
1150
1151 lai->bool_type_default = builtin->builtin_int;
cad351d1 1152}
685419e2 1153
6aecb9c2 1154const struct exp_descriptor exp_descriptor_c =
6c7a06a3
TT
1155{
1156 print_subexp_standard,
1157 operator_length_standard,
c0201579 1158 operator_check_standard,
6c7a06a3
TT
1159 op_name_standard,
1160 dump_subexp_body_standard,
1161 evaluate_subexp_c
1162};
1163
c5aa993b
JM
1164const struct language_defn c_language_defn =
1165{
c906108c
SS
1166 "c", /* Language name */
1167 language_c,
c906108c
SS
1168 range_check_off,
1169 type_check_off,
63872f9d 1170 case_sensitive_on,
7ca2d3a3 1171 array_row_major,
9a044a89 1172 macro_expansion_c,
6c7a06a3 1173 &exp_descriptor_c,
7c8adf68 1174 c_parse,
c906108c 1175 c_error,
e85c3284 1176 null_post_parser,
c906108c
SS
1177 c_printchar, /* Print a character constant */
1178 c_printstr, /* Function to print string constant */
1179 c_emit_char, /* Print a single char */
c906108c 1180 c_print_type, /* Print a type using appropriate syntax */
5c6ce71d 1181 c_print_typedef, /* Print a typedef using appropriate syntax */
c906108c
SS
1182 c_val_print, /* Print a value using appropriate syntax */
1183 c_value_print, /* Print a top-level value */
f636b87d 1184 NULL, /* Language specific skip_trampoline */
2b2d9e11 1185 NULL, /* name_of_this */
5f9a71c3 1186 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 1187 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 1188 NULL, /* Language specific symbol demangler */
31c27f77 1189 NULL, /* Language specific class_name_from_physname */
c906108c
SS
1190 c_op_print_tab, /* expression operators for printing */
1191 1, /* c-style arrays */
1192 0, /* String lower bound */
6084f43a 1193 default_word_break_characters,
41d27058 1194 default_make_symbol_completion_list,
685419e2 1195 c_language_arch_info,
e79af960 1196 default_print_array_index,
41f1b697 1197 default_pass_by_reference,
ae6a3a4c 1198 c_get_string,
c906108c
SS
1199 LANG_MAGIC
1200};
1201
cad351d1
UW
1202enum cplus_primitive_types {
1203 cplus_primitive_type_int,
1204 cplus_primitive_type_long,
1205 cplus_primitive_type_short,
1206 cplus_primitive_type_char,
1207 cplus_primitive_type_float,
1208 cplus_primitive_type_double,
1209 cplus_primitive_type_void,
1210 cplus_primitive_type_long_long,
1211 cplus_primitive_type_signed_char,
1212 cplus_primitive_type_unsigned_char,
1213 cplus_primitive_type_unsigned_short,
1214 cplus_primitive_type_unsigned_int,
1215 cplus_primitive_type_unsigned_long,
1216 cplus_primitive_type_unsigned_long_long,
1217 cplus_primitive_type_long_double,
1218 cplus_primitive_type_complex,
1219 cplus_primitive_type_double_complex,
1220 cplus_primitive_type_bool,
213e4dc2
TJB
1221 cplus_primitive_type_decfloat,
1222 cplus_primitive_type_decdouble,
1223 cplus_primitive_type_declong,
cad351d1 1224 nr_cplus_primitive_types
c906108c
SS
1225};
1226
cad351d1
UW
1227static void
1228cplus_language_arch_info (struct gdbarch *gdbarch,
1229 struct language_arch_info *lai)
1230{
1231 const struct builtin_type *builtin = builtin_type (gdbarch);
c5504eaf 1232
cad351d1
UW
1233 lai->string_char_type = builtin->builtin_char;
1234 lai->primitive_type_vector
1235 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
1236 struct type *);
1237 lai->primitive_type_vector [cplus_primitive_type_int]
1238 = builtin->builtin_int;
1239 lai->primitive_type_vector [cplus_primitive_type_long]
1240 = builtin->builtin_long;
1241 lai->primitive_type_vector [cplus_primitive_type_short]
1242 = builtin->builtin_short;
1243 lai->primitive_type_vector [cplus_primitive_type_char]
1244 = builtin->builtin_char;
1245 lai->primitive_type_vector [cplus_primitive_type_float]
1246 = builtin->builtin_float;
1247 lai->primitive_type_vector [cplus_primitive_type_double]
1248 = builtin->builtin_double;
1249 lai->primitive_type_vector [cplus_primitive_type_void]
1250 = builtin->builtin_void;
1251 lai->primitive_type_vector [cplus_primitive_type_long_long]
1252 = builtin->builtin_long_long;
1253 lai->primitive_type_vector [cplus_primitive_type_signed_char]
1254 = builtin->builtin_signed_char;
1255 lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
1256 = builtin->builtin_unsigned_char;
1257 lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
1258 = builtin->builtin_unsigned_short;
1259 lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
1260 = builtin->builtin_unsigned_int;
1261 lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
1262 = builtin->builtin_unsigned_long;
1263 lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
1264 = builtin->builtin_unsigned_long_long;
1265 lai->primitive_type_vector [cplus_primitive_type_long_double]
1266 = builtin->builtin_long_double;
1267 lai->primitive_type_vector [cplus_primitive_type_complex]
1268 = builtin->builtin_complex;
1269 lai->primitive_type_vector [cplus_primitive_type_double_complex]
1270 = builtin->builtin_double_complex;
1271 lai->primitive_type_vector [cplus_primitive_type_bool]
1272 = builtin->builtin_bool;
213e4dc2
TJB
1273 lai->primitive_type_vector [cplus_primitive_type_decfloat]
1274 = builtin->builtin_decfloat;
1275 lai->primitive_type_vector [cplus_primitive_type_decdouble]
1276 = builtin->builtin_decdouble;
1277 lai->primitive_type_vector [cplus_primitive_type_declong]
1278 = builtin->builtin_declong;
fbb06eb1
UW
1279
1280 lai->bool_type_symbol = "bool";
1281 lai->bool_type_default = builtin->builtin_bool;
cad351d1
UW
1282}
1283
c5aa993b
JM
1284const struct language_defn cplus_language_defn =
1285{
1286 "c++", /* Language name */
c906108c 1287 language_cplus,
c906108c
SS
1288 range_check_off,
1289 type_check_off,
63872f9d 1290 case_sensitive_on,
7ca2d3a3 1291 array_row_major,
9a044a89 1292 macro_expansion_c,
6c7a06a3 1293 &exp_descriptor_c,
7c8adf68 1294 c_parse,
c906108c 1295 c_error,
e85c3284 1296 null_post_parser,
c906108c
SS
1297 c_printchar, /* Print a character constant */
1298 c_printstr, /* Function to print string constant */
1299 c_emit_char, /* Print a single char */
c906108c 1300 c_print_type, /* Print a type using appropriate syntax */
5c6ce71d 1301 c_print_typedef, /* Print a typedef using appropriate syntax */
c906108c
SS
1302 c_val_print, /* Print a value using appropriate syntax */
1303 c_value_print, /* Print a top-level value */
b18be20d 1304 cplus_skip_trampoline, /* Language specific skip_trampoline */
2b2d9e11 1305 "this", /* name_of_this */
1fcb5155 1306 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 1307 cp_lookup_transparent_type, /* lookup_transparent_type */
9a3d7dfd 1308 cplus_demangle, /* Language specific symbol demangler */
31c27f77 1309 cp_class_name_from_physname, /* Language specific class_name_from_physname */
c906108c
SS
1310 c_op_print_tab, /* expression operators for printing */
1311 1, /* c-style arrays */
1312 0, /* String lower bound */
6084f43a 1313 default_word_break_characters,
41d27058 1314 default_make_symbol_completion_list,
cad351d1 1315 cplus_language_arch_info,
e79af960 1316 default_print_array_index,
41f1b697 1317 cp_pass_by_reference,
ae6a3a4c 1318 c_get_string,
c906108c
SS
1319 LANG_MAGIC
1320};
1321
c5aa993b
JM
1322const struct language_defn asm_language_defn =
1323{
c906108c
SS
1324 "asm", /* Language name */
1325 language_asm,
c906108c
SS
1326 range_check_off,
1327 type_check_off,
63872f9d 1328 case_sensitive_on,
7ca2d3a3 1329 array_row_major,
9a044a89 1330 macro_expansion_c,
6c7a06a3 1331 &exp_descriptor_c,
7c8adf68 1332 c_parse,
c906108c 1333 c_error,
e85c3284 1334 null_post_parser,
c906108c
SS
1335 c_printchar, /* Print a character constant */
1336 c_printstr, /* Function to print string constant */
1337 c_emit_char, /* Print a single char */
c906108c 1338 c_print_type, /* Print a type using appropriate syntax */
5c6ce71d 1339 c_print_typedef, /* Print a typedef using appropriate syntax */
c906108c
SS
1340 c_val_print, /* Print a value using appropriate syntax */
1341 c_value_print, /* Print a top-level value */
f636b87d 1342 NULL, /* Language specific skip_trampoline */
2b2d9e11 1343 NULL, /* name_of_this */
5f9a71c3 1344 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 1345 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 1346 NULL, /* Language specific symbol demangler */
31c27f77 1347 NULL, /* Language specific class_name_from_physname */
c906108c
SS
1348 c_op_print_tab, /* expression operators for printing */
1349 1, /* c-style arrays */
1350 0, /* String lower bound */
6084f43a 1351 default_word_break_characters,
41d27058 1352 default_make_symbol_completion_list,
e9667a65 1353 c_language_arch_info, /* FIXME: la_language_arch_info. */
e79af960 1354 default_print_array_index,
41f1b697 1355 default_pass_by_reference,
ae6a3a4c 1356 c_get_string,
c906108c
SS
1357 LANG_MAGIC
1358};
1359
20a0e81d
JB
1360/* The following language_defn does not represent a real language.
1361 It just provides a minimal support a-la-C that should allow users
1362 to do some simple operations when debugging applications that use
1363 a language currently not supported by GDB. */
1364
1365const struct language_defn minimal_language_defn =
1366{
1367 "minimal", /* Language name */
1368 language_minimal,
20a0e81d
JB
1369 range_check_off,
1370 type_check_off,
1371 case_sensitive_on,
7ca2d3a3 1372 array_row_major,
9a044a89 1373 macro_expansion_c,
6c7a06a3 1374 &exp_descriptor_c,
7c8adf68 1375 c_parse,
20a0e81d 1376 c_error,
e85c3284 1377 null_post_parser,
20a0e81d
JB
1378 c_printchar, /* Print a character constant */
1379 c_printstr, /* Function to print string constant */
1380 c_emit_char, /* Print a single char */
20a0e81d 1381 c_print_type, /* Print a type using appropriate syntax */
5c6ce71d 1382 c_print_typedef, /* Print a typedef using appropriate syntax */
20a0e81d
JB
1383 c_val_print, /* Print a value using appropriate syntax */
1384 c_value_print, /* Print a top-level value */
1385 NULL, /* Language specific skip_trampoline */
2b2d9e11 1386 NULL, /* name_of_this */
5f9a71c3 1387 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 1388 basic_lookup_transparent_type,/* lookup_transparent_type */
20a0e81d 1389 NULL, /* Language specific symbol demangler */
31c27f77 1390 NULL, /* Language specific class_name_from_physname */
20a0e81d
JB
1391 c_op_print_tab, /* expression operators for printing */
1392 1, /* c-style arrays */
1393 0, /* String lower bound */
6084f43a 1394 default_word_break_characters,
41d27058 1395 default_make_symbol_completion_list,
e9667a65 1396 c_language_arch_info,
e79af960 1397 default_print_array_index,
41f1b697 1398 default_pass_by_reference,
ae6a3a4c 1399 c_get_string,
20a0e81d
JB
1400 LANG_MAGIC
1401};
1402
c906108c 1403void
fba45db2 1404_initialize_c_language (void)
c906108c
SS
1405{
1406 add_language (&c_language_defn);
1407 add_language (&cplus_language_defn);
1408 add_language (&asm_language_defn);
20a0e81d 1409 add_language (&minimal_language_defn);
c906108c 1410}
This page took 0.798663 seconds and 4 git commands to generate.