1 //===-- TraceIntelPT.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 9 #include "TraceIntelPT.h" 10 11 #include "TraceIntelPTSessionFileParser.h" 12 #include "lldb/Core/PluginManager.h" 13 #include "lldb/Target/Process.h" 14 #include "lldb/Target/Target.h" 15 #include "lldb/Target/ThreadTrace.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 using namespace lldb_private::trace_intel_pt; 20 using namespace llvm; 21 22 LLDB_PLUGIN_DEFINE(TraceIntelPT) 23 24 void TraceIntelPT::Initialize() { 25 PluginManager::RegisterPlugin(GetPluginNameStatic(), "Intel Processor Trace", 26 CreateInstance, 27 TraceIntelPTSessionFileParser::GetSchema()); 28 } 29 30 void TraceIntelPT::Terminate() { 31 PluginManager::UnregisterPlugin(CreateInstance); 32 } 33 34 ConstString TraceIntelPT::GetPluginNameStatic() { 35 static ConstString g_name("intel-pt"); 36 return g_name; 37 } 38 39 StringRef TraceIntelPT::GetSchema() { 40 return TraceIntelPTSessionFileParser::GetSchema(); 41 } 42 43 //------------------------------------------------------------------ 44 // PluginInterface protocol 45 //------------------------------------------------------------------ 46 47 ConstString TraceIntelPT::GetPluginName() { return GetPluginNameStatic(); } 48 49 uint32_t TraceIntelPT::GetPluginVersion() { return 1; } 50 51 void TraceIntelPT::Dump(Stream *s) const {} 52 53 Expected<TraceSP> 54 TraceIntelPT::CreateInstance(const json::Value &trace_session_file, 55 StringRef session_file_dir, Debugger &debugger) { 56 return TraceIntelPTSessionFileParser(debugger, trace_session_file, 57 session_file_dir) 58 .Parse(); 59 } 60 61 TraceIntelPT::TraceIntelPT( 62 const pt_cpu &pt_cpu, 63 const std::vector<std::shared_ptr<ThreadTrace>> &traced_threads) 64 : m_pt_cpu(pt_cpu) { 65 for (const std::shared_ptr<ThreadTrace> &thread : traced_threads) 66 m_trace_threads.emplace( 67 std::make_pair(thread->GetProcess()->GetID(), thread->GetID()), thread); 68 } 69