gpt4 book ai didi

c++ - 当我从 OnCopyData 返回 TRUE 时,为什么会触发断点?

转载 作者:可可西里 更新时间:2023-11-01 09:22:26 27 4
gpt4 key购买 nike

我正在使用 Visual Studio 调试 ATL 应用程序。

当我在这段代码中跨过return TRUE时,出现错误:

BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) {

// Code snipped from here - maybe this causes stack/heap corruption?

// I have a breakpoint here, if I step over (F10), AFX trace message
// is shown (as below)
return TRUE;

}

这是显示的消息框:

Windows has triggered a breakpoint in foobar.exe.

This may be due to a corruption of the heap, which indicates a bug in foobar.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while phonejournal.exe has focus.

The output window may have more diagnostic information.

消息有点含糊,我想知道我可以使用什么工具来获取更多信息。调试器在 atltrace.h 中调用 AtlTraceVU 时中断:

 inline void __cdecl CTrace::TraceV(const char *pszFileName, int nLine,
DWORD_PTR dwCategory, UINT nLevel, LPCWSTR pszFmt, va_list args) const
{
AtlTraceVU(m_dwModule, pszFileName, nLine, dwCategory, nLevel, pszFmt, args);
}

最佳答案

微软的Application Verifier可能会有所帮助。如果应用程序有堆损坏,此实用程序可能会导致在错误发生时出现异常。但是,它在运行时会使用大量内存,因为它会在内存分配方案中产生很大的变化。

以下明显有缺陷的代码给出了简单的演示:

char *pc = malloc( 4 );
memcpy( pc, "abcdabcd", 9 );
free( pc );

当我在没有应用程序验证器的情况下运行它时,它运行完成,没有明显的错误。但是,对于应用程序验证程序,它会导致异常 (0x80000003)。 Application Verifier 强制分配位于段的末尾(例如 0x1e9eff8)。 memcpy 导致写入后续段,这导致 memcpy 调用期间出现异常。如果在这个简单的示例中覆盖较少,则在 free 调用之前不会发生中断,但这仍然比没有异常要好。这是一个非常酷的实用程序。

关于c++ - 当我从 OnCopyData 返回 TRUE 时,为什么会触发断点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2104978/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com