LLDB mainline
IntelPTCollector.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_IntelPTCollector_H_
10#define liblldb_IntelPTCollector_H_
11
17#include "lldb/Utility/Status.h"
19#include "lldb/lldb-types.h"
20
21#include <linux/perf_event.h>
22#include <sys/mman.h>
23#include <unistd.h>
24
25namespace lldb_private {
26
27namespace process_linux {
28
29/// Main class that manages intel-pt process and thread tracing.
31public:
32 /// \param[in] process
33 /// Process to be traced.
35
36 static bool IsSupported();
37
38 /// To be invoked as soon as we know the process stopped.
39 void ProcessDidStop();
40
41 /// To be invoked before the process will resume, so that we can capture the
42 /// first instructions after the resume.
43 void ProcessWillResume();
44
45 /// If "process tracing" is enabled, then trace the given thread.
46 llvm::Error OnThreadCreated(lldb::tid_t tid);
47
48 /// Stops tracing a tracing upon a destroy event.
49 llvm::Error OnThreadDestroyed(lldb::tid_t tid);
50
51 /// Implementation of the jLLDBTraceStop packet
52 llvm::Error TraceStop(const TraceStopRequest &request);
53
54 /// Implementation of the jLLDBTraceStart packet
55 llvm::Error TraceStart(const TraceIntelPTStartRequest &request);
56
57 /// Implementation of the jLLDBTraceGetState packet
58 llvm::Expected<llvm::json::Value> GetState();
59
60 /// Implementation of the jLLDBTraceGetBinaryData packet
61 llvm::Expected<std::vector<uint8_t>>
63
64 /// Dispose of all traces
65 void Clear();
66
67private:
68 llvm::Error TraceStop(lldb::tid_t tid);
69
70 /// Start tracing a specific thread.
71 llvm::Error TraceStart(lldb::tid_t tid,
72 const TraceIntelPTStartRequest &request);
73
74 /// \return
75 /// The conversion object between TSC and wall time.
76 llvm::Expected<LinuxPerfZeroTscConversion &>
78
79 /// The target process.
81 /// Threads traced due to "thread tracing"
83
84 /// Only one instance of "process trace" can be active at a given time.
85 /// It might be \b nullptr.
87};
88
89} // namespace process_linux
90} // namespace lldb_private
91
92#endif // liblldb_IntelPTCollector_H_
This file contains a thin wrapper of the perf_event_open API and classes to handle the destruction of...
llvm::Expected< LinuxPerfZeroTscConversion & > FetchPerfTscConversionParameters()
llvm::Expected< std::vector< uint8_t > > GetBinaryData(const TraceGetBinaryDataRequest &request)
Implementation of the jLLDBTraceGetBinaryData packet.
llvm::Error TraceStart(lldb::tid_t tid, const TraceIntelPTStartRequest &request)
Start tracing a specific thread.
llvm::Error TraceStop(const TraceStopRequest &request)
Implementation of the jLLDBTraceStop packet.
IntelPTProcessTraceUP m_process_trace_up
Only one instance of "process trace" can be active at a given time.
NativeProcessProtocol & m_process
The target process.
llvm::Error TraceStart(const TraceIntelPTStartRequest &request)
Implementation of the jLLDBTraceStart packet.
IntelPTThreadTraceCollection m_thread_traces
Threads traced due to "thread tracing".
llvm::Error OnThreadCreated(lldb::tid_t tid)
If "process tracing" is enabled, then trace the given thread.
IntelPTCollector(NativeProcessProtocol &process)
llvm::Error OnThreadDestroyed(lldb::tid_t tid)
Stops tracing a tracing upon a destroy event.
llvm::Expected< llvm::json::Value > GetState()
Implementation of the jLLDBTraceGetState packet.
void ProcessWillResume()
To be invoked before the process will resume, so that we can capture the first instructions after the...
void ProcessDidStop()
To be invoked as soon as we know the process stopped.
std::unique_ptr< IntelPTProcessTrace > IntelPTProcessTraceUP
A class that represents a running process on the host machine.
uint64_t tid_t
Definition lldb-types.h:85
jLLDBTraceGetBinaryData gdb-remote packet
jLLDBTraceStop gdb-remote packet