LLDB  mainline
SBTrace.cpp
Go to the documentation of this file.
1 //===-- SBTrace.cpp ---------------------------------------------*- 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 #include "SBReproducerPrivate.h"
10 #include "lldb/Target/Process.h"
11 
12 #include "lldb/API/SBTrace.h"
14 
15 #include <memory>
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 class TraceImpl {
21 public:
23 };
24 
25 lldb::ProcessSP SBTrace::GetSP() const { return m_opaque_wp.lock(); }
26 
27 size_t SBTrace::GetTraceData(SBError &error, void *buf, size_t size,
28  size_t offset, lldb::tid_t thread_id) {
29  LLDB_RECORD_DUMMY(size_t, SBTrace, GetTraceData,
30  (lldb::SBError &, void *, size_t, size_t, lldb::tid_t),
31  error, buf, size, offset, thread_id);
32 
33  ProcessSP process_sp(GetSP());
34  llvm::MutableArrayRef<uint8_t> buffer(static_cast<uint8_t *>(buf), size);
35  error.Clear();
36 
37  if (!process_sp) {
38  error.SetErrorString("invalid process");
39  } else {
40  error.SetError(
41  process_sp->GetData(GetTraceUID(), thread_id, buffer, offset));
42  }
43  return buffer.size();
44 }
45 
46 size_t SBTrace::GetMetaData(SBError &error, void *buf, size_t size,
47  size_t offset, lldb::tid_t thread_id) {
48  LLDB_RECORD_DUMMY(size_t, SBTrace, GetMetaData,
49  (lldb::SBError &, void *, size_t, size_t, lldb::tid_t),
50  error, buf, size, offset, thread_id);
51 
52  ProcessSP process_sp(GetSP());
53  llvm::MutableArrayRef<uint8_t> buffer(static_cast<uint8_t *>(buf), size);
54  error.Clear();
55 
56  if (!process_sp) {
57  error.SetErrorString("invalid process");
58  } else {
59  error.SetError(
60  process_sp->GetMetaData(GetTraceUID(), thread_id, buffer, offset));
61  }
62  return buffer.size();
63 }
64 
65 void SBTrace::StopTrace(SBError &error, lldb::tid_t thread_id) {
66  LLDB_RECORD_METHOD(void, SBTrace, StopTrace, (lldb::SBError &, lldb::tid_t),
67  error, thread_id);
68 
69  ProcessSP process_sp(GetSP());
70  error.Clear();
71 
72  if (!process_sp) {
73  error.SetErrorString("invalid process");
74  return;
75  }
76  error.SetError(process_sp->StopTrace(GetTraceUID(), thread_id));
77 }
78 
80  LLDB_RECORD_METHOD(void, SBTrace, GetTraceConfig,
81  (lldb::SBTraceOptions &, lldb::SBError &), options, error);
82 
83  ProcessSP process_sp(GetSP());
84  error.Clear();
85 
86  if (!process_sp) {
87  error.SetErrorString("invalid process");
88  } else {
89  error.SetError(process_sp->GetTraceConfig(GetTraceUID(),
90  *(options.m_traceoptions_sp)));
91  }
92 }
93 
96 
97  if (m_trace_impl_sp)
98  return m_trace_impl_sp->uid;
99  return LLDB_INVALID_UID;
100 }
101 
103  if (m_trace_impl_sp)
104  m_trace_impl_sp->uid = uid;
105 }
106 
109 
110  m_trace_impl_sp = std::make_shared<TraceImpl>();
111  if (m_trace_impl_sp)
112  m_trace_impl_sp->uid = LLDB_INVALID_UID;
113 }
114 
115 void SBTrace::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
116 
118  LLDB_RECORD_METHOD_NO_ARGS(bool, SBTrace, IsValid);
119  return this->operator bool();
120 }
121 SBTrace::operator bool() const {
122  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTrace, operator bool);
123 
124  if (!m_trace_impl_sp)
125  return false;
126  if (!GetSP())
127  return false;
128  return true;
129 }
130 
131 namespace lldb_private {
132 namespace repro {
133 
134 template <>
136  LLDB_REGISTER_METHOD(void, SBTrace, StopTrace,
138  LLDB_REGISTER_METHOD(void, SBTrace, GetTraceConfig,
140  LLDB_REGISTER_METHOD(lldb::user_id_t, SBTrace, GetTraceUID, ());
142  LLDB_REGISTER_METHOD(bool, SBTrace, IsValid, ());
143  LLDB_REGISTER_METHOD_CONST(bool, SBTrace, operator bool, ());
144 }
145 
146 }
147 }
The registry contains a unique mapping between functions and their ID.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
size_t GetTraceData(SBError &error, void *buf, size_t size, size_t offset=0, lldb::tid_t thread_id=LLDB_INVALID_THREAD_ID)
Obtain the trace data as raw bytes.
Definition: SBTrace.cpp:27
void StopTrace(SBError &error, lldb::tid_t thread_id=LLDB_INVALID_THREAD_ID)
Stop the tracing instance.
Definition: SBTrace.cpp:65
void SetSP(const ProcessSP &process_sp)
Definition: SBTrace.cpp:115
#define LLDB_RECORD_DUMMY(Result, Class, Method, Signature,...)
The LLDB_RECORD_DUMMY macro is special because it doesn&#39;t actually record anything.
void RegisterMethods< SBTrace >(Registry &R)
Definition: SBTrace.cpp:135
void Clear()
Definition: SBError.cpp:47
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:97
#define LLDB_INVALID_UID
Definition: lldb-defines.h:91
void SetErrorString(const char *err_str)
Definition: SBError.cpp:124
lldb::TraceOptionsSP m_traceoptions_sp
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
void GetTraceConfig(SBTraceOptions &options, SBError &error)
Get the trace configuration being used for the trace instance.
Definition: SBTrace.cpp:79
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
uint64_t user_id_t
Definition: lldb-types.h:84
size_t GetMetaData(SBError &error, void *buf, size_t size, size_t offset=0, lldb::tid_t thread_id=LLDB_INVALID_THREAD_ID)
Obtain any meta data as raw bytes for the tracing instance.
Definition: SBTrace.cpp:46
uint64_t tid_t
Definition: lldb-types.h:86
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
void SetTraceUID(lldb::user_id_t uid)
Definition: SBTrace.cpp:102
bool IsValid()
Definition: SBTrace.cpp:117
Definition: SBAddress.h:15
lldb::user_id_t uid
Definition: SBTrace.cpp:22
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
lldb::ProcessSP GetSP() const
Definition: SBTrace.cpp:25
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
lldb::user_id_t GetTraceUID()
Definition: SBTrace.cpp:94