llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/171820.diff 1 Files Affected: - (modified) lldb/source/Core/Module.cpp (+18-2) ``````````diff 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; } `````````` </details> https://github.com/llvm/llvm-project/pull/171820 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
