summaryrefslogtreecommitdiffstats
path: root/src/ninja.cc
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-07-27 18:44:06 (GMT)
committerEvan Martin <martine@danga.com>2012-07-27 18:44:06 (GMT)
commit9dd3f0dfdf42cc9eefc10664d747044f50a0ffd8 (patch)
tree45479fe2fd7b29023dc375c1fe6db0bdacd3265f /src/ninja.cc
parentf7a22e3bc97fdeb87d930b7734680c481c6010bf (diff)
parent28c53397ed6876363a93e5a0ac3cd54ed66b662f (diff)
downloadNinja-9dd3f0dfdf42cc9eefc10664d747044f50a0ffd8.zip
Ninja-9dd3f0dfdf42cc9eefc10664d747044f50a0ffd8.tar.gz
Ninja-9dd3f0dfdf42cc9eefc10664d747044f50a0ffd8.tar.bz2
Merge branch 'set_terminate' of git://github.com/gmoudry/ninja into minidump
(This likely doesn't compile, just getting all the history in place.) Conflicts: src/util.cc
Diffstat (limited to 'src/ninja.cc')
-rw-r--r--src/ninja.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 619c3bf..393f717 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -628,7 +628,42 @@ int RunBuild(Globals* globals, int argc, char** argv) {
} // anonymous namespace
+
+#ifdef _MSC_VER
+
+/// This handler processes fatal crashes that you can't catch
+/// Test example: C++ exception in a stack-unwind-block
+/// Real-world example: ninja launched a compiler to process a tricky C++ input file.
+/// The compiler got itself into a state where it generated 3 GB of output and caused ninja to crash
+void ninja_terminate_fct() {
+ Create_Win32_MiniDump(NULL);
+ Fatal("terminate handler called");
+}
+
+/// main_unsafe is called from within an exception handling block
+int main_unsafe(int argc, char** argv);
+
+/// Windows main() uses SEH (Structured exception handling)
+int main(int argc, char** argv) {
+ // set a handler to catch crashes not caught by the __try..__except block (e.g. an exception in a stack-unwind-block)
+ set_terminate(ninja_terminate_fct);
+ __try {
+ // running inside __try ... __except suppresses any Windows error dialogs for errors such as bad_alloc
+ return main_unsafe(argc, argv);
+ }
+ __except(exception_filter(GetExceptionCode(), GetExceptionInformation())) {
+ // you will land here e.g. if you run out of memory, or run inside a distribution environment that fails
+ fprintf(stderr, "ninja: exception, exiting with error code 2\n");
+ // common error situations below return exitCode=1, 2 was chosen to indicate a more serious problem
+ return 2;
+ }
+}
+
+int main_unsafe (int argc, char** argv) {
+#else
+//on Linux, we have no exception handling
int main(int argc, char** argv) {
+#endif
Globals globals;
globals.ninja_command = argv[0];
const char* input_file = "build.ninja";