views:

143

answers:

5

I have a function which is called explicitly by 4 other functions in my code base. Then in turn each of these functions is called by at least 10 other functions throughout my code. I know that I could, by hand, trace one of these function calls to the main function of my program (which has 30 function calls) but it seems like this would be a better job for the computer. I just want to know which of the functions in main() is calling this buried function.

Does anyone know of any software that could help?

Also, using a debugger is out of the question. That would have been too easy. The software only runs on a hand held device.

+2  A: 

Comment it out (or better, comment out its prototype) and try to compile your program. You should see, where it is referenced.

gruszczy
+9  A: 

doxygen, correctly configured, is able to output an HTML document with navigable caller list and called-by list for every function in your code. You can generate call graphs as well.

mouviciel
+1 great suggestion.
Stephen Canon
Thanks! This kind of thing is exactly what I've been looking for. I'll start playing with it and see if it helps.
jjfine
That was exactly what I was going to suggest!
kramthegram
+1  A: 

If your platform has an API to capture backtraces, I would just instrument up the function to use those and log them to a file for later analysis. There's no guarantee that this will find all callers (or callers-of-...-of-callers), but if you exercise all of the programs features while logging like this, you should find "most" of them. For relatively simple programs, it is possible to find all callers this way.

Alternatively, many sampling tools can get you this information.

However, I have a suspicion that you may be on a platform that doesn't have a lot of these features, so a static source-analysis tool (like mouviciel suggested) is likely your best option. Assuming that you can make it work for you, this has the added benefit that it should find all callers, not just most of them.

Stephen Canon
+1  A: 

http://cscope.sourceforge.net/ I think this also can be useful.

Mahavir Jain
+1  A: 

I second mouviciel's suggestion of using doxygen for getting this info. The downside is that doxygen is working on the source code. You can only see what functions CAN POTENTIALLY call your function, not the ones that are ACTUALLY CALLING your function. If you are using Linux and you can change the source code of the function in question, you can obtain this info using the backtrace() and the backtrace_symbols() functions.

Suresh Krishnan
+1 Good point about potentially/actually.
mouviciel