LLDB  mainline
InstrumentationRuntime.cpp
Go to the documentation of this file.
1 //===-- InstrumentationRuntime.cpp ------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===---------------------------------------------------------------------===//
8 
10 #include "lldb/Core/Module.h"
11 #include "lldb/Core/ModuleList.h"
13 #include "lldb/Target/Process.h"
15 #include "lldb/lldb-private.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 void InstrumentationRuntime::ModulesDidLoad(
21  lldb_private::ModuleList &module_list, lldb_private::Process *process,
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());
38  }
39  }
40 }
41 
42 void InstrumentationRuntime::ModulesDidLoad(
43  lldb_private::ModuleList &module_list) {
44  if (IsActive())
45  return;
46 
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);
62  Activate();
63  return false; // Stop iterating, we're done.
64  }
65  }
66 
67  return true;
68  });
69 }
70 
71 lldb::ThreadCollectionSP
72 InstrumentationRuntime::GetBacktracesFromExtendedStopInfo(
74  return ThreadCollectionSP(new ThreadCollection());
75 }
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:369
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A file utility class.
Definition: FileSpec.h:55
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
std::map< lldb::InstrumentationRuntimeType, lldb::InstrumentationRuntimeSP > InstrumentationRuntimeCollection
void ForEach(std::function< bool(const lldb::ModuleSP &module_sp)> const &callback) const
InstrumentationRuntimeType
A collection class for Module objects.
Definition: ModuleList.h:91
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:247
bool Execute(llvm::StringRef string, Match *match=nullptr) const
Executes a regular expression.
Definition: SBAddress.h:15
std::shared_ptr< Object > ObjectSP