LLDB  mainline
TraceSessionFileParser.h
Go to the documentation of this file.
1 //===-- TraceSessionFileParser.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_TARGET_TRACESESSIONPARSER_H
10 #define LLDB_TARGET_TRACESESSIONPARSER_H
11 
12 #include "ThreadPostMortemTrace.h"
13 #include "TraceJSONStructs.h"
14 
15 namespace lldb_private {
16 
17 /// \class TraceSessionFileParser TraceSessionFileParser.h
18 ///
19 /// Base class for parsing the common information of JSON trace session files.
20 /// Contains the basic C++ structs that represent the JSON data, which include
21 /// \a JSONTraceSession as the root object.
22 ///
23 /// See \a Trace::FindPlugin for more information regarding these JSON files.
25 public:
26 
27  /// Helper struct holding the objects created when parsing a process
28  struct ParsedProcess {
29  lldb::TargetSP target_sp;
30  std::vector<lldb::ThreadPostMortemTraceSP> threads;
31  };
32 
33  TraceSessionFileParser(Debugger &debugger, llvm::StringRef session_file_dir,
34  llvm::StringRef schema)
35  : m_debugger(debugger), m_session_file_dir(session_file_dir),
36  m_schema(schema) {}
37 
38  /// Build the full schema for a Trace plug-in.
39  ///
40  /// \param[in] plugin_schema
41  /// The subschema that corresponds to the "trace" section of the schema.
42  ///
43  /// \return
44  /// The full schema containing the common attributes and the plug-in
45  /// specific attributes.
46  static std::string BuildSchema(llvm::StringRef plugin_schema);
47 
48  /// Parse the fields common to all trace session schemas.
49  ///
50  /// \param[in] session
51  /// The session json objects already deserialized.
52  ///
53  /// \return
54  /// A list of \a ParsedProcess containing all threads and targets created
55  /// during the parsing, or an error in case of failures. In case of
56  /// errors, no side effects are produced.
57  llvm::Expected<std::vector<ParsedProcess>>
59 
60 protected:
61  /// Resolve non-absolute paths relative to the session file folder. It
62  /// modifies the given file_spec.
63  void NormalizePath(lldb_private::FileSpec &file_spec);
64 
65  lldb::ThreadPostMortemTraceSP ParseThread(lldb::ProcessSP &process_sp,
66  const JSONThread &thread);
67 
68  llvm::Expected<ParsedProcess> ParseProcess(const JSONProcess &process);
69 
70  llvm::Error ParseModule(lldb::TargetSP &target_sp, const JSONModule &module);
71 
72  /// Create a user-friendly error message upon a JSON-parsing failure using the
73  /// \a json::ObjectMapper functionality.
74  ///
75  /// \param[in] root
76  /// The \a llvm::json::Path::Root used to parse the JSON \a value.
77  ///
78  /// \param[in] value
79  /// The json value that failed to parse.
80  ///
81  /// \return
82  /// An \a llvm::Error containing the user-friendly error message.
83  llvm::Error CreateJSONError(llvm::json::Path::Root &root,
84  const llvm::json::Value &value);
85 
88  llvm::StringRef m_schema;
89 };
90 } // namespace lldb_private
91 
92 
93 #endif // LLDB_TARGET_TRACESESSIONPARSER_H
lldb_private::TraceSessionFileParser::ParsedProcess::target_sp
lldb::TargetSP target_sp
Definition: TraceSessionFileParser.h:29
ThreadPostMortemTrace.h
lldb_private::JSONThread
Definition: TraceJSONStructs.h:28
lldb_private::TraceSessionFileParser::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: TraceSessionFileParser.cpp:57
lldb_private::TraceSessionFileParser::m_session_file_dir
std::string m_session_file_dir
Definition: TraceSessionFileParser.h:87
lldb_private::TraceSessionFileParser::ParseProcess
llvm::Expected< ParsedProcess > ParseProcess(const JSONProcess &process)
Definition: TraceSessionFileParser.cpp:90
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::TraceSessionFileParser::TraceSessionFileParser
TraceSessionFileParser(Debugger &debugger, llvm::StringRef session_file_dir, llvm::StringRef schema)
Definition: TraceSessionFileParser.h:33
lldb_private::TraceSessionFileParser::ParsedProcess::threads
std::vector< lldb::ThreadPostMortemTraceSP > threads
Definition: TraceSessionFileParser.h:30
lldb_private::TraceSessionFileParser::ParseCommonSessionFile
llvm::Expected< std::vector< ParsedProcess > > ParseCommonSessionFile(const JSONTraceSessionBase &session)
Parse the fields common to all trace session schemas.
Definition: TraceSessionFileParser.cpp:129
lldb_private::TraceSessionFileParser::ParseModule
llvm::Error ParseModule(lldb::TargetSP &target_sp, const JSONModule &module)
Definition: TraceSessionFileParser.cpp:28
lldb_private::TraceSessionFileParser::m_schema
llvm::StringRef m_schema
Definition: TraceSessionFileParser.h:88
lldb_private::Debugger
Definition: Debugger.h:70
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::JSONTraceSessionBase
Definition: TraceJSONStructs.h:44
lldb_private::TraceSessionFileParser::BuildSchema
static std::string BuildSchema(llvm::StringRef plugin_schema)
Build the full schema for a Trace plug-in.
Definition: TraceSessionFileParser.cpp:67
lldb_private::TraceSessionFileParser::ParseThread
lldb::ThreadPostMortemTraceSP ParseThread(lldb::ProcessSP &process_sp, const JSONThread &thread)
Definition: TraceSessionFileParser.cpp:76
lldb_private::TraceSessionFileParser::NormalizePath
void NormalizePath(lldb_private::FileSpec &file_spec)
Resolve non-absolute paths relative to the session file folder.
Definition: TraceSessionFileParser.cpp:23
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::JSONModule
Definition: TraceJSONStructs.h:21
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
lldb_private::TraceSessionFileParser
Definition: TraceSessionFileParser.h:24
lldb_private::TraceSessionFileParser::m_debugger
Debugger & m_debugger
Definition: TraceSessionFileParser.h:86
TraceJSONStructs.h
lldb_private::JSONProcess
Definition: TraceJSONStructs.h:33
lldb_private::TraceSessionFileParser::ParsedProcess
Helper struct holding the objects created when parsing a process.
Definition: TraceSessionFileParser.h:28