{"id":15363,"date":"2010-01-07T07:00:00","date_gmt":"2010-01-07T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/01\/07\/how-to-change-the-debugger-attached-to-a-process\/"},"modified":"2010-01-07T07:00:00","modified_gmt":"2010-01-07T07:00:00","slug":"how-to-change-the-debugger-attached-to-a-process","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100107-00\/?p=15363","title":{"rendered":"How to change the debugger attached to a process"},"content":{"rendered":"<p>Suppose your application crashes and debugger&nbsp;X is automatically connected because that&#8217;s how the system happened to be configured. But you would prefer to use debugger&nbsp;Y. After installing debugger&nbsp;Y, how do you switch the debugger from X&nbsp;to&nbsp;Y? If you try to connect debugger&nbsp;Y to the process, you get the error code <code>STATUS_PORT_ALREADY_SET<\/code>, because only one debugger can be connected to a process at a time. But if you disconnect the old debugger, the application will disappear with it. How do you escape from this Catch-22?\n Here&#8217;s what you do.<\/p>\n<ul>\n<li>Attach the ntsd debugger in non-invasive mode:     use -pv instead of -p when specifying the process id. <\/li>\n<li>The ntsd debugger will suspend all the threads in the process. <\/li>\n<li>Now tell debugger&nbsp;X to resume the process and detach from it.     (If debugger&nbsp;X is ntsd,     then the command for this is <code>qd<\/code>.) <\/li>\n<li>Next, tell debugger&nbsp;Y to attach to the process. <\/li>\n<li>Finally, go to the ntsd debugger which you attached in non-invasive mode,     and tell it to detach with the <code>qd<\/code> command. <\/li>\n<\/ul>\n<p> This trick works because the non-invasive mode of debugging doesn&#8217;t actually connect to the process as a debugger. It merely suspends all the threads in the process and lets you snoop around its memory. As a result, when you disconnect the original debugger and tell it to resume execution of the application, the application doesn&#8217;t actually resume because the non-invasive ntsd is keeping it suspended. You then can attach the new debugger to the process and resume your debugging.<\/p>\n<p> In other words, the non-invasive ntsd acts as a bridge, holding the process frozen while one debugger gets out and another one comes in. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Suppose your application crashes and debugger&nbsp;X is automatically connected because that&#8217;s how the system happened to be configured. But you would prefer to use debugger&nbsp;Y. After installing debugger&nbsp;Y, how do you switch the debugger from X&nbsp;to&nbsp;Y? If you try to connect debugger&nbsp;Y to the process, you get the error code STATUS_PORT_ALREADY_SET, because only one debugger [&hellip;]<\/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":[26],"class_list":["post-15363","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Suppose your application crashes and debugger&nbsp;X is automatically connected because that&#8217;s how the system happened to be configured. But you would prefer to use debugger&nbsp;Y. After installing debugger&nbsp;Y, how do you switch the debugger from X&nbsp;to&nbsp;Y? If you try to connect debugger&nbsp;Y to the process, you get the error code STATUS_PORT_ALREADY_SET, because only one debugger [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/15363","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=15363"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/15363\/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=15363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=15363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=15363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}