================ @@ -32,35 +34,44 @@ using namespace lldb_dap; namespace lldb_dap { -DAP::DAP(llvm::StringRef path, ReplMode repl_mode) - : debug_adaptor_path(path), broadcaster("lldb-dap"), - exception_breakpoints(), focus_tid(LLDB_INVALID_THREAD_ID), - stop_at_entry(false), is_attach(false), +DAP::DAP(llvm::StringRef path, llvm::raw_ostream *log, ReplMode repl_mode, + std::vector<std::string> pre_init_commands) + : debug_adaptor_path(path), broadcaster("lldb-dap"), log(log), + exception_breakpoints(), pre_init_commands(pre_init_commands), + focus_tid(LLDB_INVALID_THREAD_ID), stop_at_entry(false), is_attach(false), enable_auto_variable_summaries(false), enable_synthetic_child_debugging(false), display_extended_backtrace(false), restarting_process_id(LLDB_INVALID_PROCESS_ID), configuration_done_sent(false), waiting_for_run_in_terminal(false), progress_event_reporter( [&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }), - reverse_request_seq(0), repl_mode(repl_mode) { - const char *log_file_path = getenv("LLDBDAP_LOG"); -#if defined(_WIN32) - // Windows opens stdout and stdin in text mode which converts \n to 13,10 - // while the value is just 10 on Darwin/Linux. Setting the file mode to binary - // fixes this. - int result = _setmode(fileno(stdout), _O_BINARY); - assert(result); - result = _setmode(fileno(stdin), _O_BINARY); - UNUSED_IF_ASSERT_DISABLED(result); - assert(result); -#endif - if (log_file_path) - log.reset(new std::ofstream(log_file_path)); -} + reverse_request_seq(0), repl_mode(repl_mode) {} DAP::~DAP() = default; +llvm::Error DAP::ConfigureIO(int out_fd, int err_fd) { + llvm::Expected<int> new_stdout_fd = + RedirectFd(out_fd, [this](llvm::StringRef data) { + SendOutput(OutputType::Stdout, data); + }); ---------------- labath wrote:
> once the DAP object is not used anymore I don't think you can really guarantee that while there are detached forwarding threads floating around. I think we need to shut those down first. The tricky part is doing that in cross-platform way, but since we're already all-in on lldbHost, I think we could/should use lldb's Pipe::ReadWithTimeout to implement polled reads (which check for a "should terminate flag" in between). Not the most elegant solution, but I it's probably the best we can do with what we have right now. One of these days I'm going to implement a MainLoop<->Pipe integration that can multiplex reads (and other things), but it's not very easy due to very different Pipe APIs on windows vs. unix. I also believe this parts should be a separate patch, as there's a lot of subtleness involved. https://github.com/llvm/llvm-project/pull/116392 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits