Back to index

cell-binutils  2.17cvs20070401
i386.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1983, 1993, 2001
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 #include "gprof.h"
00030 #include "search_list.h"
00031 #include "source.h"
00032 #include "symtab.h"
00033 #include "cg_arcs.h"
00034 #include "corefile.h"
00035 #include "hist.h"
00036 
00037 static int i386_iscall (unsigned char *);
00038 void i386_find_call (Sym *, bfd_vma, bfd_vma);
00039 
00040 static int
00041 i386_iscall (unsigned char *ip)
00042 {
00043   if (*ip == 0xe8)
00044     return 1;
00045   return 0;
00046 }
00047 
00048 
00049 void
00050 i386_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
00051 {
00052   unsigned char *instructp;
00053   Sym *child;
00054   bfd_vma pc, destpc;
00055 
00056   if (core_text_space == 0)
00057     {
00058       return;
00059     }
00060   if (p_lowpc < s_lowpc)
00061     {
00062       p_lowpc = s_lowpc;
00063     }
00064   if (p_highpc > s_highpc)
00065     {
00066       p_highpc = s_highpc;
00067     }
00068   DBG (CALLDEBUG, printf ("[findcall] %s: 0x%lx to 0x%lx\n",
00069                        parent->name, (unsigned long) p_lowpc,
00070                        (unsigned long) p_highpc));
00071 
00072   for (pc = p_lowpc; pc < p_highpc; ++pc)
00073     {
00074       instructp = (unsigned char *) core_text_space + pc - core_text_sect->vma;
00075       if (i386_iscall (instructp))
00076        {
00077          DBG (CALLDEBUG,
00078               printf ("[findcall]\t0x%lx:call", (unsigned long) pc));
00079          /*
00080           *  regular pc relative addressing
00081           *    check that this is the address of
00082           *    a function.
00083           */
00084 
00085          destpc = bfd_get_32 (core_bfd, instructp + 1) + pc + 5;
00086          if (destpc >= s_lowpc && destpc <= s_highpc)
00087            {
00088              child = sym_lookup (&symtab, destpc);
00089              if (child && child->addr == destpc)
00090               {
00091                 /*
00092                  *      a hit
00093                  */
00094                 DBG (CALLDEBUG,
00095                      printf ("\tdestpc 0x%lx (%s)\n",
00096                             (unsigned long) destpc, child->name));
00097                 arc_add (parent, child, (unsigned long) 0);
00098                 instructp += 4;    /* call is a 5 byte instruction */
00099                 continue;
00100               }
00101            }
00102          /*
00103           *  else:
00104           *    it looked like a callf, but it:
00105           *      a) wasn't actually a callf, or
00106           *      b) didn't point to a known function in the symtab, or
00107           *      c) something funny is going on.
00108           */
00109          DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
00110        }
00111     }
00112 }