如何检测是否已连接调试器,并且*已经设置或命中了断点? [英] How can I detect whether a debugger is attached *and* a breakpoint has been set or hit?

查看:88
本文介绍了如何检测是否已连接调试器,并且*已经设置或命中了断点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用 Debugger.IsAttached 检测是否已连接调试器,但我希望能够执行以下操作

I know I can use Debugger.IsAttached to detect whether a debugger is attached, but I want to be able to do something like

if (Debugger.IsAttached && Debugger.BreakpointIsSet && Debugger.BreakpointHitCount > 0)
    timeout *= 100;
someEvent.WaitOne(timeout);

原因是我的某些测试方案涉及其他线程上的活动。在调试器下查看内容自然会干扰此过程。我希望我的主测试线程在遇到其他线程上的断点命中时能阻塞更长的时间,但是如果调试器未连接或不是断点就没有阻塞,就不会阻塞。

The reason is some of my testing scenarios involve activity on other threads. Viewing things under the debugger naturally disturbs this process. I'd like my main testing thread to block longer while I'm stepping after a breakpoint hit on some other thread, but not block as long if the debugger isn't attached, or it is but a breakpoint hasn't been hit yet.

与上述可能等同;例如,使用P / Invoke调用非托管的调试API?

Is something equivalent to the above possible; for example, using P/Invoke to an unmanaged debug API?

推荐答案

我不确定我是否完全理解你的意思计划在这里实现-但是听起来好像解决了任何问题,它只能说明线程之间相互发出信号时确实发生的确定性和混乱,这确实很混乱,尤其是在连接调试器时。

I'm not sure I fully understand what it is you plan to achieve here - but it sounds like whatever solution might be cooked up, it will only expound on the certainty and confusion of what is really happening when your threads signal each other, which is confusing enough as is, especially when attaching a debugger.

我想说,您最好远离调试器,并做好 printf调试的工作,当然,从

I'd say you're better off staying away from the debugger on this one and doing good ol' "printf debugging", and of course looking at the ThreadID from which each message was generated.

也就是说,如果您仍然希望为此使用调试器,则可能仅用于查看一个线程(仅一个线程),而另一个线程全部被阻塞,并在系统进入损坏状态时监视其活动-此链接可能对此有所帮助:
http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/07/17/automatically-freezing-threads-brrrrr.aspx

That said, if you still wish to use a debugger for this, it might be useful to look at only one thread (and one thread only) while the others are all blocked, and monitor its activity when the system enters a corrupt state - this link might be helpful for that: http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/07/17/automatically-freezing-threads-brrrrr.aspx

这篇关于如何检测是否已连接调试器,并且*已经设置或命中了断点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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