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/31082] New: rust-parse infers `0xffffffd00000009a` and other addresses as i128, preventing `as *mut _` coercions in `print`
Date: Thu, 23 Nov 2023 17:26:05 +0000	[thread overview]
Message-ID: <bug-31082-4717@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 31082
           Summary: rust-parse infers `0xffffffd00000009a` and other
                    addresses as i128, preventing `as *mut _` coercions in
                    `print`
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: rust
          Assignee: unassigned at sourceware dot org
          Reporter: tpzker at thepuzzlemaker dot info
  Target Milestone: ---

Created attachment 15226
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15226&action=edit
[PATCH] rust-parse: Infer some integer constants as u64

I've been working on an operating system in Rust for learning purposes, and
have found myself having to deal with addresses greater than `2^63-1` due to
canonicalization and higher-half kernels. Due to a bug (#29735) in GDB 13.2,
fixed in GDB 14 HEAD, however, I have been using the GDB 14 branch to perform
debugging.

However, when trying to print expressions as such:
```
p (0xffffffd00000009a as *mut u64)
```
The system returns an error: `That operation is not available on integers of
more than 8 bytes.`

To reproduce this, compile a simple Rust program like such (in `tmp.rs`, for
example):
```rs
fn main() { println!("hello world!") }
```
Then `b tmp::main` and run the print command above.

After some debugging, I've discovered that this stems from the following patch:
https://sourceware.org/pipermail/gdb-patches/2023-March/198410.html

This patch added support for `i128`, however in this process, made all `u64`s
`(2 ** 63) - 1 <= x <= (2 ** 64) - 1` inferred to be i128s, when they really
should be `u64`s. This causes the `as *mut u64` operation to fail.

This only occurs for addresses in the higher half, and not any other
addresses--perhaps why it was not discovered earlier.

I have attached a patch that is a bit hacky, but does solve this issue. It will
regress some inference of large values as i128, however, and that will require
explicit suffixing as `[number]i128`. I'm not sure how to better solve that,
though.

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

             reply	other threads:[~2023-11-23 17:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 17:26 tpzker at thepuzzlemaker dot info [this message]
2023-11-23 17:37 ` [Bug rust/31082] " tpzker at thepuzzlemaker dot info
2023-11-24 16:37 ` tromey at sourceware dot org
2023-11-24 16:56 ` tromey at sourceware dot org
2023-11-25  2:26 ` tromey at sourceware dot org
2023-12-08 15:39 ` cvs-commit at gcc dot gnu.org
2023-12-08 15:39 ` 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-31082-4717@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).