Function Breakpoints

Function Breakpoints

Rate This
  • Comments 3

This blog post is part of a series on breakpoints in the Visual Studio debugger.  In this post, we will show the function breakpoints feature of Visual Studio and how this feature can be used to save you time while debugging.

Dealing with Overloads

Let’s say that you want the debugger to stop in a specific function, but this function has a lot of overloads. One option would be to go through the code and set breakpoints on all of the overloads individually. If there are a lot of overloads, this could be quite time consuming. Another option is to use function breakpoints.

In our example (with code available to download), let’s say that you wanted to stop in the function IsPrime(), which has 4 overloads. The first thing that we will do is go to the Breakpoints Windows (can be accessed by clicking Debug->Windows->Breakpoints if it is not already visible) and click “New”.

clip_image002

Then click “Break at Function…” to bring up the new breakpoint dialog. You might notice that you can also bring up this dialog by pressing Ctrl+B.

clip_image003

Enter “IsPrime” for the function name and click OK. This will take us to a dialog where we can quickly select all of the matching function names. You can select them all by clicking the All button.

clip_image004

Now when I execute the program, I can hit the breakpoint in the version of IsPrime that my app is calling.

clip_image005

When Source Isn’t Immediately Available

Another useful trick with function breakpoints is to set breakpoints in code when that code is not readily available. To illustrate this, we will use the C++ example (available for download). This example uses ATL and let’s say we wanted to debug the ATL code to see how it works. While the ATL code is available, you are unlikely to just have it open in your IDE. Even if you did, it would probably take a while to figure out where to set a breakpoint.

You can save some time by using function breakpoints. In this code example, I am using CComPtr with the object CObject1. To set breakpoints on the ATL functions that I will use, I bring up the Breakpoints window as I did before.

clip_image006

If I enter ATL::CComPtrBase<CObject1>::Attach as the function, I will set a breakpoint on that specific function. I also have the option of using a wild card by entering ATL::CComPtrBase<CObject1>::* to set breakpoints on all matching functions. When I do this, these breakpoints appear as a tree in the Breakpoints window.

clip_image008

Now when I run the application, I will stop at these breakpoints and Visual Studio will take me to the right place in the source code.

clip_image010

Attachment: NativeBreakpointsSample.zip
Leave a Comment
  • Please add 5 and 7 and type the answer here:
  • Post
  • Please add searching to Text/XML/HTML visualizers and object browsner while debug. Drilling down throung multiple levels in hierarchy to find particular property and data, is difficult. Searching feature, similar to Solution Explorer search, cold be great.

  • @Tristan

    Hi, you should check out an extension for Visual Studio called OzCode - it's an extension that improves debugging productivity. One of its core features is the ability to search (and compare) object values, by property and data. It's a commercial extension, but it's currently free while in beta. Check it out at http://www.oz-code.com.

    Disclaimer: I'm one of the developers of OzCode!

  • @Tristan – Thanks for the suggestion please feel free to submit this on the Visual Studio UserVoice site visualstudio.uservoice.com

Page 1 of 1 (3 items)