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