{"id":96245,"date":"2017-05-29T07:00:00","date_gmt":"2017-05-29T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=96245"},"modified":"2020-01-18T10:10:43","modified_gmt":"2020-01-18T18:10:43","slug":"20170529-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20170529-00\/?p=96245","title":{"rendered":"Does DebugBreak work to launch the debugger, or doesn&#8217;t it?"},"content":{"rendered":"<p>Jorge asked <a href=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20160425-00\/?p=93345#comment-1245367\"> why the <code>Debug\u00adBreak<\/code> function stopped working<\/a>. Specifically, why it doesn&#8217;t launch the Visual Studio debugger.<\/p>\n<p>Okay, first of all, the primary purpose of the <code>Debug\u00adBreak<\/code> function is not to launch the debugger. The primary purpose of the <code>Debug\u00adBreak<\/code> function is to trigger a break into any attached debugger. That still works the same as it always did.<\/p>\n<p>The behavior Jorge asks about is a <a href=\"https:\/\/xkcd.com\/1172\/\"> second-order side effect<\/a> of the <code>Debug\u00adBreak<\/code> function.<\/p>\n<p>When you perform a <code>Debug\u00adBreak<\/code>, the <code>EXCEPTION_<wbr \/>BREAKPOINT<\/code> exception is raised. If a debugger is installed, it will intercept this exception and interpret it as a request to break into the debugger. If a debugger is not installed, then the exception is processed like any other exception, and any installed handler could step in and say, &#8220;Oh, yeah, <code>EXCEPTION_<wbr \/>BREAKPOINT<\/code>. No problem. I&#8217;ll handle that.&#8221;<\/p>\n<p>If a debugger is not installed and no code in the process handles the exception, then the exception goes to the current unhandled exception filter, and the default unhandled exception filter checks with Windows Error Reporting, and then displays a dialog box to inform the user of the problem.<\/p>\n<p>If a just-in-time debugger is installed, that dialog box has an extra <i>Debug<\/i> button:<\/p>\n<div style=\"font-family: Segoe UI, sans-serif; font-size: 10pt; border: solid 1px #949494; width: 25pc;\">\n<div style=\"padding: 1ex;\">\n<div><img decoding=\"async\" src=\"data:image\/png;base64,iVBORw0KGgoAAA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luxe<\/div>\n<p style=\"font-size: 14pt; color: #003399;\">Contoso Deluxe has stopped working<\/p>\n<p>A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.<\/p>\n<\/div>\n<div style=\"background-color: #f0f0f0; border-top: solid 1px #dfdfdf; padding: 1em; text-align: right;\"><span style=\"display: inline-block; border: solid 2px #006699; padding: 2px 1em; background-color: #e1e1e1;\">Debug<\/span> \u00a0 <span style=\"display: inline-block; border: solid 1px #adadad;\"> <span style=\"display: inline-block; border: solid 1px #e1e1e1; background-color: #e1e1e1; padding: 2px 1em;\">Close program<\/span> <\/span><\/div>\n<\/div>\n<p>Clicking the <i>Debug<\/i> button launches your just-in-time debugger.<\/p>\n<p>Notice that once you get past the point where no attached debugger has intercepted the <code>EXCEPTION_<wbr \/>BREAKPOINT<\/code> exception, the rest of the processing doesn&#8217;t treat the breakpoint exception differently from any other exception. In other words, instead of calling <code>Debug\u00adBreak<\/code>, you could have dereferenced a null pointer, written to a read-only page, executed an invalid instruction, or called <code>Raise\u00adException<\/code>. Anything that causes an exception to be raised goes through the same sequence of events, and at the end of the day will show the same dialog box.<\/p>\n<p>The <code>Debug\u00adBreak<\/code> function is not a &#8220;Launch the just-in-time debugger&#8221; function. It&#8217;s a very specific kind of &#8220;try to crash the program&#8221; function that debuggers understand and intercept. But if there&#8217;s no debugger attached, then the program crashes, and when a program crashes (for whatever reason), the just-in-time debugger gets a chance to step in.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It does, eventually, but not because it is DebugBreak.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-96245","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>It does, eventually, but not because it is DebugBreak.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/96245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=96245"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/96245\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=96245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=96245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=96245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}