From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22584 invoked by alias); 10 Jan 2009 14:25:48 -0000 Received: (qmail 22575 invoked by uid 22791); 10 Jan 2009 14:25:47 -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:25:16 +0000 Received: by bwz6 with SMTP id 6so26521303bwz.0 for ; Sat, 10 Jan 2009 06:25:13 -0800 (PST) Received: by 10.181.21.2 with SMTP id y2mr10171374bki.144.1231597513442; Sat, 10 Jan 2009 06:25:13 -0800 (PST) Received: by 10.181.219.4 with HTTP; Sat, 10 Jan 2009 06:25:13 -0800 (PST) Message-ID: <90baa01f0901100625v5668e6b6j63bfb087262248bb@mail.gmail.com> Date: Sat, 10 Jan 2009 14:25: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: <200901101421.n0AELbwx014532@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> <90baa01f0901100614n31183205vbd43992f8b8f574e@mail.gmail.com> <200901101421.n0AELbwx014532@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/msg00231.txt.bz2 2009/1/10 Mark Kettenis : >> Date: Sat, 10 Jan 2009 15:14:39 +0100 >> From: "Kai Tietz" >> >> 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? > > You're right. So something like: > > { > char *result = get_cell (); > xsnprintf (result, CELLSIZE, "0x%s", phex_nz((uintptr_t)addr, sizeof(addr))); > return result; > } > > perhaps? > Looks fine to me. Thanks, Kai -- | (\_/) This is Bunny. Copy and paste | (='.'=) Bunny into your signature to help | (")_(") him gain world domination