a9895feaf158af7c30475f6866a156f6a5c18d63
[deliverable/binutils-gdb.git] / gdb / rust-lang.c
1 /* Rust language support routines for GDB, the GNU debugger.
2
3 Copyright (C) 2016-2017 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
22 #include <ctype.h>
23
24 #include "block.h"
25 #include "c-lang.h"
26 #include "charset.h"
27 #include "cp-support.h"
28 #include "demangle.h"
29 #include "gdbarch.h"
30 #include "infcall.h"
31 #include "objfiles.h"
32 #include "rust-lang.h"
33 #include "valprint.h"
34 #include "varobj.h"
35 #include <string>
36 #include <vector>
37
38 /* Returns the last segment of a Rust path like foo::bar::baz. Will
39 not handle cases where the last segment contains generics. This
40 will return NULL if the last segment cannot be found. */
41
42 static const char *
43 rust_last_path_segment (const char * path)
44 {
45 const char *result = strrchr (path, ':');
46
47 if (result == NULL)
48 return NULL;
49 return result + 1;
50 }
51
52 /* See rust-lang.h. */
53
54 std::string
55 rust_crate_for_block (const struct block *block)
56 {
57 const char *scope = block_scope (block);
58
59 if (scope[0] == '\0')
60 return std::string ();
61
62 return std::string (scope, cp_find_first_component (scope));
63 }
64
65 /* Information about the discriminant/variant of an enum */
66
67 struct disr_info
68 {
69 /* Name of field. */
70 std::string name;
71 /* Field number in union. Negative on error. For an encoded enum,
72 the "hidden" member will always be field 1, and the "real" member
73 will always be field 0. */
74 int field_no;
75 /* True if this is an encoded enum that has a single "real" member
76 and a single "hidden" member. */
77 unsigned int is_encoded : 1;
78 };
79
80 /* The prefix of a specially-encoded enum. */
81
82 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
83
84 /* The number of the real field. */
85
86 #define RUST_ENCODED_ENUM_REAL 0
87
88 /* The number of the hidden field. */
89
90 #define RUST_ENCODED_ENUM_HIDDEN 1
91
92 /* Whether or not a TYPE_CODE_UNION value is an untagged union
93 as opposed to being a regular Rust enum. */
94 static bool
95 rust_union_is_untagged (struct type *type)
96 {
97 /* Unions must have at least one field. */
98 if (TYPE_NFIELDS (type) == 0)
99 return false;
100 /* If the first field is named, but the name has the rust enum prefix,
101 it is an enum. */
102 if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX,
103 strlen (RUST_ENUM_PREFIX)) == 0)
104 return false;
105 /* Unions only have named fields. */
106 for (int i = 0; i < TYPE_NFIELDS (type); ++i)
107 {
108 if (strlen (TYPE_FIELD_NAME (type, i)) == 0)
109 return false;
110 }
111 return true;
112 }
113
114 /* Utility function to get discriminant info for a given value. */
115
116 static struct disr_info
117 rust_get_disr_info (struct type *type, const gdb_byte *valaddr,
118 int embedded_offset, CORE_ADDR address,
119 struct value *val)
120 {
121 int i;
122 struct disr_info ret;
123 struct type *disr_type;
124 struct value_print_options opts;
125 const char *name_segment;
126
127 get_no_prettyformat_print_options (&opts);
128
129 ret.field_no = -1;
130 ret.is_encoded = 0;
131
132 if (TYPE_NFIELDS (type) == 0)
133 error (_("Encountered void enum value"));
134
135 /* If an enum has two values where one is empty and the other holds
136 a pointer that cannot be zero; then the Rust compiler optimizes
137 away the discriminant and instead uses a zero value in the
138 pointer field to indicate the empty variant. */
139 if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX,
140 strlen (RUST_ENUM_PREFIX)) == 0)
141 {
142 char *tail, *token, *saveptr = NULL;
143 unsigned long fieldno;
144 struct type *member_type;
145 LONGEST value;
146
147 ret.is_encoded = 1;
148
149 if (TYPE_NFIELDS (type) != 1)
150 error (_("Only expected one field in %s type"), RUST_ENUM_PREFIX);
151
152 /* Optimized enums have only one field. */
153 member_type = TYPE_FIELD_TYPE (type, 0);
154
155 std::string name (TYPE_FIELD_NAME (type, 0));
156 tail = &name[0] + strlen (RUST_ENUM_PREFIX);
157
158 /* The location of the value that doubles as a discriminant is
159 stored in the name of the field, as
160 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
161 where the fieldnos are the indices of the fields that should be
162 traversed in order to find the field (which may be several fields deep)
163 and the variantname is the name of the variant of the case when the
164 field is zero. */
165 for (token = strtok_r (tail, "$", &saveptr);
166 token != NULL;
167 token = strtok_r (NULL, "$", &saveptr))
168 {
169 if (sscanf (token, "%lu", &fieldno) != 1)
170 {
171 /* We have reached the enum name, which cannot start
172 with a digit. */
173 break;
174 }
175 if (fieldno >= TYPE_NFIELDS (member_type))
176 error (_("%s refers to field after end of member type"),
177 RUST_ENUM_PREFIX);
178
179 embedded_offset += TYPE_FIELD_BITPOS (member_type, fieldno) / 8;
180 member_type = TYPE_FIELD_TYPE (member_type, fieldno);
181 }
182
183 if (token == NULL)
184 error (_("Invalid form for %s"), RUST_ENUM_PREFIX);
185 value = unpack_long (member_type, valaddr + embedded_offset);
186
187 if (value == 0)
188 {
189 ret.field_no = RUST_ENCODED_ENUM_HIDDEN;
190 ret.name = std::string (TYPE_NAME (type)) + "::" + token;
191 }
192 else
193 {
194 ret.field_no = RUST_ENCODED_ENUM_REAL;
195 ret.name = (std::string (TYPE_NAME (type)) + "::"
196 + rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (type, 0))));
197 }
198
199 return ret;
200 }
201
202 disr_type = TYPE_FIELD_TYPE (type, 0);
203
204 if (TYPE_NFIELDS (disr_type) == 0)
205 {
206 /* This is a bounds check and should never be hit unless Rust
207 has changed its debuginfo format. */
208 error (_("Could not find enum discriminant field"));
209 }
210 else if (TYPE_NFIELDS (type) == 1)
211 {
212 /* Sometimes univariant enums are encoded without a
213 discriminant. In that case, treating it as an encoded enum
214 with the first field being the actual type works. */
215 const char *field_name = TYPE_NAME (TYPE_FIELD_TYPE (type, 0));
216 const char *last = rust_last_path_segment (field_name);
217 ret.name = std::string (TYPE_NAME (type)) + "::" + last;
218 ret.field_no = RUST_ENCODED_ENUM_REAL;
219 ret.is_encoded = 1;
220 return ret;
221 }
222
223 if (strcmp (TYPE_FIELD_NAME (disr_type, 0), "RUST$ENUM$DISR") != 0)
224 error (_("Rust debug format has changed"));
225
226 string_file temp_file;
227 /* The first value of the first field (or any field)
228 is the discriminant value. */
229 c_val_print (TYPE_FIELD_TYPE (disr_type, 0),
230 (embedded_offset + TYPE_FIELD_BITPOS (type, 0) / 8
231 + TYPE_FIELD_BITPOS (disr_type, 0) / 8),
232 address, &temp_file,
233 0, val, &opts);
234
235 ret.name = std::move (temp_file.string ());
236 name_segment = rust_last_path_segment (ret.name.c_str ());
237 if (name_segment != NULL)
238 {
239 for (i = 0; i < TYPE_NFIELDS (type); ++i)
240 {
241 /* Sadly, the discriminant value paths do not match the type
242 field name paths ('core::option::Option::Some' vs
243 'core::option::Some'). However, enum variant names are
244 unique in the last path segment and the generics are not
245 part of this path, so we can just compare those. This is
246 hackish and would be better fixed by improving rustc's
247 metadata for enums. */
248 const char *field_type = TYPE_NAME (TYPE_FIELD_TYPE (type, i));
249
250 if (field_type != NULL
251 && strcmp (name_segment,
252 rust_last_path_segment (field_type)) == 0)
253 {
254 ret.field_no = i;
255 break;
256 }
257 }
258 }
259
260 if (ret.field_no == -1 && !ret.name.empty ())
261 {
262 /* Somehow the discriminant wasn't found. */
263 error (_("Could not find variant of %s with discriminant %s"),
264 TYPE_TAG_NAME (type), ret.name.c_str ());
265 }
266
267 return ret;
268 }
269
270 /* See rust-lang.h. */
271
272 bool
273 rust_tuple_type_p (struct type *type)
274 {
275 /* The current implementation is a bit of a hack, but there's
276 nothing else in the debuginfo to distinguish a tuple from a
277 struct. */
278 return (TYPE_CODE (type) == TYPE_CODE_STRUCT
279 && TYPE_TAG_NAME (type) != NULL
280 && TYPE_TAG_NAME (type)[0] == '(');
281 }
282
283
284 /* Return true if all non-static fields of a structlike type are in a
285 sequence like __0, __1, __2. OFFSET lets us skip fields. */
286
287 static bool
288 rust_underscore_fields (struct type *type, int offset)
289 {
290 int i, field_number;
291
292 field_number = 0;
293
294 if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
295 return false;
296 for (i = 0; i < TYPE_NFIELDS (type); ++i)
297 {
298 if (!field_is_static (&TYPE_FIELD (type, i)))
299 {
300 if (offset > 0)
301 offset--;
302 else
303 {
304 char buf[20];
305
306 xsnprintf (buf, sizeof (buf), "__%d", field_number);
307 if (strcmp (buf, TYPE_FIELD_NAME (type, i)) != 0)
308 return false;
309 field_number++;
310 }
311 }
312 }
313 return true;
314 }
315
316 /* See rust-lang.h. */
317
318 bool
319 rust_tuple_struct_type_p (struct type *type)
320 {
321 /* This is just an approximation until DWARF can represent Rust more
322 precisely. We exclude zero-length structs because they may not
323 be tuple structs, and there's no way to tell. */
324 return TYPE_NFIELDS (type) > 0 && rust_underscore_fields (type, 0);
325 }
326
327 /* Return true if a variant TYPE is a tuple variant, false otherwise. */
328
329 static bool
330 rust_tuple_variant_type_p (struct type *type)
331 {
332 /* First field is discriminant */
333 return rust_underscore_fields (type, 1);
334 }
335
336 /* Return true if TYPE is a slice type, otherwise false. */
337
338 static bool
339 rust_slice_type_p (struct type *type)
340 {
341 return (TYPE_CODE (type) == TYPE_CODE_STRUCT
342 && TYPE_TAG_NAME (type) != NULL
343 && (strncmp (TYPE_TAG_NAME (type), "&[", 2) == 0
344 || strcmp (TYPE_TAG_NAME (type), "&str") == 0));
345 }
346
347 /* Return true if TYPE is a range type, otherwise false. */
348
349 static bool
350 rust_range_type_p (struct type *type)
351 {
352 int i;
353
354 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
355 || TYPE_NFIELDS (type) > 2
356 || TYPE_TAG_NAME (type) == NULL
357 || strstr (TYPE_TAG_NAME (type), "::Range") == NULL)
358 return false;
359
360 if (TYPE_NFIELDS (type) == 0)
361 return true;
362
363 i = 0;
364 if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
365 {
366 if (TYPE_NFIELDS (type) == 1)
367 return true;
368 i = 1;
369 }
370 else if (TYPE_NFIELDS (type) == 2)
371 {
372 /* First field had to be "start". */
373 return false;
374 }
375
376 return strcmp (TYPE_FIELD_NAME (type, i), "end") == 0;
377 }
378
379 /* Return true if TYPE seems to be the type "u8", otherwise false. */
380
381 static bool
382 rust_u8_type_p (struct type *type)
383 {
384 return (TYPE_CODE (type) == TYPE_CODE_INT
385 && TYPE_UNSIGNED (type)
386 && TYPE_LENGTH (type) == 1);
387 }
388
389 /* Return true if TYPE is a Rust character type. */
390
391 static bool
392 rust_chartype_p (struct type *type)
393 {
394 return (TYPE_CODE (type) == TYPE_CODE_CHAR
395 && TYPE_LENGTH (type) == 4
396 && TYPE_UNSIGNED (type));
397 }
398
399 \f
400
401 /* la_emitchar implementation for Rust. */
402
403 static void
404 rust_emitchar (int c, struct type *type, struct ui_file *stream, int quoter)
405 {
406 if (!rust_chartype_p (type))
407 generic_emit_char (c, type, stream, quoter,
408 target_charset (get_type_arch (type)));
409 else if (c == '\\' || c == quoter)
410 fprintf_filtered (stream, "\\%c", c);
411 else if (c == '\n')
412 fputs_filtered ("\\n", stream);
413 else if (c == '\r')
414 fputs_filtered ("\\r", stream);
415 else if (c == '\t')
416 fputs_filtered ("\\t", stream);
417 else if (c == '\0')
418 fputs_filtered ("\\0", stream);
419 else if (c >= 32 && c <= 127 && isprint (c))
420 fputc_filtered (c, stream);
421 else if (c <= 255)
422 fprintf_filtered (stream, "\\x%02x", c);
423 else
424 fprintf_filtered (stream, "\\u{%06x}", c);
425 }
426
427 /* la_printchar implementation for Rust. */
428
429 static void
430 rust_printchar (int c, struct type *type, struct ui_file *stream)
431 {
432 fputs_filtered ("'", stream);
433 LA_EMIT_CHAR (c, type, stream, '\'');
434 fputs_filtered ("'", stream);
435 }
436
437 /* la_printstr implementation for Rust. */
438
439 static void
440 rust_printstr (struct ui_file *stream, struct type *type,
441 const gdb_byte *string, unsigned int length,
442 const char *user_encoding, int force_ellipses,
443 const struct value_print_options *options)
444 {
445 /* Rust always uses UTF-8, but let the caller override this if need
446 be. */
447 const char *encoding = user_encoding;
448 if (user_encoding == NULL || !*user_encoding)
449 {
450 /* In Rust strings, characters are "u8". */
451 if (rust_u8_type_p (type))
452 encoding = "UTF-8";
453 else
454 {
455 /* This is probably some C string, so let's let C deal with
456 it. */
457 c_printstr (stream, type, string, length, user_encoding,
458 force_ellipses, options);
459 return;
460 }
461 }
462
463 /* This is not ideal as it doesn't use our character printer. */
464 generic_printstr (stream, type, string, length, encoding, force_ellipses,
465 '"', 0, options);
466 }
467
468 \f
469
470 /* rust_print_type branch for structs and untagged unions. */
471
472 static void
473 val_print_struct (struct type *type, int embedded_offset,
474 CORE_ADDR address, struct ui_file *stream,
475 int recurse, struct value *val,
476 const struct value_print_options *options)
477 {
478 int i;
479 int first_field;
480 bool is_tuple = rust_tuple_type_p (type);
481 bool is_tuple_struct = !is_tuple && rust_tuple_struct_type_p (type);
482 struct value_print_options opts;
483
484 if (!is_tuple)
485 {
486 if (TYPE_TAG_NAME (type) != NULL)
487 fprintf_filtered (stream, "%s", TYPE_TAG_NAME (type));
488
489 if (TYPE_NFIELDS (type) == 0)
490 return;
491
492 if (TYPE_TAG_NAME (type) != NULL)
493 fputs_filtered (" ", stream);
494 }
495
496 if (is_tuple || is_tuple_struct)
497 fputs_filtered ("(", stream);
498 else
499 fputs_filtered ("{", stream);
500
501 opts = *options;
502 opts.deref_ref = 0;
503
504 first_field = 1;
505 for (i = 0; i < TYPE_NFIELDS (type); ++i)
506 {
507 if (field_is_static (&TYPE_FIELD (type, i)))
508 continue;
509
510 if (!first_field)
511 fputs_filtered (",", stream);
512
513 if (options->prettyformat)
514 {
515 fputs_filtered ("\n", stream);
516 print_spaces_filtered (2 + 2 * recurse, stream);
517 }
518 else if (!first_field)
519 fputs_filtered (" ", stream);
520
521 first_field = 0;
522
523 if (!is_tuple && !is_tuple_struct)
524 {
525 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
526 fputs_filtered (": ", stream);
527 }
528
529 val_print (TYPE_FIELD_TYPE (type, i),
530 embedded_offset + TYPE_FIELD_BITPOS (type, i) / 8,
531 address,
532 stream, recurse + 1, val, &opts,
533 current_language);
534 }
535
536 if (options->prettyformat)
537 {
538 fputs_filtered ("\n", stream);
539 print_spaces_filtered (2 * recurse, stream);
540 }
541
542 if (is_tuple || is_tuple_struct)
543 fputs_filtered (")", stream);
544 else
545 fputs_filtered ("}", stream);
546 }
547
548 static const struct generic_val_print_decorations rust_decorations =
549 {
550 /* Complex isn't used in Rust, but we provide C-ish values just in
551 case. */
552 "",
553 " + ",
554 " * I",
555 "true",
556 "false",
557 "()",
558 "[",
559 "]"
560 };
561
562 /* la_val_print implementation for Rust. */
563
564 static void
565 rust_val_print (struct type *type, int embedded_offset,
566 CORE_ADDR address, struct ui_file *stream, int recurse,
567 struct value *val,
568 const struct value_print_options *options)
569 {
570 const gdb_byte *valaddr = value_contents_for_printing (val);
571
572 type = check_typedef (type);
573 switch (TYPE_CODE (type))
574 {
575 case TYPE_CODE_PTR:
576 {
577 LONGEST low_bound, high_bound;
578
579 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY
580 && rust_u8_type_p (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)))
581 && get_array_bounds (TYPE_TARGET_TYPE (type), &low_bound,
582 &high_bound)) {
583 /* We have a pointer to a byte string, so just print
584 that. */
585 struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
586 CORE_ADDR addr;
587 struct gdbarch *arch = get_type_arch (type);
588 int unit_size = gdbarch_addressable_memory_unit_size (arch);
589
590 addr = unpack_pointer (type, valaddr + embedded_offset * unit_size);
591 if (options->addressprint)
592 {
593 fputs_filtered (paddress (arch, addr), stream);
594 fputs_filtered (" ", stream);
595 }
596
597 fputs_filtered ("b", stream);
598 val_print_string (TYPE_TARGET_TYPE (elttype), "ASCII", addr,
599 high_bound - low_bound + 1, stream,
600 options);
601 break;
602 }
603 }
604 /* Fall through. */
605
606 case TYPE_CODE_METHODPTR:
607 case TYPE_CODE_MEMBERPTR:
608 c_val_print (type, embedded_offset, address, stream,
609 recurse, val, options);
610 break;
611
612 case TYPE_CODE_INT:
613 /* Recognize the unit type. */
614 if (TYPE_UNSIGNED (type) && TYPE_LENGTH (type) == 0
615 && TYPE_NAME (type) != NULL && strcmp (TYPE_NAME (type), "()") == 0)
616 {
617 fputs_filtered ("()", stream);
618 break;
619 }
620 goto generic_print;
621
622 case TYPE_CODE_STRING:
623 {
624 struct gdbarch *arch = get_type_arch (type);
625 int unit_size = gdbarch_addressable_memory_unit_size (arch);
626 LONGEST low_bound, high_bound;
627
628 if (!get_array_bounds (type, &low_bound, &high_bound))
629 error (_("Could not determine the array bounds"));
630
631 /* If we see a plain TYPE_CODE_STRING, then we're printing a
632 byte string, hence the choice of "ASCII" as the
633 encoding. */
634 fputs_filtered ("b", stream);
635 rust_printstr (stream, TYPE_TARGET_TYPE (type),
636 valaddr + embedded_offset * unit_size,
637 high_bound - low_bound + 1, "ASCII", 0, options);
638 }
639 break;
640
641 case TYPE_CODE_ARRAY:
642 {
643 LONGEST low_bound, high_bound;
644
645 if (get_array_bounds (type, &low_bound, &high_bound)
646 && high_bound - low_bound + 1 == 0)
647 fputs_filtered ("[]", stream);
648 else
649 goto generic_print;
650 }
651 break;
652
653 case TYPE_CODE_UNION:
654 {
655 int j, nfields, first_field, is_tuple, start;
656 struct type *variant_type;
657 struct disr_info disr;
658 struct value_print_options opts;
659
660 /* Untagged unions are printed as if they are structs.
661 Since the field bit positions overlap in the debuginfo,
662 the code for printing a union is same as that for a struct,
663 the only difference is that the input type will have overlapping
664 fields. */
665 if (rust_union_is_untagged (type))
666 {
667 val_print_struct (type, embedded_offset, address, stream,
668 recurse, val, options);
669 break;
670 }
671
672 opts = *options;
673 opts.deref_ref = 0;
674
675 disr = rust_get_disr_info (type, valaddr, embedded_offset, address,
676 val);
677
678 if (disr.is_encoded && disr.field_no == RUST_ENCODED_ENUM_HIDDEN)
679 {
680 fprintf_filtered (stream, "%s", disr.name.c_str ());
681 break;
682 }
683
684 first_field = 1;
685 variant_type = TYPE_FIELD_TYPE (type, disr.field_no);
686 nfields = TYPE_NFIELDS (variant_type);
687
688 is_tuple = (disr.is_encoded
689 ? rust_tuple_struct_type_p (variant_type)
690 : rust_tuple_variant_type_p (variant_type));
691 start = disr.is_encoded ? 0 : 1;
692
693 if (nfields > start)
694 {
695 /* In case of a non-nullary variant, we output 'Foo(x,y,z)'. */
696 if (is_tuple)
697 fprintf_filtered (stream, "%s(", disr.name.c_str ());
698 else
699 {
700 /* struct variant. */
701 fprintf_filtered (stream, "%s{", disr.name.c_str ());
702 }
703 }
704 else
705 {
706 /* In case of a nullary variant like 'None', just output
707 the name. */
708 fprintf_filtered (stream, "%s", disr.name.c_str ());
709 break;
710 }
711
712 for (j = start; j < TYPE_NFIELDS (variant_type); j++)
713 {
714 if (!first_field)
715 fputs_filtered (", ", stream);
716 first_field = 0;
717
718 if (!is_tuple)
719 fprintf_filtered (stream, "%s: ",
720 TYPE_FIELD_NAME (variant_type, j));
721
722 val_print (TYPE_FIELD_TYPE (variant_type, j),
723 (embedded_offset
724 + TYPE_FIELD_BITPOS (type, disr.field_no) / 8
725 + TYPE_FIELD_BITPOS (variant_type, j) / 8),
726 address,
727 stream, recurse + 1, val, &opts,
728 current_language);
729 }
730
731 if (is_tuple)
732 fputs_filtered (")", stream);
733 else
734 fputs_filtered ("}", stream);
735 }
736 break;
737
738 case TYPE_CODE_STRUCT:
739 val_print_struct (type, embedded_offset, address, stream,
740 recurse, val, options);
741 break;
742
743 default:
744 generic_print:
745 /* Nothing special yet. */
746 generic_val_print (type, embedded_offset, address, stream,
747 recurse, val, options, &rust_decorations);
748 }
749 }
750
751 \f
752
753 static void
754 rust_print_type (struct type *type, const char *varstring,
755 struct ui_file *stream, int show, int level,
756 const struct type_print_options *flags);
757
758 /* Print a struct or union typedef. */
759 static void
760 rust_print_struct_def (struct type *type, const char *varstring,
761 struct ui_file *stream, int show, int level,
762 const struct type_print_options *flags)
763 {
764 bool is_tuple_struct;
765 int i;
766
767 /* Print a tuple type simply. */
768 if (rust_tuple_type_p (type))
769 {
770 fputs_filtered (TYPE_TAG_NAME (type), stream);
771 return;
772 }
773
774 /* If we see a base class, delegate to C. */
775 if (TYPE_N_BASECLASSES (type) > 0)
776 c_print_type (type, varstring, stream, show, level, flags);
777
778 /* This code path is also used by unions. */
779 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
780 fputs_filtered ("struct ", stream);
781 else
782 fputs_filtered ("union ", stream);
783
784 if (TYPE_TAG_NAME (type) != NULL)
785 fputs_filtered (TYPE_TAG_NAME (type), stream);
786
787 is_tuple_struct = rust_tuple_struct_type_p (type);
788
789 if (TYPE_NFIELDS (type) == 0 && !rust_tuple_type_p (type))
790 return;
791 fputs_filtered (is_tuple_struct ? " (\n" : " {\n", stream);
792
793 for (i = 0; i < TYPE_NFIELDS (type); ++i)
794 {
795 const char *name;
796
797 QUIT;
798 if (field_is_static (&TYPE_FIELD (type, i)))
799 continue;
800
801 /* We'd like to print "pub" here as needed, but rustc
802 doesn't emit the debuginfo, and our types don't have
803 cplus_struct_type attached. */
804
805 /* For a tuple struct we print the type but nothing
806 else. */
807 print_spaces_filtered (level + 2, stream);
808 if (!is_tuple_struct)
809 fprintf_filtered (stream, "%s: ", TYPE_FIELD_NAME (type, i));
810
811 rust_print_type (TYPE_FIELD_TYPE (type, i), NULL,
812 stream, show - 1, level + 2,
813 flags);
814 fputs_filtered (",\n", stream);
815 }
816
817 fprintfi_filtered (level, stream, is_tuple_struct ? ")" : "}");
818 }
819
820 /* la_print_typedef implementation for Rust. */
821
822 static void
823 rust_print_typedef (struct type *type,
824 struct symbol *new_symbol,
825 struct ui_file *stream)
826 {
827 type = check_typedef (type);
828 fprintf_filtered (stream, "type %s = ", SYMBOL_PRINT_NAME (new_symbol));
829 type_print (type, "", stream, 0);
830 fprintf_filtered (stream, ";\n");
831 }
832
833 /* la_print_type implementation for Rust. */
834
835 static void
836 rust_print_type (struct type *type, const char *varstring,
837 struct ui_file *stream, int show, int level,
838 const struct type_print_options *flags)
839 {
840 int i;
841
842 QUIT;
843 if (show <= 0
844 && TYPE_NAME (type) != NULL)
845 {
846 /* Rust calls the unit type "void" in its debuginfo,
847 but we don't want to print it as that. */
848 if (TYPE_CODE (type) == TYPE_CODE_VOID)
849 fputs_filtered ("()", stream);
850 else
851 fputs_filtered (TYPE_NAME (type), stream);
852 return;
853 }
854
855 type = check_typedef (type);
856 switch (TYPE_CODE (type))
857 {
858 case TYPE_CODE_VOID:
859 fputs_filtered ("()", stream);
860 break;
861
862 case TYPE_CODE_FUNC:
863 /* Delegate varargs to the C printer. */
864 if (TYPE_VARARGS (type))
865 goto c_printer;
866
867 fputs_filtered ("fn ", stream);
868 if (varstring != NULL)
869 fputs_filtered (varstring, stream);
870 fputs_filtered ("(", stream);
871 for (i = 0; i < TYPE_NFIELDS (type); ++i)
872 {
873 QUIT;
874 if (i > 0)
875 fputs_filtered (", ", stream);
876 rust_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0,
877 flags);
878 }
879 fputs_filtered (")", stream);
880 /* If it returns unit, we can omit the return type. */
881 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
882 {
883 fputs_filtered (" -> ", stream);
884 rust_print_type (TYPE_TARGET_TYPE (type), "", stream, -1, 0, flags);
885 }
886 break;
887
888 case TYPE_CODE_ARRAY:
889 {
890 LONGEST low_bound, high_bound;
891
892 fputs_filtered ("[", stream);
893 rust_print_type (TYPE_TARGET_TYPE (type), NULL,
894 stream, show - 1, level, flags);
895
896 if (TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCEXPR
897 || TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCLIST)
898 fprintf_filtered (stream, "; variable length");
899 else if (get_array_bounds (type, &low_bound, &high_bound))
900 fprintf_filtered (stream, "; %s",
901 plongest (high_bound - low_bound + 1));
902 fputs_filtered ("]", stream);
903 }
904 break;
905
906 case TYPE_CODE_STRUCT:
907 rust_print_struct_def (type, varstring, stream, show, level, flags);
908 break;
909
910 case TYPE_CODE_ENUM:
911 {
912 int i, len = 0;
913
914 fputs_filtered ("enum ", stream);
915 if (TYPE_TAG_NAME (type) != NULL)
916 {
917 fputs_filtered (TYPE_TAG_NAME (type), stream);
918 fputs_filtered (" ", stream);
919 len = strlen (TYPE_TAG_NAME (type));
920 }
921 fputs_filtered ("{\n", stream);
922
923 for (i = 0; i < TYPE_NFIELDS (type); ++i)
924 {
925 const char *name = TYPE_FIELD_NAME (type, i);
926
927 QUIT;
928
929 if (len > 0
930 && strncmp (name, TYPE_TAG_NAME (type), len) == 0
931 && name[len] == ':'
932 && name[len + 1] == ':')
933 name += len + 2;
934 fprintfi_filtered (level + 2, stream, "%s,\n", name);
935 }
936
937 fputs_filtered ("}", stream);
938 }
939 break;
940
941 case TYPE_CODE_UNION:
942 {
943 /* ADT enums. */
944 int i, len = 0;
945 /* Skip the discriminant field. */
946 int skip_to = 1;
947
948 /* Unions and structs have the same syntax in Rust,
949 the only difference is that structs are declared with `struct`
950 and union with `union`. This difference is handled in the struct
951 printer. */
952 if (rust_union_is_untagged (type))
953 {
954 rust_print_struct_def (type, varstring, stream, show, level, flags);
955 break;
956 }
957
958 fputs_filtered ("enum ", stream);
959 if (TYPE_TAG_NAME (type) != NULL)
960 {
961 fputs_filtered (TYPE_TAG_NAME (type), stream);
962 fputs_filtered (" ", stream);
963 }
964 fputs_filtered ("{\n", stream);
965
966 if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX,
967 strlen (RUST_ENUM_PREFIX)) == 0)
968 {
969 const char *zero_field = strrchr (TYPE_FIELD_NAME (type, 0), '$');
970 if (zero_field != NULL && strlen (zero_field) > 1)
971 {
972 fprintfi_filtered (level + 2, stream, "%s,\n", zero_field + 1);
973 /* There is no explicit discriminant field, skip nothing. */
974 skip_to = 0;
975 }
976 }
977 else if (TYPE_NFIELDS (type) == 1)
978 skip_to = 0;
979
980 for (i = 0; i < TYPE_NFIELDS (type); ++i)
981 {
982 struct type *variant_type = TYPE_FIELD_TYPE (type, i);
983 const char *name
984 = rust_last_path_segment (TYPE_NAME (variant_type));
985
986 fprintfi_filtered (level + 2, stream, "%s", name);
987
988 if (TYPE_NFIELDS (variant_type) > skip_to)
989 {
990 int first = 1;
991 bool is_tuple = (TYPE_NFIELDS (type) == 1
992 ? rust_tuple_struct_type_p (variant_type)
993 : rust_tuple_variant_type_p (variant_type));
994 int j;
995
996 fputs_filtered (is_tuple ? "(" : "{", stream);
997 for (j = skip_to; j < TYPE_NFIELDS (variant_type); j++)
998 {
999 if (first)
1000 first = 0;
1001 else
1002 fputs_filtered (", ", stream);
1003
1004 if (!is_tuple)
1005 fprintf_filtered (stream, "%s: ",
1006 TYPE_FIELD_NAME (variant_type, j));
1007
1008 rust_print_type (TYPE_FIELD_TYPE (variant_type, j), NULL,
1009 stream, show - 1, level + 2,
1010 flags);
1011 }
1012 fputs_filtered (is_tuple ? ")" : "}", stream);
1013 }
1014
1015 fputs_filtered (",\n", stream);
1016 }
1017
1018 fputs_filtered ("}", stream);
1019 }
1020 break;
1021
1022 default:
1023 c_printer:
1024 c_print_type (type, varstring, stream, show, level, flags);
1025 }
1026 }
1027
1028 \f
1029
1030 /* Compute the alignment of the type T. */
1031
1032 static int
1033 rust_type_alignment (struct type *t)
1034 {
1035 t = check_typedef (t);
1036 switch (TYPE_CODE (t))
1037 {
1038 default:
1039 error (_("Could not compute alignment of type"));
1040
1041 case TYPE_CODE_PTR:
1042 case TYPE_CODE_ENUM:
1043 case TYPE_CODE_INT:
1044 case TYPE_CODE_FLT:
1045 case TYPE_CODE_REF:
1046 case TYPE_CODE_CHAR:
1047 case TYPE_CODE_BOOL:
1048 return TYPE_LENGTH (t);
1049
1050 case TYPE_CODE_ARRAY:
1051 case TYPE_CODE_COMPLEX:
1052 return rust_type_alignment (TYPE_TARGET_TYPE (t));
1053
1054 case TYPE_CODE_STRUCT:
1055 case TYPE_CODE_UNION:
1056 {
1057 int i;
1058 int align = 1;
1059
1060 for (i = 0; i < TYPE_NFIELDS (t); ++i)
1061 {
1062 int a = rust_type_alignment (TYPE_FIELD_TYPE (t, i));
1063 if (a > align)
1064 align = a;
1065 }
1066 return align;
1067 }
1068 }
1069 }
1070
1071 /* Like arch_composite_type, but uses TYPE to decide how to allocate
1072 -- either on an obstack or on a gdbarch. */
1073
1074 static struct type *
1075 rust_composite_type (struct type *original,
1076 const char *name,
1077 const char *field1, struct type *type1,
1078 const char *field2, struct type *type2)
1079 {
1080 struct type *result = alloc_type_copy (original);
1081 int i, nfields, bitpos;
1082
1083 nfields = 0;
1084 if (field1 != NULL)
1085 ++nfields;
1086 if (field2 != NULL)
1087 ++nfields;
1088
1089 TYPE_CODE (result) = TYPE_CODE_STRUCT;
1090 TYPE_NAME (result) = name;
1091 TYPE_TAG_NAME (result) = name;
1092
1093 TYPE_NFIELDS (result) = nfields;
1094 TYPE_FIELDS (result)
1095 = (struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field));
1096
1097 i = 0;
1098 bitpos = 0;
1099 if (field1 != NULL)
1100 {
1101 struct field *field = &TYPE_FIELD (result, i);
1102
1103 SET_FIELD_BITPOS (*field, bitpos);
1104 bitpos += TYPE_LENGTH (type1) * TARGET_CHAR_BIT;
1105
1106 FIELD_NAME (*field) = field1;
1107 FIELD_TYPE (*field) = type1;
1108 ++i;
1109 }
1110 if (field2 != NULL)
1111 {
1112 struct field *field = &TYPE_FIELD (result, i);
1113 int align = rust_type_alignment (type2);
1114
1115 if (align != 0)
1116 {
1117 int delta;
1118
1119 align *= TARGET_CHAR_BIT;
1120 delta = bitpos % align;
1121 if (delta != 0)
1122 bitpos += align - delta;
1123 }
1124 SET_FIELD_BITPOS (*field, bitpos);
1125
1126 FIELD_NAME (*field) = field2;
1127 FIELD_TYPE (*field) = type2;
1128 ++i;
1129 }
1130
1131 if (i > 0)
1132 TYPE_LENGTH (result)
1133 = (TYPE_FIELD_BITPOS (result, i - 1) / TARGET_CHAR_BIT +
1134 TYPE_LENGTH (TYPE_FIELD_TYPE (result, i - 1)));
1135 return result;
1136 }
1137
1138 /* See rust-lang.h. */
1139
1140 struct type *
1141 rust_slice_type (const char *name, struct type *elt_type,
1142 struct type *usize_type)
1143 {
1144 struct type *type;
1145
1146 elt_type = lookup_pointer_type (elt_type);
1147 type = rust_composite_type (elt_type, name,
1148 "data_ptr", elt_type,
1149 "length", usize_type);
1150
1151 return type;
1152 }
1153
1154 enum rust_primitive_types
1155 {
1156 rust_primitive_bool,
1157 rust_primitive_char,
1158 rust_primitive_i8,
1159 rust_primitive_u8,
1160 rust_primitive_i16,
1161 rust_primitive_u16,
1162 rust_primitive_i32,
1163 rust_primitive_u32,
1164 rust_primitive_i64,
1165 rust_primitive_u64,
1166 rust_primitive_isize,
1167 rust_primitive_usize,
1168 rust_primitive_f32,
1169 rust_primitive_f64,
1170 rust_primitive_unit,
1171 rust_primitive_str,
1172 nr_rust_primitive_types
1173 };
1174
1175 /* la_language_arch_info implementation for Rust. */
1176
1177 static void
1178 rust_language_arch_info (struct gdbarch *gdbarch,
1179 struct language_arch_info *lai)
1180 {
1181 const struct builtin_type *builtin = builtin_type (gdbarch);
1182 struct type *tem;
1183 struct type **types;
1184 unsigned int length;
1185
1186 types = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_rust_primitive_types + 1,
1187 struct type *);
1188
1189 types[rust_primitive_bool] = arch_boolean_type (gdbarch, 8, 1, "bool");
1190 types[rust_primitive_char] = arch_character_type (gdbarch, 32, 1, "char");
1191 types[rust_primitive_i8] = arch_integer_type (gdbarch, 8, 0, "i8");
1192 types[rust_primitive_u8] = arch_integer_type (gdbarch, 8, 1, "u8");
1193 types[rust_primitive_i16] = arch_integer_type (gdbarch, 16, 0, "i16");
1194 types[rust_primitive_u16] = arch_integer_type (gdbarch, 16, 1, "u16");
1195 types[rust_primitive_i32] = arch_integer_type (gdbarch, 32, 0, "i32");
1196 types[rust_primitive_u32] = arch_integer_type (gdbarch, 32, 1, "u32");
1197 types[rust_primitive_i64] = arch_integer_type (gdbarch, 64, 0, "i64");
1198 types[rust_primitive_u64] = arch_integer_type (gdbarch, 64, 1, "u64");
1199
1200 length = 8 * TYPE_LENGTH (builtin->builtin_data_ptr);
1201 types[rust_primitive_isize] = arch_integer_type (gdbarch, length, 0, "isize");
1202 types[rust_primitive_usize] = arch_integer_type (gdbarch, length, 1, "usize");
1203
1204 types[rust_primitive_f32] = arch_float_type (gdbarch, 32, "f32",
1205 floatformats_ieee_single);
1206 types[rust_primitive_f64] = arch_float_type (gdbarch, 64, "f64",
1207 floatformats_ieee_double);
1208
1209 types[rust_primitive_unit] = arch_integer_type (gdbarch, 0, 1, "()");
1210
1211 tem = make_cv_type (1, 0, types[rust_primitive_u8], NULL);
1212 types[rust_primitive_str] = rust_slice_type ("&str", tem,
1213 types[rust_primitive_usize]);
1214
1215 lai->primitive_type_vector = types;
1216 lai->bool_type_default = types[rust_primitive_bool];
1217 lai->string_char_type = types[rust_primitive_u8];
1218 }
1219
1220 \f
1221
1222 /* A helper for rust_evaluate_subexp that handles OP_FUNCALL. */
1223
1224 static struct value *
1225 rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
1226 {
1227 int i;
1228 int num_args = exp->elts[*pos + 1].longconst;
1229 const char *method;
1230 struct value *function, *result, *arg0;
1231 struct type *type, *fn_type;
1232 const struct block *block;
1233 struct block_symbol sym;
1234
1235 /* For an ordinary function call we can simply defer to the
1236 generic implementation. */
1237 if (exp->elts[*pos + 3].opcode != STRUCTOP_STRUCT)
1238 return evaluate_subexp_standard (NULL, exp, pos, noside);
1239
1240 /* Skip over the OP_FUNCALL and the STRUCTOP_STRUCT. */
1241 *pos += 4;
1242 method = &exp->elts[*pos + 1].string;
1243 *pos += 3 + BYTES_TO_EXP_ELEM (exp->elts[*pos].longconst + 1);
1244
1245 /* Evaluate the argument to STRUCTOP_STRUCT, then find its
1246 type in order to look up the method. */
1247 arg0 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1248
1249 if (noside == EVAL_SKIP)
1250 {
1251 for (i = 0; i < num_args; ++i)
1252 evaluate_subexp (NULL_TYPE, exp, pos, noside);
1253 return arg0;
1254 }
1255
1256 std::vector<struct value *> args (num_args + 1);
1257 args[0] = arg0;
1258
1259 /* We don't yet implement real Deref semantics. */
1260 while (TYPE_CODE (value_type (args[0])) == TYPE_CODE_PTR)
1261 args[0] = value_ind (args[0]);
1262
1263 type = value_type (args[0]);
1264 if ((TYPE_CODE (type) != TYPE_CODE_STRUCT
1265 && TYPE_CODE (type) != TYPE_CODE_UNION
1266 && TYPE_CODE (type) != TYPE_CODE_ENUM)
1267 || rust_tuple_type_p (type))
1268 error (_("Method calls only supported on struct or enum types"));
1269 if (TYPE_TAG_NAME (type) == NULL)
1270 error (_("Method call on nameless type"));
1271
1272 std::string name = std::string (TYPE_TAG_NAME (type)) + "::" + method;
1273
1274 block = get_selected_block (0);
1275 sym = lookup_symbol (name.c_str (), block, VAR_DOMAIN, NULL);
1276 if (sym.symbol == NULL)
1277 error (_("Could not find function named '%s'"), name.c_str ());
1278
1279 fn_type = SYMBOL_TYPE (sym.symbol);
1280 if (TYPE_NFIELDS (fn_type) == 0)
1281 error (_("Function '%s' takes no arguments"), name.c_str ());
1282
1283 if (TYPE_CODE (TYPE_FIELD_TYPE (fn_type, 0)) == TYPE_CODE_PTR)
1284 args[0] = value_addr (args[0]);
1285
1286 function = address_of_variable (sym.symbol, block);
1287
1288 for (i = 0; i < num_args; ++i)
1289 args[i + 1] = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1290
1291 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1292 result = value_zero (TYPE_TARGET_TYPE (fn_type), not_lval);
1293 else
1294 result = call_function_by_hand (function, NULL, num_args + 1, args.data ());
1295 return result;
1296 }
1297
1298 /* A helper for rust_evaluate_subexp that handles OP_RANGE. */
1299
1300 static struct value *
1301 rust_range (struct expression *exp, int *pos, enum noside noside)
1302 {
1303 enum range_type kind;
1304 struct value *low = NULL, *high = NULL;
1305 struct value *addrval, *result;
1306 CORE_ADDR addr;
1307 struct type *range_type;
1308 struct type *index_type;
1309 struct type *temp_type;
1310 const char *name;
1311
1312 kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
1313 *pos += 3;
1314
1315 if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
1316 low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1317 if (kind == LOW_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
1318 high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1319
1320 if (noside == EVAL_SKIP)
1321 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
1322
1323 if (low == NULL)
1324 {
1325 if (high == NULL)
1326 {
1327 index_type = NULL;
1328 name = "std::ops::RangeFull";
1329 }
1330 else
1331 {
1332 index_type = value_type (high);
1333 name = "std::ops::RangeTo";
1334 }
1335 }
1336 else
1337 {
1338 if (high == NULL)
1339 {
1340 index_type = value_type (low);
1341 name = "std::ops::RangeFrom";
1342 }
1343 else
1344 {
1345 if (!types_equal (value_type (low), value_type (high)))
1346 error (_("Range expression with different types"));
1347 index_type = value_type (low);
1348 name = "std::ops::Range";
1349 }
1350 }
1351
1352 /* If we don't have an index type, just allocate this on the
1353 arch. Here any type will do. */
1354 temp_type = (index_type == NULL
1355 ? language_bool_type (exp->language_defn, exp->gdbarch)
1356 : index_type);
1357 /* It would be nicer to cache the range type. */
1358 range_type = rust_composite_type (temp_type, name,
1359 low == NULL ? NULL : "start", index_type,
1360 high == NULL ? NULL : "end", index_type);
1361
1362 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1363 return value_zero (range_type, lval_memory);
1364
1365 addrval = value_allocate_space_in_inferior (TYPE_LENGTH (range_type));
1366 addr = value_as_long (addrval);
1367 result = value_at_lazy (range_type, addr);
1368
1369 if (low != NULL)
1370 {
1371 struct value *start = value_struct_elt (&result, NULL, "start", NULL,
1372 "range");
1373
1374 value_assign (start, low);
1375 }
1376
1377 if (high != NULL)
1378 {
1379 struct value *end = value_struct_elt (&result, NULL, "end", NULL,
1380 "range");
1381
1382 value_assign (end, high);
1383 }
1384
1385 result = value_at_lazy (range_type, addr);
1386 return result;
1387 }
1388
1389 /* A helper function to compute the range and kind given a range
1390 value. TYPE is the type of the range value. RANGE is the range
1391 value. LOW, HIGH, and KIND are out parameters. The LOW and HIGH
1392 parameters might be filled in, or might not be, depending on the
1393 kind of range this is. KIND will always be set to the appropriate
1394 value describing the kind of range, and this can be used to
1395 determine whether LOW or HIGH are valid. */
1396
1397 static void
1398 rust_compute_range (struct type *type, struct value *range,
1399 LONGEST *low, LONGEST *high,
1400 enum range_type *kind)
1401 {
1402 int i;
1403
1404 *low = 0;
1405 *high = 0;
1406 *kind = BOTH_BOUND_DEFAULT;
1407
1408 if (TYPE_NFIELDS (type) == 0)
1409 return;
1410
1411 i = 0;
1412 if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
1413 {
1414 *kind = HIGH_BOUND_DEFAULT;
1415 *low = value_as_long (value_field (range, 0));
1416 ++i;
1417 }
1418 if (TYPE_NFIELDS (type) > i
1419 && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
1420 {
1421 *kind = (*kind == BOTH_BOUND_DEFAULT
1422 ? LOW_BOUND_DEFAULT : NONE_BOUND_DEFAULT);
1423 *high = value_as_long (value_field (range, i));
1424 }
1425 }
1426
1427 /* A helper for rust_evaluate_subexp that handles BINOP_SUBSCRIPT. */
1428
1429 static struct value *
1430 rust_subscript (struct expression *exp, int *pos, enum noside noside,
1431 int for_addr)
1432 {
1433 struct value *lhs, *rhs, *result;
1434 struct type *rhstype;
1435 LONGEST low, high_bound;
1436 /* Initialized to appease the compiler. */
1437 enum range_type kind = BOTH_BOUND_DEFAULT;
1438 LONGEST high = 0;
1439 int want_slice = 0;
1440
1441 ++*pos;
1442 lhs = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1443 rhs = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1444
1445 if (noside == EVAL_SKIP)
1446 return lhs;
1447
1448 rhstype = check_typedef (value_type (rhs));
1449 if (rust_range_type_p (rhstype))
1450 {
1451 if (!for_addr)
1452 error (_("Can't take slice of array without '&'"));
1453 rust_compute_range (rhstype, rhs, &low, &high, &kind);
1454 want_slice = 1;
1455 }
1456 else
1457 low = value_as_long (rhs);
1458
1459 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1460 {
1461 struct type *type = check_typedef (value_type (lhs));
1462
1463 result = value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (lhs));
1464 }
1465 else
1466 {
1467 LONGEST low_bound;
1468 struct value *base;
1469 struct type *type = check_typedef (value_type (lhs));
1470
1471 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
1472 {
1473 base = lhs;
1474 if (!get_array_bounds (type, &low_bound, &high_bound))
1475 error (_("Can't compute array bounds"));
1476 if (low_bound != 0)
1477 error (_("Found array with non-zero lower bound"));
1478 ++high_bound;
1479 }
1480 else if (rust_slice_type_p (type))
1481 {
1482 struct value *len;
1483
1484 base = value_struct_elt (&lhs, NULL, "data_ptr", NULL, "slice");
1485 len = value_struct_elt (&lhs, NULL, "length", NULL, "slice");
1486 low_bound = 0;
1487 high_bound = value_as_long (len);
1488 }
1489 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
1490 {
1491 base = lhs;
1492 low_bound = 0;
1493 high_bound = LONGEST_MAX;
1494 }
1495 else
1496 error (_("Cannot subscript non-array type"));
1497
1498 if (want_slice
1499 && (kind == BOTH_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT))
1500 low = low_bound;
1501 if (low < 0)
1502 error (_("Index less than zero"));
1503 if (low > high_bound)
1504 error (_("Index greater than length"));
1505
1506 result = value_subscript (base, low);
1507 }
1508
1509 if (for_addr)
1510 {
1511 if (want_slice)
1512 {
1513 struct type *usize, *slice;
1514 CORE_ADDR addr;
1515 struct value *addrval, *tem;
1516
1517 if (kind == BOTH_BOUND_DEFAULT || kind == HIGH_BOUND_DEFAULT)
1518 high = high_bound;
1519 if (high < 0)
1520 error (_("High index less than zero"));
1521 if (low > high)
1522 error (_("Low index greater than high index"));
1523 if (high > high_bound)
1524 error (_("High index greater than length"));
1525
1526 usize = language_lookup_primitive_type (exp->language_defn,
1527 exp->gdbarch,
1528 "usize");
1529 slice = rust_slice_type ("&[*gdb*]", value_type (result),
1530 usize);
1531
1532 addrval = value_allocate_space_in_inferior (TYPE_LENGTH (slice));
1533 addr = value_as_long (addrval);
1534 tem = value_at_lazy (slice, addr);
1535
1536 value_assign (value_field (tem, 0), value_addr (result));
1537 value_assign (value_field (tem, 1),
1538 value_from_longest (usize, high - low));
1539
1540 result = value_at_lazy (slice, addr);
1541 }
1542 else
1543 result = value_addr (result);
1544 }
1545
1546 return result;
1547 }
1548
1549 /* evaluate_exp implementation for Rust. */
1550
1551 static struct value *
1552 rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
1553 int *pos, enum noside noside)
1554 {
1555 struct value *result;
1556
1557 switch (exp->elts[*pos].opcode)
1558 {
1559 case UNOP_COMPLEMENT:
1560 {
1561 struct value *value;
1562
1563 ++*pos;
1564 value = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1565 if (noside == EVAL_SKIP)
1566 {
1567 /* Preserving the type is enough. */
1568 return value;
1569 }
1570 if (TYPE_CODE (value_type (value)) == TYPE_CODE_BOOL)
1571 result = value_from_longest (value_type (value),
1572 value_logical_not (value));
1573 else
1574 result = value_complement (value);
1575 }
1576 break;
1577
1578 case BINOP_SUBSCRIPT:
1579 result = rust_subscript (exp, pos, noside, 0);
1580 break;
1581
1582 case OP_FUNCALL:
1583 result = rust_evaluate_funcall (exp, pos, noside);
1584 break;
1585
1586 case OP_AGGREGATE:
1587 {
1588 int pc = (*pos)++;
1589 struct type *type = exp->elts[pc + 1].type;
1590 int arglen = longest_to_int (exp->elts[pc + 2].longconst);
1591 int i;
1592 CORE_ADDR addr = 0;
1593 struct value *addrval = NULL;
1594
1595 *pos += 3;
1596
1597 if (noside == EVAL_NORMAL)
1598 {
1599 addrval = value_allocate_space_in_inferior (TYPE_LENGTH (type));
1600 addr = value_as_long (addrval);
1601 result = value_at_lazy (type, addr);
1602 }
1603
1604 if (arglen > 0 && exp->elts[*pos].opcode == OP_OTHERS)
1605 {
1606 struct value *init;
1607
1608 ++*pos;
1609 init = rust_evaluate_subexp (NULL, exp, pos, noside);
1610 if (noside == EVAL_NORMAL)
1611 {
1612 /* This isn't quite right but will do for the time
1613 being, seeing that we can't implement the Copy
1614 trait anyway. */
1615 value_assign (result, init);
1616 }
1617
1618 --arglen;
1619 }
1620
1621 gdb_assert (arglen % 2 == 0);
1622 for (i = 0; i < arglen; i += 2)
1623 {
1624 int len;
1625 const char *fieldname;
1626 struct value *value, *field;
1627
1628 gdb_assert (exp->elts[*pos].opcode == OP_NAME);
1629 ++*pos;
1630 len = longest_to_int (exp->elts[*pos].longconst);
1631 ++*pos;
1632 fieldname = &exp->elts[*pos].string;
1633 *pos += 2 + BYTES_TO_EXP_ELEM (len + 1);
1634
1635 value = rust_evaluate_subexp (NULL, exp, pos, noside);
1636 if (noside == EVAL_NORMAL)
1637 {
1638 field = value_struct_elt (&result, NULL, fieldname, NULL,
1639 "structure");
1640 value_assign (field, value);
1641 }
1642 }
1643
1644 if (noside == EVAL_SKIP)
1645 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
1646 1);
1647 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1648 result = allocate_value (type);
1649 else
1650 result = value_at_lazy (type, addr);
1651 }
1652 break;
1653
1654 case OP_RUST_ARRAY:
1655 {
1656 int pc = (*pos)++;
1657 int copies;
1658 struct value *elt;
1659 struct value *ncopies;
1660
1661 elt = rust_evaluate_subexp (NULL, exp, pos, noside);
1662 ncopies = rust_evaluate_subexp (NULL, exp, pos, noside);
1663 copies = value_as_long (ncopies);
1664 if (copies < 0)
1665 error (_("Array with negative number of elements"));
1666
1667 if (noside == EVAL_NORMAL)
1668 {
1669 CORE_ADDR addr;
1670 int i;
1671 std::vector<struct value *> eltvec (copies);
1672
1673 for (i = 0; i < copies; ++i)
1674 eltvec[i] = elt;
1675 result = value_array (0, copies - 1, eltvec.data ());
1676 }
1677 else
1678 {
1679 struct type *arraytype
1680 = lookup_array_range_type (value_type (elt), 0, copies - 1);
1681 result = allocate_value (arraytype);
1682 }
1683 }
1684 break;
1685
1686 case STRUCTOP_ANONYMOUS:
1687 {
1688 /* Anonymous field access, i.e. foo.1. */
1689 struct value *lhs;
1690 int pc, field_number, nfields;
1691 struct type *type, *variant_type;
1692 struct disr_info disr;
1693
1694 pc = (*pos)++;
1695 field_number = longest_to_int (exp->elts[pc + 1].longconst);
1696 (*pos) += 2;
1697 lhs = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1698
1699 type = value_type (lhs);
1700 /* Untagged unions can't have anonymous field access since
1701 they can only have named fields. */
1702 if (TYPE_CODE (type) == TYPE_CODE_UNION
1703 && !rust_union_is_untagged (type))
1704 {
1705 disr = rust_get_disr_info (type, value_contents (lhs),
1706 value_embedded_offset (lhs),
1707 value_address (lhs), lhs);
1708
1709 if (disr.is_encoded && disr.field_no == RUST_ENCODED_ENUM_HIDDEN)
1710 {
1711 variant_type = NULL;
1712 nfields = 0;
1713 }
1714 else
1715 {
1716 variant_type = TYPE_FIELD_TYPE (type, disr.field_no);
1717 nfields = TYPE_NFIELDS (variant_type);
1718 }
1719
1720 if (!disr.is_encoded)
1721 ++field_number;
1722
1723 if (field_number >= nfields || field_number < 0)
1724 error(_("Cannot access field %d of variant %s, \
1725 there are only %d fields"),
1726 disr.is_encoded ? field_number : field_number - 1,
1727 disr.name.c_str (),
1728 disr.is_encoded ? nfields : nfields - 1);
1729
1730 if (!(disr.is_encoded
1731 ? rust_tuple_struct_type_p (variant_type)
1732 : rust_tuple_variant_type_p (variant_type)))
1733 error(_("Variant %s is not a tuple variant"), disr.name.c_str ());
1734
1735 result = value_primitive_field (lhs, 0, field_number,
1736 variant_type);
1737 }
1738 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1739 {
1740 /* Tuples and tuple structs */
1741 nfields = TYPE_NFIELDS(type);
1742
1743 if (field_number >= nfields || field_number < 0)
1744 error(_("Cannot access field %d of %s, there are only %d fields"),
1745 field_number, TYPE_TAG_NAME (type), nfields);
1746
1747 /* Tuples are tuple structs too. */
1748 if (!rust_tuple_struct_type_p (type))
1749 error(_("Attempting to access anonymous field %d of %s, which is \
1750 not a tuple, tuple struct, or tuple-like variant"),
1751 field_number, TYPE_TAG_NAME (type));
1752
1753 result = value_primitive_field (lhs, 0, field_number, type);
1754 }
1755 else
1756 error(_("Anonymous field access is only allowed on tuples, \
1757 tuple structs, and tuple-like enum variants"));
1758 }
1759 break;
1760
1761 case STRUCTOP_STRUCT:
1762 {
1763 struct value *lhs;
1764 struct type *type;
1765 int tem, pc;
1766
1767 pc = (*pos)++;
1768 tem = longest_to_int (exp->elts[pc + 1].longconst);
1769 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1770 lhs = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1771
1772 const char *field_name = &exp->elts[pc + 2].string;
1773 type = value_type (lhs);
1774 if (TYPE_CODE (type) == TYPE_CODE_UNION
1775 && !rust_union_is_untagged (type))
1776 {
1777 int i, start;
1778 struct disr_info disr;
1779 struct type *variant_type;
1780
1781 disr = rust_get_disr_info (type, value_contents (lhs),
1782 value_embedded_offset (lhs),
1783 value_address (lhs), lhs);
1784
1785 if (disr.is_encoded && disr.field_no == RUST_ENCODED_ENUM_HIDDEN)
1786 error(_("Could not find field %s of struct variant %s"),
1787 field_name, disr.name.c_str ());
1788
1789 variant_type = TYPE_FIELD_TYPE (type, disr.field_no);
1790
1791 if (variant_type == NULL
1792 || (disr.is_encoded
1793 ? rust_tuple_struct_type_p (variant_type)
1794 : rust_tuple_variant_type_p (variant_type)))
1795 error(_("Attempting to access named field %s of tuple variant %s, \
1796 which has only anonymous fields"),
1797 field_name, disr.name.c_str ());
1798
1799 start = disr.is_encoded ? 0 : 1;
1800 for (i = start; i < TYPE_NFIELDS (variant_type); i++)
1801 {
1802 if (strcmp (TYPE_FIELD_NAME (variant_type, i),
1803 field_name) == 0) {
1804 result = value_primitive_field (lhs, 0, i, variant_type);
1805 break;
1806 }
1807 }
1808
1809 if (i == TYPE_NFIELDS (variant_type))
1810 /* We didn't find it. */
1811 error(_("Could not find field %s of struct variant %s"),
1812 field_name, disr.name.c_str ());
1813 }
1814 else
1815 {
1816 result = value_struct_elt (&lhs, NULL, field_name, NULL,
1817 "structure");
1818 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1819 result = value_zero (value_type (result), VALUE_LVAL (result));
1820 }
1821 }
1822 break;
1823
1824 case OP_RANGE:
1825 result = rust_range (exp, pos, noside);
1826 break;
1827
1828 case UNOP_ADDR:
1829 /* We might have &array[range], in which case we need to make a
1830 slice. */
1831 if (exp->elts[*pos + 1].opcode == BINOP_SUBSCRIPT)
1832 {
1833 ++*pos;
1834 result = rust_subscript (exp, pos, noside, 1);
1835 break;
1836 }
1837 /* Fall through. */
1838 default:
1839 result = evaluate_subexp_standard (expect_type, exp, pos, noside);
1840 break;
1841 }
1842
1843 return result;
1844 }
1845
1846 /* operator_length implementation for Rust. */
1847
1848 static void
1849 rust_operator_length (const struct expression *exp, int pc, int *oplenp,
1850 int *argsp)
1851 {
1852 int oplen = 1;
1853 int args = 0;
1854
1855 switch (exp->elts[pc - 1].opcode)
1856 {
1857 case OP_AGGREGATE:
1858 /* We handle aggregate as a type and argument count. The first
1859 argument might be OP_OTHERS. After that the arguments
1860 alternate: first an OP_NAME, then an expression. */
1861 oplen = 4;
1862 args = longest_to_int (exp->elts[pc - 2].longconst);
1863 break;
1864
1865 case OP_OTHERS:
1866 oplen = 1;
1867 args = 1;
1868 break;
1869
1870 case STRUCTOP_ANONYMOUS:
1871 oplen = 3;
1872 args = 1;
1873 break;
1874
1875 case OP_RUST_ARRAY:
1876 oplen = 1;
1877 args = 2;
1878 break;
1879
1880 default:
1881 operator_length_standard (exp, pc, oplenp, argsp);
1882 return;
1883 }
1884
1885 *oplenp = oplen;
1886 *argsp = args;
1887 }
1888
1889 /* op_name implementation for Rust. */
1890
1891 static const char *
1892 rust_op_name (enum exp_opcode opcode)
1893 {
1894 switch (opcode)
1895 {
1896 case OP_AGGREGATE:
1897 return "OP_AGGREGATE";
1898 case OP_OTHERS:
1899 return "OP_OTHERS";
1900 default:
1901 return op_name_standard (opcode);
1902 }
1903 }
1904
1905 /* dump_subexp_body implementation for Rust. */
1906
1907 static int
1908 rust_dump_subexp_body (struct expression *exp, struct ui_file *stream,
1909 int elt)
1910 {
1911 switch (exp->elts[elt].opcode)
1912 {
1913 case OP_AGGREGATE:
1914 {
1915 int length = longest_to_int (exp->elts[elt + 2].longconst);
1916 int i;
1917
1918 fprintf_filtered (stream, "Type @");
1919 gdb_print_host_address (exp->elts[elt + 1].type, stream);
1920 fprintf_filtered (stream, " (");
1921 type_print (exp->elts[elt + 1].type, NULL, stream, 0);
1922 fprintf_filtered (stream, "), length %d", length);
1923
1924 elt += 4;
1925 for (i = 0; i < length; ++i)
1926 elt = dump_subexp (exp, stream, elt);
1927 }
1928 break;
1929
1930 case OP_STRING:
1931 case OP_NAME:
1932 {
1933 LONGEST len = exp->elts[elt + 1].longconst;
1934
1935 fprintf_filtered (stream, "%s: %s",
1936 (exp->elts[elt].opcode == OP_STRING
1937 ? "string" : "name"),
1938 &exp->elts[elt + 2].string);
1939 elt += 4 + BYTES_TO_EXP_ELEM (len + 1);
1940 }
1941 break;
1942
1943 case OP_OTHERS:
1944 elt = dump_subexp (exp, stream, elt + 1);
1945 break;
1946
1947 case STRUCTOP_ANONYMOUS:
1948 {
1949 int field_number;
1950
1951 field_number = longest_to_int (exp->elts[elt + 1].longconst);
1952
1953 fprintf_filtered (stream, "Field number: %d", field_number);
1954 elt = dump_subexp (exp, stream, elt + 3);
1955 }
1956 break;
1957
1958 case OP_RUST_ARRAY:
1959 ++elt;
1960 break;
1961
1962 default:
1963 elt = dump_subexp_body_standard (exp, stream, elt);
1964 break;
1965 }
1966
1967 return elt;
1968 }
1969
1970 /* print_subexp implementation for Rust. */
1971
1972 static void
1973 rust_print_subexp (struct expression *exp, int *pos, struct ui_file *stream,
1974 enum precedence prec)
1975 {
1976 switch (exp->elts[*pos].opcode)
1977 {
1978 case OP_AGGREGATE:
1979 {
1980 int length = longest_to_int (exp->elts[*pos + 2].longconst);
1981 int i;
1982
1983 type_print (exp->elts[*pos + 1].type, "", stream, 0);
1984 fputs_filtered (" { ", stream);
1985
1986 *pos += 4;
1987 for (i = 0; i < length; ++i)
1988 {
1989 rust_print_subexp (exp, pos, stream, prec);
1990 fputs_filtered (", ", stream);
1991 }
1992 fputs_filtered (" }", stream);
1993 }
1994 break;
1995
1996 case OP_NAME:
1997 {
1998 LONGEST len = exp->elts[*pos + 1].longconst;
1999
2000 fputs_filtered (&exp->elts[*pos + 2].string, stream);
2001 *pos += 4 + BYTES_TO_EXP_ELEM (len + 1);
2002 }
2003 break;
2004
2005 case OP_OTHERS:
2006 {
2007 fputs_filtered ("<<others>> (", stream);
2008 ++*pos;
2009 rust_print_subexp (exp, pos, stream, prec);
2010 fputs_filtered (")", stream);
2011 }
2012 break;
2013
2014 case STRUCTOP_ANONYMOUS:
2015 {
2016 int tem = longest_to_int (exp->elts[*pos + 1].longconst);
2017
2018 (*pos) += 3;
2019 print_subexp (exp, pos, stream, PREC_SUFFIX);
2020 fprintf_filtered (stream, ".%d", tem);
2021 }
2022 break;
2023
2024 case OP_RUST_ARRAY:
2025 ++*pos;
2026 fprintf_filtered (stream, "[");
2027 rust_print_subexp (exp, pos, stream, prec);
2028 fprintf_filtered (stream, "; ");
2029 rust_print_subexp (exp, pos, stream, prec);
2030 fprintf_filtered (stream, "]");
2031 break;
2032
2033 default:
2034 print_subexp_standard (exp, pos, stream, prec);
2035 break;
2036 }
2037 }
2038
2039 /* operator_check implementation for Rust. */
2040
2041 static int
2042 rust_operator_check (struct expression *exp, int pos,
2043 int (*objfile_func) (struct objfile *objfile,
2044 void *data),
2045 void *data)
2046 {
2047 switch (exp->elts[pos].opcode)
2048 {
2049 case OP_AGGREGATE:
2050 {
2051 struct type *type = exp->elts[pos + 1].type;
2052 struct objfile *objfile = TYPE_OBJFILE (type);
2053
2054 if (objfile != NULL && (*objfile_func) (objfile, data))
2055 return 1;
2056 }
2057 break;
2058
2059 case OP_OTHERS:
2060 case OP_NAME:
2061 case OP_RUST_ARRAY:
2062 break;
2063
2064 default:
2065 return operator_check_standard (exp, pos, objfile_func, data);
2066 }
2067
2068 return 0;
2069 }
2070
2071 \f
2072
2073 /* Implementation of la_lookup_symbol_nonlocal for Rust. */
2074
2075 static struct block_symbol
2076 rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
2077 const char *name,
2078 const struct block *block,
2079 const domain_enum domain)
2080 {
2081 struct block_symbol result = {NULL, NULL};
2082
2083 if (symbol_lookup_debug)
2084 {
2085 fprintf_unfiltered (gdb_stdlog,
2086 "rust_lookup_symbol_non_local"
2087 " (%s, %s (scope %s), %s)\n",
2088 name, host_address_to_string (block),
2089 block_scope (block), domain_name (domain));
2090 }
2091
2092 /* Look up bare names in the block's scope. */
2093 if (name[cp_find_first_component (name)] == '\0')
2094 {
2095 const char *scope = block_scope (block);
2096
2097 if (scope[0] != '\0')
2098 {
2099 std::string scopedname = std::string (scope) + "::" + name;
2100
2101 result = lookup_symbol_in_static_block (scopedname.c_str (), block,
2102 domain);
2103 if (result.symbol == NULL)
2104 result = lookup_global_symbol (scopedname.c_str (), block, domain);
2105 }
2106 }
2107 return result;
2108 }
2109
2110 \f
2111
2112 /* la_sniff_from_mangled_name for Rust. */
2113
2114 static int
2115 rust_sniff_from_mangled_name (const char *mangled, char **demangled)
2116 {
2117 *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
2118 return *demangled != NULL;
2119 }
2120
2121 \f
2122
2123 /* la_watch_location_expression for Rust. */
2124
2125 static gdb::unique_xmalloc_ptr<char>
2126 rust_watch_location_expression (struct type *type, CORE_ADDR addr)
2127 {
2128 type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
2129 std::string name = type_to_string (type);
2130 return gdb::unique_xmalloc_ptr<char>
2131 (xstrprintf ("*(%s as *mut %s)", core_addr_to_string (addr),
2132 name.c_str ()));
2133 }
2134
2135 \f
2136
2137 static const struct exp_descriptor exp_descriptor_rust =
2138 {
2139 rust_print_subexp,
2140 rust_operator_length,
2141 rust_operator_check,
2142 rust_op_name,
2143 rust_dump_subexp_body,
2144 rust_evaluate_subexp
2145 };
2146
2147 static const char *rust_extensions[] =
2148 {
2149 ".rs", NULL
2150 };
2151
2152 extern const struct language_defn rust_language_defn =
2153 {
2154 "rust",
2155 "Rust",
2156 language_rust,
2157 range_check_on,
2158 case_sensitive_on,
2159 array_row_major,
2160 macro_expansion_no,
2161 rust_extensions,
2162 &exp_descriptor_rust,
2163 rust_parse,
2164 rustyyerror,
2165 null_post_parser,
2166 rust_printchar, /* Print a character constant */
2167 rust_printstr, /* Function to print string constant */
2168 rust_emitchar, /* Print a single char */
2169 rust_print_type, /* Print a type using appropriate syntax */
2170 rust_print_typedef, /* Print a typedef using appropriate syntax */
2171 rust_val_print, /* Print a value using appropriate syntax */
2172 c_value_print, /* Print a top-level value */
2173 default_read_var_value, /* la_read_var_value */
2174 NULL, /* Language specific skip_trampoline */
2175 NULL, /* name_of_this */
2176 rust_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
2177 basic_lookup_transparent_type,/* lookup_transparent_type */
2178 gdb_demangle, /* Language specific symbol demangler */
2179 rust_sniff_from_mangled_name,
2180 NULL, /* Language specific
2181 class_name_from_physname */
2182 c_op_print_tab, /* expression operators for printing */
2183 1, /* c-style arrays */
2184 0, /* String lower bound */
2185 default_word_break_characters,
2186 default_collect_symbol_completion_matches,
2187 rust_language_arch_info,
2188 default_print_array_index,
2189 default_pass_by_reference,
2190 c_get_string,
2191 rust_watch_location_expression,
2192 NULL, /* la_get_symbol_name_cmp */
2193 iterate_over_symbols,
2194 &default_varobj_ops,
2195 NULL,
2196 NULL,
2197 LANG_MAGIC
2198 };
This page took 0.073683 seconds and 3 git commands to generate.