M$VC 调试器一个奇怪的BUG
在 VC6 和VS2K5 上试过, 其他版本没试过, 不过可能还是这样子...
#include <stdio.h>
int main()
{
printf( "Hello World!\n" );
__asm int 3;
printf( "Hello World!\n" );
__asm _emit 0CDH;
__asm _emit 03H ;
printf( "Hello World!\n" );
return 0;
}
为什么 CD 03 被M$当成单字节指令了. 这个是比较蛋疼, 为啥米不用 CC 要用 CD 03 , 搞不懂nasm弄的啥飞机...
这个帖子有好点的结果了一起领分: http://topic.csdn.net/u/20110721/03/b85d4dda-0579-4972-9b61-ef0187380726.html
等一周没啥结果就大家平分...
[解决办法]
yasm试试?
[解决办法]
这个和nasm啥关系?VC用的不是masm么?
[解决办法]
6: __asm int 3;0110102B CC int 3 7: printf( "Hello World!\n" );0110102C 8B F4 mov esi,esp 0110102E 68 10 70 10 01 push offset _RTC_ErrorLevels-28h (1107010h) 01101033 FF 15 D4 82 10 01 call dword ptr [__imp__printf (11082D4h)] 01101039 83 C4 04 add esp,4 0110103C 3B F4 cmp esi,esp 0110103E E8 4D 00 00 00 call _RTC_CheckEsp (1101090h) 8: __asm _emit 0CDH;01101043 CD 03 int 3
[解决办法]
很奇怪啊,直接给合并了
[解决办法]
1628: int __declspec(naked) main() 1629: {__asm { 1630: push edi;01171420 57 push edi 1631: mov edi , offset foobar ;01171421 BF 1E 10 17 01 mov edi,offset foobar (117101Eh) 1632: call edi;01171426 FF D7 call edi 1633: _emit 0CCH ;01171428 CC int 3 1634: call edi;01171429 FF D7 call edi 1635: _emit 0CDH ;0117142B CD db cdh 1636: _emit 03H ;0117142C 03 FF add edi,edi 0117142E D7 xlat byte ptr [ebx] 1638: call edi;0117142F FF D7 call edi 1639: call edi;01171431 FF D7 call edi 1640: pop edi;01171433 5F pop edi 1641: ret01171434 C3 ret
[解决办法]
INT 3指令有两种形式,一种是0xcc 一种是0xcd 0x03,其中第二种是INT n的标准形式。 0xCC是特别针对breakpoint优化的。可以查看Intel Instruction Set Reference第二卷.
Opcode Instruction Description
CC INT 3 Interrupt 3—trap to debugger
CD ib INT imm8 Interrupt vector number specified by immediate byte
The INT 3 instruction generates a special one byte opcode (CC) that is intended for calling the debug exception handler. (This one byte form is valuable because it can be used to replace the first byte of any instruction with a breakpoint, including other one byte instructions, without over-writing other code). To further support its function as a debug breakpoint, the interrupt generated with the CC opcode also differs from the regular software interrupts as follows:
? Interrupt redirection does not happen when in VME mode; the interrupt is handled by a
protected-mode handler.
? The virtual-8086 mode IOPL checks do not occur. The interrupt is taken without faulting at
any IOPL level.
Note that the “normal” 2-byte opcode for INT 3 (CD03) does not have these special features.
Intel and Microsoft assemblers will not generate the CD03 opcode from any mnemonic, but this
opcode can be created by direct numeric code definition or by self-modifying code.
注意到最后一段特别提到intel和ms的汇编引擎不会生成CD03的操作码。
所以,这个问题可以认为是MS的bug吧~~
[解决办法]
楼主参考一下这个
VC++内联汇编(MSDN相关内容完整翻译)
[解决办法]