[Lldb-commits] [lldb] [lldb-dap] Ensure the IO forwarding threads are managed by the DAP object lifecycle. (PR #120457)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 20 02:37:51 PST 2024
================
@@ -173,6 +178,63 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
return nullptr;
}
+llvm::Error DAP::ConfigureIO(std::optional<std::FILE *> overrideOut,
+ std::optional<std::FILE *> overrideErr) {
+ auto *inull = lldb_private::FileSystem::Instance().Fopen(
+ lldb_private::FileSystem::DEV_NULL, "w");
+ in = lldb::SBFile(inull, true);
+
+ lldb_private::Status status;
+ status = pout.CreateNew(/*child_process_inherit=*/false);
+ if (status.Fail())
+ return status.takeError();
+ status = perr.CreateNew(/*child_process_inherit=*/false);
+ if (status.Fail())
+ return status.takeError();
+
+ if (overrideOut) {
+ if (dup2(pout.GetWriteFileDescriptor(), fileno(*overrideOut)) == -1) {
+ return llvm::make_error<llvm::StringError>(
+ llvm::errnoAsErrorCode(),
+ llvm::formatv("override fd=%d failed", fileno(*overrideOut))
+ .str()
+ .c_str());
+ }
+ }
+
+ if (overrideErr) {
+ if (dup2(perr.GetWriteFileDescriptor(), fileno(*overrideErr)) == -1) {
+ return llvm::make_error<llvm::StringError>(
+ llvm::errnoAsErrorCode(),
+ llvm::formatv("override fd=%d failed", fileno(*overrideErr))
+ .str()
+ .c_str());
+ }
+ }
+
+ auto forwarder = [&](lldb_private::Pipe &pipe, OutputType outputType) {
----------------
labath wrote:
don't use `[&]` in a lambda which outlives the enclosing function. List the captures explicitly.
https://github.com/llvm/llvm-project/pull/120457
More information about the lldb-commits
mailing list