Skip to content

Commit 555a7a6

Browse files
author
Zachary Turner
committed
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 llvm-svn: 224137
1 parent 59aaa6c commit 555a7a6

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

lldb/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*.orig
1616
# Byte compiled python modules.
1717
*.pyc
18+
*.pyproj
19+
*.sln
20+
*.suo
1821
# vim swap files
1922
.*.swp
2023
.sw?

lldb/source/Host/windows/ProcessLauncherWindows.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info, Erro
3838
startupinfo.hStdInput = stdin_handle;
3939
startupinfo.hStdOutput = stdout_handle;
4040

41+
const char *hide_console_var = getenv("LLDB_LAUNCH_INFERIORS_WITHOUT_CONSOLE");
42+
if (hide_console_var && llvm::StringRef(hide_console_var).equals_lower("true"))
43+
{
44+
startupinfo.dwFlags |= STARTF_USESHOWWINDOW;
45+
startupinfo.wShowWindow = SW_HIDE;
46+
}
47+
4148
DWORD flags = CREATE_NEW_CONSOLE;
4249
if (launch_info.GetFlags().Test(eLaunchFlagDebug))
4350
flags |= DEBUG_ONLY_THIS_PROCESS;

lldb/source/lldb.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#endif
8484

8585
#if defined (_WIN32)
86+
#include "lldb/Host/windows/windows.h"
8687
#include "Plugins/Process/Windows/DynamicLoaderWindows.h"
8788
#include "Plugins/Process/Windows/ProcessWindows.h"
8889
#endif
@@ -118,6 +119,25 @@ lldb_private::Initialize ()
118119
if (!g_inited)
119120
{
120121
g_inited = true;
122+
123+
#if defined(_MSC_VER)
124+
const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
125+
if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true"))
126+
{
127+
// This will prevent Windows from displaying a dialog box requiring user interaction when
128+
// LLDB crashes. This is mostly useful when automating LLDB, for example via the test
129+
// suite, so that a crash in LLDB does not prevent completion of the test suite.
130+
::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
131+
132+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
133+
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
134+
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
135+
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
136+
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
137+
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
138+
}
139+
#endif
140+
121141
Log::Initialize();
122142
HostInfo::Initialize();
123143
Timer::Initialize ();

lldb/test/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ set(LLDB_TEST_COMMON_ARGS
4242
-u CFLAGS
4343
)
4444

45+
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
46+
set(LLDB_TEST_DEBUG_TEST_CRASHES
47+
0
48+
CACHE BOOL "(Windows only) Enables debugging of tests in the test suite by showing the crash dialog when lldb crashes")
49+
50+
set(LLDB_TEST_HIDE_CONSOLE_WINDOWS
51+
1
52+
CACHE BOOL "(Windows only) Hides the console window for an inferior when it is launched through the test suite")
53+
54+
if (LLDB_TEST_DEBUG_TEST_CRASHES)
55+
set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --enable-crash-dialog)
56+
endif()
57+
58+
if (NOT LLDB_TEST_HIDE_CONSOLE_WINDOWS)
59+
set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --show-inferior-console)
60+
endif()
61+
endif()
62+
4563
add_python_test_target(check-lldb-single
4664
${LLDB_SOURCE_DIR}/test/dotest.py
4765
"${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS}"
@@ -51,7 +69,7 @@ add_python_test_target(check-lldb-single
5169
set(LLDB_DOSEP_ARGS -o;\"-q;${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS}\")
5270

5371
# If tests crash cause LLDB to crash, or things are otherwise unstable, or if machine-parsable
54-
# output is desired (i.e. in continuous integration contexts) check-lldb-sep is a better target.
72+
# output is desired (i.e. in continuous integration contexts) check-lldb-single is a better target.
5573
add_python_test_target(check-lldb
5674
${LLDB_SOURCE_DIR}/test/dosep.py
5775
"${LLDB_DOSEP_ARGS}"

lldb/test/dotest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ def parseOptionsAndInitTestdirs():
554554
X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)')
555555
X('-w', 'Insert some wait time (currently 0.5 sec) between consecutive test cases')
556556
X('-T', 'Obtain and dump svn information for this checkout of LLDB (off by default)')
557+
group.add_argument('--enable-crash-dialog', dest='disable_crash_dialog', action='store_false', help='(Windows only) When LLDB crashes, display the Windows crash dialog.')
558+
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.')
559+
group.set_defaults(disable_crash_dialog=True)
560+
group.set_defaults(hide_inferior_console=True)
557561

558562
# Remove the reference to our helper function
559563
del X
@@ -775,6 +779,10 @@ def parseOptionsAndInitTestdirs():
775779
if args.sharp:
776780
count = args.sharp
777781

782+
if sys.platform.startswith('win32'):
783+
os.environ['LLDB_DISABLE_CRASH_DIALOG'] = str(args.disable_crash_dialog)
784+
os.environ['LLDB_LAUNCH_INFERIORS_WITHOUT_CONSOLE'] = str(args.hide_inferior_console)
785+
778786
if do_help == True:
779787
usage(parser)
780788

0 commit comments

Comments
 (0)