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