Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to find the caller(s) of a particular member function?

hajimemlhajimeml Member Posts: 7
Hello. I am trying to understand and modify a very complex program written by others. There are many files, classes and member functions within each class. I have found the member function of interest. Now, I want to know which other functions (i.e. callers) call it. Is there a way to do it? Thanks.

Comments

  • bilderbikkelbilderbikkel Member Posts: 754
    > Now, I want to know which other functions (i.e. callers) call it.
    > Is there a way to do it?
    If you want to know this while debugging, do the following:
    - put a breakpoint at the function you are interested in
    - let the program run to the breakpoint
    - view the call stack. The call stack will show the caller of the function

    Have fun, as the call stack is a great debugging tool!

    Bilderbikkel
  • hajimemlhajimeml Member Posts: 7
    Thanks. I know that there are programs which display the relationship of the classes in figures all at the same time. Something like that for member functions and their corresponding callers would be nice. It is tedious to go through hundreds of files to search for calls to the function(s) I am interested in.
  • LundinLundin Member Posts: 3,711
    Another neat little trick is to alter the function with some debug code:

    [code]void some_function(int x, int y, void(*caller)(void)
    {
    ...
    }


    void some_caller_func ()
    {
    some_function(1, 2, some_caller_func);
    }[/code]

    That way you can watch the function pointer passed and get the address to the caller function.
  • bilderbikkelbilderbikkel Member Posts: 754
    Some profilers can also show the calling of functions. I've used the Shiny C++ profiler (see http://richelbilderbeek.nl/CppToolShiny.htm for links and info) that will also show a call stack mapping.

    Perhaps you might try finding a suitable one.

    See ya, Bilderbikkel
Sign In or Register to comment.