0

I'm using PVS-Studio in docker image based on ubuntu:18.04 for cross-compiling a couple of files with arm-none-eabi-gcc. After doing pvs-studio-analyzer trace -- .test/compile_with_gcc.sh strace_out file is successfully created, it's not empty and contains calls to arm-none-eabi-gcc.

However pvs-studio-analyzer analyze complains that "No compilation units were found". I tried using --compiler arm-none-eabi-gcc key with no success.

Any ideas?

Amomum
  • 6,217
  • 8
  • 34
  • 62
  • Unfortunately, to answer your question, we need more information than your question contains. To research the problem, we need to analyze compiler calls in the strace_out file. Could you please share this file with us? You can upload it to a cloud resource and post a link here. – AndreyKarpov Feb 17 '21 at 12:35
  • @AndreyKarpov sure, https://pastebin.com/4mSMvM9e – Amomum Feb 17 '21 at 18:54
  • Hello, we looked at the strace_out file and noticed that the sources are in the root folder. There is an assumption that the analyzer lacks permissions to analyze them. Try running the analysis using sudo or under the admin account. – AndreyKarpov Feb 18 '21 at 08:40
  • @AndreyKarpov Well, it is inside docker container with no specified user, so it's already run under root. – Amomum Feb 18 '21 at 22:39

2 Answers2

1

The problem was in my approach to compilation. Instead of using a proper build system, I used a wacky shell script (surely, I thought, using a build system for 3 files is an overkill, shell script won't hurt anybody). And in that script I used grep to redefine one constant in the source - kinda like that: grep -v -i "#define[[:blank:]]\+${define_name}[[:blank:]]" ${project}/src/main/main.c | ~/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi-gcc -o main.o -xc

So compiler didn't actually compiled a proper file, it compiled output of grep. So naturally, PVS-Studio wasn't able to analyze it.

TL;DR: Don't use shell scripts as build system.

Amomum
  • 6,217
  • 8
  • 34
  • 62
  • bumped into the same problem: packet build system was removing the sources after the compilation. So it should be pointed somewhere that the sources must be available to PVS-studio at both 'trace' and 'analyze' steps. – Vladimir Kunschikov Jul 31 '22 at 20:31
0

We have reviewed the stace_out file. It can be handled correctly by the analyzer, if the source files and compilers are located by the absolute path in the stace_out file. We have a suggestion what might help you. You can "wrap" the build command in a call to pvs-studio-analyzer -- trace and pvs-studio-analyzer analyze and place them inside your script (compile_with_gcc.sh). Thus, the script should start with the command:

pvs-studio-analyzer trace --

and end with the command:

pvs-studio-analyzer analyze

This way we will make sure that the build and analysis were started at the same container run. If the proposed method does not help, please describe in more detail, by commands, the process of building the project and running the analyzer. Also tell us whether the container reruns between the build and the formation of strace_out, and the analysis itself. It would also help us a lot if you ran the pvs-studio-analyzer command with the optional --dump-log flag and provided it to us. An example of a command that can be used to do this:

pvs-studio-analyzer analyze --dump-log ex.log

Also, it seems that it is not possible to quickly solve the problem and it is probably more convenient to continue the conversation via the feedback form on the product website.

AndreyKarpov
  • 1,083
  • 6
  • 17
  • I was trying to prepare minimal example for you to reproduce this and I think I accidentally narrowed it down to the actual source of the problem (me :D). I compiled three files, but two of them were excluded from analysis intentionally, only main.c was left. And here's how I compiled it `grep -v -i "#define[[:blank:]]\+${define_name}[[:blank:]]" ${project}/src/main/main.c | ~/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi-gcc -o main.o -xc`. Yeah, no wonder PVS was not able to analyze this file.. I feel kinda sick -_- – Amomum Feb 24 '21 at 22:37
  • Did I understand you correctly, that the problem been found and solved? If so, please, mark the issue as resolved. – AndreyKarpov Feb 28 '21 at 12:44