GDB (xrefs)
/tmp/gdb-7.10/gdb/c-lang.c
Go to the documentation of this file.
1 /* C language support routines for GDB, the GNU debugger.
2 
3  Copyright (C) 1992-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "expression.h"
24 #include "parser-defs.h"
25 #include "language.h"
26 #include "varobj.h"
27 #include "c-lang.h"
28 #include "valprint.h"
29 #include "macroscope.h"
30 #include "charset.h"
31 #include "demangle.h"
32 #include "cp-abi.h"
33 #include "cp-support.h"
34 #include "gdb_obstack.h"
35 #include <ctype.h>
36 #include "gdbcore.h"
37 
38 extern void _initialize_c_language (void);
39 
40 /* Given a C string type, STR_TYPE, return the corresponding target
41  character set name. */
42 
43 static const char *
45  struct gdbarch *gdbarch)
46 {
47  switch (str_type & ~C_CHAR)
48  {
49  case C_STRING:
50  return target_charset (gdbarch);
51  case C_WIDE_STRING:
52  return target_wide_charset (gdbarch);
53  case C_STRING_16:
54  /* FIXME: UTF-16 is not always correct. */
55  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
56  return "UTF-16BE";
57  else
58  return "UTF-16LE";
59  case C_STRING_32:
60  /* FIXME: UTF-32 is not always correct. */
61  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
62  return "UTF-32BE";
63  else
64  return "UTF-32LE";
65  }
66  internal_error (__FILE__, __LINE__, _("unhandled c_string_type"));
67 }
68 
69 /* Classify ELTTYPE according to what kind of character it is. Return
70  the enum constant representing the character type. Also set
71  *ENCODING to the name of the character set to use when converting
72  characters of this type in target BYTE_ORDER to the host character
73  set. */
74 
75 static enum c_string_type
76 classify_type (struct type *elttype, struct gdbarch *gdbarch,
77  const char **encoding)
78 {
79  enum c_string_type result;
80 
81  /* We loop because ELTTYPE may be a typedef, and we want to
82  successively peel each typedef until we reach a type we
83  understand. We don't use CHECK_TYPEDEF because that will strip
84  all typedefs at once -- but in C, wchar_t is itself a typedef, so
85  that would do the wrong thing. */
86  while (elttype)
87  {
88  const char *name = TYPE_NAME (elttype);
89 
90  if (TYPE_CODE (elttype) == TYPE_CODE_CHAR || !name)
91  {
92  result = C_CHAR;
93  goto done;
94  }
95 
96  if (!strcmp (name, "wchar_t"))
97  {
98  result = C_WIDE_CHAR;
99  goto done;
100  }
101 
102  if (!strcmp (name, "char16_t"))
103  {
104  result = C_CHAR_16;
105  goto done;
106  }
107 
108  if (!strcmp (name, "char32_t"))
109  {
110  result = C_CHAR_32;
111  goto done;
112  }
113 
114  if (TYPE_CODE (elttype) != TYPE_CODE_TYPEDEF)
115  break;
116 
117  /* Call for side effects. */
118  check_typedef (elttype);
119 
120  if (TYPE_TARGET_TYPE (elttype))
121  elttype = TYPE_TARGET_TYPE (elttype);
122  else
123  {
124  /* Perhaps check_typedef did not update the target type. In
125  this case, force the lookup again and hope it works out.
126  It never will for C, but it might for C++. */
127  CHECK_TYPEDEF (elttype);
128  }
129  }
130 
131  /* Punt. */
132  result = C_CHAR;
133 
134  done:
135  if (encoding)
136  *encoding = charset_for_string_type (result, gdbarch);
137 
138  return result;
139 }
140 
141 /* Print the character C on STREAM as part of the contents of a
142  literal string whose delimiter is QUOTER. Note that that format
143  for printing characters and strings is language specific. */
144 
145 void
146 c_emit_char (int c, struct type *type,
147  struct ui_file *stream, int quoter)
148 {
149  const char *encoding;
150 
151  classify_type (type, get_type_arch (type), &encoding);
152  generic_emit_char (c, type, stream, quoter, encoding);
153 }
154 
155 void
156 c_printchar (int c, struct type *type, struct ui_file *stream)
157 {
158  enum c_string_type str_type;
159 
160  str_type = classify_type (type, get_type_arch (type), NULL);
161  switch (str_type)
162  {
163  case C_CHAR:
164  break;
165  case C_WIDE_CHAR:
166  fputc_filtered ('L', stream);
167  break;
168  case C_CHAR_16:
169  fputc_filtered ('u', stream);
170  break;
171  case C_CHAR_32:
172  fputc_filtered ('U', stream);
173  break;
174  }
175 
176  fputc_filtered ('\'', stream);
177  LA_EMIT_CHAR (c, type, stream, '\'');
178  fputc_filtered ('\'', stream);
179 }
180 
181 /* Print the character string STRING, printing at most LENGTH
182  characters. LENGTH is -1 if the string is nul terminated. Each
183  character is WIDTH bytes long. Printing stops early if the number
184  hits print_max; repeat counts are printed as appropriate. Print
185  ellipses at the end if we had to stop before printing LENGTH
186  characters, or if FORCE_ELLIPSES. */
187 
188 void
189 c_printstr (struct ui_file *stream, struct type *type,
190  const gdb_byte *string, unsigned int length,
191  const char *user_encoding, int force_ellipses,
192  const struct value_print_options *options)
193 {
194  enum c_string_type str_type;
195  const char *type_encoding;
196  const char *encoding;
197 
198  str_type = (classify_type (type, get_type_arch (type), &type_encoding)
199  & ~C_CHAR);
200  switch (str_type)
201  {
202  case C_STRING:
203  break;
204  case C_WIDE_STRING:
205  fputs_filtered ("L", stream);
206  break;
207  case C_STRING_16:
208  fputs_filtered ("u", stream);
209  break;
210  case C_STRING_32:
211  fputs_filtered ("U", stream);
212  break;
213  }
214 
215  encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding;
216 
217  generic_printstr (stream, type, string, length, encoding, force_ellipses,
218  '"', 1, options);
219 }
220 
221 /* Obtain a C string from the inferior storing it in a newly allocated
222  buffer in BUFFER, which should be freed by the caller. If the in-
223  and out-parameter *LENGTH is specified at -1, the string is read
224  until a null character of the appropriate width is found, otherwise
225  the string is read to the length of characters specified. The size
226  of a character is determined by the length of the target type of
227  the pointer or array.
228 
229  If VALUE is an array with a known length, and *LENGTH is -1,
230  the function will not read past the end of the array. However, any
231  declared size of the array is ignored if *LENGTH > 0.
232 
233  On completion, *LENGTH will be set to the size of the string read in
234  characters. (If a length of -1 is specified, the length returned
235  will not include the null character). CHARSET is always set to the
236  target charset. */
237 
238 void
240  int *length, struct type **char_type,
241  const char **charset)
242 {
243  int err, width;
244  unsigned int fetchlimit;
245  struct type *type = check_typedef (value_type (value));
246  struct type *element_type = TYPE_TARGET_TYPE (type);
247  int req_length = *length;
248  enum bfd_endian byte_order
250 
251  if (element_type == NULL)
252  goto error;
253 
254  if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
255  {
256  /* If we know the size of the array, we can use it as a limit on
257  the number of characters to be fetched. */
258  if (TYPE_NFIELDS (type) == 1
259  && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
260  {
261  LONGEST low_bound, high_bound;
262 
264  &low_bound, &high_bound);
265  fetchlimit = high_bound - low_bound + 1;
266  }
267  else
268  fetchlimit = UINT_MAX;
269  }
270  else if (TYPE_CODE (type) == TYPE_CODE_PTR)
271  fetchlimit = UINT_MAX;
272  else
273  /* We work only with arrays and pointers. */
274  goto error;
275 
276  if (! c_textual_element_type (element_type, 0))
277  goto error;
278  classify_type (element_type, get_type_arch (element_type), charset);
279  width = TYPE_LENGTH (element_type);
280 
281  /* If the string lives in GDB's memory instead of the inferior's,
282  then we just need to copy it to BUFFER. Also, since such strings
283  are arrays with known size, FETCHLIMIT will hold the size of the
284  array. */
285  if ((VALUE_LVAL (value) == not_lval
286  || VALUE_LVAL (value) == lval_internalvar)
287  && fetchlimit != UINT_MAX)
288  {
289  int i;
290  const gdb_byte *contents = value_contents (value);
291 
292  /* If a length is specified, use that. */
293  if (*length >= 0)
294  i = *length;
295  else
296  /* Otherwise, look for a null character. */
297  for (i = 0; i < fetchlimit; i++)
298  if (extract_unsigned_integer (contents + i * width,
299  width, byte_order) == 0)
300  break;
301 
302  /* I is now either a user-defined length, the number of non-null
303  characters, or FETCHLIMIT. */
304  *length = i * width;
305  *buffer = xmalloc (*length);
306  memcpy (*buffer, contents, *length);
307  err = 0;
308  }
309  else
310  {
311  CORE_ADDR addr = value_as_address (value);
312 
313  /* Prior to the fix for PR 16196 read_string would ignore fetchlimit
314  if length > 0. The old "broken" behaviour is the behaviour we want:
315  The caller may want to fetch 100 bytes from a variable length array
316  implemented using the common idiom of having an array of length 1 at
317  the end of a struct. In this case we want to ignore the declared
318  size of the array. However, it's counterintuitive to implement that
319  behaviour in read_string: what does fetchlimit otherwise mean if
320  length > 0. Therefore we implement the behaviour we want here:
321  If *length > 0, don't specify a fetchlimit. This preserves the
322  previous behaviour. We could move this check above where we know
323  whether the array is declared with a fixed size, but we only want
324  to apply this behaviour when calling read_string. PR 16286. */
325  if (*length > 0)
326  fetchlimit = UINT_MAX;
327 
328  err = read_string (addr, *length, width, fetchlimit,
329  byte_order, buffer, length);
330  if (err)
331  {
332  xfree (*buffer);
333  memory_error (err, addr);
334  }
335  }
336 
337  /* If the LENGTH is specified at -1, we want to return the string
338  length up to the terminating null character. If an actual length
339  was specified, we want to return the length of exactly what was
340  read. */
341  if (req_length == -1)
342  /* If the last character is null, subtract it from LENGTH. */
343  if (*length > 0
344  && extract_unsigned_integer (*buffer + *length - width,
345  width, byte_order) == 0)
346  *length -= width;
347 
348  /* The read_string function will return the number of bytes read.
349  If length returned from read_string was > 0, return the number of
350  characters read by dividing the number of bytes by width. */
351  if (*length != 0)
352  *length = *length / width;
353 
354  *char_type = element_type;
355 
356  return;
357 
358  error:
359  {
360  char *type_str;
361 
362  type_str = type_to_string (type);
363  if (type_str)
364  {
365  make_cleanup (xfree, type_str);
366  error (_("Trying to read string with inappropriate type `%s'."),
367  type_str);
368  }
369  else
370  error (_("Trying to read string with inappropriate type."));
371  }
372 }
373 
374 
375 /* Evaluating C and C++ expressions. */
376 
377 /* Convert a UCN. The digits of the UCN start at P and extend no
378  farther than LIMIT. DEST_CHARSET is the name of the character set
379  into which the UCN should be converted. The results are written to
380  OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
381  Returns a pointer to just after the final digit of the UCN. */
382 
383 static char *
384 convert_ucn (char *p, char *limit, const char *dest_charset,
385  struct obstack *output, int length)
386 {
387  unsigned long result = 0;
388  gdb_byte data[4];
389  int i;
390 
391  for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p)
392  result = (result << 4) + host_hex_value (*p);
393 
394  for (i = 3; i >= 0; --i)
395  {
396  data[i] = result & 0xff;
397  result >>= 8;
398  }
399 
400  convert_between_encodings ("UTF-32BE", dest_charset, data,
401  4, 4, output, translit_none);
402 
403  return p;
404 }
405 
406 /* Emit a character, VALUE, which was specified numerically, to
407  OUTPUT. TYPE is the target character type. */
408 
409 static void
410 emit_numeric_character (struct type *type, unsigned long value,
411  struct obstack *output)
412 {
413  gdb_byte *buffer;
414 
415  buffer = alloca (TYPE_LENGTH (type));
416  pack_long (buffer, type, value);
417  obstack_grow (output, buffer, TYPE_LENGTH (type));
418 }
419 
420 /* Convert an octal escape sequence. TYPE is the target character
421  type. The digits of the escape sequence begin at P and extend no
422  farther than LIMIT. The result is written to OUTPUT. Returns a
423  pointer to just after the final digit of the escape sequence. */
424 
425 static char *
426 convert_octal (struct type *type, char *p,
427  char *limit, struct obstack *output)
428 {
429  int i;
430  unsigned long value = 0;
431 
432  for (i = 0;
433  i < 3 && p < limit && isdigit (*p) && *p != '8' && *p != '9';
434  ++i)
435  {
436  value = 8 * value + host_hex_value (*p);
437  ++p;
438  }
439 
440  emit_numeric_character (type, value, output);
441 
442  return p;
443 }
444 
445 /* Convert a hex escape sequence. TYPE is the target character type.
446  The digits of the escape sequence begin at P and extend no farther
447  than LIMIT. The result is written to OUTPUT. Returns a pointer to
448  just after the final digit of the escape sequence. */
449 
450 static char *
451 convert_hex (struct type *type, char *p,
452  char *limit, struct obstack *output)
453 {
454  unsigned long value = 0;
455 
456  while (p < limit && isxdigit (*p))
457  {
458  value = 16 * value + host_hex_value (*p);
459  ++p;
460  }
461 
462  emit_numeric_character (type, value, output);
463 
464  return p;
465 }
466 
467 #define ADVANCE \
468  do { \
469  ++p; \
470  if (p == limit) \
471  error (_("Malformed escape sequence")); \
472  } while (0)
473 
474 /* Convert an escape sequence to a target format. TYPE is the target
475  character type to use, and DEST_CHARSET is the name of the target
476  character set. The backslash of the escape sequence is at *P, and
477  the escape sequence will not extend past LIMIT. The results are
478  written to OUTPUT. Returns a pointer to just past the final
479  character of the escape sequence. */
480 
481 static char *
482 convert_escape (struct type *type, const char *dest_charset,
483  char *p, char *limit, struct obstack *output)
484 {
485  /* Skip the backslash. */
486  ADVANCE;
487 
488  switch (*p)
489  {
490  case '\\':
491  obstack_1grow (output, '\\');
492  ++p;
493  break;
494 
495  case 'x':
496  ADVANCE;
497  if (!isxdigit (*p))
498  error (_("\\x used with no following hex digits."));
499  p = convert_hex (type, p, limit, output);
500  break;
501 
502  case '0':
503  case '1':
504  case '2':
505  case '3':
506  case '4':
507  case '5':
508  case '6':
509  case '7':
510  p = convert_octal (type, p, limit, output);
511  break;
512 
513  case 'u':
514  case 'U':
515  {
516  int length = *p == 'u' ? 4 : 8;
517 
518  ADVANCE;
519  if (!isxdigit (*p))
520  error (_("\\u used with no following hex digits"));
521  p = convert_ucn (p, limit, dest_charset, output, length);
522  }
523  }
524 
525  return p;
526 }
527 
528 /* Given a single string from a (C-specific) OP_STRING list, convert
529  it to a target string, handling escape sequences specially. The
530  output is written to OUTPUT. DATA is the input string, which has
531  length LEN. DEST_CHARSET is the name of the target character set,
532  and TYPE is the type of target character to use. */
533 
534 static void
535 parse_one_string (struct obstack *output, char *data, int len,
536  const char *dest_charset, struct type *type)
537 {
538  char *limit;
539 
540  limit = data + len;
541 
542  while (data < limit)
543  {
544  char *p = data;
545 
546  /* Look for next escape, or the end of the input. */
547  while (p < limit && *p != '\\')
548  ++p;
549  /* If we saw a run of characters, convert them all. */
550  if (p > data)
551  convert_between_encodings (host_charset (), dest_charset,
552  (gdb_byte *) data, p - data, 1,
553  output, translit_none);
554  /* If we saw an escape, convert it. */
555  if (p < limit)
556  p = convert_escape (type, dest_charset, p, limit, output);
557  data = p;
558  }
559 }
560 
561 /* Expression evaluator for the C language family. Most operations
562  are delegated to evaluate_subexp_standard; see that function for a
563  description of the arguments. */
564 
565 struct value *
566 evaluate_subexp_c (struct type *expect_type, struct expression *exp,
567  int *pos, enum noside noside)
568 {
569  enum exp_opcode op = exp->elts[*pos].opcode;
570 
571  switch (op)
572  {
573  case OP_STRING:
574  {
575  int oplen, limit;
576  struct type *type;
577  struct obstack output;
578  struct cleanup *cleanup;
579  struct value *result;
580  enum c_string_type dest_type;
581  const char *dest_charset;
582  int satisfy_expected = 0;
583 
584  obstack_init (&output);
585  cleanup = make_cleanup_obstack_free (&output);
586 
587  ++*pos;
588  oplen = longest_to_int (exp->elts[*pos].longconst);
589 
590  ++*pos;
591  limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
592  dest_type
593  = (enum c_string_type) longest_to_int (exp->elts[*pos].longconst);
594  switch (dest_type & ~C_CHAR)
595  {
596  case C_STRING:
598  exp->gdbarch);
599  break;
600  case C_WIDE_STRING:
601  type = lookup_typename (exp->language_defn, exp->gdbarch,
602  "wchar_t", NULL, 0);
603  break;
604  case C_STRING_16:
605  type = lookup_typename (exp->language_defn, exp->gdbarch,
606  "char16_t", NULL, 0);
607  break;
608  case C_STRING_32:
609  type = lookup_typename (exp->language_defn, exp->gdbarch,
610  "char32_t", NULL, 0);
611  break;
612  default:
613  internal_error (__FILE__, __LINE__, _("unhandled c_string_type"));
614  }
615 
616  /* Ensure TYPE_LENGTH is valid for TYPE. */
617  check_typedef (type);
618 
619  /* If the caller expects an array of some integral type,
620  satisfy them. If something odder is expected, rely on the
621  caller to cast. */
622  if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_ARRAY)
623  {
624  struct type *element_type
625  = check_typedef (TYPE_TARGET_TYPE (expect_type));
626 
627  if (TYPE_CODE (element_type) == TYPE_CODE_INT
628  || TYPE_CODE (element_type) == TYPE_CODE_CHAR)
629  {
630  type = element_type;
631  satisfy_expected = 1;
632  }
633  }
634 
635  dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
636 
637  ++*pos;
638  while (*pos < limit)
639  {
640  int len;
641 
642  len = longest_to_int (exp->elts[*pos].longconst);
643 
644  ++*pos;
645  if (noside != EVAL_SKIP)
646  parse_one_string (&output, &exp->elts[*pos].string, len,
647  dest_charset, type);
648  *pos += BYTES_TO_EXP_ELEM (len);
649  }
650 
651  /* Skip the trailing length and opcode. */
652  *pos += 2;
653 
654  if (noside == EVAL_SKIP)
655  {
656  /* Return a dummy value of the appropriate type. */
657  if (expect_type != NULL)
658  result = allocate_value (expect_type);
659  else if ((dest_type & C_CHAR) != 0)
660  result = allocate_value (type);
661  else
662  result = value_cstring ("", 0, type);
663  do_cleanups (cleanup);
664  return result;
665  }
666 
667  if ((dest_type & C_CHAR) != 0)
668  {
669  LONGEST value;
670 
671  if (obstack_object_size (&output) != TYPE_LENGTH (type))
672  error (_("Could not convert character "
673  "constant to target character set"));
674  value = unpack_long (type, (gdb_byte *) obstack_base (&output));
675  result = value_from_longest (type, value);
676  }
677  else
678  {
679  int i;
680 
681  /* Write the terminating character. */
682  for (i = 0; i < TYPE_LENGTH (type); ++i)
683  obstack_1grow (&output, 0);
684 
685  if (satisfy_expected)
686  {
687  LONGEST low_bound, high_bound;
688  int element_size = TYPE_LENGTH (type);
689 
690  if (get_discrete_bounds (TYPE_INDEX_TYPE (expect_type),
691  &low_bound, &high_bound) < 0)
692  {
693  low_bound = 0;
694  high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1;
695  }
696  if (obstack_object_size (&output) / element_size
697  > (high_bound - low_bound + 1))
698  error (_("Too many array elements"));
699 
700  result = allocate_value (expect_type);
701  memcpy (value_contents_raw (result), obstack_base (&output),
702  obstack_object_size (&output));
703  }
704  else
705  result = value_cstring (obstack_base (&output),
706  obstack_object_size (&output),
707  type);
708  }
709  do_cleanups (cleanup);
710  return result;
711  }
712  break;
713 
714  default:
715  break;
716  }
717  return evaluate_subexp_standard (expect_type, exp, pos, noside);
718 }
719 
720 
721 
722 /* Table mapping opcodes into strings for printing operators
723  and precedences of the operators. */
724 
725 const struct op_print c_op_print_tab[] =
726 {
727  {",", BINOP_COMMA, PREC_COMMA, 0},
728  {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
729  {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
730  {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
731  {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
732  {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
733  {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
734  {"==", BINOP_EQUAL, PREC_EQUAL, 0},
735  {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
736  {"<=", BINOP_LEQ, PREC_ORDER, 0},
737  {">=", BINOP_GEQ, PREC_ORDER, 0},
738  {">", BINOP_GTR, PREC_ORDER, 0},
739  {"<", BINOP_LESS, PREC_ORDER, 0},
740  {">>", BINOP_RSH, PREC_SHIFT, 0},
741  {"<<", BINOP_LSH, PREC_SHIFT, 0},
742  {"+", BINOP_ADD, PREC_ADD, 0},
743  {"-", BINOP_SUB, PREC_ADD, 0},
744  {"*", BINOP_MUL, PREC_MUL, 0},
745  {"/", BINOP_DIV, PREC_MUL, 0},
746  {"%", BINOP_REM, PREC_MUL, 0},
747  {"@", BINOP_REPEAT, PREC_REPEAT, 0},
748  {"+", UNOP_PLUS, PREC_PREFIX, 0},
749  {"-", UNOP_NEG, PREC_PREFIX, 0},
750  {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
751  {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
752  {"*", UNOP_IND, PREC_PREFIX, 0},
753  {"&", UNOP_ADDR, PREC_PREFIX, 0},
754  {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
755  {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
756  {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
757  {NULL, 0, 0, 0}
758 };
759 
782 };
783 
784 void
786  struct language_arch_info *lai)
787 {
788  const struct builtin_type *builtin = builtin_type (gdbarch);
789 
790  lai->string_char_type = builtin->builtin_char;
793  struct type *);
814 
815  lai->bool_type_default = builtin->builtin_int;
816 }
817 
818 const struct exp_descriptor exp_descriptor_c =
819 {
826 };
827 
828 const struct language_defn c_language_defn =
829 {
830  "c", /* Language name */
831  "C",
832  language_c,
838  c_parse,
839  c_error,
841  c_printchar, /* Print a character constant */
842  c_printstr, /* Function to print string constant */
843  c_emit_char, /* Print a single char */
844  c_print_type, /* Print a type using appropriate syntax */
845  c_print_typedef, /* Print a typedef using appropriate syntax */
846  c_val_print, /* Print a value using appropriate syntax */
847  c_value_print, /* Print a top-level value */
848  default_read_var_value, /* la_read_var_value */
849  NULL, /* Language specific skip_trampoline */
850  NULL, /* name_of_this */
851  basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
852  basic_lookup_transparent_type,/* lookup_transparent_type */
853  NULL, /* Language specific symbol demangler */
854  NULL, /* Language specific
855  class_name_from_physname */
856  c_op_print_tab, /* expression operators for printing */
857  1, /* c-style arrays */
858  0, /* String lower bound */
860  default_make_symbol_completion_list,
864  c_get_string,
865  NULL, /* la_get_symbol_name_cmp */
867  &c_varobj_ops,
870  LANG_MAGIC
871 };
872 
896 };
897 
898 static void
900  struct language_arch_info *lai)
901 {
902  const struct builtin_type *builtin = builtin_type (gdbarch);
903 
904  lai->string_char_type = builtin->builtin_char;
907  struct type *);
909  = builtin->builtin_int;
911  = builtin->builtin_long;
913  = builtin->builtin_short;
915  = builtin->builtin_char;
917  = builtin->builtin_float;
919  = builtin->builtin_double;
921  = builtin->builtin_void;
923  = builtin->builtin_long_long;
925  = builtin->builtin_signed_char;
927  = builtin->builtin_unsigned_char;
929  = builtin->builtin_unsigned_short;
931  = builtin->builtin_unsigned_int;
933  = builtin->builtin_unsigned_long;
935  = builtin->builtin_unsigned_long_long;
937  = builtin->builtin_long_double;
939  = builtin->builtin_complex;
941  = builtin->builtin_double_complex;
943  = builtin->builtin_bool;
945  = builtin->builtin_decfloat;
947  = builtin->builtin_decdouble;
949  = builtin->builtin_declong;
950 
951  lai->bool_type_symbol = "bool";
952  lai->bool_type_default = builtin->builtin_bool;
953 }
954 
955 const struct language_defn cplus_language_defn =
956 {
957  "c++", /* Language name */
958  "C++",
965  c_parse,
966  c_error,
968  c_printchar, /* Print a character constant */
969  c_printstr, /* Function to print string constant */
970  c_emit_char, /* Print a single char */
971  c_print_type, /* Print a type using appropriate syntax */
972  c_print_typedef, /* Print a typedef using appropriate syntax */
973  c_val_print, /* Print a value using appropriate syntax */
974  c_value_print, /* Print a top-level value */
975  default_read_var_value, /* la_read_var_value */
976  cplus_skip_trampoline, /* Language specific skip_trampoline */
977  "this", /* name_of_this */
978  cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
979  cp_lookup_transparent_type, /* lookup_transparent_type */
980  gdb_demangle, /* Language specific symbol demangler */
981  cp_class_name_from_physname, /* Language specific
982  class_name_from_physname */
983  c_op_print_tab, /* expression operators for printing */
984  1, /* c-style arrays */
985  0, /* String lower bound */
987  default_make_symbol_completion_list,
991  c_get_string,
992  NULL, /* la_get_symbol_name_cmp */
995  NULL,
996  NULL,
997  LANG_MAGIC
998 };
999 
1000 const struct language_defn asm_language_defn =
1001 {
1002  "asm", /* Language name */
1003  "assembly",
1004  language_asm,
1010  c_parse,
1011  c_error,
1013  c_printchar, /* Print a character constant */
1014  c_printstr, /* Function to print string constant */
1015  c_emit_char, /* Print a single char */
1016  c_print_type, /* Print a type using appropriate syntax */
1017  c_print_typedef, /* Print a typedef using appropriate syntax */
1018  c_val_print, /* Print a value using appropriate syntax */
1019  c_value_print, /* Print a top-level value */
1020  default_read_var_value, /* la_read_var_value */
1021  NULL, /* Language specific skip_trampoline */
1022  NULL, /* name_of_this */
1023  basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1024  basic_lookup_transparent_type,/* lookup_transparent_type */
1025  NULL, /* Language specific symbol demangler */
1026  NULL, /* Language specific
1027  class_name_from_physname */
1028  c_op_print_tab, /* expression operators for printing */
1029  1, /* c-style arrays */
1030  0, /* String lower bound */
1032  default_make_symbol_completion_list,
1033  c_language_arch_info, /* FIXME: la_language_arch_info. */
1036  c_get_string,
1037  NULL, /* la_get_symbol_name_cmp */
1040  NULL,
1041  NULL,
1042  LANG_MAGIC
1043 };
1044 
1045 /* The following language_defn does not represent a real language.
1046  It just provides a minimal support a-la-C that should allow users
1047  to do some simple operations when debugging applications that use
1048  a language currently not supported by GDB. */
1049 
1050 const struct language_defn minimal_language_defn =
1051 {
1052  "minimal", /* Language name */
1053  "Minimal",
1060  c_parse,
1061  c_error,
1063  c_printchar, /* Print a character constant */
1064  c_printstr, /* Function to print string constant */
1065  c_emit_char, /* Print a single char */
1066  c_print_type, /* Print a type using appropriate syntax */
1067  c_print_typedef, /* Print a typedef using appropriate syntax */
1068  c_val_print, /* Print a value using appropriate syntax */
1069  c_value_print, /* Print a top-level value */
1070  default_read_var_value, /* la_read_var_value */
1071  NULL, /* Language specific skip_trampoline */
1072  NULL, /* name_of_this */
1073  basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1074  basic_lookup_transparent_type,/* lookup_transparent_type */
1075  NULL, /* Language specific symbol demangler */
1076  NULL, /* Language specific
1077  class_name_from_physname */
1078  c_op_print_tab, /* expression operators for printing */
1079  1, /* c-style arrays */
1080  0, /* String lower bound */
1082  default_make_symbol_completion_list,
1086  c_get_string,
1087  NULL, /* la_get_symbol_name_cmp */
1090  NULL,
1091  NULL,
1092  LANG_MAGIC
1093 };
1094 
1095 void
1097 {
1098  add_language (&c_language_defn);
1099  add_language (&cplus_language_defn);
1100  add_language (&asm_language_defn);
1101  add_language (&minimal_language_defn);
1102 }
struct type * cp_lookup_transparent_type(const char *name)
union exp_element elts[1]
Definition: expression.h:85
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
const struct op_print c_op_print_tab[]
Definition: c-lang.c:725
struct type * builtin_declong
Definition: gdbtypes.h:1501
const char * target_charset(struct gdbarch *gdbarch)
Definition: charset.c:407
static char * convert_ucn(char *p, char *limit, const char *dest_charset, struct obstack *output, int length)
Definition: c-lang.c:384
struct value * evaluate_subexp_c(struct type *expect_type, struct expression *exp, int *pos, enum noside noside)
Definition: c-lang.c:566
struct type * builtin_long_double
Definition: gdbtypes.h:1492
enum exp_opcode opcode
Definition: expression.h:65
bfd_vma CORE_ADDR
Definition: common-types.h:41
noside
Definition: expression.h:122
struct type * builtin_unsigned_int
Definition: gdbtypes.h:1488
struct type * builtin_double_complex
Definition: gdbtypes.h:1494
void xfree(void *)
Definition: common-utils.c:97
Definition: c-lang.h:50
#define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE)
Definition: gdbarch.h:1614
int fputc_filtered(int c, struct ui_file *stream)
Definition: utils.c:2178
int cp_pass_by_reference(struct type *type)
Definition: cp-abi.c:225
#define TYPE_NAME(thistype)
Definition: gdbtypes.h:1227
#define ADVANCE
Definition: c-lang.c:467
struct type * language_string_char_type(const struct language_defn *la, struct gdbarch *gdbarch)
Definition: language.c:956
c_string_type
Definition: c-lang.h:37
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition: gdbtypes.c:4766
c_primitive_types
Definition: c-lang.c:760
void internal_error(const char *file, int line, const char *fmt,...)
Definition: errors.c:50
const struct language_defn * language_defn
Definition: expression.h:81
void c_val_print(struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, const struct value *, const struct value_print_options *)
Definition: c-valprint.c:134
void c_language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai)
Definition: c-lang.c:785
struct value * default_read_var_value(struct symbol *var, struct frame_info *frame)
Definition: findvar.c:416
char * c_compute_program(struct compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc)
static void emit_numeric_character(struct type *type, unsigned long value, struct obstack *output)
Definition: c-lang.c:410
static char * convert_hex(struct type *type, char *p, char *limit, struct obstack *output)
Definition: c-lang.c:451
#define _(String)
Definition: gdb_locale.h:40
struct type * string_char_type
Definition: language.h:120
struct type * builtin_complex
Definition: gdbtypes.h:1493
#define BYTES_TO_EXP_ELEM(bytes)
Definition: expression.h:93
#define TYPE_FIELD_TYPE(thistype, n)
Definition: gdbtypes.h:1368
const struct lang_varobj_ops c_varobj_ops
Definition: c-varobj.c:545
#define VALUE_LVAL(val)
Definition: value.h:411
struct value * allocate_value(struct type *type)
Definition: value.c:962
void add_language(const struct language_defn *lang)
Definition: language.c:518
void c_get_string(struct value *value, gdb_byte **buffer, int *length, struct type **char_type, const char **charset)
Definition: c-lang.c:239
struct type * builtin_short
Definition: gdbtypes.h:1482
int longest_to_int(LONGEST)
Definition: valprint.c:1054
void memory_error(enum target_xfer_status err, CORE_ADDR memaddr)
Definition: corefile.c:217
struct type * lookup_typename(const struct language_defn *language, struct gdbarch *gdbarch, const char *name, const struct block *block, int noerr)
Definition: gdbtypes.c:1404
const char *const name
Definition: aarch64-tdep.c:68
char * gdb_demangle(const char *name, int options)
Definition: cp-support.c:1529
char * default_word_break_characters(void)
Definition: language.c:669
#define LA_EMIT_CHAR(ch, type, stream, quoter)
Definition: language.h:499
struct type * builtin_decdouble
Definition: gdbtypes.h:1500
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:2217
const gdb_byte * value_contents(struct value *value)
Definition: value.c:1329
void convert_between_encodings(const char *from, const char *to, const gdb_byte *bytes, unsigned int num_bytes, int width, struct obstack *output, enum transliterations translit)
Definition: charset.c:476
void generic_printstr(struct ui_file *stream, struct type *type, const gdb_byte *string, unsigned int length, const char *encoding, int force_ellipses, int quote_char, int c_style_terminator, const struct value_print_options *options)
Definition: valprint.c:2380
const struct exp_descriptor exp_descriptor_c
Definition: c-lang.c:818
struct type * builtin_unsigned_long
Definition: gdbtypes.h:1489
struct type * bool_type_default
Definition: language.h:125
void null_post_parser(struct expression **exp, int void_context_p)
Definition: parse.c:1358
#define UINT_MAX
Definition: defs.h:505
void c_emit_char(int c, struct type *type, struct ui_file *stream, int quoter)
Definition: c-lang.c:146
const char * target_wide_charset(struct gdbarch *gdbarch)
Definition: charset.c:415
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
Definition: gnu-nat.c:1816
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:2145
const char * bool_type_symbol
Definition: language.h:123
static const char * charset_for_string_type(enum c_string_type str_type, struct gdbarch *gdbarch)
Definition: c-lang.c:44
int default_pass_by_reference(struct type *type)
Definition: language.c:659
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
struct type * basic_lookup_transparent_type(const char *name)
Definition: symtab.c:2851
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:117
Definition: gdbtypes.h:749
char string
Definition: expression.h:72
struct gdbarch * get_type_arch(const struct type *type)
Definition: gdbtypes.c:232
int host_hex_value(char c)
Definition: charset.c:453
static const char * type
Definition: language.c:103
int dump_subexp_body_standard(struct expression *exp, struct ui_file *stream, int elt)
Definition: expprint.c:762
struct value * value_from_longest(struct type *type, LONGEST num)
Definition: value.c:3464
struct type * builtin_decfloat
Definition: gdbtypes.h:1499
void iterate_over_symbols(const struct block *block, const char *name, const domain_enum domain, symbol_found_callback_ftype *callback, void *data)
Definition: symtab.c:2912
struct type * builtin_long
Definition: gdbtypes.h:1484
const struct lang_varobj_ops cplus_varobj_ops
Definition: c-varobj.c:959
void _initialize_c_language(void)
Definition: c-lang.c:1096
void default_print_array_index(struct value *index_value, struct ui_file *stream, const struct value_print_options *options)
Definition: language.c:677
struct type * builtin_unsigned_char
Definition: gdbtypes.h:1486
char * op_name_standard(enum exp_opcode opcode)
Definition: expprint.c:662
void c_print_typedef(struct type *, struct symbol *, struct ui_file *)
Definition: c-typeprint.c:143
static char encoding[]
Definition: remote-mips.c:2988
void * xmalloc(YYSIZE_T)
struct type * builtin_bool
Definition: gdbtypes.h:1496
struct type * builtin_unsigned_long_long
Definition: gdbtypes.h:1498
LONGEST unpack_long(struct type *type, const gdb_byte *valaddr)
Definition: value.c:2797
struct type * builtin_signed_char
Definition: gdbtypes.h:1485
int c_parse(struct parser_state *par_state)
Definition: c-exp.c:5798
static enum c_string_type classify_type(struct type *elttype, struct gdbarch *gdbarch, const char **encoding)
Definition: c-lang.c:76
cplus_primitive_types
Definition: c-lang.c:873
Definition: value.c:172
struct type * builtin_unsigned_short
Definition: gdbtypes.h:1487
static void cplus_language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai)
Definition: c-lang.c:899
void c_printstr(struct ui_file *stream, struct type *type, const gdb_byte *string, unsigned int length, const char *user_encoding, int force_ellipses, const struct value_print_options *options)
Definition: c-lang.c:189
static char * convert_escape(struct type *type, const char *dest_charset, char *p, char *limit, struct obstack *output)
Definition: c-lang.c:482
char * cp_class_name_from_physname(const char *physname)
Definition: cp-support.c:673
struct compile_instance * c_get_compile_context(void)
int read_string(CORE_ADDR addr, int len, int width, unsigned int fetchlimit, enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read)
Definition: valprint.c:1814
bfd_byte gdb_byte
Definition: common-types.h:38
unsigned length
Definition: gdbtypes.h:807
struct type * builtin_char
Definition: gdbtypes.h:1481
#define TYPE_TARGET_TYPE(thistype)
Definition: gdbtypes.h:1229
struct type * builtin_double
Definition: gdbtypes.h:1491
void print_subexp_standard(struct expression *exp, int *pos, struct ui_file *stream, enum precedence prec)
Definition: expprint.c:58
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1240
#define TYPE_INDEX_TYPE(type)
Definition: gdbtypes.h:1244
#define default_varobj_ops
Definition: varobj.h:233
void c_print_type(struct type *, const char *, struct ui_file *, int, int, const struct type_print_options *)
Definition: c-typeprint.c:80
void c_error(char *)
int operator_check_standard(struct expression *exp, int pos, int(*objfile_func)(struct objfile *objfile, void *data), void *data)
Definition: parse.c:1782
#define TYPE_NFIELDS(thistype)
Definition: gdbtypes.h:1241
void generic_emit_char(int c, struct type *type, struct ui_file *stream, int quoter, const char *encoding)
Definition: valprint.c:2051
Definition: buffer.h:23
struct value * value_cstring(char *ptr, ssize_t len, struct type *char_type)
Definition: valops.c:1642
exp_opcode
Definition: expression.h:43
struct symbol * cp_lookup_symbol_nonlocal(const struct language_defn *langdef, const char *name, const struct block *block, const domain_enum domain)
Definition: cp-namespace.c:843
#define CHECK_TYPEDEF(TYPE)
Definition: gdbtypes.h:1817
struct value * evaluate_subexp_standard(struct type *expect_type, struct expression *exp, int *pos, enum noside noside)
Definition: eval.c:699
int c_textual_element_type(struct type *, char)
Definition: c-valprint.c:57
LONGEST longconst
Definition: expression.h:67
void operator_length_standard(const struct expression *expr, int endpos, int *oplenp, int *argsp)
Definition: parse.c:859
static char * convert_octal(struct type *type, char *p, char *limit, struct obstack *output)
Definition: c-lang.c:426
struct type * builtin_long_long
Definition: gdbtypes.h:1497
struct gdbarch * gdbarch
Definition: expression.h:83
struct symbol * basic_lookup_symbol_nonlocal(const struct language_defn *langdef, const char *name, const struct block *block, const domain_enum domain)
Definition: symtab.c:2481
struct type * value_type(const struct value *value)
Definition: value.c:1021
void c_printchar(int c, struct type *type, struct ui_file *stream)
Definition: c-lang.c:156
CORE_ADDR value_as_address(struct value *val)
Definition: value.c:2679
static void parse_one_string(struct obstack *output, char *data, int len, const char *dest_charset, struct type *type)
Definition: c-lang.c:535
const char * host_charset(void)
Definition: charset.c:399
gdb_byte * value_contents_raw(struct value *value)
Definition: value.c:1084
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1237
#define LANG_MAGIC
Definition: language.h:402
struct cleanup * make_cleanup_obstack_free(struct obstack *obstack)
Definition: utils.c:225
char * type_to_string(struct type *type)
Definition: typeprint.c:370
Definition: defs.h:353
struct type ** primitive_type_vector
Definition: language.h:113
void pack_long(gdb_byte *buf, struct type *type, LONGEST num)
Definition: value.c:3392
void c_value_print(struct value *, struct ui_file *, const struct value_print_options *)
Definition: c-valprint.c:459
struct type * builtin_void
Definition: gdbtypes.h:1480
int get_discrete_bounds(struct type *type, LONGEST *lowp, LONGEST *highp)
Definition: gdbtypes.c:899
void error(const char *fmt,...)
Definition: errors.c:38
long long LONGEST
Definition: common-types.h:52
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
struct type * builtin_float
Definition: gdbtypes.h:1490
CORE_ADDR cplus_skip_trampoline(struct frame_info *frame, CORE_ADDR stop_pc)
Definition: cp-abi.c:156
struct type * builtin_int
Definition: gdbtypes.h:1483
const ULONGEST const LONGEST len
Definition: target.h:309