[LLVMdev] CrashRecoveryContext on Windows

Justin Holewinski justin.holewinski at gmail.com
Tue Jun 5 08:08:43 PDT 2012


By default, calls to abort() in the MS CRT do not trigger an exception and
forcefully terminate the process, making CrashRecoveryContext not very
useful on Windows for catching abort(), and consequently, assert().  One
solution is to create a custom abort() handler that calls RaiseException(),
which will be caught by the handler in CrashRecoveryContext.

The relevant client-side code is:

void win_abort_handler(int) {
  RaiseException(0, 0, 0, NULL);
}

void handle_llvm_fatal(void *User, const std::string &Reason) {
  std::cerr << "Caught LLVM ERROR: " << Reason << "\n";
  abort();  // Chains to win_abort_handler on Windows
}

int main() {
  install_fatal_error_handler(handle_llvm_crash, NULL);

  signal(SIGABRT, win_abort_handler);
  _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);

  llvm_start_multithreaded();

  ContextRecoveryContext::Enable();
  // "safe" calls with RunSafely()
  ContextRecoveryContext::Disable();

  return 0;
}


Do you think it is a good idea to fold the abort signal handler and
signal/_set_abort_handler into CrashRecoveryContext?  The handler can be
registered in Enable() and removed in Disable(), like it is done in the
POSIX implementation.


-- 

Thanks,

Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120605/56821ae1/attachment.html>


More information about the llvm-dev mailing list