{"id":2453,"date":"2013-10-08T15:00:00","date_gmt":"2013-10-08T15:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2013\/10\/08\/function-breakpoints\/"},"modified":"2022-07-19T00:10:08","modified_gmt":"2022-07-19T08:10:08","slug":"function-breakpoints","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/function-breakpoints\/","title":{"rendered":"Function Breakpoints"},"content":{"rendered":"<p>This blog post is part of a series on <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2013\/10\/07\/breakpoints-in-visual-studio-2013.aspx\">breakpoints<\/a> in the Visual Studio debugger and has been updated to reflect the experience in Visual Studio 2015.\u00a0 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.<\/p>\n<h2>Dealing with Overloads<\/h2>\n<p>Let\u2019s 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.<\/p>\n<p>In our example (<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/02\/ManagedBreakpointSamples.zip\" title=\"with code available to download\">with code available to download<\/a>), let\u2019s 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 \u201cNew\u201d.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/10\/7282.FunctionBP.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>Then click \u201cFunction Breakpoint\u2026\u201d to bring up the new breakpoint dialog. You might notice that you can also bring up this dialog by pressing Alt+F9, B.<br \/>\n<em>Note: This shortcut (Alt+F9, B)\u00a0is different from\u00a0previous versions of Visual Studio\u00a0which use\u00a0Ctrl+B.<\/em><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/10\/4403.FunctionBP.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>Enter \u201cIsPrime\u201d for the function name and click OK. This will create\u00a0the Function Breakpoint. We can see it appear in the Breakpoints Window.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/10\/4174.FunctionBP.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>When I execute the program the breakpoint will\u00a0be hit\u00a0whenever a method named IsPrime is called. The function overloads will appear as a tree of breakpoints\u00a0in the Breakpoints Window. You can double click on any of these breakpoints to navigate to the source code.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/10\/7142.FunctionBP.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0I can hit the breakpoint in the version of IsPrime that my app is calling.<\/p>\n<p><img decoding=\"async\" style=\"border-width: 0px\" title=\"clip_image005\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/10\/5861.clip_image005_thumb_6D2745DA.png\" alt=\"clip_image005\" width=\"661\" height=\"445\" border=\"0\" \/><\/p>\n<h2>When Source Isn\u2019t Immediately Available<\/h2>\n<p>Another useful trick with function breakpoints is to set breakpoints in code <a>when that code is not readily available. <\/a>To illustrate this, we will use the C++ example (<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/02\/NativeBreakpointsSample.zip\" title=\"available to download\">available for download<\/a>). This example uses ATL and let\u2019s 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.<\/p>\n<p>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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/10\/2870.FunctionBP.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>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.<\/p>\n<p><img decoding=\"async\" style=\"border-width: 0px\" title=\"clip_image008\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/10\/0576.clip_image008_thumb_2C18C676.jpg\" alt=\"clip_image008\" width=\"666\" height=\"142\" border=\"0\" \/><\/p>\n<p>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.<\/p>\n<p><img decoding=\"async\" style=\"border-width: 0px\" title=\"clip_image010\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/10\/3021.clip_image010_thumb_4573A1DD.jpg\" alt=\"clip_image010\" width=\"720\" height=\"195\" border=\"0\" \/><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/02\/NativeBreakpointsSample.zip\">NativeBreakpointsSample.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog post is part of a series on breakpoints in the Visual Studio debugger and has been updated to reflect the experience in Visual Studio 2015.\u00a0 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 [&hellip;]<\/p>\n","protected":false},"author":75,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,225],"tags":[],"class_list":["post-2453","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-git"],"acf":[],"blog_post_summary":"<p>This blog post is part of a series on breakpoints in the Visual Studio debugger and has been updated to reflect the experience in Visual Studio 2015.\u00a0 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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/2453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=2453"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/2453\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=2453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=2453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=2453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}