Add new virtual method for language runtime plug-ins:

virtual void
LanguageRuntime::ModulesDidLoad (const ModuleList &module_list);

Then reorganized how the objective C plug-in is notified so it will work for all LanguageRuntime subclasses.

llvm-svn: 235118
This commit is contained in:
Greg Clayton 2015-04-16 17:13:34 +00:00
parent 1c130bb04b
commit 35ca64b127
7 changed files with 106 additions and 62 deletions

View File

@ -119,6 +119,12 @@ public:
return false;
}
virtual void
ModulesDidLoad (const ModuleList &module_list)
{
return;
}
protected:
//------------------------------------------------------------------
// Classes that inherit from LanguageRuntime can see and modify these

View File

@ -313,8 +313,8 @@ public:
virtual
~ObjCLanguageRuntime();
virtual lldb::LanguageType
GetLanguageType () const
lldb::LanguageType
GetLanguageType () const override
{
return lldb::eLanguageTypeObjC;
}
@ -515,10 +515,10 @@ public:
m_negative_complete_class_cache.clear();
}
virtual bool
bool
GetTypeBitSize (const ClangASTType& clang_type,
uint64_t &size);
uint64_t &size) override;
protected:
//------------------------------------------------------------------
// Classes that inherit from ObjCLanguageRuntime can see and modify these
@ -645,6 +645,9 @@ protected:
ISAToDescriptorIterator
GetDescriptorIterator (const ConstString &name);
void
ReadObjCLibraryIfNeeded (const ModuleList &module_list);
DISALLOW_COPY_AND_ASSIGN (ObjCLanguageRuntime);
};

View File

@ -39,6 +39,15 @@ using namespace lldb_private;
#define PO_FUNCTION_TIMEOUT_USEC 15*1000*1000
AppleObjCRuntime::AppleObjCRuntime(Process *process) :
ObjCLanguageRuntime (process),
m_read_objc_library (false),
m_objc_trampoline_handler_ap (),
m_Foundation_major()
{
ReadObjCLibraryIfNeeded (process->GetTarget().GetImages());
}
bool
AppleObjCRuntime::GetObjectDescription (Stream &str, ValueObject &valobj)
{
@ -443,3 +452,29 @@ AppleObjCRuntime::CreateExceptionSearchFilter ()
}
}
void
AppleObjCRuntime::ReadObjCLibraryIfNeeded (const ModuleList &module_list)
{
if (!HasReadObjCLibrary ())
{
Mutex::Locker locker (module_list.GetMutex ());
size_t num_modules = module_list.GetSize();
for (size_t i = 0; i < num_modules; i++)
{
auto mod = module_list.GetModuleAtIndex (i);
if (IsModuleObjCLibrary (mod))
{
ReadObjCLibrary (mod);
break;
}
}
}
}
void
AppleObjCRuntime::ModulesDidLoad (const ModuleList &module_list)
{
ReadObjCLibraryIfNeeded (module_list);
}

View File

