92 lines · c
1//===-- IntelPTCollector.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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef liblldb_IntelPTCollector_H_10#define liblldb_IntelPTCollector_H_11 12#include "IntelPTMultiCoreTrace.h"13#include "IntelPTPerThreadProcessTrace.h"14#include "IntelPTSingleBufferTrace.h"15#include "Perf.h"16#include "lldb/Host/common/NativeProcessProtocol.h"17#include "lldb/Utility/Status.h"18#include "lldb/Utility/TraceIntelPTGDBRemotePackets.h"19#include "lldb/lldb-types.h"20#include <linux/perf_event.h>21#include <sys/mman.h>22#include <unistd.h>23 24namespace lldb_private {25 26namespace process_linux {27 28/// Main class that manages intel-pt process and thread tracing.29class IntelPTCollector {30public:31 /// \param[in] process32 /// Process to be traced.33 IntelPTCollector(NativeProcessProtocol &process);34 35 static bool IsSupported();36 37 /// To be invoked as soon as we know the process stopped.38 void ProcessDidStop();39 40 /// To be invoked before the process will resume, so that we can capture the41 /// first instructions after the resume.42 void ProcessWillResume();43 44 /// If "process tracing" is enabled, then trace the given thread.45 llvm::Error OnThreadCreated(lldb::tid_t tid);46 47 /// Stops tracing a tracing upon a destroy event.48 llvm::Error OnThreadDestroyed(lldb::tid_t tid);49 50 /// Implementation of the jLLDBTraceStop packet51 llvm::Error TraceStop(const TraceStopRequest &request);52 53 /// Implementation of the jLLDBTraceStart packet54 llvm::Error TraceStart(const TraceIntelPTStartRequest &request);55 56 /// Implementation of the jLLDBTraceGetState packet57 llvm::Expected<llvm::json::Value> GetState();58 59 /// Implementation of the jLLDBTraceGetBinaryData packet60 llvm::Expected<std::vector<uint8_t>>61 GetBinaryData(const TraceGetBinaryDataRequest &request);62 63 /// Dispose of all traces64 void Clear();65 66private:67 llvm::Error TraceStop(lldb::tid_t tid);68 69 /// Start tracing a specific thread.70 llvm::Error TraceStart(lldb::tid_t tid,71 const TraceIntelPTStartRequest &request);72 73 /// \return74 /// The conversion object between TSC and wall time.75 llvm::Expected<LinuxPerfZeroTscConversion &>76 FetchPerfTscConversionParameters();77 78 /// The target process.79 NativeProcessProtocol &m_process;80 /// Threads traced due to "thread tracing"81 IntelPTThreadTraceCollection m_thread_traces;82 83 /// Only one instance of "process trace" can be active at a given time.84 /// It might be \b nullptr.85 IntelPTProcessTraceUP m_process_trace_up;86};87 88} // namespace process_linux89} // namespace lldb_private90 91#endif // liblldb_IntelPTCollector_H_92