Commit | Line | Data |
---|---|---|
5ec4a8f3 NC |
1 | /* |
2 | * Copyright (c) 1983, 1993, 1998, 2001, 2002 | |
3 | * The Regents of the University of California. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. Neither the name of the University nor the names of its contributors | |
14 | * may be used to endorse or promote products derived from this software | |
15 | * without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
27 | * SUCH DAMAGE. | |
28 | */ | |
0461a601 | 29 | |
252b5132 | 30 | #include "gprof.h" |
ecba005f | 31 | #include "libiberty.h" |
066c2a57 | 32 | #include "bfdver.h" |
6d9c411a AM |
33 | #include "search_list.h" |
34 | #include "source.h" | |
35 | #include "symtab.h" | |
252b5132 RH |
36 | #include "basic_blocks.h" |
37 | #include "call_graph.h" | |
38 | #include "cg_arcs.h" | |
39 | #include "cg_print.h" | |
40 | #include "corefile.h" | |
41 | #include "gmon_io.h" | |
42 | #include "hertz.h" | |
43 | #include "hist.h" | |
252b5132 | 44 | #include "sym_ids.h" |
28c309a2 | 45 | #include "demangle.h" |
82fe033f | 46 | #include "getopt.h" |
252b5132 | 47 | |
3e8f6abf | 48 | static void usage (FILE *, int) ATTRIBUTE_NORETURN; |
1355568a | 49 | |
0e27a8f6 NC |
50 | const char * whoami; |
51 | const char * function_mapping_file; | |
52 | static const char * external_symbol_table; | |
53 | const char * a_out_name = A_OUTNAME; | |
252b5132 RH |
54 | long hz = HZ_WRONG; |
55 | ||
56 | /* | |
57 | * Default options values: | |
58 | */ | |
59 | int debug_level = 0; | |
60 | int output_style = 0; | |
61 | int output_width = 80; | |
b34976b6 AM |
62 | bfd_boolean bsd_style_output = FALSE; |
63 | bfd_boolean demangle = TRUE; | |
b34976b6 AM |
64 | bfd_boolean ignore_direct_calls = FALSE; |
65 | bfd_boolean ignore_static_funcs = FALSE; | |
66 | bfd_boolean ignore_zeros = TRUE; | |
67 | bfd_boolean line_granularity = FALSE; | |
68 | bfd_boolean print_descriptions = TRUE; | |
69 | bfd_boolean print_path = FALSE; | |
70 | bfd_boolean ignore_non_functions = FALSE; | |
630b0510 | 71 | bfd_boolean inline_file_names = FALSE; |
252b5132 RH |
72 | File_Format file_format = FF_AUTO; |
73 | ||
b34976b6 | 74 | bfd_boolean first_output = TRUE; |
252b5132 RH |
75 | |
76 | char copyright[] = | |
ff096a7c AO |
77 | "@(#) Copyright (c) 1983 Regents of the University of California.\n\ |
78 | All rights reserved.\n"; | |
252b5132 RH |
79 | |
80 | static char *gmon_name = GMONNAME; /* profile filename */ | |
81 | ||
252b5132 RH |
82 | /* |
83 | * Functions that get excluded by default: | |
84 | */ | |
85 | static char *default_excluded_list[] = | |
86 | { | |
87 | "_gprof_mcount", "mcount", "_mcount", "__mcount", "__mcount_internal", | |
88 | "__mcleanup", | |
252b5132 RH |
89 | 0 |
90 | }; | |
91 | ||
92 | /* Codes used for the long options with no short synonyms. 150 isn't | |
93 | special; it's just an arbitrary non-ASCII char value. */ | |
94 | ||
630b0510 CH |
95 | #define OPTION_DEMANGLE (150) |
96 | #define OPTION_NO_DEMANGLE (OPTION_DEMANGLE + 1) | |
97 | #define OPTION_INLINE_FILE_NAMES (OPTION_DEMANGLE + 2) | |
252b5132 RH |
98 | |
99 | static struct option long_options[] = | |
100 | { | |
101 | {"line", no_argument, 0, 'l'}, | |
102 | {"no-static", no_argument, 0, 'a'}, | |
103 | {"ignore-non-functions", no_argument, 0, 'D'}, | |
0e27a8f6 | 104 | {"external-symbol-table", required_argument, 0, 'S'}, |
252b5132 RH |
105 | |
106 | /* output styles: */ | |
107 | ||
108 | {"annotated-source", optional_argument, 0, 'A'}, | |
109 | {"no-annotated-source", optional_argument, 0, 'J'}, | |
110 | {"flat-profile", optional_argument, 0, 'p'}, | |
111 | {"no-flat-profile", optional_argument, 0, 'P'}, | |
112 | {"graph", optional_argument, 0, 'q'}, | |
113 | {"no-graph", optional_argument, 0, 'Q'}, | |
114 | {"exec-counts", optional_argument, 0, 'C'}, | |
115 | {"no-exec-counts", optional_argument, 0, 'Z'}, | |
116 | {"function-ordering", no_argument, 0, 'r'}, | |
117 | {"file-ordering", required_argument, 0, 'R'}, | |
118 | {"file-info", no_argument, 0, 'i'}, | |
119 | {"sum", no_argument, 0, 's'}, | |
120 | ||
121 | /* various options to affect output: */ | |
122 | ||
123 | {"all-lines", no_argument, 0, 'x'}, | |
28c309a2 | 124 | {"demangle", optional_argument, 0, OPTION_DEMANGLE}, |
252b5132 RH |
125 | {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLE}, |
126 | {"directory-path", required_argument, 0, 'I'}, | |
127 | {"display-unused-functions", no_argument, 0, 'z'}, | |
630b0510 | 128 | {"inline-file-names", no_argument, 0, OPTION_INLINE_FILE_NAMES}, |
252b5132 RH |
129 | {"min-count", required_argument, 0, 'm'}, |
130 | {"print-path", no_argument, 0, 'L'}, | |
131 | {"separate-files", no_argument, 0, 'y'}, | |
132 | {"static-call-graph", no_argument, 0, 'c'}, | |
133 | {"table-length", required_argument, 0, 't'}, | |
134 | {"time", required_argument, 0, 'n'}, | |
135 | {"no-time", required_argument, 0, 'N'}, | |
136 | {"width", required_argument, 0, 'w'}, | |
137 | /* | |
138 | * These are for backwards-compatibility only. Their functionality | |
139 | * is provided by the output style options already: | |
140 | */ | |
141 | {"", required_argument, 0, 'e'}, | |
142 | {"", required_argument, 0, 'E'}, | |
143 | {"", required_argument, 0, 'f'}, | |
144 | {"", required_argument, 0, 'F'}, | |
145 | {"", required_argument, 0, 'k'}, | |
146 | ||
147 | /* miscellaneous: */ | |
148 | ||
149 | {"brief", no_argument, 0, 'b'}, | |
150 | {"debug", optional_argument, 0, 'd'}, | |
151 | {"help", no_argument, 0, 'h'}, | |
152 | {"file-format", required_argument, 0, 'O'}, | |
153 | {"traditional", no_argument, 0, 'T'}, | |
154 | {"version", no_argument, 0, 'v'}, | |
155 | {0, no_argument, 0, 0} | |
156 | }; | |
157 | ||
158 | ||
159 | static void | |
3e8f6abf | 160 | usage (FILE *stream, int status) |
252b5132 RH |
161 | { |
162 | fprintf (stream, _("\ | |
0e27a8f6 | 163 | Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqSQZ][name]] [-I dirs]\n\ |
252b5132 RH |
164 | [-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\ |
165 | [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\ | |
166 | [--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\ | |
167 | [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]\n\ | |
630b0510 | 168 | [--function-ordering] [--file-ordering] [--inline-file-names]\n\ |
252b5132 RH |
169 | [--directory-path=dirs] [--display-unused-functions]\n\ |
170 | [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]\n\ | |
171 | [--no-static] [--print-path] [--separate-files]\n\ | |
172 | [--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\ | |
173 | [--version] [--width=n] [--ignore-non-functions]\n\ | |
0e27a8f6 | 174 | [--demangle[=STYLE]] [--no-demangle] [--external-symbol-table=name] [@FILE]\n\ |
252b5132 RH |
175 | [image-file] [profile-file...]\n"), |
176 | whoami); | |
92f01d61 | 177 | if (REPORT_BUGS_TO[0] && status == 0) |
8ad3436c | 178 | fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO); |
252b5132 RH |
179 | done (status); |
180 | } | |
181 | ||
182 | ||
183 | int | |
3e8f6abf | 184 | main (int argc, char **argv) |
252b5132 RH |
185 | { |
186 | char **sp, *str; | |
187 | Sym **cg = 0; | |
188 | int ch, user_specified = 0; | |
189 | ||
190 | #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) | |
191 | setlocale (LC_MESSAGES, ""); | |
3882b010 L |
192 | #endif |
193 | #if defined (HAVE_SETLOCALE) | |
194 | setlocale (LC_CTYPE, ""); | |
252b5132 | 195 | #endif |
a70c2403 | 196 | #ifdef ENABLE_NLS |
252b5132 RH |
197 | bindtextdomain (PACKAGE, LOCALEDIR); |
198 | textdomain (PACKAGE); | |
a70c2403 | 199 | #endif |
252b5132 RH |
200 | |
201 | whoami = argv[0]; | |
202 | xmalloc_set_program_name (whoami); | |
203 | ||
869b9d07 MM |
204 | expandargv (&argc, &argv); |
205 | ||
252b5132 | 206 | while ((ch = getopt_long (argc, argv, |
0e27a8f6 | 207 | "aA::bBcC::d::De:E:f:F:hiI:J::k:lLm:n:N:O:p::P::q::Q::rR:sS:t:Tvw:xyzZ::", |
252b5132 RH |
208 | long_options, 0)) |
209 | != EOF) | |
210 | { | |
211 | switch (ch) | |
212 | { | |
213 | case 'a': | |
b34976b6 | 214 | ignore_static_funcs = TRUE; |
252b5132 RH |
215 | break; |
216 | case 'A': | |
217 | if (optarg) | |
218 | { | |
219 | sym_id_add (optarg, INCL_ANNO); | |
220 | } | |
221 | output_style |= STYLE_ANNOTATED_SOURCE; | |
222 | user_specified |= STYLE_ANNOTATED_SOURCE; | |
223 | break; | |
224 | case 'b': | |
b34976b6 | 225 | print_descriptions = FALSE; |
252b5132 RH |
226 | break; |
227 | case 'B': | |
228 | output_style |= STYLE_CALL_GRAPH; | |
229 | user_specified |= STYLE_CALL_GRAPH; | |
230 | break; | |
231 | case 'c': | |
b34976b6 | 232 | ignore_direct_calls = TRUE; |
252b5132 RH |
233 | break; |
234 | case 'C': | |
235 | if (optarg) | |
236 | { | |
237 | sym_id_add (optarg, INCL_EXEC); | |
238 | } | |
239 | output_style |= STYLE_EXEC_COUNTS; | |
240 | user_specified |= STYLE_EXEC_COUNTS; | |
241 | break; | |
242 | case 'd': | |
243 | if (optarg) | |
244 | { | |
245 | debug_level |= atoi (optarg); | |
246 | debug_level |= ANYDEBUG; | |
247 | } | |
248 | else | |
249 | { | |
250 | debug_level = ~0; | |
251 | } | |
252 | DBG (ANYDEBUG, printf ("[main] debug-level=0x%x\n", debug_level)); | |
253 | #ifndef DEBUG | |
254 | printf (_("%s: debugging not supported; -d ignored\n"), whoami); | |
255 | #endif /* DEBUG */ | |
256 | break; | |
257 | case 'D': | |
b34976b6 | 258 | ignore_non_functions = TRUE; |
252b5132 RH |
259 | break; |
260 | case 'E': | |
261 | sym_id_add (optarg, EXCL_TIME); | |
1a0670f3 | 262 | /* Fall through. */ |
252b5132 RH |
263 | case 'e': |
264 | sym_id_add (optarg, EXCL_GRAPH); | |
265 | break; | |
266 | case 'F': | |
267 | sym_id_add (optarg, INCL_TIME); | |
1a0670f3 | 268 | /* Fall through. */ |
252b5132 RH |
269 | case 'f': |
270 | sym_id_add (optarg, INCL_GRAPH); | |
271 | break; | |
272 | case 'g': | |
273 | sym_id_add (optarg, EXCL_FLAT); | |
274 | break; | |
275 | case 'G': | |
276 | sym_id_add (optarg, INCL_FLAT); | |
277 | break; | |
278 | case 'h': | |
279 | usage (stdout, 0); | |
280 | case 'i': | |
281 | output_style |= STYLE_GMON_INFO; | |
282 | user_specified |= STYLE_GMON_INFO; | |
283 | break; | |
284 | case 'I': | |
285 | search_list_append (&src_search_list, optarg); | |
286 | break; | |
287 | case 'J': | |
288 | if (optarg) | |
289 | { | |
290 | sym_id_add (optarg, EXCL_ANNO); | |
291 | output_style |= STYLE_ANNOTATED_SOURCE; | |
292 | } | |
293 | else | |
294 | { | |
295 | output_style &= ~STYLE_ANNOTATED_SOURCE; | |
296 | } | |
297 | user_specified |= STYLE_ANNOTATED_SOURCE; | |
298 | break; | |
299 | case 'k': | |
300 | sym_id_add (optarg, EXCL_ARCS); | |
301 | break; | |
302 | case 'l': | |
b34976b6 | 303 | line_granularity = TRUE; |
252b5132 RH |
304 | break; |
305 | case 'L': | |
b34976b6 | 306 | print_path = TRUE; |
252b5132 RH |
307 | break; |
308 | case 'm': | |
309 | bb_min_calls = (unsigned long) strtoul (optarg, (char **) NULL, 10); | |
310 | break; | |
311 | case 'n': | |
312 | sym_id_add (optarg, INCL_TIME); | |
313 | break; | |
314 | case 'N': | |
315 | sym_id_add (optarg, EXCL_TIME); | |
316 | break; | |
317 | case 'O': | |
318 | switch (optarg[0]) | |
319 | { | |
320 | case 'a': | |
321 | file_format = FF_AUTO; | |
322 | break; | |
323 | case 'm': | |
324 | file_format = FF_MAGIC; | |
325 | break; | |
326 | case 'b': | |
327 | file_format = FF_BSD; | |
328 | break; | |
329 | case '4': | |
330 | file_format = FF_BSD44; | |
331 | break; | |
332 | case 'p': | |
333 | file_format = FF_PROF; | |
334 | break; | |
335 | default: | |
336 | fprintf (stderr, _("%s: unknown file format %s\n"), | |
337 | optarg, whoami); | |
338 | done (1); | |
339 | } | |
340 | break; | |
341 | case 'p': | |
342 | if (optarg) | |
343 | { | |
344 | sym_id_add (optarg, INCL_FLAT); | |
345 | } | |
346 | output_style |= STYLE_FLAT_PROFILE; | |
347 | user_specified |= STYLE_FLAT_PROFILE; | |
348 | break; | |
349 | case 'P': | |
350 | if (optarg) | |
351 | { | |
352 | sym_id_add (optarg, EXCL_FLAT); | |
353 | output_style |= STYLE_FLAT_PROFILE; | |
354 | } | |
355 | else | |
356 | { | |
357 | output_style &= ~STYLE_FLAT_PROFILE; | |
358 | } | |
359 | user_specified |= STYLE_FLAT_PROFILE; | |
360 | break; | |
361 | case 'q': | |
362 | if (optarg) | |
363 | { | |
364 | if (strchr (optarg, '/')) | |
365 | { | |
366 | sym_id_add (optarg, INCL_ARCS); | |
367 | } | |
368 | else | |
369 | { | |
370 | sym_id_add (optarg, INCL_GRAPH); | |
371 | } | |
372 | } | |
373 | output_style |= STYLE_CALL_GRAPH; | |
374 | user_specified |= STYLE_CALL_GRAPH; | |
375 | break; | |
376 | case 'r': | |
377 | output_style |= STYLE_FUNCTION_ORDER; | |
378 | user_specified |= STYLE_FUNCTION_ORDER; | |
379 | break; | |
380 | case 'R': | |
381 | output_style |= STYLE_FILE_ORDER; | |
382 | user_specified |= STYLE_FILE_ORDER; | |
383 | function_mapping_file = optarg; | |
384 | break; | |
385 | case 'Q': | |
386 | if (optarg) | |
387 | { | |
388 | if (strchr (optarg, '/')) | |
389 | { | |
390 | sym_id_add (optarg, EXCL_ARCS); | |
391 | } | |
392 | else | |
393 | { | |
394 | sym_id_add (optarg, EXCL_GRAPH); | |
395 | } | |
396 | output_style |= STYLE_CALL_GRAPH; | |
397 | } | |
398 | else | |
399 | { | |
400 | output_style &= ~STYLE_CALL_GRAPH; | |
401 | } | |
402 | user_specified |= STYLE_CALL_GRAPH; | |
403 | break; | |
404 | case 's': | |
405 | output_style |= STYLE_SUMMARY_FILE; | |
406 | user_specified |= STYLE_SUMMARY_FILE; | |
407 | break; | |
0e27a8f6 NC |
408 | case 'S': |
409 | external_symbol_table = optarg; | |
410 | DBG (AOUTDEBUG, printf ("external-symbol-table: %s\n", optarg)); | |
411 | break; | |
252b5132 RH |
412 | case 't': |
413 | bb_table_length = atoi (optarg); | |
414 | if (bb_table_length < 0) | |
415 | { | |
416 | bb_table_length = 0; | |
417 | } | |
418 | break; | |
419 | case 'T': | |
b34976b6 | 420 | bsd_style_output = TRUE; |
252b5132 RH |
421 | break; |
422 | case 'v': | |
423 | /* This output is intended to follow the GNU standards document. */ | |
066c2a57 | 424 | printf (_("GNU gprof %s\n"), BFD_VERSION_STRING); |
252b5132 RH |
425 | printf (_("Based on BSD gprof, copyright 1983 Regents of the University of California.\n")); |
426 | printf (_("\ | |
427 | This program is free software. This program has absolutely no warranty.\n")); | |
428 | done (0); | |
429 | case 'w': | |
430 | output_width = atoi (optarg); | |
431 | if (output_width < 1) | |
432 | { | |
433 | output_width = 1; | |
434 | } | |
435 | break; | |
436 | case 'x': | |
b34976b6 | 437 | bb_annotate_all_lines = TRUE; |
252b5132 RH |
438 | break; |
439 | case 'y': | |
b34976b6 | 440 | create_annotation_files = TRUE; |
252b5132 RH |
441 | break; |
442 | case 'z': | |
b34976b6 | 443 | ignore_zeros = FALSE; |
252b5132 RH |
444 | break; |
445 | case 'Z': | |
446 | if (optarg) | |
447 | { | |
448 | sym_id_add (optarg, EXCL_EXEC); | |
449 | output_style |= STYLE_EXEC_COUNTS; | |
450 | } | |
451 | else | |
452 | { | |
453 | output_style &= ~STYLE_EXEC_COUNTS; | |
454 | } | |
a0389de0 | 455 | user_specified |= STYLE_EXEC_COUNTS; |
252b5132 RH |
456 | break; |
457 | case OPTION_DEMANGLE: | |
b34976b6 | 458 | demangle = TRUE; |
28c309a2 NC |
459 | if (optarg != NULL) |
460 | { | |
461 | enum demangling_styles style; | |
0eee5820 | 462 | |
28c309a2 | 463 | style = cplus_demangle_name_to_style (optarg); |
0eee5820 | 464 | if (style == unknown_demangling) |
28c309a2 NC |
465 | { |
466 | fprintf (stderr, | |
467 | _("%s: unknown demangling style `%s'\n"), | |
468 | whoami, optarg); | |
469 | xexit (1); | |
470 | } | |
0eee5820 | 471 | |
28c309a2 | 472 | cplus_demangle_set_style (style); |
0eee5820 | 473 | } |
252b5132 RH |
474 | break; |
475 | case OPTION_NO_DEMANGLE: | |
b34976b6 | 476 | demangle = FALSE; |
252b5132 | 477 | break; |
630b0510 CH |
478 | case OPTION_INLINE_FILE_NAMES: |
479 | inline_file_names = TRUE; | |
480 | break; | |
252b5132 RH |
481 | default: |
482 | usage (stderr, 1); | |
483 | } | |
484 | } | |
485 | ||
486 | /* Don't allow both ordering options, they modify the arc data in-place. */ | |
487 | if ((user_specified & STYLE_FUNCTION_ORDER) | |
488 | && (user_specified & STYLE_FILE_ORDER)) | |
489 | { | |
490 | fprintf (stderr,_("\ | |
491 | %s: Only one of --function-ordering and --file-ordering may be specified.\n"), | |
492 | whoami); | |
493 | done (1); | |
494 | } | |
495 | ||
37b1bfcd BE |
496 | /* --sum implies --line, otherwise we'd lose basic block counts in |
497 | gmon.sum */ | |
252b5132 | 498 | if (output_style & STYLE_SUMMARY_FILE) |
13f178c0 | 499 | line_granularity = 1; |
252b5132 RH |
500 | |
501 | /* append value of GPROF_PATH to source search list if set: */ | |
502 | str = (char *) getenv ("GPROF_PATH"); | |
503 | if (str) | |
13f178c0 | 504 | search_list_append (&src_search_list, str); |
252b5132 RH |
505 | |
506 | if (optind < argc) | |
13f178c0 BE |
507 | a_out_name = argv[optind++]; |
508 | ||
252b5132 | 509 | if (optind < argc) |
13f178c0 | 510 | gmon_name = argv[optind++]; |
252b5132 | 511 | |
13f178c0 | 512 | /* Turn off default functions. */ |
252b5132 RH |
513 | for (sp = &default_excluded_list[0]; *sp; sp++) |
514 | { | |
515 | sym_id_add (*sp, EXCL_TIME); | |
516 | sym_id_add (*sp, EXCL_GRAPH); | |
252b5132 | 517 | sym_id_add (*sp, EXCL_FLAT); |
252b5132 RH |
518 | } |
519 | ||
37b1bfcd | 520 | /* Read symbol table from core file. */ |
252b5132 RH |
521 | core_init (a_out_name); |
522 | ||
37b1bfcd BE |
523 | /* If we should ignore direct function calls, we need to load to |
524 | core's text-space. */ | |
252b5132 | 525 | if (ignore_direct_calls) |
37b1bfcd | 526 | core_get_text_space (core_bfd); |
252b5132 | 527 | |
37b1bfcd | 528 | /* Create symbols from core image. */ |
0e27a8f6 NC |
529 | if (external_symbol_table) |
530 | core_create_syms_from (external_symbol_table); | |
531 | else if (line_granularity) | |
37b1bfcd | 532 | core_create_line_syms (); |
252b5132 | 533 | else |
37b1bfcd | 534 | core_create_function_syms (); |
252b5132 | 535 | |
37b1bfcd | 536 | /* Translate sym specs into syms. */ |
252b5132 RH |
537 | sym_id_parse (); |
538 | ||
539 | if (file_format == FF_PROF) | |
540 | { | |
252b5132 RH |
541 | fprintf (stderr, |
542 | _("%s: sorry, file format `prof' is not yet supported\n"), | |
543 | whoami); | |
544 | done (1); | |
252b5132 RH |
545 | } |
546 | else | |
547 | { | |
37b1bfcd | 548 | /* Get information about gmon.out file(s). */ |
252b5132 RH |
549 | do |
550 | { | |
551 | gmon_out_read (gmon_name); | |
552 | if (optind < argc) | |
13f178c0 | 553 | gmon_name = argv[optind]; |
252b5132 RH |
554 | } |
555 | while (optind++ < argc); | |
556 | } | |
557 | ||
13f178c0 BE |
558 | /* If user did not specify output style, try to guess something |
559 | reasonable. */ | |
252b5132 RH |
560 | if (output_style == 0) |
561 | { | |
562 | if (gmon_input & (INPUT_HISTOGRAM | INPUT_CALL_GRAPH)) | |
fe541ea9 JW |
563 | { |
564 | if (gmon_input & INPUT_HISTOGRAM) | |
565 | output_style |= STYLE_FLAT_PROFILE; | |
566 | if (gmon_input & INPUT_CALL_GRAPH) | |
567 | output_style |= STYLE_CALL_GRAPH; | |
568 | } | |
252b5132 | 569 | else |
37b1bfcd BE |
570 | output_style = STYLE_EXEC_COUNTS; |
571 | ||
252b5132 RH |
572 | output_style &= ~user_specified; |
573 | } | |
574 | ||
37b1bfcd BE |
575 | /* Dump a gmon.sum file if requested (before any other |
576 | processing!) */ | |
252b5132 RH |
577 | if (output_style & STYLE_SUMMARY_FILE) |
578 | { | |
579 | gmon_out_write (GMONSUM); | |
580 | } | |
581 | ||
582 | if (gmon_input & INPUT_HISTOGRAM) | |
583 | { | |
584 | hist_assign_samples (); | |
585 | } | |
586 | ||
587 | if (gmon_input & INPUT_CALL_GRAPH) | |
588 | { | |
589 | cg = cg_assemble (); | |
590 | } | |
591 | ||
37b1bfcd | 592 | /* Do some simple sanity checks. */ |
252b5132 RH |
593 | if ((output_style & STYLE_FLAT_PROFILE) |
594 | && !(gmon_input & INPUT_HISTOGRAM)) | |
595 | { | |
596 | fprintf (stderr, _("%s: gmon.out file is missing histogram\n"), whoami); | |
597 | done (1); | |
598 | } | |
599 | ||
600 | if ((output_style & STYLE_CALL_GRAPH) && !(gmon_input & INPUT_CALL_GRAPH)) | |
601 | { | |
602 | fprintf (stderr, | |
603 | _("%s: gmon.out file is missing call-graph data\n"), whoami); | |
604 | done (1); | |
605 | } | |
606 | ||
13f178c0 | 607 | /* Output whatever user whishes to see. */ |
252b5132 RH |
608 | if (cg && (output_style & STYLE_CALL_GRAPH) && bsd_style_output) |
609 | { | |
13f178c0 BE |
610 | /* Print the dynamic profile. */ |
611 | cg_print (cg); | |
252b5132 RH |
612 | } |
613 | ||
614 | if (output_style & STYLE_FLAT_PROFILE) | |
615 | { | |
13f178c0 | 616 | /* Print the flat profile. */ |
f3445b37 | 617 | hist_print (); |
252b5132 RH |
618 | } |
619 | ||
620 | if (cg && (output_style & STYLE_CALL_GRAPH)) | |
621 | { | |
622 | if (!bsd_style_output) | |
623 | { | |
13f178c0 | 624 | /* Print the dynamic profile. */ |
f3445b37 | 625 | cg_print (cg); |
252b5132 RH |
626 | } |
627 | cg_print_index (); | |
628 | } | |
629 | ||
630 | if (output_style & STYLE_EXEC_COUNTS) | |
13f178c0 | 631 | print_exec_counts (); |
f3445b37 | 632 | |
252b5132 | 633 | if (output_style & STYLE_ANNOTATED_SOURCE) |
13f178c0 | 634 | print_annotated_source (); |
f3445b37 | 635 | |
252b5132 | 636 | if (output_style & STYLE_FUNCTION_ORDER) |
13f178c0 | 637 | cg_print_function_ordering (); |
f3445b37 | 638 | |
252b5132 | 639 | if (output_style & STYLE_FILE_ORDER) |
13f178c0 BE |
640 | cg_print_file_ordering (); |
641 | ||
252b5132 RH |
642 | return 0; |
643 | } | |
644 | ||
645 | void | |
3e8f6abf | 646 | done (int status) |
252b5132 RH |
647 | { |
648 | exit (status); | |
649 | } |