1 //===-- InstrumentationRuntime.cpp ------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===---------------------------------------------------------------------===// 9 10 // C Includes 11 // C++ Includes 12 // Other libraries and framework includes 13 // Project includes 14 #include "lldb/lldb-private.h" 15 #include "lldb/Target/Process.h" 16 #include "lldb/Core/Module.h" 17 #include "lldb/Core/ModuleList.h" 18 #include "lldb/Core/PluginManager.h" 19 #include "lldb/Core/RegularExpression.h" 20 #include "lldb/Target/InstrumentationRuntime.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 void 26 InstrumentationRuntime::ModulesDidLoad(lldb_private::ModuleList &module_list, lldb_private::Process *process, InstrumentationRuntimeCollection &runtimes) 27 { 28 InstrumentationRuntimeCreateInstance create_callback = nullptr; 29 InstrumentationRuntimeGetType get_type_callback; 30 for (uint32_t idx = 0; ; ++idx) 31 { 32 create_callback = PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(idx); 33 if (create_callback == nullptr) 34 break; 35 get_type_callback = PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(idx); 36 InstrumentationRuntimeType type = get_type_callback(); 37 38 InstrumentationRuntimeCollection::iterator pos; 39 pos = runtimes.find (type); 40 if (pos == runtimes.end()) { 41 runtimes[type] = create_callback(process->shared_from_this()); 42 } 43 } 44 } 45 46 void 47 InstrumentationRuntime::ModulesDidLoad(lldb_private::ModuleList &module_list) 48 { 49 if (IsActive()) 50 return; 51 52 if (GetRuntimeModuleSP()) 53 { 54 Activate(); 55 return; 56 } 57 58 module_list.ForEach([this](const lldb::ModuleSP module_sp) -> bool { 59 const FileSpec &file_spec = module_sp->GetFileSpec(); 60 if (!file_spec) 61 return true; // Keep iterating. 62 63 const RegularExpression &runtime_regex = GetPatternForRuntimeLibrary(); 64 if (runtime_regex.Execute(file_spec.GetFilename().GetCString()) || module_sp->IsExecutable()) 65 { 66 if (CheckIfRuntimeIsValid(module_sp)) 67 { 68 SetRuntimeModuleSP(module_sp); 69 Activate(); 70 return false; // Stop iterating, we're done. 71 } 72 } 73 74 return true; 75 }); 76 } 77 78 lldb::ThreadCollectionSP 79 InstrumentationRuntime::GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) 80 { 81 return ThreadCollectionSP(new ThreadCollection()); 82 } 83