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