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