Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 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 | // |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 8 | //===---------------------------------------------------------------------===// |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 9 | |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 14 | #include "lldb/lldb-private.h" |
| 15 | #include "lldb/Target/Process.h" |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Module.h" |
| 17 | #include "lldb/Core/ModuleList.h" |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 18 | #include "lldb/Core/PluginManager.h" |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 19 | #include "lldb/Core/RegularExpression.h" |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 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 | { |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 28 | InstrumentationRuntimeCreateInstance create_callback = nullptr; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 29 | InstrumentationRuntimeGetType get_type_callback; |
| 30 | for (uint32_t idx = 0; ; ++idx) |
| 31 | { |
| 32 | create_callback = PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(idx); |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 33 | if (create_callback == nullptr) |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 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 | |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 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 | |
Kuba Brecka | 1aad8fb | 2016-04-10 18:57:38 +0000 | [diff] [blame] | 78 | lldb::ThreadCollectionSP |
| 79 | InstrumentationRuntime::GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) |
| 80 | { |
| 81 | return ThreadCollectionSP(new ThreadCollection()); |
| 82 | } |