Bug 31517 - [15 Regression] Rust upstream GDB tests regressions with GDB 15
Summary: [15 Regression] Rust upstream GDB tests regressions with GDB 15
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: rust (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 15.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-20 22:33 UTC by liushuyu
Modified: 2024-04-02 17:45 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Error logs (1.84 KB, text/x-log)
2024-03-20 22:33 UTC, liushuyu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description liushuyu 2024-03-20 22:33:22 UTC
Created attachment 15423 [details]
Error logs

Hi there,

Recently, I tried building and running Rust 1.76 testsuites on my device, and I encountered a slew of errors when the test runner started to run GDB-related tests.

The errors were like this: (see the log file attached).

I remember those tests passing before, so I did some digging on GDB, and I found this commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=b0dd661fa16a424f059b1e1d80e779508b1a9a12 that caused this kind of error.

I am unsure if this new behaviour is intentional. If it is, how should someone print out the size of a Rust slice in this case?

I have also opened a bug report on the Rust upstream: https://github.com/rust-lang/rust/issues/122751, in case GDB cannot do anything to fix this situation (so that Rust upstream can fix their tests instead).

Thanks!
Comment 1 liushuyu 2024-03-20 22:37:26 UTC
If you don't want to run all the tests, you may just check this one: https://raw.githubusercontent.com/rust-lang/rust/e3df96cfda905301fc8514e000f942222c1ab6ad/tests/debuginfo/vec-slices.rs
Comment 2 Matthias Klose 2024-03-20 22:40:52 UTC
checked with trunk 20240312 and 20240320
Comment 3 Tom Tromey 2024-03-21 14:47:06 UTC
The gdb change was intentional.  See bug #30330.

There's also a follow-up patch that will land before gdb 15:
https://sourceware.org/pipermail/gdb-patches/2024-March/207190.html

This patch slightly changes the output in some cases.

In fact... let's use this bug to track that patch, to make sure
it really does land for 15.

> If it is, how should someone print out the size of a Rust slice in this case?

I built vec-slices.rs and ran it under a gdb with the patch
applied:

(gdb) info local
mut_slice = &mut [i64] [1, 2, 3, 4, 5]
padded_struct = &[vec_slices::AStruct] [
  vec_slices::AStruct {x: 10, y: 11, z: 12}, 
  vec_slices::AStruct {x: 13, y: 14, z: 15}]
padded_tuple = &[(i32, i16)] [(6, 7), (8, 9)]
slice_of_slice = &[i64] [3, 4]
multiple = &[i64] [2, 3, 4, 5]
singleton = &[i64] [1]
empty = &[i64] []
Comment 4 liushuyu 2024-03-21 21:42:26 UTC
> I built vec-slices.rs and ran it under a gdb with the patch
> applied:

Thanks for the information!
Although I am curious about how to print the length of a slice like using `print slice.length` before?

I have also built a GDB with the patch applied; the auto-completion in the interactive mode still completes `.length` in this case:

(gdb) p multiple.
data_ptr  length    

Is this expected?
Comment 5 Tom Tromey 2024-03-21 23:26:18 UTC
(In reply to liushuyu from comment #4)

> Although I am curious about how to print the length of a slice like using
> `print slice.length` before?

You can't, not directly anyway.
In Rust you use len() but the Rust compiler doesn't emit enough information
for gdb to do calls via traits.

> I have also built a GDB with the patch applied; the auto-completion in the
> interactive mode still completes `.length` in this case:
> 
> (gdb) p multiple.
> data_ptr  length    
> 
> Is this expected?

No, this should have a separate report.
The completer still sees the underlying C-like type.
Comment 6 Joel Brobecker 2024-03-23 03:59:56 UTC
Hello,

From what I could understand, Tom is saying that there is no issue in GDB, and so we should be able to close this PR?
Comment 7 Tom Tromey 2024-03-23 15:20:51 UTC
I want to land the patch mentioned in comment#3 first.
Comment 8 Sourceware Commits 2024-04-02 17:44:28 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=251cedaeb57fe1e0fd28798f476fbee75373bbf4

commit 251cedaeb57fe1e0fd28798f476fbee75373bbf4
Author: Tom Tromey <tromey@adacore.com>
Date:   Thu Mar 7 12:57:07 2024 -0700

    Print type name when printing Rust slice
    
    The recent change to how unsized Rust values are printed included a
    small regression from past behavior.  Previously, a slice's type would
    be printed, like:
    
        (gdb) print slice
        $80 = &[i32] [3]
    
    The patch changed this to just
    
        (gdb) print slice
        $80 = [3]
    
    This patch restores the previous behavior.
    
    Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30330
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31517
Comment 9 Tom Tromey 2024-04-02 17:45:31 UTC
I am going to close this now.