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]

Re: [RFC] convert a host address to a string


> Date: Sat, 10 Jan 2009 14:30:29 +0100
> From: "Kai Tietz" <ktietz70@googlemail.com>
> 
> ok, so I sugget the following patch instead. It is able to generate
> addresses for XP64 without the use of any vendor specific printf
> formatters, and uses for targets where sizeof(long) == sizeof(void*)
> the long variant.

+#if defined(PRINTF_HAS_LONG_LONG) && BITSIZEOF_SIZE_T == 64 && \
+  SIZEOF_LONG == 4
+  sprintf (str, "0x%llx", (unsigned long long) (uintptr_t) addr);
+#elif BITSIZEOF_SIZE_T == 64 && SIZEOF_LONG == 4
+  unsigned long long val = (unsigned long) (uintptr_t) addr;
+  if ((val & ~0xffffffffull) != 0)
+    sprintf (str, "0x%lx%08lx",
+             (unsigned long) (val >> 32), (unsigned long) val);
+  else
+    sprintf (str, "0x%lx", (unsigned long) (uintptr_t) val);
+#else
+  sprintf (str, "0x%lx", (unsigned long) (uintptr_t) addr);
+#endif
   return str;
+  BITSIZEOF_SIZE_T SIZEOF_LONG

This is madness.  If you go this route please do a simple

const char *
host_address_to_string (const void *addr)
{
  return phex_nz ((uintptr_t)addr, sizeof(addr));
}


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