Skip to content

[lldb] Remove Debugger::Get{Output,Error}Stream (NFC) #126821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

JDevlieghere
Copy link
Member

Remove Debugger::GetOutputStream and Debugger::GetErrorStream in preparation for replacing both with a new variant that needs to be locked and hence can't be handed out like we do right now.

The patch replaces most uses with GetAsyncOutputStream and GetAsyncErrorStream respectively. There methods return new StreamSP objects that automatically get flushed on destruction.

See #126630 for more details.

@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

Remove Debugger::GetOutputStream and Debugger::GetErrorStream in preparation for replacing both with a new variant that needs to be locked and hence can't be handed out like we do right now.

The patch replaces most uses with GetAsyncOutputStream and GetAsyncErrorStream respectively. There methods return new StreamSP objects that automatically get flushed on destruction.

See #126630 for more details.


Patch is 25.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/126821.diff

15 Files Affected:

  • (modified) lldb/include/lldb/Core/Debugger.h (-4)
  • (modified) lldb/source/API/SBDebugger.cpp (+10-18)
  • (modified) lldb/source/Core/Debugger.cpp (+4-5)
  • (modified) lldb/source/Core/DynamicLoader.cpp (+8-8)
  • (modified) lldb/source/Interpreter/ScriptInterpreter.cpp (+2-2)
  • (modified) lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (+40-41)
  • (modified) lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp (+11-12)
  • (modified) lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp (+6-5)
  • (modified) lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp (+2-2)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp (+2-2)
  • (modified) lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp (+2-2)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+2-2)
  • (modified) lldb/source/Target/Process.cpp (+2-2)
  • (modified) lldb/source/Target/Target.cpp (+3-3)
  • (modified) lldb/source/Target/ThreadPlanTracer.cpp (+1-1)
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 70f4c4216221c..d7751ca045bb2 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -143,10 +143,6 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
 
   File &GetErrorFile() { return m_error_stream_sp->GetFile(); }
 
-  StreamFile &GetOutputStream() { return *m_output_stream_sp; }
-
-  StreamFile &GetErrorStream() { return *m_error_stream_sp; }
-
   repro::DataRecorder *GetInputRecorder();
 
   Status SetInputString(const char *data);
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index bdb8e538b99f8..5d7cfef07c138 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -508,39 +508,31 @@ SBFile SBDebugger::GetInputFile() {
 
 FILE *SBDebugger::GetOutputFileHandle() {
   LLDB_INSTRUMENT_VA(this);
-  if (m_opaque_sp) {
-    StreamFile &stream_file = m_opaque_sp->GetOutputStream();
-    return stream_file.GetFile().GetStream();
-  }
+  if (m_opaque_sp)
+    return m_opaque_sp->GetOutputStreamSP()->GetFile().GetStream();
   return nullptr;
 }
 
 SBFile SBDebugger::GetOutputFile() {
   LLDB_INSTRUMENT_VA(this);
-  if (m_opaque_sp) {
-    SBFile file(m_opaque_sp->GetOutputStream().GetFileSP());
-    return file;
-  }
+  if (m_opaque_sp)
+    return SBFile(m_opaque_sp->GetOutputStreamSP()->GetFileSP());
   return SBFile();
 }
 
 FILE *SBDebugger::GetErrorFileHandle() {
   LLDB_INSTRUMENT_VA(this);
 
-  if (m_opaque_sp) {
-    StreamFile &stream_file = m_opaque_sp->GetErrorStream();
-    return stream_file.GetFile().GetStream();
-  }
+  if (m_opaque_sp)
+    return m_opaque_sp->GetErrorStreamSP()->GetFile().GetStream();
   return nullptr;
 }
 
 SBFile SBDebugger::GetErrorFile() {
   LLDB_INSTRUMENT_VA(this);
   SBFile file;
-  if (m_opaque_sp) {
-    SBFile file(m_opaque_sp->GetErrorStream().GetFileSP());
-    return file;
-  }
+  if (m_opaque_sp)
+    return SBFile(m_opaque_sp->GetErrorStreamSP()->GetFileSP());
   return SBFile();
 }
 
@@ -581,8 +573,8 @@ void SBDebugger::HandleCommand(const char *command) {
 
     sb_interpreter.HandleCommand(command, result, false);
 
-    result.PutError(m_opaque_sp->GetErrorStream().GetFileSP());
-    result.PutOutput(m_opaque_sp->GetOutputStream().GetFileSP());
+    result.PutError(m_opaque_sp->GetErrorFile().GetStream());
+    result.PutOutput(m_opaque_sp->GetOutputFile().GetStream());
 
     if (!m_opaque_sp->GetAsyncExecution()) {
       SBProcess process(GetCommandInterpreter().GetProcess());
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 2df2aeb20aa26..18569e155b517 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -257,12 +257,11 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
         std::list<Status> errors;
         StreamString feedback_stream;
         if (!target_sp->LoadScriptingResources(errors, feedback_stream)) {
-          Stream &s = GetErrorStream();
-          for (auto &error : errors) {
-            s.Printf("%s\n", error.AsCString());
-          }
+          lldb::StreamSP s = GetAsyncErrorStream();
+          for (auto &error : errors)
+            s->Printf("%s\n", error.AsCString());
           if (feedback_stream.GetSize())
-            s.PutCString(feedback_stream.GetString());
+            s->PutCString(feedback_stream.GetString());
         }
       }
     }
diff --git a/lldb/source/Core/DynamicLoader.cpp b/lldb/source/Core/DynamicLoader.cpp
index acc84dbf016fb..9c6ca1e5f910c 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -263,7 +263,7 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
         module_sp = std::make_shared<Module>(module_spec);
       } else if (force_symbol_search && error.AsCString("") &&
                  error.AsCString("")[0] != '\0') {
-        target.GetDebugger().GetErrorStream() << error.AsCString();
+        *target.GetDebugger().GetAsyncErrorStream() << error.AsCString();
       }
     }
 
