1 //===-- IntelPTCollector.h ------------------------------------ -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_IntelPTCollector_H_
10 #define liblldb_IntelPTCollector_H_
12 #include "IntelPTMultiCoreTrace.h"
13 #include "IntelPTPerThreadProcessTrace.h"
14 #include "IntelPTSingleBufferTrace.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>
24 namespace lldb_private
{
26 namespace process_linux
{
28 /// Main class that manages intel-pt process and thread tracing.
29 class IntelPTCollector
{
31 /// \param[in] process
32 /// Process to be traced.
33 IntelPTCollector(NativeProcessProtocol
&process
);
35 static bool IsSupported();
37 /// To be invoked as soon as we know the process stopped.
38 void ProcessDidStop();
40 /// To be invoked before the process will resume, so that we can capture the
41 /// first instructions after the resume.
42 void ProcessWillResume();
44 /// If "process tracing" is enabled, then trace the given thread.
45 llvm::Error
OnThreadCreated(lldb::tid_t tid
);
47 /// Stops tracing a tracing upon a destroy event.
48 llvm::Error
OnThreadDestroyed(lldb::tid_t tid
);
50 /// Implementation of the jLLDBTraceStop packet
51 llvm::Error
TraceStop(const TraceStopRequest
&request
);
53 /// Implementation of the jLLDBTraceStart packet
54 llvm::Error
TraceStart(const TraceIntelPTStartRequest
&request
);
56 /// Implementation of the jLLDBTraceGetState packet
57 llvm::Expected
<llvm::json::Value
> GetState();
59 /// Implementation of the jLLDBTraceGetBinaryData packet
60 llvm::Expected
<std::vector
<uint8_t>>
61 GetBinaryData(const TraceGetBinaryDataRequest
&request
);
63 /// Dispose of all traces
67 llvm::Error
TraceStop(lldb::tid_t tid
);
69 /// Start tracing a specific thread.
70 llvm::Error
TraceStart(lldb::tid_t tid
,
71 const TraceIntelPTStartRequest
&request
);
74 /// The conversion object between TSC and wall time.
75 llvm::Expected
<LinuxPerfZeroTscConversion
&>
76 FetchPerfTscConversionParameters();
78 /// The target process.
79 NativeProcessProtocol
&m_process
;
80 /// Threads traced due to "thread tracing"
81 IntelPTThreadTraceCollection m_thread_traces
;
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
;
88 } // namespace process_linux
89 } // namespace lldb_private
91 #endif // liblldb_IntelPTCollector_H_