From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A0B013858C52; Wed, 28 Feb 2024 18:02:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0B013858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1709143353; bh=oQNMQahzP+82jRxNg9ay7bvxDylb5ksk5drrz0UaNio=; h=From:To:Subject:Date:From; b=XVaG2obw3MhDcVRgm29zikUNnDOJ2A5B9JgUrKdhRkczdx6TpxmxO48JKOnkJ6mON D9vH5iU8kCJyVJrLOLC9QhHo0VzPoAtoFPYN8UtQXn4lJ5xQx117RqGRlsPWnMuvJ/ bEXrPeS0BxCe4qRjjF+V9uT/e5zAM6IyKhEDnROM= From: "tromey at sourceware dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: rust X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: tromey at sourceware dot org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31431 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 =3D env::args(); let x =3D args.next().unwrap(); let y =3D args.next().unwrap(); let z =3D foo(&x, &y); println!("z=3D{:?}", 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 =3D y =3D 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 =3D {data_ptr =3D , length =3D 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=3D0x2b442b= 0) at ../../binutils-gdb/gdb/value.c:1130 #3 0x0000000000d1cad5 in value::contents (this=3D0x2b442b0) at ../../binutils-gdb/gdb/value.c:1310 #4 0x0000000000d1fcc7 in value_as_address (val=3D0x2b442b0) at ../../binutils-gdb/gdb/value.c:2779 #5 0x0000000000b2f42e in convert_slice (val=3D0x2b9e840) at ../../binutils-gdb/gdb/rust-lang.c:365 #6 0x0000000000b2f68a in rust_language::val_print_slice (this=3D0x2653180 , val=3D0x2b9e840, stream=3D0x26c8850,=20 recurse=3D0, options=3D0x7fffffffd620) at ../../binutils-gdb/gdb/rust-lang.c:461 #7 0x0000000000b2f801 in rust_language::val_print_struct (this=3D0x2653180 , val=3D0x2b9e840, stream=3D0x26c8850,=20 recurse=3D0, options=3D0x7fffffffd620) 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 =3D --=20 You are receiving this mail because: You are on the CC list for the bug.=