[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Property.cpp ------------------------------------------------------===//
|
2012-08-23 01:17:09 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-08-23 01:17:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/Property.h"
|
|
|
|
|
|
|
|
#include "lldb/Core/UserSettingsController.h"
|
2015-01-16 04:08:35 +08:00
|
|
|
#include "lldb/Host/StringConvert.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2018-04-10 17:03:59 +08:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
#include "lldb/Interpreter/OptionValues.h"
|
2015-09-02 09:06:46 +08:00
|
|
|
#include "lldb/Target/Language.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
|
2019-02-12 07:13:08 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
Property::Property(const PropertyDefinition &definition)
|
|
|
|
: m_name(definition.name), m_description(definition.description),
|
|
|
|
m_value_sp(), m_is_global(definition.global) {
|
|
|
|
switch (definition.type) {
|
|
|
|
case OptionValue::eTypeInvalid:
|
|
|
|
case OptionValue::eTypeProperties:
|
|
|
|
break;
|
|
|
|
case OptionValue::eTypeArch:
|
|
|
|
// "definition.default_uint_value" is not used
|
|
|
|
// "definition.default_cstr_value" as a string value that represents the
|
|
|
|
// default string value for the architecture/triple
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp =
|
|
|
|
std::make_shared<OptionValueArch>(definition.default_cstr_value);
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
2015-01-13 04:44:02 +08:00
|
|
|
|
|
|
|
case OptionValue::eTypeArgs:
|
|
|
|
// "definition.default_uint_value" is always a OptionValue::Type
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueArgs>();
|
2015-01-13 04:44:02 +08:00
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeArray:
|
|
|
|
// "definition.default_uint_value" is always a OptionValue::Type
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp =
|
|
|
|
std::make_shared<OptionValueArray>(OptionValue::ConvertTypeToMask(
|
|
|
|
(OptionValue::Type)definition.default_uint_value));
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeBoolean:
|
|
|
|
// "definition.default_uint_value" is the default boolean value if
|
|
|
|
// "definition.default_cstr_value" is NULL, otherwise interpret
|
|
|
|
// "definition.default_cstr_value" as a string value that represents the
|
2016-09-17 03:09:12 +08:00
|
|
|
// default value.
|
2015-02-20 19:14:59 +08:00
|
|
|
if (definition.default_cstr_value)
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp =
|
|
|
|
std::make_shared<OptionValueBoolean>(OptionArgParser::ToBoolean(
|
|
|
|
llvm::StringRef(definition.default_cstr_value), false, nullptr));
|
2012-08-23 01:17:09 +08:00
|
|
|
else
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueBoolean>(
|
|
|
|
definition.default_uint_value != 0);
|
2015-02-19 07:12:26 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-17 03:09:12 +08:00
|
|
|
case OptionValue::eTypeChar: {
|
|
|
|
llvm::StringRef s(definition.default_cstr_value ? definition.default_cstr_value : "");
|
2018-04-10 17:03:59 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueChar>(
|
|
|
|
OptionArgParser::ToChar(s, '\0', nullptr));
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
2016-09-17 03:09:12 +08:00
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeDictionary:
|
|
|
|
// "definition.default_uint_value" is always a OptionValue::Type
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp =
|
|
|
|
std::make_shared<OptionValueDictionary>(OptionValue::ConvertTypeToMask(
|
|
|
|
(OptionValue::Type)definition.default_uint_value));
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeEnum:
|
|
|
|
// "definition.default_uint_value" is the default enumeration value if
|
|
|
|
// "definition.default_cstr_value" is NULL, otherwise interpret
|
|
|
|
// "definition.default_cstr_value" as a string value that represents the
|
2018-05-01 00:49:04 +08:00
|
|
|
// default value.
|
2015-02-05 06:00:53 +08:00
|
|
|
{
|
|
|
|
OptionValueEnumeration *enum_value = new OptionValueEnumeration(
|
2015-02-21 03:46:30 +08:00
|
|
|
definition.enum_values, definition.default_uint_value);
|
|
|
|
m_value_sp.reset(enum_value);
|
|
|
|
if (definition.default_cstr_value) {
|
2016-09-24 01:48:13 +08:00
|
|
|
if (enum_value
|
|
|
|
->SetValueFromString(
|
|
|
|
llvm::StringRef(definition.default_cstr_value))
|
2015-02-21 03:46:30 +08:00
|
|
|
.Success()) {
|
|
|
|
enum_value->SetDefaultValue(enum_value->GetCurrentValue());
|
2018-05-01 00:49:04 +08:00
|
|
|
// Call Clear() since we don't want the value to appear as having
|
|
|
|
// been set since we called SetValueFromString() above. Clear will
|
|
|
|
// set the current value to the default and clear the boolean that
|
|
|
|
// says that the value has been set.
|
2012-08-23 01:17:09 +08:00
|
|
|
enum_value->Clear();
|
2015-02-21 03:46:30 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2015-02-05 06:00:53 +08:00
|
|
|
break;
|
|
|
|
|
2020-07-17 02:34:50 +08:00
|
|
|
case OptionValue::eTypeFileLineColumn:
|
|
|
|
// "definition.default_uint_value" is not used for a
|
|
|
|
// OptionValue::eTypeFileSpecList
|
|
|
|
m_value_sp = std::make_shared<OptionValueFileColonLine>();
|
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeFileSpec: {
|
|
|
|
// "definition.default_uint_value" represents if the
|
2018-05-01 00:49:04 +08:00
|
|
|
// "definition.default_cstr_value" should be resolved or not
|
2015-01-22 05:51:02 +08:00
|
|
|
const bool resolve = definition.default_uint_value != 0;
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec file_spec = FileSpec(definition.default_cstr_value);
|
|
|
|
if (resolve)
|
|
|
|
FileSystem::Instance().Resolve(file_spec);
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueFileSpec>(file_spec, resolve);
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeFileSpecList:
|
|
|
|
// "definition.default_uint_value" is not used for a
|
|
|
|
// OptionValue::eTypeFileSpecList
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueFileSpecList>();
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeFormat:
|
|
|
|
// "definition.default_uint_value" is the default format enumeration value
|
2018-05-01 00:49:04 +08:00
|
|
|
// if "definition.default_cstr_value" is NULL, otherwise interpret
|
2012-08-23 01:17:09 +08:00
|
|
|
// "definition.default_cstr_value" as a string value that represents the
|
2018-05-01 00:49:04 +08:00
|
|
|
// default value.
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2012-08-23 01:17:09 +08:00
|
|
|
Format new_format = eFormatInvalid;
|
2015-02-05 06:00:53 +08:00
|
|
|
if (definition.default_cstr_value)
|
2018-04-10 17:03:59 +08:00
|
|
|
OptionArgParser::ToFormat(definition.default_cstr_value, new_format,
|
|
|
|
nullptr);
|
2012-09-01 08:38:36 +08:00
|
|
|
else
|
|
|
|
new_format = (Format)definition.default_uint_value;
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueFormat>(new_format);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
case OptionValue::eTypeLanguage:
|
2018-05-01 00:49:04 +08:00
|
|
|
// "definition.default_uint_value" is the default language enumeration
|
|
|
|
// value if "definition.default_cstr_value" is NULL, otherwise interpret
|
2012-08-23 01:17:09 +08:00
|
|
|
// "definition.default_cstr_value" as a string value that represents the
|
2018-05-01 00:49:04 +08:00
|
|
|
// default value.
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2015-02-21 03:46:30 +08:00
|
|
|
LanguageType new_lang = eLanguageTypeUnknown;
|
2012-08-23 01:17:09 +08:00
|
|
|
if (definition.default_cstr_value)
|
2016-09-17 10:00:02 +08:00
|
|
|
Language::GetLanguageTypeFromString(
|
|
|
|
llvm::StringRef(definition.default_cstr_value));
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2012-08-23 01:17:09 +08:00
|
|
|
new_lang = (LanguageType)definition.default_uint_value;
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueLanguage>(new_lang);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeFormatEntity:
|
|
|
|
// "definition.default_cstr_value" as a string value that represents the
|
|
|
|
// default
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueFormatEntity>(
|
|
|
|
definition.default_cstr_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypePathMap:
|
|
|
|
// "definition.default_uint_value" tells us if notifications should occur
|
2018-05-01 00:49:04 +08:00
|
|
|
// for path mappings
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValuePathMappings>(
|
|
|
|
definition.default_uint_value != 0);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
case OptionValue::eTypeRegex:
|
|
|
|
// "definition.default_uint_value" is used to the regular expression flags
|
|
|
|
// "definition.default_cstr_value" the default regular expression value
|
|
|
|
// value.
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp =
|
|
|
|
std::make_shared<OptionValueRegex>(definition.default_cstr_value);
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeSInt64:
|
|
|
|
// "definition.default_uint_value" is the default integer value if
|
|
|
|
// "definition.default_cstr_value" is NULL, otherwise interpret
|
|
|
|
// "definition.default_cstr_value" as a string value that represents the
|
2018-05-01 00:49:04 +08:00
|
|
|
// default value.
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueSInt64>(
|
2012-08-23 01:17:09 +08:00
|
|
|
definition.default_cstr_value
|
|
|
|
? StringConvert::ToSInt64(definition.default_cstr_value)
|
2019-02-12 07:13:08 +08:00
|
|
|
: definition.default_uint_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeUInt64:
|
|
|
|
// "definition.default_uint_value" is the default unsigned integer value if
|
2015-02-21 03:46:30 +08:00
|
|
|
// "definition.default_cstr_value" is NULL, otherwise interpret
|
2012-08-23 01:17:09 +08:00
|
|
|
// "definition.default_cstr_value" as a string value that represents the
|
2018-05-01 00:49:04 +08:00
|
|
|
// default value.
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueUInt64>(
|
2012-08-23 01:17:09 +08:00
|
|
|
definition.default_cstr_value
|
|
|
|
? StringConvert::ToUInt64(definition.default_cstr_value)
|
2019-02-12 07:13:08 +08:00
|
|
|
: definition.default_uint_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeUUID:
|
|
|
|
// "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
|
|
|
|
// "definition.default_cstr_value" can contain a default UUID value
|
|
|
|
{
|
2015-02-05 06:00:53 +08:00
|
|
|
UUID uuid;
|
2012-08-23 01:17:09 +08:00
|
|
|
if (definition.default_cstr_value)
|
2018-06-21 23:24:39 +08:00
|
|
|
uuid.SetFromStringRef(definition.default_cstr_value);
|
2019-02-12 07:13:08 +08:00
|
|
|
m_value_sp = std::make_shared<OptionValueUUID>(uuid);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case OptionValue::eTypeString:
|
2018-05-01 00:49:04 +08:00
|
|
|
// "definition.default_uint_value" can contain the string option flags
|
|
|
|
// OR'ed together "definition.default_cstr_value" can contain a default
|
|
|
|
// string value
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2012-09-01 08:38:36 +08:00
|
|
|
OptionValueString *string_value =
|
2015-01-16 04:08:35 +08:00
|
|
|
new OptionValueString(definition.default_cstr_value);
|
2012-08-23 01:17:09 +08:00
|
|
|
if (definition.default_uint_value != 0)
|
|
|
|
string_value->GetOptions().Reset(definition.default_uint_value);
|
2012-09-01 08:38:36 +08:00
|
|
|
m_value_sp.reset(string_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
Property::Property(ConstString name, ConstString desc,
|
2012-08-23 01:17:09 +08:00
|
|
|
bool is_global, const lldb::OptionValueSP &value_sp)
|
2015-01-16 04:08:35 +08:00
|
|
|
: m_name(name), m_description(desc), m_value_sp(value_sp),
|
2012-08-23 01:17:09 +08:00
|
|
|
m_is_global(is_global) {}
|
|
|
|
|
|
|
|
bool Property::DumpQualifiedName(Stream &strm) const {
|
|
|
|
if (m_name) {
|
|
|
|
if (m_value_sp->DumpQualifiedName(strm))
|
|
|
|
strm.PutChar('.');
|
|
|
|
strm << m_name;
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
void Property::Dump(const ExecutionContext *exe_ctx, Stream &strm,
|
|
|
|
uint32_t dump_mask) const {
|
|
|
|
if (m_value_sp) {
|
|
|
|
const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription;
|
2018-10-26 08:00:17 +08:00
|
|
|
const bool dump_cmd = dump_mask & OptionValue::eDumpOptionCommand;
|
2012-08-23 01:17:09 +08:00
|
|
|
const bool transparent = m_value_sp->ValueIsTransparent();
|
2018-10-26 08:00:17 +08:00
|
|
|
if (dump_cmd && !transparent)
|
|
|
|
strm << "settings set -f ";
|
2012-08-23 01:17:09 +08:00
|
|
|
if (dump_desc || !transparent) {
|
|
|
|
if ((dump_mask & OptionValue::eDumpOptionName) && m_name) {
|
|
|
|
DumpQualifiedName(strm);
|
|
|
|
if (dump_mask & ~OptionValue::eDumpOptionName)
|
|
|
|
strm.PutChar(' ');
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
if (dump_desc) {
|
2016-11-16 07:36:43 +08:00
|
|
|
llvm::StringRef desc = GetDescription();
|
|
|
|
if (!desc.empty())
|
|
|
|
strm << "-- " << desc;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
if (transparent && (dump_mask == (OptionValue::eDumpOptionName |
|
|
|
|
OptionValue::eDumpOptionDescription)))
|
|
|
|
strm.EOL();
|
|
|
|
}
|
|
|
|
m_value_sp->DumpValue(exe_ctx, strm, dump_mask);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Property::DumpDescription(CommandInterpreter &interpreter, Stream &strm,
|
|
|
|
uint32_t output_width,
|
|
|
|
bool display_qualified_name) const {
|
2016-11-16 07:36:43 +08:00
|
|
|
if (!m_value_sp)
|
|
|
|
return;
|
|
|
|
llvm::StringRef desc = GetDescription();
|
2012-08-23 01:17:09 +08:00
|
|
|
|
2016-11-16 07:36:43 +08:00
|
|
|
if (desc.empty())
|
|
|
|
return;
|
2012-08-23 01:17:09 +08:00
|
|
|
|
2016-11-16 07:36:43 +08:00
|
|
|
StreamString qualified_name;
|
|
|
|
const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
|
|
|
|
if (sub_properties) {
|
|
|
|
strm.EOL();
|
|
|
|
|
|
|
|
if (m_value_sp->DumpQualifiedName(qualified_name))
|
2016-11-17 05:15:24 +08:00
|
|
|
strm.Printf("'%s' variables:\n\n", qualified_name.GetData());
|
2016-11-16 07:36:43 +08:00
|
|
|
sub_properties->DumpAllDescriptions(interpreter, strm);
|
|
|
|
} else {
|
|
|
|
if (display_qualified_name) {
|
|
|
|
StreamString qualified_name;
|
|
|
|
DumpQualifiedName(qualified_name);
|
2016-11-17 05:15:24 +08:00
|
|
|
interpreter.OutputFormattedHelpText(strm, qualified_name.GetString(),
|
|
|
|
"--", desc, output_width);
|
2016-11-16 07:36:43 +08:00
|
|
|
} else {
|
2016-11-17 05:15:24 +08:00
|
|
|
interpreter.OutputFormattedHelpText(strm, m_name.GetStringRef(), "--",
|
|
|
|
desc, output_width);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2020-01-09 21:14:54 +08:00
|
|
|
void Property::SetValueChangedCallback(std::function<void()> callback) {
|
2015-01-14 05:13:08 +08:00
|
|
|
if (m_value_sp)
|
2020-01-09 21:14:54 +08:00
|
|
|
m_value_sp->SetValueChangedCallback(std::move(callback));
|
2015-01-14 05:13:08 +08:00
|
|
|
}
|