显式崩溃应用程序的最简洁方法?
我的应用程序内置了自定义崩溃处理(请参阅 John Robbins 的有关“调试 Windows 应用程序”的优秀书籍)。为了测试这个功能,我总是使用 Windows 函数 DebugBreak() 并且它总是工作得很好。但从 Windows 7 开始,调用此函数只会显示“已到达断点”并停止应用程序,而不会调用我的崩溃处理程序。
我总是可以将此代码放入我的应用程序中来测试崩溃功能:
int *ptr = (int *)0xdeadbeef;
*ptr = 123456789;
或者甚至添加几个案例,以防万一 0xdeadbeef 是一个有效地址:
int *ptr = (int *)0xdeadbeef;
*ptr = 123456789;
ptr = (int *)0L;
*ptr = 123456789;
ptr = (int *)0xffffffff;
*ptr = 123456789;
但我想知道:是否有一种更干净的方法可以在 Windows 下崩溃您的应用程序?
My application has custom crash-handling built-in (see John Robbins' excellent book about "Debugging Windows Applications"). To test this functionality, I always used the Windows function DebugBreak() and this always worked perfectly. But since Windows 7, calling this function just says "A breakpoint has been reached" and stops the application without calling my crash handlers.
I could always put this code in my application to test the crash-functionality:
int *ptr = (int *)0xdeadbeef;
*ptr = 123456789;
Or even add several cases, just in case 0xdeadbeef is a valid address:
int *ptr = (int *)0xdeadbeef;
*ptr = 123456789;
ptr = (int *)0L;
*ptr = 123456789;
ptr = (int *)0xffffffff;
*ptr = 123456789;
But I was wondering: isn't there a cleaner way to crash your application under Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需创建一个指向具有某些成员函数的对象的空指针,然后尝试调用其中一个?也许在一个函数中执行它,这样你就知道它是什么,
这绝对是最简单的方法,并且非常清楚发生了什么
Just create a null pointer to an object with some member functions a try and call one of them? And maybe do it in a function so you know what it daoes
Definitely the easiest way and pretty clear whats going on
您可以使用 __debugbreak() 内在函数代替 DebugBreak() 函数。这不会说明任何问题,并且会因 EXCEPTION_BREAKPOINT
RaiseException()< /a> 是另一种崩溃方式。
You can use __debugbreak() intrinsic instead of DebugBreak() function. This does not say anything and crashes with EXCEPTION_BREAKPOINT
RaiseException() is yet another way to crash.