LLDB mainline
OptionValueBoolean.cpp
Go to the documentation of this file.
1//===-- OptionValueBoolean.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
11#include "lldb/Host/PosixApi.h"
14#include "lldb/Utility/Stream.h"
16#include "llvm/ADT/STLExtras.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
22 Stream &strm, uint32_t dump_mask) {
23 if (dump_mask & eDumpOptionType)
24 strm.Printf("(%s)", GetTypeAsCString());
25 // if (dump_mask & eDumpOptionName)
26 // DumpQualifiedName (strm);
27 if (dump_mask & eDumpOptionValue) {
28 if (dump_mask & eDumpOptionType)
29 strm.PutCString(" = ");
30 strm.PutCString(m_current_value ? "true" : "false");
31 if (dump_mask & eDumpOptionDefaultValue &&
33 DefaultValueFormat label(strm);
34 strm.PutCString(m_default_value ? "true" : "false");
35 }
36 }
37}
38
42 switch (op) {
44 Clear();
46 break;
47
50 bool success = false;
51 bool value = OptionArgParser::ToBoolean(value_str, false, &success);
52 if (success) {
53 m_value_was_set = true;
54 m_current_value = value;
56 } else {
57 if (value_str.size() == 0)
58 error = Status::FromErrorString("invalid boolean string value <empty>");
59 else
61 "invalid boolean string value: '%s'", value_str.str().c_str());
62 }
63 } break;
64
71 break;
72 }
73 return error;
74}
75
77 CompletionRequest &request) {
78 llvm::StringRef autocomplete_entries[] = {"true", "false", "on", "off",
79 "yes", "no", "1", "0"};
80
81 auto entries = llvm::ArrayRef(autocomplete_entries);
82
83 // only suggest "true" or "false" by default
84 if (request.GetCursorArgumentPrefix().empty())
85 entries = entries.take_front(2);
86
87 for (auto entry : entries)
88 request.TryCompleteCurrentArg(entry);
89}
static llvm::raw_ostream & error(Stream &strm)
"lldb/Utility/ArgCompletionRequest.h"
llvm::StringRef GetCursorArgumentPrefix() const
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
void AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request) override
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
virtual const char * GetTypeAsCString() const
Definition OptionValue.h:89
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)