From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15774 invoked by alias); 7 Jan 2009 12:19:22 -0000 Received: (qmail 15765 invoked by uid 22791); 7 Jan 2009 12:19:22 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 07 Jan 2009 12:19:18 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 949D52A9660 for ; Wed, 7 Jan 2009 07:19:16 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id I3oWJkJoy1bi for ; Wed, 7 Jan 2009 07:19:16 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id A2BD42A964A for ; Wed, 7 Jan 2009 07:19:15 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 7E659E7ACD; Wed, 7 Jan 2009 16:19:08 +0400 (RET) Date: Wed, 07 Jan 2009 12:19:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFC] convert a host address to a string Message-ID: <20090107121908.GH1751@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="4C6bbPZ6c/S1npyF" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-01/txt/msg00088.txt.bz2 --4C6bbPZ6c/S1npyF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1142 The host_address_to_string function converts the host address to a string using sprintf after having converted the address to an unsigned long. Unfortunately for us, on x86_64-windows, unsigned long is not big enough to hold an address. My initial approach was to detect this case by using a configure check which defines HOST_IS_LLP64 if sizeof (void*) is 8 while sizeof (long) is 4. Mark's reaction was that we should be able to use something more elegant. One of the things we could do, perhaps, is use %p, which is mentioned by the comment inside the function. I checked the C90 draft, and %p is definitely mentioned, so I suspect it's fine to use it assuming we require C90. The problem is, are we going to break the build on some targets if we do? 2009-01-07 Joel Brobecker * configure.ac: Define HOST_IS_LLP64 if the host uses the LLP64 ABI. * configure, config.in: Regenerate. * utils.c (host_address_to_string): Use "long long" to print addresses rather than "long" if HOST_IS_LLP64 is defined. Tested on x86-linux, x86-windows and x86_64-windows. Thoughts? -- Joel --4C6bbPZ6c/S1npyF Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="print_addr2.diff" Content-length: 1831 diff --git a/gdb/configure.ac b/gdb/configure.ac index e970234..8774309 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -1189,6 +1189,20 @@ if test $gdb_cv_printf_has_long_long = yes; then [Define to 1 if the "%ll" format works to print long longs.]) fi +# Check if the host is LLP64 (pointers are 64bits and "long" is only 32bits). + +AC_CACHE_CHECK([host is LLP64], + gdb_cv_host_is_llp64, + [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], +[[return !(sizeof (void *) == 8 && sizeof (long) == 4);]])], + gdb_cv_host_is_llp64=yes, + gdb_cv_host_is_llp64=no, + gdb_cv_host_is_llp64=no)]) +if test $gdb_cv_host_is_llp64 = yes; then + AC_DEFINE(HOST_IS_LLP64, 1, + [Define to 1 if host is LLP64 (pointers is 64bits and "long" is32bits)]) +fi + # Check if the compiler and runtime support printing decfloats. AC_CACHE_CHECK([for decfloat support in printf], diff --git a/gdb/utils.c b/gdb/utils.c index 2549a3c..d289509 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3066,9 +3066,15 @@ host_address_to_string (const void *addr) char *str = get_cell (); /* We could use the %p conversion specifier to sprintf if we had any - way of knowing whether this host supports it. But the following - should work on the Alpha and on 32 bit machines. */ + way of knowing whether this host supports it. */ +#ifdef HOST_IS_LLP64 + /* On LLP64 hosts, longs are only 32bits whereas pointers are 64bit. + Use a "long long" to print our address. */ + sprintf (str, "0x%llx", (unsigned long long) addr); +#else + /* The following should work on the Alpha and on 32 bit machines. */ sprintf (str, "0x%lx", (unsigned long) addr); +#endif return str; } --4C6bbPZ6c/S1npyF--