LLDB  mainline
TraceIntelPTBundleLoader.h
Go to the documentation of this file.
1 //===-- TraceIntelPTBundleLoader.h ----------------------------*- 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 
9 #ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTBUNDLELOADER_H
10 #define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTBUNDLELOADER_H
11 
12 #include "../common/ThreadPostMortemTrace.h"
14 
15 namespace lldb_private {
16 namespace trace_intel_pt {
17 
18 class TraceIntelPT;
19 
21 public:
22  /// Helper struct holding the objects created when parsing a process
23  struct ParsedProcess {
24  lldb::TargetSP target_sp;
25  std::vector<lldb::ThreadPostMortemTraceSP> threads;
26  };
27 
28  /// \param[in] debugger
29  /// The debugger that will own the targets to create.
30  ///
31  /// \param[in] bundle_description
32  /// The JSON description of a trace bundle that follows the schema of the intel pt trace plug-in.
33  ///
34  /// \param[in] bundle_dir
35  /// The folder where the trace bundle is located.
37  const llvm::json::Value &bundle_description,
38  llvm::StringRef bundle_dir)
39  : m_debugger(debugger), m_bundle_description(bundle_description),
40  m_bundle_dir(bundle_dir) {}
41 
42  /// \return
43  /// The JSON schema for the bundle description.
44  static llvm::StringRef GetSchema();
45 
46  /// Parse the trace bundle description and create the corresponding \a
47  /// Target objects. In case of an error, no targets are created.
48  ///
49  /// \return
50  /// A \a lldb::TraceSP instance created according to the trace bundle information. In case of
51  /// errors, return a null pointer.
52  llvm::Expected<lldb::TraceSP> Load();
53 
54 private:
55  /// Resolve non-absolute paths relative to the bundle folder.
56  FileSpec NormalizePath(const std::string &path);
57 
58  /// Create a post-mortem thread associated with the given \p process
59  /// using the definition from \p thread.
60  lldb::ThreadPostMortemTraceSP ParseThread(Process &process,
61  const JSONThread &thread);
62 
63  /// Given a bundle description and a list of fully parsed processes,
64  /// create an actual Trace instance that "traces" these processes.
65  llvm::Expected<lldb::TraceSP>
67  std::vector<ParsedProcess> &parsed_processes);
68 
69  /// Create the corresponding Threads and Process objects given the JSON
70  /// process definition.
71  ///
72  /// \param[in] process
73  /// The JSON process definition
74  llvm::Expected<ParsedProcess> ParseProcess(const JSONProcess &process);
75 
76  /// Create a module associated with the given \p target using the definition from \p module.
77  llvm::Error ParseModule(Target &target, const JSONModule &module);
78 
79  /// Create a user-friendly error message upon a JSON-parsing failure using the
80  /// \a json::ObjectMapper functionality.
81  ///
82  /// \param[in] root
83  /// The \a llvm::json::Path::Root used to parse the JSON \a value.
84  ///
85  /// \param[in] value
86  /// The json value that failed to parse.
87  ///
88  /// \return
89  /// An \a llvm::Error containing the user-friendly error message.
90  llvm::Error CreateJSONError(llvm::json::Path::Root &root,
91  const llvm::json::Value &value);
92 
93  /// Create the corresponding Process, Thread and Module objects given this
94  /// bundle description.
95  llvm::Expected<std::vector<ParsedProcess>>
96  LoadBundle(const JSONTraceBundleDescription &bundle_description);
97 
98  /// When applicable, augment the list of threads in the trace bundle by
99  /// inspecting the context switch trace. This only applies for threads of
100  /// processes already specified in this bundle description.
101  ///
102  /// \return
103  /// An \a llvm::Error in case if failures, or \a llvm::Error::success
104  /// otherwise.
106 
107  /// Modifiy the bundle description by normalizing all the paths relative to the
108  /// session file directory.
109  void NormalizeAllPaths(JSONTraceBundleDescription &bundle_description);
110 
112  const llvm::json::Value &m_bundle_description;
114 };
115 
116 } // namespace trace_intel_pt
117 } // namespace lldb_private
118 
119 
120 #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTBUNDLELOADER_H
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::ParsedProcess::target_sp
lldb::TargetSP target_sp
Definition: TraceIntelPTBundleLoader.h:24
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::ParsedProcess::threads
std::vector< lldb::ThreadPostMortemTraceSP > threads
Definition: TraceIntelPTBundleLoader.h:25
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::TraceIntelPTBundleLoader
TraceIntelPTBundleLoader(Debugger &debugger, const llvm::json::Value &bundle_description, llvm::StringRef bundle_dir)
Definition: TraceIntelPTBundleLoader.h:36
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::ParseProcess
llvm::Expected< ParsedProcess > ParseProcess(const JSONProcess &process)
Create the corresponding Threads and Process objects given the JSON process definition.
Definition: TraceIntelPTBundleLoader.cpp:92
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::Load
llvm::Expected< lldb::TraceSP > Load()
Parse the trace bundle description and create the corresponding Target objects.
Definition: TraceIntelPTBundleLoader.cpp:317
lldb_private::Process
Definition: Process.h:338
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::m_debugger
Debugger & m_debugger
Definition: TraceIntelPTBundleLoader.h:111
lldb_private::Target
Definition: Target.h:467
lldb_private::trace_intel_pt::JSONModule
Definition: TraceIntelPTJSONStructs.h:25
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::m_bundle_dir
const std::string m_bundle_dir
Definition: TraceIntelPTBundleLoader.h:113
TraceIntelPTJSONStructs.h
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader
Definition: TraceIntelPTBundleLoader.h:20
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::CreateJSONError
llvm::Error CreateJSONError(llvm::json::Path::Root &root, const llvm::json::Value &value)
Create a user-friendly error message upon a JSON-parsing failure using the json::ObjectMapper functio...
Definition: TraceIntelPTBundleLoader.cpp:66
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::ParseThread
lldb::ThreadPostMortemTraceSP ParseThread(Process &process, const JSONThread &thread)
Create a post-mortem thread associated with the given process using the definition from thread.
Definition: TraceIntelPTBundleLoader.cpp:77
lldb_private::trace_intel_pt::JSONThread
Definition: TraceIntelPTJSONStructs.h:32
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::ParseModule
llvm::Error ParseModule(Target &target, const JSONModule &module)
Create a module associated with the given target using the definition from module.
Definition: TraceIntelPTBundleLoader.cpp:32
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::GetSchema
static llvm::StringRef GetSchema()
Definition: TraceIntelPTBundleLoader.cpp:152
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::AugmentThreadsFromContextSwitches
llvm::Error AugmentThreadsFromContextSwitches(JSONTraceBundleDescription &bundle_description)
When applicable, augment the list of threads in the trace bundle by inspecting the context switch tra...
Definition: TraceIntelPTBundleLoader.cpp:229
lldb_private::Debugger
Definition: Debugger.h:74
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::NormalizePath
FileSpec NormalizePath(const std::string &path)
Resolve non-absolute paths relative to the bundle folder.
Definition: TraceIntelPTBundleLoader.cpp:25
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::CreateTraceIntelPTInstance
llvm::Expected< lldb::TraceSP > CreateTraceIntelPTInstance(JSONTraceBundleDescription &bundle_description, std::vector< ParsedProcess > &parsed_processes)
Given a bundle description and a list of fully parsed processes, create an actual Trace instance that...
Definition: TraceIntelPTBundleLoader.cpp:277
lldb_private::trace_intel_pt::JSONTraceBundleDescription
Definition: TraceIntelPTJSONStructs.h:50
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::NormalizeAllPaths
void NormalizeAllPaths(JSONTraceBundleDescription &bundle_description)
Modifiy the bundle description by normalizing all the paths relative to the session file directory.
Definition: TraceIntelPTBundleLoader.cpp:295
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::LoadBundle
llvm::Expected< std::vector< ParsedProcess > > LoadBundle(const JSONTraceBundleDescription &bundle_description)
Create the corresponding Process, Thread and Module objects given this bundle description.
Definition: TraceIntelPTBundleLoader.cpp:131
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::m_bundle_description
const llvm::json::Value & m_bundle_description
Definition: TraceIntelPTBundleLoader.h:112
lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::ParsedProcess
Helper struct holding the objects created when parsing a process.
Definition: TraceIntelPTBundleLoader.h:23
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
lldb_private::trace_intel_pt::JSONProcess
Definition: TraceIntelPTJSONStructs.h:37