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