LLDB  mainline
SBStringList.cpp
Go to the documentation of this file.
1 //===-- SBStringList.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 
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
13 
14 using namespace lldb;
15 using namespace lldb_private;
16 
17 SBStringList::SBStringList() : m_opaque_up() {
19 }
20 
22  : m_opaque_up() {
23  if (lldb_strings_ptr)
24  m_opaque_up = std::make_unique<StringList>(*lldb_strings_ptr);
25 }
26 
27 SBStringList::SBStringList(const SBStringList &rhs) : m_opaque_up() {
29 
31 }
32 
35  SBStringList, operator=,(const lldb::SBStringList &), rhs);
36 
37  if (this != &rhs)
39  return LLDB_RECORD_RESULT(*this);
40 }
41 
42 SBStringList::~SBStringList() = default;
43 
45  return m_opaque_up.get();
46 }
47 
49  return *m_opaque_up;
50 }
51 
52 bool SBStringList::IsValid() const {
54  return this->operator bool();
55 }
56 SBStringList::operator bool() const {
57  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBStringList, operator bool);
58 
59  return (m_opaque_up != nullptr);
60 }
61 
62 void SBStringList::AppendString(const char *str) {
63  LLDB_RECORD_METHOD(void, SBStringList, AppendString, (const char *), str);
64 
65  if (str != nullptr) {
66  if (IsValid())
67  m_opaque_up->AppendString(str);
68  else
69  m_opaque_up = std::make_unique<lldb_private::StringList>(str);
70  }
71 }
72 
73 void SBStringList::AppendList(const char **strv, int strc) {
74  LLDB_RECORD_METHOD(void, SBStringList, AppendList, (const char **, int), strv,
75  strc);
76 
77  if ((strv != nullptr) && (strc > 0)) {
78  if (IsValid())
79  m_opaque_up->AppendList(strv, strc);
80  else
81  m_opaque_up = std::make_unique<lldb_private::StringList>(strv, strc);
82  }
83 }
84 
85 void SBStringList::AppendList(const SBStringList &strings) {
87  (const lldb::SBStringList &), strings);
88 
89  if (strings.IsValid()) {
90  if (!IsValid())
91  m_opaque_up = std::make_unique<lldb_private::StringList>();
92  m_opaque_up->AppendList(*(strings.m_opaque_up));
93  }
94 }
95 
96 void SBStringList::AppendList(const StringList &strings) {
97  if (!IsValid())
98  m_opaque_up = std::make_unique<lldb_private::StringList>();
99  m_opaque_up->AppendList(strings);
100 }
101 
104 
105  if (IsValid()) {
106  return m_opaque_up->GetSize();
107  }
108  return 0;
109 }
110 
111 const char *SBStringList::GetStringAtIndex(size_t idx) {
112  LLDB_RECORD_METHOD(const char *, SBStringList, GetStringAtIndex, (size_t),
113  idx);
114 
115  if (IsValid()) {
116  return m_opaque_up->GetStringAtIndex(idx);
117  }
118  return nullptr;
119 }
120 
121 const char *SBStringList::GetStringAtIndex(size_t idx) const {
123  (size_t), idx);
124 
125  if (IsValid()) {
126  return m_opaque_up->GetStringAtIndex(idx);
127  }
128  return nullptr;
129 }
130 
133 
134  if (IsValid()) {
135  m_opaque_up->Clear();
136  }
137 }
138 
139 namespace lldb_private {
140 namespace repro {
141 
142 template <>
147  SBStringList, operator=,(const lldb::SBStringList &));
148  LLDB_REGISTER_METHOD_CONST(bool, SBStringList, IsValid, ());
149  LLDB_REGISTER_METHOD_CONST(bool, SBStringList, operator bool, ());
150  LLDB_REGISTER_METHOD(void, SBStringList, AppendString, (const char *));
151  LLDB_REGISTER_METHOD(void, SBStringList, AppendList, (const char **, int));
152  LLDB_REGISTER_METHOD(void, SBStringList, AppendList,
153  (const lldb::SBStringList &));
155  LLDB_REGISTER_METHOD(const char *, SBStringList, GetStringAtIndex,
156  (size_t));
157  LLDB_REGISTER_METHOD_CONST(const char *, SBStringList, GetStringAtIndex,
158  (size_t));
159  LLDB_REGISTER_METHOD(void, SBStringList, Clear, ());
160 }
161 
162 }
163 }
lldb::SBStringList::operator*
const lldb_private::StringList & operator*() const
Definition: SBStringList.cpp:48
lldb::SBStringList
Definition: SBStringList.h:16
lldb::SBStringList::AppendString
void AppendString(const char *str)
Definition: SBStringList.cpp:62
lldb::SBStringList::GetSize
uint32_t GetSize() const
Definition: SBStringList.cpp:102
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
SBStringList.h
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::SBStringList::GetStringAtIndex
const char * GetStringAtIndex(size_t idx)
Definition: SBStringList.cpp:111
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
lldb::SBStringList::IsValid
bool IsValid() const
Definition: SBStringList.cpp:52
lldb_private::repro::RegisterMethods< SBStringList >
void RegisterMethods< SBStringList >(Registry &R)
Definition: SBStringList.cpp:143
lldb_private::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Utils.h
lldb::SBStringList::Clear
void Clear()
Definition: SBStringList.cpp:131
lldb_private::StringList
Definition: StringList.h:25
StringList.h
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::SBStringList::SBStringList
SBStringList()
Definition: SBStringList.cpp:17
uint32_t
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBStringList::operator->
const lldb_private::StringList * operator->() const
Definition: SBStringList.cpp:44
lldb::SBStringList::operator=
const SBStringList & operator=(const SBStringList &rhs)
Definition: SBStringList.cpp:33
LLDB_RECORD_METHOD_CONST
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:161
lldb::SBStringList::m_opaque_up
std::unique_ptr< lldb_private::StringList > m_opaque_up
Definition: SBStringList.h:60
lldb
Definition: SBAddress.h:15
lldb::SBStringList::~SBStringList
~SBStringList()
lldb::SBStringList::AppendList
void AppendList(const char **strv, int strc)
Definition: SBStringList.cpp:73
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93