LLDB  mainline
SBTrace.cpp
Go to the documentation of this file.
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"
11 
12 #include "lldb/API/SBDebugger.h"
14 #include "lldb/API/SBThread.h"
15 #include "lldb/API/SBTrace.h"
16 
18 
19 #include <memory>
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 using namespace llvm;
24 
26 
27 SBTrace::SBTrace(const lldb::TraceSP &trace_sp) : m_opaque_sp(trace_sp) {
28  LLDB_INSTRUMENT_VA(this, trace_sp);
29 }
30 
32  const SBFileSpec &trace_description_file) {
33  LLDB_INSTRUMENT_VA(error, debugger, trace_description_file);
34 
35  Expected<lldb::TraceSP> trace_or_err = Trace::LoadPostMortemTraceFromFile(
36  debugger.ref(), trace_description_file.ref());
37 
38  if (!trace_or_err) {
39  error.SetErrorString(toString(trace_or_err.takeError()).c_str());
40  return SBTrace();
41  }
42 
43  return SBTrace(trace_or_err.get());
44 }
45 
47  LLDB_INSTRUMENT_VA(this);
48  return m_opaque_sp ? m_opaque_sp->GetStartConfigurationHelp() : nullptr;
49 }
50 
51 SBError SBTrace::Start(const SBStructuredData &configuration) {
52  LLDB_INSTRUMENT_VA(this, configuration);
53  SBError error;
54  if (!m_opaque_sp)
55  error.SetErrorString("error: invalid trace");
56  else if (llvm::Error err =
57  m_opaque_sp->Start(configuration.m_impl_up->GetObjectSP()))
58  error.SetErrorString(llvm::toString(std::move(err)).c_str());
59  return error;
60 }
61 
63  const SBStructuredData &configuration) {
64  LLDB_INSTRUMENT_VA(this, thread, configuration);
65 
66  SBError error;
67  if (!m_opaque_sp)
68  error.SetErrorString("error: invalid trace");
69  else {
70  if (llvm::Error err =
71  m_opaque_sp->Start(std::vector<lldb::tid_t>{thread.GetThreadID()},
72  configuration.m_impl_up->GetObjectSP()))
73  error.SetErrorString(llvm::toString(std::move(err)).c_str());
74  }
75 
76  return error;
77 }
78 
80  LLDB_INSTRUMENT_VA(this);
81  SBError error;
82  if (!m_opaque_sp)
83  error.SetErrorString("error: invalid trace");
84  else if (llvm::Error err = m_opaque_sp->Stop())
85  error.SetErrorString(llvm::toString(std::move(err)).c_str());
86  return error;
87 }
88 
89 SBError SBTrace::Stop(const SBThread &thread) {
90  LLDB_INSTRUMENT_VA(this, thread);
91  SBError error;
92  if (!m_opaque_sp)
93  error.SetErrorString("error: invalid trace");
94  else if (llvm::Error err = m_opaque_sp->Stop({thread.GetThreadID()}))
95  error.SetErrorString(llvm::toString(std::move(err)).c_str());
96  return error;
97 }
98 
100  LLDB_INSTRUMENT_VA(this);
101  return this->operator bool();
102 }
103 
104 SBTrace::operator bool() const {
105  LLDB_INSTRUMENT_VA(this);
106  return (bool)m_opaque_sp;
107 }
lldb_private::toString
const char * toString(AppleArm64ExceptionClass EC)
Definition: AppleArm64ExceptionClass.h:38
Instrumentation.h
lldb::SBDebugger::ref
lldb_private::Debugger & ref() const
Definition: SBDebugger.cpp:1259
llvm
Definition: Debugger.h:50
lldb::SBThread
Definition: SBThread.h:20
lldb::SBTrace::m_opaque_sp
lldb::TraceSP m_opaque_sp
Definition: SBTrace.h:103
lldb::SBError
Definition: SBError.h:20
lldb::SBTrace::SBTrace
SBTrace()
Default constructor for an invalid Trace object.
Definition: SBTrace.cpp:25
lldb::SBStructuredData::m_impl_up
StructuredDataImplUP m_impl_up
Definition: SBStructuredData.h:104
Process.h
lldb::SBTrace
Definition: SBTrace.h:17
lldb::SBTrace::IsValid
bool IsValid()
Definition: SBTrace.cpp:99
lldb::SBTrace::LoadTraceFromFile
static SBTrace LoadTraceFromFile(SBError &error, SBDebugger &debugger, const SBFileSpec &trace_description_file)
See SBDebugger::LoadTraceFromFile.
Definition: SBTrace.cpp:31
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::SBDebugger
Definition: SBDebugger.h:34
SBThread.h
lldb::SBFileSpec::ref
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
SBDebugger.h
lldb::SBStructuredData
Definition: SBStructuredData.h:17
lldb::SBTrace::GetStartConfigurationHelp
const char * GetStartConfigurationHelp()
Definition: SBTrace.cpp:46
SBStructuredData.h
lldb::SBFileSpec
Definition: SBFileSpec.h:16
SBTrace.h
StructuredDataImpl.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb
Definition: SBAddress.h:15
lldb::SBTrace::Start
SBError Start(const SBStructuredData &configuration)
Start tracing all current and future threads in a live process using a provided configuration.
Definition: SBTrace.cpp:51
lldb::SBTrace::Stop
SBError Stop()
Stop tracing all threads in a live process.
Definition: SBTrace.cpp:79