aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-parse.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2023-05-17 09:07:50 -0600
committerTom Tromey <tom@tromey.com>2023-05-17 11:47:16 -0600
commitcd61a1453e685a763bd91b3795a58edd3d9b4f40 (patch)
treeefb4285ba1cdd9ec2d28d024bdbda5243c558599 /gdb/rust-parse.c
parent80d4e113d7b9af8a5a36e5ea4399bca86050784f (diff)
downloadbinutils-cd61a1453e685a763bd91b3795a58edd3d9b4f40.zip
binutils-cd61a1453e685a763bd91b3795a58edd3d9b4f40.tar.gz
binutils-cd61a1453e685a763bd91b3795a58edd3d9b4f40.tar.bz2
Special case "&str" in Rust parser
"&str" is an important type in Rust -- it's the type of string literals. However, the compiler puts it in the DWARF in a funny way. The slice itself is present and named "&str". However, the Rust parser doesn't look for types with names like this, but instead tries to construct them from components. In this case it tries to make a pointer-to-"str" -- but "str" isn't always available, and in any case that wouldn't yield the best result. This patch adds a special case for &str. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22251 Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/rust-parse.c')
-rw-r--r--gdb/rust-parse.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 648e48d..4271696 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -1682,6 +1682,16 @@ rust_parser::parse_slice_type ()
{
assume ('&');
+ /* Handle &str specially. This is an important type in Rust. While
+ the compiler does emit the "&str" type in the DWARF, just "str"
+ itself isn't always available -- but it's handy if this works
+ seamlessly. */
+ if (current_token == IDENT && get_string () == "str")
+ {
+ lex ();
+ return rust_slice_type ("&str", get_type ("u8"), get_type ("usize"));
+ }
+
bool is_slice = current_token == '[';
if (is_slice)
lex ();