xref: /openbsd-src/gnu/usr.bin/binutils/gprof/symtab.h (revision c074d1c999f3e07019cd5e9a2f190b057ef3b935)
1b55d4692Sfgsch /* symtab.h
2b55d4692Sfgsch 
3*c074d1c9Sdrahn    Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
4b55d4692Sfgsch 
5b55d4692Sfgsch This file is part of GNU Binutils.
6b55d4692Sfgsch 
7b55d4692Sfgsch This program is free software; you can redistribute it and/or modify
8b55d4692Sfgsch it under the terms of the GNU General Public License as published by
9b55d4692Sfgsch the Free Software Foundation; either version 2 of the License, or
10b55d4692Sfgsch (at your option) any later version.
11b55d4692Sfgsch 
12b55d4692Sfgsch This program is distributed in the hope that it will be useful,
13b55d4692Sfgsch but WITHOUT ANY WARRANTY; without even the implied warranty of
14b55d4692Sfgsch MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15b55d4692Sfgsch GNU General Public License for more details.
16b55d4692Sfgsch 
17b55d4692Sfgsch You should have received a copy of the GNU General Public License
18b55d4692Sfgsch along with this program; if not, write to the Free Software
19b55d4692Sfgsch Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20b55d4692Sfgsch 
212159047fSniklas #ifndef symtab_h
222159047fSniklas #define symtab_h
232159047fSniklas 
24b55d4692Sfgsch /* For a profile to be intelligible to a human user, it is necessary
25b55d4692Sfgsch    to map code-addresses into source-code information.  Source-code
26b55d4692Sfgsch    information can be any combination of: (i) function-name, (ii)
27b55d4692Sfgsch    source file-name, and (iii) source line number.
28b55d4692Sfgsch 
29b55d4692Sfgsch    The symbol table is used to map addresses into source-code
30b55d4692Sfgsch    information.  */
312159047fSniklas 
32b305b0f1Sespie #define NBBS 10
33b305b0f1Sespie 
34b55d4692Sfgsch /* Symbol-entry.  For each external in the specified file we gather
35b55d4692Sfgsch    its address, the number of calls and compute its share of cpu time.  */
362159047fSniklas typedef struct sym
372159047fSniklas   {
38b55d4692Sfgsch     /* Common information:
392159047fSniklas 
40b55d4692Sfgsch        In the symbol-table, fields ADDR and FUNC_NAME are guaranteed
41b55d4692Sfgsch        to contain valid information.  FILE may be 0, if unknown and
42b55d4692Sfgsch        LINE_NUM maybe 0 if unknown.  */
432159047fSniklas 
44b55d4692Sfgsch     bfd_vma addr;		/* Address of entry point.  */
45b55d4692Sfgsch     bfd_vma end_addr;		/* End-address.  */
46b55d4692Sfgsch     const char *name;		/* Name of function this sym is from.  */
47b55d4692Sfgsch     Source_File *file;		/* Source file symbol comes from.  */
48b55d4692Sfgsch     int line_num;		/* Source line number.  */
49b55d4692Sfgsch     unsigned int		/* Boolean fields:  */
50b55d4692Sfgsch       is_func:1,		/*  Is this a function entry point?  */
51b55d4692Sfgsch       is_static:1,		/*  Is this a local (static) symbol?  */
52b55d4692Sfgsch       is_bb_head:1,		/*  Is this the head of a basic-blk?  */
53b55d4692Sfgsch       mapped:1,			/*  This symbol was mapped to another name.  */
54b55d4692Sfgsch       has_been_placed:1;	/*  Have we placed this symbol?  */
55b55d4692Sfgsch     unsigned long ncalls;	/* How many times executed  */
56b55d4692Sfgsch     int nuses;			/* How many times this symbol appears in
57b55d4692Sfgsch 				   a particular context.  */
58b55d4692Sfgsch     bfd_vma bb_addr[NBBS];	/* Address of basic-block start.  */
59b55d4692Sfgsch     unsigned long bb_calls[NBBS];/* How many times basic-block was called.  */
60b55d4692Sfgsch     struct sym *next;		/* For building chains of syms.  */
61b55d4692Sfgsch     struct sym *prev;		/* For building chains of syms.  */
62b55d4692Sfgsch 
63b55d4692Sfgsch     /* Profile specific information:  */
64b55d4692Sfgsch 
65b55d4692Sfgsch     /* Histogram specific information:  */
662159047fSniklas     struct
672159047fSniklas       {
68b55d4692Sfgsch 	double time;		/* (Weighted) ticks in this routine.  */
69b55d4692Sfgsch 	bfd_vma scaled_addr;	/* Scaled entry point.  */
702159047fSniklas       }
712159047fSniklas     hist;
722159047fSniklas 
73b55d4692Sfgsch     /* Call-graph specific information:  */
742159047fSniklas     struct
752159047fSniklas       {
76b55d4692Sfgsch 	unsigned long self_calls; /* How many calls to self.  */
77b55d4692Sfgsch 	double child_time;	/* Cumulative ticks in children.  */
78b55d4692Sfgsch 	int index;		/* Index in the graph list.  */
79b55d4692Sfgsch 	int top_order;		/* Graph call chain top-sort order.  */
80*c074d1c9Sdrahn 	bfd_boolean print_flag;	/* Should this be printed?  */
812159047fSniklas 	struct
822159047fSniklas 	  {
83b55d4692Sfgsch 	    double fract;	/* What % of time propagates.  */
84b55d4692Sfgsch 	    double self;	/* How much self time propagates.  */
85b55d4692Sfgsch 	    double child;	/* How much child time propagates.  */
862159047fSniklas 	  }
872159047fSniklas 	prop;
882159047fSniklas 	struct
892159047fSniklas 	  {
90b55d4692Sfgsch 	    int num;		/* Internal number of cycle on.  */
91b55d4692Sfgsch 	    struct sym *head;	/* Head of cycle.  */
92b55d4692Sfgsch 	    struct sym *next;	/* Next member of cycle.  */
932159047fSniklas 	  }
942159047fSniklas 	cyc;
95b55d4692Sfgsch 	struct arc *parents;	/* List of caller arcs.  */
96b55d4692Sfgsch 	struct arc *children;	/* List of callee arcs.  */
972159047fSniklas       }
982159047fSniklas     cg;
992159047fSniklas   }
1002159047fSniklas Sym;
1012159047fSniklas 
102b55d4692Sfgsch /* Symbol-tables are always assumed to be sorted
103b55d4692Sfgsch    in increasing order of addresses.  */
1042159047fSniklas typedef struct
1052159047fSniklas   {
106b55d4692Sfgsch     unsigned int len;		/* # of symbols in this table.  */
107b55d4692Sfgsch     Sym *base;			/* First element in symbol table.  */
108b55d4692Sfgsch     Sym *limit;			/* Limit = base + len.  */
1092159047fSniklas   }
1102159047fSniklas Sym_Table;
1112159047fSniklas 
112b55d4692Sfgsch extern Sym_Table symtab;	/* The symbol table.  */
1132159047fSniklas 
114b55d4692Sfgsch extern void sym_init        PARAMS ((Sym *));
115b55d4692Sfgsch extern void symtab_finalize PARAMS ((Sym_Table *));
116*c074d1c9Sdrahn #ifdef DEBUG
117*c074d1c9Sdrahn extern Sym *dbg_sym_lookup  PARAMS ((Sym_Table *, bfd_vma));
118*c074d1c9Sdrahn #endif
119b55d4692Sfgsch extern Sym *sym_lookup      PARAMS ((Sym_Table *, bfd_vma));
1206a4c786fSespie extern void find_call       PARAMS ((Sym *, bfd_vma, bfd_vma));
1216a4c786fSespie 
1222159047fSniklas #endif /* symtab_h */
123