This is an archive of the discontinued LLVM Phabricator instance.

[Support] Don't print stacktrace if DbgHelp.dll hasn't been loaded yet
ClosedPublic

Authored by werat on Feb 7 2022, 12:38 PM.

Details

Summary

On Windows certain function from Signals.h require that DbgHelp.dll is loaded. This typically happens when the main program calls llvm::InitLLVM, however in some cases main program doesn't do that (e.g. when the application is using LLDB via liblldb.dll). This patch adds a safe guard to prevent crashes. More discussion in
https://reviews.llvm.org/D119009.

Diff Detail

Event Timeline

werat created this revision.Feb 7 2022, 12:38 PM
werat requested review of this revision.Feb 7 2022, 12:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2022, 12:38 PM
aganea added a comment.Feb 7 2022, 1:05 PM

Do you think you can add a unit test (in SupportTests) that demonstrates the issue before your patch?

aganea added a comment.Feb 7 2022, 1:16 PM

Maybe take a look at llvm/unittests/Support/ProgramTest.cpp (for example TestExecuteAndWaitTimeout). You should be able to start the executable again with an extra env. variable which prevents the call to PrintStackTraceOnErrorSignal in llvm/utils/unittest/UnitTestMain/TestMain.cpp.

werat updated this revision to Diff 406737.Feb 8 2022, 2:06 AM

Added a unit test.

werat added a comment.Feb 8 2022, 2:07 AM

Maybe take a look at llvm/unittests/Support/ProgramTest.cpp (for example TestExecuteAndWaitTimeout). You should be able to start the executable again with an extra env. variable which prevents the call to PrintStackTraceOnErrorSignal in llvm/utils/unittest/UnitTestMain/TestMain.cpp.

I've added a test and verified that on Windows it fails without the safeguard in Signals.inc. Thanks for the pointer!

aganea accepted this revision.Feb 8 2022, 5:30 AM

LGTM with a comment:

llvm/utils/unittest/UnitTestMain/TestMain.cpp
25

I think it's more desirable to not have an empty block. You could could do if (!getenv...) and add the comment above the if statement.

This revision is now accepted and ready to land.Feb 8 2022, 5:30 AM
werat updated this revision to Diff 406797.Feb 8 2022, 6:37 AM

Remove empty if block

werat marked an inline comment as done.Feb 8 2022, 6:37 AM

Thanks! I've removed the empty if block.

This revision was landed with ongoing or failed builds.Feb 8 2022, 8:38 AM
This revision was automatically updated to reflect the committed changes.