1cfca06d7SDimitry Andric //===-- InstrumentationRuntime.cpp ----------------------------------------===// 2205afe67SEd Maste // 35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6205afe67SEd Maste // 7f3fbd1c0SDimitry Andric //===---------------------------------------------------------------------===// 8205afe67SEd Maste 9205afe67SEd Maste #include "lldb/Target/InstrumentationRuntime.h" 1014f1b3e8SDimitry Andric #include "lldb/Core/Module.h" 1114f1b3e8SDimitry Andric #include "lldb/Core/ModuleList.h" 1214f1b3e8SDimitry Andric #include "lldb/Core/PluginManager.h" 1314f1b3e8SDimitry Andric #include "lldb/Target/Process.h" 1474a628f7SDimitry Andric #include "lldb/Utility/RegularExpression.h" 1514f1b3e8SDimitry Andric #include "lldb/lldb-private.h" 16205afe67SEd Maste 17205afe67SEd Maste using namespace lldb; 18205afe67SEd Maste using namespace lldb_private; 19205afe67SEd Maste ModulesDidLoad(lldb_private::ModuleList & module_list,lldb_private::Process * process,InstrumentationRuntimeCollection & runtimes)2014f1b3e8SDimitry Andricvoid InstrumentationRuntime::ModulesDidLoad( 2114f1b3e8SDimitry Andric lldb_private::ModuleList &module_list, lldb_private::Process *process, 2214f1b3e8SDimitry Andric InstrumentationRuntimeCollection &runtimes) { 23f3fbd1c0SDimitry Andric InstrumentationRuntimeCreateInstance create_callback = nullptr; 24205afe67SEd Maste InstrumentationRuntimeGetType get_type_callback; 2514f1b3e8SDimitry Andric for (uint32_t idx = 0;; ++idx) { 2614f1b3e8SDimitry Andric create_callback = 2714f1b3e8SDimitry Andric PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(idx); 28f3fbd1c0SDimitry Andric if (create_callback == nullptr) 29205afe67SEd Maste break; 3014f1b3e8SDimitry Andric get_type_callback = 3114f1b3e8SDimitry Andric PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(idx); 32205afe67SEd Maste InstrumentationRuntimeType type = get_type_callback(); 33205afe67SEd Maste 34205afe67SEd Maste InstrumentationRuntimeCollection::iterator pos; 35205afe67SEd Maste pos = runtimes.find(type); 36205afe67SEd Maste if (pos == runtimes.end()) { 37205afe67SEd Maste runtimes[type] = create_callback(process->shared_from_this()); 38205afe67SEd Maste } 39205afe67SEd Maste } 40205afe67SEd Maste } 41205afe67SEd Maste ModulesDidLoad(lldb_private::ModuleList & module_list)4214f1b3e8SDimitry Andricvoid InstrumentationRuntime::ModulesDidLoad( 4314f1b3e8SDimitry Andric lldb_private::ModuleList &module_list) { 4414f1b3e8SDimitry Andric if (IsActive()) 4514f1b3e8SDimitry Andric return; 4614f1b3e8SDimitry Andric 4714f1b3e8SDimitry Andric if (GetRuntimeModuleSP()) { 4814f1b3e8SDimitry Andric Activate(); 4914f1b3e8SDimitry Andric return; 50205afe67SEd Maste } 51205afe67SEd Maste 5214f1b3e8SDimitry Andric module_list.ForEach([this](const lldb::ModuleSP module_sp) -> bool { 5314f1b3e8SDimitry Andric const FileSpec &file_spec = module_sp->GetFileSpec(); 5414f1b3e8SDimitry Andric if (!file_spec) 5514f1b3e8SDimitry Andric return true; // Keep iterating. 5614f1b3e8SDimitry Andric 5714f1b3e8SDimitry Andric const RegularExpression &runtime_regex = GetPatternForRuntimeLibrary(); 5814f1b3e8SDimitry Andric if (runtime_regex.Execute(file_spec.GetFilename().GetCString()) || 5914f1b3e8SDimitry Andric module_sp->IsExecutable()) { 6014f1b3e8SDimitry Andric if (CheckIfRuntimeIsValid(module_sp)) { 6114f1b3e8SDimitry Andric SetRuntimeModuleSP(module_sp); 6214f1b3e8SDimitry Andric Activate(); 63ac9a064cSDimitry Andric if (!IsActive()) 64ac9a064cSDimitry Andric SetRuntimeModuleSP({}); // Don't cache module if activation failed. 6514f1b3e8SDimitry Andric return false; // Stop iterating, we're done. 6614f1b3e8SDimitry Andric } 6714f1b3e8SDimitry Andric } 6814f1b3e8SDimitry Andric 6914f1b3e8SDimitry Andric return true; 7014f1b3e8SDimitry Andric }); 71205afe67SEd Maste } 72f3fbd1c0SDimitry Andric 73f3fbd1c0SDimitry Andric lldb::ThreadCollectionSP GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info)7414f1b3e8SDimitry AndricInstrumentationRuntime::GetBacktracesFromExtendedStopInfo( 7514f1b3e8SDimitry Andric StructuredData::ObjectSP info) { 76f3fbd1c0SDimitry Andric return ThreadCollectionSP(new ThreadCollection()); 77f3fbd1c0SDimitry Andric } 78