xiaobai created this revision.
xiaobai added reviewers: JDevlieghere, labath, compnerd, teemperor.
Herald added a project: LLDB.
This will generalize some behavior in ValueObject. Although this code
path is still specific to C++, it no longer references ClangASTContext directly.
This will allow us to move ClangASTContext out of Symbol in the near future.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69820
Files:
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/source/Core/ValueObject.cpp
lldb/source/Symbol/ClangASTContext.cpp
Index: lldb/source/Symbol/ClangASTContext.cpp
===================================================================
--- lldb/source/Symbol/ClangASTContext.cpp
+++ lldb/source/Symbol/ClangASTContext.cpp
@@ -3850,6 +3850,15 @@
return ClangASTContextSupportsLanguage(language);
}
+Optional<std::string>
+ClangASTContext::GetClassName(const CompilerType &compiler_type,
+ const lldb::LanguageType lang_type) {
+ // TODO: Support more than C++, if needed.
+ if (lang_type != eLanguageTypeC_plus_plus)
+ return llvm::None;
+ return GetCXXClassName(compiler_type);
+}
+
Optional<std::string>
ClangASTContext::GetCXXClassName(const CompilerType &type) {
if (!type)
Index: lldb/source/Core/ValueObject.cpp
===================================================================
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -25,7 +25,6 @@
#include "lldb/DataFormatters/TypeValidator.h"
#include "lldb/DataFormatters/ValueObjectPrinter.h"
#include "lldb/Expression/ExpressionVariable.h"
-#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/Declaration.h"
@@ -2019,20 +2018,34 @@
}
bool ValueObject::GetBaseClassPath(Stream &s) {
- if (IsBaseClass()) {
- bool parent_had_base_class =
- GetParent() && GetParent()->GetBaseClassPath(s);
- CompilerType compiler_type = GetCompilerType();
- llvm::Optional<std::string> cxx_class_name =
- ClangASTContext::GetCXXClassName(compiler_type);
- if (cxx_class_name) {
- if (parent_had_base_class)
- s.PutCString("::");
- s.PutCString(cxx_class_name.getValue());
- }
- return parent_had_base_class || cxx_class_name;
+ if (!IsBaseClass())
+ return false;
+
+ TargetSP target_sp = GetTargetSP();
+ if (!target_sp)
+ return false;
+
+ // TODO: Don't make this specific to C++.
+ auto type_system_or_err =
+ target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeC_plus_plus);
+ if (!type_system_or_err) {
+ LLDB_LOG_ERROR(
+ lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS),
+ type_system_or_err.takeError(),
+ "Unable to get TypeSystem in order to get class name in "
+ "ValueObject::GetBaseClassPath");
+ return false;
}
- return false;
+
+ llvm::Optional<std::string> class_name = type_system_or_err->GetClassName(
+ GetCompilerType(), eLanguageTypeC_plus_plus);
+ bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath(s);
+ if (class_name) {
+ if (parent_had_base_class)
+ s.PutCString("::");
+ s.PutCString(class_name.getValue());
+ }
+ return parent_had_base_class || class_name;
}
ValueObject *ValueObject::GetNonBaseClassParent() {
Index: lldb/include/lldb/Symbol/TypeSystem.h
===================================================================
--- lldb/include/lldb/Symbol/TypeSystem.h
+++ lldb/include/lldb/Symbol/TypeSystem.h
@@ -217,6 +217,10 @@
// Accessors
+ virtual llvm::Optional<std::string>
+ GetClassName(const CompilerType &compiler_type,
+ const lldb::LanguageType lang_type) = 0;
+
virtual ConstString GetTypeName(lldb::opaque_compiler_type_t type) = 0;
virtual uint32_t
Index: lldb/include/lldb/Symbol/ClangASTContext.h
===================================================================
--- lldb/include/lldb/Symbol/ClangASTContext.h
+++ lldb/include/lldb/Symbol/ClangASTContext.h
@@ -609,6 +609,10 @@
// Accessors
+ llvm::Optional<std::string>
+ GetClassName(const CompilerType &compiler_type,
+ const lldb::LanguageType lang_type) override;
+
ConstString GetTypeName(lldb::opaque_compiler_type_t type) override;
uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type,
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits