[Lldb-commits] [lldb] [lldb-dap] Add stdio redirection for integrated and external terminals (PR #161089)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 7 13:10:29 PDT 2025


================
@@ -143,6 +148,73 @@ static void PrintVersion() {
   llvm::outs() << "liblldb: " << lldb::SBDebugger::GetVersionString() << '\n';
 }
 
+#if not defined(_WIN32)
+struct FDGroup {
+  std::vector<int> fds;
+  bool read = false;
+  bool write = false;
+};
+
+static llvm::Error RedirectToFile(const FDGroup &fdg, llvm::StringRef file) {
+  if (!fdg.read && !fdg.write)
+    return llvm::Error::success();
+  int flags = 0;
+  if (fdg.read && fdg.write)
+    flags = O_NOCTTY | O_CREAT | O_RDWR;
+  else if (fdg.read)
+    flags = O_NOCTTY | O_RDONLY;
+  else
+    flags = O_NOCTTY | O_CREAT | O_WRONLY | O_TRUNC;
----------------
JDevlieghere wrote:

Maybe consider making this `FDGroup::GetFlags()` and have some early returns to avoid all the else cases? Something like:

```
int GetFlags() const {
  if (fdg.read && fdg.write)
    return O_NOCTTY | O_CREAT | O_RDWR;
  if (fdg.read)
    return O_NOCTTY | O_RDONLY;
  return O_NOCTTY | O_CREAT | O_WRONLY | O_TRUNC;
} 
``` 

https://github.com/llvm/llvm-project/pull/161089


More information about the lldb-commits mailing list