使用Visual Studio 2013 调试 MASM 汇编程序!
原文地址:http://kipirvine.com/asm/debug/vstudio2013/index.htm
Using the Microsoft Visual Studio 2013 Debugger |
Updated 6/21/2014
This tutorial explains how to use the Microsoft Visual Studio 2013 Debugger to debug 32-bit assembly language programs running in Protected mode. Specifically, you will learn how to perform the following tasks:
For additional information about debugging in Visual Studio 2013, visit http://msdn.microsoft.com and search for Debugging in Visual Studio. Select this link if you're having trouble getting the debugger to recognize debugging information. Configure Visual Studio for DebuggingVisual Studio has a set of different configurations that make it easy to create a variety of project types (Visual Basic, ASP.NET, etc.). In order to get the most out of debugging assembly language programs, you need to select an appropriate configuration. From the Tools menu in Visual Studio, select Import and Export Settings. (In Visual Studio Express, select Settings from the Tools menu, then select Import and Export Settings.) In the following dialog, select Reset all settings and click the Next button. In the next pane, you have the option of saving your current settings. This would be useful if you want to return to your current settings later. Select an option and click the Next button. In the following pane (from Visual Studio Professional), select the Visual C++ settings and click the Finish button. In Visual Studio Express you will see the following two options. Select Expert Settings and click the Finish button: Once your settings have been reset, click the Close button to close the wizard. Note: In Visual Studio Express, you can switch between Basic Settings and Expert Settings by selecting Settings from the Tools menu. The Expert Settings option in Visual Studio Express is required if you want to display Registers, Memory, and Disassembly windows.
Once you begin working with the debugger, you can fine-tune the arrangement of the Visual Studio menus and windows, and save your specific settings for later recall. Open a Visual Studio Project fileIn this step-by-step tutorial, you will open the sample project and insert an example program named AddTwo.asm.
; AddTwo.asm - adds two 32-bit integers. Build the project by selecting Build Solution from the Build menu. In the output window, you should see text similar to that shown below. Extra lines may be added: 1>_MASM: The important thing to notice is the last line, which indicates that the build operation succeeded. Start the DebuggerPress the F10 key to start the debugger. Your environment should appear like this: Don't worry if some of the windows shown here do not appear on your screen. You can open and close them at will. First however, let's take a tour: Source WindowThe Source window displays the program's source file. Note that the first MOV statement has a yellow arrow next to it. The arrow always indicates the next statement that's about to execute.
Adjust the Debugging Support WindowsThis is a good time to remove panels that you will not use. In the lower part of the debugger window, select an remove all but the Watch and Output panels. On the side panel, remove all but the Solution Explorer window. Also, from the Debug menu, select Windows, and select Registers. You may want to remove some of the extra toolbars from the top of the window. If so, select Toolbars from the View menu, and un-check any toolbars you want to remove. You can also remove individual buttons from a toolbar: Select the dropdown arrow on the right side of the toolbar, and select Add or Remove Buttons. Moving and Undocking WindowsYou can move any window by dragging its titlebar with the mouse. You can dock it (position it) by dropping it on any side of your workspace. For example, I like to put the Registers and Watch windows on the right side of the work area. If, however, you have more than one window positioned directly on top of each other, dragging the title bar will move all windows at once. If you want to select only one window from a cluster of windows, drag its tab (on the bottom) to the new location. The other windows in the cluster will not be affected. You can undock a window by dragging it with the mouse to any location on your desktop. It can be completely outside the Visual Studio window. Watch WindowFor this part of the tutorial, you will need two download the AddSub2.asm program by right-clicking this link. After downloading the file, please add it to your Solution Explorer window, and remove the AddTwo.asm program. Here is a partial program listing: INCLUDE Irvine32.inc If at some later time the watch window disappears, you can get it back again. While currently debugging a program, select Windows from the Debug menu, and select Watch 1. A Watch window is like an electronic spreadsheet that displays the names and values of selected variables. As you step through a program, you can see variables in this window change value. Currently the window is empty, but you can drag any program variable into the window with your mouse. Next, you will display the value of some variables in the Watch window. Drag the val1, val2, val3, and finalVal variables into the Watch window and note their current values: The values are currently displayed in decimal, so select hexadecimal format by right-clicking on the watch window and selecting Hexadecimal Display from the popup menu. Following is a sample: Memory WindowFrom the Debug menu, welect Windows, select Memory, and select Memory 1. The Memory1 window displays a raw dump of memory in either hexadecimal or decimal. It is particularly useful when working with array variables. Since we don't have any arrays in the program, let's display the value of val3. Next to the Address label, type: &val3 The & before the variable name means to interpret the variable name as an address. In assembly language, all labels are implied addresses. Variable names are case-sensitive in the debugger. The Memory window displays a series of individual memory bytes, beginning at the address of val3. Right-click on the window, and select 4-byte Integer as the display format. Along the left side of the window is shown the address of the first value in each line: In our sample, val3 is located at address 00405008, although your addresses might be different. You can also type a hexadecmal constant into the Address field. Use the C-language format, where the digits are preceded by "0x". For example: 0x0040400C. Note: The memory Windows are only available if address-level debugging is enabled in the Tools / Options / Debugging settings, available by clicking on the Tools menu in Visual Studio, and then selecting Options. Register WindowYou can display the Register window by selecting Windows from the Debug menu, and selecting Register. The Register window displays the contents of the CPU registers. The flag values do not show by default, but you can add them in by right-clicking and selecting Flags:
Disassembly WindowSelect Windows from the Debug menu, and select Disassembly. The Disassembly window displays a raw listing of the program's code. In some programs, it will show code generated by macros or by high-level MASM directives (such as .IF, in Chapter 6). If you right-click inside the Disassembly window, the popup context menu offers different viewing options: Here is a sample in which Show Source Code is disabled, and both Show address and Show symbol names options are enabled: --- AddSub2.asm ---------------------------------------------------------------- The offset of each variable apears next to its name. The exit statement in the source code listing has been translated into a call to the MS-Windows ExitProcess function, which terminates the current program. Steping Through the Program's ExecutionNext, you will begin stepping through the program's execution, one line at a time. Press the F10 several times and watch the yellow arrow in the Source window move from statement to statement. Notice the following as you step through the program:
As soon as you step past the call DumpRegs statement, click on the black MS-DOS icon on the Taskbar at the bottom of the screen. You should see the program's output, which is a register display: When you reach the exit statement and press F10, the debugger halts and you return to editing mode. Step Into Command (F11)Another way to step through a program is to use the Step Into (F11) command. It steps down into procedure calls. In contrast, the F10 key just executes procedure calls without tracing into the procedure code. Stopping and RestartingIt's easy to either stop or restart your program inside the debugger while you're in the process of stepping through a program:
Toggle Breakpoint (F9)You can set a breakpoint on any executable line in your source program by either clicking the mouse in the left margin, or pressing the F9 key. This can be done before you start the debugger, or while you are stepping through the program. If you press F9 when the cursor is on a line containing a breakpoint, the breakpoint is removed. The following image shows code containing a breakpoint: When you set a breakpoint, you can run your program at full speed up to the line containing the first breakpoint. The debugger will pause on the line, and wait for you to either step through the code from that point, or run the program to the next breakpoint.
Viewing the Runtime StackThe runtime stack will become more important as you beginn to write programs that contain procedures other than main. Each time you call a procedure, you place the program's return address on the stack. (This is explained in Chapter 5.) To view the runtime stack while debugging, display a memory window at the address specified in the ESP register. In the following image, the stack shows a return address (00401025) stored at the memory location point to by the ESP (stack pointer) register: When you display the stack, right-click the memory window and select 4-byte Integer as the display format. Saving Your Visual Studio SetupAfter configuring Visual Studio to your debugging and editing preferences, you would be wise to save your setup. Here are the steps:
If you ever want to return Visual Studio to the settings you've saved, just run the Import and Export Settings Wizard again. |
Error Messages
Debugging information for "project.exe" cannot be found or does not match. Binary was not built with debugging information.
This error occurs when the Visual Studio project is not configured correctly for debugging. This might happen if you are working with a Visual Studio project file that has been altered or reconfigured accidentally. Here's how to fix it:
- From the Project menu, select (projectname) Properties
- In the left panel, expand "Configuration Properties" entry
- Expand the C/C++ entry
- Select "General"
- In the right panel, change "Debug Information Format" to "Program Database For Edit And Continue (/ZI)"
- In the left panel, Select "Optimization"
- In the right panel, change "Optimization" to "Disabled (/Od)"
- In the left panel, expand "Linker"
- In the left panel, select "Debugging"
- In the right panel, change "Generate Debug Info" to "Yes"
- Click OK button to save your changes.
- Rebuild your application and begin debugging.
其它关于调试MASM汇编程序文章:
http://kipirvine.com/asm/debug/index.htm
使用Visual Studio 2013 调试 MASM 汇编程序!的更多相关文章
- (英文版)使用Visual Studio 2015 编写 MASM 汇编程序!
原文地址:http://kipirvine.com/asm/gettingStartedVS2015/index.htm#CreatingProject Getting Started with MA ...
- 用Visual Studio 2015 编写 MASM 汇编程序(一)环境配置
原文地址:http://kipirvine.com/asm/gettingStartedVS2015/index.htm#CreatingProject 下面内容根据上面文章翻译整理而来! 开发32位 ...
- 解决Visual Studio 2013调试时 Web服务框架中出现了无法识别的错误 问题
此问题出现过很多次,点帮助,google, baidu 都没解决,后经过摸索解决,记录下来1.查找80port是否有被占用情况,需要查看skype[这东西不知道为什么为占用80], Reporting ...
- 用Visual Studio 2015 编写 MASM 汇编程序(二)从头开发一个Win32汇编程序
一,建立一个VC的控制台类型的空工程: 1,从VS菜单中选择“文件”->“新建”->“项目”. 2,在新建项目中选择:“Visual c++”->"Win32"- ...
- .net转PHP从零开始-配置visual studio 2013 PHP开发环境php for visual studio
作为一个.net开发者,一直在visual studio这款强大的编辑器宠爱下,其他编辑器都不会用,也用着不熟练.最近这不是转php吗,使用php编辑器很不爽,觉得还是用visual studio舒服 ...
- Visual Studio 2013环境下操作vc6/vc7/vc8等低版本平台项目【编译|生成|调试】
现代化的开发环境,微软一直在推出更新换代,我们所处的技术环境在日新月异的变化:不过在中国多数人们一边疲惫的追赶着时代的步伐,一边坚守着自己所获悉所掌握的那些紧吧吧的知本.对技术工具的掌握并非他们所想要 ...
- Visual Studio 2013 如何在停止调试Web程序后阻止IIS Express关闭
vs2013 调试项目的时候,当停止调试的时候,端口就被断了.之前以为是IIS那边的控制问题,但是其他并行的项目运行都没有出现这种情况. 最初也没在意,直到现在实在忍受不了了,每次重开也太烦了.就去各 ...
- Visual Studio 2013中因SignalR的Browser Link引起的Javascript错误一则
众所周知Visual Studio 2013中有一个由SignalR机制实现的Browser Link功能,意思是开发人员可以同时使用多个浏览器进行调试,当按下IDE中的Browser Link按钮后 ...
- 微软正式发布Visual Studio 2013 Update 3 (2013.3) RTM
昨天微软的Visual Studio 2013 Update 3(Visual Studio 2013.3)正式发布(RTM)了,做为微软认证金牌合作的葡萄城控件,我们组织力量第一时间进行翻译.分享给 ...
随机推荐
- Java static block static constructor , static field
http://stackoverflow.com/questions/7121213/singleton-instantiation http://docs.oracle.com/javase/spe ...
- APK软件反编译 去广告
具体步骤: 1.下载 apktool 下载地址:https://code.google.com/p/android-apktool/downloads/list 2.通过apktool 反编译apk. ...
- IE下必须点击一下页面空白的地方才可以激活onchange事件
checkbox在IE下必须点击一下页面空白的地方才可以激活onchange事件. 解决办法把onchange换成onclick
- JavaScript中知而不全的this (转)
原文引自:http://www.cnblogs.com/snandy/p/4773184.html 都说 JavaScript 是一种很灵活的语言,这其实也可以说它是一个混乱的语言.它把函数式编程和面 ...
- Mysql 索引 转载
转自 :http://blog.csdn.net/wud_jiyanhui/article/details/7403375 什么是索引 索引时一种特殊的文件,他们包涵着对数据表里所有记录的引用指针. ...
- 数据库连接工具类——包含取得连接和关闭资源 ConnUtil.java
package com.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepare ...
- Keepalived+MySQL实现高可用(转)
http://www.cnblogs.com/wingsless/p/4033093.html MHA高可用 http://www.cnblogs.com/gomysql/p/3856484.ht ...
- C# Color Table颜色对照表
.AliceBlue 240,248,255 .LightSalmon 255,160,122 .AntiqueWhite 250,235,215 .LightSeaGreen 32,178,170 ...
- 提示“应用程序无法启动,因为应用程序的并行配置不正确”不能加载 System.Data.SQLite.dll
新版本SQLITE,如果下载Precompiled Binaries版会出现提示“应用程序无法启动,因为应用程序的并行配置不正确”不能加载 System.Data.SQLite.dll. 下载Prec ...
- Maven 依赖管理
1 概念介绍 之前我们说过,maven 坐标能够确定一个项目.换句话说,我们可以用它来解决依赖关系.在 POM 中,依赖关系是在 dependencies部分中定义的.在上面的 POM 例子中,我们 ...