From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8773 invoked by alias); 10 Jan 2009 14:15:15 -0000 Received: (qmail 8762 invoked by uid 22791); 10 Jan 2009 14:15:14 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-bw0-f13.google.com (HELO mail-bw0-f13.google.com) (209.85.218.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 10 Jan 2009 14:14:42 +0000 Received: by bwz6 with SMTP id 6so26514525bwz.0 for ; Sat, 10 Jan 2009 06:14:39 -0800 (PST) Received: by 10.181.201.18 with SMTP id d18mr9206583bkq.72.1231596879246; Sat, 10 Jan 2009 06:14:39 -0800 (PST) Received: by 10.181.219.4 with HTTP; Sat, 10 Jan 2009 06:14:39 -0800 (PST) Message-ID: <90baa01f0901100614n31183205vbd43992f8b8f574e@mail.gmail.com> Date: Sat, 10 Jan 2009 14:15:00 -0000 From: "Kai Tietz" To: "Mark Kettenis" Subject: Re: [RFC] convert a host address to a string Cc: brobecker@adacore.com, Kai.Tietz@onevision.com, gdb-patches@sourceware.org In-Reply-To: <200901101403.n0AE3PYP005895@brahms.sibelius.xs4all.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20090109131227.GL24105@adacore.com> <20090110071137.GN24105@adacore.com> <90baa01f0901100530t6590599bucfaa12aea8898c57@mail.gmail.com> <200901101403.n0AE3PYP005895@brahms.sibelius.xs4all.nl> X-IsSubscribed: yes 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/msg00229.txt.bz2 2009/1/10 Mark Kettenis : >> Date: Sat, 10 Jan 2009 14:30:29 +0100 >> From: "Kai Tietz" >> >> 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)); > } > hmm, well, but a "0x" has to be as prefix here, isn't it? Kai -- | (\_/) This is Bunny. Copy and paste | (='.'=) Bunny into your signature to help | (")_(") him gain world domination