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 std::lock_guard<std::mutex> lock(other.m_mutex);
20
22 m_callback = other.m_callback;
24
25}
26
28 std::scoped_lock<std::mutex, std::mutex> lock(m_mutex, other.m_mutex);
29
31 m_callback = other.m_callback;
33
34 return *this;
35}
36
38 VarSetOperationType op, llvm::StringRef name,
39 llvm::StringRef value) {
41 error.SetErrorString("SetSubValue is not supported");
42 return error;
43}
44
47 return static_cast<OptionValueBoolean *>(this);
48 return nullptr;
49}
50
53 return static_cast<const OptionValueBoolean *>(this);
54 return nullptr;
55}
56
59 return static_cast<const OptionValueChar *>(this);
60 return nullptr;
61}
62
65 return static_cast<OptionValueChar *>(this);
66 return nullptr;
67}
68
71 return static_cast<OptionValueFileSpec *>(this);
72 return nullptr;
73}
74
77 return static_cast<const OptionValueFileSpec *>(this);
78 return nullptr;
79}
80
83 return static_cast<OptionValueFileSpecList *>(this);
84 return nullptr;
85}
86
89 return static_cast<const OptionValueFileSpecList *>(this);
90 return nullptr;
91}
92
95 return static_cast<OptionValueArch *>(this);
96 return nullptr;
97}
98
101 return static_cast<const OptionValueArch *>(this);
102 return nullptr;
103}
104
107 return static_cast<OptionValueArray *>(this);
108 return nullptr;
109}
110
113 return static_cast<const OptionValueArray *>(this);
114 return nullptr;
115}
116
119 return static_cast<OptionValueArgs *>(this);
120 return nullptr;
121}
122
125 return static_cast<const OptionValueArgs *>(this);
126 return nullptr;
127}
128
131 return static_cast<OptionValueDictionary *>(this);
132 return nullptr;
133}
134
137 return static_cast<const OptionValueDictionary *>(this);
138 return nullptr;
139}
140
143 return static_cast<OptionValueEnumeration *>(this);
144 return nullptr;
145}
146
149 return static_cast<const OptionValueEnumeration *>(this);
150 return nullptr;
151}
152
155 return static_cast<OptionValueFormat *>(this);
156 return nullptr;
157}
158
161 return static_cast<const OptionValueFormat *>(this);
162 return nullptr;
163}
164
167 return static_cast<OptionValueLanguage *>(this);
168 return nullptr;
169}
170
173 return static_cast<const OptionValueLanguage *>(this);
174 return nullptr;
175}
176
179 return static_cast<OptionValueFormatEntity *>(this);
180 return nullptr;
181}
182
185 return static_cast<const OptionValueFormatEntity *>(this);
186 return nullptr;
187}
188
191 return static_cast<OptionValuePathMappings *>(this);
192 return nullptr;
193}
194
197 return static_cast<const OptionValuePathMappings *>(this);
198 return nullptr;
199}
200
203 return static_cast<OptionValueProperties *>(this);
204 return nullptr;
205}
206
209 return static_cast<const OptionValueProperties *>(this);
210 return nullptr;
211}
212
215 return static_cast<OptionValueRegex *>(this);
216 return nullptr;
217}
218
221 return static_cast<const OptionValueRegex *>(this);
222 return nullptr;
223}
224
227 return static_cast<OptionValueSInt64 *>(this);
228 return nullptr;
229}
230
233 return static_cast<const OptionValueSInt64 *>(this);
234 return nullptr;
235}
236
239 return static_cast<OptionValueString *>(this);
240 return nullptr;
241}
242
245 return static_cast<const OptionValueString *>(this);
246 return nullptr;
247}
248
251 return static_cast<OptionValueUInt64 *>(this);
252 return nullptr;
253}
254
257 return static_cast<const OptionValueUInt64 *>(this);
258 return nullptr;
259}
260
263 return static_cast<OptionValueUUID *>(this);
264 return nullptr;
265}
266
269 return static_cast<const OptionValueUUID *>(this);
270 return nullptr;
271}
272
273std::optional<bool> OptionValue::GetBooleanValue() const {
274 std::lock_guard<std::mutex> lock(m_mutex);
275 if (const OptionValueBoolean *option_value = GetAsBoolean())
276 return option_value->GetCurrentValue();
277 return {};
278}
279
280bool OptionValue::SetBooleanValue(bool new_value) {
281 std::lock_guard<std::mutex> lock(m_mutex);
282 if (OptionValueBoolean *option_value = GetAsBoolean()) {
283 option_value->SetCurrentValue(new_value);
284 return true;
285 }
286 return false;
287}
288
289std::optional<char> OptionValue::GetCharValue() const {
290 std::lock_guard<std::mutex> lock(m_mutex);
291 if (const OptionValueChar *option_value = GetAsChar())
292 return option_value->GetCurrentValue();
293 return {};
294}
295
296bool OptionValue::SetCharValue(char new_value) {
297 std::lock_guard<std::mutex> lock(m_mutex);
298 if (OptionValueChar *option_value = GetAsChar()) {
299 option_value->SetCurrentValue(new_value);
300 return true;
301 }
302 return false;
303}
304
305std::optional<int64_t> OptionValue::GetEnumerationValue() const {
306 std::lock_guard<std::mutex> lock(m_mutex);
307 if (const OptionValueEnumeration *option_value = GetAsEnumeration())
308 return option_value->GetCurrentValue();
309 return {};
310}
311
313 std::lock_guard<std::mutex> lock(m_mutex);
314 if (OptionValueEnumeration *option_value = GetAsEnumeration()) {
315 option_value->SetCurrentValue(value);
316 return true;
317 }
318 return false;
319}
320
321std::optional<FileSpec> OptionValue::GetFileSpecValue() const {
322 std::lock_guard<std::mutex> lock(m_mutex);
323 if (const OptionValueFileSpec *option_value = GetAsFileSpec())
324 return option_value->GetCurrentValue();
325 return {};
326}
327
329 std::lock_guard<std::mutex> lock(m_mutex);
330 if (OptionValueFileSpec *option_value = GetAsFileSpec()) {
331 option_value->SetCurrentValue(file_spec, false);
332 return true;
333 }
334 return false;
335}
336
338 std::lock_guard<std::mutex> lock(m_mutex);
339 if (OptionValueFileSpecList *option_value = GetAsFileSpecList()) {
340 option_value->AppendCurrentValue(file_spec);
341 return true;
342 }
343 return false;
344}
345
346std::optional<FileSpecList> OptionValue::GetFileSpecListValue() const {
347 std::lock_guard<std::mutex> lock(m_mutex);
348 if (const OptionValueFileSpecList *option_value = GetAsFileSpecList())
349 return option_value->GetCurrentValue();
350 return {};
351}
352
353std::optional<lldb::Format> OptionValue::GetFormatValue() const {
354 std::lock_guard<std::mutex> lock(m_mutex);
355 if (const OptionValueFormat *option_value = GetAsFormat())
356 return option_value->GetCurrentValue();
357 return {};
358}
359
361 std::lock_guard<std::mutex> lock(m_mutex);
362 if (OptionValueFormat *option_value = GetAsFormat()) {
363 option_value->SetCurrentValue(new_value);
364 return true;
365 }
366 return false;
367}
368
369std::optional<lldb::LanguageType> OptionValue::GetLanguageValue() const {
370 std::lock_guard<std::mutex> lock(m_mutex);
371 if (const OptionValueLanguage *option_value = GetAsLanguage())
372 return option_value->GetCurrentValue();
373 return {};
374}
375
377 std::lock_guard<std::mutex> lock(m_mutex);
378 if (OptionValueLanguage *option_value = GetAsLanguage()) {
379 option_value->SetCurrentValue(new_language);
380 return true;
381 }
382 return false;
383}
384
386 std::lock_guard<std::mutex> lock(m_mutex);
387 if (const OptionValueFormatEntity *option_value = GetAsFormatEntity())
388 return &option_value->GetCurrentValue();
389 return nullptr;
390}
391
393 std::lock_guard<std::mutex> lock(m_mutex);
394 if (const OptionValueRegex *option_value = GetAsRegex())
395 return option_value->GetCurrentValue();
396 return nullptr;
397}
398
399std::optional<int64_t> OptionValue::GetSInt64Value() const {
400 std::lock_guard<std::mutex> lock(m_mutex);
401 if (const OptionValueSInt64 *option_value = GetAsSInt64())
402 return option_value->GetCurrentValue();
403 return {};
404}
405
406bool OptionValue::SetSInt64Value(int64_t new_value) {
407 std::lock_guard<std::mutex> lock(m_mutex);
408 if (OptionValueSInt64 *option_value = GetAsSInt64()) {
409 option_value->SetCurrentValue(new_value);
410 return true;
411 }
412 return false;
413}
414
415std::optional<llvm::StringRef> OptionValue::GetStringValue() const {
416 std::lock_guard<std::mutex> lock(m_mutex);
417 if (const OptionValueString *option_value = GetAsString())
418 return option_value->GetCurrentValueAsRef();
419 return {};
420}
421
422bool OptionValue::SetStringValue(llvm::StringRef new_value) {
423 std::lock_guard<std::mutex> lock(m_mutex);
424 if (OptionValueString *option_value = GetAsString()) {
425 option_value->SetCurrentValue(new_value);
426 return true;
427 }
428 return false;
429}
430
431std::optional<uint64_t> OptionValue::GetUInt64Value() const {
432 std::lock_guard<std::mutex> lock(m_mutex);
433 if (const OptionValueUInt64 *option_value = GetAsUInt64())
434 return option_value->GetCurrentValue();
435 return {};
436}
437
438bool OptionValue::SetUInt64Value(uint64_t new_value) {
439 std::lock_guard<std::mutex> lock(m_mutex);
440 if (OptionValueUInt64 *option_value = GetAsUInt64()) {
441 option_value->SetCurrentValue(new_value);
442 return true;
443 }
444 return false;
445}
446
447std::optional<UUID> OptionValue::GetUUIDValue() const {
448 std::lock_guard<std::mutex> lock(m_mutex);
449 if (const OptionValueUUID *option_value = GetAsUUID())
450 return option_value->GetCurrentValue();
451 return {};
452}
453
455 std::lock_guard<std::mutex> lock(m_mutex);
456 if (OptionValueUUID *option_value = GetAsUUID()) {
457 option_value->SetCurrentValue(uuid);
458 return true;
459 }
460 return false;
461}
462
463std::optional<ArchSpec> OptionValue::GetArchSpecValue() const {
464 std::lock_guard<std::mutex> lock(m_mutex);
465 if (const OptionValueArch *option_value = GetAsArch())
466 return option_value->GetCurrentValue();
467 return {};
468}
469
471 std::lock_guard<std::mutex> lock(m_mutex);
472 if (OptionValueArch *option_value = GetAsArch()) {
473 option_value->SetCurrentValue(arch_spec, false);
474 return true;
475 }
476 return false;
477}
478
480 switch (t) {
481 case eTypeInvalid:
482 return "invalid";
483 case eTypeArch:
484 return "arch";
485 case eTypeArgs:
486 return "arguments";
487 case eTypeArray:
488 return "array";
489 case eTypeBoolean:
490 return "boolean";
491 case eTypeChar:
492 return "char";
493 case eTypeDictionary:
494 return "dictionary";
495 case eTypeEnum:
496 return "enum";
498 return "file:line:column specifier";
499 case eTypeFileSpec:
500 return "file";
502 return "file-list";
503 case eTypeFormat:
504 return "format";
506 return "format-string";
507 case eTypeLanguage:
508 return "language";
509 case eTypePathMap:
510 return "path-map";
511 case eTypeProperties:
512 return "properties";
513 case eTypeRegex:
514 return "regex";
515 case eTypeSInt64:
516 return "int";
517 case eTypeString:
518 return "string";
519 case eTypeUInt64:
520 return "unsigned";
521 case eTypeUUID:
522 return "uuid";
523 }
524 return nullptr;
525}
526
528 const char *value_cstr, uint32_t type_mask, Status &error) {
529 // If only 1 bit is set in the type mask for a dictionary or array then we
530 // know how to decode a value from a cstring
531 lldb::OptionValueSP value_sp;
532 switch (type_mask) {
533 case 1u << eTypeArch:
534 value_sp = std::make_shared<OptionValueArch>();
535 break;
536 case 1u << eTypeBoolean:
537 value_sp = std::make_shared<OptionValueBoolean>(false);
538 break;
539 case 1u << eTypeChar:
540 value_sp = std::make_shared<OptionValueChar>('\0');
541 break;
542 case 1u << eTypeFileSpec:
543 value_sp = std::make_shared<OptionValueFileSpec>();
544 break;
545 case 1u << eTypeFormat:
546 value_sp = std::make_shared<OptionValueFormat>(eFormatInvalid);
547 break;
548 case 1u << eTypeFormatEntity:
549 value_sp = std::make_shared<OptionValueFormatEntity>(nullptr);
550 break;
551 case 1u << eTypeLanguage:
552 value_sp = std::make_shared<OptionValueLanguage>(eLanguageTypeUnknown);
553 break;
554 case 1u << eTypeSInt64:
555 value_sp = std::make_shared<OptionValueSInt64>();
556 break;
557 case 1u << eTypeString:
558 value_sp = std::make_shared<OptionValueString>();
559 break;
560 case 1u << eTypeUInt64:
561 value_sp = std::make_shared<OptionValueUInt64>();
562 break;
563 case 1u << eTypeUUID:
564 value_sp = std::make_shared<OptionValueUUID>();
565 break;
566 }
567
568 if (value_sp)
569 error = value_sp->SetValueFromString(value_cstr, eVarSetOperationAssign);
570 else
571 error.SetErrorString("unsupported type mask");
572 return value_sp;
573}
574
576 bool dumped_something = false;
577 lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
578 if (m_parent_sp) {
579 if (m_parent_sp->DumpQualifiedName(strm))
580 dumped_something = true;
581 }
582 llvm::StringRef name(GetName());
583 if (!name.empty()) {
584 if (dumped_something)
585 strm.PutChar('.');
586 else
587 dumped_something = true;
588 strm << name;
589 }
590 return dumped_something;
591}
592
594 auto clone = Clone();
595 clone->SetParent(new_parent);
596 return clone;
597}
598
600 CompletionRequest &request) {}
601
605 switch (op) {
607 error.SetErrorStringWithFormat(
608 "%s objects do not support the 'replace' operation",
610 break;
612 error.SetErrorStringWithFormat(
613 "%s objects do not support the 'insert-before' operation",
615 break;
617 error.SetErrorStringWithFormat(
618 "%s objects do not support the 'insert-after' operation",
620 break;
622 error.SetErrorStringWithFormat(
623 "%s objects do not support the 'remove' operation", GetTypeAsCString());
624 break;
626 error.SetErrorStringWithFormat(
627 "%s objects do not support the 'append' operation", GetTypeAsCString());
628 break;
630 error.SetErrorStringWithFormat(
631 "%s objects do not support the 'clear' operation", GetTypeAsCString());
632 break;
634 error.SetErrorStringWithFormat(
635 "%s objects do not support the 'assign' operation", GetTypeAsCString());
636 break;
638 error.SetErrorStringWithFormat("invalid operation performed on a %s object",
640 break;
641 }
642 return error;
643}
static llvm::raw_ostream & error(Stream &strm)
An architecture specification class.
Definition: ArchSpec.h:31
"lldb/Utility/ArgCompletionRequest.h"
"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:344
OptionValueFileSpecList * GetAsFileSpecList()
Definition: OptionValue.cpp:81
OptionValueRegex * GetAsRegex()
OptionValueUInt64 * GetAsUInt64()
OptionValue & operator=(const OptionValue &other)
Definition: OptionValue.cpp:27
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()
virtual const char * GetTypeAsCString() const
Definition: OptionValue.h:87
OptionValueChar * GetAsChar()
Definition: OptionValue.cpp:63
bool AppendFileSpecValue(FileSpec file_spec)
OptionValueArray * GetAsArray()
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:45
OptionValueFileSpec * GetAsFileSpec()
Definition: OptionValue.cpp:69
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:132
OptionValueArch * GetAsArch()
Definition: OptionValue.cpp:93
bool SetFormatValue(lldb::Format new_value)
bool SetLanguageValue(lldb::LanguageType new_language)
std::function< void()> m_callback
Definition: OptionValue.h:345
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:37
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:131
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.
std::shared_ptr< lldb_private::OptionValue > OptionValueSP
Definition: lldb-forward.h:382