【问题标题】:How to trigger jit debugger under windows while in wndproc message handler?如何在 wndproc 消息处理程序中触发 windows 下的 jit 调试器?
【发布时间】:2013-10-29 06:41:47
【问题描述】:

我写了一个 ASSERT 宏,如下代码:

do{
    if (true) { 
        int ret = _DbgCheckMsg(__WSHORT_FILE__, __LINE__, L"haha", L"haha", (const wchar_t*)nullptr);
        if (ret == 1) {
            TRACEF("called int 3");
            __asm int 3;
            TRACEF("after called int 3");
        } else if (ret == -1) 
            _DbgAbort();
    }
} while (0);

在 Visual Studio 中使用 F5 运行,或者在没有 F5 但不在 wndproc 处理程序中运行时,它运行良好,但如果在没有 F5 和 wndproc 消息处理程序中运行,wndproc 只是默默地吞下断点异常,就像它对c 标准断言函数。

但我需要在 wndproc 消息处理程序中触发 jit 对话框,而无需先附加调试器。我该怎么办?

我曾尝试在 SEH 中扭曲 wndproc,但没有帮助,因为它会中断异常处理程序而不是中断消息处理程序代码。

LRESULT CALLBACK WndProcWrapper(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    __try {
        return WndProc(hWnd, message, wParam, lParam);
    } __except(GetExceptionCode() == EXCEPTION_BREAKPOINT ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
        TRACEF("exception caught");
        //LPEXCEPTION_POINTERS pep = GetExceptionInformation();
    }

}

【问题讨论】:

  • 试试DebugBreak()
  • @EdwardClements:DebugBreak() 没有帮助,因为它实际上是 __asm int 3;

标签: c++ debugging winapi


【解决方案1】:

access violation in WM_PAINT not caught的回答

SEH实际上只捕获了一些wm消息,例如SEH没有捕获WM_LBUTTONDOWN。在调用 WndProc 之前删除所有 SEH 处理程序,然后您可以使用 __asm int 3 或 __debugbreak() 来中断应用程序。

    LRESULT CALLBACK WndProcWrapper(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        // get thread information block
        NT_TIB* tib;
        __asm {
            mov EAX, FS:[18h]
            mov [tib], EAX
        }
        // old exception handler list
        _EXCEPTION_REGISTRATION_RECORD* old_exception_handler = tib->ExceptionList;
        // remove all exception handler with exception of the default handler
        while( tib->ExceptionList->Next != (_EXCEPTION_REGISTRATION_RECORD*)-1 ) {
            tib->ExceptionList = tib->ExceptionList->Next;
        }

        LRESULT result = WndProc( hWnd, message, wParam, lParam );

        // restore old exception handler
        tib->ExceptionList = old_exception_handler;

        return result;
    }

【讨论】:

    猜你喜欢
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    相关资源
    最近更新 更多