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