Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: eliz@gnu.org
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFC] Use %p conversion specifier to fix hppa compiler warning
Date: Sun, 19 Jun 2005 21:31:00 -0000	[thread overview]
Message-ID: <200506192130.j5JLUxDB026134@elgar.sibelius.xs4all.nl> (raw)
In-Reply-To: <u1x767pl4.fsf@gnu.org> (message from Eli Zaretskii on Mon, 13 Jun 2005 09:12:07 +0300)

   Date: Mon, 13 Jun 2005 09:12:07 +0300
   From: Eli Zaretskii <eliz@gnu.org>

   > Date: Sun, 12 Jun 2005 23:02:15 +0200 (CEST)
   > From: Mark Kettenis <mark.kettenis@xs4all.nl>
   > 
   > Currently the compiler warns about hppa_pointer_to_address_hack().
   > Rather than adding ugly casts and making this an even worse hack, I
   > propose to remove it completely in favour of using the %p format
   > specifier.
   > 
   > In the past we didn't use the %p conversion specifier since it wasn't
   > portable; ancient UNIX didn't support it.  However, I'm confident that
   > we do not support those systems any more.  I've done some archeology,
   > and it seems %p is supported by Ultrix 4.0, HP-UX 10.01 and SunOS
   > 4.1.3.

   %p is ANSI/ISO C89, IIRC, so we can use it freely.  The one problem
   with it is that its results are inconsistent: some libraries produce
   "0x" before the address, others don't.  This is a minor inconsistency,
   but with some numerical values, if you don't have the telltale "0x",
   you may wonder whether the number is in hex or decimal.

Hmm, you're right.  Linux and *BSD do print the 0x, Solaris and HP-UX
don't.  Not sure if that's an issue, but I committed the attached
patch (which avoid %p) instead.  We use the %lx with cast to unsigned
long trick in several places.  Should be fine on ILP32 and LP64, and
the compiler will hopefully warn about it if we ever encounter a
systems that isn't one of those.

Mark

Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* hppa-tdep.c (hppa_pointer_to_address_hack): Remove function.
	(unwind_command): Use %lx to print pointer.

Index: hppa-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
retrieving revision 1.209
diff -u -p -r1.209 hppa-tdep.c
--- hppa-tdep.c 18 Jun 2005 22:03:41 -0000 1.209
+++ hppa-tdep.c 19 Jun 2005 21:22:06 -0000
@@ -2395,16 +2395,6 @@ hppa_lookup_stub_minimal_symbol (const c
   return NULL;
 }
 
-/* Instead of this nasty cast, add a method pvoid() that prints out a
-   host VOID data type (remember %p isn't portable).  */
-
-static CORE_ADDR
-hppa_pointer_to_address_hack (void *ptr)
-{
-  gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
-  return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
-}
-
 static void
 unwind_command (char *exp, int from_tty)
 {
@@ -2426,8 +2416,7 @@ unwind_command (char *exp, int from_tty)
       return;
     }
 
-  printf_unfiltered ("unwind_table_entry (0x%s):\n",
-		     paddr_nz (hppa_pointer_to_address_hack (u)));
+  printf_unfiltered ("unwind_table_entry (0x%lx):\n", (unsigned long)u);
 
   printf_unfiltered ("\tregion_start = ");
   print_address (u->region_start, gdb_stdout);


      reply	other threads:[~2005-06-19 21:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-12 21:02 Mark Kettenis
2005-06-13  6:12 ` Eli Zaretskii
2005-06-19 21:31   ` Mark Kettenis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200506192130.j5JLUxDB026134@elgar.sibelius.xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox