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; | |
faa7a260 AM |
62 | bool bsd_style_output = false; |
63 | bool demangle = true; | |
64 | bool ignore_direct_calls = false; | |
65 | bool ignore_static_funcs = false; | |
66 | bool ignore_zeros = true; | |
67 | bool line_granularity = false; | |
68 | bool print_descriptions = true; | |
69 | bool print_path = false; | |
70 | bool ignore_non_functions = false; | |
71 | bool inline_file_names = false; | |
252b5132 RH |
72 | File_Format file_format = FF_AUTO; |
73 | ||
faa7a260 | 74 | bool 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, _("\ | |
efa97609 | 163 | Usage: %s [-[abcDhilLrsTvwxyz]] [-[ACeEfFJnNOpPqQRStZ][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 | ||
5d4d26d1 | 190 | #ifdef HAVE_LC_MESSAGES |
252b5132 | 191 | setlocale (LC_MESSAGES, ""); |
3882b010 | 192 | #endif |
3882b010 | 193 | setlocale (LC_CTYPE, ""); |
a70c2403 | 194 | #ifdef ENABLE_NLS |
252b5132 RH |
195 | bindtextdomain (PACKAGE, LOCALEDIR); |
196 | textdomain (PACKAGE); | |
a70c2403 | 197 | #endif |
252b5132 RH |
198 | |
199 | whoami = argv[0]; | |
200 | xmalloc_set_program_name (whoami); | |
201 | ||
869b9d07 MM |
202 | expandargv (&argc, &argv); |
203 | ||
252b5132 | 204 | while ((ch = getopt_long (argc, argv, |
0e27a8f6 | 205 | "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 |
206 | long_options, 0)) |
207 | != EOF) | |
208 | { | |
209 | switch (ch) | |
210 | { | |
211 | case 'a': | |
faa7a260 | 212 | ignore_static_funcs = true; |
252b5132 RH |
213 | break; |
214 | case 'A': | |
215 | if (optarg) | |
216 | { | |
217 | sym_id_add (optarg, INCL_ANNO); | |
218 | } | |
219 | output_style |= STYLE_ANNOTATED_SOURCE; | |
220 | user_specified |= STYLE_ANNOTATED_SOURCE; | |
221 | break; | |
222 | case 'b': | |
faa7a260 | 223 | print_descriptions = false; |
252b5132 RH |
224 | break; |
225 | case 'B': | |
226 | output_style |= STYLE_CALL_GRAPH; | |
227 | user_specified |= STYLE_CALL_GRAPH; | |
228 | break; | |
229 | case 'c': | |
faa7a260 | 230 | ignore_direct_calls = true; |
252b5132 RH |
231 | break; |
232 | case 'C': | |
233 | if (optarg) | |
234 | { | |
235 | sym_id_add (optarg, INCL_EXEC); | |
236 | } | |
237 | output_style |= STYLE_EXEC_COUNTS; | |
238 | user_specified |= STYLE_EXEC_COUNTS; | |
239 | break; | |
240 | case 'd': | |
241 | if (optarg) | |
242 | { | |
243 | debug_level |= atoi (optarg); | |
244 | debug_level |= ANYDEBUG; | |
245 | } | |
246 | else | |
247 | { | |
248 | debug_level = ~0; | |
249 | } | |
250 | DBG (ANYDEBUG, printf ("[main] debug-level=0x%x\n", debug_level)); | |
251 | #ifndef DEBUG | |
252 | printf (_("%s: debugging not supported; -d ignored\n"), whoami); | |
253 | #endif /* DEBUG */ | |
254 | break; | |
255 | case 'D': | |
faa7a260 | 256 | ignore_non_functions = true; |
252b5132 RH |
257 | break; |
258 | case 'E': | |
259 | sym_id_add (optarg, EXCL_TIME); | |
1a0670f3 | 260 | /* Fall through. */ |
252b5132 RH |
261 | case 'e': |
262 | sym_id_add (optarg, EXCL_GRAPH); | |
263 | break; | |
264 | case 'F': | |
265 | sym_id_add (optarg, INCL_TIME); | |
1a0670f3 | 266 | /* Fall through. */ |
252b5132 RH |
267 | case 'f': |
268 | sym_id_add (optarg, INCL_GRAPH); | |
269 | break; | |
efa97609 NC |
270 | /* FIXME: The -g and -G options are not present in the getopt_long |
271 | invocation above, and they are not documented in gprof.texi. | |
272 | Therefore they appear to be deprecated. Test this theory and | |
273 | delete them if true. */ | |
252b5132 RH |
274 | case 'g': |
275 | sym_id_add (optarg, EXCL_FLAT); | |
276 | break; | |
277 | case 'G': | |
278 | sym_id_add (optarg, INCL_FLAT); | |
279 | break; | |
280 | case 'h': | |
281 | usage (stdout, 0); | |
282 | case 'i': | |
283 | output_style |= STYLE_GMON_INFO; | |
284 | user_specified |= STYLE_GMON_INFO; | |
285 | break; | |
286 | case 'I': | |
287 | search_list_append (&src_search_list, optarg); | |
288 | break; | |
289 | case 'J': | |
290 | if (optarg) | |
291 | { | |
292 | sym_id_add (optarg, EXCL_ANNO); | |
293 | output_style |= STYLE_ANNOTATED_SOURCE; | |
294 | } | |
295 | else | |
296 | { | |
297 | output_style &= ~STYLE_ANNOTATED_SOURCE; | |
298 | } | |
299 | user_specified |= STYLE_ANNOTATED_SOURCE; | |
300 | break; | |
301 | case 'k': | |
302 | sym_id_add (optarg, EXCL_ARCS); | |
303 | break; | |
304 | case 'l': | |
faa7a260 | 305 | line_granularity = true; |
252b5132 RH |
306 | break; |
307 | case 'L': | |
faa7a260 | 308 | print_path = true; |
252b5132 RH |
309 | break; |
310 | case 'm': | |
311 | bb_min_calls = (unsigned long) strtoul (optarg, (char **) NULL, 10); | |
312 | break; | |
313 | case 'n': | |
314 | sym_id_add (optarg, INCL_TIME); | |
315 | break; | |
316 | case 'N': | |
317 | sym_id_add (optarg, EXCL_TIME); | |
318 | break; | |
319 | case 'O': | |
320 | switch (optarg[0]) | |
321 | { | |
322 | case 'a': | |
323 | file_format = FF_AUTO; | |
324 | break; | |
325 | case 'm': | |
326 | file_format = FF_MAGIC; | |
327 | break; | |
328 | case 'b': | |
329 | file_format = FF_BSD; | |
330 | break; | |
331 | case '4': | |
332 | file_format = FF_BSD44; | |
333 | break; | |
334 | case 'p': | |
335 | file_format = FF_PROF; | |
336 | break; | |
337 | default: | |
338 | fprintf (stderr, _("%s: unknown file format %s\n"), | |
339 | optarg, whoami); | |
340 | done (1); | |
341 | } | |
342 | break; | |
343 | case 'p': | |
344 | if (optarg) | |
345 | { | |
346 | sym_id_add (optarg, INCL_FLAT); | |
347 | } | |
348 | output_style |= STYLE_FLAT_PROFILE; | |
349 | user_specified |= STYLE_FLAT_PROFILE; | |
350 | break; | |
351 | case 'P': | |
352 | if (optarg) | |
353 | { | |
354 | sym_id_add (optarg, EXCL_FLAT); | |
355 | output_style |= STYLE_FLAT_PROFILE; | |
356 | } | |
357 | else | |
358 | { | |
359 | output_style &= ~STYLE_FLAT_PROFILE; | |
360 | } | |
361 | user_specified |= STYLE_FLAT_PROFILE; | |
362 | break; | |
363 | case 'q': | |
364 | if (optarg) | |
365 | { | |
366 | if (strchr (optarg, '/')) | |
367 | { | |
368 | sym_id_add (optarg, INCL_ARCS); | |
369 | } | |
370 | else | |
371 | { | |
372 | sym_id_add (optarg, INCL_GRAPH); | |
373 | } | |
374 | } | |
375 | output_style |= STYLE_CALL_GRAPH; | |
376 | user_specified |= STYLE_CALL_GRAPH; | |
377 | break; | |
378 | case 'r': | |
379 | output_style |= STYLE_FUNCTION_ORDER; | |
380 | user_specified |= STYLE_FUNCTION_ORDER; | |
381 | break; | |
382 | case 'R': | |
383 | output_style |= STYLE_FILE_ORDER; | |
384 | user_specified |= STYLE_FILE_ORDER; | |
385 | function_mapping_file = optarg; | |
386 | break; | |
387 | case 'Q': | |
388 | if (optarg) | |
389 | { | |
390 | if (strchr (optarg, '/')) | |
391 | { | |
392 | sym_id_add (optarg, EXCL_ARCS); | |
393 | } | |
394 | else | |
395 | { | |
396 | sym_id_add (optarg, EXCL_GRAPH); | |
397 | } | |
398 | output_style |= STYLE_CALL_GRAPH; | |
399 | } | |
400 | else | |
401 | { | |
402 | output_style &= ~STYLE_CALL_GRAPH; | |
403 | } | |
404 | user_specified |= STYLE_CALL_GRAPH; | |
405 | break; | |
406 | case 's': | |
407 | output_style |= STYLE_SUMMARY_FILE; | |
408 | user_specified |= STYLE_SUMMARY_FILE; | |
409 | break; | |
0e27a8f6 NC |
410 | case 'S': |
411 | external_symbol_table = optarg; | |
412 | DBG (AOUTDEBUG, printf ("external-symbol-table: %s\n", optarg)); | |
413 | break; | |
252b5132 RH |
414 | case 't': |
415 | bb_table_length = atoi (optarg); | |
416 | if (bb_table_length < 0) | |
417 | { | |
418 | bb_table_length = 0; | |
419 | } | |
420 | break; | |
421 | case 'T': | |
faa7a260 | 422 | bsd_style_output = true; |
252b5132 RH |
423 | break; |
424 | case 'v': | |
425 | /* This output is intended to follow the GNU standards document. */ | |
066c2a57 | 426 | printf (_("GNU gprof %s\n"), BFD_VERSION_STRING); |
252b5132 RH |
427 | printf (_("Based on BSD gprof, copyright 1983 Regents of the University of California.\n")); |
428 | printf (_("\ | |
429 | This program is free software. This program has absolutely no warranty.\n")); | |
430 | done (0); | |
431 | case 'w': | |
432 | output_width = atoi (optarg); | |
433 | if (output_width < 1) | |
434 | { | |
435 | output_width = 1; | |
436 | } | |
437 | break; | |
438 | case 'x': | |
faa7a260 | 439 | bb_annotate_all_lines = true; |
252b5132 RH |
440 | break; |
441 | case 'y': | |
faa7a260 | 442 | create_annotation_files = true; |
252b5132 RH |
443 | break; |
444 | case 'z': | |
faa7a260 | 445 | ignore_zeros = false; |
252b5132 RH |
446 | break; |
447 | case 'Z': | |
448 | if (optarg) | |
449 | { | |
450 | sym_id_add (optarg, EXCL_EXEC); | |
451 | output_style |= STYLE_EXEC_COUNTS; | |
452 | } | |
453 | else | |
454 | { | |
455 | output_style &= ~STYLE_EXEC_COUNTS; | |
456 | } | |
a0389de0 | 457 | user_specified |= STYLE_EXEC_COUNTS; |
252b5132 RH |
458 | break; |
459 | case OPTION_DEMANGLE: | |
faa7a260 | 460 | demangle = true; |
28c309a2 NC |
461 | if (optarg != NULL) |
462 | { | |
463 | enum demangling_styles style; | |
0eee5820 | 464 | |
28c309a2 | 465 | style = cplus_demangle_name_to_style (optarg); |
0eee5820 | 466 | if (style == unknown_demangling) |
28c309a2 NC |
467 | { |
468 | fprintf (stderr, | |
469 | _("%s: unknown demangling style `%s'\n"), | |
470 | whoami, optarg); | |
471 | xexit (1); | |
472 | } | |
0eee5820 | 473 | |
28c309a2 | 474 | cplus_demangle_set_style (style); |
0eee5820 | 475 | } |
252b5132 RH |
476 | break; |
477 | case OPTION_NO_DEMANGLE: | |
faa7a260 | 478 | demangle = false; |
252b5132 | 479 | break; |
630b0510 | 480 | case OPTION_INLINE_FILE_NAMES: |
faa7a260 | 481 | inline_file_names = true; |
630b0510 | 482 | break; |
252b5132 RH |
483 | default: |
484 | usage (stderr, 1); | |
485 | } | |
486 | } | |
487 | ||
488 | /* Don't allow both ordering options, they modify the arc data in-place. */ | |
489 | if ((user_specified & STYLE_FUNCTION_ORDER) | |
490 | && (user_specified & STYLE_FILE_ORDER)) | |
491 | { | |
492 | fprintf (stderr,_("\ | |
493 | %s: Only one of --function-ordering and --file-ordering may be specified.\n"), | |
494 | whoami); | |
495 | done (1); | |
496 | } | |
497 | ||
37b1bfcd BE |
498 | /* --sum implies --line, otherwise we'd lose basic block counts in |
499 | gmon.sum */ | |
252b5132 | 500 | if (output_style & STYLE_SUMMARY_FILE) |
13f178c0 | 501 | line_granularity = 1; |
252b5132 RH |
502 | |
503 | /* append value of GPROF_PATH to source search list if set: */ | |
504 | str = (char *) getenv ("GPROF_PATH"); | |
505 | if (str) | |
13f178c0 | 506 | search_list_append (&src_search_list, str); |
252b5132 RH |
507 | |
508 | if (optind < argc) | |
13f178c0 BE |
509 | a_out_name = argv[optind++]; |
510 | ||
252b5132 | 511 | if (optind < argc) |
13f178c0 | 512 | gmon_name = argv[optind++]; |
252b5132 | 513 | |
13f178c0 | 514 | /* Turn off default functions. */ |
252b5132 RH |
515 | for (sp = &default_excluded_list[0]; *sp; sp++) |
516 | { | |
517 | sym_id_add (*sp, EXCL_TIME); | |
518 | sym_id_add (*sp, EXCL_GRAPH); | |
252b5132 | 519 | sym_id_add (*sp, EXCL_FLAT); |
252b5132 RH |
520 | } |
521 | ||
37b1bfcd | 522 | /* Read symbol table from core file. */ |
252b5132 RH |
523 | core_init (a_out_name); |
524 | ||
37b1bfcd BE |
525 | /* If we should ignore direct function calls, we need to load to |
526 | core's text-space. */ | |
252b5132 | 527 | if (ignore_direct_calls) |
37b1bfcd | 528 | core_get_text_space (core_bfd); |
252b5132 | 529 | |
37b1bfcd | 530 | /* Create symbols from core image. */ |
0e27a8f6 NC |
531 | if (external_symbol_table) |
532 | core_create_syms_from (external_symbol_table); | |
533 | else if (line_granularity) | |
37b1bfcd | 534 | core_create_line_syms (); |
252b5132 | 535 | else |
37b1bfcd | 536 | core_create_function_syms (); |
252b5132 | 537 | |
37b1bfcd | 538 | /* Translate sym specs into syms. */ |
252b5132 RH |
539 | sym_id_parse (); |
540 | ||
541 | if (file_format == FF_PROF) | |
542 | { | |
252b5132 RH |
543 | fprintf (stderr, |
544 | _("%s: sorry, file format `prof' is not yet supported\n"), | |
545 | whoami); | |
546 | done (1); | |
252b5132 RH |
547 | } |
548 | else | |
549 | { | |
37b1bfcd | 550 | /* Get information about gmon.out file(s). */ |
252b5132 RH |
551 | do |
552 | { | |
553 | gmon_out_read (gmon_name); | |
554 | if (optind < argc) | |
13f178c0 | 555 | gmon_name = argv[optind]; |
252b5132 RH |
556 | } |
557 | while (optind++ < argc); | |
558 | } | |
559 | ||
13f178c0 BE |
560 | /* If user did not specify output style, try to guess something |
561 | reasonable. */ | |
252b5132 RH |
562 | if (output_style == 0) |
563 | { | |
564 | if (gmon_input & (INPUT_HISTOGRAM | INPUT_CALL_GRAPH)) | |
fe541ea9 JW |
565 | { |
566 | if (gmon_input & INPUT_HISTOGRAM) | |
567 | output_style |= STYLE_FLAT_PROFILE; | |
568 | if (gmon_input & INPUT_CALL_GRAPH) | |
569 | output_style |= STYLE_CALL_GRAPH; | |
570 | } | |
252b5132 | 571 | else |
37b1bfcd BE |
572 | output_style = STYLE_EXEC_COUNTS; |
573 | ||
252b5132 RH |
574 | output_style &= ~user_specified; |
575 | } | |
576 | ||
37b1bfcd BE |
577 | /* Dump a gmon.sum file if requested (before any other |
578 | processing!) */ | |
252b5132 RH |
579 | if (output_style & STYLE_SUMMARY_FILE) |
580 | { | |
581 | gmon_out_write (GMONSUM); | |
582 | } | |
583 | ||
584 | if (gmon_input & INPUT_HISTOGRAM) | |
585 | { | |
586 | hist_assign_samples (); | |
587 | } | |
588 | ||
589 | if (gmon_input & INPUT_CALL_GRAPH) | |
590 | { | |
591 | cg = cg_assemble (); | |
592 | } | |
593 | ||
37b1bfcd | 594 | /* Do some simple sanity checks. */ |
252b5132 RH |
595 | if ((output_style & STYLE_FLAT_PROFILE) |
596 | && !(gmon_input & INPUT_HISTOGRAM)) | |
597 | { | |
598 | fprintf (stderr, _("%s: gmon.out file is missing histogram\n"), whoami); | |
599 | done (1); | |
600 | } | |
601 | ||
602 | if ((output_style & STYLE_CALL_GRAPH) && !(gmon_input & INPUT_CALL_GRAPH)) | |
603 | { | |
604 | fprintf (stderr, | |
605 | _("%s: gmon.out file is missing call-graph data\n"), whoami); | |
606 | done (1); | |
607 | } | |
608 | ||
13f178c0 | 609 | /* Output whatever user whishes to see. */ |
252b5132 RH |
610 | if (cg && (output_style & STYLE_CALL_GRAPH) && bsd_style_output) |
611 | { | |
13f178c0 BE |
612 | /* Print the dynamic profile. */ |
613 | cg_print (cg); | |
252b5132 RH |
614 | } |
615 | ||
616 | if (output_style & STYLE_FLAT_PROFILE) | |
617 | { | |
13f178c0 | 618 | /* Print the flat profile. */ |
f3445b37 | 619 | hist_print (); |
252b5132 RH |
620 | } |
621 | ||
622 | if (cg && (output_style & STYLE_CALL_GRAPH)) | |
623 | { | |
624 | if (!bsd_style_output) | |
625 | { | |
13f178c0 | 626 | /* Print the dynamic profile. */ |
f3445b37 | 627 | cg_print (cg); |
252b5132 RH |
628 | } |
629 | cg_print_index (); | |
630 | } | |
631 | ||
632 | if (output_style & STYLE_EXEC_COUNTS) | |
13f178c0 | 633 | print_exec_counts (); |
f3445b37 | 634 | |
252b5132 | 635 | if (output_style & STYLE_ANNOTATED_SOURCE) |
13f178c0 | 636 | print_annotated_source (); |
f3445b37 | 637 | |
252b5132 | 638 | if (output_style & STYLE_FUNCTION_ORDER) |
13f178c0 | 639 | cg_print_function_ordering (); |
f3445b37 | 640 | |
252b5132 | 641 | if (output_style & STYLE_FILE_ORDER) |
13f178c0 BE |
642 | cg_print_file_ordering (); |
643 | ||
252b5132 RH |
644 | return 0; |
645 | } | |
646 | ||
647 | void | |
3e8f6abf | 648 | done (int status) |
252b5132 RH |
649 | { |
650 | exit (status); | |
651 | } |