This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gprof failed to compile


This patch grew a bit as I kept finding things wrong with gprof.

gprof/ChangeLog
	* alpha.c (alpha_Instruction): Don't use.
	(alpha_find_call): Avoid use of bitfields and casts between
	pointers and integers of different sizes.  Avoid endian problems
	when cross-compiling.
	* vax.c (vax_find_call): Likewise.
	(struct modebyte): Don't use.
	(vax_operandmode): Pass in an unsigned char *.
	(vax_operandlength): Likewise.
	(vax_reladdr): Rename to vax_offset and return relative offset
	rather than address.
	* i386.c (i386_find_call): Avoid casts between pointers and
	integers of different sizes.
	* sparc.c (sparc_find_call): Likewise.  Avoid endian problems.
	* tahoe.c (tahoe_find_call): Likewise.
	(tahoe_reladdr): Rename to tahoe_offset and return relative offset
	rather than address.

	* basic_blocks.h: Don't include headers here.
	* call_graph.h: Likewise.
	* cg_arcs.h: Likewise.
	* cg_print.h: Likewise.
	* corefile.h: Likewise.
	* gmon_io.h: Likewise.
	* gmon_out.h: Likewise.
	* hertz.h: Likewise.
	* hist.h: Likewise.
	* source.h: Likewise.
	* sym_ids.h: Likewise.
	* symtab.h: Likewise.
	* gprof.h: Don't include ansidecl.h, do include bfd.h.
	(bool): Don't typedef.
	* alpha.c: Adjust #include's for above header changes.
	* basic_blocks.c: Likewise.
	* call_graph.c: Likewise.
	* cg_arcs.c: Likewise.
	* cg_dfn.c: Likewise.
	* cg_print.c: Likewise.
	* corefile.c: Likewise.
	* gmon_io.c: Likewise.
	* gprof.c: Likewise.
	* hertz.c: Likewise.
	* hist.c: Likewise.
	* i386.c: Likewise.
	* mips.c: Likewise.
	* sparc.c: Likewise.
	* sym_ids.c: Likewise.
	* symtab.c: Likewise.
	* tahoe.c: Likewise.
	* utils.c: Likewise.
	* vax.c: Likewise.

	* po/POTFILES.in: Regenerate.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

Index: gprof/alpha.c
===================================================================
RCS file: /cvs/src/src/gprof/alpha.c,v
retrieving revision 1.4
diff -u -p -r1.4 alpha.c
--- alpha.c	2001/09/18 11:12:25	1.4
+++ alpha.c	2002/01/31 11:34:56
@@ -17,10 +17,12 @@
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "corefile.h"
 #include "hist.h"
-#include "symtab.h"
 
 /*
  * Opcodes of the call instructions:
@@ -33,6 +35,9 @@
 #define Jxx_FUNC_RET		2
 #define Jxx_FUNC_JSR_COROUTINE	3
 
+#if 0
+/* Here to document only.  We can't use this when cross compiling as
+   the bitfield layout might not be the same as native.  */
 typedef union
   {
     struct
@@ -59,6 +64,7 @@ typedef union
     j;				/* jump format */
   }
 alpha_Instruction;
+#endif
 
 static Sym indirect_child;
 