@@ -328,19 +328,19 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
     }
   } else {
     if (force_symbol_search) {
-      Stream &s = target.GetDebugger().GetErrorStream();
-      s.Printf("Unable to find file");
+      lldb::StreamSP s = target.GetDebugger().GetAsyncErrorStream();
+      s->Printf("Unable to find file");
       if (!name.empty())
-        s.Printf(" %s", name.str().c_str());
+        s->Printf(" %s", name.str().c_str());
       if (uuid.IsValid())
-        s.Printf(" with UUID %s", uuid.GetAsString().c_str());
+        s->Printf(" with UUID %s", uuid.GetAsString().c_str());
       if (value != LLDB_INVALID_ADDRESS) {
         if (value_is_offset)
-          s.Printf(" with slide 0x%" PRIx64, value);
+          s->Printf(" with slide 0x%" PRIx64, value);
         else
-          s.Printf(" at address 0x%" PRIx64, value);
+          s->Printf(" at address 0x%" PRIx64, value);
       }
-      s.Printf("\n");
+      s->Printf("\n");
     }
     LLDB_LOGF(log,
               "Unable to find binary %s with UUID %s and load it at "
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 559b8301c1010..8d10e5de01225 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -245,8 +245,8 @@ ScriptInterpreterIORedirect::ScriptInterpreterIORedirect(
       if (outfile_handle)
         ::setbuf(outfile_handle, nullptr);
 
-      result->SetImmediateOutputFile(debugger.GetOutputStream().GetFileSP());
-      result->SetImmediateErrorFile(debugger.GetErrorStream().GetFileSP());
+      result->SetImmediateOutputFile(debugger.GetOutputStreamSP()->GetFileSP());
+      result->SetImmediateErrorFile(debugger.GetErrorStreamSP()->GetFileSP());
     }
   }
 
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index b8941dae01078..cff44b588e26e 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -738,9 +738,9 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
   }
 
   if (IsKernel() && m_uuid.IsValid()) {
-    Stream &s = target.GetDebugger().GetOutputStream();
-    s.Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
-    s.Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
+    lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
+    s->Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
+    s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
 
     // Start of a kernel debug session, we have the UUID of the kernel.
     // Go through the target's list of modules and if there are any kernel
@@ -830,12 +830,12 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
       }
 
       if (IsKernel() && !m_module_sp) {
-        Stream &s = target.GetDebugger().GetErrorStream();
-        s.Printf("WARNING: Unable to locate kernel binary on the debugger "
-                 "system.\n");
+        lldb::StreamSP s = target.GetDebugger().GetAsyncErrorStream();
+        s->Printf("WARNING: Unable to locate kernel binary on the debugger "
+                  "system.\n");
         if (kernel_search_error.Fail() && kernel_search_error.AsCString("") &&
             kernel_search_error.AsCString("")[0] != '\0') {
-          s << kernel_search_error.AsCString();
+          *s << kernel_search_error.AsCString();
         }
       }
     }
