Repository: rust
Issue: `rustc` failed to pass `debuginfo` testsuite when using GDB 15
Labels: A-testsuite,A-debuginfo,T-compiler,C-bug,WG-debugging

Recently, I tried building `rustc` on my system with a pre-release GDB version (15.0-git, commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=1ab9eefe3cea741aba17e11ff28ed48ac3a8293a) and I encountered a lot of `debuginfo` test failures.

Some examples:

<details>
<summary>Click to see example failures</summary>
<p>

```
NOTE: compiletest thinks it is using GDB version 15000050
executing PYTHONPATH="/<<PKGBUILDDIR>>/./src/etc" "/usr/bin/gdb" "-quiet" "-batch" "-nx" "-command=/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/test/debuginfo/embedded-visualizer.gdb/embedded-visualizer.debugger.script"
------stdout------------------------------
GNU gdb (Ubuntu 15.0.50.20240312-0ubuntu1) 15.0.50.20240312-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x1fcd: file tests/debuginfo/embedded-visualizer.rs, line 107.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, embedded_visualizer::main () at tests/debuginfo/embedded-visualizer.rs:107
107	    zzz(); // #break
Loaded  Script                                                                 
Yes     gdb_load_rust_pretty_printers.py                                       
	full name: /<<PKGBUILDDIR>>/src/etc/gdb_load_rust_pretty_printers.py
Yes     pretty-printer-embedded_visualizer-0                                   
Yes     pretty-printer-embedded_visualizer-1                                   
Yes     pretty-printer-embedded_visualizer-2                                   
$1 = (0, 0)
$2 = (5, 8)
$3 = ((0, 0), (5, 8))
$4 = alloc::string::String {vec: alloc::vec::Vec<u8, alloc::alloc::Global> {buf: alloc::raw_vec::RawVec<u8, alloc::alloc::Global> {ptr: core::ptr::unique::Unique<u8> {pointer: core::ptr::non_null::NonNull<u8> {pointer: 0x55555555aba0}, _marker: core::marker::PhantomData<u8>}, cap: 8, alloc: alloc::alloc::Global}, len: 8}} is 10 years old.
A debugging session is active.

	Inferior 1 [process 176000] will be killed.

Quit anyway? (y or n) [answered Y; input not from terminal]

------stderr------------------------------
Python Exception <class 'NameError'>: name '__file__' is not defined

------------------------------------------

error: check directive(s) from `/<<PKGBUILDDIR>>/tests/debuginfo/embedded-visualizer.rs` not found in debugger output. errors:
    (embedded-visualizer.rs:60) `$4 = "Person A" is 10 years old.`
the following subset of check directive(s) was found successfully:
    (embedded-visualizer.rs:51) `Yes     pretty-printer-embedded_visualizer-0                                   `
    (embedded-visualizer.rs:52) `Yes     pretty-printer-embedded_visualizer-1                                   `
    (embedded-visualizer.rs:54) `$1 = (0, 0)`
    (embedded-visualizer.rs:56) `$2 = (5, 8)`
    (embedded-visualizer.rs:58) `$3 = ((0, 0), (5, 8))`
status: exit status: 0
command: PYTHONPATH="/<<PKGBUILDDIR>>/./src/etc" "/usr/bin/gdb" "-quiet" "-batch" "-nx" "-command=/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/test/debuginfo/embedded-visualizer.gdb/embedded-visualizer.debugger.script"
--- stdout -------------------------------
GNU gdb (Ubuntu 15.0.50.20240312-0ubuntu1) 15.0.50.20240312-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x1fcd: file tests/debuginfo/embedded-visualizer.rs, line 107.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, embedded_visualizer::main () at tests/debuginfo/embedded-visualizer.rs:107
107	    zzz(); // #break
Loaded  Script                                                                 
Yes     gdb_load_rust_pretty_printers.py                                       
	full name: /<<PKGBUILDDIR>>/src/etc/gdb_load_rust_pretty_printers.py
Yes     pretty-printer-embedded_visualizer-0                                   
Yes     pretty-printer-embedded_visualizer-1                                   
Yes     pretty-printer-embedded_visualizer-2                                   
$1 = (0, 0)
$2 = (5, 8)
$3 = ((0, 0), (5, 8))
$4 = alloc::string::String {vec: alloc::vec::Vec<u8, alloc::alloc::Global> {buf: alloc::raw_vec::RawVec<u8, alloc::alloc::Global> {ptr: core::ptr::unique::Unique<u8> {pointer: core::ptr::non_null::NonNull<u8> {pointer: 0x55555555aba0}, _marker: core::marker::PhantomData<u8>}, cap: 8, alloc: alloc::alloc::Global}, len: 8}} is 10 years old.
A debugging session is active.

	Inferior 1 [process 176000] will be killed.

Quit anyway? (y or n) [answered Y; input not from terminal]
------------------------------------------
--- stderr -------------------------------
Python Exception <class 'NameError'>: name '__file__' is not defined
------------------------------------------


---- [debuginfo-gdb] tests/debuginfo/include_string.rs stdout ----


NOTE: compiletest thinks it is using GDB with native rust support
executing RUSTC_ICE="0" "/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/<<PKGBUILDDIR>>/tests/debuginfo/include_string.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/<<PKGBUILDDIR>>/debian/cargo" "--sysroot" "/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "-C" "prefer-dynamic" "-o" "/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/test/debuginfo/include_string.gdb/a" "-A" "internal_features" "-Crpath" "-Lnative=/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=x86_64-linux-gnu-gcc" "-L" "/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/test/debuginfo/include_string.gdb/auxiliary" "-g"
------stdout------------------------------

------stderr------------------------------

------------------------------------------
NOTE: compiletest thinks it is using GDB version 15000050
executing PYTHONPATH="/<<PKGBUILDDIR>>/./src/etc" "/usr/bin/gdb" "-quiet" "-batch" "-nx" "-command=/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/test/debuginfo/include_string.gdb/include_string.debugger.script"
------stdout------------------------------
GNU gdb (Ubuntu 15.0.50.20240312-0ubuntu1) 15.0.50.20240312-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x12b3: file tests/debuginfo/include_string.rs, line 42.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, include_string::main () at tests/debuginfo/include_string.rs:42
42	    zzz(); // #break

------stderr------------------------------
/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/test/debuginfo/include_string.gdb/include_string.debugger.script:11: Error in sourced command file:
Attempt to extract a component of a value that is not a structure.

------------------------------------------

error: gdb failed to execute
status: exit status: 1
command: PYTHONPATH="/<<PKGBUILDDIR>>/./src/etc" "/usr/bin/gdb" "-quiet" "-batch" "-nx" "-command=/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/test/debuginfo/include_string.gdb/include_string.debugger.script"
--- stdout -------------------------------
GNU gdb (Ubuntu 15.0.50.20240312-0ubuntu1) 15.0.50.20240312-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x12b3: file tests/debuginfo/include_string.rs, line 42.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, include_string::main () at tests/debuginfo/include_string.rs:42
42	    zzz(); // #break
------------------------------------------
--- stderr -------------------------------
/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/test/debuginfo/include_string.gdb/include_string.debugger.script:11: Error in sourced command file:
Attempt to extract a component of a value that is not a structure.
------------------------------------------
```

</p>
</details>

I am unsure if this is a `rustc` problem, a GDB pretty printer problem or a GDB problem. This is likely due to a GDB behaviour change, and I tried bisecting the changes for GDB. Then I discovered this commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=b0dd661fa16a424f059b1e1d80e779508b1a9a12.

I don't know if this issue should be resolved from `rustc`, in-repository GDB pretty-printer or GDB itself. Can anyone give me some pointers?

### Meta

`rustc --version --verbose`:
```
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
```

### Backtrace

N/A