@@ -77,15 +83,12 @@ alpha_find_call (parent, p_lowpc, p_high
      bfd_vma p_lowpc;
      bfd_vma p_highpc;
 {
-  static bfd_vma delta = 0;
-  bfd_vma dest_pc;
-  alpha_Instruction *pc;
+  bfd_vma pc, dest_pc;
+  unsigned long insn;
   Sym *child;
 
-  if (!delta)
+  if (indirect_child.name == NULL)
     {
-      delta = (bfd_vma) core_text_space - core_text_sect->vma;
-
       sym_init (&indirect_child);
       indirect_child.name = _("<indirect child>");
       indirect_child.cg.prop.fract = 1.0;
@@ -107,13 +110,13 @@ alpha_find_call (parent, p_lowpc, p_high
   DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"),
 			  parent->name, (unsigned long) p_lowpc,
 			  (unsigned long) p_highpc));
-  for (pc = (alpha_Instruction *) (p_lowpc + delta);
-       pc < (alpha_Instruction *) (p_highpc + delta);
-       ++pc)
+  for (pc = (p_lowpc + 3) & ~3; pc < p_highpc; pc += 4)
     {
-      switch (pc->a.op_code)
+      insn = bfd_get_32 (core_bfd, ((unsigned char *) core_text_space
+				    + pc - core_text_sect->vma));
+      switch (insn & (0x3f << 26))
 	{
-	case OP_Jxx:
+	case OP_Jxx << 26:
 	  /*
 	   * There is no simple and reliable way to determine the
 	   * target of a jsr (the hint bits help, but there aren't
@@ -122,28 +125,29 @@ alpha_find_call (parent, p_lowpc, p_high
 	   * to INDIRECT_CHILD---that way the user it at least able
 	   * to see that there are other calls as well.
 	   */
-	  if (pc->j.func == Jxx_FUNC_JSR
-	      || pc->j.func == Jxx_FUNC_JSR_COROUTINE)
+	  if ((insn & (3 << 14)) == Jxx_FUNC_JSR << 14
+	      || (insn & (3 << 14)) == Jxx_FUNC_JSR_COROUTINE << 14)
 	    {
 	      DBG (CALLDEBUG,
 		   printf (_("[find_call] 0x%lx: jsr%s <indirect_child>\n"),
-			   (unsigned long) pc - (unsigned long) delta,
-			   pc->j.func == Jxx_FUNC_JSR ? "" : "_coroutine"));
+			   (unsigned long) pc,
+			   ((insn & (3 << 14)) == Jxx_FUNC_JSR << 14
+			    ? "" : "_coroutine")));
 	      arc_add (parent, &indirect_child, (unsigned long) 0);
 	    }
 	  break;
 
-	case OP_BSR:
+	case OP_BSR << 26:
 	  DBG (CALLDEBUG,
-	       printf (_("[find_call] 0x%lx: bsr"),
-		       (unsigned long) pc - (unsigned long) delta));
+	       printf (_("[find_call] 0x%lx: bsr"), (unsigned long) pc));
 	  /*
 	   * Regular PC relative addressing.  Check that this is the
 	   * address of a function.  The linker sometimes redirects
 	   * the entry point by 8 bytes to skip loading the global
-	   * pointer, so we all for either address:
+	   * pointer, so we allow for either address:
 	   */
-	  dest_pc = ((bfd_vma) (pc + 1 + pc->b.disp)) - delta;
+	  dest_pc = pc + 4 + (((bfd_signed_vma) (insn & 0x1fffff)
+			       ^ 0x100000) - 0x100000);
 	  if (dest_pc >= s_lowpc && dest_pc <= s_highpc)
 	    {
 	      child = sym_lookup (&symtab, dest_pc);
Index: gprof/basic_blocks.c
===================================================================
RCS file: /cvs/src/src/gprof/basic_blocks.c,v
retrieving revision 1.6
diff -u -p -r1.6 basic_blocks.c
--- basic_blocks.c	2001/03/14 03:14:56	1.6
+++ basic_blocks.c	2002/01/31 11:34:56
@@ -21,18 +21,16 @@
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
-#include <stdio.h>
+#include "libiberty.h"
+#include "gprof.h"
 #include "basic_blocks.h"
 #include "corefile.h"
 #include "gmon_io.h"
 #include "gmon_out.h"
-#include "gprof.h"
-#include "libiberty.h"
+#include "search_list.h"
 #include "source.h"
+#include "symtab.h"
 #include "sym_ids.h"
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 
 /* Default option values:  */
 bool bb_annotate_all_lines = FALSE;
Index: gprof/basic_blocks.h
===================================================================
RCS file: /cvs/src/src/gprof/basic_blocks.h,v
retrieving revision 1.3
diff -u -p -r1.3 basic_blocks.h
--- basic_blocks.h	2001/03/13 21:07:29	1.3
+++ basic_blocks.h	2002/01/31 11:34:56
@@ -20,11 +20,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef basic_blocks_h
 #define basic_blocks_h
 
-#include <stdio.h>
-#include "gprof.h"
-#include "source.h"
-#include "symtab.h"
-
 /* Options:  */
 extern bool bb_annotate_all_lines;	/* Force annotation of all lines?  */
 extern int bb_table_length;		/* Length of most-used bb table.  */
Index: gprof/call_graph.c
===================================================================
RCS file: /cvs/src/src/gprof/call_graph.c,v
retrieving revision 1.5
diff -u -p -r1.5 call_graph.c
--- call_graph.c	2001/03/14 03:14:56	1.5
+++ call_graph.c	2002/01/31 11:34:56
@@ -19,12 +19,15 @@
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
+#include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "call_graph.h"
 #include "corefile.h"
 #include "gmon_io.h"
 #include "gmon_out.h"
-#include "symtab.h"
 #include "sym_ids.h"
 
 extern void
Index: gprof/call_graph.h
===================================================================
RCS file: /cvs/src/src/gprof/call_graph.h,v
retrieving revision 1.4
diff -u -p -r1.4 call_graph.h
--- call_graph.h	2001/03/14 03:14:56	1.4
+++ call_graph.h	2002/01/31 11:34:56
@@ -21,10 +21,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef call_graph_h
 #define call_graph_h
 
-#include <stdio.h>
-#include "gprof.h"
-#include "symtab.h"
-
 extern void cg_tally      PARAMS ((bfd_vma, bfd_vma, unsigned long));
 extern void cg_read_rec   PARAMS ((FILE *, const char *));
 extern void cg_write_arcs PARAMS ((FILE *, const char *));
Index: gprof/cg_arcs.c
===================================================================
RCS file: /cvs/src/src/gprof/cg_arcs.c,v
retrieving revision 1.2
diff -u -p -r1.2 cg_arcs.c
--- cg_arcs.c	2001/03/14 03:14:56	1.2
+++ cg_arcs.c	2002/01/31 11:34:56
@@ -18,6 +18,9 @@
  */
 #include "libiberty.h"
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "call_graph.h"
 #include "cg_arcs.h"
 #include "cg_dfn.h"
Index: gprof/cg_arcs.h
===================================================================
RCS file: /cvs/src/src/gprof/cg_arcs.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 cg_arcs.h
--- cg_arcs.h	1999/05/03 07:29:11	1.1.1.1
+++ cg_arcs.h	2002/01/31 11:34:56
@@ -1,9 +1,6 @@
 #ifndef cg_arcs_h
 #define cg_arcs_h
 
-#include "gprof.h"
-#include "symtab.h"
-
 /*
  * Arc structure for call-graph.
  *
Index: gprof/cg_dfn.c
===================================================================
RCS file: /cvs/src/src/gprof/cg_dfn.c,v
retrieving revision 1.2
diff -u -p -r1.2 cg_dfn.c
--- cg_dfn.c	1999/06/13 19:38:06	1.2
+++ cg_dfn.c	2002/01/31 11:34:56
@@ -16,12 +16,13 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
-#include <stdio.h>
 #include "libiberty.h"
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "cg_dfn.h"
-#include "symtab.h"
 #include "utils.h"
 
 #define	DFN_INCR_DEPTH (128)
Index: gprof/cg_print.c
===================================================================
RCS file: /cvs/src/src/gprof/cg_print.c,v
retrieving revision 1.5
diff -u -p -r1.5 cg_print.c
--- cg_print.c	2002/01/02 15:55:48	1.5
+++ cg_print.c	2002/01/31 11:34:58
@@ -20,6 +20,10 @@
    02111-1307, USA.  */
 
 #include "libiberty.h"
+#include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "cg_print.h"
 #include "hist.h"
Index: gprof/cg_print.h
===================================================================
RCS file: /cvs/src/src/gprof/cg_print.h,v
retrieving revision 1.4
diff -u -p -r1.4 cg_print.h
--- cg_print.h	2001/03/14 03:14:56	1.4
+++ cg_print.h	2002/01/31 11:34:58
@@ -21,9 +21,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef cg_print_h
 #define cg_print_h
 
-#include "gprof.h"
-#include "symtab.h"
-
 extern double print_time;	/* Total of time being printed.  */
 
 extern void cg_print                    PARAMS ((Sym **));
Index: gprof/corefile.c
===================================================================
RCS file: /cvs/src/src/gprof/corefile.c,v
retrieving revision 1.8
diff -u -p -r1.8 corefile.c
--- corefile.c	2002/01/26 17:19:35	1.8
+++ corefile.c	2002/01/31 11:34:58
@@ -21,8 +21,10 @@
 
 #include "libiberty.h"
 #include "gprof.h"
-#include "corefile.h"
+#include "search_list.h"
+#include "source.h"
 #include "symtab.h"
+#include "corefile.h"
 
 bfd *core_bfd;
 int core_num_syms;
Index: gprof/corefile.h
===================================================================
RCS file: /cvs/src/src/gprof/corefile.h,v
retrieving revision 1.4
diff -u -p -r1.4 corefile.h
--- corefile.h	2001/03/14 03:14:56	1.4
+++ corefile.h	2002/01/31 11:34:58
@@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef corefile_h
 #define corefile_h
 
-#include "bfd.h"
-
 extern bfd *core_bfd;		/* BFD for core-file.  */
 extern int core_num_syms;	/* # of entries in symbol-table.  */
 extern asymbol **core_syms;	/* Symbol table in a.out.  */
Index: gprof/gmon_io.c
===================================================================
RCS file: /cvs/src/src/gprof/gmon_io.c,v
retrieving revision 1.10
diff -u -p -r1.10 gmon_io.c
--- gmon_io.c	2002/01/03 21:32:36	1.10
+++ gmon_io.c	2002/01/31 11:34:59
@@ -19,15 +19,17 @@
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
+#include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "basic_blocks.h"
-#include "bfd.h"
 #include "corefile.h"
 #include "call_graph.h"
 #include "gmon_io.h"
 #include "gmon_out.h"
 #include "gmon.h"		/* Fetch header for old format.  */
-#include "gprof.h"
 #include "hertz.h"
 #include "hist.h"
 #include "libiberty.h"
Index: gprof/gmon_io.h
===================================================================
RCS file: /cvs/src/src/gprof/gmon_io.h,v
retrieving revision 1.5
diff -u -p -r1.5 gmon_io.h
--- gmon_io.h	2001/03/14 03:14:56	1.5
+++ gmon_io.h	2002/01/31 11:34:59
@@ -21,9 +21,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef gmon_io_h
 #define gmon_io_h
 
-#include "bfd.h"
-#include "gmon.h"
-
 /* Some platforms need to put stdin into binary mode, to read
    binary files.  */
 #include "sysdep.h"
Index: gprof/gmon_out.h
===================================================================
RCS file: /cvs/src/src/gprof/gmon_out.h,v
retrieving revision 1.4
diff -u -p -r1.4 gmon_out.h
--- gmon_out.h	2001/03/14 03:14:56	1.4
+++ gmon_out.h	2002/01/31 11:34:59
@@ -24,8 +24,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef gmon_out_h
 #define gmon_out_h
 
-#include <gconfig.h>
-
 #define	GMON_MAGIC	"gmon"	/* magic cookie */
 #define GMON_VERSION	1	/* version number */
 
Index: gprof/gprof.c
===================================================================
RCS file: /cvs/src/src/gprof/gprof.c,v
retrieving revision 1.8
diff -u -p -r1.8 gprof.c
--- gprof.c	2001/09/19 05:33:31	1.8
+++ gprof.c	2002/01/31 11:34:59
@@ -19,6 +19,9 @@
 #include "getopt.h"
 #include "libiberty.h"
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "basic_blocks.h"
 #include "call_graph.h"
 #include "cg_arcs.h"
@@ -27,7 +30,6 @@
 #include "gmon_io.h"
 #include "hertz.h"
 #include "hist.h"
-#include "source.h"
 #include "sym_ids.h"
 #include "demangle.h"
 
Index: gprof/gprof.h
===================================================================
RCS file: /cvs/src/src/gprof/gprof.h,v
retrieving revision 1.5
diff -u -p -r1.5 gprof.h
--- gprof.h	2000/06/01 00:11:31	1.5
+++ gprof.h	2002/01/31 11:34:59
@@ -21,10 +21,9 @@
 #ifndef gprof_h
 #define gprof_h
 
-#include "ansidecl.h"
-
 /* Include the BFD sysdep.h file.  */
 #include "sysdep.h"
+#include "bfd.h"
 
 /* Undefine the BFD PACKAGE and VERSION macros before including the
    gprof config.h file.  */
@@ -109,7 +108,6 @@ typedef enum
   }
 File_Format;
 
-typedef int bool;
 typedef unsigned char UNIT[2];	/* unit of profiling */
 
 extern const char *whoami;	/* command-name, for error messages */
Index: gprof/hertz.c
===================================================================
RCS file: /cvs/src/src/gprof/hertz.c,v
retrieving revision 1.2
diff -u -p -r1.2 hertz.c
--- hertz.c	2000/05/26 13:11:56	1.2
+++ hertz.c	2002/01/31 11:34:59
@@ -16,6 +16,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
+#include "gprof.h"
 #include "hertz.h"
 
 
Index: gprof/hertz.h
===================================================================
RCS file: /cvs/src/src/gprof/hertz.h,v
retrieving revision 1.2
diff -u -p -r1.2 hertz.h
--- hertz.h	2000/03/26 12:31:16	1.2
+++ hertz.h	2002/01/31 11:34:59
@@ -1,8 +1,6 @@
 #ifndef hertz_h
 #define hertz_h
 
-#include "gprof.h"
-
 #define	HZ_WRONG 0		/* impossible clock frequency */
 
 /*
Index: gprof/hist.c
===================================================================
RCS file: /cvs/src/src/gprof/hist.c,v
retrieving revision 1.5
diff -u -p -r1.5 hist.c
--- hist.c	2001/03/14 03:14:56	1.5
+++ hist.c	2002/01/31 11:34:59
@@ -19,14 +19,15 @@
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
-#include <stdio.h>
 #include "libiberty.h"
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "corefile.h"
 #include "gmon_io.h"
 #include "gmon_out.h"
 #include "hist.h"
-#include "symtab.h"
 #include "sym_ids.h"
 #include "utils.h"
 
Index: gprof/hist.h
===================================================================
RCS file: /cvs/src/src/gprof/hist.h,v
retrieving revision 1.4
diff -u -p -r1.4 hist.h
--- hist.h	2001/03/14 03:14:56	1.4
+++ hist.h	2002/01/31 11:34:59
@@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef hist_h
 #define hist_h
 
-#include "bfd.h"
-
 extern bfd_vma s_lowpc;		/* Lowpc from the profile file.  */
 extern bfd_vma s_highpc;	/* Highpc from the profile file.  */
 extern bfd_vma lowpc, highpc;	/* Range profiled, in UNIT's.  */
Index: gprof/i386.c
===================================================================
RCS file: /cvs/src/src/gprof/i386.c,v
retrieving revision 1.6
diff -u -p -r1.6 i386.c
--- i386.c	2002/01/27 02:43:52	1.6
+++ i386.c	2002/01/31 11:34:59
@@ -17,10 +17,12 @@
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "corefile.h"
 #include "hist.h"
-#include "symtab.h"
 
 static int i386_iscall PARAMS ((unsigned char *));
 void i386_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
@@ -43,7 +45,7 @@ i386_find_call (parent, p_lowpc, p_highp
 {
   unsigned char *instructp;
   Sym *child;
-  bfd_vma destpc, delta;
+  bfd_vma pc, destpc;
 
   if (core_text_space == 0)
     {
@@ -60,26 +62,21 @@ i386_find_call (parent, p_lowpc, p_highp
   DBG (CALLDEBUG, printf ("[findcall] %s: 0x%lx to 0x%lx\n",
 			  parent->name, (unsigned long) p_lowpc,
 			  (unsigned long) p_highpc));
-
-  delta = (bfd_vma) core_text_space - core_text_sect->vma;
 
-  for (instructp = (unsigned char *) (p_lowpc + delta);
-       instructp < (unsigned char *) (p_highpc + delta);
-       instructp ++)
+  for (pc = p_lowpc; pc < p_highpc; ++pc)
     {
+      instructp = (unsigned char *) core_text_space + pc - core_text_sect->vma;
       if (i386_iscall (instructp))
 	{
 	  DBG (CALLDEBUG,
-	       printf ("[findcall]\t0x%lx:call",
-		       (unsigned long) (instructp - (unsigned char *) delta)));
+	       printf ("[findcall]\t0x%lx:call", (unsigned long) pc));
 	  /*
 	   *  regular pc relative addressing
 	   *    check that this is the address of
 	   *    a function.
 	   */
 
-	  destpc = ((bfd_vma) bfd_get_32 (core_bfd, instructp + 1)
-		    + (bfd_vma) instructp - (bfd_vma) delta + 5);
+	  destpc = bfd_get_32 (core_bfd, instructp + 1) + pc + 5;
 	  if (destpc >= s_lowpc && destpc <= s_highpc)
 	    {
 	      child = sym_lookup (&symtab, destpc);
Index: gprof/mips.c
===================================================================
RCS file: /cvs/src/src/gprof/mips.c,v
retrieving revision 1.1
diff -u -p -r1.1 mips.c
--- mips.c	2002/01/26 17:19:35	1.1
+++ mips.c	2002/01/31 11:35:00
@@ -17,10 +17,12 @@
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "corefile.h"
 #include "hist.h"
-#include "symtab.h"
 
 static Sym indirect_child;
 
Index: gprof/source.h
===================================================================
RCS file: /cvs/src/src/gprof/source.h,v
retrieving revision 1.4
diff -u -p -r1.4 source.h
--- source.h	2001/03/14 03:14:56	1.4
+++ source.h	2002/01/31 11:35:00
@@ -21,10 +21,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef source_h
 #define source_h
 
-#include <stdio.h>
-#include "gprof.h"
-#include "search_list.h"
-
 typedef struct source_file
   {
     struct source_file *next;
Index: gprof/sparc.c
===================================================================
RCS file: /cvs/src/src/gprof/sparc.c,v
retrieving revision 1.4
diff -u -p -r1.4 sparc.c
--- sparc.c	2001/09/18 11:12:25	1.4
+++ sparc.c	2002/01/31 11:35:00
@@ -17,10 +17,12 @@
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "corefile.h"
 #include "hist.h"
-#include "symtab.h"
 
     /*
      *        opcode of the `callf' instruction
@@ -35,12 +37,10 @@ sparc_find_call (parent, p_lowpc, p_high
      bfd_vma p_lowpc;
      bfd_vma p_highpc;
 {
-  bfd_vma dest_pc, delta;
-  unsigned int *instr;
+  bfd_vma pc, dest_pc;
+  unsigned long insn;
   Sym *child;
 
-  delta = (bfd_vma) core_text_space - core_text_sect->vma;
-
   if (core_text_space == 0)
     {
       return;
@@ -56,20 +56,20 @@ sparc_find_call (parent, p_lowpc, p_high
   DBG (CALLDEBUG, printf ("[find_call] %s: 0x%lx to 0x%lx\n",
 			  parent->name, (unsigned long) p_lowpc,
 			  (unsigned long) p_highpc));
-  for (instr = (unsigned int *) (((p_lowpc + delta) + 3) &~ 3);
-       instr < (unsigned int *) (p_highpc + delta);
-       ++instr)
+  for (pc = (p_lowpc + 3) & ~3; pc < p_highpc; pc += 4)
     {
-      if ((*instr & CALL))
+      insn = bfd_get_32 (core_bfd, ((unsigned char *) core_text_space
+				    + pc - core_text_sect->vma));
+      if (insn & CALL)
 	{
 	  DBG (CALLDEBUG,
-	       printf ("[find_call] 0x%lx: callf",
-		       (unsigned long) instr - (unsigned long) delta));
+	       printf ("[find_call] 0x%lx: callf", (unsigned long) pc));
 	  /*
 	   * Regular pc relative addressing check that this is the
 	   * address of a function.
 	   */
-	  dest_pc = ((bfd_vma) (instr + (*instr & ~CALL))) - delta;
+	  dest_pc = pc + (((bfd_signed_vma) (insn & 0x3fffffff)
+			   ^ 0x20000000) - 0x20000000);
 	  if (dest_pc >= s_lowpc && dest_pc <= s_highpc)
 	    {
 	      child = sym_lookup (&symtab, dest_pc);
Index: gprof/sym_ids.c
===================================================================
RCS file: /cvs/src/src/gprof/sym_ids.c,v
retrieving revision 1.8
diff -u -p -r1.8 sym_ids.c
--- sym_ids.c	2001/09/19 05:33:31	1.8
+++ sym_ids.c	2002/01/31 11:35:00
@@ -21,6 +21,10 @@
 
 #include "libiberty.h"
 #include "safe-ctype.h"
+#include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "sym_ids.h"
 
Index: gprof/sym_ids.h
===================================================================
RCS file: /cvs/src/src/gprof/sym_ids.h,v
retrieving revision 1.4
diff -u -p -r1.4 sym_ids.h
--- sym_ids.h	2001/03/14 03:14:56	1.4
+++ sym_ids.h	2002/01/31 11:35:00
@@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef sym_ids_h
 #define sym_ids_h
 
-#include "symtab.h"
-
 typedef enum
   {
     INCL_GRAPH = 0, EXCL_GRAPH,
Index: gprof/symtab.c
===================================================================
RCS file: /cvs/src/src/gprof/symtab.c,v
retrieving revision 1.6
diff -u -p -r1.6 symtab.c
--- symtab.c	2001/03/14 03:14:56	1.6
+++ symtab.c	2002/01/31 11:35:00
@@ -20,9 +20,11 @@
    02111-1307, USA.  */
 
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "corefile.h"
-#include "symtab.h"
 
 Sym_Table symtab;
 
Index: gprof/symtab.h
===================================================================
RCS file: /cvs/src/src/gprof/symtab.h,v
retrieving revision 1.4
diff -u -p -r1.4 symtab.h
--- symtab.h	2001/03/14 03:14:56	1.4
+++ symtab.h	2002/01/31 11:35:00
@@ -21,9 +21,6 @@ Foundation, Inc., 59 Temple Place - Suit
 #ifndef symtab_h
 #define symtab_h
 
-#include "bfd.h"
-#include "gprof.h"
-
 /* For a profile to be intelligible to a human user, it is necessary
    to map code-addresses into source-code information.  Source-code
    information can be any combination of: (i) function-name, (ii)
@@ -31,8 +28,6 @@ Foundation, Inc., 59 Temple Place - Suit
 
    The symbol table is used to map addresses into source-code
    information.  */
-
-#include "source.h"
 
 #define NBBS 10
 
Index: gprof/tahoe.c
===================================================================
RCS file: /cvs/src/src/gprof/tahoe.c,v
retrieving revision 1.6
diff -u -p -r1.6 tahoe.c
--- tahoe.c	2002/01/27 02:43:52	1.6
+++ tahoe.c	2002/01/31 11:35:01
@@ -17,10 +17,12 @@
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "corefile.h"
 #include "hist.h"
-#include "symtab.h"
 
     /*
      *        opcode of the `callf' instruction
@@ -49,16 +51,16 @@ static Sym indirectchild;
 static tahoe_operandenum tahoe_operandmode PARAMS ((unsigned char *));
 static char *tahoe_operandname PARAMS ((tahoe_operandenum));
 static long tahoe_operandlength PARAMS ((unsigned char *));
-static bfd_vma tahoe_reladdr PARAMS ((char *));
+static bfd_signed_vma tahoe_offset PARAMS ((unsigned char *));
 void tahoe_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
 
 static tahoe_operandenum
 tahoe_operandmode (modep)
      unsigned char *modep;
 {
-  long usesreg = ((long) *modep) & 0xf;
+  long usesreg = *modep & 0xf;
 
-  switch (((long) *modep) >> 4)
+  switch ((*modep >> 4) & 0xf)
     {
     case 0:
     case 1:
@@ -186,34 +188,24 @@ tahoe_operandlength (modep)
   abort ();
 }
 
-static bfd_vma
-tahoe_reladdr (modep)
-     char *modep;
+static bfd_signed_vma
+tahoe_offset (modep)
+     unsigned char *modep;
 {
   tahoe_operandenum mode = tahoe_operandmode (modep);
-  char *cp;
-  short *sp;
-  long *lp;
-  int i;
-  long value = 0;
 
-  cp = modep;
-  ++cp;				/* skip over the mode */
+  ++modep;				/* skip over the mode */
   switch (mode)
     {
     default:
       fprintf (stderr, "[reladdr] not relative address\n");
-      return (bfd_vma) modep;
+      return 0;
     case byterel:
-      return (bfd_vma) (cp + sizeof *cp + *cp);
+      return 1 + bfd_get_signed_8 (core_bfd, modep);
     case wordrel:
-      for (i = 0; (size_t) i < sizeof *sp; i++)
-	value = (value << 8) + (cp[i] & 0xff);
-      return (bfd_vma) (cp + sizeof *sp + value);
+      return 2 + bfd_get_signed_16 (core_bfd, modep);
     case longrel:
-      for (i = 0; (size_t) i < sizeof *lp; i++)
-	value = (value << 8) + (cp[i] & 0xff);
-      return (bfd_vma) (cp + sizeof *lp + value);
+      return 4 + bfd_get_signed_32 (core_bfd, modep);
     }
 }
 
@@ -228,7 +220,7 @@ tahoe_find_call (parent, p_lowpc, p_high
   Sym *child;
   tahoe_operandenum mode;
   tahoe_operandenum firstmode;
-  bfd_vma destpc;
+  bfd_vma pc, destpc;
   static bool inited = FALSE;
 
   if (!inited)
@@ -254,21 +246,19 @@ tahoe_find_call (parent, p_lowpc, p_high
   DBG (CALLDEBUG, printf ("[findcall] %s: 0x%lx to 0x%lx\n",
 			  parent->name, (unsigned long) p_lowpc,
 			  (unsigned long) p_highpc));
-  for (instructp = (unsigned char *) core_text_space + p_lowpc;
-       instructp < (unsigned char *) core_text_space + p_highpc;
-       instructp += length)
+  for (pc = p_lowpc; pc < p_highpc; pc += length)
     {
       length = 1;
-      if (*instructp == CALLF)
+      instructp = ((unsigned char *) core_text_space
+		   + pc - core_text_sect->vma);
+      if ((*instructp & 0xff) == CALLF)
 	{
 	  /*
 	   *    maybe a callf, better check it out.
 	   *      skip the count of the number of arguments.
 	   */
 	  DBG (CALLDEBUG, printf ("[findcall]\t0x%lx:callf",
-				  ((unsigned long)
-				   (instructp
-				    - (unsigned char *) core_text_space))));
+				  (unsigned long) pc));
 	  firstmode = tahoe_operandmode (instructp + length);
 	  switch (firstmode)
 	    {
@@ -312,8 +302,7 @@ tahoe_find_call (parent, p_lowpc, p_high
 	       *      check that this is the address of
 	       *      a function.
 	       */
-	      destpc = tahoe_reladdr (instructp + length)
-		- (bfd_vma) core_text_space;
+	      destpc = pc + tahoe_offset (instructp + length);
 	      if (destpc >= s_lowpc && destpc <= s_highpc)
 		{
 		  child = sym_lookup (&symtab, destpc);
Index: gprof/utils.c
===================================================================
RCS file: /cvs/src/src/gprof/utils.c,v
retrieving revision 1.3
diff -u -p -r1.3 utils.c
--- utils.c	2001/03/14 03:14:56	1.3
+++ utils.c	2002/01/31 11:35:01
@@ -16,10 +16,12 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
-#include <demangle.h>
+#include "demangle.h"
 #include "gprof.h"
-#include "cg_arcs.h"
+#include "search_list.h"
+#include "source.h"
 #include "symtab.h"
+#include "cg_arcs.h"
 
 
 /*
Index: gprof/vax.c
===================================================================
RCS file: /cvs/src/src/gprof/vax.c,v
retrieving revision 1.6
diff -u -p -r1.6 vax.c
--- vax.c	2002/01/27 02:43:52	1.6
+++ vax.c	2002/01/31 11:35:01
@@ -17,10 +17,12 @@
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include "gprof.h"
+#include "search_list.h"
+#include "source.h"
+#include "symtab.h"
 #include "cg_arcs.h"
 #include "corefile.h"
 #include "hist.h"
-#include "symtab.h"
 
     /*
      *        opcode of the `calls' instruction
@@ -41,30 +43,34 @@ enum opermodes
   };
 typedef enum opermodes operandenum;
 
+#if 0
+/* Here to document only.  We can't use this when cross compiling as
+   the bitfield layout might not be the same as native.  */
 struct modebyte
   {
     unsigned int regfield:4;
     unsigned int modefield:4;
   };
+#endif
 
 /*
  * A symbol to be the child of indirect calls:
  */
 static Sym indirectchild;
 
-static operandenum vax_operandmode PARAMS ((struct modebyte *));
+static operandenum vax_operandmode PARAMS ((unsigned char *));
 static char *vax_operandname PARAMS ((operandenum));
-static long vax_operandlength PARAMS ((struct modebyte *));
-static bfd_vma vax_reladdr PARAMS ((struct modebyte *));
+static long vax_operandlength PARAMS ((unsigned char *));
+static bfd_signed_vma vax_offset PARAMS ((unsigned char *));
 void vax_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
 
 static operandenum
 vax_operandmode (modep)
-     struct modebyte *modep;
+     unsigned char *modep;
 {
-  long usesreg = modep->regfield;
+  int usesreg = *modep & 0xf;
 
-  switch (modep->modefield)
+  switch ((*modep >> 4) & 0xf)
     {
     case 0:
     case 1:
@@ -156,7 +162,7 @@ vax_operandname (mode)
 
 static long
 vax_operandlength (modep)
-     struct modebyte *modep;
+     unsigned char *modep;
 {
 
   switch (vax_operandmode (modep))
@@ -186,36 +192,30 @@ vax_operandlength (modep)
     case longreldef:
       return 5;
     case indexed:
-      return 1 + vax_operandlength ((struct modebyte *) ((char *) modep) + 1);
+      return 1 + vax_operandlength (modep + 1);
     }
   /* NOTREACHED */
   abort ();
 }
 
-static bfd_vma
-vax_reladdr (modep)
-     struct modebyte *modep;
+static bfd_signed_vma
+vax_offset (modep)
+     unsigned char *modep;
 {
   operandenum mode = vax_operandmode (modep);
-  char *cp;
-  short *sp;
-  long *lp;
 
-  cp = (char *) modep;
-  ++cp;				/* skip over the mode */
+  ++modep;				/* skip over the mode */
   switch (mode)
     {
     default:
       fprintf (stderr, "[reladdr] not relative address\n");
-      return (bfd_vma) modep;
+      return 0;
     case byterel:
-      return (bfd_vma) (cp + sizeof *cp + *cp);
+      return 1 + bfd_get_signed_8 (core_bfd, modep);
     case wordrel:
-      sp = (short *) cp;
-      return (bfd_vma) (cp + sizeof *sp + *sp);
+      return 2 + bfd_get_signed_16 (core_bfd, modep);
     case longrel:
-      lp = (long *) cp;
-      return (bfd_vma) (cp + sizeof *lp + *lp);
+      return 4 + bfd_get_signed_32 (core_bfd, modep);
     }
 }
 
@@ -231,7 +231,7 @@ vax_find_call (parent, p_lowpc, p_highpc
   Sym *child;
   operandenum mode;
   operandenum firstmode;
-  bfd_vma destpc;
+  bfd_vma pc, destpc;
   static bool inited = FALSE;
 
   if (!inited)
@@ -257,22 +257,20 @@ vax_find_call (parent, p_lowpc, p_highpc
   DBG (CALLDEBUG, printf ("[findcall] %s: 0x%lx to 0x%lx\n",
 			  parent->name, (unsigned long) p_lowpc,
 			  (unsigned long) p_highpc));
-  for (instructp = (unsigned char *) core_text_space + p_lowpc;
-       instructp < (unsigned char *) core_text_space + p_highpc;
-       instructp += length)
+  for (pc = p_lowpc; pc < p_highpc; pc += length)
     {
       length = 1;
-      if (*instructp == CALLS)
+      instructp = ((unsigned char *) core_text_space
+		   + pc - core_text_sect->vma);
+      if ((*instructp & 0xff) == CALLS)
 	{
 	  /*
 	   *    maybe a calls, better check it out.
 	   *      skip the count of the number of arguments.
 	   */
 	  DBG (CALLDEBUG,
-	       printf ("[findcall]\t0x%lx:calls",
-		       ((unsigned long)
-			(instructp - (unsigned char *) core_text_space))));
-	  firstmode = vax_operandmode ((struct modebyte *) (instructp + length));
+	       printf ("[findcall]\t0x%lx:calls", (unsigned long) pc));
+	  firstmode = vax_operandmode (instructp + length);
 	  switch (firstmode)
 	    {
 	    case literal:
@@ -281,8 +279,8 @@ vax_find_call (parent, p_lowpc, p_highpc
 	    default:
 	      goto botched;
 	    }
-	  length += vax_operandlength ((struct modebyte *) (instructp + length));
-	  mode = vax_operandmode ((struct modebyte *) (instructp + length));
+	  length += vax_operandlength (instructp + length);
+	  mode = vax_operandmode (instructp + length);
 	  DBG (CALLDEBUG,
 	       printf ("\tfirst operand is %s", vax_operandname (firstmode));
 	       printf ("\tsecond operand is %s\n", vax_operandname (mode)));
@@ -304,8 +302,7 @@ vax_find_call (parent, p_lowpc, p_highpc
 	       *       e.g. arrays of pointers to functions???]
 	       */
 	      arc_add (parent, &indirectchild, (unsigned long) 0);
-	      length += vax_operandlength (
-				  (struct modebyte *) (instructp + length));
+	      length += vax_operandlength (instructp + length);
 	      continue;
 	    case byterel:
 	    case wordrel:
@@ -315,8 +312,7 @@ vax_find_call (parent, p_lowpc, p_highpc
 	       *      check that this is the address of
 	       *      a function.
 	       */
-	      destpc = vax_reladdr ((struct modebyte *) (instructp + length))
-		- (bfd_vma) core_text_space;
+	      destpc = pc + vax_offset (instructp + length);
 	      if (destpc >= s_lowpc && destpc <= s_highpc)
 		{
 		  child = sym_lookup (&symtab, destpc);
@@ -333,8 +329,7 @@ vax_find_call (parent, p_lowpc, p_highpc
 		       *    a hit
 		       */
 		      arc_add (parent, child, (unsigned long) 0);
-		      length += vax_operandlength ((struct modebyte *)
-						   (instructp + length));
+		      length += vax_operandlength (instructp + length);
 		      continue;
 		    }
 		  goto botched;
Index: gprof/po/POTFILES.in
===================================================================
RCS file: /cvs/src/src/gprof/po/POTFILES.in,v
retrieving revision 1.2
diff -u -p -r1.2 POTFILES.in
--- POTFILES.in	1999/06/03 03:26:49	1.2
+++ POTFILES.in	2002/01/31 11:35:01
@@ -22,6 +22,7 @@ hertz.h
 hist.c
 hist.h
 i386.c
+mips.c
 search_list.c
 search_list.h
 source.c


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]