2

I am aware that some IDEs, like MS Studio have an option to find all uses of a variable in code.

However, from what I can see, that finding stops when you pass a variable as a parameter to a function. I.e. it does not track further usage of that variable within the called function or functions to which it, in turn, passes the variable.

Is there any tool (code browser, IDE, call it what you will) which will let me do this for c/c++, preferably for free?

I don't mind swapping operating systems on those occasions when I want to use this. I have Googled, but didn't find anything (maybe I didn't look deeply enough), so I won't place any restrictions on o/s or budget.

0

1 Answer 1

1

This isn't finding all "uses" of a variable.

It is tracking all uses of a computed value. (You could call the function with argument x+y and consider tracking that, too). Generally this is called "program slicing".

I think Code Surfer will do what you want. The authors, GrammaTech, build world-class program analysis tools.

Summary:

  • Code Browser
  • Traces uses of variables and expressions within and across function boundaries
  • Not free
7
  • Hmm, you took it one stop beyond what I had considered. While it is true that I did not consider passing x+y as a a parameter when I am interested in x, I find that I don't want that. However, there may well be other gotchas. I really was just interested if following a single datum (variable). I had been thinking of objects of a class, but there might, as you say, be more to it than that. Apr 14, 2015 at 12:09
  • Ha ha -but considering "CodeSurfer/x86 is not currently available for sale to the public. The CodeSurfer Programmable Package includes the GUI, the Path Inspector, and the scripting language / API. U.S. pricing for a floating license is $6990, including the first year of maintenance. A minimum number of licenses is required" - you will have to do better than "I think Code Surfer will do what you want" ;-) I could write and ask them, but when I stupidly said "no budget limit", I wasn’t quite expecting that & doubt that my employer would go for it. Apr 14, 2015 at 12:11
  • You asked, you received. CodeSurfer has an extremely good reputation. These tools are hard to build, and the number of people that are willing to buy them is small, so I'm not surprised at the price. I don't understand the bit about "Not available to the public"...sounds like you just described how to get it, even if that's a price you don't want to pay.
    – Ira Baxter
    Apr 14, 2015 at 14:42
  • "You'll have to do better than 'I think'".... OK, I'll do better. I'm very sure they do this well. I will admit that I have not used the product. But I track the technology to do this kind of thing, and Grammatech is one of the clear leaders here.
    – Ira Baxter
    Apr 14, 2015 at 17:33
  • 1
    If you point to a specific assignment of variable (there may be more than one; it may be a side effect of a pointer update, it may be binding to an argument list element), a forward slicer will find all the uses of that particular assignment, and let you follow the downstream impact as far as you want in any direction, including through function arguments, via indirect pointer access to the variable, etc. Grammatech (famously) claims to provide both forward slicing and backward slicing ("what computations fed into this this assignment"). I suggest you ask Grammatech for more details.
    – Ira Baxter
    Apr 15, 2015 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.