Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* |
0eee5820 | 2 | * Copyright (c) 1983, 2001 Regents of the University of California. |
252b5132 RH |
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" | |
6d9c411a AM |
20 | #include "search_list.h" |
21 | #include "source.h" | |
22 | #include "symtab.h" | |
252b5132 RH |
23 | #include "cg_arcs.h" |
24 | #include "corefile.h" | |
25 | #include "hist.h" | |
252b5132 | 26 | |
3b04e729 | 27 | static int i386_iscall PARAMS ((unsigned char *)); |
5789ecea | 28 | void i386_find_call PARAMS ((Sym *, bfd_vma, bfd_vma)); |
252b5132 | 29 | |
3b04e729 | 30 | static int |
5789ecea AM |
31 | i386_iscall (ip) |
32 | unsigned char *ip; | |
252b5132 RH |
33 | { |
34 | if (*ip == 0xe8) | |
35 | return 1; | |
36 | return 0; | |
37 | } | |
38 | ||
39 | ||
40 | void | |
41 | i386_find_call (parent, p_lowpc, p_highpc) | |
42 | Sym *parent; | |
43 | bfd_vma p_lowpc; | |
44 | bfd_vma p_highpc; | |
45 | { | |
46 | unsigned char *instructp; | |
47 | Sym *child; | |
6d9c411a | 48 | bfd_vma pc, destpc; |
252b5132 RH |
49 | |
50 | if (core_text_space == 0) | |
51 | { | |
52 | return; | |
53 | } | |
54 | if (p_lowpc < s_lowpc) | |
55 | { | |
56 | p_lowpc = s_lowpc; | |
57 | } | |
58 | if (p_highpc > s_highpc) | |
59 | { | |
60 | p_highpc = s_highpc; | |
61 | } | |
62 | DBG (CALLDEBUG, printf ("[findcall] %s: 0x%lx to 0x%lx\n", | |
fdcf7d43 ILT |
63 | parent->name, (unsigned long) p_lowpc, |
64 | (unsigned long) p_highpc)); | |
252b5132 | 65 | |
6d9c411a | 66 | for (pc = p_lowpc; pc < p_highpc; ++pc) |
252b5132 | 67 | { |
6d9c411a | 68 | instructp = (unsigned char *) core_text_space + pc - core_text_sect->vma; |
252b5132 RH |
69 | if (i386_iscall (instructp)) |
70 | { | |
71 | DBG (CALLDEBUG, | |
6d9c411a | 72 | printf ("[findcall]\t0x%lx:call", (unsigned long) pc)); |
252b5132 RH |
73 | /* |
74 | * regular pc relative addressing | |
0eee5820 | 75 | * check that this is the address of |
252b5132 RH |
76 | * a function. |
77 | */ | |
78 | ||
6d9c411a | 79 | destpc = bfd_get_32 (core_bfd, instructp + 1) + pc + 5; |
252b5132 RH |
80 | if (destpc >= s_lowpc && destpc <= s_highpc) |
81 | { | |
82 | child = sym_lookup (&symtab, destpc); | |
83 | if (child && child->addr == destpc) | |
84 | { | |
85 | /* | |
86 | * a hit | |
87 | */ | |
88 | DBG (CALLDEBUG, | |
fdcf7d43 ILT |
89 | printf ("\tdestpc 0x%lx (%s)\n", |
90 | (unsigned long) destpc, child->name)); | |
252b5132 RH |
91 | arc_add (parent, child, (unsigned long) 0); |
92 | instructp += 4; /* call is a 5 byte instruction */ | |
93 | continue; | |
94 | } | |
95 | } | |
96 | /* | |
97 | * else: | |
98 | * it looked like a callf, but it: | |
99 | * a) wasn't actually a callf, or | |
100 | * b) didn't point to a known function in the symtab, or | |
101 | * c) something funny is going on. | |
102 | */ | |
103 | DBG (CALLDEBUG, printf ("\tbut it's a botch\n")); | |
104 | } | |
105 | } | |
106 | } |