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"
13 #include "lldb/Utility/Stream.h"
15 #include "llvm/ADT/STLExtras.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
21  Stream &strm, uint32_t dump_mask) {
22  if (dump_mask & eDumpOptionType)
23  strm.Printf("(%s)", GetTypeAsCString());
24  // if (dump_mask & eDumpOptionName)
25  // DumpQualifiedName (strm);
26  if (dump_mask & eDumpOptionValue) {
27  if (dump_mask & eDumpOptionType)
28  strm.PutCString(" = ");
29  strm.PutCString(m_current_value ? "true" : "false");
30  }
31 }
32 
33 Status OptionValueBoolean::SetValueFromString(llvm::StringRef value_str,
35  Status error;
36  switch (op) {
38  Clear();
39  NotifyValueChanged();
40  break;
41 
44  bool success = false;
45  bool value = OptionArgParser::ToBoolean(value_str, false, &success);
46  if (success) {
47  m_value_was_set = true;
48  m_current_value = value;
49  NotifyValueChanged();
50  } else {
51  if (value_str.size() == 0)
52  error.SetErrorString("invalid boolean string value <empty>");
53  else
54  error.SetErrorStringWithFormat("invalid boolean string value: '%s'",
55  value_str.str().c_str());
56  }
57  } break;
58 
64  error = OptionValue::SetValueFromString(value_str, op);
65  break;
66  }
67  return error;
68 }
69 
70 void OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter,
71  CompletionRequest &request) {
72  llvm::StringRef autocomplete_entries[] = {"true", "false", "on", "off",
73  "yes", "no", "1", "0"};
74 
75  auto entries = llvm::makeArrayRef(autocomplete_entries);
76 
77  // only suggest "true" or "false" by default
78  if (request.GetCursorArgumentPrefix().empty())
79  entries = entries.take_front(2);
80 
81  for (auto entry : entries)
82  request.TryCompleteCurrentArg(entry);
83 }
lldb_private::eVarSetOperationInsertBefore
@ eVarSetOperationInsertBefore
Definition: lldb-private-enumerations.h:85
lldb_private::eVarSetOperationReplace
@ eVarSetOperationReplace
Definition: lldb-private-enumerations.h:84
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::CompletionRequest::TryCompleteCurrentArg
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
Definition: CompletionRequest.h:180
OptionArgParser.h
lldb_private::Stream
Definition: Stream.h:28
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::VarSetOperationType
VarSetOperationType
Settable state variable types.
Definition: lldb-private-enumerations.h:83
lldb_private::eVarSetOperationAppend
@ eVarSetOperationAppend
Definition: lldb-private-enumerations.h:88
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::CompletionRequest::GetCursorArgumentPrefix
llvm::StringRef GetCursorArgumentPrefix() const
Definition: CompletionRequest.h:217
StringList.h
lldb_private::Status
Definition: Status.h:44
uint32_t
lldb_private::eVarSetOperationRemove
@ eVarSetOperationRemove
Definition: lldb-private-enumerations.h:87
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
PosixApi.h
lldb_private::eVarSetOperationInvalid
@ eVarSetOperationInvalid
Definition: lldb-private-enumerations.h:91
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
OptionValueBoolean.h
lldb
Definition: SBAddress.h:15
lldb_private::eVarSetOperationClear
@ eVarSetOperationClear
Definition: lldb-private-enumerations.h:89
DumpValue
static bool DumpValue(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const FormatEntity::Entry &entry, ValueObject *valobj)
Definition: FormatEntity.cpp:673
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::eVarSetOperationInsertAfter
@ eVarSetOperationInsertAfter
Definition: lldb-private-enumerations.h:86
lldb_private::eVarSetOperationAssign
@ eVarSetOperationAssign
Definition: lldb-private-enumerations.h:90