GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/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-2023 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 "c-support.h"
29#include "valprint.h"
30#include "macroscope.h"
31#include "charset.h"
32#include "demangle.h"
33#include "cp-abi.h"
34#include "cp-support.h"
35#include "gdbsupport/gdb_obstack.h"
36#include <ctype.h>
37#include "gdbcore.h"
38#include "gdbarch.h"
40#include "c-exp.h"
41
42/* Given a C string type, STR_TYPE, return the corresponding target
43 character set name. */
44
45static const char *
46charset_for_string_type (c_string_type str_type, 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:
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 (_("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
74 set. */
75
76static c_string_type
77classify_type (struct type *elttype, struct gdbarch *gdbarch,
78 const char **encoding)
79{
80 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 const char *name = elttype->name ();
90
91 if (name == nullptr)
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 (elttype->code () != TYPE_CODE_TYPEDEF)
116 break;
117
118 /* Call for side effects. */
119 check_typedef (elttype);
120
121 if (elttype->target_type ())
122 elttype = elttype->target_type ();
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 elttype = 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/* Print the character C on STREAM as part of the contents of a
143 literal string whose delimiter is QUOTER. Note that that format
144 for printing characters and strings is language specific. */
145
146void
148 struct ui_file *stream, int quoter) const
149{
150 const char *encoding;
151
152 classify_type (type, type->arch (), &encoding);
153 generic_emit_char (c, type, stream, quoter, encoding);
154}
155
156/* See language.h. */
157
158void
160 struct ui_file * stream) const
161{
162 c_string_type str_type;
163
164 str_type = classify_type (type, type->arch (), NULL);
165 switch (str_type)
166 {
167 case C_CHAR:
168 break;
169 case C_WIDE_CHAR:
170 gdb_putc ('L', stream);
171 break;
172 case C_CHAR_16:
173 gdb_putc ('u', stream);
174 break;
175 case C_CHAR_32:
176 gdb_putc ('U', stream);
177 break;
178 }
179
180 gdb_putc ('\'', stream);
181 emitchar (c, type, stream, '\'');
182 gdb_putc ('\'', stream);
183}
184
185/* Print the character string STRING, printing at most LENGTH
186 characters. LENGTH is -1 if the string is nul terminated. Each
187 character is WIDTH bytes long. Printing stops early if the number
188 hits print_max; repeat counts are printed as appropriate. Print
189 ellipses at the end if we had to stop before printing LENGTH
190 characters, or if FORCE_ELLIPSES. */
191
192void
193language_defn::printstr (struct ui_file *stream, struct type *type,
194 const gdb_byte *string, unsigned int length,
195 const char *user_encoding, int force_ellipses,
196 const struct value_print_options *options) const
197{
198 c_string_type str_type;
199 const char *type_encoding;
200 const char *encoding;
201
202 str_type = (classify_type (type, type->arch (), &type_encoding)
203 & ~C_CHAR);
204 switch (str_type)
205 {
206 case C_STRING:
207 break;
208 case C_WIDE_STRING:
209 gdb_puts ("L", stream);
210 break;
211 case C_STRING_16:
212 gdb_puts ("u", stream);
213 break;
214 case C_STRING_32:
215 gdb_puts ("U", stream);
216 break;
217 }
218
219 encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding;
220
221 generic_printstr (stream, type, string, length, encoding, force_ellipses,
222 '"', 1, options);
223}
224
225/* Obtain a C string from the inferior storing it in a newly allocated
226 buffer in BUFFER, which should be freed by the caller. If the in-
227 and out-parameter *LENGTH is specified at -1, the string is read
228 until a null character of the appropriate width is found, otherwise
229 the string is read to the length of characters specified. The size
230 of a character is determined by the length of the target type of
231 the pointer or array.
232
233 If VALUE is an array with a known length, and *LENGTH is -1,
234 the function will not read past the end of the array. However, any
235 declared size of the array is ignored if *LENGTH > 0.
236
237 On completion, *LENGTH will be set to the size of the string read in
238 characters. (If a length of -1 is specified, the length returned
239 will not include the null character). CHARSET is always set to the
240 target charset. */
241
242void
243c_get_string (struct value *value, gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
244 int *length, struct type **char_type,
245 const char **charset)
246{
247 int err, width;
248 unsigned int fetchlimit;
249 struct type *type = check_typedef (value_type (value));
250 struct type *element_type = type->target_type ();
251 int req_length = *length;
252 enum bfd_endian byte_order
254
255 if (element_type == NULL)
256 goto error;
257
258 if (type->code () == TYPE_CODE_ARRAY)
259 {
260 /* If we know the size of the array, we can use it as a limit on
261 the number of characters to be fetched. */
262 if (type->num_fields () == 1
263 && type->field (0).type ()->code () == TYPE_CODE_RANGE)
264 {
265 LONGEST low_bound, high_bound;
266
268 &low_bound, &high_bound);
269 fetchlimit = high_bound - low_bound + 1;
270 }
271 else
272 fetchlimit = UINT_MAX;
273 }
274 else if (type->code () == TYPE_CODE_PTR)
275 fetchlimit = UINT_MAX;
276 else
277 /* We work only with arrays and pointers. */
278 goto error;
279
280 if (! c_textual_element_type (element_type, 0))
281 goto error;
282 classify_type (element_type, element_type->arch (), charset);
283 width = element_type->length ();
284
285 /* If the string lives in GDB's memory instead of the inferior's,
286 then we just need to copy it to BUFFER. Also, since such strings
287 are arrays with known size, FETCHLIMIT will hold the size of the
288 array.
289
290 An array is assumed to live in GDB's memory, so we take this path
291 here.
292
293 However, it's possible for the caller to request more array
294 elements than apparently exist -- this can happen when using the
295 C struct hack. So, only do this if either no length was
296 specified, or the length is within the existing bounds. This
297 avoids running off the end of the value's contents. */
298 if ((VALUE_LVAL (value) == not_lval
300 || type->code () == TYPE_CODE_ARRAY)
301 && fetchlimit != UINT_MAX
302 && (*length < 0 || *length <= fetchlimit))
303 {
304 int i;
305 const gdb_byte *contents = value_contents (value).data ();
306
307 /* If a length is specified, use that. */
308 if (*length >= 0)
309 i = *length;
310 else
311 /* Otherwise, look for a null character. */
312 for (i = 0; i < fetchlimit; i++)
313 if (extract_unsigned_integer (contents + i * width,
314 width, byte_order) == 0)
315 break;
316
317 /* I is now either a user-defined length, the number of non-null
318 characters, or FETCHLIMIT. */
319 *length = i * width;
320 buffer->reset ((gdb_byte *) xmalloc (*length));
321 memcpy (buffer->get (), contents, *length);
322 err = 0;
323 }
324 else
325 {
326 /* value_as_address does not return an address for an array when
327 c_style_arrays is false, so we handle that specially
328 here. */
329 CORE_ADDR addr;
330 if (type->code () == TYPE_CODE_ARRAY)
331 {
333 error (_("Attempt to take address of value "
334 "not located in memory."));
335 addr = value_address (value);
336 }
337 else
338 addr = value_as_address (value);
339
340 /* Prior to the fix for PR 16196 read_string would ignore fetchlimit
341 if length > 0. The old "broken" behaviour is the behaviour we want:
342 The caller may want to fetch 100 bytes from a variable length array
343 implemented using the common idiom of having an array of length 1 at
344 the end of a struct. In this case we want to ignore the declared
345 size of the array. However, it's counterintuitive to implement that
346 behaviour in read_string: what does fetchlimit otherwise mean if
347 length > 0. Therefore we implement the behaviour we want here:
348 If *length > 0, don't specify a fetchlimit. This preserves the
349 previous behaviour. We could move this check above where we know
350 whether the array is declared with a fixed size, but we only want
351 to apply this behaviour when calling read_string. PR 16286. */
352 if (*length > 0)
353 fetchlimit = UINT_MAX;
354
355 err = target_read_string (addr, *length, width, fetchlimit,
356 buffer, length);
357 if (err != 0)
359 }
360
361 /* If the LENGTH is specified at -1, we want to return the string
362 length up to the terminating null character. If an actual length
363 was specified, we want to return the length of exactly what was
364 read. */
365 if (req_length == -1)
366 /* If the last character is null, subtract it from LENGTH. */
367 if (*length > 0
368 && extract_unsigned_integer (buffer->get () + *length - width,
369 width, byte_order) == 0)
370 *length -= width;
371
372 /* The read_string function will return the number of bytes read.
373 If length returned from read_string was > 0, return the number of
374 characters read by dividing the number of bytes by width. */
375 if (*length != 0)
376 *length = *length / width;
377
378 *char_type = element_type;
379
380 return;
381
382 error:
383 {
384 std::string type_str = type_to_string (type);
385 if (!type_str.empty ())
386 {
387 error (_("Trying to read string with inappropriate type `%s'."),
388 type_str.c_str ());
389 }
390 else
391 error (_("Trying to read string with inappropriate type."));
392 }
393}
394
395
396/* Evaluating C and C++ expressions. */
397
398/* Convert a UCN. The digits of the UCN start at P and extend no
399 farther than LIMIT. DEST_CHARSET is the name of the character set
400 into which the UCN should be converted. The results are written to
401 OUTPUT. LENGTH is the maximum length of the UCN, either 4 or 8.
402 Returns a pointer to just after the final digit of the UCN. */
403
404static const char *
405convert_ucn (const char *p, const char *limit, const char *dest_charset,
406 struct obstack *output, int length)
407{
408 unsigned long result = 0;
409 gdb_byte data[4];
410 int i;
411
412 for (i = 0; i < length && p < limit && ISXDIGIT (*p); ++i, ++p)
413 result = (result << 4) + fromhex (*p);
414
415 for (i = 3; i >= 0; --i)
416 {
417 data[i] = result & 0xff;
418 result >>= 8;
419 }
420
421 convert_between_encodings ("UTF-32BE", dest_charset, data,
422 4, 4, output, translit_none);
423
424 return p;
425}
426
427/* Emit a character, VALUE, which was specified numerically, to
428 OUTPUT. TYPE is the target character type. */
429
430static void
431emit_numeric_character (struct type *type, unsigned long value,
432 struct obstack *output)
433{
434 gdb_byte *buffer;
435
436 buffer = (gdb_byte *) alloca (type->length ());
437 pack_long (buffer, type, value);
438 obstack_grow (output, buffer, type->length ());
439}
440
441/* Convert an octal escape sequence. TYPE is the target character
442 type. The digits of the escape sequence begin at P and extend no
443 farther than LIMIT. The result is written to OUTPUT. Returns a
444 pointer to just after the final digit of the escape sequence. */
445
446static const char *
447convert_octal (struct type *type, const char *p,
448 const char *limit, struct obstack *output)
449{
450 int i;
451 unsigned long value = 0;
452
453 for (i = 0;
454 i < 3 && p < limit && ISDIGIT (*p) && *p != '8' && *p != '9';
455 ++i)
456 {
457 value = 8 * value + fromhex (*p);
458 ++p;
459 }
460
462
463 return p;
464}
465
466/* Convert a hex escape sequence. TYPE is the target character type.
467 The digits of the escape sequence begin at P and extend no farther
468 than LIMIT. The result is written to OUTPUT. Returns a pointer to
469 just after the final digit of the escape sequence. */
470
471static const char *
472convert_hex (struct type *type, const char *p,
473 const char *limit, struct obstack *output)
474{
475 unsigned long value = 0;
476
477 while (p < limit && ISXDIGIT (*p))
478 {
479 value = 16 * value + fromhex (*p);
480 ++p;
481 }
482
484
485 return p;
486}
487
488#define ADVANCE \
489 do { \
490 ++p; \
491 if (p == limit) \
492 error (_("Malformed escape sequence")); \
493 } while (0)
494
495/* Convert an escape sequence to a target format. TYPE is the target
496 character type to use, and DEST_CHARSET is the name of the target
497 character set. The backslash of the escape sequence is at *P, and
498 the escape sequence will not extend past LIMIT. The results are
499 written to OUTPUT. Returns a pointer to just past the final
500 character of the escape sequence. */
501
502static const char *
503convert_escape (struct type *type, const char *dest_charset,
504 const char *p, const char *limit, struct obstack *output)
505{
506 /* Skip the backslash. */
507 ADVANCE;
508
509 switch (*p)
510 {
511 case '\\':
512 obstack_1grow (output, '\\');
513 ++p;
514 break;
515
516 case 'x':
517 ADVANCE;
518 if (!ISXDIGIT (*p))
519 error (_("\\x used with no following hex digits."));
520 p = convert_hex (type, p, limit, output);
521 break;
522
523 case '0':
524 case '1':
525 case '2':
526 case '3':
527 case '4':
528 case '5':
529 case '6':
530 case '7':
531 p = convert_octal (type, p, limit, output);
532 break;
533
534 case 'u':
535 case 'U':
536 {
537 int length = *p == 'u' ? 4 : 8;
538
539 ADVANCE;
540 if (!ISXDIGIT (*p))
541 error (_("\\u used with no following hex digits"));
542 p = convert_ucn (p, limit, dest_charset, output, length);
543 }
544 }
545
546 return p;
547}
548
549/* Given a single string from a (C-specific) OP_STRING list, convert
550 it to a target string, handling escape sequences specially. The
551 output is written to OUTPUT. DATA is the input string, which has
552 length LEN. DEST_CHARSET is the name of the target character set,
553 and TYPE is the type of target character to use. */
554
555static void
556parse_one_string (struct obstack *output, const char *data, int len,
557 const char *dest_charset, struct type *type)
558{
559 const char *limit;
560
561 limit = data + len;
562
563 while (data < limit)
564 {
565 const char *p = data;
566
567 /* Look for next escape, or the end of the input. */
568 while (p < limit && *p != '\\')
569 ++p;
570 /* If we saw a run of characters, convert them all. */
571 if (p > data)
572 convert_between_encodings (host_charset (), dest_charset,
573 (const gdb_byte *) data, p - data, 1,
574 output, translit_none);
575 /* If we saw an escape, convert it. */
576 if (p < limit)
577 p = convert_escape (type, dest_charset, p, limit, output);
578 data = p;
579 }
580}
581
582namespace expr
583{
584
585value *
587 struct expression *exp,
588 enum noside noside)
589{
590 struct type *type;
591 struct value *result;
592 c_string_type dest_type;
593 const char *dest_charset;
594 int satisfy_expected = 0;
595
596 auto_obstack output;
597
598 dest_type = std::get<0> (m_storage);
599
600 switch (dest_type & ~C_CHAR)
601 {
602 case C_STRING:
604 exp->gdbarch);
605 break;
606 case C_WIDE_STRING:
607 type = lookup_typename (exp->language_defn, "wchar_t", NULL, 0);
608 break;
609 case C_STRING_16:
610 type = lookup_typename (exp->language_defn, "char16_t", NULL, 0);
611 break;
612 case C_STRING_32:
613 type = lookup_typename (exp->language_defn, "char32_t", NULL, 0);
614 break;
615 default:
616 internal_error (_("unhandled c_string_type"));
617 }
618
619 /* Ensure TYPE_LENGTH is valid for TYPE. */
621
622 /* If the caller expects an array of some integral type,
623 satisfy them. If something odder is expected, rely on the
624 caller to cast. */
625 if (expect_type && expect_type->code () == TYPE_CODE_ARRAY)
626 {
627 struct type *element_type
628 = check_typedef (expect_type->target_type ());
629
630 if (element_type->code () == TYPE_CODE_INT
631 || element_type->code () == TYPE_CODE_CHAR)
632 {
633 type = element_type;
634 satisfy_expected = 1;
635 }
636 }
637
638 dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
639
640 for (const std::string &item : std::get<1> (m_storage))
641 parse_one_string (&output, item.c_str (), item.size (),
642 dest_charset, type);
643
644 if ((dest_type & C_CHAR) != 0)
645 {
646 LONGEST value;
647
648 if (obstack_object_size (&output) != type->length ())
649 error (_("Could not convert character "
650 "constant to target character set"));
651 value = unpack_long (type, (gdb_byte *) obstack_base (&output));
652 result = value_from_longest (type, value);
653 }
654 else
655 {
656 int i;
657
658 /* Write the terminating character. */
659 for (i = 0; i < type->length (); ++i)
660 obstack_1grow (&output, 0);
661
662 if (satisfy_expected)
663 {
664 LONGEST low_bound, high_bound;
665 int element_size = type->length ();
666
667 if (!get_discrete_bounds (expect_type->index_type (),
668 &low_bound, &high_bound))
669 {
670 low_bound = 0;
671 high_bound = (expect_type->length () / element_size) - 1;
672 }
673 if (obstack_object_size (&output) / element_size
674 > (high_bound - low_bound + 1))
675 error (_("Too many array elements"));
676
677 result = allocate_value (expect_type);
678 memcpy (value_contents_raw (result).data (), obstack_base (&output),
679 obstack_object_size (&output));
680 }
681 else
682 result = value_cstring ((const char *) obstack_base (&output),
683 obstack_object_size (&output),
684 type);
685 }
686 return result;
687}
688
689} /* namespace expr */
690
691
692/* See c-lang.h. */
693
694bool
696{
698 while (type->code () == TYPE_CODE_REF)
699 {
700 type = type->target_type ();
702 }
703
704 switch (type->code ())
705 {
706 case TYPE_CODE_ARRAY:
707 {
708 /* See if target type looks like a string. */
709 struct type *array_target_type = type->target_type ();
710 return (type->length () > 0
711 && array_target_type->length () > 0
712 && c_textual_element_type (array_target_type, 0));
713 }
714 case TYPE_CODE_STRING:
715 return true;
716 case TYPE_CODE_PTR:
717 {
718 struct type *element_type = type->target_type ();
719 return c_textual_element_type (element_type, 0);
720 }
721 default:
722 break;
723 }
724
725 return false;
726}
727
728
729
730/* See c-lang.h. */
731
732gdb::unique_xmalloc_ptr<char>
734{
735 if (strchr (name, ' ') != nullptr
736 || streq (name, "signed")
737 || streq (name, "unsigned"))
739 return nullptr;
740}
741
742
743
744void
746 struct language_arch_info *lai)
747{
748 const struct builtin_type *builtin = builtin_type (gdbarch);
749
750 /* Helper function to allow shorter lines below. */
751 auto add = [&] (struct type * t)
752 {
753 lai->add_primitive_type (t);
754 };
755
756 add (builtin->builtin_int);
757 add (builtin->builtin_long);
758 add (builtin->builtin_short);
759 add (builtin->builtin_char);
760 add (builtin->builtin_float);
761 add (builtin->builtin_double);
762 add (builtin->builtin_void);
763 add (builtin->builtin_long_long);
764 add (builtin->builtin_signed_char);
765 add (builtin->builtin_unsigned_char);
766 add (builtin->builtin_unsigned_short);
767 add (builtin->builtin_unsigned_int);
768 add (builtin->builtin_unsigned_long);
769 add (builtin->builtin_unsigned_long_long);
770 add (builtin->builtin_long_double);
771 add (builtin->builtin_complex);
772 add (builtin->builtin_double_complex);
773 add (builtin->builtin_decfloat);
774 add (builtin->builtin_decdouble);
775 add (builtin->builtin_declong);
776
777 lai->set_string_char_type (builtin->builtin_char);
778 lai->set_bool_type (builtin->builtin_int);
779}
780
781/* Class representing the C language. */
782
784{
785public:
788 { /* Nothing. */ }
789
790 /* See language.h. */
791
792 const char *name () const override
793 { return "c"; }
794
795 /* See language.h. */
796
797 const char *natural_name () const override
798 { return "C"; }
799
800 /* See language.h. */
801
802 const std::vector<const char *> &filename_extensions () const override
803 {
804 static const std::vector<const char *> extensions = { ".c" };
805 return extensions;
806 }
807
808 /* See language.h. */
810 struct language_arch_info *lai) const override
811 {
813 }
814
815 /* See language.h. */
816 std::unique_ptr<compile_instance> get_compile_instance () const override
817 {
818 return c_get_compile_context ();
819 }
820
821 /* See language.h. */
823 const char *input,
824 struct gdbarch *gdbarch,
825 const struct block *expr_block,
826 CORE_ADDR expr_pc) const override
827 {
828 return c_compute_program (inst, input, gdbarch, expr_block, expr_pc);
829 }
830
831 /* See language.h. */
832
833 bool can_print_type_offsets () const override
834 {
835 return true;
836 }
837
838 /* See language.h. */
839
840 void print_type (struct type *type, const char *varstring,
841 struct ui_file *stream, int show, int level,
842 const struct type_print_options *flags) const override
843 {
844 c_print_type (type, varstring, stream, show, level, la_language, flags);
845 }
846
847 /* See language.h. */
848
850 { return true; }
851
852 /* See language.h. */
853
854 enum macro_expansion macro_expansion () const override
855 { return macro_expansion_c; }
856};
857
858/* Single instance of the C language class. */
859
861
862/* A class for the C++ language. */
863
865{
866public:
869 { /* Nothing. */ }
870
871 /* See language.h. */
872
873 const char *name () const override
874 { return "c++"; }
875
876 /* See language.h. */
877
878 const char *natural_name () const override
879 { return "C++"; }
880
881 /* See language.h */
882 const char *get_digit_separator () const override
883 { return "\'"; }
884
885 /* See language.h. */
886
887 const std::vector<const char *> &filename_extensions () const override
888 {
889 static const std::vector<const char *> extensions
890 = { ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++" };
891 return extensions;
892 }
893
894 /* See language.h. */
895
897 (struct type *type) const override
898 {
899 return cp_pass_by_reference (type);
900 }
901
902 /* See language.h. */
904 struct language_arch_info *lai) const override
905 {
906 const struct builtin_type *builtin = builtin_type (gdbarch);
907
908 /* Helper function to allow shorter lines below. */
909 auto add = [&] (struct type * t)
910 {
911 lai->add_primitive_type (t);
912 };
913
914 add (builtin->builtin_int);
915 add (builtin->builtin_long);
916 add (builtin->builtin_short);
917 add (builtin->builtin_char);
918 add (builtin->builtin_float);
919 add (builtin->builtin_double);
920 add (builtin->builtin_void);
921 add (builtin->builtin_long_long);
922 add (builtin->builtin_signed_char);
923 add (builtin->builtin_unsigned_char);
924 add (builtin->builtin_unsigned_short);
925 add (builtin->builtin_unsigned_int);
926 add (builtin->builtin_unsigned_long);
927 add (builtin->builtin_unsigned_long_long);
928 add (builtin->builtin_long_double);
929 add (builtin->builtin_complex);
930 add (builtin->builtin_double_complex);
931 add (builtin->builtin_bool);
932 add (builtin->builtin_decfloat);
933 add (builtin->builtin_decdouble);
934 add (builtin->builtin_declong);
935 add (builtin->builtin_char16);
936 add (builtin->builtin_char32);
937 add (builtin->builtin_wchar);
938
939 lai->set_string_char_type (builtin->builtin_char);
940 lai->set_bool_type (builtin->builtin_bool, "bool");
941 }
942
943 /* See language.h. */
944 struct type *lookup_transparent_type (const char *name) const override
945 {
947 }
948
949 /* See language.h. */
950 std::unique_ptr<compile_instance> get_compile_instance () const override
951 {
953 }
954
955 /* See language.h. */
957 const char *input,
958 struct gdbarch *gdbarch,
959 const struct block *expr_block,
960 CORE_ADDR expr_pc) const override
961 {
962 return cplus_compute_program (inst, input, gdbarch, expr_block, expr_pc);
963 }
964
965 /* See language.h. */
966 unsigned int search_name_hash (const char *name) const override
967 {
968 return cp_search_name_hash (name);
969 }
970
971 /* See language.h. */
973 (const char *mangled,
974 gdb::unique_xmalloc_ptr<char> *demangled) const override
975 {
976 *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
977 return *demangled != NULL;
978 }
979
980 /* See language.h. */
981
982 gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
983 int options) const override
984 {
985 return gdb_demangle (mangled, options);
986 }
987
988 /* See language.h. */
989
990 bool can_print_type_offsets () const override
991 {
992 return true;
993 }
994
995 /* See language.h. */
996
997 void print_type (struct type *type, const char *varstring,
998 struct ui_file *stream, int show, int level,
999 const struct type_print_options *flags) const override
1000 {
1001 c_print_type (type, varstring, stream, show, level, la_language, flags);
1002 }
1003
1004 /* See language.h. */
1005
1007 CORE_ADDR pc) const override
1008 {
1009 return cplus_skip_trampoline (fi, pc);
1010 }
1011
1012 /* See language.h. */
1013
1014 char *class_name_from_physname (const char *physname) const override
1015 {
1016 return cp_class_name_from_physname (physname);
1017 }
1018
1019 /* See language.h. */
1020
1022 (const char *name, const struct block *block,
1023 const domain_enum domain) const override
1024 {
1025 return cp_lookup_symbol_nonlocal (this, name, block, domain);
1026 }
1027
1028 /* See language.h. */
1029
1030 const char *name_of_this () const override
1031 { return "this"; }
1032
1033 /* See language.h. */
1034
1035 enum macro_expansion macro_expansion () const override
1036 { return macro_expansion_c; }
1037
1038 /* See language.h. */
1039
1040 const struct lang_varobj_ops *varobj_ops () const override
1041 { return &cplus_varobj_ops; }
1042
1043protected:
1044
1045 /* See language.h. */
1046
1048 (const lookup_name_info &lookup_name) const override
1049 {
1050 return cp_get_symbol_name_matcher (lookup_name);
1051 }
1052};
1053
1054/* The single instance of the C++ language class. */
1055
1057
1058/* A class for the ASM language. */
1059
1061{
1062public:
1065 { /* Nothing. */ }
1066
1067 /* See language.h. */
1068
1069 const char *name () const override
1070 { return "asm"; }
1071
1072 /* See language.h. */
1073
1074 const char *natural_name () const override
1075 { return "Assembly"; }
1076
1077 /* See language.h. */
1078
1079 const std::vector<const char *> &filename_extensions () const override
1080 {
1081 static const std::vector<const char *> extensions
1082 = { ".s", ".sx", ".S" };
1083 return extensions;
1084 }
1085
1086 /* See language.h.
1087
1088 FIXME: Should this have its own arch info method? */
1090 struct language_arch_info *lai) const override
1091 {
1093 }
1094
1095 /* See language.h. */
1096
1097 bool can_print_type_offsets () const override
1098 {
1099 return true;
1100 }
1101
1102 /* See language.h. */
1103
1104 void print_type (struct type *type, const char *varstring,
1105 struct ui_file *stream, int show, int level,
1106 const struct type_print_options *flags) const override
1107 {
1108 c_print_type (type, varstring, stream, show, level, la_language, flags);
1109 }
1110
1111 /* See language.h. */
1112
1114 { return true; }
1115
1116 /* See language.h. */
1117
1118 enum macro_expansion macro_expansion () const override
1119 { return macro_expansion_c; }
1120};
1121
1122/* The single instance of the ASM language class. */
1124
1125/* A class for the minimal language. This does not represent a real
1126 language. It just provides a minimal support a-la-C that should allow
1127 users to do some simple operations when debugging applications that use
1128 a language currently not supported by GDB. */
1129
1131{
1132public:
1135 { /* Nothing. */ }
1136
1137 /* See language.h. */
1138
1139 const char *name () const override
1140 { return "minimal"; }
1141
1142 /* See language.h. */
1143
1144 const char *natural_name () const override
1145 { return "Minimal"; }
1146
1147 /* See language.h. */
1149 struct language_arch_info *lai) const override
1150 {
1152 }
1153
1154 /* See language.h. */
1155
1156 bool can_print_type_offsets () const override
1157 {
1158 return true;
1159 }
1160
1161 /* See language.h. */
1162
1163 void print_type (struct type *type, const char *varstring,
1164 struct ui_file *stream, int show, int level,
1165 const struct type_print_options *flags) const override
1166 {
1167 c_print_type (type, varstring, stream, show, level, la_language, flags);
1168 }
1169
1170 /* See language.h. */
1171
1173 { return true; }
1174
1175 /* See language.h. */
1176
1177 enum macro_expansion macro_expansion () const override
1178 { return macro_expansion_c; }
1179};
1180
1181/* The single instance of the minimal language class. */
const char *const name
Definition: aarch64-tdep.c:67
void * xmalloc(YYSIZE_T)
static const char * convert_octal(struct type *type, const char *p, const char *limit, struct obstack *output)
Definition: c-lang.c:447
bool c_is_string_type_p(struct type *type)
Definition: c-lang.c:695
void c_language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai)
Definition: c-lang.c:745
static void emit_numeric_character(struct type *type, unsigned long value, struct obstack *output)
Definition: c-lang.c:431
static const char * convert_ucn(const char *p, const char *limit, const char *dest_charset, struct obstack *output, int length)
Definition: c-lang.c:405
static const char * convert_hex(struct type *type, const char *p, const char *limit, struct obstack *output)
Definition: c-lang.c:472
void c_get_string(struct value *value, gdb::unique_xmalloc_ptr< gdb_byte > *buffer, int *length, struct type **char_type, const char **charset)
Definition: c-lang.c:243
static asm_language asm_language_defn
Definition: c-lang.c:1123
static void parse_one_string(struct obstack *output, const char *data, int len, const char *dest_charset, struct type *type)
Definition: c-lang.c:556
static cplus_language cplus_language_defn
Definition: c-lang.c:1056
static c_language c_language_defn
Definition: c-lang.c:860
static const char * charset_for_string_type(c_string_type str_type, struct gdbarch *gdbarch)
Definition: c-lang.c:46
gdb::unique_xmalloc_ptr< char > c_canonicalize_name(const char *name)
Definition: c-lang.c:733
static minimal_language minimal_language_defn
Definition: c-lang.c:1182
#define ADVANCE
Definition: c-lang.c:488
static c_string_type classify_type(struct type *elttype, struct gdbarch *gdbarch, const char **encoding)
Definition: c-lang.c:77
static const char * convert_escape(struct type *type, const char *dest_charset, const char *p, const char *limit, struct obstack *output)
Definition: c-lang.c:503
std::string cplus_compute_program(compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc)
std::unique_ptr< compile_instance > cplus_get_compile_context()
@ C_WIDE_STRING
Definition: c-lang.h:42
@ C_STRING_16
Definition: c-lang.h:44
@ C_CHAR_16
Definition: c-lang.h:54
@ C_STRING
Definition: c-lang.h:40
@ C_WIDE_CHAR
Definition: c-lang.h:52
@ C_CHAR_32
Definition: c-lang.h:56
@ C_CHAR
Definition: c-lang.h:50
@ C_STRING_32
Definition: c-lang.h:46
std::string c_compute_program(compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc)
void c_print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, enum language language, const struct type_print_options *flags)
Definition: c-typeprint.c:169
int c_textual_element_type(struct type *, char)
Definition: c-valprint.c:57
std::unique_ptr< compile_instance > c_get_compile_context()
const struct lang_varobj_ops cplus_varobj_ops
Definition: c-varobj.c:944
const char * target_wide_charset(struct gdbarch *gdbarch)
Definition: charset.c:432
const char * host_charset(void)
Definition: charset.c:416
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:497
const char * target_charset(struct gdbarch *gdbarch)
Definition: charset.c:424
@ translit_none
Definition: charset.h:46
const char * natural_name() const override
Definition: c-lang.c:1074
const std::vector< const char * > & filename_extensions() const override
Definition: c-lang.c:1079
bool store_sym_names_in_linkage_form_p() const override
Definition: c-lang.c:1113
enum macro_expansion macro_expansion() const override
Definition: c-lang.c:1118
void language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai) const override
Definition: c-lang.c:1089
const char * name() const override
Definition: c-lang.c:1069
void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override
Definition: c-lang.c:1104
bool can_print_type_offsets() const override
Definition: c-lang.c:1097
asm_language()
Definition: c-lang.c:1063
bool can_print_type_offsets() const override
Definition: c-lang.c:833
const char * name() const override
Definition: c-lang.c:792
c_language()
Definition: c-lang.c:786
const char * natural_name() const override
Definition: c-lang.c:797
std::string compute_program(compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc) const override
Definition: c-lang.c:822
void language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai) const override
Definition: c-lang.c:809
enum macro_expansion macro_expansion() const override
Definition: c-lang.c:854
void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override
Definition: c-lang.c:840
const std::vector< const char * > & filename_extensions() const override
Definition: c-lang.c:802
std::unique_ptr< compile_instance > get_compile_instance() const override
Definition: c-lang.c:816
bool store_sym_names_in_linkage_form_p() const override
Definition: c-lang.c:849
const struct lang_varobj_ops * varobj_ops() const override
Definition: c-lang.c:1040
bool sniff_from_mangled_name(const char *mangled, gdb::unique_xmalloc_ptr< char > *demangled) const override
Definition: c-lang.c:973
char * class_name_from_physname(const char *physname) const override
Definition: c-lang.c:1014
struct block_symbol lookup_symbol_nonlocal(const char *name, const struct block *block, const domain_enum domain) const override
Definition: c-lang.c:1022
void language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai) const override
Definition: c-lang.c:903
cplus_language()
Definition: c-lang.c:867
std::unique_ptr< compile_instance > get_compile_instance() const override
Definition: c-lang.c:950
enum macro_expansion macro_expansion() const override
Definition: c-lang.c:1035
symbol_name_matcher_ftype * get_symbol_name_matcher_inner(const lookup_name_info &lookup_name) const override
Definition: c-lang.c:1048
std::string compute_program(compile_instance *inst, const char *input, struct gdbarch *gdbarch, const struct block *expr_block, CORE_ADDR expr_pc) const override
Definition: c-lang.c:956
const char * name_of_this() const override
Definition: c-lang.c:1030
unsigned int search_name_hash(const char *name) const override
Definition: c-lang.c:966
const char * name() const override
Definition: c-lang.c:873
bool can_print_type_offsets() const override
Definition: c-lang.c:990
struct language_pass_by_ref_info pass_by_reference_info(struct type *type) const override
Definition: c-lang.c:897
struct type * lookup_transparent_type(const char *name) const override
Definition: c-lang.c:944
const char * natural_name() const override
Definition: c-lang.c:878
CORE_ADDR skip_trampoline(frame_info_ptr fi, CORE_ADDR pc) const override
Definition: c-lang.c:1006
const char * get_digit_separator() const override
Definition: c-lang.c:882
gdb::unique_xmalloc_ptr< char > demangle_symbol(const char *mangled, int options) const override
Definition: c-lang.c:982
void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override
Definition: c-lang.c:997
const std::vector< const char * > & filename_extensions() const override
Definition: c-lang.c:887
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition: c-lang.c:586
enum macro_expansion macro_expansion() const override
Definition: c-lang.c:1177
bool store_sym_names_in_linkage_form_p() const override
Definition: c-lang.c:1172
void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override
Definition: c-lang.c:1163
const char * name() const override
Definition: c-lang.c:1139
const char * natural_name() const override
Definition: c-lang.c:1144
bool can_print_type_offsets() const override
Definition: c-lang.c:1156
void language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai) const override
Definition: c-lang.c:1148
void memory_error(enum target_xfer_status err, CORE_ADDR memaddr)
Definition: corefile.c:185
struct language_pass_by_ref_info cp_pass_by_reference(struct type *type)
Definition: cp-abi.c:226
CORE_ADDR cplus_skip_trampoline(frame_info_ptr frame, CORE_ADDR stop_pc)
Definition: cp-abi.c:155
struct type * cp_lookup_transparent_type(const char *name)
Definition: cp-namespace.c:961
struct block_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:710
gdb::unique_xmalloc_ptr< char > gdb_demangle(const char *name, int options)
Definition: cp-support.c:1606
symbol_name_matcher_ftype * cp_get_symbol_name_matcher(const lookup_name_info &lookup_name)
Definition: cp-support.c:1870
gdb::unique_xmalloc_ptr< char > cp_canonicalize_string(const char *string)
Definition: cp-support.c:626
char * cp_class_name_from_physname(const char *physname)
Definition: cp-support.c:705
unsigned int cp_search_name_hash(const char *search_name)
Definition: cp-support.c:1695
@ language_minimal
Definition: defs.h:225
@ language_cplus
Definition: defs.h:216
@ language_asm
Definition: defs.h:221
@ language_c
Definition: defs.h:214
@ lval_memory
Definition: defs.h:364
@ not_lval
Definition: defs.h:362
@ lval_internalvar
Definition: defs.h:368
#define UINT_MAX
Definition: defs.h:453
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition: defs.h:526
noside
Definition: expression.h:55
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1370
enum bfd_endian type_byte_order(const struct type *type)
Definition: gdbtypes.c:4018
struct type * lookup_typename(const struct language_defn *language, const char *name, const struct block *block, int noerr)
Definition: gdbtypes.c:1702
bool get_discrete_bounds(struct type *type, LONGEST *lowp, LONGEST *highp)
Definition: gdbtypes.c:1201
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:3010
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition: gnu-nat.c:1790
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition: gnu-nat.c:1862
struct type * language_string_char_type(const struct language_defn *la, struct gdbarch *gdbarch)
Definition: language.c:925
macro_expansion
Definition: language.h:83
@ macro_expansion_c
Definition: language.h:84
Definition: ada-exp.h:80
Definition: block.h:109
struct type * builtin_signed_char
Definition: gdbtypes.h:2250
struct type * builtin_declong
Definition: gdbtypes.h:2268
struct type * builtin_long_long
Definition: gdbtypes.h:2264
struct type * builtin_double
Definition: gdbtypes.h:2258
struct type * builtin_long
Definition: gdbtypes.h:2249
struct type * builtin_bool
Definition: gdbtypes.h:2263
struct type * builtin_unsigned_char
Definition: gdbtypes.h:2251
struct type * builtin_complex
Definition: gdbtypes.h:2260
struct type * builtin_long_double
Definition: gdbtypes.h:2259
struct type * builtin_unsigned_long_long
Definition: gdbtypes.h:2265
struct type * builtin_char16
Definition: gdbtypes.h:2295
struct type * builtin_short
Definition: gdbtypes.h:2247
struct type * builtin_double_complex
Definition: gdbtypes.h:2261
struct type * builtin_char
Definition: gdbtypes.h:2246
struct type * builtin_int
Definition: gdbtypes.h:2248
struct type * builtin_decfloat
Definition: gdbtypes.h:2266
struct type * builtin_unsigned_short
Definition: gdbtypes.h:2252
struct type * builtin_wchar
Definition: gdbtypes.h:2297
struct type * builtin_unsigned_int
Definition: gdbtypes.h:2253
struct type * builtin_decdouble
Definition: gdbtypes.h:2267
struct type * builtin_char32
Definition: gdbtypes.h:2296
struct type * builtin_unsigned_long
Definition: gdbtypes.h:2254
struct type * builtin_void
Definition: gdbtypes.h:2245
struct type * builtin_float
Definition: gdbtypes.h:2257
const struct language_defn * language_defn
Definition: expression.h:223
struct gdbarch * gdbarch
Definition: expression.h:225
struct type * type() const
Definition: gdbtypes.h:559
void set_string_char_type(struct type *type)
Definition: language.h:114
void add_primitive_type(struct type *type)
Definition: language.h:130
void set_bool_type(struct type *type, const char *name=nullptr)
Definition: language.h:102
virtual void emitchar(int ch, struct type *chtype, struct ui_file *stream, int quoter) const
Definition: c-lang.c:147
enum language la_language
Definition: language.h:275
virtual void printstr(struct ui_file *stream, struct type *elttype, const gdb_byte *string, unsigned int length, const char *encoding, int force_ellipses, const struct value_print_options *options) const
Definition: c-lang.c:193
virtual void printchar(int ch, struct type *chtype, struct ui_file *stream) const
Definition: c-lang.c:159
Definition: gdbtypes.h:922
struct type * target_type() const
Definition: gdbtypes.h:1000
type_code code() const
Definition: gdbtypes.h:927
ULONGEST length() const
Definition: gdbtypes.h:954
struct field & field(int idx) const
Definition: gdbtypes.h:983
int num_fields() const
Definition: gdbtypes.h:965
gdbarch * arch() const
Definition: gdbtypes.c:245
const char * name() const
Definition: gdbtypes.h:939
type * index_type() const
Definition: gdbtypes.h:995
Definition: value.c:181
bool() symbol_name_matcher_ftype(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
Definition: symtab.h:398
domain_enum
Definition: symtab.h:871
int target_read_string(CORE_ADDR addr, int len, int width, unsigned int fetchlimit, gdb::unique_xmalloc_ptr< gdb_byte > *buffer, int *bytes_read)
Definition: target.c:65
@ TARGET_XFER_E_IO
Definition: target.h:227
std::string type_to_string(struct type *type)
Definition: typeprint.c:402
void gdb_putc(int c)
Definition: utils.c:1841
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:1788
struct value * value_cstring(const char *ptr, ssize_t len, struct type *char_type)
Definition: valops.c:1736
void generic_emit_char(int c, struct type *type, struct ui_file *stream, int quoter, const char *encoding)
Definition: valprint.c:2174
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:2492
struct type * value_type(const struct value *value)
Definition: value.c:1109
struct value * allocate_value(struct type *type)
Definition: value.c:1053
CORE_ADDR value_as_address(struct value *val)
Definition: value.c:2804
CORE_ADDR value_address(const struct value *value)
Definition: value.c:1607
struct value * value_from_longest(struct type *type, LONGEST num)
Definition: value.c:3625
gdb::array_view< gdb_byte > value_contents_raw(struct value *value)
Definition: value.c:1167
gdb::array_view< const gdb_byte > value_contents(struct value *value)
Definition: value.c:1464
void pack_long(gdb_byte *buf, struct type *type, LONGEST num)
Definition: value.c:3513
LONGEST unpack_long(struct type *type, const gdb_byte *valaddr)
Definition: value.c:2921
#define VALUE_LVAL(val)
Definition: value.h:438