开发者

What is the purpose of the Call Stack window in Visual Studio?

What is the 开发者_如何学运维purpose of the Call Stack window in Visual Studio?


When your code breaks (i.e., when an exception is thrown) the Stack Trace Window will show you all methods that have been called prior to the method that raised the exception, including the parameters for each method and the state of these parameters. This makes debugging easier, especially in more complex call graphs (that is, when you cannot determine by looking at your code who called what other method/property/function).

Just try it, place a breakpoint somewhere in your code (F9), run your code, wait for the breakpoint to be hit and then open the stack window. You'll see all calls up to the current line. You can double click each entry in the stack trace window and the cursor will jump right at it.

In case you wondered: gray lines are method calls of which no source code, or symbols are loaded. You can rightclick these lines and select Load Symbols to load the symbols.


Each time you call a method, an entry is place on the "stack" for that thread describing the method and the parameters used to call the method. When the method returns, the method and it's parameters are removed from the stack. That's how the operating environment knows where to return when a method finishes. It just removes the top entry from the stack, cleans up any local variables that were created during that stack frame, and returns to the previous method. (That's over simplified, but generally the idea.)

You can think of it literally as a "stack" of the instructions that got you here.

That's what it means to the operating environment.

To the developer, the practical purpose is to help you understand why your program is in the state it is in. Whenever execution of the program stops in the debugger, either by breakpoint or by an exception being thrown (depending on your Visual Studio settings), you will have access to the current stack. Remember that this stack doesn't show ALL methods that have been called up to this point. Any method that completed was removed from the stack. It's not a log.

You can double click on any of the entries in the stack to go to that source code (if it's available on your machine). While you're there, you can inspect local variables, etc. It's a kind of detective tool to help you figure out what has happened in your program up to this point.


The purpose in the call stack is to allow you to see exactly what call caused an issue to happen.

When you look at the stack trace in an Exception, you can see the original call that caused the error to happen.

When debugging in Visual Studio, you can navigate up and down the call stack to see what values your application is storing at different levels. It's useful in debugging how your application got to the state it is in.


The purpose of the call stack window is to provide you access to the full code path which got you to the current instruction. You can use it to navigate to previous function calls within the program, inspect local variables, parameters, etc ... It's an invaluable tool for determining why your code is doing what it's doing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