Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- InstrumentationRuntime.cpp ----------------------------------------===// |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 6 | // |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 7 | //===---------------------------------------------------------------------===// |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 8 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9 | #include "lldb/Target/InstrumentationRuntime.h" |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 10 | #include "lldb/Core/Module.h" |
| 11 | #include "lldb/Core/ModuleList.h" |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 12 | #include "lldb/Core/PluginManager.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 13 | #include "lldb/Target/Process.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 14 | #include "lldb/Utility/RegularExpression.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 15 | #include "lldb/lldb-private.h" |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 16 | |
| 17 | using namespace lldb; |
| 18 | using namespace lldb_private; |
| 19 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | void InstrumentationRuntime::ModulesDidLoad( |
| 21 | lldb_private::ModuleList &module_list, lldb_private::Process *process, |
| 22 | InstrumentationRuntimeCollection &runtimes) { |
| 23 | InstrumentationRuntimeCreateInstance create_callback = nullptr; |
| 24 | InstrumentationRuntimeGetType get_type_callback; |
| 25 | for (uint32_t idx = 0;; ++idx) { |
| 26 | create_callback = |
| 27 | PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(idx); |
| 28 | if (create_callback == nullptr) |
| 29 | break; |
| 30 | get_type_callback = |
| 31 | PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(idx); |
| 32 | InstrumentationRuntimeType type = get_type_callback(); |
| 33 | |
| 34 | InstrumentationRuntimeCollection::iterator pos; |
| 35 | pos = runtimes.find(type); |
| 36 | if (pos == runtimes.end()) { |
| 37 | runtimes[type] = create_callback(process->shared_from_this()); |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 38 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | } |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | void InstrumentationRuntime::ModulesDidLoad( |
| 43 | lldb_private::ModuleList &module_list) { |
| 44 | if (IsActive()) |
| 45 | return; |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | if (GetRuntimeModuleSP()) { |
| 48 | Activate(); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | module_list.ForEach([this](const lldb::ModuleSP module_sp) -> bool { |
| 53 | const FileSpec &file_spec = module_sp->GetFileSpec(); |
| 54 | if (!file_spec) |
| 55 | return true; // Keep iterating. |
| 56 | |
| 57 | const RegularExpression &runtime_regex = GetPatternForRuntimeLibrary(); |
| 58 | if (runtime_regex.Execute(file_spec.GetFilename().GetCString()) || |
| 59 | module_sp->IsExecutable()) { |
| 60 | if (CheckIfRuntimeIsValid(module_sp)) { |
| 61 | SetRuntimeModuleSP(module_sp); |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 62 | Activate(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | return false; // Stop iterating, we're done. |
| 64 | } |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | return true; |
| 68 | }); |
Vedant Kumar | 1c23c14 | 2016-08-11 17:28:37 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Kuba Brecka | 1aad8fb | 2016-04-10 18:57:38 +0000 | [diff] [blame] | 71 | lldb::ThreadCollectionSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | InstrumentationRuntime::GetBacktracesFromExtendedStopInfo( |
| 73 | StructuredData::ObjectSP info) { |
| 74 | return ThreadCollectionSP(new ThreadCollection()); |
Kuba Brecka | 1aad8fb | 2016-04-10 18:57:38 +0000 | [diff] [blame] | 75 | } |