In an embedded C project which is using a SDK's source and header files, I want to have a list of functions, definitions, and variables that a specific source file is using across the project. In other words, a tool that statically analyzes and lists dependencies of a specific source code without the need to execute functions ( not dynamic) of the source file.
I checked static code analysis tools, but they are mostly linters and do not give me a list of dependencies.
I think this type of work is not being explored by the community and any answer will help a lot.
Thanks
You can try CppDepend and its code query language, here's an example of a cqlinq query to get all methods with their files used by a source file.
from m in JustMyCode.Methods where m.SourceDecl.SourceFile.FileName=="test.cpp"
from mc in m.MethodsCalled
select new { m,mc,mc.SourceDecl.SourceFile.FileName}
Related
I am currently writing a test class in objective c and in that class i am writing unit test cases for the c classes (old classes) that is there in the project.To do unit test i have imported the header file in the test class and in xcode i am able to acess those functions defined in that c class.
But when i try to run unit test cases then i am so many errors in the Foundation framework.
I have tried
Thousand of errors in base classes like NSObject.h,NSObjCRuntime.h
Renamed the .c class to .m which created a list of more errors.
Error I am getting in xcode
I have been hitting my head for last couple of days to fix this !!.
Can anyone have any suggestions or solutions to this issue?
The problem is that .c files are treated as pure C files (in actuality C++) and presumably you are co-mingling C code with Obj-C.
By default, C and C++ files will be set to be Default - C++ Source.
You have two choices.
You could rename the extensions of the offending files to .mm.
Alternatively to preserve the file name, go to File Inspector and change the type to Objective C++ Source. I'm showing you what it would look like. Note since this is a .mm file, it is automatically set to Objective C++ Source. Just set the C files to this type.
The source codes downloaded from internet has a lot of non standard, uncommon header files
from a different depended modules, say.
#include<calendar.h>
or
#include <vconf.h>
Given any header file, is there a way to find out from which files these headers are fetched from?
look at the documentation of the lib to that the header belongs may the best way.
you also may look into the header and note down some function names and search through the lib which does define the symbol that belongs to that function
edit:
ah i thought you have a bunch of libs and headers and you do not know which you have to link to get functionality that is declared in a specific header
In your case looking at documentation from downloaded source code may be the only way (mostly this information is in the INSTALL or README - file)
No, not in general.
The string inside of #include is just a filename, and those can easily be reused by different projects, especially generic names like "calendar.h".
You could try googling the header names, or try to compile and google the function names that are used in the downloaded code, but defined in the missing header file. You could try asking the author of the code, or looking for more information from where you downloaded the code.
I would like to compile the following C file on an embedded platform:
https://github.com/openwsn-berkeley/openwsn-fw/blob/develop/firmware/openos/bsp/chips/at86rf231/radio.c
However, as you can see, on lines 20-26 of radio.c it references "radiotimer_capture_cbt":
typedef struct {
radiotimer_capture_cbt startFrame_cb;
radiotimer_capture_cbt endFrame_cb;
radio_state_t state;
} radio_vars_t;
radio_vars_t radio_vars;
So now I need to hunt down where it is defined and make sure I include the right header.
I have cloned the entire GIT repository here: https://github.com/openwsn-berkeley/openwsn-fw, and I'm looking for a way to compile this easily.
Is there a better way to get this compiled other than going through the brutal dependency nightmare?
My ultimate goal is only to get radio.c compiled and anything it needs. I do not see any makefiles in this project so I'm expecting they want us to use an IDE.
The project seems to use scons as a build system. So the simplest way is to dive into the scons files.
There's a small scons file in the directory containing the linked file and two main script in the top directory.
But if you want to play, first remove headers include, try to compile (using -c) to know which one are really needed. Once you get an object file (.o) you can use nm to identify missing symbols (marked with U.) Good luck …
When I work on someone else's code, I tipically need to abuse of grep in order to find data types declarations etc, and this usually makes me confused.
I'd like to have some tool which analyzes the source code and produces some graphviz-like drawing and allows me to follow dependencies.
Also I've found this on the internet, but I think is taylored for the linux kernel only.
Have you tried doxygen?
Doxygen can produce dot files, and you can build the documentation without changing the source code with the right options set in the Doxyfile.
Do you use an editor that can take advantage of tags ? In Emacs, I just type M-. to go to the definition of a symbol, and M-* to go back to where I was once I have read it. This also enables the command tags-search to grep among the files of the software project (very convenient if they are in multiple directories).
I am trying to use Eclipse and NetBeans for programming in C (not C++). Is there a feature/plugin for them which automatically keeps the source and header files in sync?
As in, when I implement a function in the source file, does it automatically insert the correct lines in the header file?
I did look at solutions like lzz, but they are not what I am looking for.
Eclipse CDT allows you to write a prototype in the header file, and automatically add it to the C file.
Instructions
Add function prototype to .h file void foobar()
Select the function name "foobar" (try double clicking)
In the toolbar click Source -> Implement Method
Wizard it up
Thats probably the best you're gonna get out of the box
Agree with approach proposed by Ryu. In C, I would not automatically create declarations in headers. This should be an explicit action making public some symbol from the C module.
However if declaration/implementation are already setup and you want to modify any of them, I imagine that with Eclipse you may want to use Toggle Function Definition in a possible workflow where you copy in clipboard intermediate toggling results and paste them later over the changed declaration or implementation declaration.
Also use rename refactoring intensively when you change things.