Lots of changes from David Mosberger-Tang; see ChangeLog and NOTES for details:
[binutils-gdb.git] / gprof / i386.c
1 /*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that: (1) source distributions retain this entire copyright
7 * notice and comment, and (2) distributions including binaries display
8 * the following acknowledgement: ``This product includes software
9 * developed by the University of California, Berkeley and its contributors''
10 * in the documentation or other materials provided with the distribution
11 * and in all advertising materials mentioning features or use of this
12 * software. Neither the name of the University nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 */
19 #include "gprof.h"
20 #include "cg_arcs.h"
21 #include "core.h"
22 #include "hist.h"
23 #include "symtab.h"
24
25
26 int
27 DEFUN(iscall, (ip), unsigned char *ip)
28 {
29 if (*ip == 0xeb || *ip == 0x9a)
30 return 1;
31 return 0;
32 }
33
34
35 void
36 find_call(parent, p_lowpc, p_highpc)
37 Sym *parent;
38 bfd_vma p_lowpc;
39 bfd_vma p_highpc;
40 {
41 unsigned char *instructp;
42 long length;
43 Sym *child;
44 bfd_vma destpc;
45
46 if (core_text_space == 0) {
47 return;
48 }
49 if (p_lowpc < s_lowpc) {
50 p_lowpc = s_lowpc;
51 }
52 if (p_highpc > s_highpc) {
53 p_highpc = s_highpc;
54 }
55 DBG(CALLDEBUG, printf("[findcall] %s: 0x%lx to 0x%lx\n",
56 parent->name, p_lowpc, p_highpc));
57 for ( instructp = (unsigned char*) core_text_space + p_lowpc ;
58 instructp < (unsigned char*) core_text_space + p_highpc ;
59 instructp += length) {
60 length = 1;
61 if (iscall (instructp)) {
62 DBG(CALLDEBUG,
63 printf("[findcall]\t0x%x:callf",
64 instructp - (unsigned char*) core_text_space));
65 length = 4;
66 /*
67 * regular pc relative addressing
68 * check that this is the address of
69 * a function.
70 */
71 destpc = ((bfd_vma)instructp + 5 - (bfd_vma) core_text_space);
72 if (destpc >= s_lowpc && destpc <= s_highpc) {
73 child = sym_lookup(&symtab, destpc);
74 DBG(CALLDEBUG,
75 printf("[findcall]\tdestpc 0x%lx", destpc);
76 printf(" child->name %s", child->name);
77 printf(" child->addr 0x%lx\n", child->addr);
78 );
79 if (child->addr == destpc) {
80 /*
81 * a hit
82 */
83 arc_add(parent, child, (long) 0);
84 length += 4; /* constant lengths */
85 continue;
86 }
87 goto botched;
88 }
89 /*
90 * else:
91 * it looked like a callf,
92 * but it wasn't to anywhere.
93 */
94 botched:
95 /*
96 * something funny going on.
97 */
98 DBG(CALLDEBUG, printf("[findcall]\tbut it's a botch\n"));
99 length = 1;
100 continue;
101 }
102 }
103 }