https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/171820

Currently if we are debugging an app that was compiled against an SDK that we 
don't know about on the host, then every time we evaluate an expression we get 
following spam on the console (probably one error per LLDB module):
```
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
error: Error while searching for Xcode SDK: Unrecognized SDK type: <some SDK>
```

It is not a fatal error but the way we spam it pretty much ruins the debugging 
experience.

This patch tries to only log this error once per debugger session. The reason 
it looks a bit over-engineered is that I want to log it per SDK name. Having a 
single `once_flag` wouldn't work if there were CUs with different SDK types 
that we don't recognize.

Not sure how to best test this yet.

>From aa7333b09df4700b61937065cb78ef0f7d368542 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Thu, 11 Dec 2025 12:42:10 +0000
Subject: [PATCH] [lldb][Module] Only log SDK search error once per debugger
 session

---
 lldb/source/Core/Module.cpp | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index da2c188899f03..9672b89dc5b9d 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1562,14 +1562,30 @@ std::optional<std::string> 
Module::RemapSourceFile(llvm::StringRef path) const {
   return {};
 }
 
+/// Logs the specified \c err to the console as an error. This function will
+/// only log the error per \c sdk_name for a given debugger session.
+static void ReportSDKSearchError(llvm::StringRef sdk_name, llvm::Error err) {
+  static std::mutex s_reported_sdks_mutex;
+  static llvm::DenseMap<llvm::StringRef, std::unique_ptr<std::once_flag>>
+      s_reported_sdks;
+
+  std::scoped_lock lck(s_reported_sdks_mutex);
+  auto [it, _] =
+      s_reported_sdks.try_emplace(sdk_name, 
std::make_unique<std::once_flag>());
+
+  Debugger::ReportError("Error while searching for Xcode SDK: " +
+                            toString(std::move(err)),
+                        /*debugger_id=*/std::nullopt,
+                        /*once=*/it->getSecond().get());
+}
+
 void Module::RegisterXcodeSDK(llvm::StringRef sdk_name,
                               llvm::StringRef sysroot) {
   auto sdk_path_or_err =
       HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk_name.str()});
 
   if (!sdk_path_or_err) {
-    Debugger::ReportError("Error while searching for Xcode SDK: " +
-                          toString(sdk_path_or_err.takeError()));
+    ReportSDKSearchError(sdk_name, sdk_path_or_err.takeError());
     return;
   }
 

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to