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 "lldb/Utility/ReproducerInstrumentation.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 23 SBTrace::SBTrace() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTrace); } 24 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 29 const char *SBTrace::GetStartConfigurationHelp() { 30 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTrace, GetStartConfigurationHelp); 31 return m_opaque_sp ? m_opaque_sp->GetStartConfigurationHelp() : nullptr; 32 } 33 34 SBError SBTrace::Start(const SBStructuredData &configuration) { 35 LLDB_RECORD_METHOD(SBError, SBTrace, Start, (const SBStructuredData &), 36 configuration); 37 SBError error; 38 if (!m_opaque_sp) 39 error.SetErrorString("error: invalid trace"); 40 else if (llvm::Error err = 41 m_opaque_sp->Start(configuration.m_impl_up->GetObjectSP())) 42 error.SetErrorString(llvm::toString(std::move(err)).c_str()); 43 return error; 44 } 45 46 SBError SBTrace::Start(const SBThread &thread, 47 const SBStructuredData &configuration) { 48 LLDB_RECORD_METHOD(SBError, SBTrace, Start, 49 (const SBThread &, const SBStructuredData &), thread, 50 configuration); 51 52 SBError error; 53 if (!m_opaque_sp) 54 error.SetErrorString("error: invalid trace"); 55 else { 56 if (llvm::Error err = 57 m_opaque_sp->Start(std::vector<lldb::tid_t>{thread.GetThreadID()}, 58 configuration.m_impl_up->GetObjectSP())) 59 error.SetErrorString(llvm::toString(std::move(err)).c_str()); 60 } 61 62 return error; 63 } 64 65 SBError SBTrace::Stop() { 66 LLDB_RECORD_METHOD_NO_ARGS(SBError, SBTrace, Stop); 67 SBError error; 68 if (!m_opaque_sp) 69 error.SetErrorString("error: invalid trace"); 70 else if (llvm::Error err = m_opaque_sp->Stop()) 71 error.SetErrorString(llvm::toString(std::move(err)).c_str()); 72 return error; 73 } 74 75 SBError SBTrace::Stop(const SBThread &thread) { 76 LLDB_RECORD_METHOD(SBError, SBTrace, Stop, (const SBThread &), thread); 77 SBError error; 78 if (!m_opaque_sp) 79 error.SetErrorString("error: invalid trace"); 80 else if (llvm::Error err = m_opaque_sp->Stop({thread.GetThreadID()})) 81 error.SetErrorString(llvm::toString(std::move(err)).c_str()); 82 return error; 83 } 84 85 bool SBTrace::IsValid() { 86 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTrace, IsValid); 87 return this->operator bool(); 88 } 89 90 SBTrace::operator bool() const { 91 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTrace, operator bool); 92 return (bool)m_opaque_sp; 93 } 94