I know for myself: the earlier I’m able to fix a bug, the better. So I’m always grateful for things which help me to find issues in my sources as early in the development process as possible. Eclipse and CodeWarrior already help me to find syntax errors in my code while I’m typing:
With the built-in syntax checker of Eclipse, this helps me many times to get things right without the need to build my code with the compiler. But when I’m able to compile successfully my code, this does not mean it is without bugs. It would be good to catch as many errors *before* downloading and running it on the target.
I have presented a while ago PC-lint: but this does not come free of charge. The good news is that the new Eclipse version in CodeWarroir for MCU10.3 has static code analyser built-in: Code name “Codan”: not as powerful as PC-lint, but good enough as a little helper.
C/C++ Code Analysis
The static C/C++ Code Analysis is available if I select the project and use the context menu:
But when I run this, nothing seems to happen?
Enabling Code Analysis
The reason is that CodeWarrior has it disabled by default in a new workspace. It is enabled/disabled for each project. What I recommend is to enable it on the workspace level. Using the menu Window > Preferences and filter for ‘code’ shows the setting:
Usually I enable all the ‘Potential Programming Problems’:
The cool thing is: now it parses my sources in the background for problems:
Additionally it flags the problem place in the source view:
At any time, Code Analysis is run with the context menu on the project folder.
Customizing Code Analysis
The analysis is customized using the ‘Customize Selected..‘ Button:
I can configure the behaviour, such as if things are worth an error or are just a warning:
For example I can specify inclusion or exclusion pattern/files for each message:
❓ I have not found a way to configure/disable messages directly in the source files. That’s something I really like with PC-lint, but I’m not able to do with the Eclipse C/C++ Code Analysis?
I expect the features and functionality of the C/C++ Code Analysis to grow and extend over time in Eclipse. Right now it is able to catch not that many problems, and some are rather basic. But still: it helps to get my code right the first time. There are sometimes bogus messages, but then I can disable the messages or add that file to the ‘exclusion’ list. And even a small little helper adds to the benefits of Eclipse.
Happy analysing 🙂
Is there any way to export these settings to a file, so I can import them into other projects, instead of setting it up for each one?
yes, the normal File > Export > Preferences (see https://mcuoneclipse.com/2012/04/04/copy-my-workspace-settings/) should do this.
Pingback: Tutorial: IAR + FreeRTOS + Freedom Board | MCU on Eclipse
Pingback: Top 10 Customization of Eclipse Settings | MCU on Eclipse
We think support in PVS-Studio the Eclipse environment (Win). PVS-Studio is a static analyzer for C/C++/C++11 ( http://www.viva64.com/en/pvs-studio/ ). I want to see if there is interest from people to it. Please write to us, who would it be interesting – http://www.viva64.com/en/about-feedback/
I would be interested in such an Eclipse integration for sure. Right now PVS Studio looks more ‘Desktop’ oriented. I’m wondering how applicable it would be for the Embedded World? I think very well if it would be nicely intergrated in Eclipse and for example gcc?
Now stand alone version of PVS-Studio is available. Description: http://www.viva64.com/en/b/0219/ , Example of use: http://www.viva64.com/en/b/0221/
Andrey, any news on an Eclipse integration/version?
Pingback: Eclipse CODAN (Static Code Analysis) for C/C++ | MCU on Eclipse