Serving Industries Worldwide

Innovative Ways - Satisfied Clientele

How to improve Debug-time Productivity?


Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

 
 

improve-Debug-time

You assume that the reader knows the basics of debugging in Visual Studio but we will know about some major concepts in debugging.There are many developers who handle their debugging sessions with a powerful-enough knowledge kit. The Visual Studio Debugging tools have much more to offer the developers. There is a list of improving debug-time productivity. Those tips and shortcuts have been validated with Visual Studio 2019 with no extension installed.

Many times, the debugger tracking down a bug, stepping through the code, in a code you look at what local variables value changed, sometimes the value isn’t what you expected, and you cannot step into the method that produced it because it’s from a library or .NET framework itself? Or You can also set a conditional breakpoint waiting to examine how some value got set.

Table of Content

In Visual Studio the biggest change is that the .NET platform is open source and maintained on GitHub. GitHub is also maintained many NuGet libraries that we all use on daily basis. It means that the source we would like to see in our debugger is just one HTTPS GET away. This is also a wonderfully productive ecosystem with all debug source, for all our dependencies, at that time. It would be nice! The Source Link project, that would be built an experience that did just that.

In the Source Link-enabled libraries, your debugger can download the underlying source files as you step in, and you can set breakpoints/tracepoints like you would with any other source. The Source Link-enabled debugging makes it easier to understand the full flow of your code from your code down to the runtime. There is language-agnostic, so you can benefit from it for any .NET language and some native libraries.

Debugging the Framework

Sometimes it will happen your code to step into the framework to see what’s going on especially in your code that you didn’t except with Source Link, you can also step into your code with framework methods, inspect all variables, and set breakpoints.

You can see if you are tired without the source link, before and after hitting F11 to step in the below example.

debug1

Figure: Debugging time value check
 

debug2

Figure: Debug value check on a curly bracket
 

The debugger does not step into Console.WriteLine() because there are no symbols or source for it. If you configure the source link, you can acquire different result.

The Visual Studio has downloaded the matching sources and stepped into the method. If you see the Autos window, it shows the local variables passed in. You can do step into, over, and out of the framework code as much as youlike.

   

Debugging a Dependency

If the issue is caused that isbecause you are trying to solve its dependency. It wouldn’t be great if you could step into the source for your dependencies too? Your dependency has been added Source Link information during its build, you can see this example with Newtonsoft.json. The only Newtonsoft.json was built with Source Link information, you can step into its code.

When you have stepped in, the debugger skipped a couple of methods that were marked with DebuggerStepThrough and stopped on the next statement in the CreateDefault method. It comes from the internet (GitHub, in this case). You are prompted only allowed it, either for just a single file or for all files.

Exceptions

The Source link helps you with the exceptions that come from the framework or dependencies. How many times you have seen this message and what you want is to examine the variables?

debug3

Figure: Exception on the int value
 

If you have Source Link, the debugger will take you to the spot where the exception is thrown where you can then navigate the call stack and investigate.

Enabling Source Link

The Source Link downloads source files from the internet, The Source Link is not enabled by default. In this below software, you can enable it.

Visual Studio

There are below steps that you can enable.

You can go to Tools -> Options -> Debugging -> Symbols and select the ‘NuGet.org Symbol Server’ option is checked. You can also Specify or directory for the symbol cache is a good idea to avoid downloading the same symbols again.

debug4

Figure: Symbol check on debug-time productivity
 

If you improve debug-time productivity in .NET Framework code, you will also need a ‘Microsoft Symbol Server’ option.

You can select Disable Just My Code in Tools -> Options -> Debugging -> General and since we want the debugger to attempt to locate symbols for code outside your solution.

debug5

Figure: Disable Just My Code
 

If you improve debug-time productivity in the .NET Framework code, you’ll also need to check Enable .NET Framework source stepping, this is not required for .NET Core.

 

Planning to Hire ASP.Net Developer ?

Your Search ends here.

 

Visual Studio Code

In Visual Studio Code, It has debugger settings configured per project in the launch.json.

Example:

"justMyCode": false,"symbolOptions": {
"searchMicrosoftSymbolServer": true,
"searchNuGetOrgSymbolServer": true},"suppressJITOptimizations": true,"env": {
"COMPlus_ZapDisable": "1",
"COMPlus_ReadyToRun": "0"}

Visual Studio for Mac

If you enable Source Link in Visual Studio for Mac, you can select Visual Studio -> Preferences -> Projects -> Debugger and select the step into external code option is checked and click OK to save your changes.

Run to Cursor

You can go with the shortcut CTRL + F10, you can also tell the debugger to run until the line pointed by the cursor.

debug6

Figure: Run to Cursor
 

Run Execution through a Simple Mouse Click

When you are hovering the source code while debugging, a Run execution through here a green glyph appears. You can click this glyph.

debug7

Figure: Show green glyph while mouse click
 

Set Next Statement

While Run execution time, your green glyph can be transformed into set next statement to here by holding the key CTRL. The Run execution through here because the statement is not executed. There is below a small image, we can see the code in Visual Studio that the reference object remains null, Student constructor in between hasn’t been executed.

debug8

Figure: Set Next Statement
 

Conclusion

The Visual Studio shines but it especially shines when it comes to debugging. Microsoft provided libraries with .pdb files on the Microsoft symbol server, so you can disable that option if you are only interested in an OSS library.

