Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "The Puzzlemaker" <tpzker@thepuzzlemaker.info>
To: gdb-patches@sourceware.org
Subject: [FIXED] [PATCH 1/1] rust-parse: Infer some integer constants as u64
Date: Thu, 23 Nov 2023 11:36:23 -0600	[thread overview]
Message-ID: <47-655f8d80-3-52811600@102229502> (raw)

This is a bit hacky, I admit. This commit causes integers in the range
`2^63-1 <= x <= 2^64 - 1` to be inferred as `u64` instead of as `i128`.
This helps solve an issue where these integers would not be able to be
used as addresses, helpful when e.g. debugging higher-half kernels.
---
 gdb/rust-parse.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 4b3348d8ca6..a807884bd20 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -1033,9 +1033,13 @@ rust_parser::lex_number ()
       if (implicit_i32)
 	{
 	 static gdb_mpz sixty_three_bit = gdb_mpz::pow (2, 63);
+	 static gdb_mpz sixty_four_bit = gdb_mpz::pow (2, 64);
 	 static gdb_mpz thirty_one_bit = gdb_mpz::pow (2, 31);
-
-	 if (current_int_val.val >= sixty_three_bit)
+	 static gdb_mpz thirty_two_bit = gdb_mpz::pow (2, 32);
+  
+	 if (current_int_val.val < sixty_four_bit && current_int_val.val >= thirty_two_bit)
+	   type = get_type ("u64");
+	 else if (current_int_val.val >= sixty_three_bit)
 	   type = get_type ("i128");
 	 else if (current_int_val.val >= thirty_one_bit)
 	   type = get_type ("i64");
-- 
2.43.0

Sorry about the last email, my email client was not set up right for plaintext.
See #31082, https://sourceware.org/bugzilla/show_bug.cgi?id=31082

Let me know if there's anything I missed here.

Thanks,
James aka ThePuzzlemaker


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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 17:36 The Puzzlemaker [this message]
2023-11-25  3:41 ` Tom Tromey

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=47-655f8d80-3-52811600@102229502 \
    --to=tpzker@thepuzzlemaker.info \
    --cc=gdb-patches@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