Blame gprof/mips.c

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