LLDB mainline
InstrumentationRuntime.cpp
Go to the documentation of this file.
1//===-- InstrumentationRuntime.cpp ----------------------------------------===//
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"
13#include "lldb/Target/Process.h"
15#include "lldb/lldb-private.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
24 InstrumentationRuntimeType type = cbs.get_type_callback();
25 if (runtimes.find(type) == runtimes.end())
26 runtimes[type] = cbs.create_callback(process->shared_from_this());
27 }
28}
29
31 lldb_private::ModuleList &module_list) {
32 if (IsActive())
33 return;
34
35 if (GetRuntimeModuleSP()) {
36 Activate();
37 return;
38 }
39
40 module_list.ForEach([this](const lldb::ModuleSP module_sp) {
41 const FileSpec &file_spec = module_sp->GetFileSpec();
42 if (!file_spec)
44
45 const RegularExpression &runtime_regex = GetPatternForRuntimeLibrary();
46 if (MatchAllModules() || runtime_regex.Execute(file_spec.GetFilename()) ||
47 module_sp->IsExecutable()) {
48 if (CheckIfRuntimeIsValid(module_sp)) {
49 SetRuntimeModuleSP(module_sp);
50 Activate();
51 if (!IsActive())
52 SetRuntimeModuleSP({}); // Don't cache module if activation failed.
54 }
55 }
56
58 });
59}
60
64 return std::make_shared<ThreadCollection>();
65}
A file utility class.
Definition FileSpec.h:57
llvm::StringRef GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:249
virtual lldb::ThreadCollectionSP GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info)
void SetRuntimeModuleSP(lldb::ModuleSP module_sp)
virtual void Activate()=0
Register a breakpoint in the runtime library and perform any other necessary initialization.
virtual bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp)=0
Check whether module_sp corresponds to a valid runtime library.
virtual const RegularExpression & GetPatternForRuntimeLibrary()=0
Return a regular expression which can be used to identify a valid version of the runtime library.
static void ModulesDidLoad(lldb_private::ModuleList &module_list, Process *process, InstrumentationRuntimeCollection &runtimes)
A collection class for Module objects.
Definition ModuleList.h:125
void ForEach(std::function< IterationAction(const lldb::ModuleSP &module_sp)> const &callback) const
Applies 'callback' to each module in this ModuleList.
static llvm::SmallVector< InstrumentationRuntimeCallbacks > GetInstrumentationRuntimeCallbacks(bool enabled_only=true)
A plug-in interface definition class for debugging a process.
Definition Process.h:359
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
std::map< lldb::InstrumentationRuntimeType, lldb::InstrumentationRuntimeSP > InstrumentationRuntimeCollection
InstrumentationRuntimeType
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::ThreadCollection > ThreadCollectionSP