Update description of macro keyword argument assignment in assembler documentation.
[binutils-gdb.git] / gdb / c-lang.c
blob922bf8c0de34cd8e9076856792bd57c17b62d42b
1 /* C language support routines for GDB, the GNU debugger.
3 Copyright (C) 1992-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "symtab.h"
21 #include "gdbtypes.h"
22 #include "expression.h"
23 #include "parser-defs.h"
24 #include "language.h"
25 #include "varobj.h"
26 #include "c-lang.h"
27 #include "c-support.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 "gdbsupport/gdb_obstack.h"
35 #include <ctype.h>
36 #include "gdbcore.h"
37 #include "gdbarch.h"
38 #include "c-exp.h"
40 /* Given a C string type, STR_TYPE, return the corresponding target
41 character set name. */
43 static const char *
44 charset_for_string_type (c_string_type str_type, struct gdbarch *gdbarch)
46 switch (str_type & ~C_CHAR)
48 case C_STRING:
49 return target_charset (gdbarch);
50 case C_WIDE_STRING:
51 return target_wide_charset (gdbarch);
52 case C_STRING_16:
53 /* FIXME: UTF-16 is not always correct. */
54 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
55 return "UTF-16BE";
56 else
57 return "UTF-16LE";
58 case C_STRING_32:
59 /* FIXME: UTF-32 is not always correct. */
60 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
61 return "UTF-32BE";
62 else
63 return "UTF-32LE";
65 internal_error (_("unhandled c_string_type"));
68 /* Classify ELTTYPE according to what kind of character it is. Return
69 the enum constant representing the character type. Also set
70 *ENCODING to the name of the character set to use when converting
71 characters of this type in target BYTE_ORDER to the host character
72 set. */
74 static c_string_type
75 classify_type (struct type *elttype, struct gdbarch *gdbarch,
76 const char **encoding)
78 c_string_type result;
80 /* We loop because ELTTYPE may be a typedef, and we want to
81 successively peel each typedef until we reach a type we
82 understand. We don't use CHECK_TYPEDEF because that will strip
83 all typedefs at once -- but in C, wchar_t is itself a typedef, so
84 that would do the wrong thing. */
85 while (elttype)
87 const char *name = elttype->name ();
89 if (name == nullptr)
91 result = C_CHAR;
92 goto done;
95 if (!strcmp (name, "wchar_t"))
97 result = C_WIDE_CHAR;
98 goto done;
101 if (!strcmp (name, "char16_t"))
103 result = C_CHAR_16;
104 goto done;
107 if (!strcmp (name, "char32_t"))
109 result = C_CHAR_32;
110 goto done;
113 if (elttype->code () != TYPE_CODE_TYPEDEF)
114 break;
116 /* Call for side effects. */
117 check_typedef (elttype);
119 if (elttype->target_type ())
120 elttype = elttype->target_type ();
121 else
123 /* Perhaps check_typedef did not update the target type. In
124 this case, force the lookup again and hope it works out.
125 It never will for C, but it might for C++. */
126 elttype = check_typedef (elttype);
130 /* Punt. */
131 result = C_CHAR;
133 done:
134 if (encoding)
135 *encoding = charset_for_string_type (result, gdbarch);
137 return result;
140 /* Print the character C on STREAM as part of the contents of a
141 literal string whose delimiter is QUOTER. Note that that format
142 for printing characters and strings is language specific. */
144 void
145 language_defn::emitchar (int c, struct type *type,
146 struct ui_file *stream, int quoter) const
148 const char *encoding;
150 classify_type (type, type->arch (), &encoding);
151 generic_emit_char (c, type, stream, quoter, encoding);
154 /* See language.h. */
156 void
157 language_defn::printchar (int c, struct type *type,
158 struct ui_file * stream) const
160 c_string_type str_type;
162 str_type = classify_type (type, type->arch (), NULL);
163 switch (str_type)
165 case C_CHAR:
166 break;
167 case C_WIDE_CHAR:
168 gdb_putc ('L', stream);
169 break;
170 case C_CHAR_16:
171 gdb_putc ('u', stream);
172 break;
173 case C_CHAR_32:
174 gdb_putc ('U', stream);
175 break;
178 gdb_putc ('\'', stream);
179 emitchar (c, type, stream, '\'');
180 gdb_putc ('\'', stream);
183 /* Print the character string STRING, printing at most LENGTH
184 characters. LENGTH is -1 if the string is nul terminated. Each
185 character is WIDTH bytes long. Printing stops early if the number
186 hits print_max_chars; repeat counts are printed as appropriate.
187 Print ellipses at the end if we had to stop before printing LENGTH
188 characters, or if FORCE_ELLIPSES. */
190 void
191 language_defn::printstr (struct ui_file *stream, struct type *type,
192 const gdb_byte *string, unsigned int length,
193 const char *user_encoding, int force_ellipses,
194 const struct value_print_options *options) const
196 c_string_type str_type;
197 const char *type_encoding;
198 const char *encoding;
200 str_type = (classify_type (type, type->arch (), &type_encoding)
201 & ~C_CHAR);
202 switch (str_type)
204 case C_STRING:
205 break;
206 case C_WIDE_STRING:
207 gdb_puts ("L", stream);
208 break;
209 case C_STRING_16:
210 gdb_puts ("u", stream);
211 break;
212 case C_STRING_32:
213 gdb_puts ("U", stream);
214 break;
217 encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding;
219 generic_printstr (stream, type, string, length, encoding, force_ellipses,
220 '"', 1, options);
223 /* Obtain a C string from the inferior storing it in a newly allocated
224 buffer in BUFFER, which should be freed by the caller. If the in-
225 and out-parameter *LENGTH is specified at -1, the string is read
226 until a null character of the appropriate width is found, otherwise
227 the string is read to the length of characters specified. The size
228 of a character is determined by the length of the target type of
229 the pointer or array.
231 If VALUE is an array with a known length, and *LENGTH is -1,
232 the function will not read past the end of the array. However, any
233 declared size of the array is ignored if *LENGTH > 0.
235 On completion, *LENGTH will be set to the size of the string read in
236 characters. (If a length of -1 is specified, the length returned
237 will not include the null character). CHARSET is always set to the
238 target charset. */
240 void
241 c_get_string (struct value *value, gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
242 int *length, struct type **char_type,
243 const char **charset)
245 int err, width;
246 unsigned int fetchlimit;
247 struct type *type = check_typedef (value->type ());
248 struct type *element_type = type->target_type ();
249 int req_length = *length;
250 enum bfd_endian byte_order
251 = type_byte_order (type);
253 if (element_type == NULL)
254 goto error;
256 if (type->code () == TYPE_CODE_ARRAY)
258 /* If we know the size of the array, we can use it as a limit on
259 the number of characters to be fetched. */
260 if (type->num_fields () == 1
261 && type->field (0).type ()->code () == TYPE_CODE_RANGE)
263 LONGEST low_bound, high_bound;
265 get_discrete_bounds (type->field (0).type (),
266 &low_bound, &high_bound);
267 fetchlimit = high_bound - low_bound + 1;
269 else
270 fetchlimit = UINT_MAX;
272 else if (type->code () == TYPE_CODE_PTR)
273 fetchlimit = UINT_MAX;
274 else
275 /* We work only with arrays and pointers. */
276 goto error;
278 if (! c_textual_element_type (element_type, 0))
279 goto error;
280 classify_type (element_type, element_type->arch (), charset);
281 width = element_type->length ();
283 /* If the string lives in GDB's memory instead of the inferior's,
284 then we just need to copy it to BUFFER. Also, since such strings
285 are arrays with known size, FETCHLIMIT will hold the size of the
286 array.
288 An array is assumed to live in GDB's memory, so we take this path
289 here.
291 However, it's possible for the caller to request more array
292 elements than apparently exist -- this can happen when using the
293 C struct hack. So, only do this if either no length was
294 specified, or the length is within the existing bounds. This
295 avoids running off the end of the value's contents. */
296 if ((value->lval () == not_lval
297 || value->lval () == lval_internalvar
298 || type->code () == TYPE_CODE_ARRAY)
299 && fetchlimit != UINT_MAX
300 && (*length < 0 || *length <= fetchlimit))
302 int i;
303 const gdb_byte *contents = value->contents ().data ();
305 /* If a length is specified, use that. */
306 if (*length >= 0)
307 i = *length;
308 else
309 /* Otherwise, look for a null character. */
310 for (i = 0; i < fetchlimit; i++)
311 if (extract_unsigned_integer (contents + i * width,
312 width, byte_order) == 0)
313 break;
315 /* I is now either a user-defined length, the number of non-null
316 characters, or FETCHLIMIT. */
317 *length = i * width;
318 buffer->reset ((gdb_byte *) xmalloc (*length));
319 memcpy (buffer->get (), contents, *length);
320 err = 0;
322 else
324 /* value_as_address does not return an address for an array when
325 c_style_arrays is false, so we handle that specially
326 here. */
327 CORE_ADDR addr;
328 if (type->code () == TYPE_CODE_ARRAY)
330 if (value->lval () != lval_memory)
331 error (_("Attempt to take address of value "
332 "not located in memory."));
333 addr = value->address ();
335 else
336 addr = value_as_address (value);
338 /* Prior to the fix for PR 16196 read_string would ignore fetchlimit
339 if length > 0. The old "broken" behaviour is the behaviour we want:
340 The caller may want to fetch 100 bytes from a variable length array
341 implemented using the common idiom of having an array of length 1 at
342 the end of a struct. In this case we want to ignore the declared
343 size of the array. However, it's counterintuitive to implement that
344 behaviour in read_string: what does fetchlimit otherwise mean if
345 length > 0. Therefore we implement the behaviour we want here:
346 If *length > 0, don't specify a fetchlimit. This preserves the
347 previous behaviour. We could move this check above where we know
348 whether the array is declared with a fixed size, but we only want
349 to apply this behaviour when calling read_string. PR 16286. */
350 if (*length > 0)
351 fetchlimit = UINT_MAX;
353 err = target_read_string (addr, *length, width, fetchlimit,
354 buffer, length);
355 if (err != 0)
356 memory_error (TARGET_XFER_E_IO, addr);
359 /* If the LENGTH is specified at -1, we want to return the string
360 length up to the terminating null character. If an actual length
361 was specified, we want to return the length of exactly what was
362 read. */
363 if (req_length == -1)
364 /* If the last character is null, subtract it from LENGTH. */
365 if (*length > 0
366 && extract_unsigned_integer (buffer->get () + *length - width,
367 width, byte_order) == 0)
368 *length -= width;
370 /* The read_string function will return the number of bytes read.
371 If length returned from read_string was > 0, return the number of
372 characters read by dividing the number of bytes by width. */
373 if (*length != 0)
374 *length = *length / width;
376 *char_type = element_type;
378 return;
380 error:
382 std::string type_str = type_to_string (type);
383 if (!type_str.empty ())
385 error (_("Trying to read string with inappropriate type `%s'."),
386 type_str.c_str ());
388 else
389 error (_("Trying to read string with inappropriate type."));
394 /* Evaluating C and C++ expressions. */
396 /* Convert a UCN. The digits of the UCN start at P and extend no
397 farther than LIMIT. DEST_CHARSET is the name of the character set
398 into which the UCN should be converted. The results are written to
399 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
400 Returns a pointer to just after the final digit of the UCN. */
402 static const char *
403 convert_ucn (const char *p, const char *limit, const char *dest_charset,
404 struct obstack *output, int length)
406 unsigned long result = 0;
407 gdb_byte data[4];
408 int i;
410 for (i = 0; i < length && p < limit && ISXDIGIT (*p); ++i, ++p)
411 result = (result << 4) + fromhex (*p);
413 for (i = 3; i >= 0; --i)
415 data[i] = result & 0xff;
416 result >>= 8;
419 convert_between_encodings ("UTF-32BE", dest_charset, data,
420 4, 4, output, translit_none);
422 return p;
425 /* Emit a character, VALUE, which was specified numerically, to
426 OUTPUT. TYPE is the target character type. */
428 static void
429 emit_numeric_character (struct type *type, unsigned long value,
430 struct obstack *output)
432 gdb_byte *buffer;
434 buffer = (gdb_byte *) alloca (type->length ());
435 pack_long (buffer, type, value);
436 obstack_grow (output, buffer, type->length ());
439 /* Convert an octal escape sequence. TYPE is the target character
440 type. The digits of the escape sequence begin at P and extend no
441 farther than LIMIT. The result is written to OUTPUT. Returns a
442 pointer to just after the final digit of the escape sequence. */
444 static const char *
445 convert_octal (struct type *type, const char *p,
446 const char *limit, struct obstack *output)
448 int i;
449 unsigned long value = 0;
451 for (i = 0;
452 i < 3 && p < limit && ISDIGIT (*p) && *p != '8' && *p != '9';
453 ++i)
455 value = 8 * value + fromhex (*p);
456 ++p;
459 emit_numeric_character (type, value, output);
461 return p;
464 /* Convert a hex escape sequence. TYPE is the target character type.
465 The digits of the escape sequence begin at P and extend no farther
466 than LIMIT. The result is written to OUTPUT. Returns a pointer to
467 just after the final digit of the escape sequence. */
469 static const char *
470 convert_hex (struct type *type, const char *p,
471 const char *limit, struct obstack *output)
473 unsigned long value = 0;
475 while (p < limit && ISXDIGIT (*p))
477 value = 16 * value + fromhex (*p);
478 ++p;
481 emit_numeric_character (type, value, output);
483 return p;
486 #define ADVANCE \
487 do { \
488 ++p; \
489 if (p == limit) \
490 error (_("Malformed escape sequence")); \
491 } while (0)
493 /* Convert an escape sequence to a target format. TYPE is the target
494 character type to use, and DEST_CHARSET is the name of the target
495 character set. The backslash of the escape sequence is at *P, and
496 the escape sequence will not extend past LIMIT. The results are
497 written to OUTPUT. Returns a pointer to just past the final
498 character of the escape sequence. */
500 static const char *
501 convert_escape (struct type *type, const char *dest_charset,
502 const char *p, const char *limit, struct obstack *output)
504 /* Skip the backslash. */
505 ADVANCE;
507 switch (*p)
509 case '\\':
510 obstack_1grow (output, '\\');
511 ++p;
512 break;
514 case 'x':
515 ADVANCE;
516 if (!ISXDIGIT (*p))
517 error (_("\\x used with no following hex digits."));
518 p = convert_hex (type, p, limit, output);
519 break;
521 case '0':
522 case '1':
523 case '2':
524 case '3':
525 case '4':
526 case '5':
527 case '6':
528 case '7':
529 p = convert_octal (type, p, limit, output);
530 break;
532 case 'u':
533 case 'U':
535 int length = *p == 'u' ? 4 : 8;
537 ADVANCE;
538 if (!ISXDIGIT (*p))
539 error (_("\\u used with no following hex digits"));
540 p = convert_ucn (p, limit, dest_charset, output, length);
544 return p;
547 /* Given a single string from a (C-specific) OP_STRING list, convert
548 it to a target string, handling escape sequences specially. The
549 output is written to OUTPUT. DATA is the input string, which has
550 length LEN. DEST_CHARSET is the name of the target character set,
551 and TYPE is the type of target character to use. */
553 static void
554 parse_one_string (struct obstack *output, const char *data, int len,
555 const char *dest_charset, struct type *type)
557 const char *limit;
559 limit = data + len;
561 while (data < limit)
563 const char *p = data;
565 /* Look for next escape, or the end of the input. */
566 while (p < limit && *p != '\\')
567 ++p;
568 /* If we saw a run of characters, convert them all. */
569 if (p > data)
570 convert_between_encodings (host_charset (), dest_charset,
571 (const gdb_byte *) data, p - data, 1,
572 output, translit_none);
573 /* If we saw an escape, convert it. */
574 if (p < limit)
575 p = convert_escape (type, dest_charset, p, limit, output);
576 data = p;
580 namespace expr
583 value *
584 c_string_operation::evaluate (struct type *expect_type,
585 struct expression *exp,
586 enum noside noside)
588 struct type *type;
589 struct value *result;
590 c_string_type dest_type;
591 const char *dest_charset;
592 int satisfy_expected = 0;
594 auto_obstack output;
596 dest_type = std::get<0> (m_storage);
598 switch (dest_type & ~C_CHAR)
600 case C_STRING:
601 type = language_string_char_type (exp->language_defn,
602 exp->gdbarch);
603 break;
604 case C_WIDE_STRING:
605 type = lookup_typename (exp->language_defn, "wchar_t", NULL, 0);
606 break;
607 case C_STRING_16:
608 type = lookup_typename (exp->language_defn, "char16_t", NULL, 0);
609 break;
610 case C_STRING_32:
611 type = lookup_typename (exp->language_defn, "char32_t", NULL, 0);
612 break;
613 default:
614 internal_error (_("unhandled c_string_type"));
617 /* If the caller expects an array of some integral type,
618 satisfy them. If something odder is expected, rely on the
619 caller to cast. */
620 if (expect_type && expect_type->code () == TYPE_CODE_ARRAY)
622 struct type *element_type
623 = check_typedef (expect_type->target_type ());
625 if (element_type->code () == TYPE_CODE_INT
626 || element_type->code () == TYPE_CODE_CHAR)
628 type = element_type;
629 satisfy_expected = 1;
633 dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
635 for (const std::string &item : std::get<1> (m_storage))
636 parse_one_string (&output, item.c_str (), item.size (),
637 dest_charset, type);
639 if ((dest_type & C_CHAR) != 0)
641 LONGEST value;
643 if (obstack_object_size (&output) != type->length ())
644 error (_("Could not convert character "
645 "constant to target character set"));
646 value = unpack_long (type, (gdb_byte *) obstack_base (&output));
647 result = value_from_longest (type, value);
649 else
651 int element_size = type->length ();
653 if (satisfy_expected)
655 LONGEST low_bound, high_bound;
657 if (!get_discrete_bounds (expect_type->index_type (),
658 &low_bound, &high_bound))
660 low_bound = 0;
661 high_bound = (expect_type->length () / element_size) - 1;
663 if (obstack_object_size (&output) / element_size
664 > (high_bound - low_bound + 1))
665 error (_("Too many array elements"));
667 result = value::allocate (expect_type);
668 memcpy (result->contents_raw ().data (), obstack_base (&output),
669 obstack_object_size (&output));
670 /* Write the terminating character. */
671 memset (result->contents_raw ().data () + obstack_object_size (&output),
672 0, element_size);
674 else
675 result = value_cstring ((const gdb_byte *) obstack_base (&output),
676 obstack_object_size (&output) / element_size,
677 type);
679 return result;
682 } /* namespace expr */
685 /* See c-lang.h. */
687 bool
688 c_is_string_type_p (struct type *type)
690 type = check_typedef (type);
691 while (type->code () == TYPE_CODE_REF)
693 type = type->target_type ();
694 type = check_typedef (type);
697 switch (type->code ())
699 case TYPE_CODE_ARRAY:
701 /* See if target type looks like a string. */
702 struct type *array_target_type = type->target_type ();
703 return (type->length () > 0
704 && array_target_type->length () > 0
705 && c_textual_element_type (array_target_type, 0));
707 case TYPE_CODE_STRING:
708 return true;
709 case TYPE_CODE_PTR:
711 struct type *element_type = type->target_type ();
712 return c_textual_element_type (element_type, 0);
714 default:
715 break;
718 return false;
723 /* See c-lang.h. */
725 gdb::unique_xmalloc_ptr<char>
726 c_canonicalize_name (const char *name)
728 if (strchr (name, ' ') != nullptr
729 || streq (name, "signed")
730 || streq (name, "unsigned"))
731 return cp_canonicalize_string (name);
732 return nullptr;
737 void
738 c_language_arch_info (struct gdbarch *gdbarch,
739 struct language_arch_info *lai)
741 const struct builtin_type *builtin = builtin_type (gdbarch);
743 /* Helper function to allow shorter lines below. */
744 auto add = [&] (struct type * t)
746 lai->add_primitive_type (t);
749 add (builtin->builtin_int);
750 add (builtin->builtin_long);
751 add (builtin->builtin_short);
752 add (builtin->builtin_char);
753 add (builtin->builtin_float);
754 add (builtin->builtin_double);
755 add (builtin->builtin_void);
756 add (builtin->builtin_long_long);
757 add (builtin->builtin_signed_char);
758 add (builtin->builtin_unsigned_char);
759 add (builtin->builtin_unsigned_short);
760 add (builtin->builtin_unsigned_int);
761 add (builtin->builtin_unsigned_long);
762 add (builtin->builtin_unsigned_long_long);
763 add (builtin->builtin_long_double);
764 add (builtin->builtin_complex);
765 add (builtin->builtin_double_complex);
766 add (builtin->builtin_decfloat);
767 add (builtin->builtin_decdouble);
768 add (builtin->builtin_declong);
770 lai->set_string_char_type (builtin->builtin_char);
771 lai->set_bool_type (builtin->builtin_int);
774 /* Class representing the C language. */
776 class c_language : public language_defn
778 public:
779 c_language ()
780 : language_defn (language_c)
781 { /* Nothing. */ }
783 /* See language.h. */
785 const char *name () const override
786 { return "c"; }
788 /* See language.h. */
790 const char *natural_name () const override
791 { return "C"; }
793 /* See language.h. */
795 const std::vector<const char *> &filename_extensions () const override
797 static const std::vector<const char *> extensions = { ".c" };
798 return extensions;
801 /* See language.h. */
802 void language_arch_info (struct gdbarch *gdbarch,
803 struct language_arch_info *lai) const override
805 c_language_arch_info (gdbarch, lai);
808 /* See language.h. */
809 std::unique_ptr<compile_instance> get_compile_instance () const override
811 return c_get_compile_context ();
814 /* See language.h. */
815 std::string compute_program (compile_instance *inst,
816 const char *input,
817 struct gdbarch *gdbarch,
818 const struct block *expr_block,
819 CORE_ADDR expr_pc) const override
821 return c_compute_program (inst, input, gdbarch, expr_block, expr_pc);
824 /* See language.h. */
826 bool can_print_type_offsets () const override
828 return true;
831 /* See language.h. */
833 void print_type (struct type *type, const char *varstring,
834 struct ui_file *stream, int show, int level,
835 const struct type_print_options *flags) const override
837 c_print_type (type, varstring, stream, show, level, la_language, flags);
840 /* See language.h. */
842 bool store_sym_names_in_linkage_form_p () const override
843 { return true; }
845 /* See language.h. */
847 enum macro_expansion macro_expansion () const override
848 { return macro_expansion_c; }
851 /* Single instance of the C language class. */
853 static c_language c_language_defn;
855 /* A class for the C++ language. */
857 class cplus_language : public language_defn
859 public:
860 cplus_language ()
861 : language_defn (language_cplus)
862 { /* Nothing. */ }
864 /* See language.h. */
866 const char *name () const override
867 { return "c++"; }
869 /* See language.h. */
871 const char *natural_name () const override
872 { return "C++"; }
874 /* See language.h */
875 const char *get_digit_separator () const override
876 { return "\'"; }
878 /* See language.h. */
880 const std::vector<const char *> &filename_extensions () const override
882 static const std::vector<const char *> extensions
883 = { ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++" };
884 return extensions;
887 /* See language.h. */
889 struct language_pass_by_ref_info pass_by_reference_info
890 (struct type *type) const override
892 return cp_pass_by_reference (type);
895 /* See language.h. */
896 void language_arch_info (struct gdbarch *gdbarch,
897 struct language_arch_info *lai) const override
899 const struct builtin_type *builtin = builtin_type (gdbarch);
901 /* Helper function to allow shorter lines below. */
902 auto add = [&] (struct type * t)
904 lai->add_primitive_type (t);
907 add (builtin->builtin_int);
908 add (builtin->builtin_long);
909 add (builtin->builtin_short);
910 add (builtin->builtin_char);
911 add (builtin->builtin_float);
912 add (builtin->builtin_double);
913 add (builtin->builtin_void);
914 add (builtin->builtin_long_long);
915 add (builtin->builtin_signed_char);
916 add (builtin->builtin_unsigned_char);
917 add (builtin->builtin_unsigned_short);
918 add (builtin->builtin_unsigned_int);
919 add (builtin->builtin_unsigned_long);
920 add (builtin->builtin_unsigned_long_long);
921 add (builtin->builtin_long_double);
922 add (builtin->builtin_complex);
923 add (builtin->builtin_double_complex);
924 add (builtin->builtin_bool);
925 add (builtin->builtin_decfloat);
926 add (builtin->builtin_decdouble);
927 add (builtin->builtin_declong);
928 add (builtin->builtin_char16);
929 add (builtin->builtin_char32);
930 add (builtin->builtin_wchar);
932 lai->set_string_char_type (builtin->builtin_char);
933 lai->set_bool_type (builtin->builtin_bool, "bool");
936 /* See language.h. */
937 struct type *lookup_transparent_type (const char *name,
938 domain_search_flags flags)
939 const override
941 return cp_lookup_transparent_type (name, flags);
944 /* See language.h. */
945 std::unique_ptr<compile_instance> get_compile_instance () const override
947 return cplus_get_compile_context ();
950 /* See language.h. */
951 std::string compute_program (compile_instance *inst,
952 const char *input,
953 struct gdbarch *gdbarch,
954 const struct block *expr_block,
955 CORE_ADDR expr_pc) const override
957 return cplus_compute_program (inst, input, gdbarch, expr_block, expr_pc);
960 /* See language.h. */
961 unsigned int search_name_hash (const char *name) const override
963 return cp_search_name_hash (name);
966 /* See language.h. */
967 bool sniff_from_mangled_name
968 (const char *mangled,
969 gdb::unique_xmalloc_ptr<char> *demangled) const override
971 *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
972 return *demangled != NULL;
975 /* See language.h. */
977 gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
978 int options) const override
980 return gdb_demangle (mangled, options);
983 /* See language.h. */
985 bool can_print_type_offsets () const override
987 return true;
990 /* See language.h. */
992 void print_type (struct type *type, const char *varstring,
993 struct ui_file *stream, int show, int level,
994 const struct type_print_options *flags) const override
996 c_print_type (type, varstring, stream, show, level, la_language, flags);
999 /* See language.h. */
1001 CORE_ADDR skip_trampoline (const frame_info_ptr &fi,
1002 CORE_ADDR pc) const override
1004 return cplus_skip_trampoline (fi, pc);
1007 /* See language.h. */
1009 char *class_name_from_physname (const char *physname) const override
1011 return cp_class_name_from_physname (physname);
1014 /* See language.h. */
1016 struct block_symbol lookup_symbol_nonlocal
1017 (const char *name, const struct block *block,
1018 const domain_search_flags domain) const override
1020 return cp_lookup_symbol_nonlocal (this, name, block, domain);
1023 /* See language.h. */
1025 const char *name_of_this () const override
1026 { return "this"; }
1028 /* See language.h. */
1030 enum macro_expansion macro_expansion () const override
1031 { return macro_expansion_c; }
1033 /* See language.h. */
1035 const struct lang_varobj_ops *varobj_ops () const override
1036 { return &cplus_varobj_ops; }
1038 protected:
1040 /* See language.h. */
1042 symbol_name_matcher_ftype *get_symbol_name_matcher_inner
1043 (const lookup_name_info &lookup_name) const override
1045 return cp_get_symbol_name_matcher (lookup_name);
1049 /* The single instance of the C++ language class. */
1051 static cplus_language cplus_language_defn;
1053 /* A class for the ASM language. */
1055 class asm_language : public language_defn
1057 public:
1058 asm_language ()
1059 : language_defn (language_asm)
1060 { /* Nothing. */ }
1062 /* See language.h. */
1064 const char *name () const override
1065 { return "asm"; }
1067 /* See language.h. */
1069 const char *natural_name () const override
1070 { return "Assembly"; }
1072 /* See language.h. */
1074 const std::vector<const char *> &filename_extensions () const override
1076 static const std::vector<const char *> extensions
1077 = { ".s", ".sx", ".S" };
1078 return extensions;
1081 /* See language.h.
1083 FIXME: Should this have its own arch info method? */
1084 void language_arch_info (struct gdbarch *gdbarch,
1085 struct language_arch_info *lai) const override
1087 c_language_arch_info (gdbarch, lai);
1090 /* See language.h. */
1092 bool can_print_type_offsets () const override
1094 return true;
1097 /* See language.h. */
1099 void print_type (struct type *type, const char *varstring,
1100 struct ui_file *stream, int show, int level,
1101 const struct type_print_options *flags) const override
1103 c_print_type (type, varstring, stream, show, level, la_language, flags);
1106 /* See language.h. */
1108 bool store_sym_names_in_linkage_form_p () const override
1109 { return true; }
1111 /* See language.h. */
1113 enum macro_expansion macro_expansion () const override
1114 { return macro_expansion_c; }
1117 /* The single instance of the ASM language class. */
1118 static asm_language asm_language_defn;
1120 /* A class for the minimal language. This does not represent a real
1121 language. It just provides a minimal support a-la-C that should allow
1122 users to do some simple operations when debugging applications that use
1123 a language currently not supported by GDB. */
1125 class minimal_language : public language_defn
1127 public:
1128 minimal_language ()
1129 : language_defn (language_minimal)
1130 { /* Nothing. */ }
1132 /* See language.h. */
1134 const char *name () const override
1135 { return "minimal"; }
1137 /* See language.h. */
1139 const char *natural_name () const override
1140 { return "Minimal"; }
1142 /* See language.h. */
1143 void language_arch_info (struct gdbarch *gdbarch,
1144 struct language_arch_info *lai) const override
1146 c_language_arch_info (gdbarch, lai);
1149 /* See language.h. */
1151 bool can_print_type_offsets () const override
1153 return true;
1156 /* See language.h. */
1158 void print_type (struct type *type, const char *varstring,
1159 struct ui_file *stream, int show, int level,
1160 const struct type_print_options *flags) const override
1162 c_print_type (type, varstring, stream, show, level, la_language, flags);
1165 /* See language.h. */
1167 bool store_sym_names_in_linkage_form_p () const override
1168 { return true; }
1170 /* See language.h. */
1172 enum macro_expansion macro_expansion () const override
1173 { return macro_expansion_c; }
1176 /* The single instance of the minimal language class. */
1177 static minimal_language minimal_language_defn;