This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] [gdbserver] paddress() can truncate its argument


Hi:

Noticed this while messing around with win64 support: paddress() casts
its CORE_ADDR argument (which is specifically defined as long long in
gdbserver) to long, probably assuming LP64 convention. For win64, which
is LLP64, it is not true (sizeof(long) == 4 always) and it truncates
its argument.

Shouldn't paddress() just return phex_nz() instead, like the following:

Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/utils.c,v
retrieving revision 1.23
diff -u -p -r1.23 utils.c
--- utils.c	1 Jun 2010 13:20:52 -0000	1.23
+++ utils.c	16 Jul 2010 20:41:14 -0000
@@ -257,17 +257,6 @@ xsnprintf (char *str, size_t size, const
   return ret;
 }

-/* Convert a CORE_ADDR into a HEX string, like %lx.
-   The result is stored in a circular static buffer, NUMCELLS deep.  */
-
-char *
-paddress (CORE_ADDR addr)
-{
-  char *str = get_cell ();
-  xsnprintf (str, CELLSIZE, "%lx", (long) addr);
-  return str;
-}
-
 static char *
 decimal2str (char *sign, ULONGEST addr, int width)
 {
@@ -372,3 +361,12 @@ phex_nz (ULONGEST l, int sizeof_l)

   return str;
 }
+
+/* Convert a CORE_ADDR into a HEX string, like %lx.
+   The result is stored in a circular static buffer, NUMCELLS deep.  */
+
+char *
+paddress (CORE_ADDR addr)
+{
+  return phex_nz (addr, sizeof (CORE_ADDR));
+}

Comments?

--
Ozkan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]