Anyone written a script that turns gcov branch coverage output into compiler warning format?

StackOverflow https://stackoverflow.com/questions/1957635

  •  21-09-2019
  •  | 
  •  

Question

Most code editors know how to take a reasonably standard format of file_path, line_number, message_text and hyperlink into code. They know how because that's how they display compiler warnings. Visual Studio does it, and Source Insight is trivial to configure for that. If I have to I will write the script myself, but maybe someone has done so already.

Looking for a script that takes gcc's gcov branch coverage output and translates it into that format.

Was it helpful?

Solution

You can process the output of gcov with a simple awk script:

/.*:.*:/ {
    split($2,tokens,":");
    LINE=tokens[1];
}

/#####:/ { print FILENAME ":" LINE ": warning: Line not executed"}

/branch/ {
    if ($4 == 0)
    print FILENAME ":" LINE ": warning: " $0;
}

Run with awk -f warn.awk main.c.gcov and it will convert the output to:

main.c.gcov:35: warning: branch 0 taken 0 (fallthrough)
main.c.gcov:37: warning: Line not executed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top