Visual Studio 2013: Working with Breakpoint Labels
NOTE: This is an older feature. I’ve updated the information for VS2013.
The Breakpoints Window has supported adding labels since VS2010, however most people aren’t aware of this feature. But how does this help you? Well, first, you can put friendly names for Breakpoints to make them easier to understand. Second, you can sort by the label names. And, third, you can search the labels when you have a lot of Breakpoints. Let’s see how to make this happen.
Creating Labels (Friendly Names) for Breakpoints
Go into any code base and create several breakpoints (F9) then open the Breakpoints Window (CTRL+ALT+B):
Notice the Labels column? It goes largely ignored unless someone points it out. To add a label to a single breakpoint just Right-Click it and choose Edit Labels:
Alternatively, you can select multiple breakpoints and do the same thing to create labels in bulk:
For this demo, select about half (or a little more) of you breakpoints and edit their labels. This will bring up the Edit Breakpoint Labels dialog:
Put in a label of “cart” to indicate these breakpoints are associated with our shopping cart and click add:
It turns out that these particular breakpoints are also associated with adding items to the cart so let’s put in another label of add item:
The point here being that you can add multiple labels to breakpoints. Click the OK button and notice the result:
Let’s assume the rest of the breakpoints deal with deleting items from the cart. Select them and edit the labels:
Since “cart” is already in our list of breakpoint labels we can simply select it:
Now we just add “delete item” to the list and we are all set:
Click OK and verify all the breakpoints have labels:
Sorting Breakpoints by Label
Now that we have set the labels we can sort by the labels column entries by click on the column header:
Everything looks in order but let’s make a change. Edit one of the “add item” entries to read “modify item”:
Take a look at your list again and notice how they are sorted:
The labels are sorted alphabetically from left-to-right so pay attention to your label names. In this example we have a potential issue since the word “cart” is keeping the sort from happening the way we want it. Fortunately for me, since they are all related to the cart, I can safely turn off the “cart” word and still have contextual meaning for my labels:
Searching Breakpoints by Label
Now that we have good labels set up we can do more advanced activities. We can search by any column but searching by labels we designate is particularly powerful. For demo purposes I’m going to make a point about searching you need to pay attention to. We want to find all the “add item” breakpoints. Click in the search box and type the letter “a” and press Enter:
As you can see it did not filter as expected. This is because the In Column value is set to All Visible. Since the letter “a” appears somewhere in every breakpoint we need to tell search to only pay attention to the labels column:
This results in getting the desired outcome:
To clear the search criteria just click the Reset Search Criteria button:
All the breakpoints will come back:
Finally
You can do many great things with this feature so experiment and see if it is valuable for you. There are a lot of great things you can do with breakpoints and this is only the tip of the iceberg. I’ll discuss other features in a future article.