LLDB mainline
OptionValue.cpp
Go to the documentation of this file.
1//===-- OptionValue.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
12
13#include <memory>
14
15using namespace lldb;
16using namespace lldb_private;
17
18// Get this value as a uint64_t value if it is encoded as a boolean, uint64_t
19// or int64_t. Other types will cause "fail_value" to be returned
20uint64_t OptionValue::GetUInt64Value(uint64_t fail_value, bool *success_ptr) {
21 if (success_ptr)
22 *success_ptr = true;
23 switch (GetType()) {
25 return static_cast<OptionValueBoolean *>(this)->GetCurrentValue();
27 return static_cast<OptionValueSInt64 *>(this)->GetCurrentValue();
29 return static_cast<OptionValueUInt64 *>(this)->GetCurrentValue();
30 default:
31 break;
32 }
33 if (success_ptr)
34 *success_ptr = false;
35 return fail_value;
36}
37
39 VarSetOperationType op, llvm::StringRef name,
40 llvm::StringRef value) {
42 error.SetErrorString("SetSubValue is not supported");
43 return error;
44}
45
48 return static_cast<OptionValueBoolean *>(this);
49 return nullptr;
50}
51
54 return static_cast<const OptionValueBoolean *>(this);
55 return nullptr;
56}
57
60 return static_cast<const OptionValueChar *>(this);
61 return nullptr;
62}
63
66 return static_cast<OptionValueChar *>(this);
67 return nullptr;
68}
69
72 return static_cast<OptionValueFileSpec *>(this);
73 return nullptr;
74}
75
78 return static_cast<const OptionValueFileSpec *>(this);
79 return nullptr;
80}
81
84 return static_cast<OptionValueFileSpecList *>(this);
85 return nullptr;
86}
87
90 return static_cast<const OptionValueFileSpecList *>(this);
91 return nullptr;
92}
93
96 return static_cast<OptionValueArch *>(this);
97 return nullptr;
98}
99
102 return static_cast<const OptionValueArch *>(this);
103 return nullptr;
104}
105
108 return static_cast<OptionValueArray *>(this);
109 return nullptr;
110}
111
114 return static_cast<const OptionValueArray *>(this);
115 return nullptr;
116}
117
120 return static_cast<OptionValueArgs *>(this);
121 return nullptr;
122}
123
126 return static_cast<const OptionValueArgs *>(this);
127 return nullptr;
128}
129
132 return static_cast<OptionValueDictionary *>(this);
133 return nullptr;
134}
135
138 return static_cast<const OptionValueDictionary *>(this);
139 return nullptr;
140}
141
144 return static_cast<OptionValueEnumeration *>(this);
145 return nullptr;
146}
147
150 return static_cast<const OptionValueEnumeration *>(this);
151 return nullptr;
152}
153
156 return static_cast<OptionValueFormat *>(this);
157 return nullptr;
158}
159
162 return static_cast<const OptionValueFormat *>(this);
163 return nullptr;
164}
165
168 return static_cast<OptionValueLanguage *>(this);
169 return nullptr;
170}
171
174 return static_cast<const OptionValueLanguage *>(this);
175 return nullptr;
176}
177
180 return static_cast<OptionValueFormatEntity *>(this);
181 return nullptr;
182}
183
186 return static_cast<const OptionValueFormatEntity *>(this);
187 return nullptr;
188}
189
192 return static_cast<OptionValuePathMappings *>(this);
193 return nullptr;
194}
195
198 return static_cast<const OptionValuePathMappings *>(this);
199 return nullptr;
200}
201
204 return static_cast<OptionValueProperties *>(this);
205 return nullptr;
206}
207
210 return static_cast<const OptionValueProperties *>(this);
211 return nullptr;
212}
213
216 return static_cast<OptionValueRegex *>(this);
217 return nullptr;
218}
219
222 return static_cast<const OptionValueRegex *>(this);
223 return nullptr;
224}
225
228 return static_cast<OptionValueSInt64 *>(this);
229 return nullptr;
230}
231
234 return static_cast<const OptionValueSInt64 *>(this);
235 return nullptr;
236}
237
240 return static_cast<OptionValueString *>(this);
241 return nullptr;
242}
243
246 return static_cast<const OptionValueString *>(this);
247 return nullptr;
248}
249
252 return static_cast<OptionValueUInt64 *>(this);
253 return nullptr;
254}
255
258 return static_cast<const OptionValueUInt64 *>(this);
259 return nullptr;
260}
261
264 return static_cast<OptionValueUUID *>(this);
265 return nullptr;
266}
267
270 return static_cast<const OptionValueUUID *>(this);
271 return nullptr;
272}
273
274bool OptionValue::GetBooleanValue(bool fail_value) const {
275 const OptionValueBoolean *option_value = GetAsBoolean();
276 if (option_value)
277 return option_value->GetCurrentValue();
278 return fail_value;
279}
280
281bool OptionValue::SetBooleanValue(bool new_value) {
282 OptionValueBoolean *option_value = GetAsBoolean();
283 if (option_value) {
284 option_value->SetCurrentValue(new_value);
285 return true;
286 }
287 return false;
288}
289
290char OptionValue::GetCharValue(char fail_value) const {
291 const OptionValueChar *option_value = GetAsChar();
292 if (option_value)
293 return option_value->GetCurrentValue();
294 return fail_value;
295}
296
297char OptionValue::SetCharValue(char new_value) {
298 OptionValueChar *option_value = GetAsChar();
299 if (option_value) {
300 option_value->SetCurrentValue(new_value);
301 return true;
302 }
303 return false;
304}
305
306int64_t OptionValue::GetEnumerationValue(int64_t fail_value) const {
307 const OptionValueEnumeration *option_value = GetAsEnumeration();
308 if (option_value)
309 return option_value->GetCurrentValue();
310 return fail_value;
311}
312
315 if (option_value) {
316 option_value->SetCurrentValue(value);
317 return true;
318 }
319 return false;
320}
321
323 const OptionValueFileSpec *option_value = GetAsFileSpec();
324 if (option_value)
325 return option_value->GetCurrentValue();
326 return FileSpec();
327}
328
330 OptionValueFileSpec *option_value = GetAsFileSpec();
331 if (option_value) {
332 option_value->SetCurrentValue(file_spec, false);
333 return true;
334 }
335 return false;
336}
337
339 const OptionValueFileSpecList *option_value = GetAsFileSpecList();
340 if (option_value)
341 return option_value->GetCurrentValue();
342 return FileSpecList();
343}
344
346 const OptionValueFormat *option_value = GetAsFormat();
347 if (option_value)
348 return option_value->GetCurrentValue();
349 return fail_value;
350}
351
353 OptionValueFormat *option_value = GetAsFormat();
354 if (option_value) {
355 option_value->SetCurrentValue(new_value);
356 return true;
357 }
358 return false;
359}
360
363 const OptionValueLanguage *option_value = GetAsLanguage();
364 if (option_value)
365 return option_value->GetCurrentValue();
366 return fail_value;
367}
368
370 OptionValueLanguage *option_value = GetAsLanguage();
371 if (option_value) {
372 option_value->SetCurrentValue(new_language);
373 return true;
374 }
375 return false;
376}
377
379 const OptionValueFormatEntity *option_value = GetAsFormatEntity();
380 if (option_value)
381 return &option_value->GetCurrentValue();
382 return nullptr;
383}
384
386 const OptionValueRegex *option_value = GetAsRegex();
387 if (option_value)
388 return option_value->GetCurrentValue();
389 return nullptr;
390}
391
392int64_t OptionValue::GetSInt64Value(int64_t fail_value) const {
393 const OptionValueSInt64 *option_value = GetAsSInt64();
394 if (option_value)
395 return option_value->GetCurrentValue();
396 return fail_value;
397}
398
399bool OptionValue::SetSInt64Value(int64_t new_value) {
400 OptionValueSInt64 *option_value = GetAsSInt64();
401 if (option_value) {
402 option_value->SetCurrentValue(new_value);
403 return true;
404 }
405 return false;
406}
407
408llvm::StringRef OptionValue::GetStringValue(llvm::StringRef fail_value) const {
409 const OptionValueString *option_value = GetAsString();
410 if (option_value)
411 return option_value->GetCurrentValueAsRef();
412 return fail_value;
413}
414
415bool OptionValue::SetStringValue(llvm::StringRef new_value) {
416 OptionValueString *option_value = GetAsString();
417 if (option_value) {
418 option_value->SetCurrentValue(new_value);
419 return true;
420 }
421 return false;
422}
423
424uint64_t OptionValue::GetUInt64Value(uint64_t fail_value) const {
425 const OptionValueUInt64 *option_value = GetAsUInt64();
426 if (option_value)
427 return option_value->GetCurrentValue();
428 return fail_value;
429}
430
431bool OptionValue::SetUInt64Value(uint64_t new_value) {
432 OptionValueUInt64 *option_value = GetAsUInt64();
433 if (option_value) {
434 option_value->SetCurrentValue(new_value);
435 return true;
436 }
437 return false;
438}
439
441 const OptionValueUUID *option_value = GetAsUUID();
442 if (option_value)
443 return option_value->GetCurrentValue();
444 return UUID();
445}
446
448 OptionValueUUID *option_value = GetAsUUID();
449 if (option_value) {
450 option_value->SetCurrentValue(uuid);
451 return true;
452 }
453 return false;
454}
455
457 switch (t) {
458 case eTypeInvalid:
459 return "invalid";
460 case eTypeArch:
461 return "arch";
462 case eTypeArgs:
463 return "arguments";
464 case eTypeArray:
465 return "array";
466 case eTypeBoolean:
467 return "boolean";
468 case eTypeChar:
469 return "char";
470 case eTypeDictionary:
471 return "dictionary";
472 case eTypeEnum:
473 return "enum";
475 return "file:line:column specifier";
476 case eTypeFileSpec:
477 return "file";
479 return "file-list";
480 case eTypeFormat:
481 return "format";
483 return "format-string";
484 case eTypeLanguage:
485 return "language";
486 case eTypePathMap:
487 return "path-map";
488 case eTypeProperties:
489 return "properties";
490 case eTypeRegex:
491 return "regex";
492 case eTypeSInt64:
493 return "int";
494 case eTypeString:
495 return "string";
496 case eTypeUInt64:
497 return "unsigned";
498 case eTypeUUID:
499 return "uuid";
500 }
501 return nullptr;
502}
503
505 const char *value_cstr, uint32_t type_mask, Status &error) {
506 // If only 1 bit is set in the type mask for a dictionary or array then we
507 // know how to decode a value from a cstring
508 lldb::OptionValueSP value_sp;
509 switch (type_mask) {
510 case 1u << eTypeArch:
511 value_sp = std::make_shared<OptionValueArch>();
512 break;
513 case 1u << eTypeBoolean:
514 value_sp = std::make_shared<OptionValueBoolean>(false);
515 break;
516 case 1u << eTypeChar:
517 value_sp = std::make_shared<OptionValueChar>('\0');
518 break;
519 case 1u << eTypeFileSpec:
520 value_sp = std::make_shared<OptionValueFileSpec>();
521 break;
522 case 1u << eTypeFormat:
523 value_sp = std::make_shared<OptionValueFormat>(eFormatInvalid);
524 break;
525 case 1u << eTypeFormatEntity:
526 value_sp = std::make_shared<OptionValueFormatEntity>(nullptr);
527 break;
528 case 1u << eTypeLanguage:
529 value_sp = std::make_shared<OptionValueLanguage>(eLanguageTypeUnknown);
530 break;
531 case 1u << eTypeSInt64:
532 value_sp = std::make_shared<OptionValueSInt64>();
533 break;
534 case 1u << eTypeString:
535 value_sp = std::make_shared<OptionValueString>();
536 break;
537 case 1u << eTypeUInt64:
538 value_sp = std::make_shared<OptionValueUInt64>();
539 break;
540 case 1u << eTypeUUID:
541 value_sp = std::make_shared<OptionValueUUID>();
542 break;
543 }
544
545 if (value_sp)
546 error = value_sp->SetValueFromString(value_cstr, eVarSetOperationAssign);
547 else
548 error.SetErrorString("unsupported type mask");
549 return value_sp;
550}
551
553 bool dumped_something = false;
554 lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
555 if (m_parent_sp) {
556 if (m_parent_sp->DumpQualifiedName(strm))
557 dumped_something = true;
558 }
559 ConstString name(GetName());
560 if (name) {
561 if (dumped_something)
562 strm.PutChar('.');
563 else
564 dumped_something = true;
565 strm << name;
566 }
567 return dumped_something;
568}
569
570OptionValueSP OptionValue::DeepCopy(const OptionValueSP &new_parent) const {
571 auto clone = Clone();
572 clone->SetParent(new_parent);
573 return clone;
574}
575
577 CompletionRequest &request) {}
578
582 switch (op) {
584 error.SetErrorStringWithFormat(
585 "%s objects do not support the 'replace' operation",
587 break;
589 error.SetErrorStringWithFormat(
590 "%s objects do not support the 'insert-before' operation",
592 break;
594 error.SetErrorStringWithFormat(
595 "%s objects do not support the 'insert-after' operation",
597 break;
599 error.SetErrorStringWithFormat(
600 "%s objects do not support the 'remove' operation", GetTypeAsCString());
601 break;
603 error.SetErrorStringWithFormat(
604 "%s objects do not support the 'append' operation", GetTypeAsCString());
605 break;
607 error.SetErrorStringWithFormat(
608 "%s objects do not support the 'clear' operation", GetTypeAsCString());
609 break;
611 error.SetErrorStringWithFormat(
612 "%s objects do not support the 'assign' operation", GetTypeAsCString());
613 break;
615 error.SetErrorStringWithFormat("invalid operation performed on a %s object",
617 break;
618 }
619 return error;
620}
static llvm::raw_ostream & error(Stream &strm)
"lldb/Utility/ArgCompletionRequest.h"
A uniqued constant string class.
Definition: ConstString.h:39
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition: FileSpec.h:56
void SetCurrentValue(char value)
void SetCurrentValue(const FileSpec &value, bool set_value_was_set)
void SetCurrentValue(lldb::Format value)
lldb::Format GetCurrentValue() const
lldb::LanguageType GetCurrentValue() const
void SetCurrentValue(lldb::LanguageType value)
const RegularExpression * GetCurrentValue() const
bool SetCurrentValue(int64_t value)
llvm::StringRef GetCurrentValueAsRef() const
Status SetCurrentValue(llvm::StringRef value)
void SetCurrentValue(uint64_t value)
void SetCurrentValue(const UUID &value)
virtual bool DumpQualifiedName(Stream &strm) const
OptionValueDictionary * GetAsDictionary()
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
OptionValueSInt64 * GetAsSInt64()
static lldb::OptionValueSP CreateValueFromCStringForTypeMask(const char *value_cstr, uint32_t type_mask, Status &error)
llvm::StringRef GetStringValue() const
Definition: OptionValue.h:302
FileSpecList GetFileSpecListValue() const
virtual lldb::OptionValueSP Clone() const =0
virtual Type GetType() const =0
lldb::OptionValueWP m_parent_wp
Definition: OptionValue.h:340
OptionValueFileSpecList * GetAsFileSpecList()
Definition: OptionValue.cpp:82
OptionValueRegex * GetAsRegex()
uint64_t GetUInt64Value(uint64_t fail_value, bool *success_ptr)
Definition: OptionValue.cpp:20
lldb::Format GetFormatValue(lldb::Format fail_value=lldb::eFormatDefault) const
OptionValueUInt64 * GetAsUInt64()
char GetCharValue(char fail_value) const
OptionValueFormatEntity * GetAsFormatEntity()
char SetCharValue(char new_value)
OptionValuePathMappings * GetAsPathMappings()
virtual void AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request)
OptionValueProperties * GetAsProperties()
OptionValueEnumeration * GetAsEnumeration()
virtual lldb::OptionValueSP DeepCopy(const lldb::OptionValueSP &new_parent) const
int64_t GetEnumerationValue(int64_t fail_value=-1) const
static const char * GetBuiltinTypeAsCString(Type t)
OptionValueFormat * GetAsFormat()
virtual ConstString GetName() const
Definition: OptionValue.h:123
bool GetBooleanValue(bool fail_value=false) const
OptionValueArgs * GetAsArgs()
virtual const char * GetTypeAsCString() const
Definition: OptionValue.h:77
OptionValueChar * GetAsChar()
Definition: OptionValue.cpp:64
OptionValueArray * GetAsArray()
lldb::LanguageType GetLanguageValue(lldb::LanguageType fail_value=lldb::eLanguageTypeUnknown) const
bool SetStringValue(llvm::StringRef new_value)
bool SetUUIDValue(const UUID &uuid)
int64_t GetSInt64Value(int64_t fail_value=0) const
bool SetBooleanValue(bool new_value)
OptionValueBoolean * GetAsBoolean()
Definition: OptionValue.cpp:46
OptionValueFileSpec * GetAsFileSpec()
Definition: OptionValue.cpp:70
FileSpec GetFileSpecValue() const
const RegularExpression * GetRegexValue() const
const FormatEntity::Entry * GetFormatEntity() const
bool SetEnumerationValue(int64_t value)
OptionValueUUID * GetAsUUID()
bool SetUInt64Value(uint64_t new_value)
OptionValueArch * GetAsArch()
Definition: OptionValue.cpp:94
bool SetFormatValue(lldb::Format new_value)
bool SetLanguageValue(lldb::LanguageType new_language)
OptionValueLanguage * GetAsLanguage()
bool SetSInt64Value(int64_t new_value)
virtual Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef name, llvm::StringRef value)
Definition: OptionValue.cpp:38
OptionValueString * GetAsString()
bool SetFileSpecValue(const FileSpec &file_spec)
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t PutChar(char ch)
Definition: Stream.cpp:104
A class that represents a running process on the host machine.
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
VarSetOperationType
Settable state variable types.
Definition: SBAddress.h:15
Format
Display format definitions.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.