LLDB  mainline
TraceIntelPTSessionFileParser.cpp
Go to the documentation of this file.
1 //===-- TraceIntelPTSessionFileParser.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 
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Target/Process.h"
13 #include "lldb/Target/Target.h"
14 #include "lldb/Target/ThreadList.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 using namespace lldb_private::trace_intel_pt;
21 using namespace llvm;
22 
23 StringRef TraceIntelPTSessionFileParser::GetSchema() {
24  static std::string schema;
25  if (schema.empty()) {
26  schema = TraceSessionFileParser::BuildSchema(R"({
27  "type": "intel-pt",
28  "cpuInfo": {
29  "vendor": "intel" | "unknown",
30  "family": integer,
31  "model": integer,
32  "stepping": integer
33  }
34  })");
35  }
36  return schema;
37 }
38 
39 pt_cpu TraceIntelPTSessionFileParser::ParsePTCPU(
40  const JSONTraceIntelPTCPUInfo &cpu_info) {
41  return {cpu_info.vendor.compare("intel") == 0 ? pcv_intel : pcv_unknown,
42  static_cast<uint16_t>(cpu_info.family),
43  static_cast<uint8_t>(cpu_info.model),
44  static_cast<uint8_t>(cpu_info.stepping)};
45 }
46 
47 TraceSP TraceIntelPTSessionFileParser::CreateTraceIntelPTInstance(
48  const pt_cpu &cpu_info, std::vector<ParsedProcess> &parsed_processes) {
49  std::vector<ThreadPostMortemTraceSP> threads;
50  for (const ParsedProcess &parsed_process : parsed_processes)
51  threads.insert(threads.end(), parsed_process.threads.begin(),
52  parsed_process.threads.end());
53 
54  TraceSP trace_instance(new TraceIntelPT(cpu_info, threads));
55  for (const ParsedProcess &parsed_process : parsed_processes)
56  parsed_process.target_sp->SetTrace(trace_instance);
57 
58  return trace_instance;
59 }
60 
61 Expected<TraceSP> TraceIntelPTSessionFileParser::Parse() {
62  json::Path::Root root("traceSession");
64  if (!json::fromJSON(m_trace_session_file, session, root))
65  return CreateJSONError(root, m_trace_session_file);
66 
67  if (Expected<std::vector<ParsedProcess>> parsed_processes =
68  ParseCommonSessionFile(session))
69  return CreateTraceIntelPTInstance(ParsePTCPU(session.trace.cpuInfo),
70  *parsed_processes);
71  else
72  return parsed_processes.takeError();
73 }
74 
75 namespace llvm {
76 namespace json {
77 
78 bool fromJSON(
79  const Value &value,
81  Path path) {
82  ObjectMapper o(value, path);
83  return o && o.map("cpuInfo", plugin_settings.cpuInfo) &&
84  fromJSON(
85  value,
87  path);
88 }
89 
90 bool fromJSON(const json::Value &value,
92  Path path) {
93  ObjectMapper o(value, path);
94  return o && o.map("vendor", cpu_info.vendor) &&
95  o.map("family", cpu_info.family) && o.map("model", cpu_info.model) &&
96  o.map("stepping", cpu_info.stepping);
97 }
98 
101  return Value(Object{{"family", cpu_info.family},
102  {"model", cpu_info.model},
103  {"stepping", cpu_info.stepping},
104  {"vendor", cpu_info.vendor}});
105 }
106 
107 } // namespace json
108 } // namespace llvm
llvm
Definition: Debugger.h:49
lldb_private::trace_intel_pt::TraceIntelPTSessionFileParser::JSONTraceIntelPTCPUInfo::stepping
int64_t stepping
Definition: TraceIntelPTSessionFileParser.h:25
lldb_private::TraceSessionFileParser::JSONTraceSession::trace
TPluginSettings trace
Definition: TraceSessionFileParser.h:64
TraceIntelPTSessionFileParser.h
lldb_private::trace_intel_pt::TraceIntelPTSessionFileParser::JSONTraceIntelPTCPUInfo::model
int64_t model
Definition: TraceIntelPTSessionFileParser.h:24
lldb_private::Value
Definition: Value.h:38
lldb_private::TraceSessionFileParser::JSONTraceSession
The trace plug-in implementation should provide its own TPluginSettings, which corresponds to the "tr...
Definition: TraceSessionFileParser.h:63
ThreadPostMortemTrace.h
lldb_private::trace_intel_pt::TraceIntelPTSessionFileParser::JSONTraceIntelPTCPUInfo::vendor
std::string vendor
Definition: TraceIntelPTSessionFileParser.h:26
lldb_private::trace_intel_pt::TraceIntelPT
Definition: TraceIntelPT.h:18
lldb_private::trace_intel_pt::TraceIntelPTSessionFileParser::JSONTraceIntelPTSettings
Definition: TraceIntelPTSessionFileParser.h:29
Debugger.h
Process.h
lldb_private::trace_intel_pt::TraceIntelPTSessionFileParser::JSONTraceIntelPTSettings::cpuInfo
JSONTraceIntelPTCPUInfo cpuInfo
Definition: TraceIntelPTSessionFileParser.h:31
Target.h
ThreadList.h
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
lldb_private::trace_intel_pt::TraceIntelPTSessionFileParser::JSONTraceIntelPTCPUInfo
Definition: TraceIntelPTSessionFileParser.h:22
llvm::json::toJSON
Value toJSON(const TraceIntelPTSessionFileParser::JSONTraceIntelPTCPUInfo &cpu_info)
Definition: TraceIntelPTSessionFileParser.cpp:99
llvm::json::fromJSON
bool fromJSON(const json::Value &value, TraceIntelPTSessionFileParser::JSONTraceIntelPTCPUInfo &cpu_info, Path path)
Definition: TraceIntelPTSessionFileParser.cpp:90
lldb_private::trace_intel_pt::TraceIntelPTSessionFileParser::JSONTraceIntelPTCPUInfo::family
int64_t family
Definition: TraceIntelPTSessionFileParser.h:23
uint16_t
lldb_private::TraceSessionFileParser::JSONTracePluginSettings
Definition: TraceSessionFileParser.h:52
TraceOptions.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::trace_intel_pt
Definition: CommandObjectTraceStartIntelPT.h:18
lldb
Definition: SBAddress.h:15
lldb_private::TraceSessionFileParser::ParsedProcess
Helper struct holding the objects created when parsing a process.
Definition: TraceSessionFileParser.h:69