LLDB  mainline
OptionValue.h
Go to the documentation of this file.
1 //===-- OptionValue.h -------------------------------------------*- C++ -*-===//
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 #ifndef liblldb_OptionValue_h_
10 #define liblldb_OptionValue_h_
11 
12 #include "lldb/Core/FormatEntity.h"
15 #include "lldb/Utility/Status.h"
16 #include "lldb/lldb-defines.h"
19 
20 namespace lldb_private {
21 
22 // OptionValue
23 class OptionValue {
24 public:
25  typedef enum {
46  } Type;
47 
48  enum {
49  eDumpOptionName = (1u << 0),
50  eDumpOptionType = (1u << 1),
51  eDumpOptionValue = (1u << 2),
53  eDumpOptionRaw = (1u << 4),
54  eDumpOptionCommand = (1u << 5),
59  };
60 
62  : m_callback(nullptr), m_baton(nullptr), m_value_was_set(false) {}
63 
65  : m_callback(rhs.m_callback), m_baton(rhs.m_baton),
67 
68  virtual ~OptionValue() = default;
69 
70  // Subclasses should override these functions
71  virtual Type GetType() const = 0;
72 
73  // If this value is always hidden, the avoid showing any info on this value,
74  // just show the info for the child values.
75  virtual bool ValueIsTransparent() const {
76  return GetType() == eTypeProperties;
77  }
78 
79  virtual const char *GetTypeAsCString() const {
81  }
82 
83  static const char *GetBuiltinTypeAsCString(Type t);
84 
85  virtual void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
86  uint32_t dump_mask) = 0;
87 
88  virtual Status
89  SetValueFromString(llvm::StringRef value,
91 
92  virtual bool Clear() = 0;
93 
94  virtual lldb::OptionValueSP DeepCopy() const = 0;
95 
96  virtual size_t AutoComplete(CommandInterpreter &interpreter,
97  CompletionRequest &request);
98 
99  // Subclasses can override these functions
100  virtual lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
101  llvm::StringRef name,
102  bool will_modify,
103  Status &error) const {
104  error.SetErrorStringWithFormat("'%s' is not a value subvalue", name.str().c_str());
105  return lldb::OptionValueSP();
106  }
107 
108  virtual Status SetSubValue(const ExecutionContext *exe_ctx,
109  VarSetOperationType op, llvm::StringRef name,
110  llvm::StringRef value);
111 
112  virtual bool IsAggregateValue() const { return false; }
113 
114  virtual ConstString GetName() const { return ConstString(); }
115 
116  virtual bool DumpQualifiedName(Stream &strm) const;
117 
118  // Subclasses should NOT override these functions as they use the above
119  // functions to implement functionality
120  uint32_t GetTypeAsMask() { return 1u << GetType(); }
121 
123  return 1u << type;
124  }
125 
127  // If only one bit is set, then return an appropriate enumeration
128  switch (type_mask) {
129  case 1u << eTypeArch:
130  return eTypeArch;
131  case 1u << eTypeArgs:
132  return eTypeArgs;
133  case 1u << eTypeArray:
134  return eTypeArray;
135  case 1u << eTypeBoolean:
136  return eTypeBoolean;
137  case 1u << eTypeChar:
138  return eTypeChar;
139  case 1u << eTypeDictionary:
140  return eTypeDictionary;
141  case 1u << eTypeEnum:
142  return eTypeEnum;
143  case 1u << eTypeFileSpec:
144  return eTypeFileSpec;
145  case 1u << eTypeFileSpecList:
146  return eTypeFileSpecList;
147  case 1u << eTypeFormat:
148  return eTypeFormat;
149  case 1u << eTypeLanguage:
150  return eTypeLanguage;
151  case 1u << eTypePathMap:
152  return eTypePathMap;
153  case 1u << eTypeProperties:
154  return eTypeProperties;
155  case 1u << eTypeRegex:
156  return eTypeRegex;
157  case 1u << eTypeSInt64:
158  return eTypeSInt64;
159  case 1u << eTypeString:
160  return eTypeString;
161  case 1u << eTypeUInt64:
162  return eTypeUInt64;
163  case 1u << eTypeUUID:
164  return eTypeUUID;
165  }
166  // Else return invalid
167  return eTypeInvalid;
168  }
169 
170  static lldb::OptionValueSP
171  CreateValueFromCStringForTypeMask(const char *value_cstr, uint32_t type_mask,
172  Status &error);
173 
174  // Get this value as a uint64_t value if it is encoded as a boolean, uint64_t
175  // or int64_t. Other types will cause "fail_value" to be returned
176  uint64_t GetUInt64Value(uint64_t fail_value, bool *success_ptr);
177 
179 
180  const OptionValueArch *GetAsArch() const;
181 
183 
184  const OptionValueArray *GetAsArray() const;
185 
187 
188  const OptionValueArgs *GetAsArgs() const;
189 
191 
193 
194  const OptionValueBoolean *GetAsBoolean() const;
195 
196  const OptionValueChar *GetAsChar() const;
197 
199 
200  const OptionValueDictionary *GetAsDictionary() const;
201 
203 
205 
207 
208  const OptionValueFileSpec *GetAsFileSpec() const;
209 
211 
213 
215 
216  const OptionValueFormat *GetAsFormat() const;
217 
219 
220  const OptionValueLanguage *GetAsLanguage() const;
221 
223 
225 
227 
228  const OptionValueProperties *GetAsProperties() const;
229 
231 
232  const OptionValueRegex *GetAsRegex() const;
233 
235 
236  const OptionValueSInt64 *GetAsSInt64() const;
237 
239 
240  const OptionValueString *GetAsString() const;
241 
243 
244  const OptionValueUInt64 *GetAsUInt64() const;
245 
247 
248  const OptionValueUUID *GetAsUUID() const;
249 
251 
253 
254  bool GetBooleanValue(bool fail_value = false) const;
255 
256  bool SetBooleanValue(bool new_value);
257 
258  char GetCharValue(char fail_value) const;
259 
260  char SetCharValue(char new_value);
261 
262  int64_t GetEnumerationValue(int64_t fail_value = -1) const;
263 
264  bool SetEnumerationValue(int64_t value);
265 
266  FileSpec GetFileSpecValue() const;
267 
268  bool SetFileSpecValue(const FileSpec &file_spec);
269 
270  FileSpecList GetFileSpecListValue() const;
271 
274 
275  bool SetFormatValue(lldb::Format new_value);
276 
279 
280  bool SetLanguageValue(lldb::LanguageType new_language);
281 
282  const FormatEntity::Entry *GetFormatEntity() const;
283 
284  const RegularExpression *GetRegexValue() const;
285 
286  int64_t GetSInt64Value(int64_t fail_value = 0) const;
287 
288  bool SetSInt64Value(int64_t new_value);
289 
290  llvm::StringRef GetStringValue(llvm::StringRef fail_value) const;
291  llvm::StringRef GetStringValue() const { return GetStringValue(llvm::StringRef()); }
292 
293  bool SetStringValue(llvm::StringRef new_value);
294 
295  uint64_t GetUInt64Value(uint64_t fail_value = 0) const;
296 
297  bool SetUInt64Value(uint64_t new_value);
298 
299  UUID GetUUIDValue() const;
300 
301  bool SetUUIDValue(const UUID &uuid);
302 
303  bool OptionWasSet() const { return m_value_was_set; }
304 
305  void SetOptionWasSet() { m_value_was_set = true; }
306 
307  void SetParent(const lldb::OptionValueSP &parent_sp) {
308  m_parent_wp = parent_sp;
309  }
310 
311  void SetValueChangedCallback(OptionValueChangedCallback callback,
312  void *baton) {
313  assert(m_callback == nullptr);
314  m_callback = callback;
315  m_baton = baton;
316  }
317 
319  if (m_callback)
320  m_callback(m_baton, this);
321  }
322 
323 protected:
324  lldb::OptionValueWP m_parent_wp;
325  OptionValueChangedCallback m_callback;
326  void *m_baton;
327  bool m_value_was_set; // This can be used to see if a value has been set
328  // by a call to SetValueFromCString(). It is often
329  // handy to know if an option value was set from the
330  // command line or as a setting, versus if we just have
331  // the default value that was already populated in the
332  // option value.
333 };
334 
335 } // namespace lldb_private
336 
337 #endif // liblldb_OptionValue_h_
OptionValueArgs * GetAsArgs()
virtual lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx, llvm::StringRef name, bool will_modify, Status &error) const
Definition: OptionValue.h:100
OptionValueProperties * GetAsProperties()
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
OptionValueChangedCallback m_callback
Definition: OptionValue.h:325
virtual Type GetType() const =0
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
const FormatEntity::Entry * GetFormatEntity() const
OptionValuePathMappings * GetAsPathMappings()
virtual bool ValueIsTransparent() const
Definition: OptionValue.h:75
void SetValueChangedCallback(OptionValueChangedCallback callback, void *baton)
Definition: OptionValue.h:311
static lldb::OptionValueSP CreateValueFromCStringForTypeMask(const char *value_cstr, uint32_t type_mask, Status &error)
bool SetBooleanValue(bool new_value)
bool SetEnumerationValue(int64_t value)
A file utility class.
Definition: FileSpec.h:55
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
virtual bool IsAggregateValue() const
Definition: OptionValue.h:112
bool SetFileSpecValue(const FileSpec &file_spec)
virtual ConstString GetName() const
Definition: OptionValue.h:114
bool GetBooleanValue(bool fail_value=false) const
FileSpec GetFileSpecValue() const
void SetParent(const lldb::OptionValueSP &parent_sp)
Definition: OptionValue.h:307
bool SetUUIDValue(const UUID &uuid)
OptionValueUUID * GetAsUUID()
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
OptionValueFormat * GetAsFormat()
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
virtual bool Clear()=0
"lldb/Utility/ArgCompletionRequest.h"
OptionValueUInt64 * GetAsUInt64()
OptionValueBoolean * GetAsBoolean()
Definition: OptionValue.cpp:45
lldb::LanguageType GetLanguageValue(lldb::LanguageType fail_value=lldb::eLanguageTypeUnknown) const
llvm::StringRef GetStringValue() const
Definition: OptionValue.h:291
LanguageType
Programming language type.
uint64_t GetUInt64Value(uint64_t fail_value, bool *success_ptr)
Definition: OptionValue.cpp:19
VarSetOperationType
Settable state variable types.
OptionValueFileSpecList * GetAsFileSpecList()
Definition: OptionValue.cpp:81
static uint32_t ConvertTypeToMask(OptionValue::Type type)
Definition: OptionValue.h:122
OptionValueDictionary * GetAsDictionary()
static const char * GetBuiltinTypeAsCString(Type t)
OptionValue(const OptionValue &rhs)
Definition: OptionValue.h:64
OptionValueSInt64 * GetAsSInt64()
OptionValueFileSpec * GetAsFileSpec()
Definition: OptionValue.cpp:69
int64_t GetSInt64Value(int64_t fail_value=0) const
OptionValueChar * GetAsChar()
Definition: OptionValue.cpp:63
static OptionValue::Type ConvertTypeMaskToType(uint32_t type_mask)
Definition: OptionValue.h:126
bool SetStringValue(llvm::StringRef new_value)
OptionValueLanguage * GetAsLanguage()
virtual lldb::OptionValueSP DeepCopy() const =0
lldb::Format GetFormatValue(lldb::Format fail_value=lldb::eFormatDefault) const
char GetCharValue(char fail_value) const
char SetCharValue(char new_value)
lldb::OptionValueWP m_parent_wp
Definition: OptionValue.h:324
const RegularExpression * GetRegexValue() const
virtual void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)=0
OptionValueArch * GetAsArch()
Definition: OptionValue.cpp:93
bool SetUInt64Value(uint64_t new_value)
A uniqued constant string class.
Definition: ConstString.h:38
Unknown or invalid language value.
virtual const char * GetTypeAsCString() const
Definition: OptionValue.h:79
virtual bool DumpQualifiedName(Stream &strm) const
bool SetLanguageValue(lldb::LanguageType new_language)
virtual ~OptionValue()=default
virtual size_t AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request)
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
bool SetSInt64Value(int64_t new_value)
OptionValueEnumeration * GetAsEnumeration()
OptionValueRegex * GetAsRegex()
OptionValueString * GetAsString()
FileSpecList GetFileSpecListValue() const
OptionValueFormatEntity * GetAsFormatEntity()
virtual Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef name, llvm::StringRef value)
Definition: OptionValue.cpp:37
int64_t GetEnumerationValue(int64_t fail_value=-1) const
bool SetFormatValue(lldb::Format new_value)
An error handling class.
Definition: Status.h:44
OptionValueArray * GetAsArray()