On Fri, May 24, 2013 at 2:32 PM, Sharad Singhai <sing...@google.com> wrote:
>        if (flag_gcov_file)
>   {
> -  char *gcov_file_name
> -    = make_gcov_file_name (file_name, src->coverage.name);
> +          if (flag_intermediate_format)
> +            /* Output the intermediate format without requiring source
> +               files.  This outputs a section to a *single* file.  */
> +            output_intermediate_file (gcov_file_intermediate, src);

Is there an indentation issue here?



> +          else
> +            {
> +              char *gcov_file_name
> +                = make_gcov_file_name (file_name, src->coverage.name);
>


Try to avoid the following format only changes by reorganization --
for instance refactor the following part into a helper function.

Ok for google branch with those change.  Please submit the change to trunk asap.

thanks,

David

> -  if (src->coverage.lines)
> -    {
> -      FILE *gcov_file = fopen (gcov_file_name, "w");
> +              if (src->coverage.lines)
> +                {
> +                  FILE *gcov_file = fopen (gcov_file_name, "w");
>
> -      if (gcov_file)
> - {
> -  fnotice (stdout, "Creating '%s'\n", gcov_file_name);
> -  output_lines (gcov_file, src);
> -  if (ferror (gcov_file))
> -    fnotice (stderr, "Error writing output file '%s'\n",
> -     gcov_file_name);
> -  fclose (gcov_file);
> - }
> -      else
> - fnotice (stderr, "Could not open output file '%s'\n",
> - gcov_file_name);
> -    }
> -  else
> -    {
> -      unlink (gcov_file_name);
> -      fnotice (stdout, "Removing '%s'\n", gcov_file_name);
> -    }
> -  free (gcov_file_name);
> - }
> -      fnotice (stdout, "\n");
> +                  if (gcov_file)
> +                    {
> +                      fnotice (stdout, "Creating '%s'\n", gcov_file_name);
> +                      output_lines (gcov_file, src);
> +                      if (ferror (gcov_file))
> +                        fnotice (stderr, "Error writing output file '%s'\n",
> +                                 gcov_file_name);
> +                      fclose (gcov_file);
> +                    }
> +                  else
> +                    fnotice (stderr, "Could not open output file '%s'\n",
> +                             gcov_file_name);
> +                }
> +              else
> +                {
> +                  unlink (gcov_file_name);
> +                  fnotice (stdout, "Removing '%s'\n", gcov_file_name);
> +                }
> +              free (gcov_file_name);
> +            }
> +          fnotice (stdout, "\n");
> +        }
>      }
>
> +  if (flag_gcov_file && flag_intermediate_format)
> +    {
> +      /* Now we've finished writing the intermediate file.  */
> +      fclose (gcov_file_intermediate);
> +      XDELETEVEC (gcov_file_intermediate_name);
> +    }
> +
>    if (!file_name)
>      executed_summary (total_lines, total_executed);
>  }
> @@ -766,6 +914,9 @@ release_function (function_t *fn)
>      }
>    free (fn->blocks);
>    free (fn->counts);
> +  if (flag_demangled_names && fn->demangled_name != fn->name)
> +    free (fn->demangled_name);
> +  free (fn->name);
>  }
>
>  /* Release all memory used.  */
> @@ -1051,6 +1202,12 @@ read_graph_file (void)
>
>    fn = XCNEW (function_t);
>    fn->name = function_name;
> +          if (flag_demangled_names)
> +            {
> +              fn->demangled_name = cplus_demangle (fn->name, DMGL_PARAMS);
> +              if (!fn->demangled_name)
> +                fn->demangled_name = fn->name;
> +            }
>    fn->ident = ident;
>    fn->lineno_checksum = lineno_checksum;
>    fn->cfg_checksum = cfg_checksum;
> @@ -2280,7 +2437,8 @@ output_lines (FILE *gcov_file, const source_t *src
>      if (arc->fake)
>        return_count -= arc->count;
>
> -  fprintf (gcov_file, "function %s", fn->name);
> +  fprintf (gcov_file, "function %s", flag_demangled_names ?
> +                   fn->demangled_name : fn->name);
>    fprintf (gcov_file, " called %s",
>     format_gcov (called_count, 0, -1));
>    fprintf (gcov_file, " returned %s",
> Index: doc/gcov.texi
> ===================================================================
> --- doc/gcov.texi (revision 199269)
> +++ doc/gcov.texi (working copy)
> @@ -131,6 +131,8 @@ gcov [@option{-v}|@option{--version}] [@option{-h}
>       [@option{-o}|@option{--object-directory} @var{directory|file}]
>       [@option{-s}|@option{--source-prefix} @var{directory}]
>       [@option{-d}|@option{--display-progress}]
> +     [@option{-i}|@option{--intermediate-format}]
> +     [@option{-m}|@option{--demangled-names}]
>       @var{files}
>  @c man end
>  @c man begin SEEALSO
> @@ -232,6 +234,50 @@ Unconditional branches are normally not interestin
>  @itemx --display-progress
>  Display the progress on the standard output.
>
> +@item -i
> +@itemx --intermediate-format
> +Output gcov file in an easy-to-parse intermediate text format that can
> +be used by @command{lcov} or other tools. The output is a single
> +@file{.gcov} file per @file{.gcda} file. No source code is required.
> +
> +The format of the intermediate @file{.gcov} file is plain text with
> +one entry per line
> +
> +@smallexample
> +file:@var{source_file_name}
> +function:@var{line_number},@var{execution_count},@var{function_name}
> +lcount:@var{line number},@var{execution_count}
> +branch:@var{line_number},@var{branch_coverage_type}
> +
> +Where the @var{branch_coverage_type} is
> +   notexec (Branch not executed)
> +   taken (Branch executed and taken)
> +   nottaken (Branch executed, but not taken)
> +
> +There can be multiple @var{file} entries in an intermediate gcov
> +file. All entries following a @var{file} pertain to that source file
> +until the next @var{file} entry.
> +@end smallexample
> +
> +Here is a sample when @option{-i} is used in conjuction with
> @option{-b} option:
> +
> +@smallexample
> +file:array.cc
> +function:11,1,_Z3sumRKSt6vectorIPiSaIS0_EE
> +function:22,1,main
> +lcount:11,1
> +lcount:12,1
> +lcount:14,1
> +branch:14,taken
> +lcount:26,1
> +branch:28,nottaken
> +@end smallexample
> +
> +@item -m
> +@itemx --demangled-names
> +Display demangled function names in output. The default is to show
> +mangled function names.
> +
>  @end table
>
>  @command{gcov} should be run with the current directory the same as that

Reply via email to