@@ -974,22 +974,19 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
   bool is_loaded = IsLoaded();
 
   if (is_loaded && m_module_sp && IsKernel()) {
-    Stream &s = target.GetDebugger().GetOutputStream();
+    lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
     ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
     if (kernel_object_file) {
       addr_t file_address =
           kernel_object_file->GetBaseAddress().GetFileAddress();
       if (m_load_address != LLDB_INVALID_ADDRESS &&
           file_address != LLDB_INVALID_ADDRESS) {
-        s.Printf("Kernel slid 0x%" PRIx64 " in memory.\n",
-                 m_load_address - file_address);
+        s->Printf("Kernel slid 0x%" PRIx64 " in memory.\n",
+                  m_load_address - file_address);
       }
     }
-    {
-      s.Printf("Loaded kernel file %s\n",
-               m_module_sp->GetFileSpec().GetPath().c_str());
-    }
-    s.Flush();
+    s->Printf("Loaded kernel file %s\n",
+              m_module_sp->GetFileSpec().GetPath().c_str());
   }
 
   // Notify the target about the module being added;
@@ -1195,10 +1192,11 @@ bool DynamicLoaderDarwinKernel::ReadKextSummaryHeader() {
           lldb::offset_t offset = 0;
           m_kext_summary_header.version = data.GetU32(&offset);
           if (m_kext_summary_header.version > 128) {
-            Stream &s = m_process->GetTarget().GetDebugger().GetOutputStream();
-            s.Printf("WARNING: Unable to read kext summary header, got "
-                     "improbable version number %u\n",
-                     m_kext_summary_header.version);
+            lldb::StreamSP s =
+                m_process->GetTarget().GetDebugger().GetOutputStreamSP();
+            s->Printf("WARNING: Unable to read kext summary header, got "
+                      "improbable version number %u\n",
+                      m_kext_summary_header.version);
             // If we get an improbably large version number, we're probably
             // getting bad memory.
             m_kext_summary_header_addr.Clear();
@@ -1209,11 +1207,11 @@ bool DynamicLoaderDarwinKernel::ReadKextSummaryHeader() {
             if (m_kext_summary_header.entry_size > 4096) {
               // If we get an improbably large entry_size, we're probably
               // getting bad memory.
-              Stream &s =
-                  m_process->GetTarget().GetDebugger().GetOutputStream();
-              s.Printf("WARNING: Unable to read kext summary header, got "
-                       "improbable entry_size %u\n",
-                       m_kext_summary_header.entry_size);
+              lldb::StreamSP s =
+                  m_process->GetTarget().GetDebugger().GetOutputStreamSP();
+              s->Printf("WARNING: Unable to read kext summary header, got "
+                        "improbable entry_size %u\n",
+                        m_kext_summary_header.entry_size);
               m_kext_summary_header_addr.Clear();
               return false;
             }
@@ -1227,10 +1225,11 @@ bool DynamicLoaderDarwinKernel::ReadKextSummaryHeader() {
           if (m_kext_summary_header.entry_count > 10000) {
             // If we get an improbably large number of kexts, we're probably
             // getting bad memory.
-            Stream &s = m_process->GetTarget().GetDebugger().GetOutputStream();
-            s.Printf("WARNING: Unable to read kext summary header, got "
-                     "improbable number of kexts %u\n",
-                     m_kext_summary_header.entry_count);
+            lldb::StreamSP s =
+                m_process->GetTarget().GetDebugger().GetOutputStreamSP();
+            s->Printf("WARNING: Unable to read kext summary header, got "
+                      "improbable number of kexts %u\n",
+                      m_kext_summary_header.entry_count);
             m_kext_summary_header_addr.Clear();
             return false;
           }
@@ -1331,17 +1330,18 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
       number_of_old_kexts_being_removed == 0)
     return true;
 
-  Stream &s = m_process->GetTarget().GetDebugger().GetOutputStream();
+  lldb::StreamSP s = m_process->GetTarget().GetDebugger().GetOutputStreamSP();
   if (load_kexts) {
     if (number_of_new_kexts_being_added > 0 &&
         number_of_old_kexts_being_removed > 0) {
-      s.Printf("Loading %d kext modules and unloading %d kext modules ",
-               number_of_new_kexts_being_added,
-               number_of_old_kexts_being_removed);
+      s->Printf("Loading %d kext modules and unloading %d kext modules ",
+                number_of_new_kexts_being_added,
+                number_of_old_kexts_being_removed);
     } else if (number_of_new_kexts_being_added > 0) {
-      s.Printf("Loading %d kext modules ", number_of_new_kexts_being_added);
+      s->Printf("Loading %d kext modules ", number_of_new_kexts_being_added);
     } else if (number_of_old_kexts_being_removed > 0) {
-      s.Printf("Unloading %d kext modules ", number_of_old_kexts_being_removed);
+      s->Printf("Unloading %d kext modules ",
+                number_of_old_kexts_being_removed);
     }
   }
 
@@ -1405,7 +1405,7 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
           if (image_info.GetModule()) {
             unloaded_module_list.AppendIfNeeded(image_info.GetModule());
           }
-          s.Printf(".");
+          s->Printf(".");
           image_info.Clear();
           // should pull it out of the KextImageInfos vector but that would
           // mutate the list and invalidate the to_be_removed bool vector;
@@ -1417,11 +1417,11 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
   }
 
   if (load_kexts) {
-    s.Printf(" done.\n");
+    s->Printf(" done.\n");
     if (kexts_failed_to_load.size() > 0 && number_of_new_kexts_being_added > 0) {
-      s.Printf("Failed to load %d of %d kexts:\n",
-               (int)kexts_failed_to_load.size(),
-               number_of_new_kexts_being_added);
+      s->Printf("Failed to load %d of %d kexts:\n",
+                (int)kexts_failed_to_load.size(),
+                number_of_new_kexts_being_added);
       // print a sorted list of <kext-name, uuid> kexts which failed to load
       unsigned longest_name = 0;
       std::sort(kexts_failed_to_load.begin(), kexts_failed_to_load.end());
@@ -1433,10 +1433,9 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
         std::string uuid;
         if (ku.second.IsValid())
           uuid = ku.second.GetAsString();
-        s.Printf(" %-*s %s\n", longest_name, ku.first.c_str(), uuid.c_str());
+        s->Printf(" %-*s %s\n", longest_name, ku.first.c_str(), uuid.c_str());
       }
     }
-    s.Flush();
   }
 
   return true;
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index 8391467c375f4..3bf0a46de57af 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -327,9 +327,9 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
   Target &target = process->GetTarget();
 
   if (IsKernel() && m_uuid.IsValid()) {
-    Stream &s = target.GetDebugger().GetOutputStream();
-    s.Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
-    s.Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
+    lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
+    s->Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
+    s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
   }
 
   // Test if the module is loaded into the taget,
@@ -355,9 +355,9 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
       if (!m_module_sp)
         m_module_sp = target.GetOrCreateModule(module_spec, true);
       if (IsKernel() && !m_module_sp) {
-        Stream &s = target.GetDebugger().GetOutputStream();
-        s.Printf("WARNING: Unable to locate kernel binary on the debugger "
-                 "system.\n");
+        lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
+        s->Printf("WARNING: Unable to locate kernel binary on the debugger "
+                  "system.\n");
       }
     }
 
