|
-
August 11th, 2009, 07:59 AM
#1
Is there a good way to find the callers to a particular function?
Hello. I am trying to understand and modify a complex programs written by others. I found the function which I need to modify and would like to get a list of caller(s) to this function. Given that there are hundreds of files and classes, it would be ineffective to go through each file to search for the callers. Is there a good way to do that? I know that there are programs which display the relationships among classes graphically. Something like that for member functions would be great. I am looking for a solution without the use of a debugger. Thanks.
-
August 11th, 2009, 08:11 AM
#2
Re: Is there a good way to find the callers to a particular function?
#include <iostream>
using namespace std;
/*
//this is the function u want to monitor the caller.
void foo()
{
cout << "foo" << endl;
}
*/
//now, u can modify foo as follow
//in your project, u should modify both the header file and the implemention file of function foo
//when foo has some papameter, it is similar
void foo_rename()
{
cout << "foo" << endl;
}
void foo_wrapper(const char* name)
{
cout << name << endl;
foo_rename();
}
#define foo() foo_wrapper(__FUNCTION__)
int main()
{
foo();
return 0;
}
Last edited by baihacker; August 11th, 2009 at 08:18 AM.
-
August 11th, 2009, 08:17 AM
#3
Re: Is there a good way to find the callers to a particular function?
eh, when the function has a default parameter, it becomes more difficult.
#include <iostream>
using namespace std;
/*
void foo(int x)
{
cout << x << endl;
}
*/
void foo_rename(int x)
{
cout << x << endl;
}
void foo_wrapper(int x, const char* name)
{
cout << name << endl;
foo_rename(x);
}
#define foo(x) foo_wrapper(x, __FUNCTION__)
int main()
{
foo(1);
return 0;
}
-
August 11th, 2009, 08:42 AM
#4
Re: Is there a good way to find the callers to a particular function?
If you're using Visual Studio, then bring up the 'Call Browser' window.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
August 11th, 2009, 11:26 AM
#5
Re: Is there a good way to find the callers to a particular function?
 Originally Posted by hajimeml
Hello. I am trying to understand and modify a complex programs written by others. I found the function which I need to modify and would like to get a list of caller(s) to this function. Given that there are hundreds of files and classes, it would be ineffective to go through each file to search for the callers. Is there a good way to do that? I know that there are programs which display the relationships among classes graphically. Something like that for member functions would be great. I am looking for a solution without the use of a debugger. Thanks.
Have you tried simply searching for the function name in all of the .cpp files using the directory search tools provided by the OS?
Here is another option. You could download the free full trial and perhaps your company will buy it if you think it is useful. I have seen others at my organization use it and it does a pretty good job of building graphical function call charts.
http://www.scitools.com/
-
August 11th, 2009, 07:54 PM
#6
Re: Is there a good way to find the callers to a particular function?
 Originally Posted by JohnW@Wessex
If you're using Visual Studio, then bring up the 'Call Browser' window.
I am using Borland C++ Builder Professional 6.
-
August 11th, 2009, 09:46 PM
#7
Re: Is there a good way to find the callers to a particular function?
Mistype your function name and compile, you should get errors where it is called. Heavy handed but it works.
-
August 13th, 2009, 07:25 PM
#8
Re: Is there a good way to find the callers to a particular function?
The scitools's Understand software seems to be what I need eventually. I will give it a try. Thank you very much for letting me know.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|