From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4378 invoked by alias); 9 Jan 2009 14:28:26 -0000 Received: (qmail 4367 invoked by uid 22791); 9 Jan 2009 14:28:24 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from outdoor.onevision.de (HELO outdoor.onevision.de) (212.77.172.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 09 Jan 2009 14:27:44 +0000 Received: from sanders.onevision.de (moonrace [212.77.172.62]) by outdoor.onevision.de (8.14.3/8.13.7/ROSCH/DDB) with ESMTP id n09EREOO024506; Fri, 9 Jan 2009 15:27:19 +0100 In-Reply-To: <20090109131227.GL24105@adacore.com> To: Joel Brobecker Cc: gdb-patches@sourceware.org, Mark Kettenis Subject: Re: [RFC] convert a host address to a string MIME-Version: 1.0 Message-ID: From: Kai Tietz Date: Fri, 09 Jan 2009 14:28:00 -0000 Content-Type: text/plain; charset="US-ASCII" 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/msg00196.txt.bz2 Hi Joel, gdb-patches-owner@sourceware.org wrote on 09.01.2009 14:12:27: > > > 3. Work through uintptr_t. > > > > > > #ifdef PRINTF_HAS_LONG_LONG > > > fprintf (buf, "0x%llx", (unsigned long long) > (uintptr_t) address); > > > #else > > > fprintf (buf, "0x%lx", (unsigned long) (uintptr_t) address); > > > #endif > > > > This wouldn't be the first place where we'd use a double cast in > > connection with intptr_t/uintptr_t. So I'd say that while this is a > > bit ugly, it's certainly acceptable. It's by far the simplest way to > > fix things. > > Here is a new patch implementing this approach. As I told Kai, > it's probably not going to work for x86_64/XP, but it works for > x86_64/Vista (I think Kai agreed to take on the job of improving > this approach to work on XP as well :-). > > 2009-01-09 Joel Brobecker > > * utils.c (host_address_to_string): Cast the address to uintptr_t > first to avoid a possible compilation warning about casting to > an integer of the wrong size. Then format the address using > unsigned long long if supported by printf. Otherwise, fallback > on using usingned long, hoping that long is large enough to hold > an address. > > Tested on x86-linux. I also verified that it still builds on > x86_64 Vista, as well as x86/Windows XP (on XP, PRINTF_HAS_LONG_LONG > is undefined). I think it is a sub-optimal solution to have just support for Vista64, but not for XP. On a second thought, I remembered, that bfd does things right ;) There is the macro sprintf_vma in bfd.h, which handles things pretty well and can be used here in utils.c, too. Cheers, Kai | (\_/) This is Bunny. Copy and paste Bunny | (='.'=) into your signature to help him gain | (")_(") world domination.