public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "tpzker at thepuzzlemaker dot info" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug rust/29735] Can't have multiple breakpoints - crash otherwise
Date: Sat, 28 Oct 2023 18:34:28 +0000	[thread overview]
Message-ID: <bug-29735-4717-YhBDeYw6Vf@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-29735-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=29735

The Puzzlemaker <tpzker at thepuzzlemaker dot info> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tpzker at thepuzzlemaker dot info

--- Comment #7 from The Puzzlemaker <tpzker at thepuzzlemaker dot info> ---
Created attachment 15198
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15198&action=edit
Patch for this issue, or an issue similar to it

I experienced this in 13.2. I believe it's related to the null pointer
optimization, or at least the case I encountered was.

```
use std::num::NonZeroUsize;
use std::hint::black_box;

pub fn main() {
    foo(black_box(NonZeroUsize::new(5)), black_box(NonZeroUsize::new(5)))
}

#[inline(never)]
pub fn foo(x: Option<NonZeroUsize>, y: Option<NonZeroUsize>) {
    black_box(x.unwrap().checked_add(y.unwrap().into()));
}
```

Put this in `tmp.rs`.
Compile with `rustc tmp.rs -Copt-level=1 -Cdebuginfo=full`
Run `gdb tmp::foo`
`break foo`
`run`
`info args`

Observe assertion fail:
```
x = core::option::Option<core::num::nonzero::NonZeroUsize>::Some(
../../gdb/gdbtypes.h:985: internal-error: field: Assertion `idx >= 0 && idx <
num_fields ()' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
```

This issue is related to this portion of code in `rust_lang::print_enum`:
```
 461   type = resolve_dynamic_type (type, view, value_address (val));
 ...   [snip]
 472   int variant_fieldno = rust_enum_variant (type);
 473   val = value_field (val, variant_fieldno);
 474   struct type *variant_type = type->field (variant_fieldno).type ();
```
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/rust-lang.c;h=74808ad0716e4d67f6af859f05ebff2b55d5e276;hb=662243de0e14a4945555a480dca33c0e677976eb#l461
The type from `resolve_dynamic_type` makes only the variant field of the active
discriminant in active. However, the type of `val` has *all* variant fields
enabled, thus making this index meaningless for that. I created a patch for
this, which is somewhat hacky--any maintainers here, feel free to change it up
a bit; I am a Rust developer by nature and don't know much about idiomatic C/++
and in general, what the GDB codebase looks like.

Please let me know if you'd like me to test/update this patch to the v14
codebase.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-10-28 18:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31 13:25 [Bug gdb/29735] New: " amab8901 at protonmail dot com
2022-10-31 20:21 ` [Bug rust/29735] " tromey at sourceware dot org
2022-11-01  3:37 ` amab8901 at protonmail dot com
2022-11-01 13:38 ` tromey at sourceware dot org
2022-11-01 14:27 ` amab8901 at protonmail dot com
2022-11-02 19:47 ` tromey at sourceware dot org
2023-03-08  0:28 ` tromey at sourceware dot org
2023-10-28 18:34 ` tpzker at thepuzzlemaker dot info [this message]
2023-10-28 18:51 ` tpzker at thepuzzlemaker dot info
2023-10-28 18:55 ` tpzker at thepuzzlemaker dot info
2023-10-28 20:46 ` tromey at sourceware dot org
2023-10-28 20:48 ` tromey at sourceware dot org
2023-10-28 20:56 ` tpzker at thepuzzlemaker dot info
2023-10-28 20:57 ` tpzker at thepuzzlemaker dot info
2023-10-28 21:08 ` tpzker at thepuzzlemaker dot info
2023-10-29 10:06 ` sam at gentoo dot org
2023-11-24 16:30 ` tromey at sourceware dot org

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-29735-4717-YhBDeYw6Vf@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: link
Be 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).