Author: Jonas Devlieghere Date: 2022-06-21T18:51:39-07:00 New Revision: c866f8544c929578a49e0b222f2171da71c9f415
URL: https://github.com/llvm/llvm-project/commit/c866f8544c929578a49e0b222f2171da71c9f415 DIFF: https://github.com/llvm/llvm-project/commit/c866f8544c929578a49e0b222f2171da71c9f415.diff LOG: [lldb] Add a setting to specify the preferred dynamic class info extractor o Add a setting to configure how LLDB parses dynamic Objective-C class metadata. By default LLDB will choose the most appropriate method for the target OS. Differential revision: https://reviews.llvm.org/D128312 Added: Modified: lldb/include/lldb/Target/Target.h lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h lldb/source/Target/Target.cpp lldb/source/Target/TargetProperties.td Removed: ################################################################################ diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 53fe4831b82fa..93ea8504f8bac 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -71,6 +71,13 @@ enum ImportStdModule { eImportStdModuleTrue, }; +enum DynamicClassInfoHelper { + eDynamicClassInfoHelperAuto, + eDynamicClassInfoHelperRealizedClassesStruct, + eDynamicClassInfoHelperCopyRealizedClassList, + eDynamicClassInfoHelperGetRealizedClassList, +}; + class TargetExperimentalProperties : public Properties { public: TargetExperimentalProperties(); @@ -152,6 +159,8 @@ class TargetProperties : public Properties { ImportStdModule GetImportStdModule() const; + DynamicClassInfoHelper GetDynamicClassInfoHelper() const; + bool GetEnableAutoApplyFixIts() const; uint64_t GetNumberOfRetriesWithFixits() const; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index 5c00da8b40ade..4d21f1f3765f3 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -1724,7 +1724,8 @@ AppleObjCRuntimeV2::DynamicClassInfoExtractor::GetClassInfoArgs(Helper helper) { } AppleObjCRuntimeV2::DynamicClassInfoExtractor::Helper -AppleObjCRuntimeV2::DynamicClassInfoExtractor::ComputeHelper() const { +AppleObjCRuntimeV2::DynamicClassInfoExtractor::ComputeHelper( + ExecutionContext &exe_ctx) const { if (!m_runtime.m_has_objc_copyRealizedClassList && !m_runtime.m_has_objc_getRealizedClassList_trylock) return DynamicClassInfoExtractor::gdb_objc_realized_classes; @@ -1732,10 +1733,20 @@ AppleObjCRuntimeV2::DynamicClassInfoExtractor::ComputeHelper() const { if (Process *process = m_runtime.GetProcess()) { if (DynamicLoader *loader = process->GetDynamicLoader()) { if (loader->IsFullyInitialized()) { - if (m_runtime.m_has_objc_getRealizedClassList_trylock) - return DynamicClassInfoExtractor::objc_getRealizedClassList_trylock; - if (m_runtime.m_has_objc_copyRealizedClassList) - return DynamicClassInfoExtractor::objc_copyRealizedClassList; + switch (exe_ctx.GetTargetRef().GetDynamicClassInfoHelper()) { + case eDynamicClassInfoHelperAuto: + [[clang::fallthrough]]; + case eDynamicClassInfoHelperGetRealizedClassList: + if (m_runtime.m_has_objc_getRealizedClassList_trylock) + return DynamicClassInfoExtractor::objc_getRealizedClassList_trylock; + [[clang::fallthrough]]; + case eDynamicClassInfoHelperCopyRealizedClassList: + if (m_runtime.m_has_objc_copyRealizedClassList) + return DynamicClassInfoExtractor::objc_copyRealizedClassList; + [[clang::fallthrough]]; + case eDynamicClassInfoHelperRealizedClassesStruct: + return DynamicClassInfoExtractor::gdb_objc_realized_classes; + } } } } @@ -1872,7 +1883,7 @@ AppleObjCRuntimeV2::DynamicClassInfoExtractor::UpdateISAToDescriptorMap( Status err; // Compute which helper we're going to use for this update. - const DynamicClassInfoExtractor::Helper helper = ComputeHelper(); + const DynamicClassInfoExtractor::Helper helper = ComputeHelper(exe_ctx); // Read the total number of classes from the hash table const uint32_t num_classes = diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h index 0a2c8ff29275a..1a8e9d4aa339c 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h @@ -341,7 +341,7 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime { /// must use gdb_objc_realized_classes. Otherwise, we prefer /// objc_getRealizedClassList_trylock and objc_copyRealizedClassList /// respectively, depending on availability. - Helper ComputeHelper() const; + Helper ComputeHelper(ExecutionContext &exe_ctx) const; UtilityFunction *GetClassInfoUtilityFunction(ExecutionContext &exe_ctx, Helper helper); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 34dea43a64ddf..65064ecf75b1c 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -3801,6 +3801,22 @@ static constexpr OptionEnumValueElement g_import_std_module_value_types[] = { }, }; +static constexpr OptionEnumValueElement + g_dynamic_class_info_helper_value_types[] = { + { + eDynamicClassInfoHelperAuto, + "auto", + "Automatically determine the most appropriate method for the " + "target OS.", + }, + {eDynamicClassInfoHelperRealizedClassesStruct, "RealizedClassesStruct", + "Prefer using the realized classes struct."}, + {eDynamicClassInfoHelperCopyRealizedClassList, "CopyRealizedClassList", + "Prefer using the CopyRealizedClassList API."}, + {eDynamicClassInfoHelperGetRealizedClassList, "GetRealizedClassList", + "Prefer using the GetRealizedClassList API."}, +}; + static constexpr OptionEnumValueElement g_hex_immediate_style_values[] = { { Disassembler::eHexStyleC, @@ -4299,6 +4315,13 @@ ImportStdModule TargetProperties::GetImportStdModule() const { nullptr, idx, g_target_properties[idx].default_uint_value); } +DynamicClassInfoHelper TargetProperties::GetDynamicClassInfoHelper() const { + const uint32_t idx = ePropertyDynamicClassInfoHelper; + return (DynamicClassInfoHelper) + m_collection_sp->GetPropertyAtIndexAsEnumeration( + nullptr, idx, g_target_properties[idx].default_uint_value); +} + bool TargetProperties::GetEnableAutoApplyFixIts() const { const uint32_t idx = ePropertyAutoApplyFixIts; return m_collection_sp->GetPropertyAtIndexAsBoolean( diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index 1ceb9db82013d..02d82fbc109b9 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -54,6 +54,10 @@ let Definition = "target" in { EnumValues<"OptionEnumValues(g_import_std_module_value_types)">, Desc<"Import the 'std' C++ module to improve expression parsing involving " " C++ standard library types.">; + def DynamicClassInfoHelper: Property<"objc-dynamic-class-extractor", "Enum">, + DefaultEnumValue<"eDynamicClassInfoHelperAuto">, + EnumValues<"OptionEnumValues(g_dynamic_class_info_helper_value_types)">, + Desc<"Configure how LLDB parses dynamic Objective-C class metadata. By default LLDB will choose the most appropriate method for the target OS.">; def AutoApplyFixIts: Property<"auto-apply-fixits", "Boolean">, DefaultTrue, Desc<"Automatically apply fix-it hints to expressions.">; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits