1 //===-- SBTrace.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 "SBReproducerPrivate.h"
10 #include "lldb/Target/Process.h"
11
12 #include "lldb/API/SBStructuredData.h"
13 #include "lldb/API/SBThread.h"
14 #include "lldb/API/SBTrace.h"
15
16 #include "lldb/Core/StructuredDataImpl.h"
17
18 #include <memory>
19
20 using namespace lldb;
21 using namespace lldb_private;
22
SBTrace()23 SBTrace::SBTrace() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTrace); }
24
SBTrace(const lldb::TraceSP & trace_sp)25 SBTrace::SBTrace(const lldb::TraceSP &trace_sp) : m_opaque_sp(trace_sp) {
26 LLDB_RECORD_CONSTRUCTOR(SBTrace, (const lldb::TraceSP &), trace_sp);
27 }
28
GetStartConfigurationHelp()29 const char *SBTrace::GetStartConfigurationHelp() {
30 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTrace, GetStartConfigurationHelp);
31 return LLDB_RECORD_RESULT(
32 m_opaque_sp ? m_opaque_sp->GetStartConfigurationHelp() : nullptr);
33 }
34
Start(const SBStructuredData & configuration)35 SBError SBTrace::Start(const SBStructuredData &configuration) {
36 LLDB_RECORD_METHOD(SBError, SBTrace, Start, (const SBStructuredData &),
37 configuration);
38 SBError error;
39 if (!m_opaque_sp)
40 error.SetErrorString("error: invalid trace");
41 else if (llvm::Error err =
42 m_opaque_sp->Start(configuration.m_impl_up->GetObjectSP()))
43 error.SetErrorString(llvm::toString(std::move(err)).c_str());
44 return LLDB_RECORD_RESULT(error);
45 }
46
Start(const SBThread & thread,const SBStructuredData & configuration)47 SBError SBTrace::Start(const SBThread &thread,
48 const SBStructuredData &configuration) {
49 LLDB_RECORD_METHOD(SBError, SBTrace, Start,
50 (const SBThread &, const SBStructuredData &), thread,
51 configuration);
52
53 SBError error;
54 if (!m_opaque_sp)
55 error.SetErrorString("error: invalid trace");
56 else {
57 if (llvm::Error err =
58 m_opaque_sp->Start(std::vector<lldb::tid_t>{thread.GetThreadID()},
59 configuration.m_impl_up->GetObjectSP()))
60 error.SetErrorString(llvm::toString(std::move(err)).c_str());
61 }
62
63 return LLDB_RECORD_RESULT(error);
64 }
65
Stop()66 SBError SBTrace::Stop() {
67 LLDB_RECORD_METHOD_NO_ARGS(SBError, SBTrace, Stop);
68 SBError error;
69 if (!m_opaque_sp)
70 error.SetErrorString("error: invalid trace");
71 else if (llvm::Error err = m_opaque_sp->Stop())
72 error.SetErrorString(llvm::toString(std::move(err)).c_str());
73 return LLDB_RECORD_RESULT(error);
74 }
75
Stop(const SBThread & thread)76 SBError SBTrace::Stop(const SBThread &thread) {
77 LLDB_RECORD_METHOD(SBError, SBTrace, Stop, (const SBThread &), thread);
78 SBError error;
79 if (!m_opaque_sp)
80 error.SetErrorString("error: invalid trace");
81 else if (llvm::Error err = m_opaque_sp->Stop({thread.GetThreadID()}))
82 error.SetErrorString(llvm::toString(std::move(err)).c_str());
83 return LLDB_RECORD_RESULT(error);
84 }
85
IsValid()86 bool SBTrace::IsValid() {
87 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTrace, IsValid);
88 return this->operator bool();
89 }
90
operator bool() const91 SBTrace::operator bool() const {
92 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTrace, operator bool);
93 return (bool)m_opaque_sp;
94 }
95
96 namespace lldb_private {
97 namespace repro {
98
99 template <>
RegisterMethods(Registry & R)100 void RegisterMethods<SBTrace>(Registry &R) {
101 LLDB_REGISTER_CONSTRUCTOR(SBTrace, ());
102 LLDB_REGISTER_CONSTRUCTOR(SBTrace, (const lldb::TraceSP &));
103 LLDB_REGISTER_METHOD(SBError, SBTrace, Start, (const SBStructuredData &));
104 LLDB_REGISTER_METHOD(SBError, SBTrace, Start,
105 (const SBThread &, const SBStructuredData &));
106 LLDB_REGISTER_METHOD(SBError, SBTrace, Stop, (const SBThread &));
107 LLDB_REGISTER_METHOD(SBError, SBTrace, Stop, ());
108 LLDB_REGISTER_METHOD(bool, SBTrace, IsValid, ());
109 LLDB_REGISTER_METHOD(const char *, SBTrace, GetStartConfigurationHelp, ());
110 LLDB_REGISTER_METHOD_CONST(bool, SBTrace, operator bool, ());
111 }
112
113 }
114 }
115