On Windows lldbassert()[1] will segfault[2] if RegisterHandler() from lib/Support/Windows/Signals.inc wasn't called earlier at some point (it loads Dbghelp.dll and initializes the function pointers [3]). The RegisterHandler() function is called from RemoveFileOnSignal, DontRemoveFileOnSignal, SetInterruptFunction, AddSignalHandler and PrintStackTraceOnErrorSignal.
For LLDB PrintStackTraceOnErrorSignal() is called from InitLLVM ctor [4], which is created in the LLDB driver [5]. However in case of using the SB API via liblldb, none of these functions is called and thus any lldbassert() will crash the process.
At first glance it seems SBDebugger::Initialize() can do the initialization, but PrintStackTraceOnErrorSignal requires argv, which is not available there at the moment (and I'm not sure whether this is desirable behavior for the _library_).
It's also possible to just call RegisterHandler() in llvm::sys::PrintStackTrace() to ensure the Dbghelp.dll is always loaded. This patch does that.
Please, let me know if this approach is OK or a different solution should be implemented.
[1] https://github.com/llvm/llvm-project/blob/0236c571810dea1b72d99ee0af124a7a09976e00/lldb/source/Utility/LLDBAssert.cpp#L45
[2] https://github.com/llvm/llvm-project/blob/0236c571810dea1b72d99ee0af124a7a09976e00/llvm/lib/Support/Windows/Signals.inc#L300
[3] https://github.com/llvm/llvm-project/blob/0236c571810dea1b72d99ee0af124a7a09976e00/llvm/lib/Support/Windows/Signals.inc#L163
[4] https://github.com/llvm/llvm-project/blob/0236c571810dea1b72d99ee0af124a7a09976e00/llvm/lib/Support/InitLLVM.cpp#L37
[5] https://github.com/llvm/llvm-project/blob/0236c571810dea1b72d99ee0af124a7a09976e00/lldb/tools/driver/Driver.cpp#L778