Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Static analysis tools
Static analysis tools [message #532438] Sun, 09 May 2010 23:13 Go to next message
Eclipse UserFriend
I'm writing code for the PIC32MX using Microchip's GCC-based C32 compiler. I'd like to use static analysis tools to check my code (gnu99 style).

The trouble is, I can't use cppcheck because the C32 header files contain dozens of preprocessor macro flags to select the appropriate code for specific chips and cppcheck tries to analyse all possible combinations of them.

I can't use splint because it cannot check C99 code.

I was thinking of trying clang (scan-build to be more precise), but it works by interposing as the compiler so you can just run "scan-build make". My project does not use make, and I can't figure out how to get Eclipse to do anything useful with scan-build.

So I have two questions: has anyone gotten clang's scan-build to work with Eclipse's internal builder, OR is there a better solution for static checking under Eclipse?
Re: Static analysis tools [message #540136 is a reply to message #532438] Tue, 15 June 2010 02:58 Go to previous messageGo to next message
Eclipse UserFriend
Sorry for the bump, but I've done a lot more looking since I asked this and come up with nothing. Do people use external tools? Is it the case that not a single C developer using Eclipse CDT does any static analysis :p ? Or am I looking in the wrong places?

[Updated on: Tue, 15 June 2010 02:58] by Moderator

Re: Static analysis tools [message #540242 is a reply to message #540136] Tue, 15 June 2010 09:17 Go to previous messageGo to next message
Eclipse UserFriend
detly wrote on Tue, 15 June 2010 02:58
Sorry for the bump, but I've done a lot more looking since I asked this and come up with nothing. Do people use external tools? Is it the case that not a single C developer using Eclipse CDT does any static analysis Razz ? Or am I looking in the wrong places?

No, that's because it is not quite clear what you are doing Wink

CDT got built-in static analysis in 7.0 using young Codan framework which has limited set of checkers at the moment. It is possible to do SA with an external tool but you may need to be a bit determined in order to set it up well.

Quote:
So I have two questions: has anyone gotten clang's scan-build to work with Eclipse's internal builder, OR is there a better solution for static checking under Eclipse?

Why are you using internal builder? I would suggest to run your external tool in Make Targets View but that won't work with Internal builder because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=304774

Andrew
Re: Static analysis tools [message #540396 is a reply to message #540242] Tue, 15 June 2010 21:41 Go to previous messageGo to next message
Eclipse UserFriend
Andrew Gvozdev wrote on Tue, 15 June 2010 09:17
detly wrote on Tue, 15 June 2010 02:58
Sorry for the bump, but I've done a lot more looking since I asked this and come up with nothing. Do people use external tools? Is it the case that not a single C developer using Eclipse CDT does any static analysis Razz ? Or am I looking in the wrong places?

No, that's because it is not quite clear what you are doing Wink



Well, I'm writing firmware for the PIC32 using piccbuilder. The compiler is pretty much GCC 3.4, but goes by the name "pic32-gcc".

I avoid any dynamically allocated memory, so I'm not too interested in detecting memory leaks. But there are lots of little things that I know static analysis tools can pick up that aren't malloc-related mistakes Smile

Quote:

CDT got built-in static analysis in 7.0 using young Codan framework which has limited set of checkers at the moment. It is possible to do SA with an external tool but you may need to be a bit determined in order to set it up well.



So... where do I begin? Has anyone written up how to do it with one particular tool?

Quote:

Quote:
So I have two questions: has anyone gotten clang's scan-build to work with Eclipse's internal builder, OR is there a better solution for static checking under Eclipse?

Why are you using internal builder?


So far I haven't had any reason not to. But, I gave it a shot, and it made no difference. I set the build command to

scan-build make -k -j4 all 


...which, looking in the console, does exactly the same thing as...

make -k -j4 all 


No reports are generated, nothing seems to be done by scan-build whatsoever. Everything is compiled as normal.

Incidentally, I've never been able to get Eclipse to "clean" a project using the external builder. It just says

make -k -j4 all 
make: Nothing to be done for `all'.


Quote:
I would suggest to run your external tool in Make Targets View but that won't work with Internal builder because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=304774



I don't understand what "run your external tool in Make Targets View" means. Does it require that I manually write a makefile first?
Re: Static analysis tools [message #540397 is a reply to message #540396] Tue, 15 June 2010 21:47 Go to previous messageGo to next message
Eclipse UserFriend
detly wrote on Tue, 15 June 2010 21:41

Incidentally, I've never been able to get Eclipse to "clean" a project using the external builder. It just says

make -k -j4 all 
make: Nothing to be done for `all'.




I just figured out why this is... that output seems to be from a subsequent automatically triggered build (of course), and I don't see the results of clean (right click on the project, select "Clean") because it's automatically cleared from the console (???).

Once I created the target in the make file view, it left it in the console, I saw this:

make: del: Command not found
make: [clean] Error 127 (ignored)


So it's trying to use "del" on Debian instead of "rm". Not sure if that's an issue with Eclipse or piccbuilder.

[Updated on: Tue, 15 June 2010 22:03] by Moderator

Re: Static analysis tools [message #540593 is a reply to message #540397] Wed, 16 June 2010 11:32 Go to previous messageGo to next message
Eclipse UserFriend
detly wrote on Tue, 15 June 2010 21:41

Once I created the target in the make file view, it left it in the console, I saw this:

make: del: Command not found
make: [clean] Error 127 (ignored)


So it's trying to use "del" on Debian instead of "rm". Not sure if that's an issue with Eclipse or piccbuilder.

Which toolchain did you use creating the project? I see rm -f in any project I tried and I am on Windows.

BTW which version of eclipse you are using? You are on debian, I hope you are not using 3.2, are you?

Quote:
I just figured out why this is... that output seems to be from a subsequent automatically triggered build (of course), and I don't see the results of clean (right click on the project, select "Clean") because it's automatically cleared from the console (???).

You should disable Project->Build Automatically, that's what most of users do.


Quote:
So... where do I begin? Has anyone written up how to do it with one particular tool?

I suggest to switch to external builder. Ensure you can build and clean in context menu (right-click on the project) but it is really a separate issue.

Then you can create a new "Target" in the Make Targets View. It does not have to be related to makefile. For your case, I would uncheck "Use builder settings" and enter whatever command you want to use for static analysis ([scan-build make all] I suppose? or "clang Hello.cpp") You can use "Make target" field to organize your targets (i.e. move "all" there), it is simply appended to the build command. Uncheck "Run all project builders", you don't need that.

The advantage of running in the Make Targets View (vs. Run/Launch/External-Tool facility or plain command line) is that you get Error Parsers parse build output and create markers for jumping and visualizing the errors in UI. You may need to adjust the parsers or create a new one, but it's possible GCC Error Parser would be able to pick some as it is.

Another way is to create a different build configuration (project context menu->Build Configurations->Manage->New and replace build command with "scan-build make". Whatever suits you better.

Andrew
Re: Static analysis tools [message #540601 is a reply to message #540593] Wed, 16 June 2010 12:04 Go to previous message
Eclipse UserFriend
Andrew Gvozdev wrote on Wed, 16 June 2010 11:32

Which toolchain did you use creating the project? I see rm -f in any project I tried and I am on Windows.

BTW which version of eclipse you are using? You are on debian, I hope you are not using 3.2, are you?



Toolchain is piccbuilder (pic32-gcc), listed as "PIC Cross Target Application". Eclipse is 3.5.2, CDT is 6.0.2

If the "del" instead of "rm" is a problem with piccbuilder, I'll file a bug there.

Quote:

Then you can create a new "Target" in the Make Targets View. It does not have to be related to makefile. For your case, I would uncheck "Use builder settings" and enter whatever command you want to use for static analysis ([scan-build make all] I suppose? or "clang Hello.cpp") You can use "Make target" field to organize your targets (i.e. move "all" there), it is simply appended to the build command. Uncheck "Run all project builders", you don't need that.



Yeah, I tried that. It ran scan-build, but it didn't actually do anything. That is, the code was compiled and linked, but no reports were generated.

Maybe I can take the makefile generated by Eclipse and see whether I can do it from the command line.

Quote:

Another way is to create a different build configuration (project context menu->Build Configurations->Manage->New and replace build command with "scan-build make". Whatever suits you better.



Ah, that was the first thing I tried, with the same results.

It doesn't have to be clang/scan-build though. The whole point of this post was to just to get *something* to work. I'll keep tinkering with it.

[Updated on: Wed, 16 June 2010 12:05] by Moderator

Previous Topic:C/C++ formatter API/plug-in in CDT or Eclipse
Next Topic:Trouble running sample code
Goto Forum:
  


Current Time: Wed May 07 14:16:50 EDT 2025

Powered by FUDForum. Page generated in 0.04038 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top