Breakpoint Generator Extension
Posting on behalf of Jakob Ehn and Utkarsh Shigihalli, Visual Studio ALM Rangers and MVPs
As developers, we are often confronted with existing, potentially large codebases that we have never seen before but are asked to make changes in.
It can be a class library received from a colleague or a complete application downloaded from GitHub to reuse or extend. However, before we can start making changes to the code, we need to understand the existing flow of the application. Where does it start, what are the public entry points to the different assemblies that are part of the application solution and so on.
To do that, we will often start by reading the code, guessing what functions will be called, setting several breakpoints and start debugging. This works relatively well in small code bases, but in case of a large applications this can be a very time consuming process.
This is where our Breakpoint Generator extension comes in. This Visual Studio extension automatically scans the source code in the active solution, finds the public methods (which are typical entry points to the program), and puts a breakpoint and a configurable trace message to the beginning of each method. You can do this for a single file, project, or complete solution.
How to get the extension
You can get the extension from the Visual Studio marketplace and install it either by going to Tools | Extensions and Updates inside Visual Studio, or by downloading the extension from marketplace and double clicking to install it.
NOTE: Currently the extension only supports Visual Studio 2015 and C# projects.
How it works
Once you install the extension, you will see a new menu item ‘Generate Breakpoints’ under the Debug menu.
You can also access this menu item by right clicking on a solution, project or file in Solution Explorer.
Once you have selected this, the extension will analyze the corresponding code and show a tree view, similar to the Solution Explorer, that shows all projects, files and public methods in those files.
The extension uses the Roslyn SDK to analyze the selected projects. Generally, this process is fast, but for large solutions it might take a short while. The extension does not block the UI though–everything is done in the background.
Now you can select the scope of the code for which you want to generate breakpoints. In this case, we have checked the web application project (ProjectArchive.Web) which will result in all public methods (including properties) having a breakpoint at the start position.
As you can see below, the breakpoints are generated with an action that logs the output as a TracePoint.
This message format is configurable. More on that later.
Now, if you start debugging the application it will log these messages to the output window:
This makes it very easy to quickly understand the different execution paths of the application. A nice thing about TracePoints is that they also appear as IntelliTrace events in the Enterprise edition of Visual Studio 2015, which additionally lets you navigate back to source code.
Configuring the trace message
The extension allows you to configure the trace message, so that you can see the information you want about the method in IntelliTrace window.
By default we use “$FUNCTION called by $CALLER” expression, but you can use any available keywords.
As you can see in the screenshot above, you can also decide whether to continue execution by setting the Continue Execution option. By default, this is set to True, meaning the all the generated breakpoints will not stop the application, only log the message. You can also customize any given breakpoint’s message and settings either from the settings in the editor or the Breakpoints window.
We hope that you will find this extension useful. This is the initial release of the extension and we plan to add more features to it in the near future. We already have some ideas for new features and improvements, such as:
- Looking at the possibility of the extension finding existing breakpoints and maintaining “state” on breakpoints each time the tool is brought up
- Supporting VB.NET
- Improving performance
About the authors
Both authors found this project very interesting as we have a passion for making it easier to dig into large unknown codebases.
Jakob Ehn is a Microsoft Visual Studio ALM MVP and Visual Studio ALM Ranger. Among other things, he loves customizing and extending Visual Studio and Team Foundation Server to make these products even better. He has published several popular extension such as GitFlow for Visual Studio and AssociateRecentWorkItems. You can find him blogging at http://geekswithblogs.net and tweeting as @jakobehn.
Utkarsh ****Shigihalli is a Microsoft Visual Studio ALM MVP and Visual Studio ALM Ranger. Utkarsh loves building Visual Studio extensions and Visual Studio Online. He has worked on numerous extensions and actively blogs about extending Visual Studio at http://www.visualstudiogeeks.com. You can follow him on Twitter at @onlyutkarsh.
Please let us know how the extension works for you? What do you like, dislike and/or miss in the extension?
Add a comment or contact us here.