- Notifications
You must be signed in to change notification settings - Fork 15.5k
[lldb][Module] Only log SDK search error once per debugger session #171820
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
Conversation
| @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesCurrently 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): 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 Not sure how to best test this yet. Full diff: https://github.com/llvm/llvm-project/pull/171820.diff 1 Files Affected:
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; } |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
fcbe4c4 to b31aa38 Compare b31aa38 to 8591030 Compare …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)
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:
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.