Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > C code analisys tool

Reply
Thread Tools

C code analisys tool

 
 
kazak
Guest
Posts: n/a
 
      05-11-2006
Hello,
I am looking for C code analysing tool,

My problem is:
To discover the portion of code that depends on(deals with) a number
of specified structures and variables.
Sample:

void funct(struct header* h)
{
.....

memcpy(buff,h,sizeof(struct header));
func2(buff)
.....
a kind of other code....

}
The idea is to detect all the code that depends on or deals with "h"

Do you know the tools that can solve the problem?

Thanks a lot.
Andrey

 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      05-11-2006
kazak a écrit :
> Hello,
> I am looking for C code analysing tool,
>
> My problem is:
> To discover the portion of code that depends on(deals with) a number
> of specified structures and variables.
> Sample:
>
> void funct(struct header* h)
> {
> ....
>
> memcpy(buff,h,sizeof(struct header));
> func2(buff)
> ....
> a kind of other code....
>
> }
> The idea is to detect all the code that depends on or deals with "h"
>
> Do you know the tools that can solve the problem?
>
> Thanks a lot.
> Andrey
>


If you are using the lcc-win32 IDE put the cursor in your identifier and
press CTRL+F8. This will display all usages of that identifier in all
loaded files. If you want to display the usage just within a function
right click in the identifier and choose the "Locals in <function name>"
option from the context menu that appears.

The second option will show a slice of all lines that use the given
identifier ignoring all lines where the identifier does not appear. This
is very handy for seeing the actual usage of a variable

http://www.cs.virginia.edu/~lcc-win32

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      05-11-2006
kazak wrote:
> Hello,
> I am looking for C code analysing tool,
>

This sort of thing might be provided by you tool chain, check the docs.

--
Ian Collins.
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      05-11-2006
Ian Collins a écrit :
> kazak wrote:
>
>>Hello,
>>I am looking for C code analysing tool,
>>

>
> This sort of thing might be provided by you tool chain, check the docs.
>


Probably not. This very common option is absent, for instance, in the
latest version of Visual Studio (VC even if that software takes 3GB
disk space and as a zillion options.

The gcc IDE DevC++ doesn't do it either. Under linux, most IDEs do not
do any syntax analysis.

Of course

grep MyId *.c

will do it (sort of) but it will not eliminate comments and doesn't
follow scopes.
 
Reply With Quote
 
pibru@tin.it
Guest
Posts: n/a
 
      05-11-2006
vim+ctags
kazak wrote:
> Hello,
> I am looking for C code analysing tool,
>
> My problem is:
> To discover the portion of code that depends on(deals with) a number
> of specified structures and variables.
> Sample:
>
> void funct(struct header* h)
> {
> ....
>
> memcpy(buff,h,sizeof(struct header));
> func2(buff)
> ....
> a kind of other code....
>
> }
> The idea is to detect all the code that depends on or deals with "h"
>
> Do you know the tools that can solve the problem?
>
> Thanks a lot.
> Andrey
>

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-11-2006
jacob navia wrote:
> Ian Collins a écrit :
>
>> kazak wrote:
>>
>>> Hello,
>>> I am looking for C code analysing tool,
>>>

>>
>> This sort of thing might be provided by you tool chain, check the docs.
>>

>
> Probably not. This very common option is absent, for instance, in the
> latest version of Visual Studio (VC even if that software takes 3GB
> disk space and as a zillion options.
>
> The gcc IDE DevC++ doesn't do it either. Under linux, most IDEs do not
> do any syntax analysis.
>

That does appear to be a common trend. Bit of a pain for legacy code
support.

> Of course
>
> grep MyId *.c
>
> will do it (sort of) but it will not eliminate comments and doesn't
> follow scopes.


But it does encourage meaningful names, try greping for 'h'...

--
Ian Collins.
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      05-11-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) a écrit :
> vim+ctags


ctags will give you all usage of a variable within a function?

How do you do that?


Just curious...

jacob
 
Reply With Quote
 
Mark Laczynski
Guest
Posts: n/a
 
      05-12-2006
It sounds to me like you just want to cross reference this h variable.
I would use vim with ctags and/or cscope. To learn how to use any of
these tools w/ vim just check out vim's help system.

Mark

kazak wrote:
> Hello,
> I am looking for C code analysing tool,
>
> My problem is:
> To discover the portion of code that depends on(deals with) a number
> of specified structures and variables.
> Sample:
>
> void funct(struct header* h)
> {
> ....
>
> memcpy(buff,h,sizeof(struct header));
> func2(buff)
> ....
> a kind of other code....
>
> }
> The idea is to detect all the code that depends on or deals with "h"
>
> Do you know the tools that can solve the problem?
>
> Thanks a lot.
> Andrey


 
Reply With Quote
 
Ben C
Guest
Posts: n/a
 
      05-12-2006
On 2006-05-11, jacob navia <(E-Mail Removed)> wrote:
> (E-Mail Removed) a écrit :
>> vim+ctags

>
> ctags will give you all usage of a variable within a function?
>
> How do you do that?


I don't know if you can do that with ctags, but cscope can give you all
the references to a variable, and, in some versions, all the assignments
to a variable.

But the OP's problem is much harder than this:

OP> My problem is: To discover the portion of code that depends on(deals
OP> with) a number of specified structures and variables. Sample:

OP> void funct(struct header* h)
OP> {
OP> ....
OP>
OP> memcpy(buff,h,sizeof(struct header));
OP> func2(buff)
OP> ....
OP> a kind of other code....
OP>
OP> }

OP> The idea is to detect all the code that depends on or deals with "h"

The type of buff isn't given, but let's assume it's char * for the sake
of argument.

So now anything that deals with buff deals with *h, and we have to follow
a memcpy to see this.

I think a runtime tool would be an easier task than a static tool here.
What's needed is a kind of "radioactive data" where the actual bytes
comprising *h can be made to glow in the dark so we can follow them
through the system.

You could possibly set something up with a combination of gdb's
watchpoints and commands, but if *h is big this might be difficult.

DTrace from Solaris may be able to do the job:

http://www.sun.com/bigadmin/content/dtrace/
 
Reply With Quote
 
kazak
Guest
Posts: n/a
 
      05-12-2006
No greps or cross references can help, cause I don't care about
variable only, I want discover all code that deals with it(it's
execution depends on that variable, but it can be copied in "buff" for
example and tool must look for buff dependent code and futher more...)

Static analisys is the way, have found a lot of tools like CIL, ACL2
and other, but using them does not seem to be a trivial task.

I am going to do it for the piece of code in Linux kernel

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Physical sythesis tool PALAC is not supported by Formal Verification tool Conf bbiandov Software 0 12-22-2008 05:25 AM
Html code cleaner - Powerful HTML Code Compression Tool heren ASP .Net 1 09-14-2005 12:39 PM
msn search tool & plishing tool Kue2 Windows 64bit 1 09-02-2005 02:29 PM
need recommendations on what brand, specific computer tool kit to buy (physical tool kits, not software kits/suites) Trevor Smithson Computer Information 1 05-27-2005 01:15 AM
need recommendations on what brand, specific computer tool kit to buy (physical tool kits, not software kits/suites) Trevor Smithson Computer Support 5 05-25-2005 07:48 PM



Advertisments