<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx</link><description>In this blog entry, I’ll explain how setting source-level breakpoints in a managed debugger work under the hood from end to end. Here’s an overview of the pipeline of components: 1) End-user 2) Debugger (such as Visual Studio or MDbg ) . 3) CLR Debugging</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#343537</link><pubDate>Wed, 29 Dec 2004 09:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:343537</guid><dc:creator>Pavel Lebedinsky</dc:creator><description>Why is the auxillary buffer necessary? Couldn't the helper thread keep all the other threads suspended until the current thread has executed the initial single-step after the breakpoint?</description></item><item><title>re: How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#343667</link><pubDate>Wed, 29 Dec 2004 18:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:343667</guid><dc:creator>jwf</dc:creator><description>So why does Visual Studio 2003 hang occasionally when &amp;quot;stepping&amp;quot; through a mixed managed/unmanaged debugging session?&lt;br&gt;&lt;br&gt;This is the single most frustrating aspect of trying to develop new parts of our smart client applications in managed code while integrating with a huge unmanaged code base that has a ton of UI.&lt;br&gt;</description></item><item><title>re: How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#343754</link><pubDate>Wed, 29 Dec 2004 20:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:343754</guid><dc:creator>Mike Stall</dc:creator><description>Pavel - interesting idea, but there's a problem. Somehow you need to execute  the opcode underneath the breakpoint opcode (int3).  You can either:&lt;br&gt;1) temporarily remove the breakpoint and restore the original opcode. Single step to execute the opcode and then put the breakpoint back in.&lt;br&gt;2) use an auxillary buffer (as described above). &lt;br&gt;&lt;br&gt;The problem with #1 is from multi-threaded scenarios. If the other threads are not suspended, then they may race through the breakpoint while we have it removed.&lt;br&gt;If they are suspended, then we may deadlock if that single opcode we're stepping over blocks on another thread for some reasons (perhaps it's a system call).</description></item><item><title>re: How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#343756</link><pubDate>Wed, 29 Dec 2004 20:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:343756</guid><dc:creator>Mike Stall</dc:creator><description>jwf - that's because interop-debugging in v1.1 / VS 2003 is just really unstable in general. &lt;br&gt;In some hangs I've diagnosed, I've counted at least 7 different races that could cause it. There could be 100 reasons why your scenario is hanging.&lt;br&gt;&lt;br&gt;FWIW, There was large debate over whether to cut it completely or ship a half working feature that may still provide some value in some cases.&lt;br&gt;&lt;br&gt;On the good side, we've spent a lot of resources in v2.0 trying to stabalize interop-debugging and we believe it's a lot better. Check out VS2005 beta 1 and let us know if you still see such hangs (at least use Watson to report them).&lt;br&gt;&lt;br&gt;</description></item><item><title>re: How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#344061</link><pubDate>Thu, 30 Dec 2004 05:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:344061</guid><dc:creator>Nicholas Allen</dc:creator><description>I'm having a little trouble figuring out the mechanics of step 10.  If the &lt;a title="" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/structured_exception_handling.asp" target="_blank"&gt;SEH&lt;/a&gt; is injected before running managed code, isn't it possible for someone to add another &lt;a title="" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/structured_exception_handling.asp" target="_blank"&gt;SEH&lt;/a&gt; and be farther up the stack, possibly grabbing the breakpoint exception before Left-Side can see it?  And couldn't a vectored exception handler steal the exception as well before you get it?&lt;br&gt;&lt;br&gt;Or am I misinterpreting this and the hardware exception has already been converted to a managed exception?  In which case, why aren't other managed handlers exposed to this exception before it hits your filter?&lt;br&gt;&lt;br&gt;I would have thought this would be handled by Right-Side where the debugger can handle the exception before the debuggee even gets to see it.  And then communicate to Left-Side that a breakpoint has been hit to stop threads.  But I'm guessing there's a reason this is all done in Left-Side.</description></item><item><title>re: How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#344092</link><pubDate>Thu, 30 Dec 2004 08:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:344092</guid><dc:creator>Mike Stall</dc:creator><description>Nicholas - sorry, #10 is poorly worded. You bring up great points:&lt;br&gt;&lt;br&gt;Your interpretation is correct. So:&lt;br&gt;1) The &lt;a title="" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/structured_exception_handling.asp" target="_blank"&gt;SEH&lt;/a&gt; filter is already injected before the managed code is ever run by the CLR's EH subsystem. &lt;br&gt;2) The CLR's EH subsystem also owns the vectored exception handler. If you override it, you'll break things.&lt;br&gt;&lt;br&gt;3) While in managed code, only the CLR's EH subsystem can add &lt;a title="" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/structured_exception_handling.asp" target="_blank"&gt;SEH&lt;/a&gt; filters, so it's not possible for someone to add another &lt;a title="" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/structured_exception_handling.asp" target="_blank"&gt;SEH&lt;/a&gt; to intercept us.&lt;br&gt;&lt;br&gt;4) The CLR's EH subsystem then cooperates heavily with the CLR's debugging subsystem. It gives the debugging system first shot at all &lt;a title="" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/structured_exception_handling.asp" target="_blank"&gt;SEH&lt;/a&gt; exceptions with code=0x80000003 (breakpoint) or 0x80000004 (single-step)&lt;br&gt;&lt;br&gt;&lt;br&gt;Your last sentence is a great observation. &lt;br&gt;This is all done in the Left-side (the portion in-process w/ the debuggee) because managed-only debugging is actually not OS-debugging, and so the RS won't even get notified of the exceptions. &lt;br&gt;When interop-debugging (both managed &amp;amp; native debugging simultaneously), the RS is also an OS-debugger and so it will then get notified of the exception's via native debug events. In these cases, it detects the exceptions are meant for the CLR and then resumes the process to let the in-process filters handle them. This is done so that interop and managed-only share a lot of the same logic.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#344398</link><pubDate>Thu, 30 Dec 2004 21:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:344398</guid><dc:creator>Nicholas Allen</dc:creator><description>Thank you.  I think I understand it now.&lt;br&gt;&lt;br&gt;The CLR requires that it controls the OS exception handlers (structured and vectored) for things to work.  When the exception is hit, Right-Side ignores it (or never sees it depending on whether you're doing managed or interop) and lets Left-Side pick it up.  Left-Side will always have the first chance because it is the handler of choice for the OS.  Left-Side first gives it to the debugging exception filter (which acts like a vectored handler).  If it is a debugging related exception, we continue with the algorithm above.  Otherwise the debugging filter declines the exception and Left-Side then gives it to the managed structured handler to try.&lt;br&gt;&lt;br&gt;One consequence of handling all exceptions in-process is that we have extra transitions between Left-Side and Right-Side when doing interop debugging.&lt;br&gt;&lt;br&gt;RS (hit exception, decline) -&amp;gt; LS (hit exception, accept) -&amp;gt; RS (notify of exception) -&amp;gt; LS (suspend debuggee) -&amp;gt; RS (run debugger)&lt;br&gt;&lt;br&gt;If we took the native exception it would look like&lt;br&gt;&lt;br&gt;RS (hit exception, accept) -&amp;gt; LS (suspend debuggee) -&amp;gt; RS (run debugger)&lt;br&gt;&lt;br&gt;Manged debugging always goes&lt;br&gt;&lt;br&gt;LS (hit exception, accept) -&amp;gt; RS (notify of exception) -&amp;gt; LS (suspend debuggee) -&amp;gt; RS (run debugger)</description></item><item><title>re: How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#344447</link><pubDate>Thu, 30 Dec 2004 22:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:344447</guid><dc:creator>Mike Stall</dc:creator><description>That's 99% correct.&lt;br&gt;&lt;br&gt;Your last sentence is technically wrong. For managed debugging, the RS never sees the raw exception (0x80000003), it only sees the higher level managed debug events (like &amp;quot;Breakpoint&amp;quot;). So your last sentence should be:&lt;br&gt;Managed debugging always goes:&lt;br&gt;LS (hit exception, accept) -&amp;gt; RS (queue managed debug event) -&amp;gt; LS (suspend debuggee) -&amp;gt; RS (dispatch debug events) --&amp;gt; User responds --&amp;gt; RS(run debuggee)&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>Blog link of the week 53</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#345527</link><pubDate>Mon, 03 Jan 2005 02:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:345527</guid><dc:creator>Daniel Moth</dc:creator><description>Blog link of the week 53</description></item><item><title>Geek Notes 2005-01-24</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#359563</link><pubDate>Mon, 24 Jan 2005 19:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:359563</guid><dc:creator>Geek Noise</dc:creator><description /></item><item><title>.NET Nightly 169</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#359860</link><pubDate>Tue, 25 Jan 2005 03:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:359860</guid><dc:creator>.Avery Blog</dc:creator><description /></item><item><title>.NET Nightly 169</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#360292</link><pubDate>Tue, 25 Jan 2005 21:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:360292</guid><dc:creator>.Avery Blog</dc:creator><description /></item><item><title>Interop-stepping is 400 times faster in Whidbey over Everett</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#430962</link><pubDate>Tue, 21 Jun 2005 07:23:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:430962</guid><dc:creator>Mike Stall's .NET Debugging Blog</dc:creator><description>We’ve made Interop-debugging (aka “mixed-mode debugging”) much faster and more stable in Whidbey (VS8)...</description></item><item><title>O que acontece quando voc? aperta F9?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#433481</link><pubDate>Tue, 28 Jun 2005 22:54:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:433481</guid><dc:creator>How Things (Should) Work</dc:creator><description /></item><item><title>Being a CLR dev does not mean you know everything about the CLR</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#550181</link><pubDate>Mon, 13 Mar 2006 07:50:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:550181</guid><dc:creator>Mike Stall's .NET Debugging Blog</dc:creator><description>I find people often assume that just being a developer on the CLR means you somehow know everything about...</description></item><item><title>.NET Internals Tid-Bit #1: Managed Breakpoints</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#551121</link><pubDate>Tue, 14 Mar 2006 15:56:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:551121</guid><dc:creator>Eldar (NasdaqNM: ERJR)</dc:creator><description /></item><item><title>.NET Internals Tid-Bit #1: Managed Breakpoints</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#551198</link><pubDate>Tue, 14 Mar 2006 18:06:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:551198</guid><dc:creator>Eldar (NasdaqNM: ERJR)</dc:creator><description /></item><item><title>.NET internals tid-bit #1: Managed breakpoints</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#3756255</link><pubDate>Sun, 08 Jul 2007 06:20:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3756255</guid><dc:creator>Eldar</dc:creator><description>&lt;p&gt;From Tuesday, March 14th, 2006: A friend of mine asked me recently if I had any good books on .NET internals...&lt;/p&gt;
</description></item><item><title>Employment Wages &amp;raquo; Mike Stall&amp;#8217;s .NET Debugging Blog : How do Managed Breakpoints work?</title><link>http://blogs.msdn.com/jmstall/archive/2004/12/28/339756.aspx#8341336</link><pubDate>Fri, 28 Mar 2008 12:54:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8341336</guid><dc:creator>Employment Wages » Mike Stall’s .NET Debugging Blog : How do Managed Breakpoints work?</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://employmentwagesblog.info/mike-stalls-net-debugging-blog-how-do-managed-breakpoints-work/"&gt;http://employmentwagesblog.info/mike-stalls-net-debugging-blog-how-do-managed-breakpoints-work/&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>