How to improve Debug-time Productivity?

improve-Debug-time

You assume that the reader knows the basics of debugging in Visual Studio but we will know about some major concepts in debugging.There are many developers who handle their debugging sessions with a powerful-enough knowledge kit. The Visual Studio Debugging tools have much more to offer the developers. There is a list of improving debug-time productivity. Those tips and shortcuts have been validated with Visual Studio 2019 with no extension installed.

Many times, the debugger tracking down a bug, stepping through the code, in a code you look at what local variables value changed, sometimes the value isn’t what you expected, and you cannot step into the method that produced it because it’s from a library or .NET framework itself? Or You can also set a conditional breakpoint waiting to examine how some value got set.

Table of Content

In Visual Studio the biggest change is that the .NET platform is open source and maintained on GitHub. GitHub is also maintained many NuGet libraries that we all use on daily basis. It means that the source we would like to see in our debugger is just one HTTPS GET away. This is also a wonderfully productive ecosystem with all debug source, for all our dependencies, at that time. It would be nice! The Source Link project, that would be built an experience that did just that.

In the Source Link-enabled libraries, your debugger can download the underlying source files as you step in, and you can set breakpoints/tracepoints like you would with any other source. The Source Link-enabled debugging makes it easier to understand the full flow of your code from your code down to the runtime. There is language-agnostic, so you can benefit from it for any .NET language and some native libraries.

Debugging the Framework

Sometimes it will happen your code to step into the framework to see what’s going on especially in your code that you didn’t except with Source Link, you can also step into your code with framework methods, inspect all variables, and set breakpoints.

You can see if you are tired without the source link, before and after hitting F11 to step in the below example.

debug1

Figure: Debugging time value check
 

debug2

Figure: Debug value check on a curly bracket
 

The debugger does not step into Console.WriteLine() because there are no symbols or source for it. If you configure the source link, you can acquire different result.

The Visual Studio has downloaded the matching sources and stepped into the method. If you see the Autos window, it shows the local variables passed in. You can do step into, over, and out of the framework code as much as youlike.

   

Debugging a Dependency

If the issue is caused that isbecause you are trying to solve its dependency. It wouldn’t be great if you could step into the source for your dependencies too? Your dependency has been added Source Link information during its build, you can see this example with Newtonsoft.json. The only Newtonsoft.json was built with Source Link information, you can step into its code.

When you have stepped in, the debugger skipped a couple of methods that were marked with DebuggerStepThrough and stopped on the next statement in the CreateDefault method. It comes from the internet (GitHub, in this case). You are prompted only allowed it, either for just a single file or for all files.

Exceptions

The Source link helps you with the exceptions that come from the framework or dependencies. How many times you have seen this message and what you want is to examine the variables?

debug3

Figure: Exception on the int value
 

If you have Source Link, the debugger will take you to the spot where the exception is thrown where you can then navigate the call stack and investigate.

Enabling Source Link

The Source Link downloads source files from the internet, The Source Link is not enabled by default. In this below software, you can enable it.

Visual Studio

There are below steps that you can enable.

You can go to Tools -> Options -> Debugging -> Symbols and select the ‘NuGet.org Symbol Server’ option is checked. You can also Specify or directory for the symbol cache is a good idea to avoid downloading the same symbols again.

debug4

Figure: Symbol check on debug-time productivity
 

If you improve debug-time productivity in .NET Framework code, you will also need a ‘Microsoft Symbol Server’ option.

You can select Disable Just My Code in Tools -> Options -> Debugging -> General and since we want the debugger to attempt to locate symbols for code outside your solution.

debug5

Figure: Disable Just My Code
 

If you improve debug-time productivity in the .NET Framework code, you’ll also need to check Enable .NET Framework source stepping, this is not required for .NET Core.

 

Planning to Hire ASP.Net Developer ?

Your Search ends here.

 

Visual Studio Code

In Visual Studio Code, It has debugger settings configured per project in the launch.json.

Example:

"justMyCode": false,"symbolOptions": {
"searchMicrosoftSymbolServer": true,
"searchNuGetOrgSymbolServer": true},"suppressJITOptimizations": true,"env": {
"COMPlus_ZapDisable": "1",
"COMPlus_ReadyToRun": "0"}

Visual Studio for Mac

If you enable Source Link in Visual Studio for Mac, you can select Visual Studio -> Preferences -> Projects -> Debugger and select the step into external code option is checked and click OK to save your changes.

Run to Cursor

You can go with the shortcut CTRL + F10, you can also tell the debugger to run until the line pointed by the cursor.

debug6

Figure: Run to Cursor
 

Run Execution through a Simple Mouse Click

When you are hovering the source code while debugging, a Run execution through here a green glyph appears. You can click this glyph.

debug7

Figure: Show green glyph while mouse click
 

Set Next Statement

While Run execution time, your green glyph can be transformed into set next statement to here by holding the key CTRL. The Run execution through here because the statement is not executed. There is below a small image, we can see the code in Visual Studio that the reference object remains null, Student constructor in between hasn’t been executed.

debug8

Figure: Set Next Statement
 

Conclusion

The Visual Studio shines but it especially shines when it comes to debugging. Microsoft provided libraries with .pdb files on the Microsoft symbol server, so you can disable that option if you are only interested in an OSS library.