[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBTrace.cpp
blob9b871e6781d9ba0f5d7005c1f853fd28b88e0ab5
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 //===----------------------------------------------------------------------===//
9 #include "SBReproducerPrivate.h"
10 #include "lldb/Target/Process.h"
12 #include "lldb/API/SBTrace.h"
13 #include "lldb/API/SBTraceOptions.h"
15 #include <memory>
17 using namespace lldb;
18 using namespace lldb_private;
20 class TraceImpl {
21 public:
22 lldb::user_id_t uid;
25 lldb::ProcessSP SBTrace::GetSP() const { return m_opaque_wp.lock(); }
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);
33 ProcessSP process_sp(GetSP());
34 llvm::MutableArrayRef<uint8_t> buffer(static_cast<uint8_t *>(buf), size);
35 error.Clear();
37 if (!process_sp) {
38 error.SetErrorString("invalid process");
39 } else {
40 error.SetError(
41 process_sp->GetData(GetTraceUID(), thread_id, buffer, offset));
43 return buffer.size();
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);
52 ProcessSP process_sp(GetSP());
53 llvm::MutableArrayRef<uint8_t> buffer(static_cast<uint8_t *>(buf), size);
54 error.Clear();
56 if (!process_sp) {
57 error.SetErrorString("invalid process");
58 } else {
59 error.SetError(
60 process_sp->GetMetaData(GetTraceUID(), thread_id, buffer, offset));
62 return buffer.size();
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);
69 ProcessSP process_sp(GetSP());
70 error.Clear();
72 if (!process_sp) {
73 error.SetErrorString("invalid process");
74 return;
76 error.SetError(process_sp->StopTrace(GetTraceUID(), thread_id));
79 void SBTrace::GetTraceConfig(SBTraceOptions &options, SBError &error) {
80 LLDB_RECORD_METHOD(void, SBTrace, GetTraceConfig,
81 (lldb::SBTraceOptions &, lldb::SBError &), options, error);
83 ProcessSP process_sp(GetSP());
84 error.Clear();
86 if (!process_sp) {
87 error.SetErrorString("invalid process");
88 } else {
89 error.SetError(process_sp->GetTraceConfig(GetTraceUID(),
90 *(options.m_traceoptions_sp)));
94 lldb::user_id_t SBTrace::GetTraceUID() {
95 LLDB_RECORD_METHOD_NO_ARGS(lldb::user_id_t, SBTrace, GetTraceUID);
97 if (m_trace_impl_sp)
98 return m_trace_impl_sp->uid;
99 return LLDB_INVALID_UID;
102 void SBTrace::SetTraceUID(lldb::user_id_t uid) {
103 if (m_trace_impl_sp)
104 m_trace_impl_sp->uid = uid;
107 SBTrace::SBTrace() {
108 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTrace);
110 m_trace_impl_sp = std::make_shared<TraceImpl>();
111 if (m_trace_impl_sp)
112 m_trace_impl_sp->uid = LLDB_INVALID_UID;
115 void SBTrace::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
117 bool SBTrace::IsValid() {
118 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTrace, IsValid);
119 return this->operator bool();
121 SBTrace::operator bool() const {
122 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTrace, operator bool);
124 if (!m_trace_impl_sp)
125 return false;
126 if (!GetSP())
127 return false;
128 return true;
131 namespace lldb_private {
132 namespace repro {
134 template <>
135 void RegisterMethods<SBTrace>(Registry &R) {
136 LLDB_REGISTER_METHOD(void, SBTrace, StopTrace,
137 (lldb::SBError &, lldb::tid_t));
138 LLDB_REGISTER_METHOD(void, SBTrace, GetTraceConfig,
139 (lldb::SBTraceOptions &, lldb::SBError &));
140 LLDB_REGISTER_METHOD(lldb::user_id_t, SBTrace, GetTraceUID, ());
141 LLDB_REGISTER_CONSTRUCTOR(SBTrace, ());
142 LLDB_REGISTER_METHOD(bool, SBTrace, IsValid, ());
143 LLDB_REGISTER_METHOD_CONST(bool, SBTrace, operator bool, ());