I am new to Arduino and gcov. I have a .ino
sketch file, avr-gcov
, and avr-gcc
from Arduino library in the same directory. Could someone guide me to the steps I should take to run avr-gcov
on my .ino
file and get a .gcov
file?
These are the things I have tried so far. When I run
./avr-gcov filename.ino
,
it throws the error filename.gcno: cannot open notes file
. My assumption was that I needed create a .gcno
file before running gcov. So I tried to create one using the command
./avr-gcc -c -Wall -pg -fprofile-arcs -ftest-coverage filename.ino
.
But doing so gives a warning: linker input file unused because linking not done and doesn't produce anything.
I tried to create an object code from the sketch file by passing -o
flag but that throws the error avr-gcc: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found
.
Any help would be appreciated.
-
why do you want to use gcov?jsotola– jsotola2023年04月03日 14:57:37 +00:00Commented Apr 3, 2023 at 14:57
-
The sketch file is very large. I would like to get the code coverage and identify the blocks that are reached more often and generate a control flow graph based on that.Md Jabir Hossain– Md Jabir Hossain2023年04月03日 15:04:09 +00:00Commented Apr 3, 2023 at 15:04
1 Answer 1
Code coverage by "gcov" has some prerequisites:
- Instrumented code to count the number the control flow reaches certain points of the program. This is done via the options you tried.
- Linking with the support library. This is done via the options you tried. The result is a "gcno" file for each translation unit.
- This support library expects a file system to store the accumulated counter values.
- Running the application, the support library creates a "gcda" file for each translation unit. This file holds the accumulated counter values.
- "gcov" expects all these "gcno" and "gcda" files to generate an annotated listing.
Since common Arduinos don't have a file system, the prerequisites cannot be fulfilled. This is the reason why you receive the error messages.
So what can you do now? There are multiple alternatives, but this site is not appropriate to present you ready-made solutions.
- You can compile the sketch for the PC. For this you need to provide all used Arduino functions, for example as mocks or simulation.
- You can provide the missing functions on your own, some kind of persistent storage, and finally transfer the data as "gcda" files to your PC. (This sounds complicated and resource expensive, and it is. However, it's doable, I did this years ago with another embedded system and a former version of "gcov".)
- Refrain from using "gcov" and try other approaches of finding your hot spots. For example, toggle different port pins and/or with different patterns to literally "see" which code is executed. You need a good oscilloscope or logic analyzer for this.