LLDB  mainline
Property.cpp
Go to the documentation of this file.
1 //===-- Property.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 
16 #include "lldb/Target/Language.h"
17 
18 #include <memory>
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
23 Property::Property(const PropertyDefinition &definition)
24  : m_name(definition.name), m_description(definition.description),
25  m_is_global(definition.global) {
26  switch (definition.type) {
29  break;
31  // "definition.default_uint_value" is not used
32  // "definition.default_cstr_value" as a string value that represents the
33  // default string value for the architecture/triple
34  m_value_sp =
35  std::make_shared<OptionValueArch>(definition.default_cstr_value);
36  break;
37 
39  // "definition.default_uint_value" is always a OptionValue::Type
40  m_value_sp = std::make_shared<OptionValueArgs>();
41  break;
42 
44  // "definition.default_uint_value" is always a OptionValue::Type
45  m_value_sp =
46  std::make_shared<OptionValueArray>(OptionValue::ConvertTypeToMask(
48  break;
49 
51  // "definition.default_uint_value" is the default boolean value if
52  // "definition.default_cstr_value" is NULL, otherwise interpret
53  // "definition.default_cstr_value" as a string value that represents the
54  // default value.
55  if (definition.default_cstr_value)
56  m_value_sp =
57  std::make_shared<OptionValueBoolean>(OptionArgParser::ToBoolean(
58  llvm::StringRef(definition.default_cstr_value), false, nullptr));
59  else
60  m_value_sp = std::make_shared<OptionValueBoolean>(
61  definition.default_uint_value != 0);
62  break;
63 
65  llvm::StringRef s(definition.default_cstr_value ? definition.default_cstr_value : "");
66  m_value_sp = std::make_shared<OptionValueChar>(
67  OptionArgParser::ToChar(s, '\0', nullptr));
68  break;
69  }
71  // "definition.default_uint_value" is always a OptionValue::Type
72  m_value_sp =
73  std::make_shared<OptionValueDictionary>(OptionValue::ConvertTypeToMask(
75  break;
76 
78  // "definition.default_uint_value" is the default enumeration value if
79  // "definition.default_cstr_value" is NULL, otherwise interpret
80  // "definition.default_cstr_value" as a string value that represents the
81  // default value.
82  {
84  definition.enum_values, definition.default_uint_value);
85  m_value_sp.reset(enum_value);
86  if (definition.default_cstr_value) {
87  if (enum_value
88  ->SetValueFromString(
89  llvm::StringRef(definition.default_cstr_value))
90  .Success()) {
91  enum_value->SetDefaultValue(enum_value->GetCurrentValue());
92  // Call Clear() since we don't want the value to appear as having
93  // been set since we called SetValueFromString() above. Clear will
94  // set the current value to the default and clear the boolean that
95  // says that the value has been set.
96  enum_value->Clear();
97  }
98  }
99  }
100  break;
101 
103  // "definition.default_uint_value" is not used for a
104  // OptionValue::eTypeFileSpecList
105  m_value_sp = std::make_shared<OptionValueFileColonLine>();
106  break;
107 
109  // "definition.default_uint_value" represents if the
110  // "definition.default_cstr_value" should be resolved or not
111  const bool resolve = definition.default_uint_value != 0;
112  FileSpec file_spec = FileSpec(definition.default_cstr_value);
113  if (resolve)
114  FileSystem::Instance().Resolve(file_spec);
115  m_value_sp = std::make_shared<OptionValueFileSpec>(file_spec, resolve);
116  break;
117  }
118 
120  // "definition.default_uint_value" is not used for a
121  // OptionValue::eTypeFileSpecList
122  m_value_sp = std::make_shared<OptionValueFileSpecList>();
123  break;
124 
126  // "definition.default_uint_value" is the default format enumeration value
127  // if "definition.default_cstr_value" is NULL, otherwise interpret
128  // "definition.default_cstr_value" as a string value that represents the
129  // default value.
130  {
131  Format new_format = eFormatInvalid;
132  if (definition.default_cstr_value)
133  OptionArgParser::ToFormat(definition.default_cstr_value, new_format,
134  nullptr);
135  else
136  new_format = (Format)definition.default_uint_value;
137  m_value_sp = std::make_shared<OptionValueFormat>(new_format);
138  }
139  break;
140 
142  // "definition.default_uint_value" is the default language enumeration
143  // value if "definition.default_cstr_value" is NULL, otherwise interpret
144  // "definition.default_cstr_value" as a string value that represents the
145  // default value.
146  {
148  if (definition.default_cstr_value)
150  llvm::StringRef(definition.default_cstr_value));
151  else
152  new_lang = (LanguageType)definition.default_uint_value;
153  m_value_sp = std::make_shared<OptionValueLanguage>(new_lang);
154  }
155  break;
156 
158  // "definition.default_cstr_value" as a string value that represents the
159  // default
160  m_value_sp = std::make_shared<OptionValueFormatEntity>(
161  definition.default_cstr_value);
162  break;
163 
165  // "definition.default_uint_value" tells us if notifications should occur
166  // for path mappings
167  m_value_sp = std::make_shared<OptionValuePathMappings>(
168  definition.default_uint_value != 0);
169  break;
170 
172  // "definition.default_uint_value" is used to the regular expression flags
173  // "definition.default_cstr_value" the default regular expression value
174  // value.
175  m_value_sp =
176  std::make_shared<OptionValueRegex>(definition.default_cstr_value);
177  break;
178 
180  // "definition.default_uint_value" is the default integer value if
181  // "definition.default_cstr_value" is NULL, otherwise interpret
182  // "definition.default_cstr_value" as a string value that represents the
183  // default value.
184  m_value_sp = std::make_shared<OptionValueSInt64>(
185  definition.default_cstr_value
187  : definition.default_uint_value);
188  break;
189 
191  // "definition.default_uint_value" is the default unsigned integer value if
192  // "definition.default_cstr_value" is NULL, otherwise interpret
193  // "definition.default_cstr_value" as a string value that represents the
194  // default value.
195  m_value_sp = std::make_shared<OptionValueUInt64>(
196  definition.default_cstr_value
198  : definition.default_uint_value);
199  break;
200 
202  // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
203  // "definition.default_cstr_value" can contain a default UUID value
204  {
205  UUID uuid;
206  if (definition.default_cstr_value)
207  uuid.SetFromStringRef(definition.default_cstr_value);
208  m_value_sp = std::make_shared<OptionValueUUID>(uuid);
209  }
210  break;
211 
213  // "definition.default_uint_value" can contain the string option flags
214  // OR'ed together "definition.default_cstr_value" can contain a default
215  // string value
216  {
217  OptionValueString *string_value =
218  new OptionValueString(definition.default_cstr_value);
219  if (definition.default_uint_value != 0)
220  string_value->GetOptions().Reset(definition.default_uint_value);
221  m_value_sp.reset(string_value);
222  }
223  break;
224  }
225 }
226 
228  bool is_global, const lldb::OptionValueSP &value_sp)
229  : m_name(name), m_description(desc), m_value_sp(value_sp),
230  m_is_global(is_global) {}
231 
233  if (m_name) {
234  if (m_value_sp->DumpQualifiedName(strm))
235  strm.PutChar('.');
236  strm << m_name;
237  return true;
238  }
239  return false;
240 }
241 
242 void Property::Dump(const ExecutionContext *exe_ctx, Stream &strm,
243  uint32_t dump_mask) const {
244  if (m_value_sp) {
245  const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription;
246  const bool dump_cmd = dump_mask & OptionValue::eDumpOptionCommand;
247  const bool transparent = m_value_sp->ValueIsTransparent();
248  if (dump_cmd && !transparent)
249  strm << "settings set -f ";
250  if (dump_desc || !transparent) {
251  if ((dump_mask & OptionValue::eDumpOptionName) && m_name) {
252  DumpQualifiedName(strm);
253  if (dump_mask & ~OptionValue::eDumpOptionName)
254  strm.PutChar(' ');
255  }
256  }
257  if (dump_desc) {
258  llvm::StringRef desc = GetDescription();
259  if (!desc.empty())
260  strm << "-- " << desc;
261 
262  if (transparent && (dump_mask == (OptionValue::eDumpOptionName |
264  strm.EOL();
265  }
266  m_value_sp->DumpValue(exe_ctx, strm, dump_mask);
267  }
268 }
269 
271  uint32_t output_width,
272  bool display_qualified_name) const {
273  if (!m_value_sp)
274  return;
275  llvm::StringRef desc = GetDescription();
276 
277  if (desc.empty())
278  return;
279 
280  StreamString qualified_name;
281  const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
282  if (sub_properties) {
283  strm.EOL();
284 
285  if (m_value_sp->DumpQualifiedName(qualified_name))
286  strm.Printf("'%s' variables:\n\n", qualified_name.GetData());
287  sub_properties->DumpAllDescriptions(interpreter, strm);
288  } else {
289  if (display_qualified_name) {
290  StreamString qualified_name;
291  DumpQualifiedName(qualified_name);
292  interpreter.OutputFormattedHelpText(strm, qualified_name.GetString(),
293  "--", desc, output_width);
294  } else {
295  interpreter.OutputFormattedHelpText(strm, m_name.GetStringRef(), "--",
296  desc, output_width);
297  }
298  }
299 }
300 
301 void Property::SetValueChangedCallback(std::function<void()> callback) {
302  if (m_value_sp)
303  m_value_sp->SetValueChangedCallback(std::move(callback));
304 }
lldb_private::UUID
Definition: UUID.h:23
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::StringConvert::ToSInt64
int64_t ToSInt64(const char *s, int64_t fail_value=0, int base=0, bool *success_ptr=nullptr)
Definition: StringConvert.cpp:48
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::OptionArgParser::ToChar
static char ToChar(llvm::StringRef s, char fail_value, bool *success_ptr)
Definition: OptionArgParser.cpp:35
lldb_private::Property::Property
Property(const PropertyDefinition &definition)
Definition: Property.cpp:23
lldb_private::OptionValue::eTypeInvalid
@ eTypeInvalid
Definition: OptionValue.h:27
lldb_private::OptionValue::eTypeBoolean
@ eTypeBoolean
Definition: OptionValue.h:31
lldb_private::OptionValue::eTypeFileSpecList
@ eTypeFileSpecList
Definition: OptionValue.h:37
lldb_private::Property::m_value_sp
lldb::OptionValueSP m_value_sp
Definition: Property.h:72
lldb_private::OptionValue::eTypePathMap
@ eTypePathMap
Definition: OptionValue.h:40
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::OptionValue::eTypeUInt64
@ eTypeUInt64
Definition: OptionValue.h:45
OptionArgParser.h
lldb_private::PropertyDefinition::default_uint_value
uintptr_t default_uint_value
Definition: Property.h:28
lldb_private::OptionValue::eTypeSInt64
@ eTypeSInt64
Definition: OptionValue.h:43
lldb_private::Stream
Definition: Stream.h:28
Language.h
lldb_private::OptionValueEnumeration::Clear
void Clear() override
Definition: OptionValueEnumeration.h:48
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::OptionValueEnumeration
Definition: OptionValueEnumeration.h:22
lldb_private::PropertyDefinition::type
OptionValue::Type type
Definition: Property.h:26
lldb_private::OptionValue::eTypeRegex
@ eTypeRegex
Definition: OptionValue.h:42
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::OptionValue::eDumpOptionName
@ eDumpOptionName
Definition: OptionValue.h:51
lldb_private::OptionArgParser::ToFormat
static Status ToFormat(const char *s, lldb::Format &format, size_t *byte_size_ptr)
Definition: OptionArgParser.cpp:78
StringConvert.h
lldb_private::OptionValue::eTypeFileSpec
@ eTypeFileSpec
Definition: OptionValue.h:36
lldb_private::OptionValue::eTypeFileLineColumn
@ eTypeFileLineColumn
Definition: OptionValue.h:35
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::Property::DumpQualifiedName
bool DumpQualifiedName(Stream &strm) const
Definition: Property.cpp:232
lldb_private::OptionValue::eDumpOptionCommand
@ eDumpOptionCommand
Definition: OptionValue.h:56
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb_private::OptionValueProperties
Definition: OptionValueProperties.h:23
lldb_private::Property::Dump
void Dump(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) const
Definition: Property.cpp:242
lldb_private::PropertyDefinition::default_cstr_value
const char * default_cstr_value
Definition: Property.h:29
Property.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::Property::m_name
ConstString m_name
Definition: Property.h:70
lldb_private::OptionValue::eTypeUUID
@ eTypeUUID
Definition: OptionValue.h:46
lldb_private::Property::DumpDescription
void DumpDescription(CommandInterpreter &interpreter, Stream &strm, uint32_t output_width, bool display_qualified_name) const
Definition: Property.cpp:270
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::OptionValue::ConvertTypeToMask
static uint32_t ConvertTypeToMask(OptionValue::Type type)
Definition: OptionValue.h:120
lldb_private::OptionValueString::GetOptions
Flags & GetOptions()
Definition: OptionValueString.h:83
lldb_private::OptionValueString
Definition: OptionValueString.h:20
lldb_private::FileSystem::Resolve
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
Definition: common/FileSystem.cpp:255
lldb_private::Stream::PutChar
size_t PutChar(char ch)
Definition: Stream.cpp:104
lldb_private::OptionValue::eTypeFormat
@ eTypeFormat
Definition: OptionValue.h:38
lldb_private::Flags::Reset
void Reset(ValueType flags)
Set accessor for all flags.
Definition: Flags.h:52
lldb_private::OptionValue::eDumpOptionDescription
@ eDumpOptionDescription
Definition: OptionValue.h:54
lldb_private::OptionValue::eTypeArch
@ eTypeArch
Definition: OptionValue.h:28
OptionValues.h
lldb_private::OptionValue::eTypeArray
@ eTypeArray
Definition: OptionValue.h:30
lldb_private::Language::GetLanguageTypeFromString
static lldb::LanguageType GetLanguageTypeFromString(const char *string)=delete
lldb_private::OptionArgParser::ToBoolean
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)
Definition: OptionArgParser.cpp:18
lldb_private::OptionValue::Type
Type
Definition: OptionValue.h:26
lldb_private::OptionValue::eTypeDictionary
@ eTypeDictionary
Definition: OptionValue.h:33
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:437
lldb_private::OptionValue::eTypeChar
@ eTypeChar
Definition: OptionValue.h:32
uint32_t
lldb_private::Property::GetDescription
llvm::StringRef GetDescription() const
Definition: Property.h:44
lldb_private::PropertyDefinition::enum_values
OptionEnumValues enum_values
Definition: Property.h:30
UserSettingsController.h
lldb_private::OptionValueEnumeration::GetCurrentValue
enum_type GetCurrentValue() const
Definition: OptionValueEnumeration.h:63
lldb_private::OptionValue::eTypeString
@ eTypeString
Definition: OptionValue.h:44
lldb_private::Property::SetValueChangedCallback
void SetValueChangedCallback(std::function< void()> callback)
Definition: Property.cpp:301
lldb_private::UUID::SetFromStringRef
bool SetFromStringRef(llvm::StringRef str)
Definition: UUID.cpp:96
lldb_private::Stream::EOL
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
lldb_private::StringConvert::ToUInt64
uint64_t ToUInt64(const char *s, uint64_t fail_value=0, int base=0, bool *success_ptr=nullptr)
Definition: StringConvert.cpp:64
lldb_private::OptionValueEnumeration::SetDefaultValue
void SetDefaultValue(enum_type value)
Definition: OptionValueEnumeration.h:69
lldb_private::OptionValueProperties::DumpAllDescriptions
virtual void DumpAllDescriptions(CommandInterpreter &interpreter, Stream &strm) const
Definition: OptionValueProperties.cpp:602
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::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:45
lldb_private::PropertyDefinition
Definition: Property.h:24
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
CommandInterpreter.h
lldb_private::OptionValue::eTypeFormatEntity
@ eTypeFormatEntity
Definition: OptionValue.h:47
lldb_private::OptionValue::eTypeLanguage
@ eTypeLanguage
Definition: OptionValue.h:39
lldb_private::CommandInterpreter::OutputFormattedHelpText
void OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix, llvm::StringRef help_text)
lldb_private::OptionValue::eTypeProperties
@ eTypeProperties
Definition: OptionValue.h:41
lldb
Definition: SBAddress.h:15
lldb_private::OptionValue::eTypeEnum
@ eTypeEnum
Definition: OptionValue.h:34
lldb::eFormatInvalid
@ eFormatInvalid
Definition: lldb-enumerations.h:157
lldb_private::OptionValue::eTypeArgs
@ eTypeArgs
Definition: OptionValue.h:29