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#include <optional>
11
12using namespace lldb;
13using namespace lldb_private;
14using namespace process_linux;
15using namespace llvm;
16
18 return m_thread_traces.TracesThread(tid);
19}
20
22 return m_thread_traces.TraceStop(tid);
23}
24
27 static_cast<size_t>(*m_tracing_params.process_buffer_size_limit))
28 return createStringError(
29 inconvertibleErrorCode(),
30 "Thread %" PRIu64 " can't be traced as the process trace size limit "
31 "has been reached. Consider retracing with a higher "
32 "limit.",
33 tid);
34
36}
37
41 [&](lldb::tid_t tid, const IntelPTSingleBufferTrace &thread_trace) {
42 state.traced_threads.push_back(
43 {tid,
44 {{IntelPTDataKinds::kIptTrace, thread_trace.GetIptTraceSize()}}});
45 });
46 return state;
47}
48
49Expected<std::optional<std::vector<uint8_t>>>
51 const TraceGetBinaryDataRequest &request) {
52 return m_thread_traces.TryGetBinaryData(request);
53}
54
55Expected<std::unique_ptr<IntelPTPerThreadProcessTrace>>
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(std::move(error), trace->TraceStart(tid));
64 if (error)
65 return std::move(error);
66 return std::move(trace);
67}
static llvm::raw_ostream & error(Stream &strm)
llvm::Error Error
Manages a "process trace" instance by tracing each thread individually.
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.
This class wraps a single perf event collecting intel pt data in a single buffer.
llvm::Error TraceStop(lldb::tid_t tid)
Stop tracing the thread given by its tid.
llvm::Error TraceStart(lldb::tid_t tid, const TraceIntelPTStartRequest &request)
Start tracing the thread given by its tid.
llvm::Expected< std::optional< std::vector< uint8_t > > > TryGetBinaryData(const TraceGetBinaryDataRequest &request)
void ForEachThread(std::function< void(lldb::tid_t tid, IntelPTSingleBufferTrace &thread_trace)> callback)
Execute the provided callback on each thread that is being traced.
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
uint64_t tid_t
Definition: lldb-types.h:82
Definition: Debugger.h:53
jLLDBTraceGetBinaryData gdb-remote packet
std::vector< TraceThreadState > traced_threads
std::optional< uint64_t > process_buffer_size_limit
Required when doing "process tracing".
uint64_t ipt_trace_size
Size in bytes to use for each thread's trace buffer.