Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.h
39645 views
//===-- TraceIntelPTBundleLoader.h ----------------------------*- C++ //-*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTBUNDLELOADER_H9#define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTBUNDLELOADER_H1011#include "../common/ThreadPostMortemTrace.h"12#include "TraceIntelPTJSONStructs.h"1314namespace lldb_private {15namespace trace_intel_pt {1617class TraceIntelPT;1819class TraceIntelPTBundleLoader {20public:21/// Helper struct holding the objects created when parsing a process22struct ParsedProcess {23lldb::TargetSP target_sp;24std::vector<lldb::ThreadPostMortemTraceSP> threads;25};2627/// \param[in] debugger28/// The debugger that will own the targets to create.29///30/// \param[in] bundle_description31/// The JSON description of a trace bundle that follows the schema of the32/// intel pt trace plug-in.33///34/// \param[in] bundle_dir35/// The folder where the trace bundle is located.36TraceIntelPTBundleLoader(Debugger &debugger,37const llvm::json::Value &bundle_description,38llvm::StringRef bundle_dir)39: m_debugger(debugger), m_bundle_description(bundle_description),40m_bundle_dir(bundle_dir) {}4142/// \return43/// The JSON schema for the bundle description.44static llvm::StringRef GetSchema();4546/// Parse the trace bundle description and create the corresponding \a47/// Target objects. In case of an error, no targets are created.48///49/// \return50/// A \a lldb::TraceSP instance created according to the trace bundle51/// information. In case of errors, return a null pointer.52llvm::Expected<lldb::TraceSP> Load();5354private:55/// Resolve non-absolute paths relative to the bundle folder.56FileSpec NormalizePath(const std::string &path);5758/// Create a post-mortem thread associated with the given \p process59/// using the definition from \p thread.60lldb::ThreadPostMortemTraceSP ParseThread(Process &process,61const JSONThread &thread);6263/// Given a bundle description and a list of fully parsed processes,64/// create an actual Trace instance that "traces" these processes.65llvm::Expected<lldb::TraceSP>66CreateTraceIntelPTInstance(JSONTraceBundleDescription &bundle_description,67std::vector<ParsedProcess> &parsed_processes);6869/// Create an empty Process object with given pid and target.70llvm::Expected<ParsedProcess> CreateEmptyProcess(lldb::pid_t pid,71llvm::StringRef triple);7273/// Create the corresponding Threads and Process objects given the JSON74/// process definition.75///76/// \param[in] process77/// The JSON process definition78llvm::Expected<ParsedProcess> ParseProcess(const JSONProcess &process);7980/// Create a module associated with the given \p target using the definition81/// from \p module.82llvm::Error ParseModule(Target &target, const JSONModule &module);8384/// Create a kernel process and cpu threads given the JSON kernel definition.85llvm::Expected<ParsedProcess>86ParseKernel(const JSONTraceBundleDescription &bundle_description);8788/// Create a user-friendly error message upon a JSON-parsing failure using the89/// \a json::ObjectMapper functionality.90///91/// \param[in] root92/// The \a llvm::json::Path::Root used to parse the JSON \a value.93///94/// \param[in] value95/// The json value that failed to parse.96///97/// \return98/// An \a llvm::Error containing the user-friendly error message.99llvm::Error CreateJSONError(llvm::json::Path::Root &root,100const llvm::json::Value &value);101102/// Create the corresponding Process, Thread and Module objects given this103/// bundle description.104llvm::Expected<std::vector<ParsedProcess>>105LoadBundle(const JSONTraceBundleDescription &bundle_description);106107/// When applicable, augment the list of threads in the trace bundle by108/// inspecting the context switch trace. This only applies for threads of109/// processes already specified in this bundle description.110///111/// \return112/// An \a llvm::Error in case if failures, or \a llvm::Error::success113/// otherwise.114llvm::Error AugmentThreadsFromContextSwitches(115JSONTraceBundleDescription &bundle_description);116117/// Modifiy the bundle description by normalizing all the paths relative to118/// the session file directory.119void NormalizeAllPaths(JSONTraceBundleDescription &bundle_description);120121Debugger &m_debugger;122const llvm::json::Value &m_bundle_description;123const std::string m_bundle_dir;124};125126} // namespace trace_intel_pt127} // namespace lldb_private128129#endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTBUNDLELOADER_H130131132