LLDB mainline
IntelPTPerThreadProcessTrace.cpp
Go to the documentation of this file.
1//===-- IntelPTPerThreadProcessTrace.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
11using namespace lldb;
12using namespace lldb_private;
13using namespace process_linux;
14using namespace llvm;
15
17 return m_thread_traces.TracesThread(tid);
18}
19
21 return m_thread_traces.TraceStop(tid);
22}
23
25 if (m_thread_traces.GetTotalBufferSize() + m_tracing_params.ipt_trace_size >
26 static_cast<size_t>(*m_tracing_params.process_buffer_size_limit))
27 return createStringError(
28 inconvertibleErrorCode(),
29 "Thread %" PRIu64 " can't be traced as the process trace size limit "
30 "has been reached. Consider retracing with a higher "
31 "limit.",
32 tid);
33
34 return m_thread_traces.TraceStart(tid, m_tracing_params);
35}
36
39 m_thread_traces.ForEachThread(
40 [&](lldb::tid_t tid, const IntelPTSingleBufferTrace &thread_trace) {
41 state.traced_threads.push_back(
42 {tid,
43 {{IntelPTDataKinds::kIptTrace, thread_trace.GetIptTraceSize()}}});
44 });
45 return state;
46}
47
48Expected<std::optional<std::vector<uint8_t>>>
50 const TraceGetBinaryDataRequest &request) {
51 return m_thread_traces.TryGetBinaryData(request);
52}
53
54Expected<std::unique_ptr<IntelPTPerThreadProcessTrace>>
56 ArrayRef<lldb::tid_t> current_tids) {
57 std::unique_ptr<IntelPTPerThreadProcessTrace> trace(
58 new IntelPTPerThreadProcessTrace(request));
59
60 Error error = Error::success();
61 for (lldb::tid_t tid : current_tids)
62 error = joinErrors(std::move(error), trace->TraceStart(tid));
63 if (error)
64 return std::move(error);
65 return std::move(trace);
66}
static llvm::raw_ostream & error(Stream &strm)
llvm::Error TraceStart(lldb::tid_t tid) override
Start tracing the thread given by its tid.
TraceIntelPTGetStateResponse GetState() override
Construct a minimal jLLDBTraceGetState response for this process trace.
TraceIntelPTStartRequest m_tracing_params
Params used to trace threads when the user started "process tracing".
llvm::Expected< std::optional< std::vector< uint8_t > > > TryGetBinaryData(const TraceGetBinaryDataRequest &request) override
llvm::Error TraceStop(lldb::tid_t tid) override
Stop tracing the thread given by its tid.
static llvm::Expected< std::unique_ptr< IntelPTPerThreadProcessTrace > > Start(const TraceIntelPTStartRequest &request, llvm::ArrayRef< lldb::tid_t > current_tids)
Start tracing the current process by tracing each of its tids individually.
IntelPTPerThreadProcessTrace(const TraceIntelPTStartRequest &request)
This class wraps a single perf event collecting intel pt data in a single buffer.
A class that represents a running process on the host machine.
uint64_t tid_t
Definition lldb-types.h:85
jLLDBTraceGetBinaryData gdb-remote packet
std::vector< TraceThreadState > traced_threads