arm, objdump: print obsolote warning when 26-bit set in instructions
[binutils-gdb.git] / gdb / rust-lang.h
blob866d1ac1f6d7d1524ce0d849d7177acaa8777b43
1 /* Rust language support definitions for GDB, the GNU debugger.
3 Copyright (C) 2016-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef RUST_LANG_H
21 #define RUST_LANG_H
23 #include "demangle.h"
24 #include "language.h"
25 #include "value.h"
26 #include "c-lang.h"
28 struct parser_state;
29 struct type;
31 /* Return true if TYPE is a tuple type; otherwise false. */
32 extern bool rust_tuple_type_p (struct type *type);
34 /* Return true if TYPE is a tuple struct type; otherwise false. */
35 extern bool rust_tuple_struct_type_p (struct type *type);
37 /* Given a block, find the name of the block's crate. Returns an empty
38 stringif no crate name can be found. */
39 extern std::string rust_crate_for_block (const struct block *block);
41 /* Returns the last segment of a Rust path like foo::bar::baz. Will
42 not handle cases where the last segment contains generics. */
44 extern const char *rust_last_path_segment (const char *path);
46 /* Create a new slice type. NAME is the name of the type. ELT_TYPE
47 is the type of the elements of the slice. USIZE_TYPE is the Rust
48 "usize" type to use. The new type is allocated wherever ELT_TYPE
49 is allocated. */
50 extern struct type *rust_slice_type (const char *name, struct type *elt_type,
51 struct type *usize_type);
53 /* Return a new array that holds the contents of the given slice,
54 VAL. */
55 extern struct value *rust_slice_to_array (struct value *val);
57 /* Class representing the Rust language. */
59 class rust_language : public language_defn
61 public:
62 rust_language ()
63 : language_defn (language_rust)
64 { /* Nothing. */ }
66 /* See language.h. */
68 const char *name () const override
69 { return "rust"; }
71 /* See language.h. */
73 const char *natural_name () const override
74 { return "Rust"; }
76 /* See language.h. */
78 const char *get_digit_separator () const override
79 { return "_"; }
81 /* See language.h. */
83 const std::vector<const char *> &filename_extensions () const override
85 static const std::vector<const char *> extensions = { ".rs" };
86 return extensions;
89 /* See language.h. */
91 void language_arch_info (struct gdbarch *gdbarch,
92 struct language_arch_info *lai) const override;
94 /* See language.h. */
96 bool sniff_from_mangled_name
97 (const char *mangled, gdb::unique_xmalloc_ptr<char> *demangled)
98 const override
100 demangled->reset (rust_demangle (mangled, 0));
101 return *demangled != NULL;
104 /* See language.h. */
106 gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
107 int options) const override
109 return gdb::unique_xmalloc_ptr<char> (rust_demangle (mangled, options));
112 /* See language.h. */
114 bool can_print_type_offsets () const override
116 return true;
119 /* See language.h. */
121 void print_type (struct type *type, const char *varstring,
122 struct ui_file *stream, int show, int level,
123 const struct type_print_options *flags) const override;
125 /* See language.h. */
127 gdb::unique_xmalloc_ptr<char> watch_location_expression
128 (struct type *type, CORE_ADDR addr) const override
130 type = check_typedef (check_typedef (type)->target_type ());
131 std::string name = type_to_string (type);
132 return xstrprintf ("*(%s as *mut %s)", core_addr_to_string (addr),
133 name.c_str ());
136 /* See language.h. */
138 void value_print_inner
139 (struct value *val, struct ui_file *stream, int recurse,
140 const struct value_print_options *options) const override;
142 /* See language.h. */
144 void value_print (struct value *val, struct ui_file *stream,
145 const struct value_print_options *options) const override;
147 /* See language.h. */
149 struct block_symbol lookup_symbol_nonlocal
150 (const char *name, const struct block *block,
151 const domain_search_flags domain) const override;
153 /* See language.h. */
155 int parser (struct parser_state *ps) const override;
157 /* See language.h. */
159 void emitchar (int ch, struct type *chtype,
160 struct ui_file *stream, int quoter) const override;
162 /* See language.h. */
164 void printchar (int ch, struct type *chtype,
165 struct ui_file *stream) const override
167 gdb_puts ("'", stream);
168 emitchar (ch, chtype, stream, '\'');
169 gdb_puts ("'", stream);
172 /* See language.h. */
174 void printstr (struct ui_file *stream, struct type *elttype,
175 const gdb_byte *string, unsigned int length,
176 const char *encoding, int force_ellipses,
177 const struct value_print_options *options) const override;
179 /* See language.h. */
181 void print_typedef (struct type *type, struct symbol *new_symbol,
182 struct ui_file *stream) const override
184 type = check_typedef (type);
185 gdb_printf (stream, "type %s = ", new_symbol->print_name ());
186 type_print (type, "", stream, 0);
187 gdb_printf (stream, ";");
190 /* See language.h. */
192 bool is_string_type_p (struct type *type) const override;
194 /* See language.h. */
196 bool is_array_like (struct type *type) const override;
198 /* See language.h. */
200 struct value *to_array (struct value *val) const override
201 { return rust_slice_to_array (val); }
203 /* See language.h. */
205 bool range_checking_on_by_default () const override
206 { return true; }
208 private:
210 /* Helper for value_print_inner, arguments are as for that function.
211 Prints a slice. */
213 void val_print_slice (struct value *val, struct ui_file *stream,
214 int recurse,
215 const struct value_print_options *options) const;
217 /* Helper for value_print_inner, arguments are as for that function.
218 Prints structs and untagged unions. */
220 void val_print_struct (struct value *val, struct ui_file *stream,
221 int recurse,
222 const struct value_print_options *options) const;
224 /* Helper for value_print_inner, arguments are as for that function.
225 Prints discriminated unions (Rust enums). */
227 void print_enum (struct value *val, struct ui_file *stream, int recurse,
228 const struct value_print_options *options) const;
231 #endif /* RUST_LANG_H */