Skip to content

Commit c866f85

Browse files
committed
[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
1 parent c08f61b commit c866f85

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ enum ImportStdModule {
7171
eImportStdModuleTrue,
7272
};
7373

74+
enum DynamicClassInfoHelper {
75+
eDynamicClassInfoHelperAuto,
76+
eDynamicClassInfoHelperRealizedClassesStruct,
77+
eDynamicClassInfoHelperCopyRealizedClassList,
78+
eDynamicClassInfoHelperGetRealizedClassList,
79+
};
80+
7481
class TargetExperimentalProperties : public Properties {
7582
public:
7683
TargetExperimentalProperties();
@@ -152,6 +159,8 @@ class TargetProperties : public Properties {
152159

153160
ImportStdModule GetImportStdModule() const;
154161

162+
DynamicClassInfoHelper GetDynamicClassInfoHelper() const;
163+
155164
bool GetEnableAutoApplyFixIts() const;
156165

157166
uint64_t GetNumberOfRetriesWithFixits() const;

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,18 +1724,29 @@ AppleObjCRuntimeV2::DynamicClassInfoExtractor::GetClassInfoArgs(Helper helper) {
17241724
}
17251725

17261726
AppleObjCRuntimeV2::DynamicClassInfoExtractor::Helper
1727-
AppleObjCRuntimeV2::DynamicClassInfoExtractor::ComputeHelper() const {
1727+
AppleObjCRuntimeV2::DynamicClassInfoExtractor::ComputeHelper(
1728+
ExecutionContext &exe_ctx) const {
17281729
if (!m_runtime.m_has_objc_copyRealizedClassList &&
17291730
!m_runtime.m_has_objc_getRealizedClassList_trylock)
17301731
return DynamicClassInfoExtractor::gdb_objc_realized_classes;
17311732

17321733
if (Process *process = m_runtime.GetProcess()) {
17331734
if (DynamicLoader *loader = process->GetDynamicLoader()) {
17341735
if (loader->IsFullyInitialized()) {
1735-
if (m_runtime.m_has_objc_getRealizedClassList_trylock)
1736-
return DynamicClassInfoExtractor::objc_getRealizedClassList_trylock;
1737-
if (m_runtime.m_has_objc_copyRealizedClassList)
1738-
return DynamicClassInfoExtractor::objc_copyRealizedClassList;
1736+
switch (exe_ctx.GetTargetRef().GetDynamicClassInfoHelper()) {
1737+
case eDynamicClassInfoHelperAuto:
1738+
[[clang::fallthrough]];
1739+
case eDynamicClassInfoHelperGetRealizedClassList:
1740+
if (m_runtime.m_has_objc_getRealizedClassList_trylock)
1741+
return DynamicClassInfoExtractor::objc_getRealizedClassList_trylock;
1742+
[[clang::fallthrough]];
1743+
case eDynamicClassInfoHelperCopyRealizedClassList:
1744+
if (m_runtime.m_has_objc_copyRealizedClassList)
1745+
return DynamicClassInfoExtractor::objc_copyRealizedClassList;
1746+
[[clang::fallthrough]];
1747+
case eDynamicClassInfoHelperRealizedClassesStruct:
1748+
return DynamicClassInfoExtractor::gdb_objc_realized_classes;
1749+
}
17391750
}
17401751
}
17411752
}
@@ -1872,7 +1883,7 @@ AppleObjCRuntimeV2::DynamicClassInfoExtractor::UpdateISAToDescriptorMap(
18721883
Status err;
18731884

18741885
// Compute which helper we're going to use for this update.
1875-
const DynamicClassInfoExtractor::Helper helper = ComputeHelper();
1886+
const DynamicClassInfoExtractor::Helper helper = ComputeHelper(exe_ctx);
18761887

18771888
// Read the total number of classes from the hash table
18781889
const uint32_t num_classes =

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
341341
/// must use gdb_objc_realized_classes. Otherwise, we prefer
342342
/// objc_getRealizedClassList_trylock and objc_copyRealizedClassList
343343
/// respectively, depending on availability.
344-
Helper ComputeHelper() const;
344+
Helper ComputeHelper(ExecutionContext &exe_ctx) const;
345345

346346
UtilityFunction *GetClassInfoUtilityFunction(ExecutionContext &exe_ctx,
347347
Helper helper);

lldb/source/Target/Target.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,22 @@ static constexpr OptionEnumValueElement g_import_std_module_value_types[] = {
38013801
},
38023802
};
38033803

3804+
static constexpr OptionEnumValueElement
3805+
g_dynamic_class_info_helper_value_types[] = {
3806+
{
3807+
eDynamicClassInfoHelperAuto,
3808+
"auto",
3809+
"Automatically determine the most appropriate method for the "
3810+
"target OS.",
3811+
},
3812+
{eDynamicClassInfoHelperRealizedClassesStruct, "RealizedClassesStruct",
3813+
"Prefer using the realized classes struct."},
3814+
{eDynamicClassInfoHelperCopyRealizedClassList, "CopyRealizedClassList",
3815+
"Prefer using the CopyRealizedClassList API."},
3816+
{eDynamicClassInfoHelperGetRealizedClassList, "GetRealizedClassList",
3817+
"Prefer using the GetRealizedClassList API."},
3818+
};
3819+
38043820
static constexpr OptionEnumValueElement g_hex_immediate_style_values[] = {
38053821
{
38063822
Disassembler::eHexStyleC,
@@ -4299,6 +4315,13 @@ ImportStdModule TargetProperties::GetImportStdModule() const {
42994315
nullptr, idx, g_target_properties[idx].default_uint_value);
43004316
}
43014317

4318+
DynamicClassInfoHelper TargetProperties::GetDynamicClassInfoHelper() const {
4319+
const uint32_t idx = ePropertyDynamicClassInfoHelper;
4320+
return (DynamicClassInfoHelper)
4321+
m_collection_sp->GetPropertyAtIndexAsEnumeration(
4322+
nullptr, idx, g_target_properties[idx].default_uint_value);
4323+
}
4324+
43024325
bool TargetProperties::GetEnableAutoApplyFixIts() const {
43034326
const uint32_t idx = ePropertyAutoApplyFixIts;
43044327
return m_collection_sp->GetPropertyAtIndexAsBoolean(

lldb/source/Target/TargetProperties.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ let Definition = "target" in {
5454
EnumValues<"OptionEnumValues(g_import_std_module_value_types)">,
5555
Desc<"Import the 'std' C++ module to improve expression parsing involving "
5656
" C++ standard library types.">;
57+
def DynamicClassInfoHelper: Property<"objc-dynamic-class-extractor", "Enum">,
58+
DefaultEnumValue<"eDynamicClassInfoHelperAuto">,
59+
EnumValues<"OptionEnumValues(g_dynamic_class_info_helper_value_types)">,
60+
Desc<"Configure how LLDB parses dynamic Objective-C class metadata. By default LLDB will choose the most appropriate method for the target OS.">;
5761
def AutoApplyFixIts: Property<"auto-apply-fixits", "Boolean">,
5862
DefaultTrue,
5963
Desc<"Automatically apply fix-it hints to expressions.">;

0 commit comments

Comments
 (0)