Blame gprof/mips.c

Packit bbfece
/*
Packit bbfece
 * Copyright (c) 1983, 1993, 1998
Packit bbfece
 *      The Regents of the University of California.  All rights reserved.
Packit bbfece
 *
Packit bbfece
 * Redistribution and use in source and binary forms, with or without
Packit bbfece
 * modification, are permitted provided that the following conditions
Packit bbfece
 * are met:
Packit bbfece
 * 1. Redistributions of source code must retain the above copyright
Packit bbfece
 *    notice, this list of conditions and the following disclaimer.
Packit bbfece
 * 2. Redistributions in binary form must reproduce the above copyright
Packit bbfece
 *    notice, this list of conditions and the following disclaimer in the
Packit bbfece
 *    documentation and/or other materials provided with the distribution.
Packit bbfece
 * 3. Neither the name of the University nor the names of its contributors
Packit bbfece
 *    may be used to endorse or promote products derived from this software
Packit bbfece
 *    without specific prior written permission.
Packit bbfece
 *
Packit bbfece
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit bbfece
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit bbfece
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit bbfece
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit bbfece
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit bbfece
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit bbfece
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit bbfece
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit bbfece
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit bbfece
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit bbfece
 * SUCH DAMAGE.
Packit bbfece
 */
Packit bbfece
#include "gprof.h"
Packit bbfece
#include "search_list.h"
Packit bbfece
#include "source.h"
Packit bbfece
#include "symtab.h"
Packit bbfece
#include "cg_arcs.h"
Packit bbfece
#include "corefile.h"
Packit bbfece
#include "hist.h"
Packit bbfece
Packit bbfece
static Sym indirect_child;
Packit bbfece
Packit bbfece
void mips_find_call (Sym *, bfd_vma, bfd_vma);
Packit bbfece
Packit bbfece
void
Packit bbfece
mips_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
Packit bbfece
{
Packit bbfece
  bfd_vma pc, dest_pc;
Packit bbfece
  unsigned int op;
Packit bbfece
  int offset;
Packit bbfece
  Sym *child;
Packit bbfece
  static bfd_boolean inited = FALSE;
Packit bbfece
Packit bbfece
  if (!inited)
Packit bbfece
    {
Packit bbfece
      inited = TRUE;
Packit bbfece
      sym_init (&indirect_child);
Packit bbfece
      indirect_child.name = _("<indirect child>");
Packit bbfece
      indirect_child.cg.prop.fract = 1.0;
Packit bbfece
      indirect_child.cg.cyc.head = &indirect_child;
Packit bbfece
    }
Packit bbfece
Packit bbfece
  DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"),
Packit bbfece
			  parent->name, (unsigned long) p_lowpc,
Packit bbfece
			  (unsigned long) p_highpc));
Packit bbfece
  for (pc = p_lowpc; pc < p_highpc; pc += 4)
Packit bbfece
    {
Packit bbfece
      op = bfd_get_32 (core_bfd, ((unsigned char *)core_text_space
Packit bbfece
                                 + pc - core_text_sect->vma));
Packit bbfece
      if ((op & 0xfc000000) == 0x0c000000)
Packit bbfece
	{
Packit bbfece
	  /* This is a "jal" instruction.  Check that the destination
Packit bbfece
	     is the address of a function.  */
Packit bbfece
	  DBG (CALLDEBUG,
Packit bbfece
	       printf (_("[find_call] 0x%lx: jal"), (unsigned long) pc));
Packit bbfece
          offset = (op & 0x03ffffff) << 2;
Packit bbfece
	  dest_pc = (pc & ~(bfd_vma) 0xfffffff) | offset;
Packit bbfece
	  if (hist_check_address (dest_pc))
Packit bbfece
	    {
Packit bbfece
	      child = sym_lookup (&symtab, dest_pc);
Packit bbfece
              if (child)
Packit bbfece
		{
Packit bbfece
	          DBG (CALLDEBUG,
Packit bbfece
		       printf (" 0x%lx\t; name=%s, addr=0x%lx",
Packit bbfece
			       (unsigned long) dest_pc, child->name,
Packit bbfece
			       (unsigned long) child->addr));
Packit bbfece
	          if (child->addr == dest_pc)
Packit bbfece
		    {
Packit bbfece
		      DBG (CALLDEBUG, printf ("\n"));
Packit bbfece
		      /* a hit:  */
Packit bbfece
		      arc_add (parent, child, (unsigned long) 0);
Packit bbfece
		      continue;
Packit bbfece
		    }
Packit bbfece
		}
Packit bbfece
	    }
Packit bbfece
	  /* Something funny going on.  */
Packit bbfece
	  DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
Packit bbfece
	}
Packit bbfece
      else if ((op & 0xfc00f83f) == 0x0000f809)
Packit bbfece
	{
Packit bbfece
	  /* This is a "jalr" instruction (indirect call).  */
Packit bbfece
	  DBG (CALLDEBUG,
Packit bbfece
	       printf (_("[find_call] 0x%lx: jalr\n"), (unsigned long) pc));
Packit bbfece
	  arc_add (parent, &indirect_child, (unsigned long) 0);
Packit bbfece
	}
Packit bbfece
    }
Packit bbfece
}