Index: lldb/tools/lldb-vscode/lldb-vscode.cpp =================================================================== --- lldb/tools/lldb-vscode/lldb-vscode.cpp +++ lldb/tools/lldb-vscode/lldb-vscode.cpp @@ -44,6 +44,7 @@ #include #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" @@ -3112,6 +3113,10 @@ // Initialize LLDB first before we do anything. lldb::SBDebugger::Initialize(); + // Terminate the debugger before the C++ destructor chain kicks in. + auto terminate_debugger = + llvm::make_scope_exit([] { lldb::SBDebugger::Terminate(); }); + RegisterRequestCallbacks(); int portno = -1; @@ -3165,8 +3170,5 @@ ++packet_idx; } - // We must terminate the debugger in a thread before the C++ destructor - // chain messes everything up. - lldb::SBDebugger::Terminate(); return 0; }