0

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.

asked Apr 3, 2023 at 12:17
2
  • why do you want to use gcov? Commented 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. Commented Apr 3, 2023 at 15:04

1 Answer 1

2

Code coverage by "gcov" has some prerequisites:

  1. Instrumented code to count the number the control flow reaches certain points of the program. This is done via the options you tried.
  2. Linking with the support library. This is done via the options you tried. The result is a "gcno" file for each translation unit.
  3. This support library expects a file system to store the accumulated counter values.
  4. Running the application, the support library creates a "gcda" file for each translation unit. This file holds the accumulated counter values.
  5. "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.

  1. You can compile the sketch for the PC. For this you need to provide all used Arduino functions, for example as mocks or simulation.
  2. 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".)
  3. 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.
answered Apr 4, 2023 at 8:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.