public inbox for gdb-prs@sourceware.org help / color / mirror / Atom feed
From: "tromey at sourceware dot org" <sourceware-bugzilla@sourceware.org> To: gdb-prs@sourceware.org Subject: [Bug rust/31431] New: Sub-par output for partially optimized-out slice Date: Wed, 28 Feb 2024 18:02:33 +0000 [thread overview] Message-ID: <bug-31431-4717@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=31431 Bug ID: 31431 Summary: Sub-par output for partially optimized-out slice Product: gdb Version: HEAD Status: NEW Severity: normal Priority: P2 Component: rust Assignee: unassigned at sourceware dot org Reporter: tromey at sourceware dot org Target Milestone: --- This comes from https://github.com/rust-lang/rust/issues/46698 The test case is: use std::env; #[inline(never)] fn foo(x: &str, y: &str) -> usize { x.len() + y.len() } fn main() { let mut args = env::args(); let x = args.next().unwrap(); let y = args.next().unwrap(); let z = foo(&x, &y); println!("z={:?}", z); } Compile it with "rustc -O -g q.rs". In gdb, do: (gdb) break 3 (gdb) run a b ... stop (gdb) info args I get: (gdb) info args x = <error reading variable: value has been optimized out> y = <error reading variable: value has been optimized out> This isn't really great. The "error" text here is somewhat misleading -- no error has actually occurred. What's happening here is that the slice is partially optimized out by the compiler. This is more obvious in C mode: (gdb) set lang c Warning: the current language does not match this frame. (gdb) p x $4 = {data_ptr = <optimized out>, length = 6} What's happening is that rust-lang.c is unconditionally trying to read the data from the slice: #2 0x0000000000d1c0e3 in value::require_not_optimized_out (this=0x2b442b0) at ../../binutils-gdb/gdb/value.c:1130 #3 0x0000000000d1cad5 in value::contents (this=0x2b442b0) at ../../binutils-gdb/gdb/value.c:1310 #4 0x0000000000d1fcc7 in value_as_address (val=0x2b442b0) at ../../binutils-gdb/gdb/value.c:2779 #5 0x0000000000b2f42e in convert_slice (val=0x2b9e840) at ../../binutils-gdb/gdb/rust-lang.c:365 #6 0x0000000000b2f68a in rust_language::val_print_slice (this=0x2653180 <rust_language_defn>, val=0x2b9e840, stream=0x26c8850, recurse=0, options=0x7fffffffd620) at ../../binutils-gdb/gdb/rust-lang.c:461 #7 0x0000000000b2f801 in rust_language::val_print_struct (this=0x2653180 <rust_language_defn>, val=0x2b9e840, stream=0x26c8850, recurse=0, options=0x7fffffffd620) at ../../binutils-gdb/gdb/rust-lang.c:495 It's not totally clear what is ideal here. I'm thinking just: (gdb) print x $999 = <optimized out> -- You are receiving this mail because: You are on the CC list for the bug.
reply other threads:[~2024-02-28 18:02 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-31431-4717@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=gdb-prs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).