@@ -464,20 +464,19 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
   }
 
   if (IsLoaded() && m_module_sp && IsKernel()) {
-    Stream &s = target.GetDebugger().GetOutputStream();
+    lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
     ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
     if (kernel_object_file) {
       addr_t file_address =
           kernel_object_file->GetBaseAddress().GetFileAddress();
       if (m_load_address != LLDB_INVALID_ADDRESS &&
           file_address != LLDB_INVALID_ADDRESS) {
-        s.Printf("Kernel slide 0x%" PRIx64 " in memory.\n",
-                 m_load_address - file_address);
-        s.Printf("Loaded kernel file %s\n",
-                 m_module_sp->GetFileSpec().GetPath().c_str());
+        s->Printf("Kernel slide 0x%" PRIx64 " in memory.\n",
+                  m_load_address - file_address);
+        s->Printf("Loaded kernel file %s\n",
+                  m_module_sp->GetFileSpec().GetPath().c_str());
       }
     }
-    s.Flush();
   }
 
   return IsLoaded();
diff --git a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
index 70e36801c3fd7..498da3ffe5a4a 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
@@ -864,13 +864,14 @@ bool InstrumentationRuntimeTSan::NotifyBreakpointHit(
               CreateStopReasonWithInstrumentationData(
                   *thread_sp, stop_reason_description, report));
 
-    StreamFile &s = process_sp->GetTarget().GetDebugger().GetOutputStream();
-    s.Printf("ThreadSanitizer report breakpoint hit. Use 'thread "
-             "info -s' to get extended information about the "
-             "report.\n");
+    lldb::StreamSP s =
+        process_sp->GetTarget().GetDebugger().GetAsyncOutputStream();
+    s->Printf("ThreadSanitizer report breakpoint hit. Use 'thread "
+              "info -s' to get extended information about the "
+              "report.\n");
 
     return true; // Return true to stop the target
