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