public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/PR98273-gcov-nested-functions)] gcov: fix line output for nested functions in JSON format
@ 2020-12-14 13:01 Martin Liska
0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2020-12-14 13:01 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:1a9f3a9459d0b9b013d564b2990f941cd76b5ef9
commit 1a9f3a9459d0b9b013d564b2990f941cd76b5ef9
Author: Martin Liska <mliska@suse.cz>
Date: Mon Dec 14 14:00:08 2020 +0100
gcov: fix line output for nested functions in JSON format
gcc/ChangeLog:
PR gcov-profile/98273
* gcov.c (output_json_intermediate_file): Use stack of nested
functions for lines in a source file. Pop when a function ends.
Diff:
---
gcc/gcov.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/gcc/gcov.c b/gcc/gcov.c
index daa1266db86..8dcec9432a6 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1165,7 +1165,7 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
json::array *lineso = new json::array ();
root->set ("lines", lineso);
- function_info *last_non_group_fn = NULL;
+ vector<function_info *> last_non_group_fns;
for (unsigned line_num = 1; line_num <= src->lines.size (); line_num++)
{
@@ -1177,7 +1177,7 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
it2 != fns->end (); it2++)
{
if (!(*it2)->is_group)
- last_non_group_fn = *it2;
+ last_non_group_fns.push_back (*it2);
vector<line_info> &lines = (*it2)->lines;
/* The LINES array is allocated only for group functions. */
@@ -1191,9 +1191,17 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
/* Follow with lines associated with the source file. */
if (line_num < src->lines.size ())
- output_intermediate_json_line (lineso, &src->lines[line_num], line_num,
- (last_non_group_fn != NULL
- ? last_non_group_fn->m_name : NULL));
+ {
+ unsigned size = last_non_group_fns.size ();
+ function_info *last_fn = size > 0 ? last_non_group_fns[size - 1] : NULL;
+ const char *fname = last_fn ? last_fn->m_name : NULL;
+ output_intermediate_json_line (lineso, &src->lines[line_num], line_num,
+ fname);
+
+ /* Pop ending function from stack. */
+ if (last_fn != NULL && last_fn->end_line == line_num)
+ last_non_group_fns.pop_back ();
+ }
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* [gcc(refs/users/marxin/heads/PR98273-gcov-nested-functions)] gcov: fix line output for nested functions in JSON format
@ 2020-12-14 16:04 Martin Liska
0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2020-12-14 16:04 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f3210d3d46b1c94cfd48a8117e55b68ad6e9a284
commit f3210d3d46b1c94cfd48a8117e55b68ad6e9a284
Author: Martin Liska <mliska@suse.cz>
Date: Mon Dec 14 14:00:08 2020 +0100
gcov: fix line output for nested functions in JSON format
gcc/ChangeLog:
PR gcov-profile/98273
* gcov.c (output_json_intermediate_file): Use stack of nested
functions for lines in a source file. Pop when a function ends.
Diff:
---
gcc/gcov.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/gcc/gcov.c b/gcc/gcov.c
index daa1266db86..8dcec9432a6 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1165,7 +1165,7 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
json::array *lineso = new json::array ();
root->set ("lines", lineso);
- function_info *last_non_group_fn = NULL;
+ vector<function_info *> last_non_group_fns;
for (unsigned line_num = 1; line_num <= src->lines.size (); line_num++)
{
@@ -1177,7 +1177,7 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
it2 != fns->end (); it2++)
{
if (!(*it2)->is_group)
- last_non_group_fn = *it2;
+ last_non_group_fns.push_back (*it2);
vector<line_info> &lines = (*it2)->lines;
/* The LINES array is allocated only for group functions. */
@@ -1191,9 +1191,17 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
/* Follow with lines associated with the source file. */
if (line_num < src->lines.size ())
- output_intermediate_json_line (lineso, &src->lines[line_num], line_num,
- (last_non_group_fn != NULL
- ? last_non_group_fn->m_name : NULL));
+ {
+ unsigned size = last_non_group_fns.size ();
+ function_info *last_fn = size > 0 ? last_non_group_fns[size - 1] : NULL;
+ const char *fname = last_fn ? last_fn->m_name : NULL;
+ output_intermediate_json_line (lineso, &src->lines[line_num], line_num,
+ fname);
+
+ /* Pop ending function from stack. */
+ if (last_fn != NULL && last_fn->end_line == line_num)
+ last_non_group_fns.pop_back ();
+ }
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-14 16:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-14 13:01 [gcc(refs/users/marxin/heads/PR98273-gcov-nested-functions)] gcov: fix line output for nested functions in JSON format Martin Liska
2020-12-14 16:04 Martin Liska
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).