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
19 VarSetOperationType op, llvm::StringRef name,
20 llvm::StringRef value) {
22 error.SetErrorString("SetSubValue is not supported");
23 return error;
24}
25
28 return static_cast<OptionValueBoolean *>(this);
29 return nullptr;
30}
31
34 return static_cast<const OptionValueBoolean *>(this);
35 return nullptr;
36}
37
40 return static_cast<const OptionValueChar *>(this);
41 return nullptr;
42}
43
46 return static_cast<OptionValueChar *>(this);
47 return nullptr;
48}
49
52 return static_cast<OptionValueFileSpec *>(this);
53 return nullptr;
54}
55
58 return static_cast<const OptionValueFileSpec *>(this);
59 return nullptr;
60}
61
64 return static_cast<OptionValueFileSpecList *>(this);
65 return nullptr;
66}
67
70 return static_cast<const OptionValueFileSpecList *>(this);
71 return nullptr;
72}
73
76 return static_cast<OptionValueArch *>(this);
77 return nullptr;
78}
79
82 return static_cast<const OptionValueArch *>(this);
83 return nullptr;
84}
85
88 return static_cast<OptionValueArray *>(this);
89 return nullptr;
90}
91
94 return static_cast<const OptionValueArray *>(this);
95 return nullptr;
96}
97
100 return static_cast<OptionValueArgs *>(this);
101 return nullptr;
102}
103
106 return static_cast<const OptionValueArgs *>(this);
107 return nullptr;
108}
109
112 return static_cast<OptionValueDictionary *>(this);
113 return nullptr;
114}
115
118 return static_cast<const OptionValueDictionary *>(this);
119 return nullptr;
120}
121
124 return static_cast<OptionValueEnumeration *>(this);
125 return nullptr;
126}
127
130 return static_cast<const OptionValueEnumeration *>(this);
131 return nullptr;
132}
133
136 return static_cast<OptionValueFormat *>(this);
137 return nullptr;
138}
139
142 return static_cast<const OptionValueFormat *>(this);
143 return nullptr;
144}
145
148 return static_cast<OptionValueLanguage *>(this);
149 return nullptr;
150}
151
154 return static_cast<const OptionValueLanguage *>(this);
155 return nullptr;
156}
157
160 return static_cast<OptionValueFormatEntity *>(this);
161 return nullptr;
162}
163
166 return static_cast<const OptionValueFormatEntity *>(this);
167 return nullptr;
168}
169
172 return static_cast<OptionValuePathMappings *>(this);
173 return nullptr;
174}
175
178 return static_cast<const OptionValuePathMappings *>(this);
179 return nullptr;
180}
181
184 return static_cast<OptionValueProperties *>(this);
185 return nullptr;
186}
187
190 return static_cast<const OptionValueProperties *>(this);
191 return nullptr;
192}
193
196 return static_cast<OptionValueRegex *>(this);
197 return nullptr;
198}
199
202 return static_cast<const OptionValueRegex *>(this);
203 return nullptr;
204}
205
208 return static_cast<OptionValueSInt64 *>(this);
209 return nullptr;
210}
211
214 return static_cast<const OptionValueSInt64 *>(this);
215 return nullptr;
216}
217
220 return static_cast<OptionValueString *>(this);
221 return nullptr;
222}
223
226 return static_cast<const OptionValueString *>(this);
227 return nullptr;
228}
229
232 return static_cast<OptionValueUInt64 *>(this);
233 return nullptr;
234}
235
238 return static_cast<const OptionValueUInt64 *>(this);
239 return nullptr;
240}
241
244 return static_cast<OptionValueUUID *>(this);
245 return nullptr;
246}
247
250 return static_cast<const OptionValueUUID *>(this);
251 return nullptr;
252}
253
254std::optional<bool> OptionValue::GetBooleanValue() const {
255 if (const OptionValueBoolean *option_value = GetAsBoolean())
256 return option_value->GetCurrentValue();
257 return {};
258}
259
260bool OptionValue::SetBooleanValue(bool new_value) {
261 if (OptionValueBoolean *option_value = GetAsBoolean()) {
262 option_value->SetCurrentValue(new_value);
263 return true;
264 }
265 return false;
266}
267
268std::optional<char> OptionValue::GetCharValue() const {
269 if (const OptionValueChar *option_value = GetAsChar())
270 return option_value->GetCurrentValue();
271 return {};
272}
273
274bool OptionValue::SetCharValue(char new_value) {
275 if (OptionValueChar *option_value = GetAsChar()) {
276 option_value->SetCurrentValue(new_value);
277 return true;
278 }
279 return false;
280}
281
282std::optional<int64_t> OptionValue::GetEnumerationValue() const {
283 if (const OptionValueEnumeration *option_value = GetAsEnumeration())
284 return option_value->GetCurrentValue();
285 return {};
286}
287
289 if (OptionValueEnumeration *option_value = GetAsEnumeration()) {
290 option_value->SetCurrentValue(value);
291 return true;
292 }
293 return false;
294}
295
296std::optional<FileSpec> OptionValue::GetFileSpecValue() const {
297 if (const OptionValueFileSpec *option_value = GetAsFileSpec())
298 return option_value->GetCurrentValue();
299 return {};
300}
301
303 if (OptionValueFileSpec *option_value = GetAsFileSpec()) {
304 option_value->SetCurrentValue(file_spec, false);
305 return true;
306 }
307 return false;
308}
309
311 if (OptionValueFileSpecList *option_value = GetAsFileSpecList()) {
312 option_value->AppendCurrentValue(file_spec);
313 return true;
314 }
315 return false;
316}
317
318std::optional<FileSpecList> OptionValue::GetFileSpecListValue() const {
319 if (const OptionValueFileSpecList *option_value = GetAsFileSpecList())
320 return option_value->GetCurrentValue();
321 return {};
322}
323
324std::optional<lldb::Format> OptionValue::GetFormatValue() const {
325 if (const OptionValueFormat *option_value = GetAsFormat())
326 return option_value->GetCurrentValue();
327 return {};
328}
329
331 if (OptionValueFormat *option_value = GetAsFormat()) {
332 option_value->SetCurrentValue(new_value);
333 return true;
334 }
335 return false;
336}
337
338std::optional<lldb::LanguageType> OptionValue::GetLanguageValue() const {
339 if (const OptionValueLanguage *option_value = GetAsLanguage())
340 return option_value->GetCurrentValue();
341 return {};
342}
343
345 if (OptionValueLanguage *option_value = GetAsLanguage()) {
346 option_value->SetCurrentValue(new_language);
347 return true;
348 }
349 return false;
350}
351
353 if (const OptionValueFormatEntity *option_value = GetAsFormatEntity())
354 return &option_value->GetCurrentValue();
355 return nullptr;
356}
357
359 if (const OptionValueRegex *option_value = GetAsRegex())
360 return option_value->GetCurrentValue();
361 return nullptr;
362}
363
364std::optional<int64_t> OptionValue::GetSInt64Value() const {
365 if (const OptionValueSInt64 *option_value = GetAsSInt64())
366 return option_value->GetCurrentValue();
367 return {};
368}
369
370bool OptionValue::SetSInt64Value(int64_t new_value) {
371 if (OptionValueSInt64 *option_value = GetAsSInt64()) {
372 option_value->SetCurrentValue(new_value);
373 return true;
374 }
375 return false;
376}
377
378std::optional<llvm::StringRef> OptionValue::GetStringValue() const {
379 if (const OptionValueString *option_value = GetAsString())
380 return option_value->GetCurrentValueAsRef();
381 return {};
382}
383
384bool OptionValue::SetStringValue(llvm::StringRef new_value) {
385 if (OptionValueString *option_value = GetAsString()) {
386 option_value->SetCurrentValue(new_value);
387 return true;
388 }
389 return false;
390}
391
392std::optional<uint64_t> OptionValue::GetUInt64Value() const {
393 if (const OptionValueUInt64 *option_value = GetAsUInt64())
394 return option_value->GetCurrentValue();
395 return {};
396}
397
398bool OptionValue::SetUInt64Value(uint64_t new_value) {
399 if (OptionValueUInt64 *option_value = GetAsUInt64()) {
400 option_value->SetCurrentValue(new_value);
401 return true;
402 }
403 return false;
404}
405
406std::optional<UUID> OptionValue::GetUUIDValue() const {
407 if (const OptionValueUUID *option_value = GetAsUUID())
408 return option_value->GetCurrentValue();
409 return {};
410}
411
413 if (OptionValueUUID *option_value = GetAsUUID()) {
414 option_value->SetCurrentValue(uuid);
415 return true;
416 }
417 return false;
418}
419
420std::optional<ArchSpec> OptionValue::GetArchSpecValue() const {
421 if (const OptionValueArch *option_value = GetAsArch())
422 return option_value->GetCurrentValue();
423 return {};
424}
425
427 if (OptionValueArch *option_value = GetAsArch()) {
428 option_value->SetCurrentValue(arch_spec, false);
429 return true;
430 }
431 return false;
432}
433
435 switch (t) {
436 case eTypeInvalid:
437 return "invalid";
438 case eTypeArch:
439 return "arch";
440 case eTypeArgs:
441 return "arguments";
442 case eTypeArray:
443 return "array";
444 case eTypeBoolean:
445 return "boolean";
446 case eTypeChar:
447 return "char";
448 case eTypeDictionary:
449 return "dictionary";
450 case eTypeEnum:
451 return "enum";
453 return "file:line:column specifier";
454 case eTypeFileSpec:
455 return "file";
457 return "file-list";
458 case eTypeFormat:
459 return "format";
461 return "format-string";
462 case eTypeLanguage:
463 return "language";
464 case eTypePathMap:
465 return "path-map";
466 case eTypeProperties:
467 return "properties";
468 case eTypeRegex:
469 return "regex";
470 case eTypeSInt64:
471 return "int";
472 case eTypeString:
473 return "string";
474 case eTypeUInt64:
475 return "unsigned";
476 case eTypeUUID:
477 return "uuid";
478 }
479 return nullptr;
480}
481
483 const char *value_cstr, uint32_t type_mask, Status &error) {
484 // If only 1 bit is set in the type mask for a dictionary or array then we
485 // know how to decode a value from a cstring
486 lldb::OptionValueSP value_sp;
487 switch (type_mask) {
488 case 1u << eTypeArch:
489 value_sp = std::make_shared<OptionValueArch>();
490 break;
491 case 1u << eTypeBoolean:
492 value_sp = std::make_shared<OptionValueBoolean>(false);
493 break;
494 case 1u << eTypeChar:
495 value_sp = std::make_shared<OptionValueChar>('\0');
496 break;
497 case 1u << eTypeFileSpec:
498 value_sp = std::make_shared<OptionValueFileSpec>();
499 break;
500 case 1u << eTypeFormat:
501 value_sp = std::make_shared<OptionValueFormat>(eFormatInvalid);
502 break;
503 case 1u << eTypeFormatEntity:
504 value_sp = std::make_shared<OptionValueFormatEntity>(nullptr);
505 break;
506 case 1u << eTypeLanguage:
507 value_sp = std::make_shared<OptionValueLanguage>(eLanguageTypeUnknown);
508 break;
509 case 1u << eTypeSInt64:
510 value_sp = std::make_shared<OptionValueSInt64>();
511 break;
512 case 1u << eTypeString:
513 value_sp = std::make_shared<OptionValueString>();
514 break;
515 case 1u << eTypeUInt64:
516 value_sp = std::make_shared<OptionValueUInt64>();
517 break;
518 case 1u << eTypeUUID:
519 value_sp = std::make_shared<OptionValueUUID>();
520 break;
521 }
522
523 if (value_sp)
524 error = value_sp->SetValueFromString(value_cstr, eVarSetOperationAssign);
525 else
526 error.SetErrorString("unsupported type mask");
527 return value_sp;
528}
529
531 bool dumped_something = false;
532 lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
533 if (m_parent_sp) {
534 if (m_parent_sp->DumpQualifiedName(strm))
535 dumped_something = true;
536 }
537 ConstString name(GetName());
538 if (name) {
539 if (dumped_something)
540 strm.PutChar('.');
541 else
542 dumped_something = true;
543 strm << name;
544 }
545 return dumped_something;
546}
547
548OptionValueSP OptionValue::DeepCopy(const OptionValueSP &new_parent) const {
549 auto clone = Clone();
550 clone->SetParent(new_parent);
551 return clone;
552}
553
555 CompletionRequest &request) {}
556
560 switch (op) {
562 error.SetErrorStringWithFormat(
563 "%s objects do not support the 'replace' operation",
565 break;
567 error.SetErrorStringWithFormat(
568 "%s objects do not support the 'insert-before' operation",
570 break;
572 error.SetErrorStringWithFormat(
573 "%s objects do not support the 'insert-after' operation",
575 break;
577 error.SetErrorStringWithFormat(
578 "%s objects do not support the 'remove' operation", GetTypeAsCString());
579 break;
581 error.SetErrorStringWithFormat(
582 "%s objects do not support the 'append' operation", GetTypeAsCString());
583 break;
585 error.SetErrorStringWithFormat(
586 "%s objects do not support the 'clear' operation", GetTypeAsCString());
587 break;
589 error.SetErrorStringWithFormat(
590 "%s objects do not support the 'assign' operation", GetTypeAsCString());
591 break;
593 error.SetErrorStringWithFormat("invalid operation performed on a %s object",
595 break;
596 }
597 return error;
598}
static llvm::raw_ostream & error(Stream &strm)
An architecture specification class.
Definition: ArchSpec.h:31
"lldb/Utility/ArgCompletionRequest.h"
A uniqued constant string class.
Definition: ConstString.h:40
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition: FileSpec.h:56
virtual bool DumpQualifiedName(Stream &strm) const
std::optional< char > GetCharValue() const
std::optional< FileSpecList > GetFileSpecListValue() const
bool SetArchSpecValue(ArchSpec arch_spec)
std::optional< ArchSpec > GetArchSpecValue() const
OptionValueDictionary * GetAsDictionary()
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
OptionValueSInt64 * GetAsSInt64()
std::optional< FileSpec > GetFileSpecValue() const
static lldb::OptionValueSP CreateValueFromCStringForTypeMask(const char *value_cstr, uint32_t type_mask, Status &error)
std::optional< uint64_t > GetUInt64Value() const
bool SetFileSpecValue(FileSpec file_spec)
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:62
OptionValueRegex * GetAsRegex()
OptionValueUInt64 * GetAsUInt64()
OptionValueFormatEntity * GetAsFormatEntity()
bool 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
static const char * GetBuiltinTypeAsCString(Type t)
OptionValueFormat * GetAsFormat()
OptionValueArgs * GetAsArgs()
Definition: OptionValue.cpp:98
virtual const char * GetTypeAsCString() const
Definition: OptionValue.h:82
OptionValueChar * GetAsChar()
Definition: OptionValue.cpp:44
bool AppendFileSpecValue(FileSpec file_spec)
OptionValueArray * GetAsArray()
Definition: OptionValue.cpp:86
std::optional< lldb::LanguageType > GetLanguageValue() const
bool SetStringValue(llvm::StringRef new_value)
std::optional< int64_t > GetSInt64Value() const
bool SetUUIDValue(const UUID &uuid)
std::optional< lldb::Format > GetFormatValue() const
std::optional< int64_t > GetEnumerationValue() const
std::optional< bool > GetBooleanValue() const
bool SetBooleanValue(bool new_value)
std::optional< llvm::StringRef > GetStringValue() const
OptionValueBoolean * GetAsBoolean()
Definition: OptionValue.cpp:26
OptionValueFileSpec * GetAsFileSpec()
Definition: OptionValue.cpp:50
const RegularExpression * GetRegexValue() const
const FormatEntity::Entry * GetFormatEntity() const
bool SetEnumerationValue(int64_t value)
OptionValueUUID * GetAsUUID()
bool SetUInt64Value(uint64_t new_value)
virtual llvm::StringRef GetName() const
Definition: OptionValue.h:128
OptionValueArch * GetAsArch()
Definition: OptionValue.cpp:74
bool SetFormatValue(lldb::Format new_value)
bool SetLanguageValue(lldb::LanguageType new_language)
OptionValueLanguage * GetAsLanguage()
std::optional< UUID > GetUUIDValue() const
bool SetSInt64Value(int64_t new_value)
virtual Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef name, llvm::StringRef value)
Definition: OptionValue.cpp:18
OptionValueString * GetAsString()
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.
Definition: SBAttachInfo.h:14
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.