{"id":15173,"date":"2010-01-26T07:00:00","date_gmt":"2010-01-26T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/01\/26\/microspeak-zap\/"},"modified":"2010-01-26T07:00:00","modified_gmt":"2010-01-26T07:00:00","slug":"microspeak-zap","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100126-00\/?p=15173","title":{"rendered":"Microspeak: Zap"},"content":{"rendered":"<p>\nYou may hear an old-timer developer use the verb\n<i>zap<\/i>.\n<\/p>\n<blockquote CLASS=\"q\"><p>\nThat proposed fix will work.\nUntil everybody gets the fix,\nthey can just zap the assert.\n<\/p><\/blockquote>\n<p>\nThe verb <i>to zap<\/i> means\n<i>to replace a breakpoint instruction\nwith an appropriate number of NOP instructions<\/i>\n(effectively ignoring it).\n<\/p>\n<p>\nThe name comes from the old Windows 2.x kernel debugger.\n(Actually, it may be even older, but that&#8217;s as far back as I\nwas able to trace it.)\nThe <code>Z<\/code> (<i>zap<\/i>) command replaces the current\ninstruction with a NOP if it is an <code>int&nbsp;3<\/code>\n(the x86 single-byte breakpoint instruction),\nor replaced the previous instruction with NOPs if it is an\n<code>int&nbsp;1<\/code>\n(the x86 two-byte breakpoint instruction).\n<\/p>\n<p>\nThis operation was quite common back in the days when\nlots of code was written in assembly language.\nA technique used by some teams was to insert\na hard-coded breakpoint (called a <code>TRAP<\/code>)\ninto every code path of a function.\nHere&#8217;s an example (with comments and other identifying characteristics\nremoved and new ones made up):\n<\/p>\n<pre>\nxyz8:   mov     bl,[eax].xyz_State\n        cmp     bl,XYZSTATE_IGNORE\n        TRAPe\n        je      short xyz10     ; ignore this one\n        or      bl,bl\n        TRAPe\n        je      short xyz11     ; end of table\n        mov     bh,[eax].xyz_Flags\n        test    bh,XYZFLAGS_HIDDEN\n        TRAPz\n        jz      short xyz10     ; skip - item is hidden\n        test    bh,XYZFLAGS_MAGIC\n        TRAPe\n        je      short gvl10     ; skip - not the magic item\n        TRAP\n        bts     [esi].alt_flags,ALTFLAGS_SEENMAGIC\n        TRAPc\n        jc      short xyz10     ; weird - we shouldn't have two magic items\n<\/pre>\n<p>\nThere were a variety of <code>TRAP<\/code> macros.\nHere we see the one plain vanilla <code>TRAP<\/code> and a bunch\nof fancy traps which trigger only when certain conditions are met.\nFor example, <code>TRAPc<\/code> traps if the carry is set.\nHere&#8217;s its definition:\n<\/p>\n<pre>\nTRAPc   MACRO\n        local   l\n        jnc     short l\n        int     3\nl:\n        ENDM\n<\/pre>\n<p>\nHardly\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/03\/03\/7994007.aspx\">\nrocket science<\/a>.\n<\/p>\n<p>\nWhen you became the person to trigger a particular code path for\nthe first time,\nyou would trigger the trap, and you either stepped through\nthe code yourself or (if you weren&#8217;t familiar with the code)\ncontacted the author of the code to verify that the code\nsuccessfully handled this &#8220;never seen before&#8221; case.\nWhen sufficiently satisfied that a code path operated as expected,\nthe developer removed the corresponding <code>TRAP<\/code>\nfrom the source code.\n<\/p>\n<p>\nOf course, most <code>TRAP<\/code>s are removed before the code\ngets checked in, but the ones related to error handling or\nrecovering from data corruption\ntend to remain\n(such as here, where we inserted a <code>TRAP<\/code> when we\nencounter two magic items, which is theoretically impossible).\n<\/p>\n<p>\nWhen you trigger one trap,\nyou usually trigger it a lot,\nand you usually trigger a lot of related traps as well.\nThe <code>Z<\/code> command was quite handy at neutering each\none after you checked that everything was working.\nYou zapped the trap.\n<\/p>\n<p>\nThat&#8217;s why old-timers refer to patching out a hard-coded\nbreakpoint as zapping,\neven though the <i>zap<\/i> command hasn&#8217;t existed for over a decade.\n<\/p>\n<p>\n<b>Update<\/b>:\nAs far as I can tell, the earlier uses of the word <i>zap<\/i>\nreferred to patching binaries,\nnot for removing hard-coded breakpoints after they stopped\nin the debugger.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may hear an old-timer developer use the verb zap. That proposed fix will work. Until everybody gets the fix, they can just zap the assert. The verb to zap means to replace a breakpoint instruction with an appropriate number of NOP instructions (effectively ignoring it). The name comes from the old Windows 2.x kernel [&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":[25,105],"class_list":["post-15173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code","tag-microspeak"],"acf":[],"blog_post_summary":"<p>You may hear an old-timer developer use the verb zap. That proposed fix will work. Until everybody gets the fix, they can just zap the assert. The verb to zap means to replace a breakpoint instruction with an appropriate number of NOP instructions (effectively ignoring it). The name comes from the old Windows 2.x kernel [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/15173","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=15173"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/15173\/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=15173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=15173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=15173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}