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 "SBReproducerPrivate.h"
10 #include "lldb/Target/Process.h"
11 
13 #include "lldb/API/SBThread.h"
14 #include "lldb/API/SBTrace.h"
15 
17 
18 #include <memory>
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
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 
31  return LLDB_RECORD_RESULT(
32  m_opaque_sp ? m_opaque_sp->GetStartConfigurationHelp() : nullptr);
33 }
34 
35 SBError SBTrace::Start(const SBStructuredData &configuration) {
37  configuration);
38  SBError error;
39  if (!m_opaque_sp)
40  error.SetErrorString("error: invalid trace");
41  else if (llvm::Error err =
42  m_opaque_sp->Start(configuration.m_impl_up->GetObjectSP()))
43  error.SetErrorString(llvm::toString(std::move(err)).c_str());
44  return LLDB_RECORD_RESULT(error);
45 }
46 
48  const SBStructuredData &configuration) {
50  (const SBThread &, const SBStructuredData &), thread,
51  configuration);
52 
53  SBError error;
54  if (!m_opaque_sp)
55  error.SetErrorString("error: invalid trace");
56  else {
57  if (llvm::Error err =
58  m_opaque_sp->Start(std::vector<lldb::tid_t>{thread.GetThreadID()},
59  configuration.m_impl_up->GetObjectSP()))
60  error.SetErrorString(llvm::toString(std::move(err)).c_str());
61  }
62 
63  return LLDB_RECORD_RESULT(error);
64 }
65 
68  SBError error;
69  if (!m_opaque_sp)
70  error.SetErrorString("error: invalid trace");
71  else if (llvm::Error err = m_opaque_sp->Stop())
72  error.SetErrorString(llvm::toString(std::move(err)).c_str());
73  return LLDB_RECORD_RESULT(error);
74 }
75 
76 SBError SBTrace::Stop(const SBThread &thread) {
77  LLDB_RECORD_METHOD(SBError, SBTrace, Stop, (const SBThread &), thread);
78  SBError error;
79  if (!m_opaque_sp)
80  error.SetErrorString("error: invalid trace");
81  else if (llvm::Error err = m_opaque_sp->Stop({thread.GetThreadID()}))
82  error.SetErrorString(llvm::toString(std::move(err)).c_str());
83  return LLDB_RECORD_RESULT(error);
84 }
85 
88  return this->operator bool();
89 }
90 
91 SBTrace::operator bool() const {
92  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTrace, operator bool);
93  return (bool)m_opaque_sp;
94 }
95 
96 namespace lldb_private {
97 namespace repro {
98 
99 template <>
102  LLDB_REGISTER_CONSTRUCTOR(SBTrace, (const lldb::TraceSP &));
105  (const SBThread &, const SBStructuredData &));
106  LLDB_REGISTER_METHOD(SBError, SBTrace, Stop, (const SBThread &));
108  LLDB_REGISTER_METHOD(bool, SBTrace, IsValid, ());
109  LLDB_REGISTER_METHOD(const char *, SBTrace, GetStartConfigurationHelp, ());
110  LLDB_REGISTER_METHOD_CONST(bool, SBTrace, operator bool, ());
111 }
112 
113 }
114 }
lldb_private::toString
const char * toString(AppleArm64ExceptionClass EC)
Definition: AppleArm64ExceptionClass.h:38
lldb::SBThread
Definition: SBThread.h:20
lldb::SBTrace::m_opaque_sp
lldb::TraceSP m_opaque_sp
Definition: SBTrace.h:101
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
lldb::SBError
Definition: SBError.h:20
lldb::SBTrace::SBTrace
SBTrace()
Default constructor for an invalid Trace object.
Definition: SBTrace.cpp:23
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
SBReproducerPrivate.h
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBStructuredData::m_impl_up
StructuredDataImplUP m_impl_up
Definition: SBStructuredData.h:104
Process.h
lldb::SBTrace
Definition: SBTrace.h:19
lldb::SBTrace::IsValid
bool IsValid()
Definition: SBTrace.cpp:86
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
SBThread.h
lldb_private::repro::RegisterMethods< SBTrace >
void RegisterMethods< SBTrace >(Registry &R)
Definition: SBTrace.cpp:100
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb::SBStructuredData
Definition: SBStructuredData.h:17
lldb::SBTrace::GetStartConfigurationHelp
const char * GetStartConfigurationHelp()
Definition: SBTrace.cpp:29
SBStructuredData.h
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:29
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:35
lldb::SBTrace::Stop
SBError Stop()
Stop tracing all threads in a live process.
Definition: SBTrace.cpp:66
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93