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 
11 using namespace lldb;
12 using namespace lldb_private;
13 using namespace process_linux;
14 using namespace llvm;
15 
16 bool IntelPTPerThreadProcessTrace::TracesThread(lldb::tid_t tid) const {
17  return m_thread_traces.TracesThread(tid);
18 }
19 
20 Error IntelPTPerThreadProcessTrace::TraceStop(lldb::tid_t tid) {
21  return m_thread_traces.TraceStop(tid);
22 }
23 
24 Error IntelPTPerThreadProcessTrace::TraceStart(lldb::tid_t tid) {
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 
37 TraceIntelPTGetStateResponse IntelPTPerThreadProcessTrace::GetState() {
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 
48 Expected<llvm::Optional<std::vector<uint8_t>>>
49 IntelPTPerThreadProcessTrace::TryGetBinaryData(
50  const TraceGetBinaryDataRequest &request) {
51  return m_thread_traces.TryGetBinaryData(request);
52 }
53 
54 Expected<std::unique_ptr<IntelPTPerThreadProcessTrace>>
55 IntelPTPerThreadProcessTrace::Start(const TraceIntelPTStartRequest &request,
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 }
lldb_private::TraceGetStateResponse::traced_threads
std::vector< TraceThreadState > traced_threads
Definition: TraceGDBRemotePackets.h:133
llvm
Definition: Debugger.h:50
lldb_private::TraceGetBinaryDataRequest
jLLDBTraceGetBinaryData gdb-remote packet
Definition: TraceGDBRemotePackets.h:149
lldb_private::TraceIntelPTGetStateResponse
Definition: TraceIntelPTGDBRemotePackets.h:111
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::process_linux::IntelPTSingleBufferTrace::GetIptTraceSize
size_t GetIptTraceSize() const
Definition: IntelPTSingleBufferTrace.cpp:204
lldb_private::process_linux::IntelPTSingleBufferTrace
This class wraps a single perf event collecting intel pt data in a single buffer.
Definition: IntelPTSingleBufferTrace.h:28
lldb_private::TraceIntelPTStartRequest
jLLDBTraceStart gdb-remote packet
Definition: TraceIntelPTGDBRemotePackets.h:33
lldb_private::process_linux::IntelPTPerThreadProcessTrace
Manages a "process trace" instance by tracing each thread individually.
Definition: IntelPTPerThreadProcessTrace.h:20
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
lldb
Definition: SBAddress.h:15
IntelPTPerThreadProcessTrace.h
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86