Commit 52eba779 by Martin Liska Committed by Martin Liska

Improve JSON format: add function names for lines.

2019-03-11  Martin Liska  <mliska@suse.cz>

	* gcov.c (output_intermediate_json_line): Print function
	name of each line.
	(output_json_intermediate_file): Add new argument.
	* doc/gcov.texi: Document the change.

From-SVN: r269581
parent cb90c001
2019-03-11 Martin Liska <mliska@suse.cz>
* gcov.c (output_intermediate_json_line): Print function
name of each line.
(output_json_intermediate_file): Add new argument.
* doc/gcov.texi: Document the change.
2019-03-11 Eric Botcazou <ebotcazou@adacore.com> 2019-03-11 Eric Botcazou <ebotcazou@adacore.com>
PR rtl-optimization/89588 PR rtl-optimization/89588
......
...@@ -276,6 +276,7 @@ Each @var{line} has the following form: ...@@ -276,6 +276,7 @@ Each @var{line} has the following form:
"count": @var{count}, "count": @var{count},
"line_number": @var{line_number}, "line_number": @var{line_number},
"unexecuted_block": @var{unexecuted_block} "unexecuted_block": @var{unexecuted_block}
"function_name": @var{function_name},
@} @}
@end smallexample @end smallexample
...@@ -294,6 +295,10 @@ Fields of the @var{line} element have following semantics: ...@@ -294,6 +295,10 @@ Fields of the @var{line} element have following semantics:
(not all statements on the line are executed) (not all statements on the line are executed)
@end itemize @end itemize
@item
@var{function_name}: a name of a function this @var{line} belongs to
(for a line with an inlined statements can be not set)
Each @var{branch} has the following form: Each @var{branch} has the following form:
@smallexample @smallexample
......
...@@ -1041,17 +1041,21 @@ process_args (int argc, char **argv) ...@@ -1041,17 +1041,21 @@ process_args (int argc, char **argv)
return optind; return optind;
} }
/* Output intermediate LINE sitting on LINE_NUM to JSON OBJECT. */ /* Output intermediate LINE sitting on LINE_NUM to JSON OBJECT.
Add FUNCTION_NAME to the LINE. */
static void static void
output_intermediate_json_line (json::array *object, output_intermediate_json_line (json::array *object,
line_info *line, unsigned line_num) line_info *line, unsigned line_num,
const char *function_name)
{ {
if (!line->exists) if (!line->exists)
return; return;
json::object *lineo = new json::object (); json::object *lineo = new json::object ();
lineo->set ("line_number", new json::number (line_num)); lineo->set ("line_number", new json::number (line_num));
if (function_name != NULL)
lineo->set ("function_name", new json::string (function_name));
lineo->set ("count", new json::number (line->count)); lineo->set ("count", new json::number (line->count));
lineo->set ("unexecuted_block", lineo->set ("unexecuted_block",
new json::literal (line->has_unexecuted_block)); new json::literal (line->has_unexecuted_block));
...@@ -1141,6 +1145,8 @@ output_json_intermediate_file (json::array *json_files, source_info *src) ...@@ -1141,6 +1145,8 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
json::array *lineso = new json::array (); json::array *lineso = new json::array ();
root->set ("lines", lineso); root->set ("lines", lineso);
function_info *last_non_group_fn = NULL;
for (unsigned line_num = 1; line_num <= src->lines.size (); line_num++) for (unsigned line_num = 1; line_num <= src->lines.size (); line_num++)
{ {
vector<function_info *> *fns = src->get_functions_at_location (line_num); vector<function_info *> *fns = src->get_functions_at_location (line_num);
...@@ -1150,17 +1156,23 @@ output_json_intermediate_file (json::array *json_files, source_info *src) ...@@ -1150,17 +1156,23 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
for (vector<function_info *>::iterator it2 = fns->begin (); for (vector<function_info *>::iterator it2 = fns->begin ();
it2 != fns->end (); it2++) it2 != fns->end (); it2++)
{ {
if (!(*it2)->is_group)
last_non_group_fn = *it2;
vector<line_info> &lines = (*it2)->lines; vector<line_info> &lines = (*it2)->lines;
for (unsigned i = 0; i < lines.size (); i++) for (unsigned i = 0; i < lines.size (); i++)
{ {
line_info *line = &lines[i]; line_info *line = &lines[i];
output_intermediate_json_line (lineso, line, line_num + i); output_intermediate_json_line (lineso, line, line_num + i,
(*it2)->m_name);
} }
} }
/* Follow with lines associated with the source file. */ /* Follow with lines associated with the source file. */
if (line_num < src->lines.size ()) if (line_num < src->lines.size ())
output_intermediate_json_line (lineso, &src->lines[line_num], line_num); output_intermediate_json_line (lineso, &src->lines[line_num], line_num,
(last_non_group_fn != NULL
? last_non_group_fn->m_name : NULL));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment