[BACK]Return to pmax.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / gprof

Annotation of src/usr.bin/gprof/pmax.c, Revision 1.1.1.1

1.1       deraadt     1: /*     $NetBSD: pmax.c,v 1.3 1995/04/19 07:16:18 cgd Exp $     */
                      2:
                      3: /*
                      4:  * Copyright (c) 1992, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * This software was developed by the Computer Systems Engineering group
                      8:  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
                      9:  * contributed to Berkeley. Modified by Ralph Campbell for mips.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *     This product includes software developed by the University of
                     22:  *     California, Berkeley and its contributors.
                     23:  * 4. Neither the name of the University nor the names of its contributors
                     24:  *    may be used to endorse or promote products derived from this software
                     25:  *    without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     28:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     29:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     30:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     31:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     32:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     33:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     34:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     35:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     36:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     37:  * SUCH DAMAGE.
                     38:  *
                     39:  * From: sparc.c 5.1 (Berkeley) 7/7/92
                     40:  */
                     41:
                     42: #ifndef lint
                     43: #if 0
                     44: static char sccsid[] = "@(#)mips.c     8.1 (Berkeley) 6/6/93";
                     45: #else
                     46: static char rcsid[] = "$NetBSD: pmax.c,v 1.3 1995/04/19 07:16:18 cgd Exp $";
                     47: #endif
                     48: #endif /* not lint */
                     49:
                     50: #include       "gprof.h"
                     51:
                     52:     /*
                     53:      * a namelist entry to be the child of indirect calls
                     54:      */
                     55: nltype indirectchild = {
                     56:        "(*)" ,                         /* the name */
                     57:        (unsigned long) 0 ,             /* the pc entry point */
                     58:        (unsigned long) 0 ,             /* entry point aligned to histogram */
                     59:        (double) 0.0 ,                  /* ticks in this routine */
                     60:        (double) 0.0 ,                  /* cumulative ticks in children */
                     61:        (long) 0 ,                      /* how many times called */
                     62:        (long) 0 ,                      /* times called by live arcs */
                     63:        (long) 0 ,                      /* how many calls to self */
                     64:        (double) 1.0 ,                  /* propagation fraction */
                     65:        (double) 0.0 ,                  /* self propagation time */
                     66:        (double) 0.0 ,                  /* child propagation time */
                     67:        (short) 0 ,                     /* print flag */
                     68:        (short) 0 ,                     /* flags */
                     69:        (int) 0 ,                       /* index in the graph list */
                     70:        (int) 0 ,                       /* graph call chain top-sort order */
                     71:        (int) 0 ,                       /* internal number of cycle on */
                     72:        (int) 0 ,                       /* number of live parent arcs */
                     73:        (struct nl *) &indirectchild ,  /* pointer to head of cycle */
                     74:        (struct nl *) 0 ,               /* pointer to next member of cycle */
                     75:        (arctype *) 0 ,                 /* list of caller arcs */
                     76:        (arctype *) 0                   /* list of callee arcs */
                     77: };
                     78:
                     79: findcall(parentp, p_lowpc, p_highpc)
                     80:        nltype          *parentp;
                     81:        unsigned long   p_lowpc;
                     82:        unsigned long   p_highpc;
                     83: {
                     84:        register u_long pc;
                     85:        nltype *childp;
                     86:        unsigned long destpc;
                     87:        register long op;
                     88:        register int off;
                     89:
                     90:        if (textspace == 0)
                     91:                return;
                     92:        if (p_lowpc < s_lowpc)
                     93:                p_lowpc = s_lowpc;
                     94:        if (p_highpc > s_highpc)
                     95:                p_highpc = s_highpc;
                     96:
                     97:        for (pc = p_lowpc; pc < p_highpc; pc += 4) {
                     98:                off = pc - s_lowpc;
                     99:                op = *(u_long *)&textspace[off];
                    100:                if ((op & 0xfc000000) == 0x0c000000) {
                    101:                        /*
                    102:                         * a jal insn -- check that this
                    103:                         * is the address of a function.
                    104:                         */
                    105:                        off = (op & 0x03ffffff) << 2;
                    106:                        destpc = (pc & 0xf0000000) | off;
                    107:                        if (destpc >= s_lowpc && destpc <= s_highpc) {
                    108:                                childp = nllookup(destpc);
                    109:                                if (childp != 0 && childp->value == destpc)
                    110:                                        addarc(parentp, childp, 0L);
                    111:                        }
                    112:                } else if ((op & 0xfc00f83f) == 0x0000f809)
                    113:                        /*
                    114:                         * A jalr -- an indirect call.
                    115:                         */
                    116:                        addarc(parentp, &indirectchild, 0L);
                    117:        }
                    118: }