{"id":76,"date":"2004-03-11T18:45:58","date_gmt":"2004-03-11T17:45:58","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/archives\/2004\/03\/11\/hardware-readwrite-breakpoints\/"},"modified":"2004-03-11T18:45:58","modified_gmt":"2004-03-11T17:45:58","slug":"hardware-readwrite-breakpoints","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2004\/03\/11\/hardware-readwrite-breakpoints\/","title":{"rendered":"Hardware read\/write breakpoints"},"content":{"rendered":"<p>Intel processors have four hardware breakpoints, which means you can drop down into the debugger when someone writes *or reads* from a memory address.  This is pretty handy when you&#8217;re working with crufty languages like C++ and you have to track down memory corruption.  Of course, you could use Purify\/Boundschecker but here&#8217;s a cheaper and often faster solution.<\/p>\n<p>Include the header <a href=\"http:\/\/www.nobugs.org\/developer\/win32\/hwbreak.h\">hwbreak.h<\/a> in your project, and create a HWBreak object either on the stack or heap (depending on how long you want it to live for).  There&#8217;s a quick example in the comments.  Now when the memory at that address is modified or read, you&#8217;ll drop down into the debugger.<\/p>\n<p>(After I wrote this, I found another webpage which describes a similar approach, whose URL I&#8217;ve now lost.  The difference is that I jump through hoops to ensure that I only change the thread context on a suspended thread, since the API docs warn against doing it on a running thread).<\/p>\n<p>Now, DevStudio already gives you access to break-on-write breakpoints via the &#8220;data breakpoints&#8221; pane &#8211; you enter WO(0x12345678) to break if the WOrd at that address is modified.  But there&#8217;s no way to get break-on-read breakpoints from within DevStudio.   Well, in a <i>vanilla<\/i> DevStudio.  But if you&#8217;re stubborn you can hack the binary to use read-write breakpoints instead of write-only ones.  Details to follow &#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Intel processors have four hardware breakpoints, which means you can drop down into the debugger when someone writes *or reads* from a memory address. This is pretty handy when you&#8217;re working with crufty languages like C++ and you have to track down memory corruption. Of course, you could use Purify\/Boundschecker but here&#8217;s a cheaper and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":0,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}