blob: 6b52416df3d150167f031c1e8e005dcc1f9076b1 [file] [log] [blame]
Kuba Breckaafdf8422014-10-10 23:43:03 +00001//===-- 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 Zelenko9394d7722016-02-18 00:10:17 +00008//===---------------------------------------------------------------------===//
Kuba Breckaafdf8422014-10-10 23:43:03 +00009
Eugene Zelenko9394d7722016-02-18 00:10:17 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Kuba Breckaafdf8422014-10-10 23:43:03 +000014#include "lldb/lldb-private.h"
15#include "lldb/Target/Process.h"
Vedant Kumar1c23c142016-08-11 17:28:37 +000016#include "lldb/Core/Module.h"
17#include "lldb/Core/ModuleList.h"
Kuba Breckaafdf8422014-10-10 23:43:03 +000018#include "lldb/Core/PluginManager.h"
Vedant Kumar1c23c142016-08-11 17:28:37 +000019#include "lldb/Core/RegularExpression.h"
Kuba Breckaafdf8422014-10-10 23:43:03 +000020#include "lldb/Target/InstrumentationRuntime.h"
21
22using namespace lldb;
23using namespace lldb_private;
24
25void
26InstrumentationRuntime::ModulesDidLoad(lldb_private::ModuleList &module_list, lldb_private::Process *process, InstrumentationRuntimeCollection &runtimes)
27{
Eugene Zelenko9394d7722016-02-18 00:10:17 +000028 InstrumentationRuntimeCreateInstance create_callback = nullptr;
Kuba Breckaafdf8422014-10-10 23:43:03 +000029 InstrumentationRuntimeGetType get_type_callback;
30 for (uint32_t idx = 0; ; ++idx)
31 {
32 create_callback = PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(idx);
Eugene Zelenko9394d7722016-02-18 00:10:17 +000033 if (create_callback == nullptr)
Kuba Breckaafdf8422014-10-10 23:43:03 +000034 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 Kumar1c23c142016-08-11 17:28:37 +000046void
47InstrumentationRuntime::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 Brecka1aad8fb2016-04-10 18:57:38 +000078lldb::ThreadCollectionSP
79InstrumentationRuntime::GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info)
80{
81 return ThreadCollectionSP(new ThreadCollection());
82}