Debugging with Attach to Process
2013-10-22 10:14
423 查看
Debugging with Attach to Process
by Richard Carr, published at http://www.blackwasp.co.uk/DebuggerAttach.aspxVisual Studio allows you to execute a program in debug mode and use various debugging tools to monitor its activity. When you are running a program outside of Visual Studio, it can still be possible to attach to that software to investigate its behaviour.
Visual Studio Debugger
It is common, when writing software using Visual Studio, to compile and execute a program directly from the integrated development environment (IDE) in debug mode.This allows you to step through the code line by line or to insertbreakpoints or tracepoints that permit you to pause the program at a key point and interrogate
the state of variables and objects. This tool can be invaluable when debugging your code.
Some software cannot be started directly from Visual Studio, perhaps because it must run in a specific environment or be executed using credentials other than those of the developer. Examples of such software are Windows
services and COM applications. Such programs and libraries must be debugged in a slightly different manner.
Attaching to a Process
It is possible to attach the Visual Studio debugger to processes that are already running. However, there are some limitations, principally that the assembly to be monitored must be compiled in debugmode, not release mode. The key requirements for attaching to a running program are:
The software was compiled in debug mode and the program database file (*.PDB) is available.
The source code for the assembly, as referenced in the PDB file, is available and matches that of the compiled code.
The version of Visual Studio that you are using supports attaching to processes. This facility is not available in the Express editions.
If the conditions are met, you can attach Visual Studio to the running process. You can then add breakpoints or tracepoints to halt the code at an important location and use the usual tools such as the immediate, locals and watches
windows to assist in finding problems or confirming the correct operation of the code.
Showing the Attach to Process Dialog Box
To debug a running program you can use the Attach to Process dialog box. To display the dialog box when using Visual Studio with an open project, select "Attach to Process" from the Debug menu. If you do not currently have a project open, the Debug menu willnot be visible. In this case, select "Attach to Process" from the Tools menu.
NB: If this menu option is missing, it may be because you have SQL Server Business Intelligence Studio installed. To show the option and other missing commands, follow the instructions in the knowledgebase article KB929664.
The main area of the window shows the processes that are executing in the context of thecurrent user. If you wish to debug a program that is running
with different credentials, tick the "Show processes from all users" checkbox. The list of processes is loaded when the dialog box is first displayed and does not update in real time. You can, however, refresh the list by clicking the refresh button.
Above the list of available processes is the "Attach to" box. This shows the type of process that you will be connecting to. For example, managed code or native code. By default, the selection is made automatically. As you select processes in the list, the
contents of the box change to show the appropriate type. If you wish to be more specific about the process types that you wish to debug, you can click the Select button and choose from a list.
Once you have located and selected the process, or several processes, that you wish to debug, click the Attach button. The Visual Studio screen will change to show the debugging controls as if you had started debugging from within the IDE. You can then use
the debugging toolbar and commands as well as all of the other usual debugging utilities.
When you have completed the debugging session, you can detach from the processes individually using the Processes window, which is displayed by selecting Processes from the Debug menu's Window submenu. Simply right-click a process in the list and select "Detach
Process". You can also disconnect from all attached processes using the "Detach All" command from the Debug menu. Note that detaching does not terminate the process.
相关文章推荐
- 无法Debug SQL: Unable to start T-SQL Debugging. Could not attach to SQL Server process on
- [tip debugging]Attach VS debugger to more than one process at the same time
- 无法Debug SQL: Unable to start T-SQL Debugging. Could not attach to SQL Server process on
- apache错误 Unable to open process" with PID 4!
- ios模拟器跑不起来,报error: failed to attach to process ID 0 解决办法
- VS attach to process 到进程里无法调试
- error: failed to attach to process ID xxx
- How to deal with javadoc createProcess issue?
- error: failed to attach to process ID 0
- 程序调试技巧 —— Attach to Process
- 无法抓DUMP, 报错"Could not attach to process XXXX, NTSTATUS 0xC0000048"
- VS调试技巧 之 attach to process
- How to enter deep idle with USB plugged in (Used For Debugging)
- "error: failed to attach to process ID 0"问题解决
- Visual C++ Debugging: How to use 'ASSERT' and deal with assertions failures?
- Attach to an already running managed process on device
- Failed to process TLD with path [/WEB-INF/c-rt.tld] and URI...
- failed to attach to process ID 0
- 通过Debug-->Attach to Process的方式来调试网站
- [错误处理]: How to deal with chrome failing to launch GPU process