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