public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug rust/31431] New: Sub-par output for partially optimized-out slice
@ 2024-02-28 18:02 tromey at sourceware dot org
  0 siblings, 0 replies; only message in thread
From: tromey at sourceware dot org @ 2024-02-28 18:02 UTC (permalink / raw)
  To: gdb-prs

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-28 18:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28 18:02 [Bug rust/31431] New: Sub-par output for partially optimized-out slice tromey at sourceware dot org

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).