public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC] [PATCH] Return intptr when dereferencing integer
@ 2023-07-26 21:52 Denis Revunov
  2023-07-27 16:15 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Revunov @ 2023-07-26 21:52 UTC (permalink / raw)
  To: gdb-patches; +Cc: Denis Revunov

The code which makes default dereference type an int was intruduced in
gdb-3.4(1c997a4ae869) in 1989, 10 years before AMD64 was released. With
current adoption of 64-bit it makes sense to change default dereference
size to match the native address size, which will enable us to easily
inspect .got entries and follow chains of pointers on 64-bit systems
without excessive casting. This change won't affect 32-and-less bit
systems since intptr is the same as int there.
---
 gdb/eval.c     | 7 +++----
 gdb/gdbtypes.c | 3 +++
 gdb/gdbtypes.h | 1 +
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/eval.c b/gdb/eval.c
index 457a6697923..23568d8ed3c 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1672,11 +1672,10 @@ eval_op_ind (struct type *expect_type, struct expression *exp,
     }
 
   /* Allow * on an integer so we can cast it to whatever we want.
-     This returns an int, which seems like the most C-like thing to
-     do.  "long long" variables are rare enough that
-     BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
+     This returns an intptr, which has the same size as a native
+     address and thus can be treated as a pointer on any machine. */
   if (type->code () == TYPE_CODE_INT)
-    return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
+    return value_at_lazy (builtin_type (exp->gdbarch)->builtin_intptr,
 			  (CORE_ADDR) value_as_address (arg1));
   return value_ind (arg1);
 }
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index c5272979cb9..9deacd94ce2 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -6026,6 +6026,9 @@ create_gdbtypes_data (struct gdbarch *gdbarch)
     = init_integer_type (alloc, 128, 0, "int128_t");
   builtin_type->builtin_uint128
     = init_integer_type (alloc, 128, 1, "uint128_t");
+  builtin_type->builtin_intptr
+    = init_integer_type (alloc, gdbarch_addr_bit (gdbarch), 0,
+			 "intptr_t");
 
   builtin_type->builtin_int8->set_instance_flags
     (builtin_type->builtin_int8->instance_flags ()
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index aedaf53cd5d..222f92815a9 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2079,6 +2079,7 @@ struct builtin_type
   struct type *builtin_uint64 = nullptr;
   struct type *builtin_int128 = nullptr;
   struct type *builtin_uint128 = nullptr;
+  struct type *builtin_intptr = nullptr;
 
   /* Wide character types.  */
   struct type *builtin_char16 = nullptr;
-- 
2.41.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-13 16:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 21:52 [RFC] [PATCH] Return intptr when dereferencing integer Denis Revunov
2023-07-27 16:15 ` Tom Tromey
2023-07-29  0:14   ` Denis Revunov
2023-08-13 16:35     ` Revunov Denis

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).