Replaced fixed size array for hi16 relocations with a linked list.
[deliverable/binutils-gdb.git] / gprof / i386.c
CommitLineData
cc5697d7
SEF
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 */
5489fcc3
KR
19#include "gprof.h"
20#include "cg_arcs.h"
43870aec 21#include "corefile.h"
5489fcc3
KR
22#include "hist.h"
23#include "symtab.h"
cc5697d7 24
cc5697d7 25
cc5697d7 26int
c3de2a19 27DEFUN (i386_iscall, (ip), unsigned char *ip)
46f88c11 28{
c3de2a19 29 if (*ip == 0xe8)
cc5697d7
SEF
30 return 1;
31 return 0;
32}
33
5489fcc3
KR
34
35void
c3de2a19 36i386_find_call (parent, p_lowpc, p_highpc)
12516a37
KR
37 Sym *parent;
38 bfd_vma p_lowpc;
39 bfd_vma p_highpc;
cc5697d7 40{
12516a37 41 unsigned char *instructp;
12516a37 42 Sym *child;
c3de2a19 43 bfd_vma destpc, delta;
cc5697d7 44
12516a37
KR
45 if (core_text_space == 0)
46 {
47 return;
cc5697d7 48 }
12516a37
KR
49 if (p_lowpc < s_lowpc)
50 {
51 p_lowpc = s_lowpc;
cc5697d7 52 }
12516a37
KR
53 if (p_highpc > s_highpc)
54 {
55 p_highpc = s_highpc;
cc5697d7 56 }
12516a37 57 DBG (CALLDEBUG, printf ("[findcall] %s: 0x%lx to 0x%lx\n",
5489fcc3 58 parent->name, p_lowpc, p_highpc));
c3de2a19
ILT
59
60 delta = (bfd_vma) core_text_space - core_text_sect->vma;
61
62 for (instructp = (unsigned char *) (p_lowpc + delta);
63 instructp < (unsigned char *) (p_highpc + delta);
64 instructp ++)
12516a37 65 {
c3de2a19 66 if (i386_iscall (instructp))
12516a37
KR
67 {
68 DBG (CALLDEBUG,
c3de2a19
ILT
69 printf ("[findcall]\t0x%x:call",
70 instructp - (unsigned char *) delta));
cc5697d7 71 /*
12516a37
KR
72 * regular pc relative addressing
73 * check that this is the address of
74 * a function.
cc5697d7 75 */
c3de2a19
ILT
76
77 destpc = ((bfd_vma) bfd_get_32 (core_bfd, instructp + 1)
78 + (bfd_vma) instructp - (bfd_vma) delta + 5);
12516a37
KR
79 if (destpc >= s_lowpc && destpc <= s_highpc)
80 {
81 child = sym_lookup (&symtab, destpc);
c3de2a19 82 if (child && child->addr == destpc)
12516a37
KR
83 {
84 /*
85 * a hit
86 */
c3de2a19
ILT
87 DBG (CALLDEBUG,
88 printf ("\tdestpc 0x%lx (%s)\n", destpc, child->name));
8c73afb3 89 arc_add (parent, child, (unsigned long) 0);
c3de2a19 90 instructp += 4; /* call is a 5 byte instruction */
12516a37
KR
91 continue;
92 }
cc5697d7 93 }
cc5697d7 94 /*
12516a37 95 * else:
c3de2a19
ILT
96 * it looked like a callf, but it:
97 * a) wasn't actually a callf, or
98 * b) didn't point to a known function in the symtab, or
99 * c) something funny is going on.
cc5697d7 100 */
c3de2a19 101 DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
cc5697d7 102 }
12516a37
KR
103 }
104}
This page took 0.2378 seconds and 4 git commands to generate.