[Lldb-commits] [lldb] r224137 - Add a method to disable the Windows crash / assert dialogs.

Zachary Turner zturner at google.com
Fri Dec 12 10:10:52 PST 2014


Author: zturner
Date: Fri Dec 12 12:10:52 2014
New Revision: 224137

URL: http://llvm.org/viewvc/llvm-project?rev=224137&view=rev
Log:
Add a method to disable the Windows crash / assert dialogs.

When running the test suite on Windows, we can't have Windows popping
up dialogs when LLDB crashes in native code because it will hang
the test suite.  This patch silences those dialogs by checking an
environment variable at startup and configuring Windows based on
its value.

This patch also adds an environment variable to force inferiors to
never spawn in their own console window.  This is useful to prevent
new window spawm when running the test suite.

Reviewed by: Scott Graham

Differential Revision: http://reviews.llvm.org/D6628

Modified:
    lldb/trunk/.gitignore
    lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp
    lldb/trunk/source/lldb.cpp
    lldb/trunk/test/CMakeLists.txt
    lldb/trunk/test/dotest.py

Modified: lldb/trunk/.gitignore
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/.gitignore?rev=224137&r1=224136&r2=224137&view=diff
==============================================================================
--- lldb/trunk/.gitignore (original)
+++ lldb/trunk/.gitignore Fri Dec 12 12:10:52 2014
@@ -15,6 +15,9 @@
 *.orig
 # Byte compiled python modules.
 *.pyc
+*.pyproj
+*.sln
+*.suo
 # vim swap files
 .*.swp
 .sw?

Modified: lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp?rev=224137&r1=224136&r2=224137&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp (original)
+++ lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp Fri Dec 12 12:10:52 2014
@@ -38,6 +38,13 @@ ProcessLauncherWindows::LaunchProcess(co
     startupinfo.hStdInput = stdin_handle;
     startupinfo.hStdOutput = stdout_handle;
 
+    const char *hide_console_var = getenv("LLDB_LAUNCH_INFERIORS_WITHOUT_CONSOLE");
+    if (hide_console_var && llvm::StringRef(hide_console_var).equals_lower("true"))
+    {
+        startupinfo.dwFlags |= STARTF_USESHOWWINDOW;
+        startupinfo.wShowWindow = SW_HIDE;
+    }
+
     DWORD flags = CREATE_NEW_CONSOLE;
     if (launch_info.GetFlags().Test(eLaunchFlagDebug))
         flags |= DEBUG_ONLY_THIS_PROCESS;

Modified: lldb/trunk/source/lldb.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=224137&r1=224136&r2=224137&view=diff
==============================================================================
--- lldb/trunk/source/lldb.cpp (original)
+++ lldb/trunk/source/lldb.cpp Fri Dec 12 12:10:52 2014
@@ -83,6 +83,7 @@
 #endif
 
 #if defined (_WIN32)
+#include "lldb/Host/windows/windows.h"
 #include "Plugins/Process/Windows/DynamicLoaderWindows.h"
 #include "Plugins/Process/Windows/ProcessWindows.h"
 #endif
@@ -118,6 +119,25 @@ lldb_private::Initialize ()
     if (!g_inited)
     {
         g_inited = true;
+
+#if defined(_MSC_VER)
+        const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
+        if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true"))
+        {
+            // This will prevent Windows from displaying a dialog box requiring user interaction when
+            // LLDB crashes.  This is mostly useful when automating LLDB, for example via the test
+            // suite, so that a crash in LLDB does not prevent completion of the test suite.
+            ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
+
+            _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
+            _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
+            _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
+            _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
+            _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
+            _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
+        }
+#endif
+
         Log::Initialize();
         HostInfo::Initialize();
         Timer::Initialize ();

Modified: lldb/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/CMakeLists.txt?rev=224137&r1=224136&r2=224137&view=diff
==============================================================================
--- lldb/trunk/test/CMakeLists.txt (original)
+++ lldb/trunk/test/CMakeLists.txt Fri Dec 12 12:10:52 2014
@@ -42,6 +42,24 @@ set(LLDB_TEST_COMMON_ARGS
   -u CFLAGS
   )
 
+if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
+  set(LLDB_TEST_DEBUG_TEST_CRASHES
+    0
+    CACHE BOOL "(Windows only) Enables debugging of tests in the test suite by showing the crash dialog when lldb crashes")
+
+  set(LLDB_TEST_HIDE_CONSOLE_WINDOWS
+    1
+    CACHE BOOL "(Windows only) Hides the console window for an inferior when it is launched through the test suite")
+
+  if (LLDB_TEST_DEBUG_TEST_CRASHES)
+    set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --enable-crash-dialog)
+  endif()
+
+  if (NOT LLDB_TEST_HIDE_CONSOLE_WINDOWS)
+    set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --show-inferior-console)
+  endif()
+endif()
+
 add_python_test_target(check-lldb-single
   ${LLDB_SOURCE_DIR}/test/dotest.py
   "${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS}"
@@ -51,7 +69,7 @@ add_python_test_target(check-lldb-single
 set(LLDB_DOSEP_ARGS -o;\"-q;${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS}\")
 
 # If tests crash cause LLDB to crash, or things are otherwise unstable, or if machine-parsable
-# output is desired (i.e. in continuous integration contexts) check-lldb-sep is a better target.
+# output is desired (i.e. in continuous integration contexts) check-lldb-single is a better target.
 add_python_test_target(check-lldb
   ${LLDB_SOURCE_DIR}/test/dosep.py
   "${LLDB_DOSEP_ARGS}"

Modified: lldb/trunk/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=224137&r1=224136&r2=224137&view=diff
==============================================================================
--- lldb/trunk/test/dotest.py (original)
+++ lldb/trunk/test/dotest.py Fri Dec 12 12:10:52 2014
@@ -554,6 +554,10 @@ def parseOptionsAndInitTestdirs():
     X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)')
     X('-w', 'Insert some wait time (currently 0.5 sec) between consecutive test cases')
     X('-T', 'Obtain and dump svn information for this checkout of LLDB (off by default)')
+    group.add_argument('--enable-crash-dialog', dest='disable_crash_dialog', action='store_false', help='(Windows only) When LLDB crashes, display the Windows crash dialog.')
+    group.add_argument('--show-inferior-console', dest='hide_inferior_console', action='store_false', help='(Windows only) When launching an inferior, dont hide its console window.')
+    group.set_defaults(disable_crash_dialog=True)
+    group.set_defaults(hide_inferior_console=True)
 
     # Remove the reference to our helper function
     del X
@@ -775,6 +779,10 @@ def parseOptionsAndInitTestdirs():
     if args.sharp:
         count = args.sharp
 
+    if sys.platform.startswith('win32'):
+        os.environ['LLDB_DISABLE_CRASH_DIALOG'] = str(args.disable_crash_dialog)
+        os.environ['LLDB_LAUNCH_INFERIORS_WITHOUT_CONSOLE'] = str(args.hide_inferior_console)
+
     if do_help == True:
         usage(parser)
 





More information about the lldb-commits mailing list