Commit 3ff097ff by Jamie Madill Committed by Commit Bot

Win: Add ANGLE_WAIT_FOR_DEBUGGER option.

Setting this environment variable will make ANGLE pop up a dialog. The dev can then attach a debugger to this dialog. Only implemented on Windows currently. This option is only available when ASSERTs are enabled in libGLESv2. The code is based on SwiftShader's implementation of WaitForDebugger: https://cs.chromium.org/chromium/src/third_party/swiftshader/src/Vulkan/main.cpp Bug: angleproject:4072 Change-Id: I160cb91a423a6d4517f067f2a6f3a2d953b26505 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1892173Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 5e6be1d6
// Microsoft Visual C++ generated resource script. // Microsoft Visual C++ generated resource script.
// //
#include "resource.h" #include "../libGLESv2/resource.h"
#define APSTUDIO_READONLY_SYMBOLS #define APSTUDIO_READONLY_SYMBOLS
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
...@@ -87,6 +87,40 @@ BEGIN ...@@ -87,6 +87,40 @@ BEGIN
END END
END END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOGEX 0, 0, 129, 47
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Waiting for debugger"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,72,26,50,14
LTEXT "Attach a debugger or ESC to cancel",IDC_STATIC,7,7,115,8
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 122
TOPMARGIN, 7
BOTTOMMARGIN, 40
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources #endif // English (U.S.) resources
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
......
...@@ -942,8 +942,6 @@ libangle_null_sources = [ ...@@ -942,8 +942,6 @@ libangle_null_sources = [
libgl_sources = [ libgl_sources = [
"src/common/angleutils.h", "src/common/angleutils.h",
"src/common/debug.h", "src/common/debug.h",
"src/libGLESv2/global_state.cpp",
"src/libGLESv2/global_state.h",
"src/libGL/entry_points_gl_1_0_autogen.cpp", "src/libGL/entry_points_gl_1_0_autogen.cpp",
"src/libGL/entry_points_gl_1_0_autogen.h", "src/libGL/entry_points_gl_1_0_autogen.h",
"src/libGL/entry_points_gl_1_1_autogen.cpp", "src/libGL/entry_points_gl_1_1_autogen.cpp",
...@@ -989,7 +987,9 @@ libgl_sources = [ ...@@ -989,7 +987,9 @@ libgl_sources = [
"src/libGL/libGL.rc", "src/libGL/libGL.rc",
"src/libGL/proc_table_wgl.h", "src/libGL/proc_table_wgl.h",
"src/libGL/proc_table_wgl_autogen.cpp", "src/libGL/proc_table_wgl_autogen.cpp",
"src/libGL/resource.h", "src/libGLESv2/global_state.cpp",
"src/libGLESv2/global_state.h",
"src/libGLESv2/resource.h",
] ]
libglesv2_sources = [ libglesv2_sources = [
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "common/debug.h" #include "common/debug.h"
#include "common/platform.h" #include "common/platform.h"
#include "common/system_utils.h"
#include "common/tls.h" #include "common/tls.h"
#include "libGLESv2/resource.h"
namespace gl namespace gl
{ {
...@@ -206,11 +208,67 @@ bool TerminateProcess() ...@@ -206,11 +208,67 @@ bool TerminateProcess()
} // namespace egl } // namespace egl
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID) namespace
{
// The following WaitForDebugger code is based on SwiftShader. See:
// https://cs.chromium.org/chromium/src/third_party/swiftshader/src/Vulkan/main.cpp
# if defined(ANGLE_ENABLE_ASSERTS)
INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rect;
switch (uMsg)
{
case WM_INITDIALOG:
::GetWindowRect(GetDesktopWindow(), &rect);
::SetWindowPos(hwnd, HWND_TOP, rect.right / 2, rect.bottom / 2, 0, 0, SWP_NOSIZE);
::SetTimer(hwnd, 1, 100, NULL);
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL)
{
::EndDialog(hwnd, 0);
}
break;
case WM_TIMER:
if (angle::IsDebuggerAttached())
{
::EndDialog(hwnd, 0);
}
}
return FALSE;
}
void WaitForDebugger(HINSTANCE instance)
{
if (angle::IsDebuggerAttached())
return;
HRSRC dialog = ::FindResourceA(instance, MAKEINTRESOURCEA(IDD_DIALOG1), MAKEINTRESOURCEA(5));
if (!dialog)
{
printf("Error finding wait for debugger dialog. Error %lu.\n", ::GetLastError());
return;
}
DLGTEMPLATE *dialogTemplate = reinterpret_cast<DLGTEMPLATE *>(::LoadResource(instance, dialog));
::DialogBoxIndirectA(instance, dialogTemplate, NULL, DebuggerWaitDialogProc);
}
# else
void WaitForDebugger(HINSTANCE instance) {}
# endif // defined(ANGLE_ENABLE_ASSERTS)
} // namespace
extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID)
{ {
switch (reason) switch (reason)
{ {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
if (angle::GetEnvironmentVar("ANGLE_WAIT_FOR_DEBUGGER") == "1")
{
WaitForDebugger(instance);
}
return static_cast<BOOL>(egl::InitializeProcess()); return static_cast<BOOL>(egl::InitializeProcess());
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
......
...@@ -87,6 +87,40 @@ BEGIN ...@@ -87,6 +87,40 @@ BEGIN
END END
END END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOGEX 0, 0, 129, 47
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Waiting for debugger"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,72,26,50,14
LTEXT "Attach a debugger or ESC to cancel",IDC_STATIC,7,7,115,8
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 122
TOPMARGIN, 7
BOTTOMMARGIN, 40
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources #endif // English (U.S.) resources
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Microsoft Visual C++ generated include file. // Microsoft Visual C++ generated include file.
// Used by libGLESv2.rc // Used by libGLESv2.rc
#define IDD_DIALOG1 101
#define IDC_STATIC -1
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment