[lldb] Move UpdateISAToDescriptorMap into ClassInfoExtractor (NFC)

Move UpdateISAToDescriptorMap into ClassInfoExtractor so that all the
formerly public functions can be private and remain an implementation
detail of the extractor.

Differential revision: https://reviews.llvm.org/D99448
This commit is contained in:
Jonas Devlieghere 2021-03-29 09:14:06 -07:00
parent 29338459fb
commit bf8cbfa65f
2 changed files with 26 additions and 39 deletions

View File

@ -1551,10 +1551,9 @@ AppleObjCRuntimeV2::SharedCacheClassInfoExtractor::GetClassInfoUtilityFunction(
}
AppleObjCRuntimeV2::DescriptorMapUpdateResult
AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
AppleObjCRuntimeV2::DynamicClassInfoExtractor::UpdateISAToDescriptorMap(
RemoteNXMapTable &hash_table) {
Process *process = GetProcess();
Process *process = m_runtime.GetProcess();
if (process == nullptr)
return DescriptorMapUpdateResult::Fail();
@ -1583,22 +1582,20 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
Status err;
// Compute which helper we're going to use for this update.
const DynamicClassInfoExtractor::Helper helper =
m_dynamic_class_info_extractor.ComputeHelper();
const DynamicClassInfoExtractor::Helper helper = ComputeHelper();
// Read the total number of classes from the hash table
const uint32_t num_classes =
helper == DynamicClassInfoExtractor::gdb_objc_realized_classes
? hash_table.GetCount()
: m_realized_class_generation_count;
: m_runtime.m_realized_class_generation_count;
if (num_classes == 0) {
LLDB_LOGF(log, "No dynamic classes found.");
return DescriptorMapUpdateResult::Success(0);
}
UtilityFunction *get_class_info_code =
m_dynamic_class_info_extractor.GetClassInfoUtilityFunction(exe_ctx,
helper);
GetClassInfoUtilityFunction(exe_ctx, helper);
if (!get_class_info_code) {
// The callee will have already logged a useful error message.
return DescriptorMapUpdateResult::Fail();
@ -1629,7 +1626,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
return DescriptorMapUpdateResult::Fail();
}
std::lock_guard<std::mutex> guard(m_dynamic_class_info_extractor.GetMutex());
std::lock_guard<std::mutex> guard(m_mutex);
// Fill in our function argument values
arguments.GetValueAtIndex(0)->GetScalar() = hash_table.GetTableLoadAddress();
@ -1649,8 +1646,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
// Write our function arguments into the process so we can run our function
if (get_class_info_function->WriteFunctionArguments(
exe_ctx, m_dynamic_class_info_extractor.GetClassInfoArgs(helper),
arguments, diagnostics)) {
exe_ctx, GetClassInfoArgs(helper), arguments, diagnostics)) {
EvaluateExpressionOptions options;
options.SetUnwindOnError(true);
options.SetTryAllThreads(false);
@ -1671,8 +1667,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
// Run the function
ExpressionResults results = get_class_info_function->ExecuteFunction(
exe_ctx, &m_dynamic_class_info_extractor.GetClassInfoArgs(helper),
options, diagnostics, return_value);
exe_ctx, &GetClassInfoArgs(helper), options, diagnostics, return_value);
if (results == eExpressionCompleted) {
// The result is the number of ClassInfo structures that were filled in
@ -1687,7 +1682,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
DataExtractor class_infos_data(buffer.GetBytes(),
buffer.GetByteSize(),
process->GetByteOrder(), addr_size);
ParseClassInfoArray(class_infos_data, num_class_infos);
m_runtime.ParseClassInfoArray(class_infos_data, num_class_infos);
}
}
success = true;
@ -1788,9 +1783,8 @@ bool AppleObjCRuntimeV2::HasSymbol(ConstString Name) {
}
AppleObjCRuntimeV2::DescriptorMapUpdateResult
AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
Process *process = GetProcess();
AppleObjCRuntimeV2::SharedCacheClassInfoExtractor::UpdateISAToDescriptorMap() {
Process *process = m_runtime.GetProcess();
if (process == nullptr)
return DescriptorMapUpdateResult::Fail();
@ -1818,15 +1812,14 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
uint32_t num_class_infos = 0;
const lldb::addr_t objc_opt_ptr = GetSharedCacheReadOnlyAddress();
const lldb::addr_t objc_opt_ptr = m_runtime.GetSharedCacheReadOnlyAddress();
if (objc_opt_ptr == LLDB_INVALID_ADDRESS)
return DescriptorMapUpdateResult::Fail();
const uint32_t num_classes = 128 * 1024;
UtilityFunction *get_class_info_code =
m_shared_cache_class_info_extractor.GetClassInfoUtilityFunction(exe_ctx);
UtilityFunction *get_class_info_code = GetClassInfoUtilityFunction(exe_ctx);
FunctionCaller *get_shared_cache_class_info_function =
get_class_info_code->GetFunctionCaller();
@ -1853,8 +1846,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
return DescriptorMapUpdateResult::Fail();
}
std::lock_guard<std::mutex> guard(
m_shared_cache_class_info_extractor.GetMutex());
std::lock_guard<std::mutex> guard(m_mutex);
// Fill in our function argument values
arguments.GetValueAtIndex(0)->GetScalar() = objc_opt_ptr;
@ -1873,8 +1865,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
// Write our function arguments into the process so we can run our function
if (get_shared_cache_class_info_function->WriteFunctionArguments(
exe_ctx, m_shared_cache_class_info_extractor.GetClassInfoArgs(),
arguments, diagnostics)) {
exe_ctx, m_args, arguments, diagnostics)) {
EvaluateExpressionOptions options;
options.SetUnwindOnError(true);
options.SetTryAllThreads(false);
@ -1896,8 +1887,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
// Run the function
ExpressionResults results =
get_shared_cache_class_info_function->ExecuteFunction(
exe_ctx, &m_shared_cache_class_info_extractor.GetClassInfoArgs(),
options, diagnostics, return_value);
exe_ctx, &m_args, options, diagnostics, return_value);
if (results == eExpressionCompleted) {
// The result is the number of ClassInfo structures that were filled in
@ -1923,7 +1913,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
buffer.GetByteSize(),
process->GetByteOrder(), addr_size);
ParseClassInfoArray(class_infos_data, num_class_infos);
m_runtime.ParseClassInfoArray(class_infos_data, num_class_infos);
}
} else {
success = true;
@ -2007,7 +1997,7 @@ void AppleObjCRuntimeV2::UpdateISAToDescriptorMapIfNeeded() {
// Grab the dynamically loaded Objective-C classes from memory.
DescriptorMapUpdateResult dynamic_update_result =
UpdateISAToDescriptorMapDynamic(hash_table);
m_dynamic_class_info_extractor.UpdateISAToDescriptorMap(hash_table);
// Now get the objc classes that are baked into the Objective-C runtime in
// the shared cache, but only once per process as this data never changes
@ -2023,7 +2013,7 @@ void AppleObjCRuntimeV2::UpdateISAToDescriptorMapIfNeeded() {
const uint32_t num_classes_to_warn_at = 500;
DescriptorMapUpdateResult shared_cache_update_result =
UpdateISAToDescriptorMapSharedCache();
m_shared_cache_class_info_extractor.UpdateISAToDescriptorMap();
LLDB_LOGF(log,
"attempted to read objc class data - results: "

View File

@ -318,6 +318,10 @@ private:
DynamicClassInfoExtractor(AppleObjCRuntimeV2 &runtime)
: ClassInfoExtractor(runtime) {}
DescriptorMapUpdateResult
UpdateISAToDescriptorMap(RemoteNXMapTable &hash_table);
private:
enum Helper { gdb_objc_realized_classes, objc_copyRealizedClassList };
/// Compute which helper to use. Prefer objc_copyRealizedClassList if it's
@ -329,7 +333,6 @@ private:
Helper helper);
lldb::addr_t &GetClassInfoArgs(Helper helper);
private:
std::unique_ptr<UtilityFunction>
GetClassInfoUtilityFunctionImpl(ExecutionContext &exe_ctx, std::string code,
std::string name);
@ -356,17 +359,16 @@ private:
SharedCacheClassInfoExtractor(AppleObjCRuntimeV2 &runtime)
: ClassInfoExtractor(runtime) {}
UtilityFunction *GetClassInfoUtilityFunction(ExecutionContext &exe_ctx);
lldb::addr_t &GetClassInfoArgs() { return m_args; }
std::mutex &GetMutex() { return m_mutex; }
DescriptorMapUpdateResult UpdateISAToDescriptorMap();
private:
UtilityFunction *GetClassInfoUtilityFunction(ExecutionContext &exe_ctx);
std::unique_ptr<UtilityFunction>
GetClassInfoUtilityFunctionImpl(ExecutionContext &exe_ctx);
std::unique_ptr<UtilityFunction> m_utility_function;
lldb::addr_t m_args = LLDB_INVALID_ADDRESS;
std::mutex m_mutex;
};
AppleObjCRuntimeV2(Process *process, const lldb::ModuleSP &objc_module_sp);
@ -381,14 +383,9 @@ private:
/// change when lazily named classes get realized.
bool RealizedClassGenerationCountChanged();
DescriptorMapUpdateResult
UpdateISAToDescriptorMapDynamic(RemoteNXMapTable &hash_table);
uint32_t ParseClassInfoArray(const lldb_private::DataExtractor &data,
uint32_t num_class_infos);
DescriptorMapUpdateResult UpdateISAToDescriptorMapSharedCache();
enum class SharedCacheWarningReason {
eExpressionExecutionFailure,
eNotEnoughClassesRead