[Lldb-commits] [lldb] [lldb-dap] Refactoring lldb-dap port listening mode to allow multiple connections. (PR #116392)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 29 01:12:33 PST 2025


================
@@ -5028,48 +5021,128 @@ int main(int argc, char *argv[]) {
 #endif
 
   // Initialize LLDB first before we do anything.
-  lldb::SBDebugger::Initialize();
+  lldb::SBError error = lldb::SBDebugger::InitializeWithErrorHandling();
+  if (error.Fail()) {
+    llvm::errs() << "Failed to initialize LLDB: " << error.GetCString() << "\n";
+    return EXIT_FAILURE;
+  }
 
   // Terminate the debugger before the C++ destructor chain kicks in.
   auto terminate_debugger =
       llvm::make_scope_exit([] { lldb::SBDebugger::Terminate(); });
 
-  DAP dap = DAP(program_path.str(), default_repl_mode);
+  auto HandleClient = [=](int out_fd, int err_fd, StreamDescriptor input,
+                          StreamDescriptor output) {
+    DAP dap = DAP(program_path, log, default_repl_mode, pre_init_commands);
+    dap.input.descriptor = std::move(input);
+    dap.output.descriptor = std::move(output);
+    RegisterRequestCallbacks(dap);
+
+    if (auto Err = dap.ConfigureIO(out_fd, err_fd)) {
+      if (log)
+        *log << "configureIO failed: " << llvm::toStringWithoutConsuming(Err)
+             << "\n";
+      std::cerr << "failed to configureIO: " << llvm::toString(std::move(Err))
----------------
labath wrote:

That's good but beware `os << error` does not "consume" (set the ["checked" bit](https://llvm.org/docs/ProgrammersManual.html#recoverable-errors)), on the llvm::Error object (which means it will trigger an assert in debug mode). You need to consume it somehow, e.g., via toString, or `logAllUnhandledErrors` (the latter works best when the entire "main" function is wrapped in something returning an error object

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


More information about the lldb-commits mailing list