@ -34,37 +34,37 @@ public:
virtual ~AppleObjCRuntime() { }
// These are generic runtime functions:
virtual bool
GetObjectDescription (Stream &str, Value &value, ExecutionContextScope *exe_scope);
bool
GetObjectDescription (Stream &str, Value &value, ExecutionContextScope *exe_scope) override;
virtual bool
GetObjectDescription (Stream &str, ValueObject &object);
bool
GetObjectDescription (Stream &str, ValueObject &object) override;
virtual bool
CouldHaveDynamicValue (ValueObject &in_value);
bool
CouldHaveDynamicValue (ValueObject &in_value) override;
virtual bool
bool
GetDynamicTypeAndAddress (ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address);
Address &address) override;
// These are the ObjC specific functions.
virtual bool
IsModuleObjCLibrary (const lldb::ModuleSP &module_sp);
bool
IsModuleObjCLibrary (const lldb::ModuleSP &module_sp) override;
virtual bool
ReadObjCLibrary (const lldb::ModuleSP &module_sp);
bool
ReadObjCLibrary (const lldb::ModuleSP &module_sp) override;
virtual bool
HasReadObjCLibrary ()
bool
HasReadObjCLibrary () override
{
return m_read_objc_library;
}
virtual lldb::ThreadPlanSP
GetStepThroughTrampolinePlan (Thread &thread, bool stop_others);
lldb::ThreadPlanSP
GetStepThroughTrampolinePlan (Thread &thread, bool stop_others) override;
// Get the "libobjc.A.dylib" module from the current target if we can find
// it, also cache it once it is found to ensure quick lookups.
@ -76,10 +76,16 @@ public:
//------------------------------------------------------------------
// Note there is no CreateInstance, Initialize & Terminate functions here, because
// you can't make an instance of this generic runtime.
// Sync up with the target
void
ModulesDidLoad (const ModuleList &module_list) override;
protected:
virtual bool
CalculateHasNewLiteralsAndIndexing();
bool
CalculateHasNewLiteralsAndIndexing() override;
static bool
AppleIsModuleObjCLibrary (const lldb::ModuleSP &module_sp);
@ -87,24 +93,27 @@ protected:
static enum ObjCRuntimeVersions
GetObjCVersion (Process *process, lldb::ModuleSP &objc_module_sp);
void
ReadObjCLibraryIfNeeded (const ModuleList &module_list);
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
public:
virtual void
SetExceptionBreakpoints();
void
SetExceptionBreakpoints() override;
virtual void
ClearExceptionBreakpoints ();
void
ClearExceptionBreakpoints () override;
virtual bool
ExceptionBreakpointsAreSet ();
bool
ExceptionBreakpointsAreSet () override;
virtual bool
ExceptionBreakpointsExplainStop (lldb::StopInfoSP stop_reason);
bool
ExceptionBreakpointsExplainStop (lldb::StopInfoSP stop_reason) override;
virtual lldb::SearchFilterSP
CreateExceptionSearchFilter ();
lldb::SearchFilterSP
CreateExceptionSearchFilter () override;
uint32_t
GetFoundationVersion ();
@ -121,14 +130,8 @@ protected:
llvm::Optional<uint32_t> m_Foundation_major;
AppleObjCRuntime(Process *process) :
lldb_private::ObjCLanguageRuntime(process),
m_read_objc_library (false),
m_objc_trampoline_handler_ap (),
m_Foundation_major()
{
// Call CreateInstance instead.
}
// Call CreateInstance instead.
AppleObjCRuntime(Process *process);
};
} // namespace lldb_private

View File

@ -44,7 +44,6 @@ ObjCLanguageRuntime::ObjCLanguageRuntime (Process *process) :
m_complete_class_cache(),
m_negative_complete_class_cache()
{
}
bool

View File

@ -6469,13 +6469,29 @@ Process::ModulesDidLoad (ModuleList &module_list)
runtime->ModulesDidLoad(module_list);
}
// Let any language runtimes we have already created know
// about the modules that loaded.
// Iterate over a copy of this language runtime list in case
// the language runtime ModulesDidLoad somehow causes the language
// riuntime to be unloaded.
LanguageRuntimeCollection language_runtimes(m_language_runtimes);
for (const auto &pair: language_runtimes)
{
// We must check language_runtime_sp to make sure it is not
// NULL as we might cache the fact that we didn't have a
// language runtime for a language.
LanguageRuntimeSP language_runtime_sp = pair.second;
if (language_runtime_sp)
language_runtime_sp->ModulesDidLoad(module_list);
}
}
ThreadCollectionSP
Process::GetHistoryThreads(lldb::addr_t addr)
{
ThreadCollectionSP threads;
const MemoryHistorySP &memory_history = MemoryHistory::FindPlugin(shared_from_this());
if (! memory_history.get()) {

View File

@ -1259,24 +1259,6 @@ Target::ModulesDidLoad (ModuleList &module_list)
if (m_process_sp)
{
m_process_sp->ModulesDidLoad (module_list);
// This assumes there can only be one libobjc loaded.
ObjCLanguageRuntime *objc_runtime = m_process_sp->GetObjCLanguageRuntime ();
if (objc_runtime && !objc_runtime->HasReadObjCLibrary ())
{
Mutex::Locker locker (module_list.GetMutex ());
size_t num_modules = module_list.GetSize();
for (size_t i = 0; i < num_modules; i++)
{
auto mod = module_list.GetModuleAtIndex (i);
if (objc_runtime->IsModuleObjCLibrary (mod))
{
objc_runtime->ReadObjCLibrary (mod);
break;
}
}
}
}
BroadcastEvent (eBroadcastBitModulesLoaded, new TargetEventData (this->shared_from_this(), module_list));
}