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 |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 14 | #include "lldb/Target/InstrumentationRuntime.h" |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Module.h" |
| 16 | #include "lldb/Core/ModuleList.h" |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 17 | #include "lldb/Core/PluginManager.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | #include "lldb/Target/Process.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame^] | 19 | #include "lldb/Utility/RegularExpression.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | #include "lldb/lldb-private.h" |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace lldb; |
| 23 | using namespace lldb_private; |
| 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | void InstrumentationRuntime::ModulesDidLoad( |
| 26 | lldb_private::ModuleList &module_list, lldb_private::Process *process, |
| 27 | InstrumentationRuntimeCollection &runtimes) { |
| 28 | InstrumentationRuntimeCreateInstance create_callback = nullptr; |
| 29 | InstrumentationRuntimeGetType get_type_callback; |
| 30 | for (uint32_t idx = 0;; ++idx) { |
| 31 | create_callback = |
| 32 | PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(idx); |
| 33 | if (create_callback == nullptr) |
| 34 | break; |
| 35 | get_type_callback = |
| 36 | PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(idx); |
| 37 | InstrumentationRuntimeType type = get_type_callback(); |
| 38 | |
| 39 | InstrumentationRuntimeCollection::iterator pos; |
| 40 | pos = runtimes.find(type); |
| 41 | if (pos == runtimes.end()) { |
| 42 | runtimes[type] = create_callback(process->shared_from_this()); |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 43 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | } |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | void InstrumentationRuntime::ModulesDidLoad( |
| 48 | lldb_private::ModuleList &module_list) { |
| 49 | if (IsActive()) |
| 50 | return; |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | if (GetRuntimeModuleSP()) { |
| 53 | Activate(); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | module_list.ForEach([this](const lldb::ModuleSP module_sp) -> bool { |
| 58 | const FileSpec &file_spec = module_sp->GetFileSpec(); |
| 59 | if (!file_spec) |
| 60 | return true; // Keep iterating. |
| 61 | |
| 62 | const RegularExpression &runtime_regex = GetPatternForRuntimeLibrary(); |
| 63 | if (runtime_regex.Execute(file_spec.GetFilename().GetCString()) || |
| 64 | module_sp->IsExecutable()) { |
| 65 | if (CheckIfRuntimeIsValid(module_sp)) { |
| 66 | SetRuntimeModuleSP(module_sp); |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 67 | Activate(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | return false; // Stop iterating, we're done. |
| 69 | } |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | return true; |
| 73 | }); |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Kuba Brecka | 1aad8fb | 2016-04-10 18:57:38 +0000 | [diff] [blame] | 76 | lldb::ThreadCollectionSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | InstrumentationRuntime::GetBacktracesFromExtendedStopInfo( |
| 78 | StructuredData::ObjectSP info) { |
| 79 | return ThreadCollectionSP(new ThreadCollection()); |
Kuba Brecka | 1aad8fb | 2016-04-10 18:57:38 +0000 | [diff] [blame] | 80 | } |