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
9#include "IntelPTPerThreadProcessTrace.h"
10#include <optional>
11
12using namespace lldb;
13using namespace lldb_private;
14using namespace process_linux;
15using namespace llvm;
16
17bool IntelPTPerThreadProcessTrace::TracesThread(lldb::tid_t tid) const {
18 return m_thread_traces.TracesThread(tid);
19}
20
21Error IntelPTPerThreadProcessTrace::TraceStop(lldb::tid_t tid) {
22 return m_thread_traces.TraceStop(tid);
23}
24
25Error IntelPTPerThreadProcessTrace::TraceStart(lldb::tid_t tid) {
26 if (m_thread_traces.GetTotalBufferSize() + m_tracing_params.ipt_trace_size >
27 static_cast<size_t>(*m_tracing_params.process_buffer_size_limit))
28 return createStringError(
29 EC: inconvertibleErrorCode(),
30 Fmt: "Thread %" PRIu64 " can't be traced as the process trace size limit "
31 "has been reached. Consider retracing with a higher "
32 "limit.",
33 Vals: tid);
34
35 return m_thread_traces.TraceStart(tid, request: m_tracing_params);
36}
37
38TraceIntelPTGetStateResponse IntelPTPerThreadProcessTrace::GetState() {
39 TraceIntelPTGetStateResponse state;
40 m_thread_traces.ForEachThread(
41 callback: [&](lldb::tid_t tid, const IntelPTSingleBufferTrace &thread_trace) {
42 state.traced_threads.push_back(
43 x: {.tid: tid,
44 .binary_data: {{.kind: IntelPTDataKinds::kIptTrace, .size: thread_trace.GetIptTraceSize()}}});
45 });
46 return state;
47}
48
49Expected<std::optional<std::vector<uint8_t>>>
50IntelPTPerThreadProcessTrace::TryGetBinaryData(
51 const TraceGetBinaryDataRequest &request) {
52 return m_thread_traces.TryGetBinaryData(request);
53}
54
55Expected<std::unique_ptr<IntelPTPerThreadProcessTrace>>
56IntelPTPerThreadProcessTrace::Start(const TraceIntelPTStartRequest &request,
57 ArrayRef<lldb::tid_t> current_tids) {
58 std::unique_ptr<IntelPTPerThreadProcessTrace> trace(
59 new IntelPTPerThreadProcessTrace(request));
60
61 Error error = Error::success();
62 for (lldb::tid_t tid : current_tids)
63 error = joinErrors(E1: std::move(error), E2: trace->TraceStart(tid));
64 if (error)
65 return std::move(error);
66 return std::move(trace);
67}
68

source code of lldb/source/Plugins/Process/Linux/IntelPTPerThreadProcessTrace.cpp