How to list all calls of a function at runtime?

杀马特。学长 韩版系。学妹 提交于 2019-12-09 21:51:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!