-  } else
+  }
     return false; // Let target run
 }
 
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
index 2b8adeae10d14..7774eb843c62d 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
@@ -622,14 +622,14 @@ AppleObjCTrampolineHandler::AppleObjCTrampolineHandler(
     // step through any method dispatches.  Warn to that effect and get out of
     // here.
     if (process_sp->CanJIT()) {
-      process_sp->GetTarget().GetDebugger().GetErrorStream().Printf(
+      process_sp->GetTarget().GetDebugger().GetAsyncErrorStream()->Printf(
           "Could not find implementation lookup function \"%s\""
           " step in through ObjC method dispatch will not work.\n",
           get_impl_name.AsCString());
     }
     return;
   }
-  
+
   // We will either set the implementation to the _stret or non_stret version,
   // so either way it's safe to start filling the m_lookup_..._code here.
   m_lookup_implementation_function_code.assign(
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
index 896fc6951b85c..7e8eee9f5aa4f 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -289,7 +289,7 @@ bool ScriptInterpreterLua::BreakpointCallbackFunction(
   llvm::Expected<bool> BoolOrErr = lua.CallBreakpointCallback(
       baton, stop_frame_sp, bp_loc_sp, bp_option_data->m_extra_args_sp);
   if (llvm::Error E = BoolOrErr.takeError()) {
-    debugger.GetErrorStream() << toString(std::move(E));
+    *debugger.GetAsyncErrorStream() << toString(std::move(E));
     return true;
   }
 
@@ -316,7 +316,7 @@ bool ScriptInterpreterLua::WatchpointCallbackFunction(
   llvm::Expected<bool> BoolOrErr =
       lua.CallWatchpointCallback(baton, stop_frame_sp, ...
[truncated]

Remove Debugger::GetOutputStream and Debugger::GetErrorStream in
preparation for replacing both with a new variant that needs to be
locked and hence can't be handed out like we do right now.

The patch replaces most uses with GetAsyncOutputStream and
GetAsyncErrorStream respectively. There methods return new StreamSP
objects that automatically get flushed on destruction.

See llvm#126630 for more details.
@JDevlieghere JDevlieghere force-pushed the RemoveGetOutputErrorStream branch from 34cf65b to 34602ab Compare February 12, 2025 04:13
Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I suspect all of those uses of the method were candidates for corrupting the debugger output.

@JDevlieghere JDevlieghere merged commit eff3c34 into llvm:main Feb 12, 2025
7 checks passed
@JDevlieghere JDevlieghere deleted the RemoveGetOutputErrorStream branch February 12, 2025 16:29
flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
Remove Debugger::GetOutputStream and Debugger::GetErrorStream in
preparation for replacing both with a new variant that needs to be
locked and hence can't be handed out like we do right now.

The patch replaces most uses with GetAsyncOutputStream and
GetAsyncErrorStream respectively. There methods return new StreamSP
objects that automatically get flushed on destruction.

See llvm#126630 for more details.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
Remove Debugger::GetOutputStream and Debugger::GetErrorStream in
preparation for replacing both with a new variant that needs to be
locked and hence can't be handed out like we do right now.

The patch replaces most uses with GetAsyncOutputStream and
GetAsyncErrorStream respectively. There methods return new StreamSP
objects that automatically get flushed on destruction.

See llvm#126630 for more details.
JDevlieghere added a commit that referenced this pull request Feb 15, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
Remove Debugger::GetOutputStream and Debugger::GetErrorStream in
preparation for replacing both with a new variant that needs to be
locked and hence can't be handed out like we do right now.

The patch replaces most uses with GetAsyncOutputStream and
GetAsyncErrorStream respectively. There methods return new StreamSP
objects that automatically get flushed on destruction.

See llvm#126630 for more details.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Mar 27, 2025
Remove Debugger::GetOutputStream and Debugger::GetErrorStream in
preparation for replacing both with a new variant that needs to be
locked and hence can't be handed out like we do right now.

The patch replaces most uses with GetAsyncOutputStream and
GetAsyncErrorStream respectively. There methods return new StreamSP
objects that automatically get flushed on destruction.

See llvm#126630 for more details.

(cherry picked from commit eff3c34)
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Mar 27, 2025
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Mar 28, 2025
Remove Debugger::GetOutputStream and Debugger::GetErrorStream in
preparation for replacing both with a new variant that needs to be
locked and hence can't be handed out like we do right now.

The patch replaces most uses with GetAsyncOutputStream and
GetAsyncErrorStream respectively. There methods return new StreamSP
objects that automatically get flushed on destruction.

See llvm#126630 for more details.

(cherry picked from commit eff3c34)
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants