Skip to content

Conversation

@Michael137
Copy link
Member

@Michael137 Michael137 commented Dec 11, 2025

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:

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 makes it so we only log this error once per debugger session.

Not sure how to best test it since we'd need to build a program with a particular SDK and then make it unrecognized by LLDB. Confirmed manually that the error only gets reported once after this patch.

@llvmbot
Copy link
Member

llvmbot commented Dec 11, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

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: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; error: Error while searching for Xcode SDK: Unrecognized SDK type: &lt;some SDK&gt; 

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.


Full diff: https://github.com/llvm/llvm-project/pull/171820.diff

1 Files Affected:

  • (modified) lldb/source/Core/Module.cpp (+18-2)
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; } 
@github-actions
Copy link

github-actions bot commented Dec 11, 2025

🐧 Linux x64 Test Results

  • 33226 tests passed
  • 502 tests skipped

✅ The build succeeded and all tests passed.

@Michael137 Michael137 marked this pull request as draft December 11, 2025 13:58
@Michael137 Michael137 force-pushed the lldb/sdk-search-error branch 2 times, most recently from fcbe4c4 to b31aa38 Compare December 11, 2025 14:02
@Michael137 Michael137 marked this pull request as ready for review December 11, 2025 14:03
@Michael137 Michael137 force-pushed the lldb/sdk-search-error branch from b31aa38 to 8591030 Compare December 11, 2025 14:05
@Michael137 Michael137 merged commit 1b7f272 into llvm:main Dec 11, 2025
10 checks passed
@Michael137 Michael137 deleted the lldb/sdk-search-error branch December 11, 2025 17:26
Michael137 added a commit to swiftlang/llvm-project that referenced this pull request Dec 12, 2025
…lvm#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: ``` 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 makes it so we only log this error once per debugger session. Not sure how to best test it since we'd need to build a program with a particular SDK and then make it unrecognized by LLDB. Confirmed manually that the error only gets reported once after this patch. (cherry picked from commit 1b7f272)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants