Annotation of src/usr.bin/gprof/i386.c, Revision 1.7
1.7 ! art 1: /* $OpenBSD: i386.c,v 1.6 2002/04/20 03:37:40 tholo Exp $ */
1.1 deraadt 2: /* $NetBSD: i386.c,v 1.5 1995/04/19 07:16:04 cgd Exp $ */
3:
1.6 tholo 4: /*-
5: * Copyright (c) 1996 SigmaSoft, Th. Lockert
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. The name of the author may not be used to endorse or promote products
17: * derived from this software without specific prior written permission
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29: */
30:
1.1 deraadt 31: #ifndef lint
1.7 ! art 32: static char rcsid[] = "$OpenBSD: i386.c,v 1.6 2002/04/20 03:37:40 tholo Exp $";
1.1 deraadt 33: #endif /* not lint */
34:
35: #include "gprof.h"
36:
1.7 ! art 37: #define iscall(off) ((*(u_char *)&textspace[off]) == 0xE8)
1.3 tholo 38:
1.4 mickey 39: void
1.1 deraadt 40: findcall( parentp , p_lowpc , p_highpc )
41: nltype *parentp;
42: unsigned long p_lowpc;
43: unsigned long p_highpc;
44: {
1.7 ! art 45: unsigned long pc;
1.3 tholo 46: long len;
47: nltype *childp;
48: unsigned long destpc;
1.7 ! art 49: int off;
1.3 tholo 50:
51: if (textspace == 0)
52: return;
53: if (p_lowpc < s_lowpc)
54: p_lowpc = s_lowpc;
55: if (p_highpc > s_highpc)
56: p_highpc = s_highpc;
57: # ifdef DEBUG
58: if ( debug & CALLDEBUG ) {
59: printf( "[findcall] %s: 0x%x to 0x%x\n" ,
60: parentp -> name , p_lowpc , p_highpc );
61: }
1.5 danh 62: # endif /* DEBUG */
1.7 ! art 63: for (pc = p_lowpc; pc < p_highpc; pc += len) {
! 64: off = pc - s_lowpc;
1.3 tholo 65: len = 1;
1.7 ! art 66: if (iscall(off)) {
! 67: destpc = *(u_long *)&textspace[off + 1] + off + 5;
1.3 tholo 68: # ifdef DEBUG
69: if ( debug & CALLDEBUG ) {
70: printf( "[findcall]\t0x%x:calls" , pc - textspace );
71: printf( "\tdestpc 0x%x" , destpc );
72: }
1.5 danh 73: # endif /* DEBUG */
1.3 tholo 74: if (destpc >= s_lowpc && destpc <= s_highpc) {
75: childp = nllookup(destpc);
76: # ifdef DEBUG
77: if ( debug & CALLDEBUG ) {
78: printf( " childp->name %s" , childp -> name );
79: printf( " childp->value 0x%x\n" ,
80: childp -> value );
81: }
1.5 danh 82: # endif /* DEBUG */
1.3 tholo 83: if (childp != NULL && childp->value == destpc) {
84: addarc(parentp, childp, 0L);
85: len += 4;
86: continue;
87: }
88: }
89: # ifdef DEBUG
90: if ( debug & CALLDEBUG ) {
91: printf( "\tbut it's a botch\n" );
92: }
1.5 danh 93: # endif /* DEBUG */
1.3 tholo 94: }
95: }
1.1 deraadt 96: }