[Lldb-commits] [lldb] r365939 - [Core] Generalize ValueObject::MaybeCalculateCompleteType
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Fri Jul 12 11:34:38 PDT 2019
Author: xiaobai
Date: Fri Jul 12 11:34:37 2019
New Revision: 365939
URL: http://llvm.org/viewvc/llvm-project?rev=365939&view=rev
Log:
[Core] Generalize ValueObject::MaybeCalculateCompleteType
Summary:
Instead of hardcoding ClangASTContext and ObjCLanguageRuntime, we can
generalize this by creating the method GetRuntimeType in
LanguageRuntime and moving the current MaybeCalculateCompleteType
implementation into ObjCLanguageruntime::GetRuntimeType
Reviewers: jingham, clayborg, JDevlieghere
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D64159
Modified:
lldb/trunk/include/lldb/Target/LanguageRuntime.h
lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
lldb/trunk/source/Core/ValueObject.cpp
lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
Modified: lldb/trunk/include/lldb/Target/LanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/LanguageRuntime.h?rev=365939&r1=365938&r2=365939&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/LanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/LanguageRuntime.h Fri Jul 12 11:34:37 2019
@@ -156,6 +156,10 @@ public:
/// from the user interface.
virtual bool IsWhitelistedRuntimeValue(ConstString name) { return false; }
+ virtual llvm::Optional<CompilerType> GetRuntimeType(CompilerType base_type) {
+ return llvm::None;
+ }
+
virtual void ModulesDidLoad(const ModuleList &module_list) {}
// Called by the Clang expression evaluation engine to allow runtimes to
Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h?rev=365939&r1=365938&r2=365939&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h Fri Jul 12 11:34:37 2019
@@ -250,6 +250,8 @@ public:
lldb::TypeSP LookupInCompleteClassCache(ConstString &name);
+ llvm::Optional<CompilerType> GetRuntimeType(CompilerType base_type) override;
+
virtual UtilityFunction *CreateObjectChecker(const char *) = 0;
virtual ObjCRuntimeVersions GetRuntimeVersion() const {
Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=365939&r1=365938&r2=365939&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Fri Jul 12 11:34:37 2019
@@ -35,7 +35,6 @@
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/LanguageRuntime.h"
-#include "lldb/Target/ObjCLanguageRuntime.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
@@ -280,51 +279,21 @@ CompilerType ValueObject::MaybeCalculate
return compiler_type;
}
- CompilerType class_type;
- bool is_pointer_type = false;
-
- if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type)) {
- is_pointer_type = true;
- } else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type)) {
- class_type = compiler_type;
- } else {
- return compiler_type;
- }
-
m_did_calculate_complete_objc_class_type = true;
- if (class_type) {
- ConstString class_name(class_type.GetConstTypeName());
+ ProcessSP process_sp(
+ GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
- if (class_name) {
- ProcessSP process_sp(
- GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
-
- if (process_sp) {
- ObjCLanguageRuntime *objc_language_runtime(
- ObjCLanguageRuntime::Get(*process_sp));
-
- if (objc_language_runtime) {
- TypeSP complete_objc_class_type_sp =
- objc_language_runtime->LookupInCompleteClassCache(class_name);
-
- if (complete_objc_class_type_sp) {
- CompilerType complete_class(
- complete_objc_class_type_sp->GetFullCompilerType());
-
- if (complete_class.GetCompleteType()) {
- if (is_pointer_type) {
- m_override_type = complete_class.GetPointerType();
- } else {
- m_override_type = complete_class;
- }
-
- if (m_override_type.IsValid())
- return m_override_type;
- }
- }
- }
- }
+ if (!process_sp)
+ return compiler_type;
+
+ if (auto *runtime =
+ process_sp->GetLanguageRuntime(GetObjectRuntimeLanguage())) {
+ if (llvm::Optional<CompilerType> complete_type =
+ runtime->GetRuntimeType(compiler_type)) {
+ m_override_type = complete_type.getValue();
+ if (m_override_type.IsValid())
+ return m_override_type;
}
}
return compiler_type;
Modified: lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCLanguageRuntime.cpp?rev=365939&r1=365938&r2=365939&view=diff
==============================================================================
--- lldb/trunk/source/Target/ObjCLanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Fri Jul 12 11:34:37 2019
@@ -398,3 +398,38 @@ Status ObjCLanguageRuntime::ObjCExceptio
"The ObjC Exception breakpoint doesn't support extra options.");
return error;
}
+
+llvm::Optional<CompilerType>
+ObjCLanguageRuntime::GetRuntimeType(CompilerType base_type) {
+ CompilerType class_type;
+ bool is_pointer_type = false;
+
+ if (ClangASTContext::IsObjCObjectPointerType(base_type, &class_type))
+ is_pointer_type = true;
+ else if (ClangASTContext::IsObjCObjectOrInterfaceType(base_type))
+ class_type = base_type;
+ else
+ return llvm::None;
+
+ if (!class_type)
+ return llvm::None;
+
+ ConstString class_name(class_type.GetConstTypeName());
+ if (!class_name)
+ return llvm::None;
+
+ TypeSP complete_objc_class_type_sp = LookupInCompleteClassCache(class_name);
+ if (!complete_objc_class_type_sp)
+ return llvm::None;
+
+ CompilerType complete_class(
+ complete_objc_class_type_sp->GetFullCompilerType());
+ if (complete_class.GetCompleteType()) {
+ if (is_pointer_type)
+ return complete_class.GetPointerType();
+ else
+ return complete_class;
+ }
+
+ return llvm::None;
+}
More information about the lldb-commits
mailing list