This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch for Gprof: consistent handling of underscores


If the compiler prepends underscores to symbol names, Gprof currently
removes them when printing it's reports, but requires to include them
in symspecs.  I think this is confusing, especially for those users
who aren't aware at all that underscores are being prepended.  Newbies
who don't know anything below the C source level shouldn't be
discouraged from using the profiler, IMHO.

I think the following change makes Gprof consistent in this aspect.
Specifically, symbols in symspecs are now handled exactly like symbols
that are printed.

I also include an appropriate change to the Gprof manual.  While at
that, I spootted a few typos and other minor errors in the manual; the
diffs below include them as well.

1999-08-29  Eli Zaretskii  <eliz@is.elta.co.il>

	* sym_ids.c (match): When comparing symbol with pattern, ignore
	leading underscore of the symbol, if the compiler prepends them.

*** gprof/sym_ids.c~0	Fri May  1 18:49:44 1998
--- gprof/sym_ids.c	Sun Aug 29 21:36:50 1999
*************** DEFUN (match, (pattern, sym), Sym * patt
*** 201,207 ****
  {
    return (pattern->file ? pattern->file == sym->file : TRUE)
      && (pattern->line_num ? pattern->line_num == sym->line_num : TRUE)
!     && (pattern->name ? strcmp (pattern->name, sym->name) == 0 : TRUE);
  }
  
  
--- 201,210 ----
  {
    return (pattern->file ? pattern->file == sym->file : TRUE)
      && (pattern->line_num ? pattern->line_num == sym->line_num : TRUE)
!     && (pattern->name
! 	? strcmp (pattern->name,
! 		  sym->name+(discard_underscores && sym->name[0] == '_')) == 0
! 	: TRUE);
  }
  
  
*** gprof/gprof.t1~	Mon Jun 14 02:36:30 1999
--- gprof/gprof.texi	Sun Sep  5 18:13:10 1999
***************
*** 303,309 ****
  * Output Options::      Controlling @code{gprof}'s output style
  * Analysis Options::    Controlling how @code{gprof} analyses its data
  * Miscellaneous Options::
! * Depricated Options::  Options you no longer need to use, but which
                              have been retained for compatibility
  * Symspecs::            Specifying functions to include or exclude
  @end menu
--- 303,309 ----
  * Output Options::      Controlling @code{gprof}'s output style
  * Analysis Options::    Controlling how @code{gprof} analyses its data
  * Miscellaneous Options::
! * Deprecated Options::  Options you no longer need to use, but which
                              have been retained for compatibility
  * Symspecs::            Specifying functions to include or exclude
  @end menu
***************
*** 344,350 ****
  print a tally of functions and the number of times each was called.
  If @var{symspec} is specified, print tally only for matching symbols.
  
! If the profile data file contains basic-block count records, specifing
  the @samp{-l} option, along with @samp{-C}, will cause basic-block
  execution counts to be tallied and displayed.
  
--- 344,350 ----
  print a tally of functions and the number of times each was called.
  If @var{symspec} is specified, print tally only for matching symbols.
  
! If the profile data file contains basic-block count records, specifying
  the @samp{-l} option, along with @samp{-C}, will cause basic-block
  execution counts to be tallied and displayed.
  
***************
*** 358,364 ****
  @itemx --directory-path=@var{dirs}
  The @samp{-I} option specifies a list of search directories in
  which to find source files.  Environment variable @var{GPROF_PATH}
! can also be used to convery this information.
  Used mostly for annotated source output.
  
  @item -J[@var{symspec}]
--- 358,364 ----
  @itemx --directory-path=@var{dirs}
  The @samp{-I} option specifies a list of search directories in
  which to find source files.  Environment variable @var{GPROF_PATH}
! can also be used to convey this information.
  Used mostly for annotated source output.
  
  @item -J[@var{symspec}]
***************
*** 407,416 ****
  @item -y
  @itemx --separate-files
  This option affects annotated source output only.
! Normally, gprof prints annotated source files
  to standard-output.  If this option is specified,
! annotated source for a file named @file{path/filename}
! is generated in the file @file{filename-ann}.
  
  @item -Z[@var{symspec}]
  @itemx --no-exec-counts[=@var{symspec}]
--- 407,421 ----
  @item -y
  @itemx --separate-files
  This option affects annotated source output only.
! Normally, @code{gprof} prints annotated source files
  to standard-output.  If this option is specified,
! annotated source for a file named @file{path/@var{filename}}
! is generated in the file @file{@var{filename}-ann}.  If the underlying
! filesystem would truncate @file{@var{filename}-ann} so that it
! overwrites the original @file{@var{filename}}, @code{gprof} generates
! annotated source in the file @file{@var{filename}.ann} instead (if the
! original file name has an extension, that extension is @emph{replaced}
! with @file{.ann}).
  
  @item -Z[@var{symspec}]
  @itemx --no-exec-counts[=@var{symspec}]
***************
*** 456,462 ****
  @end group
  @end smallexample
  
! GNU @code{nm} @samp{--extern-only} @samp{--defined-only} @samp{-v} @samp{--print-file-name} can be used to create @var{map_file}.
  
  @item -T
  @itemx --traditional
--- 461,468 ----
  @end group
  @end smallexample
  
! To create a @var{map_file} with @sc{gnu} @code{nm}, type a command like
! @kbd{nm --extern-only --defined-only -v --print-file-name program-name}.
  
  @item -T
  @itemx --traditional
***************
*** 565,571 ****
  
  @end table
  
! @node Miscellaneous Options,Depricated Options,Analysis Options,Invoking
  @section Miscellaneous Options
  
  @table @code
--- 571,577 ----
  
  @end table
  
! @node Miscellaneous Options,Deprecated Options,Analysis Options,Invoking
  @section Miscellaneous Options
  
  @table @code
***************
*** 601,608 ****
  
  @end table
  
! @node Depricated Options,Symspecs,Miscellaneous Options,Invoking
! @section Depricated Options
  
  @table @code
  
--- 607,614 ----
  
  @end table
  
! @node Deprecated Options,Symspecs,Miscellaneous Options,Invoking
! @section Deprecated Options
  
  @table @code
  
***************
*** 653,659 ****
  lists in the call graph all functions that were reached from either
  @code{foo} or @code{bar} and were not reachable from @code{boring}.
  
! @node Symspecs,,Depricated Options,Invoking
  @section Symspecs
  
  Many of the output options allow functions to be included or excluded
--- 659,665 ----
  lists in the call graph all functions that were reached from either
  @code{foo} or @code{bar} and were not reachable from @code{boring}.
  
! @node Symspecs,,Deprecated Options,Invoking
  @section Symspecs
  
  Many of the output options allow functions to be included or excluded
***************
*** 672,678 ****
  @table @samp
  @item main.c
  Selects everything in file @file{main.c}---the
! dot in the string tells gprof to interpret
  the string as a filename, rather than as
  a function name.  To select a file whose
  name does not contain a dot, a trailing colon
--- 678,684 ----
  @table @samp
  @item main.c
  Selects everything in file @file{main.c}---the
! dot in the string tells @code{gprof} to interpret
  the string as a filename, rather than as
  a function name.  To select a file whose
  name does not contain a dot, a trailing colon
***************
*** 691,701 ****
  to add a leading colon to the name.  For example, @samp{:.mul} selects
  function @samp{.mul}.
  
! In some object file formats, symbols have a leading underscore.  gprof
! will normally not print these underscores.  However, you must use the
! underscore when you name a symbol in a symspec.  You can use the
! @code{nm} program to see whether symbols have underscores for the object
! file format you are using.
  
  @item main.c:main
  Selects function @samp{main} in file @file{main.c}.
--- 697,709 ----
  to add a leading colon to the name.  For example, @samp{:.mul} selects
  function @samp{.mul}.
  
! In some object file formats, symbols have a leading underscore.
! @code{gprof} will normally not print these underscores.  When you name a
! symbol in a symspec, you should type it exactly as @code{gprof} prints
! it in its output.  For example, if the compiler produces a symbol
! @samp{_main} from your @code{main} function, @code{gprof} still prints
! it as @samp{main} in its output, so you should use @samp{main} in
! symspecs.
  
  @item main.c:main
  Selects function @samp{main} in file @file{main.c}.
***************
*** 769,775 ****
  The functions are sorted by first by decreasing run-time spent in them,
  then by decreasing number of calls, then alphabetically by name.  The
  functions @samp{mcount} and @samp{profil} are part of the profiling
! aparatus and appear in every flat profile; their time gives a measure of
  the amount of overhead due to profiling.
  
  Just before the column headers, a statement appears indicating
--- 777,783 ----
  The functions are sorted by first by decreasing run-time spent in them,
  then by decreasing number of calls, then alphabetically by name.  The
  functions @samp{mcount} and @samp{profil} are part of the profiling
! apparatus and appear in every flat profile; their time gives a measure of
  the amount of overhead due to profiling.
  
  Just before the column headers, a statement appears indicating
***************
*** 781,790 ****
  The program's total execution time was 0.06
  seconds, as indicated by the @samp{cumulative seconds} field.  Since
  each sample counted for 0.01 seconds, this means only six samples
! were taken during the run.  Two of the samples occured while the
  program was in the @samp{open} function, as indicated by the
  @samp{self seconds} field.  Each of the other four samples
! occured one each in @samp{offtime}, @samp{memccpy}, @samp{write},
  and @samp{mcount}.
  Since only six samples were taken, none of these values can
  be regarded as particularly reliable.
--- 789,798 ----
  The program's total execution time was 0.06
  seconds, as indicated by the @samp{cumulative seconds} field.  Since
  each sample counted for 0.01 seconds, this means only six samples
! were taken during the run.  Two of the samples occurred while the
  program was in the @samp{open} function, as indicated by the
  @samp{self seconds} field.  Each of the other four samples
! occurred one each in @samp{offtime}, @samp{memccpy}, @samp{write},
  and @samp{mcount}.
  Since only six samples were taken, none of these values can
  be regarded as particularly reliable.
***************
*** 1019,1025 ****
  
  @item called
  Two numbers: the number of times @code{report} was called from @code{main},
! followed by the total number of nonrecursive calls to @code{report} from
  all its callers.
  
  @item name and index number
--- 1027,1033 ----
  
  @item called
  Two numbers: the number of times @code{report} was called from @code{main},
! followed by the total number of non-recursive calls to @code{report} from
  all its callers.
  
  @item name and index number
***************
*** 1078,1084 ****
  
  @item called
  Two numbers, the number of calls to @code{report} from @code{main}
! followed by the total number of nonrecursive calls to @code{report}.
  This ratio is used to determine how much of @code{report}'s @code{self}
  and @code{children} time gets credited to @code{main}.
  @xref{Assumptions}.
--- 1086,1092 ----
  
  @item called
  Two numbers, the number of calls to @code{report} from @code{main}
! followed by the total number of non-recursive calls to @code{report}.
  This ratio is used to determine how much of @code{report}'s @code{self}
  and @code{children} time gets credited to @code{main}.
  @xref{Assumptions}.
***************
*** 1211,1217 ****
  first, the number of times functions in the cycle were called by functions
  outside the cycle; second, the number of times they were called by
  functions in the cycle (including times when a function in the cycle calls
! itself).  This is a generalization of the usual split into nonrecursive and
  recursive calls.
  
  The @code{calls} field of a subroutine-line for a cycle member in the
--- 1219,1225 ----
  first, the number of times functions in the cycle were called by functions
  outside the cycle; second, the number of times they were called by
  functions in the cycle (including times when a function in the cycle calls
! itself).  This is a generalization of the usual split into non-recursive and
  recursive calls.
  
  The @code{calls} field of a subroutine-line for a cycle member in the
***************
*** 1275,1281 ****
  Now let's look at some of @code{gprof}'s output from the same program run,
  this time with line-by-line profiling enabled.  Note that @code{ct_init}'s
  four histogram hits are broken down into four lines of source code - one hit
! occured on each of lines 349, 351, 382 and 385.  In the call graph,
  note how
  @code{ct_init}'s 13327 calls to @code{init_block} are broken down
  into one call from line 396, 3071 calls from line 384, 3730 calls
--- 1283,1289 ----
  Now let's look at some of @code{gprof}'s output from the same program run,
  this time with line-by-line profiling enabled.  Note that @code{ct_init}'s
  four histogram hits are broken down into four lines of source code - one hit
! occurred on each of lines 349, 351, 382 and 385.  In the call graph,
  note how
  @code{ct_init}'s 13327 calls to @code{init_block} are broken down
  into one call from line 396, 3071 calls from line 384, 3730 calls
***************
*** 1328,1334 ****
  Compiling with @samp{gcc @dots{} -g -pg -a} augments your program
  with basic-block counting code, in addition to function counting code.
  This enables @code{gprof} to determine how many times each line
! of code was exeucted.
  For example, consider the following function, taken from gzip,
  with line numbers added:
  
--- 1336,1342 ----
  Compiling with @samp{gcc @dots{} -g -pg -a} augments your program
  with basic-block counting code, in addition to function counting code.
  This enables @code{gprof} to determine how many times each line
! of code was executed.
  For example, consider the following function, taken from gzip,
  with line numbers added:
  
***************
*** 1364,1370 ****
  basic-blocks to handle various special cases.
  
  A program augmented for basic-block counting can be analyzed with
! @code{gprof -l -A}.  I also suggest use of the @samp{-x} option,
  which ensures that each line of code is labeled at least once.
  Here is @code{updcrc}'s
  annotated source listing for a sample @code{gzip} run:
--- 1372,1378 ----
  basic-blocks to handle various special cases.
  
  A program augmented for basic-block counting can be analyzed with
! @samp{gprof -l -A}.  I also suggest use of the @samp{-x} option,
  which ensures that each line of code is labeled at least once.
  Here is @code{updcrc}'s
  annotated source listing for a sample @code{gzip} run:
***************
*** 1526,1532 ****
  
  @item How do I find which lines in my program called a particular function?
  
! Use @code{gprof -l} and lookup the function in the call graph.
  The callers will be broken down by function and line number.
  
  @item How do I analyze a program that runs for less than a second?
--- 1534,1540 ----
  
  @item How do I find which lines in my program called a particular function?
  
! Use @samp{gprof -l} and lookup the function in the call graph.
  The callers will be broken down by function and line number.
  
  @item How do I analyze a program that runs for less than a second?
***************
*** 1582,1588 ****
  @item
  In the annotated source listing,
  if there are multiple basic blocks on the same line,
! @sc{gnu} @code{gprof} prints all of their counts, seperated by commas.
  
  @ignore - it does this now
  @item
--- 1590,1596 ----
  @item
  In the annotated source listing,
  if there are multiple basic blocks on the same line,
! @sc{gnu} @code{gprof} prints all of their counts, separated by commas.
  
  @ignore - it does this now
  @item
***************
*** 1601,1607 ****
  @chapter Details of Profiling
  
  @menu
! * Implementation::      How a program collets profiling information
  * File Format::         Format of @samp{gmon.out} files
  * Internals::           @code{gprof}'s internal operation
  * Debugging::           Using @code{gprof}'s @samp{-d} option
--- 1609,1615 ----
  @chapter Details of Profiling
  
  @menu
! * Implementation::      How a program collects profiling information
  * File Format::         Format of @samp{gmon.out} files
  * Internals::           @code{gprof}'s internal operation
  * Debugging::           Using @code{gprof}'s @samp{-d} option
***************
*** 1624,1637 ****
  both its parent routine (the child) and its parent's parent.  This is
  typically done by examining the stack frame to find both
  the address of the child, and the return address in the original parent.
! Since this is a very machine-dependant operation, @code{mcount}
  itself is typically a short assembly-language stub routine
  that extracts the required
  information, and then calls @code{__mcount_internal}
  (a normal C function) with two arguments - @code{frompc} and @code{selfpc}.
  @code{__mcount_internal} is responsible for maintaining
  the in-memory call graph, which records @code{frompc}, @code{selfpc},
! and the number of times each of these call arcs was transversed.
  
  GCC Version 2 provides a magical function (@code{__builtin_return_address}),
  which allows a generic @code{mcount} function to extract the
--- 1632,1645 ----
  both its parent routine (the child) and its parent's parent.  This is
  typically done by examining the stack frame to find both
  the address of the child, and the return address in the original parent.
! Since this is a very machine-dependent operation, @code{mcount}
  itself is typically a short assembly-language stub routine
  that extracts the required
  information, and then calls @code{__mcount_internal}
  (a normal C function) with two arguments - @code{frompc} and @code{selfpc}.
  @code{__mcount_internal} is responsible for maintaining
  the in-memory call graph, which records @code{frompc}, @code{selfpc},
! and the number of times each of these call arcs was traversed.
  
  GCC Version 2 provides a magical function (@code{__builtin_return_address}),
  which allows a generic @code{mcount} function to extract the
***************
*** 1724,1730 ****
  
  The old BSD-derived file format used for profile data does not contain a
  magic cookie that allows to check whether a data file really is a
! gprof file.  Furthermore, it does not provide a version number, thus
  rendering changes to the file format almost impossible.  @sc{gnu} @code{gprof}
  uses a new file format that provides these features.  For backward
  compatibility, @sc{gnu} @code{gprof} continues to support the old BSD-derived
--- 1732,1738 ----
  
  The old BSD-derived file format used for profile data does not contain a
  magic cookie that allows to check whether a data file really is a
! @code{gprof} file.  Furthermore, it does not provide a version number, thus
  rendering changes to the file format almost impossible.  @sc{gnu} @code{gprof}
  uses a new file format that provides these features.  For backward
  compatibility, @sc{gnu} @code{gprof} continues to support the old BSD-derived
***************
*** 1827,1833 ****
  verify that it is an object file,
  and read its symbol table (@code{core.c:core_init}),
  using @code{bfd_canonicalize_symtab} after mallocing
! an appropiate sized array of asymbols.  At this point,
  function mappings are read (if the @samp{--file-ordering} option
  has been specified), and the core text space is read into
  memory (if the @samp{-c} option was given).
--- 1835,1841 ----
  verify that it is an object file,
  and read its symbol table (@code{core.c:core_init}),
  using @code{bfd_canonicalize_symtab} after mallocing
! an appropriately sized array of symbols.  At this point,
  function mappings are read (if the @samp{--file-ordering} option
  has been specified), and the core text space is read into
  memory (if the @samp{-c} option was given).
***************
*** 1845,1851 ****
  table - one to count the size of the symbol table required,
  and the other to actually read the symbols.  In between the
  two passes, a single array of type @code{Sym} is created of
! the appropiate length.
  Finally, @code{symtab.c:symtab_finalize}
  is called to sort the symbol table and remove duplicate entries
  (entries with the same memory address).
--- 1853,1859 ----
  table - one to count the size of the symbol table required,
  and the other to actually read the symbols.  In between the
  two passes, a single array of type @code{Sym} is created of
! the appropriate length.
  Finally, @code{symtab.c:symtab_finalize}
  is called to sort the symbol table and remove duplicate entries
  (entries with the same memory address).
***************
*** 1931,1937 ****
  a hit, for example.
  
  If call graph data is present, @code{cg_arcs.c:cg_assemble} is called.
! First, if @samp{-c} was specified, a machine-dependant
  routine (@code{find_call}) scans through each symbol's machine code,
  looking for subroutine call instructions, and adding them
  to the call graph with a zero call count.
--- 1939,1945 ----
  a hit, for example.
  
  If call graph data is present, @code{cg_arcs.c:cg_assemble} is called.
! First, if @samp{-c} was specified, a machine-dependent
  routine (@code{find_call}) scans through each symbol's machine code,
  looking for subroutine call instructions, and adding them
  to the call graph with a zero call count.
***************
*** 1945,1958 ****
  of which are assigned the same topological number.
  Two passes are now made through this sorted array of symbol pointers.
  The first pass, from end to beginning (parents to children),
! computes the fraction of child time to propogate to each parent
  and a print flag.
  The print flag reflects symspec handling of INCL_GRAPH/EXCL_GRAPH,
  with a parent's include or exclude (print or no print) property
  being propagated to its children, unless they themselves explicitly appear
  in INCL_GRAPH or EXCL_GRAPH.
  A second pass, from beginning to end (children to parents) actually
! propogates the timings along the call graph, subject
  to a check against INCL_TIME/EXCL_TIME.
  With the print flag, fractions, and timings now stored in the symbol
  structures, the topological sort array is now discarded, and a
--- 1953,1966 ----
  of which are assigned the same topological number.
  Two passes are now made through this sorted array of symbol pointers.
  The first pass, from end to beginning (parents to children),
! computes the fraction of child time to propagate to each parent
  and a print flag.
  The print flag reflects symspec handling of INCL_GRAPH/EXCL_GRAPH,
  with a parent's include or exclude (print or no print) property
  being propagated to its children, unless they themselves explicitly appear
  in INCL_GRAPH or EXCL_GRAPH.
  A second pass, from beginning to end (children to parents) actually
! propagates the timings along the call graph, subject
  to a check against INCL_TIME/EXCL_TIME.
  With the print flag, fractions, and timings now stored in the symbol
  structures, the topological sort array is now discarded, and a

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]