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 "SBReproducerPrivate.h" 100b57cec5SDimitry Andric #include "lldb/Target/Process.h" 110b57cec5SDimitry Andric 12*fe6060f1SDimitry Andric #include "lldb/API/SBStructuredData.h" 13*fe6060f1SDimitry Andric #include "lldb/API/SBThread.h" 140b57cec5SDimitry Andric #include "lldb/API/SBTrace.h" 15*fe6060f1SDimitry Andric 16*fe6060f1SDimitry 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*fe6060f1SDimitry Andric SBTrace::SBTrace() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTrace); } 240b57cec5SDimitry Andric 25*fe6060f1SDimitry Andric SBTrace::SBTrace(const lldb::TraceSP &trace_sp) : m_opaque_sp(trace_sp) { 26*fe6060f1SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBTrace, (const lldb::TraceSP &), trace_sp); 270b57cec5SDimitry Andric } 280b57cec5SDimitry Andric 29*fe6060f1SDimitry Andric const char *SBTrace::GetStartConfigurationHelp() { 30*fe6060f1SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTrace, GetStartConfigurationHelp); 31*fe6060f1SDimitry Andric return LLDB_RECORD_RESULT( 32*fe6060f1SDimitry Andric m_opaque_sp ? m_opaque_sp->GetStartConfigurationHelp() : nullptr); 330b57cec5SDimitry Andric } 340b57cec5SDimitry Andric 35*fe6060f1SDimitry Andric SBError SBTrace::Start(const SBStructuredData &configuration) { 36*fe6060f1SDimitry Andric LLDB_RECORD_METHOD(SBError, SBTrace, Start, (const SBStructuredData &), 37*fe6060f1SDimitry Andric configuration); 38*fe6060f1SDimitry Andric SBError error; 39*fe6060f1SDimitry Andric if (!m_opaque_sp) 40*fe6060f1SDimitry Andric error.SetErrorString("error: invalid trace"); 41*fe6060f1SDimitry Andric else if (llvm::Error err = 42*fe6060f1SDimitry Andric m_opaque_sp->Start(configuration.m_impl_up->GetObjectSP())) 43*fe6060f1SDimitry Andric error.SetErrorString(llvm::toString(std::move(err)).c_str()); 44*fe6060f1SDimitry Andric return LLDB_RECORD_RESULT(error); 450b57cec5SDimitry Andric } 460b57cec5SDimitry Andric 47*fe6060f1SDimitry Andric SBError SBTrace::Start(const SBThread &thread, 48*fe6060f1SDimitry Andric const SBStructuredData &configuration) { 49*fe6060f1SDimitry Andric LLDB_RECORD_METHOD(SBError, SBTrace, Start, 50*fe6060f1SDimitry Andric (const SBThread &, const SBStructuredData &), thread, 51*fe6060f1SDimitry Andric configuration); 520b57cec5SDimitry Andric 53*fe6060f1SDimitry Andric SBError error; 54*fe6060f1SDimitry Andric if (!m_opaque_sp) 55*fe6060f1SDimitry Andric error.SetErrorString("error: invalid trace"); 56*fe6060f1SDimitry Andric else { 57*fe6060f1SDimitry Andric if (llvm::Error err = 58*fe6060f1SDimitry Andric m_opaque_sp->Start(std::vector<lldb::tid_t>{thread.GetThreadID()}, 59*fe6060f1SDimitry Andric configuration.m_impl_up->GetObjectSP())) 60*fe6060f1SDimitry Andric error.SetErrorString(llvm::toString(std::move(err)).c_str()); 610b57cec5SDimitry Andric } 620b57cec5SDimitry Andric 63*fe6060f1SDimitry Andric return LLDB_RECORD_RESULT(error); 640b57cec5SDimitry Andric } 650b57cec5SDimitry Andric 66*fe6060f1SDimitry Andric SBError SBTrace::Stop() { 67*fe6060f1SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(SBError, SBTrace, Stop); 68*fe6060f1SDimitry Andric SBError error; 69*fe6060f1SDimitry Andric if (!m_opaque_sp) 70*fe6060f1SDimitry Andric error.SetErrorString("error: invalid trace"); 71*fe6060f1SDimitry Andric else if (llvm::Error err = m_opaque_sp->Stop()) 72*fe6060f1SDimitry Andric error.SetErrorString(llvm::toString(std::move(err)).c_str()); 73*fe6060f1SDimitry Andric return LLDB_RECORD_RESULT(error); 740b57cec5SDimitry Andric } 750b57cec5SDimitry Andric 76*fe6060f1SDimitry Andric SBError SBTrace::Stop(const SBThread &thread) { 77*fe6060f1SDimitry Andric LLDB_RECORD_METHOD(SBError, SBTrace, Stop, (const SBThread &), thread); 78*fe6060f1SDimitry Andric SBError error; 79*fe6060f1SDimitry Andric if (!m_opaque_sp) 80*fe6060f1SDimitry Andric error.SetErrorString("error: invalid trace"); 81*fe6060f1SDimitry Andric else if (llvm::Error err = m_opaque_sp->Stop({thread.GetThreadID()})) 82*fe6060f1SDimitry Andric error.SetErrorString(llvm::toString(std::move(err)).c_str()); 83*fe6060f1SDimitry Andric return LLDB_RECORD_RESULT(error); 840b57cec5SDimitry Andric } 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric bool SBTrace::IsValid() { 870b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(bool, SBTrace, IsValid); 880b57cec5SDimitry Andric return this->operator bool(); 890b57cec5SDimitry Andric } 90*fe6060f1SDimitry Andric 910b57cec5SDimitry Andric SBTrace::operator bool() const { 920b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTrace, operator bool); 93*fe6060f1SDimitry Andric return (bool)m_opaque_sp; 940b57cec5SDimitry Andric } 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric namespace lldb_private { 970b57cec5SDimitry Andric namespace repro { 980b57cec5SDimitry Andric 990b57cec5SDimitry Andric template <> 1000b57cec5SDimitry Andric void RegisterMethods<SBTrace>(Registry &R) { 1010b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBTrace, ()); 102*fe6060f1SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBTrace, (const lldb::TraceSP &)); 103*fe6060f1SDimitry Andric LLDB_REGISTER_METHOD(SBError, SBTrace, Start, (const SBStructuredData &)); 104*fe6060f1SDimitry Andric LLDB_REGISTER_METHOD(SBError, SBTrace, Start, 105*fe6060f1SDimitry Andric (const SBThread &, const SBStructuredData &)); 106*fe6060f1SDimitry Andric LLDB_REGISTER_METHOD(SBError, SBTrace, Stop, (const SBThread &)); 107*fe6060f1SDimitry Andric LLDB_REGISTER_METHOD(SBError, SBTrace, Stop, ()); 1080b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBTrace, IsValid, ()); 109*fe6060f1SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBTrace, GetStartConfigurationHelp, ()); 1100b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(bool, SBTrace, operator bool, ()); 1110b57cec5SDimitry Andric } 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric } 1140b57cec5SDimitry Andric } 115