|
From: Nicholas N. <nj...@cs...> - 2005-04-21 13:25:02
|
On Thu, 21 Apr 2005, Rex Walburn wrote: > My aim is that I want to know which variables have been accessed and > written to or modified and how many times in a particular area of the > source code(or in the whole source code). The source code could be a > collection of 200 files. I'm curious why you want to know these statistics -- Is this a profiling exercise? This is trickier than it may first sound... what is the definition of a "variable"? What about compound structures like arrays and struct -- are they a single variable or do you consider the individual elements as variables? What about stack vs. static vs. heap-allocated variables? Etc. > One way to do that was to parse the source code and do a data flow > analysis, but that would mean I would have to write a parser for C, C++, > FORTRAN or any other language. The advantage of Valgrind is that it > works with symbols and hence it does not matter which programming > language the source code was written in. If I can map an address to > atleast an entry in the symbol table, and check with "dullard" how many > times the address was read from, written to and modified, then my > problem is almost solved. I see. AIUI the symbol table handles code addresses, eg. function names, but not variable names. Variable names are in the debugging information. VG_(describe_addr)() in vg_symtypes.c provides some functionality for converting code addresses to variable names. It's used by Helgrind. You need to call VG_(needs_data_syms)() before using it. It might do something like what you want, but I'm not certain. Local variables on the stack are going to be tricky to deal with, since you'll have to identify when you're entering/exiting functions, which is harder than it first seems. > What did you mean by source-level instrumentation ? A bit like the source code parsing/data flow analysis that you mentioned -- add instrumentation to the original source code, which would require parsing the source code, and some static analysis. Then you would run the program and get the stats. N |