[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 18 14:05:58 PDT 2024
================
@@ -989,41 +989,45 @@ ValueObject::ReadPointedString(lldb::WritableDataBufferSP &buffer_sp,
return {total_bytes_read, was_capped};
}
-const char *ValueObject::GetObjectDescription() {
+llvm::Expected<std::string> ValueObject::GetObjectDescription() {
if (!UpdateValueIfNeeded(true))
- return nullptr;
+ return llvm::createStringError("could not update value");
// Return cached value.
if (!m_object_desc_str.empty())
- return m_object_desc_str.c_str();
+ return m_object_desc_str;
ExecutionContext exe_ctx(GetExecutionContextRef());
Process *process = exe_ctx.GetProcessPtr();
if (!process)
- return nullptr;
+ return llvm::createStringError("no process");
// Returns the object description produced by one language runtime.
- auto get_object_description = [&](LanguageType language) -> const char * {
+ auto get_object_description =
+ [&](LanguageType language) -> llvm::Expected<std::string> {
if (LanguageRuntime *runtime = process->GetLanguageRuntime(language)) {
StreamString s;
- if (runtime->GetObjectDescription(s, *this)) {
- m_object_desc_str.append(std::string(s.GetString()));
- return m_object_desc_str.c_str();
- }
+ if (llvm::Error error = runtime->GetObjectDescription(s, *this))
+ return error;
+ m_object_desc_str = s.GetString();
+ return m_object_desc_str;
}
- return nullptr;
+ return llvm::createStringError("no native language runtime");
};
// Try the native language runtime first.
LanguageType native_language = GetObjectRuntimeLanguage();
- if (const char *desc = get_object_description(native_language))
+ llvm::Expected<std::string> desc = get_object_description(native_language);
+ if (desc)
return desc;
// Try the Objective-C language runtime. This fallback is necessary
// for Objective-C++ and mixed Objective-C / C++ programs.
- if (Language::LanguageIsCFamily(native_language))
+ if (Language::LanguageIsCFamily(native_language)) {
+ llvm::consumeError(desc.takeError());
----------------
JDevlieghere wrote:
This is one of the few instances where it makes sense to use `consumeError` (as opposed to using `LLDB_LOG_ERROR`). Could you add a comment saying that this is the right thing?
I know I'm going to see this at some point in the future and grumble before realizing that this is actually correct. Which definitely didn't happen during the code review :-)
https://github.com/llvm/llvm-project/pull/95857
More information about the lldb-commits
mailing list