This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: gprof [PATCH RFA] try harder when determining targetpointer size.
- From: cgd at broadcom dot com
- To: amodra at bigpond dot net dot au
- Cc: binutils at sources dot redhat dot com,thorpej at wasabisystems dot com,aoliva at redhat dot com
- Date: 31 Mar 2003 11:01:16 -0800
- Subject: Re: gprof [PATCH RFA] try harder when determining targetpointer size.
- References: <yov5wuij46tj.fsf@broadcom.com><20030329065514.GW931@bubble.sa.bigpond.net.au><mailpost.1048920932.680@news-sj1-1>
At Sat, 29 Mar 2003 06:55:33 +0000 (UTC), "Alan Modra" wrote:
> On Fri, Mar 28, 2003 at 11:41:44AM -0800, cgd at broadcom dot com wrote:
> > + size = bfd_get_arch_size(core_bfd);
>
> Formatting.
FYI, you appear to have missed two formatting errors in my patch. 8-)
(existing code, which i believe to follow the style guide, had "PARAMS
((stuff...))" and i did it w/o the space. I've fixed those too.)
It's hard to convert one's brain from BSD KNF. 8-)
> > + return (sext ? ptr_signed : ptr_unsigned);
>
> ex-Pascal programmer? :)
Long long ago. (so long that I've forgotten everything about it, and
don't even get the joke. 8-) Could have scarred my brain, though...
Patch as applied is below. Thanks.
chris
--
2003-03-31 Chris Demetriou <cgd at broadcom dot com>
* gmon_io.c (enum gmon_ptr_size, enum gmon_ptr_signedness): New.
(gmon_get_ptr_size, gmon_get_ptr_signedness): New.
(gmon_io_read_vma, gmon_io_write_vma, gmon_read_raw_arc)
(gmon_write_raw_arc, gmon_out_read, gmon_out_write): Adjust to
use new functions and enums.
Index: gmon_io.c
===================================================================
RCS file: /cvs/src/src/gprof/gmon_io.c,v
retrieving revision 1.16
diff -u -p -r1.16 gmon_io.c
--- gmon_io.c 30 Nov 2002 08:39:44 -0000 1.16
+++ gmon_io.c 31 Mar 2003 18:55:32 -0000
@@ -34,6 +34,19 @@
#include "hist.h"
#include "libiberty.h"
+enum gmon_ptr_size {
+ ptr_32bit,
+ ptr_64bit
+};
+
+enum gmon_ptr_signedness {
+ ptr_signed,
+ ptr_unsigned
+};
+
+static enum gmon_ptr_size gmon_get_ptr_size PARAMS ((void));
+static enum gmon_ptr_signedness gmon_get_ptr_signedness PARAMS ((void));
+
#ifdef BFD_HOST_U_64_BIT
static int gmon_io_read_64 PARAMS ((FILE *, BFD_HOST_U_64_BIT *));
static int gmon_io_write_64 PARAMS ((FILE *, BFD_HOST_U_64_BIT));
@@ -46,6 +59,44 @@ static int gmon_write_raw_arc
int gmon_input = 0;
int gmon_file_version = 0; /* 0 == old (non-versioned) file format. */
+static enum gmon_ptr_size
+gmon_get_ptr_size ()
+{
+ int size;
+
+ /* Pick best size for pointers. Start with the ELF size, and if not
+ elf go with the architecture's address size. */
+ size = bfd_get_arch_size (core_bfd);
+ if (size == -1)
+ size = bfd_arch_bits_per_address (core_bfd);
+
+ switch (size)
+ {
+ case 32:
+ return ptr_32bit;
+
+ case 64:
+ return ptr_64bit;
+
+ default:
+ fprintf (stderr, _("%s: address size has unexpected value of %u\n"),
+ whoami, size);
+ done (1);
+ }
+}
+
+static enum gmon_ptr_signedness
+gmon_get_ptr_signedness ()
+{
+ int sext;
+
+ /* Figure out whether to sign extend. If BFD doesn't know, assume no. */
+ sext = bfd_get_sign_extend_vma (core_bfd);
+ if (sext == -1)
+ return ptr_unsigned;
+ return (sext ? ptr_signed : ptr_unsigned);
+}
+
int
gmon_io_read_32 (ifp, valp)
FILE *ifp;
@@ -84,26 +135,29 @@ gmon_io_read_vma (ifp, valp)
BFD_HOST_U_64_BIT val64;
#endif
- switch (bfd_arch_bits_per_address (core_bfd))
+ switch (gmon_get_ptr_size ())
{
- case 32:
+ case ptr_32bit:
if (gmon_io_read_32 (ifp, &val32))
return 1;
- *valp = val32;
+ if (gmon_get_ptr_signedness () == ptr_signed)
+ *valp = (int) val32;
+ else
+ *valp = val32;
break;
#ifdef BFD_HOST_U_64_BIT
- case 64:
+ case ptr_64bit:
if (gmon_io_read_64 (ifp, &val64))
return 1;
- *valp = val64;
+#ifdef BFD_HOST_64_BIT
+ if (gmon_get_ptr_signedness () == ptr_signed)
+ *valp = (BFD_HOST_64_BIT) val64;
+ else
+#endif
+ *valp = val64;
break;
#endif
-
- default:
- fprintf (stderr, _("%s: bits per address has unexpected value of %u\n"),
- whoami, bfd_arch_bits_per_address (core_bfd));
- done (1);
}
return 0;
}
@@ -153,24 +207,19 @@ gmon_io_write_vma (ofp, val)
bfd_vma val;
{
- switch (bfd_arch_bits_per_address (core_bfd))
+ switch (gmon_get_ptr_size ())
{
- case 32:
+ case ptr_32bit:
if (gmon_io_write_32 (ofp, (unsigned int) val))
return 1;
break;
#ifdef BFD_HOST_U_64_BIT
- case 64:
+ case ptr_64bit:
if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) val))
return 1;
break;
#endif
-
- default:
- fprintf (stderr, _("%s: bits per address has unexpected value of %u\n"),
- whoami, bfd_arch_bits_per_address (core_bfd));
- done (1);
}
return 0;
}
@@ -215,26 +264,21 @@ gmon_read_raw_arc (ifp, fpc, spc, cnt)
|| gmon_io_read_vma (ifp, spc))
return 1;
- switch (bfd_arch_bits_per_address (core_bfd))
+ switch (gmon_get_ptr_size ())
{
- case 32:
+ case ptr_32bit:
if (gmon_io_read_32 (ifp, &cnt32))
return 1;
*cnt = cnt32;
break;
#ifdef BFD_HOST_U_64_BIT
- case 64:
+ case ptr_64bit:
if (gmon_io_read_64 (ifp, &cnt64))
return 1;
*cnt = cnt64;
break;
#endif
-
- default:
- fprintf (stderr, _("%s: bits per address has unexpected value of %u\n"),
- whoami, bfd_arch_bits_per_address (core_bfd));
- done (1);
}
return 0;
}
@@ -251,24 +295,19 @@ gmon_write_raw_arc (ofp, fpc, spc, cnt)
|| gmon_io_write_vma (ofp, spc))
return 1;
- switch (bfd_arch_bits_per_address (core_bfd))
+ switch (gmon_get_ptr_size ())
{
- case 32:
+ case ptr_32bit:
if (gmon_io_write_32 (ofp, (unsigned int) cnt))
return 1;
break;
#ifdef BFD_HOST_U_64_BIT
- case 64:
+ case ptr_64bit:
if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) cnt))
return 1;
break;
#endif
-
- default:
- fprintf (stderr, _("%s: bits per address has unexpected value of %u\n"),
- whoami, bfd_arch_bits_per_address (core_bfd));
- done (1);
}
return 0;
}
@@ -425,21 +464,15 @@ gmon_out_read (filename)
done (1);
}
- switch (bfd_arch_bits_per_address (core_bfd))
+ switch (gmon_get_ptr_size ())
{
- case 32:
+ case ptr_32bit:
header_size = GMON_HDRSIZE_BSD44_32;
break;
- case 64:
+ case ptr_64bit:
header_size = GMON_HDRSIZE_BSD44_64;
break;
-
- default:
- fprintf (stderr,
- _("%s: bits per address has unexpected value of %u\n"),
- whoami, bfd_arch_bits_per_address (core_bfd));
- done (1);
}
}
else
@@ -452,21 +485,15 @@ gmon_out_read (filename)
done (1);
}
- switch (bfd_arch_bits_per_address (core_bfd))
+ switch (gmon_get_ptr_size ())
{
- case 32:
+ case ptr_32bit:
header_size = GMON_HDRSIZE_OLDBSD_32;
break;
- case 64:
+ case ptr_64bit:
header_size = GMON_HDRSIZE_OLDBSD_64;
break;
-
- default:
- fprintf (stderr,
- _("%s: bits per address has unexpected value of %u\n"),
- whoami, bfd_arch_bits_per_address (core_bfd));
- done (1);
}
}
@@ -649,33 +676,27 @@ gmon_out_write (filename)
|| hz != hertz())
{
padsize = 3*4;
- switch (bfd_arch_bits_per_address (core_bfd))
+ switch (gmon_get_ptr_size ())
{
- case 32:
+ case ptr_32bit:
hdrsize = GMON_HDRSIZE_BSD44_32;
break;
- case 64:
+ case ptr_64bit:
hdrsize = GMON_HDRSIZE_BSD44_64;
break;
-
- default:
- fprintf (stderr,
- _("%s: bits per address has unexpected value of %u\n"),
- whoami, bfd_arch_bits_per_address (core_bfd));
- done (1);
}
}
else
{
padsize = 0;
- switch (bfd_arch_bits_per_address (core_bfd))
+ switch (gmon_get_ptr_size ())
{
- case 32:
+ case ptr_32bit:
hdrsize = GMON_HDRSIZE_OLDBSD_32;
break;
- case 64:
+ case ptr_64bit:
hdrsize = GMON_HDRSIZE_OLDBSD_64;
/* FIXME: Checking host compiler defines here means that we can't
use a cross gprof alpha OSF. */
@@ -683,12 +704,6 @@ gmon_out_write (filename)
padsize = 4;
#endif
break;
-
- default:
- fprintf (stderr,
- _("%s: bits per address has unexpected value of %u\n"),
- whoami, bfd_arch_bits_per_address (core_bfd));
- done (1);
}
}