在正确的时间点将调试器附加到VC ++中的进程的最佳方法是什么? [英] What is the best way to attach a debugger to a process in VC++ at just the right point in time?

查看:102
本文介绍了在正确的时间点将调试器附加到VC ++中的进程的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试时,有时您需要附加一个已经运行的进程,而不是仅在调试器中启动应用程序。



对于我自己来说,通常进行Sleep()或MessageBox调用,以便附加调试器更加容易。我担心其中的某些最终可能会提交给源代码管理。



使用 #ifdef _DEBUG 保护睡眠或消息框是一种方法,但我想知道是否有更好的方法。



在睡眠状态下,您还会遇到无法及时连接的问题。使用MessageBox时,您可能会遇到问题,即您可能正在远程调试,或者正在调试没有可见GUI的进程(例如,在Vista上作为服务运行)

解决方案

您可以使用DebugBreak,检查以下链接:



http://www.epsilon-delta.net/articles/vc6_debug.html#breaking-with-debugbreak



http://blogs.msdn .com / calvin_hsia / archive / 2006/08/25 / 724572.aspx


When debugging, sometimes you need to attach an already running process instead of just starting the application in a debugger.

It's common for myself to put in a Sleep() or MessageBox call, so that it's easier to attach a debugger. I worry that some of these may be committed eventually to source control.

What is the best thing to do to avoid this situation while still delaying enough time so that you can attach your debugger to a running process?

Guarding the Sleep or message box with an #ifdef _DEBUG is one way, but I'm wondering if there is a better way.

With a Sleep you also have the problem that you may not attach in time. With a MessageBox you have the problem that you may be remotely debugging, or debugging a process that has no visible GUI (example running as a service on Vista)

解决方案

you can use DebugBreak, check these links:

http://www.epsilon-delta.net/articles/vc6_debug.html#breaking-with-debugbreak

http://blogs.msdn.com/calvin_hsia/archive/2006/08/25/724572.aspx

这篇关于在正确的时间点将调试器附加到VC ++中的进程的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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