This is an archive of the discontinued LLVM Phabricator instance.

[CrashRecovery] Use SEH __try instead of VEH when available
ClosedPublic

Authored by rnk on May 16 2017, 3:44 PM.

Details

Summary

It avoids problems when other libraries raise exceptions. In particular,
OutputDebugString raises an exception that the debugger is supposed to
catch and suppress. VEH kicks in first right now, and that is entirely
incorrect.

Unfortunately, GCC does not support SEH, so I've kept the old buggy VEH
codepath around. We could fix it with SetUnhandledExceptionFilter, but
that is not per-thread, so a well-behaved library shouldn't set it.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk created this revision.May 16 2017, 3:44 PM
zturner added inline comments.May 16 2017, 4:09 PM
llvm/lib/Support/CrashRecoveryContext.cpp
145–146 ↗(On Diff #99221)

I legitimately chuckled at this comment. But for those who aren't as familiar, can you maybe expand this comment to say why it's better?

162 ↗(On Diff #99221)

I'm probably just drawing a blank here, but "or clang"? You implemented SEH for clang. Plus, clang has _MSC_VER defined. Do you mean "clang without -fms-compatibility"?

247–261 ↗(On Diff #99221)

This function is copied down below. Can we limit it to to only one copy of the function in the source file, using some preprocessor defs?

rnk updated this revision to Diff 99226.May 16 2017, 4:51 PM
rnk marked an inline comment as done.
  • address comments
zturner accepted this revision.May 16 2017, 4:58 PM

looks good with suggested fixes.

llvm/lib/Support/CrashRecoveryContext.cpp
257 ↗(On Diff #99226)

Since we've changed this value from 1 to 0, the comment above should be fixed, perhaps with an explanation of why going last is preferable.

llvm/unittests/Support/CrashRecoveryTest.cpp
79 ↗(On Diff #99226)

Just call the test something else? CallOutputDebugString?

This revision is now accepted and ready to land.May 16 2017, 4:58 PM
rnk marked an inline comment as done.May 17 2017, 10:14 AM

Thanks! Looks like I forgot to send my replies when I re-uploaded my last patch, so they're dated.

llvm/lib/Support/CrashRecoveryContext.cpp
257 ↗(On Diff #99226)

Let's just set it back to 1. I wasn't trying to change behavior here.

162 ↗(On Diff #99221)

I meant clang configured for mingw, so all that SEH jazz is probably disabled.

247–261 ↗(On Diff #99221)

Sure. I copied it to avoid nested #if's, which get pretty annoying fast.

This revision was automatically updated to reflect the committed changes.