xref: /freebsd/contrib/llvm-project/lldb/source/API/SBTrace.cpp (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
15ffd83dbSDimitry Andric //===-- SBTrace.cpp -------------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "lldb/Target/Process.h"
10*04eeddc0SDimitry Andric #include "lldb/Utility/Instrumentation.h"
110b57cec5SDimitry Andric 
12fe6060f1SDimitry Andric #include "lldb/API/SBStructuredData.h"
13fe6060f1SDimitry Andric #include "lldb/API/SBThread.h"
140b57cec5SDimitry Andric #include "lldb/API/SBTrace.h"
15fe6060f1SDimitry Andric 
16fe6060f1SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #include <memory>
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric using namespace lldb;
210b57cec5SDimitry Andric using namespace lldb_private;
220b57cec5SDimitry Andric 
23*04eeddc0SDimitry Andric SBTrace::SBTrace() { LLDB_INSTRUMENT_VA(this); }
240b57cec5SDimitry Andric 
25fe6060f1SDimitry Andric SBTrace::SBTrace(const lldb::TraceSP &trace_sp) : m_opaque_sp(trace_sp) {
26*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, trace_sp);
270b57cec5SDimitry Andric }
280b57cec5SDimitry Andric 
29fe6060f1SDimitry Andric const char *SBTrace::GetStartConfigurationHelp() {
30*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
31*04eeddc0SDimitry Andric   return m_opaque_sp ? m_opaque_sp->GetStartConfigurationHelp() : nullptr;
320b57cec5SDimitry Andric }
330b57cec5SDimitry Andric 
34fe6060f1SDimitry Andric SBError SBTrace::Start(const SBStructuredData &configuration) {
35*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, configuration);
36fe6060f1SDimitry Andric   SBError error;
37fe6060f1SDimitry Andric   if (!m_opaque_sp)
38fe6060f1SDimitry Andric     error.SetErrorString("error: invalid trace");
39fe6060f1SDimitry Andric   else if (llvm::Error err =
40fe6060f1SDimitry Andric                m_opaque_sp->Start(configuration.m_impl_up->GetObjectSP()))
41fe6060f1SDimitry Andric     error.SetErrorString(llvm::toString(std::move(err)).c_str());
42*04eeddc0SDimitry Andric   return error;
430b57cec5SDimitry Andric }
440b57cec5SDimitry Andric 
45fe6060f1SDimitry Andric SBError SBTrace::Start(const SBThread &thread,
46fe6060f1SDimitry Andric                        const SBStructuredData &configuration) {
47*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, thread, configuration);
480b57cec5SDimitry Andric 
49fe6060f1SDimitry Andric   SBError error;
50fe6060f1SDimitry Andric   if (!m_opaque_sp)
51fe6060f1SDimitry Andric     error.SetErrorString("error: invalid trace");
52fe6060f1SDimitry Andric   else {
53fe6060f1SDimitry Andric     if (llvm::Error err =
54fe6060f1SDimitry Andric             m_opaque_sp->Start(std::vector<lldb::tid_t>{thread.GetThreadID()},
55fe6060f1SDimitry Andric                                configuration.m_impl_up->GetObjectSP()))
56fe6060f1SDimitry Andric       error.SetErrorString(llvm::toString(std::move(err)).c_str());
570b57cec5SDimitry Andric   }
580b57cec5SDimitry Andric 
59*04eeddc0SDimitry Andric   return error;
600b57cec5SDimitry Andric }
610b57cec5SDimitry Andric 
62fe6060f1SDimitry Andric SBError SBTrace::Stop() {
63*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
64fe6060f1SDimitry Andric   SBError error;
65fe6060f1SDimitry Andric   if (!m_opaque_sp)
66fe6060f1SDimitry Andric     error.SetErrorString("error: invalid trace");
67fe6060f1SDimitry Andric   else if (llvm::Error err = m_opaque_sp->Stop())
68fe6060f1SDimitry Andric     error.SetErrorString(llvm::toString(std::move(err)).c_str());
69*04eeddc0SDimitry Andric   return error;
700b57cec5SDimitry Andric }
710b57cec5SDimitry Andric 
72fe6060f1SDimitry Andric SBError SBTrace::Stop(const SBThread &thread) {
73*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, thread);
74fe6060f1SDimitry Andric   SBError error;
75fe6060f1SDimitry Andric   if (!m_opaque_sp)
76fe6060f1SDimitry Andric     error.SetErrorString("error: invalid trace");
77fe6060f1SDimitry Andric   else if (llvm::Error err = m_opaque_sp->Stop({thread.GetThreadID()}))
78fe6060f1SDimitry Andric     error.SetErrorString(llvm::toString(std::move(err)).c_str());
79*04eeddc0SDimitry Andric   return error;
800b57cec5SDimitry Andric }
810b57cec5SDimitry Andric 
820b57cec5SDimitry Andric bool SBTrace::IsValid() {
83*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
840b57cec5SDimitry Andric   return this->operator bool();
850b57cec5SDimitry Andric }
86fe6060f1SDimitry Andric 
870b57cec5SDimitry Andric SBTrace::operator bool() const {
88*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
89fe6060f1SDimitry Andric   return (bool)m_opaque_sp;
900b57cec5SDimitry Andric }
91