Visual Studio中只有打破对集会第二行? [英] Visual Studio only breaks on second line of assembly?

查看:148
本文介绍了Visual Studio中只有打破对集会第二行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上的第一行设置一个断点我的 code 段汇编程序将不会停止执行程序。

Setting a breakpoint on the first line of my .CODE segment in an assembly program will not halt execution of the program.

有关Visual Studio的调试器是什么将允许它失败在汇编语言编写的程序的第一行创建一个断点?这是调试器的一些古怪,上破多字节指令的情况下,还是我只是做一些愚蠢?

What about Visual Studio's debugger would allow it to fail to create a breakpoint at the first line of a program written in assembly? Is this some oddity of the debugger, a case of breaking on a multi-byte instruction, or am I just doing something silly?

我有以下的汇编程序编译和Visual Studio中运行:

I have the following assembly program compiling and running in Visual Studio:

; Tell MASM to use the Intel 80386 instruction set.
.386
; Flat memory model, and Win 32 calling convention
.MODEL FLAT, STDCALL
; Treat labels as case-sensitive (required for windows.inc)
OPTION CaseMap:None

include windows.inc
include masm32.inc
include user32.inc
include kernel32.inc
include macros.asm

includelib masm32.lib
includelib user32.lib
includelib kernel32.lib

.DATA
    BadText     db      "Error...", 0
    GoodText    db      "Excellent!", 0

.CODE
main PROC
        ;int 3           ; <-- If uncommented, this will not break.
        mov ecx, 6       ; <-- Breakpoint here will not hit.
        xor eax, eax     ; <-- Breakpoint here will.
_label: add eax, ecx
        dec ecx
        jnz _label
        cmp eax, 21
        jz _good
_bad:   invoke StdOut, addr BadText
        jmp _quit
_good:  invoke StdOut, addr GoodText
_quit:  invoke ExitProcess, 0
main ENDP
END main

如果我尝试设置一个断点在主函数的第一行, MOV ECX,6 ,它会被忽略,程序执行不停止。只有会,如果我把它放在后,该行 XOR EAX,EAX ,或任何后续行。

If I try to set a breakpoint on the first line of the main function, mov ecx, 6, it is ignored, and the program executes without stopping. Only will a breakpoint be hit if I set it on the line after that, xor eax, eax, or any subsequent line.

我甚至尝试插入软件断点, INT 3 ,作为函数的第一行,它也被忽略。

I have even tried inserting a software breakpoint, int 3, as the first line of the function, and it is also ignored.

我发现很奇怪的第一件事:打我的断点之一后,观看拆卸给了我以下内容:

The first thing I notice that is odd: viewing the disassembly after hitting one of my breakpoints gives me the following:

01370FFF  add         byte ptr [ecx+6],bh  
--- [Path]\main.asm 
        xor eax, eax
00841005  xor         eax,eax  --- <-- Breakpoint is hit here
_label: add eax, ecx
00841007  add         eax,ecx  
        dec ecx
00841009  dec         ecx  
        jnz _label
0084100A  jne         _label (841007h)  
        cmp eax, 21
0084100C  cmp         eax,15h  

有趣这里是, XOR ,在Visual Studio的眼睛,我在程序的第一次手术。缺席是行移动ECX,6 。正上方它认为我的源开始是实际设置 ECX 6。所以,我的节目的实际开始已经根据拆解错位。

What's interesting here is that the xor is, in Visual Studio's eyes, the first operation in my program. Absent is the line move ecx, 6. Directly above where it thinks my source begins is the line that actually sets ecx to 6. So the actual start of my program has been mangled according to the disassembly.

如果我让我的程序的第一行 INT 3 ,出现上述在我的code是在拆卸行是:

If I make the first line of my program int 3, the line that appears above where my code is in the disassembly is:

00F80FFF  add         ah,cl

作为答案的一个建议,我关掉ASLR,它看起来像拆装多一点稳定的:

As suggested in one of the answers, I turned off ASLR, and it looks like the disassembly is a little more stable:

.CODE
main PROC
        ;mov ecx, 6
        xor eax, eax
00401000  xor         eax,eax  --- <-- Breakpoint is present here, but not hit.
_label: add eax, ecx
00401002  add         eax,ecx  --- <-- Breakpoint here is hit.
        dec ecx
00401004  dec         ecx  

完整的计划是在拆卸可见,但问题仍然perists。尽管我的程序就开始预期的地址,被显示在反汇编的第一个断点,它仍然跳过。放置一个 INT 3 作为第一行仍然导致以下行:

The complete program is visible in the disassembly, but the problem still perists. Despite my program starting on an expected address, and the first breakpoint being shown in the disassembly, it is still skipped. Placing an int 3 as the first line still results in the following line:

00400FFF  add         ah,cl  

和不停止执行,的再次重新轧液我的程序的反汇编代码视图。我的程序的下一行,然后在位置 00401001 ,我想是有道理的,因为 INT 3 是一个单字节指令,但为什么它已经在拆卸消失了?

and does not stop execution, and re-mangles the view of my program in the disassembly again. The next line of my program is then at location 00401001, which I suppose makes sense because int 3 is a one-byte instruction, but why would it have disappeared in the disassembly?

甚至开始使用单步执行(F11)命令不允许我在第一行中断程序。事实上,没有断点,用F11启动程序根本不停止执行。

Even starting the program using the 'Step Into (F11)' command does not allow me to break on the first line. In fact, with no breakpoint, starting the program with F11 does not halt execution at all.

我真的不知道还有什么我可以尝试解决问题,超出了我在这里详细介绍。这是拉伸超出了我目前的组装和调试器的了解。

I'm not really sure what else I can try to solve the problem, beyond what I have detailed here. This is stretching beyond my current understanding of assembly and debuggers.

推荐答案

我发现什么问题的根源是,但我还没有线索,为什么它是如此。

I have discovered what the root of the problem is, but I haven't a clue why it is so.

创建另一个MASM项目之后,我注意到,新的的对程序的第一线断裂,而拆卸并未以是错位或改变。所以,我比较其属性,以我原来的项目(用于调试配置)。我发现的唯一区别是,我原来的项目有增量链接无效。特别是,它增加了 /增量:NO 来链接器命令行

After creating another MASM project, I noticed that the new one would break on the first line of the program, and the disassembly did not appear to be mangled or altered. So, I compared its properties to my original project (for the Debug configuration). The only difference I found was that my original project had Incremental Linking disabled. Specifically, it added /INCREMENTAL:NO to the linker command line.

删除命令行(从而使增量链接),这个选项导致程序的行为在调试过程中如预期;在反汇编窗口中显示我的code保持不变,我可以打一个断点上的程序的第一线,和 INT 3 指令也可以正确执行的第一行。

Removing this option from the command line (thereby enabling Incremental Linking) resulted in the program behaving as expected during debugging; my code shown in the disassembly window remained unaltered, I could hit a breakpoint on the first line of the main procedure, and an int 3 instruction would also execute properly as the first line.

这篇关于Visual Studio中只有打破对集会第二行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