2

In my visual C++ code I have introduced a __debugbreak statement for triggering a breakpoint. I have compiled the project with /CLR option. But it does not trigger a breakpoint during execution. Why does this happen? Please help before I shoot myself. This in on 64 bit executable.

Edit: I tried with DebugBreak() statement now and it is now hanging forever, not sure at which statement. The dll is used by a server program, which I'm accessing from a client on a different machine. Is this what is causing the problem? Should I be running it from the server machine itself? I expected it to atleast report a message about a breakpoint being triggered, even if it could not successfully launch the debugger session on the client machine. The .pdb file is avaialable on the server at the same location as the dll.

Update: I just tried ran the client program on the server machine itself, but still the DebugBreak() causes an infinite hanging. The debugger session does not get launched.

4

2 回答 2

2

我在 C# 中使用此代码,也许您可​​以将其改编为 C++

#if DEBUG
var endTime = DateTime.Now.AddSeconds(30);
while (!System.Diagnostics.Debugger.IsAttached && DateTime.Now < endTime)
  System.Threading.Thread.Sleep(10);

if (System.Diagnostics.Debugger.IsAttached)
{
  System.Diagnostics.Debugger.Break();
}
#endif
于 2012-10-24T18:45:13.690 回答
1

为什么不能在调试器中使用 F9(断点)?但是, ADebugBreak();应该可以工作。

如果无法直接加载 DLL/EXE,您可以从“调试”菜单中“附加到进程”(希望您使用的是 Visual Studio)。

于 2011-07-29T14:16:55.077 回答