I have a simple Program:
I would like to see which methods have been called within the method service.DoSomething()
at the breakpoint at line 20 like that:
Unfortunately, in debug-mode at the breakpoint at line 20, the callstack-window doesn´t show me, what calls have been made inside the method service.DoSomething()
.
The goal ist, to understand the call graph faster. Moving through the code via F10, F11 is annoying, confusing and takes much time. Is it possible to get an hirarchical list with all called methods inside service.DoSomething()
using Visual Studio 2022?
I have a simple Program:
I would like to see which methods have been called within the method service.DoSomething()
at the breakpoint at line 20 like that:
Unfortunately, in debug-mode at the breakpoint at line 20, the callstack-window doesn´t show me, what calls have been made inside the method service.DoSomething()
.
The goal ist, to understand the call graph faster. Moving through the code via F10, F11 is annoying, confusing and takes much time. Is it possible to get an hirarchical list with all called methods inside service.DoSomething()
using Visual Studio 2022?
2 Answers
Reset to default 1To display method calls in Visual Studio, you can use static analysis tools to display the internal calls. Here are several official documents for your reference:
Document 1 (A static analysis tool that displays the calling relationships in the code rather than all the paths actually executed during debugging.)
Document 2 (Based on static code analysis, it can help you understand the code structure, but it does not reflect the dynamic behavior at runtime.
In addition, as @T.S. said in the comment area, your problem is similar to this post, and you can also try to use the methods in it.
The closest I know of is Visual studios Tracing performance collection mode. This will record the entry and exit of each method call, so should give an accurate call count. I'm not sure it is possible to start this from the debugger, so you may need to run the profiler, and search for DoSomething
to find the callgraph.
But it is not very clear what the actual goal is. In most cases I would read the code, or use static analysis tools, to get a better idea of what the method can call, and place breakpoints in any methods of interest. Or just step thru the code to find that it does. Tracepoints can also be very useful to print statements at arbitrary positions.
If the goal is to learn the code base there are various kinds of visualizers and analyzers, like type or project dependency diagrams. Some are built in to visual studio, some by third party plugins. But in my experience, readability is mostly affected by the existing structure and naming. A well organized project can be understood with minimal tooling, and a disorganized project is difficult to understand no matter what tools you use.
service.DoSomething()
in your picture? I do understand that you described everything in text, but why the picture then, what it shows? Please see: Why should I not upload images of code/data/errors? – Sergey A Kryukov Commented yesterday