问题
Is there any way to list (show in VS, write to file) all callers (objects, functions) of a function while the program is running? Possibly using the debugger?
I need to record all calls (including callers) of a function from the launch of the program to its termination.
A simple scan of the source code or the binary does not do the job because the program could operate as a server which receives requests to call the desired function.
If Visual Studio does not provide this feature, are there any other solutions to this problem?
回答1:
VS profiler tool also would be helpful for you, you could select the method "CPU sampling".
After it finished, you could select "Caller/Callee".
Reference:
https://docs.microsoft.com/en-us/visualstudio/profiling/caller-callee-view
Update: We can export the report:
回答2:
IMO, your best solution is to add logging capabilities.
Find all calls to your function. Print some kind of information to a log file before the function is called. This will give you an annotated history of the function calls.
Another idea is to use a documentation tool, like Doxygen, which can print a "caller" and "callee" diagram. However, this is not during your program's execution.
回答3:
If your program is a .NET application, you can use my Runtime Flow tool to view all callers of a function while the program is running.
来源:https://stackoverflow.com/questions/44960033/how-to-list-all-calls-of-a-function-at-runtime