[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
|
|
|
//===-- OptionGroupFormat.cpp ---------------------------------------------===//
|
2011-04-28 06:04:39 +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
|
2011-04-28 06:04:39 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-05-14 04:21:08 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupFormat.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2017-03-23 07:33:16 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2012-12-15 09:44:51 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
OptionGroupFormat::OptionGroupFormat(lldb::Format default_format,
|
|
|
|
uint64_t default_byte_size,
|
|
|
|
uint64_t default_count)
|
|
|
|
: m_format(default_format, default_format),
|
|
|
|
m_byte_size(default_byte_size, default_byte_size),
|
2011-10-26 08:56:27 +08:00
|
|
|
m_count(default_count, default_count), m_prev_gdb_format('x'),
|
|
|
|
m_prev_gdb_size('w') {}
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2018-09-27 02:50:19 +08:00
|
|
|
static constexpr OptionDefinition g_option_table[] = {
|
2014-07-10 00:31:49 +08:00
|
|
|
{LLDB_OPT_SET_1, false, "format", 'f', OptionParser::eRequiredArgument,
|
2018-09-27 02:50:19 +08:00
|
|
|
nullptr, {}, 0, eArgTypeFormat,
|
2014-07-10 00:31:49 +08:00
|
|
|
"Specify a format to be used for display."},
|
|
|
|
{LLDB_OPT_SET_2, false, "gdb-format", 'G', OptionParser::eRequiredArgument,
|
2018-09-27 02:50:19 +08:00
|
|
|
nullptr, {}, 0, eArgTypeGDBFormat,
|
2014-07-10 00:31:49 +08:00
|
|
|
"Specify a format using a GDB format specifier string."},
|
|
|
|
{LLDB_OPT_SET_3, false, "size", 's', OptionParser::eRequiredArgument,
|
2018-09-27 02:50:19 +08:00
|
|
|
nullptr, {}, 0, eArgTypeByteSize,
|
2014-07-10 00:31:49 +08:00
|
|
|
"The size in bytes to use when displaying with the selected format."},
|
|
|
|
{LLDB_OPT_SET_4, false, "count", 'c', OptionParser::eRequiredArgument,
|
2018-09-27 02:50:19 +08:00
|
|
|
nullptr, {}, 0, eArgTypeCount,
|
2014-07-10 00:31:49 +08:00
|
|
|
"The number of total items to display."},
|
2011-04-28 06:04:39 +08:00
|
|
|
};
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> OptionGroupFormat::GetDefinitions() {
|
2016-09-23 05:06:13 +08:00
|
|
|
auto result = llvm::makeArrayRef(g_option_table);
|
2011-10-25 14:44:01 +08:00
|
|
|
if (m_byte_size.GetDefaultValue() < UINT64_MAX) {
|
|
|
|
if (m_count.GetDefaultValue() < UINT64_MAX)
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
return result;
|
2011-10-25 14:44:01 +08:00
|
|
|
else
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
return result.take_front(3);
|
2011-10-25 14:44:01 +08:00
|
|
|
}
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
return result.take_front(2);
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status OptionGroupFormat::SetOptionValue(uint32_t option_idx,
|
|
|
|
llvm::StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
Status error;
|
2012-12-04 08:32:51 +08:00
|
|
|
const int short_option = g_option_table[option_idx].short_option;
|
2011-04-28 06:04:39 +08:00
|
|
|
|
|
|
|
switch (short_option) {
|
|
|
|
case 'f':
|
2015-02-20 19:14:59 +08:00
|
|
|
error = m_format.SetValueFromString(option_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
case 'c':
|
|
|
|
if (m_count.GetDefaultValue() == 0) {
|
|
|
|
error.SetErrorString("--count option is disabled");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2015-02-20 19:14:59 +08:00
|
|
|
error = m_count.SetValueFromString(option_arg);
|
2011-10-25 14:44:01 +08:00
|
|
|
if (m_count.GetCurrentValue() == 0)
|
|
|
|
error.SetErrorStringWithFormat("invalid --count option value '%s'",
|
2016-09-24 01:48:13 +08:00
|
|
|
option_arg.str().c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
case 's':
|
|
|
|
if (m_byte_size.GetDefaultValue() == 0) {
|
|
|
|
error.SetErrorString("--size option is disabled");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2015-02-20 19:14:59 +08:00
|
|
|
error = m_byte_size.SetValueFromString(option_arg);
|
|
|
|
if (m_byte_size.GetCurrentValue() == 0)
|
2011-10-25 14:44:01 +08:00
|
|
|
error.SetErrorStringWithFormat("invalid --size option value '%s'",
|
2016-09-24 01:48:13 +08:00
|
|
|
option_arg.str().c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-28 06:04:39 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-26 08:56:27 +08:00
|
|
|
case 'G': {
|
|
|
|
uint64_t count = 0;
|
2016-09-24 01:48:13 +08:00
|
|
|
llvm::StringRef gdb_format_str = option_arg;
|
|
|
|
gdb_format_str.consumeInteger(0, count);
|
2011-10-25 14:44:01 +08:00
|
|
|
|
2011-10-26 08:56:27 +08:00
|
|
|
Format format = eFormatDefault;
|
|
|
|
uint32_t byte_size = 0;
|
|
|
|
|
2016-09-24 01:48:13 +08:00
|
|
|
while (!gdb_format_str.empty() &&
|
|
|
|
ParserGDBFormatLetter(execution_context, gdb_format_str[0], format,
|
2011-10-26 08:56:27 +08:00
|
|
|
byte_size)) {
|
2016-09-24 01:48:13 +08:00
|
|
|
gdb_format_str = gdb_format_str.drop_front();
|
2011-10-26 08:56:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-24 01:48:13 +08:00
|
|
|
// We the first character of the "gdb_format_str" is not the
|
2011-10-26 08:56:27 +08:00
|
|
|
// NULL terminator, we didn't consume the entire string and
|
2018-05-01 00:49:04 +08:00
|
|
|
// something is wrong. Also, if none of the format, size or count was
|
|
|
|
// specified correctly, then abort.
|
2016-09-24 01:48:13 +08:00
|
|
|
if (!gdb_format_str.empty() ||
|
2011-10-26 08:56:27 +08:00
|
|
|
(format == eFormatInvalid && byte_size == 0 && count == 0)) {
|
|
|
|
// Nothing got set correctly
|
|
|
|
error.SetErrorStringWithFormat("invalid gdb format string '%s'",
|
2016-09-24 01:48:13 +08:00
|
|
|
option_arg.str().c_str());
|
2011-10-26 08:56:27 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// At least one of the format, size or count was set correctly. Anything
|
|
|
|
// that wasn't set correctly should be set to the previous default
|
2011-10-26 08:56:27 +08:00
|
|
|
if (format == eFormatInvalid)
|
2016-08-12 07:51:28 +08:00
|
|
|
ParserGDBFormatLetter(execution_context, m_prev_gdb_format, format,
|
|
|
|
byte_size);
|
2011-10-26 08:56:27 +08:00
|
|
|
|
|
|
|
const bool byte_size_enabled = m_byte_size.GetDefaultValue() < UINT64_MAX;
|
2012-08-24 05:16:25 +08:00
|
|
|
const bool count_enabled = m_count.GetDefaultValue() < UINT64_MAX;
|
|
|
|
if (byte_size_enabled) {
|
|
|
|
// Byte size is enabled
|
|
|
|
if (byte_size == 0)
|
|
|
|
ParserGDBFormatLetter(execution_context, m_prev_gdb_size, format,
|
|
|
|
byte_size);
|
2011-10-26 08:56:27 +08:00
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Byte size is disabled, make sure it wasn't specified but if this is an
|
|
|
|
// address, it's actually necessary to specify one so don't error out
|
2011-10-26 08:56:27 +08:00
|
|
|
if (byte_size > 0 && format != lldb::eFormatAddressInfo) {
|
|
|
|
error.SetErrorString(
|
|
|
|
"this command doesn't support specifying a byte size");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count_enabled) {
|
|
|
|
// Count is enabled and was not set, set it to the default for gdb format
|
2012-08-24 05:16:25 +08:00
|
|
|
// statements (which is 1).
|
2011-10-26 08:56:27 +08:00
|
|
|
if (count == 0)
|
2012-08-24 05:16:25 +08:00
|
|
|
count = 1;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2011-10-26 08:56:27 +08:00
|
|
|
// Count is disabled, make sure it wasn't specified
|
|
|
|
if (count > 0) {
|
|
|
|
error.SetErrorString("this command doesn't support specifying a count");
|
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2011-10-26 08:56:27 +08:00
|
|
|
|
|
|
|
m_format.SetCurrentValue(format);
|
|
|
|
m_format.SetOptionWasSet();
|
|
|
|
if (byte_size_enabled) {
|
|
|
|
m_byte_size.SetCurrentValue(byte_size);
|
|
|
|
m_byte_size.SetOptionWasSet();
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
2011-10-26 08:56:27 +08:00
|
|
|
if (count_enabled) {
|
|
|
|
m_count.SetCurrentValue(count);
|
|
|
|
m_count.SetOptionWasSet();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
2019-08-22 16:08:05 +08:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-28 06:04:39 +08:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
bool OptionGroupFormat::ParserGDBFormatLetter(
|
|
|
|
ExecutionContext *execution_context, char format_letter, Format &format,
|
|
|
|
uint32_t &byte_size) {
|
2013-01-22 03:20:50 +08:00
|
|
|
m_has_gdb_format = true;
|
2011-10-26 08:56:27 +08:00
|
|
|
switch (format_letter) {
|
2011-10-29 07:27:55 +08:00
|
|
|
case 'o':
|
|
|
|
format = eFormatOctal;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
|
|
|
case 'x':
|
|
|
|
format = eFormatHex;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
|
|
|
case 'd':
|
|
|
|
format = eFormatDecimal;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
|
|
|
case 'u':
|
|
|
|
format = eFormatUnsigned;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
|
|
|
case 't':
|
|
|
|
format = eFormatBinary;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
|
|
|
case 'f':
|
|
|
|
format = eFormatFloat;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
2012-12-15 09:44:51 +08:00
|
|
|
case 'a':
|
|
|
|
format = eFormatAddressInfo;
|
2011-10-26 08:56:27 +08:00
|
|
|
{
|
2016-08-12 07:51:28 +08:00
|
|
|
TargetSP target_sp =
|
|
|
|
execution_context ? execution_context->GetTargetSP() : TargetSP();
|
|
|
|
if (target_sp)
|
2011-10-29 07:27:55 +08:00
|
|
|
byte_size = target_sp->GetArchitecture().GetAddressByteSize();
|
2016-07-20 23:41:12 +08:00
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
2011-10-26 08:56:27 +08:00
|
|
|
}
|
2011-10-29 07:27:55 +08:00
|
|
|
case 'i':
|
|
|
|
format = eFormatInstruction;
|
2012-12-15 09:44:51 +08:00
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
2011-10-25 14:44:01 +08:00
|
|
|
case 'c':
|
2011-10-29 07:27:55 +08:00
|
|
|
format = eFormatChar;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
|
|
|
case 's':
|
|
|
|
format = eFormatCString;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
|
|
|
case 'T':
|
|
|
|
format = eFormatOSType;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
|
|
|
case 'A':
|
|
|
|
format = eFormatHexFloat;
|
|
|
|
m_prev_gdb_format = format_letter;
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-20 23:41:12 +08:00
|
|
|
case 'b':
|
|
|
|
case 'h':
|
|
|
|
case 'w':
|
|
|
|
case 'g':
|
2017-01-25 09:41:48 +08:00
|
|
|
{
|
2018-05-01 00:49:04 +08:00
|
|
|
// Size isn't used for printing instructions, so if a size is specified,
|
|
|
|
// and the previous format was 'i', then we should reset it to the
|
|
|
|
// default ('x'). Otherwise we'll continue to print as instructions,
|
2017-01-25 09:41:48 +08:00
|
|
|
// which isn't expected.
|
|
|
|
if (format_letter == 'b')
|
|
|
|
byte_size = 1;
|
|
|
|
else if (format_letter == 'h')
|
|
|
|
byte_size = 2;
|
|
|
|
else if (format_letter == 'w')
|
|
|
|
byte_size = 4;
|
|
|
|
else if (format_letter == 'g')
|
|
|
|
byte_size = 8;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-01-25 09:41:48 +08:00
|
|
|
m_prev_gdb_size = format_letter;
|
|
|
|
if (m_prev_gdb_format == 'i')
|
|
|
|
m_prev_gdb_format = 'x';
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-01-25 09:41:48 +08:00
|
|
|
|
|
|
|
|
2011-10-29 07:27:55 +08:00
|
|
|
return false;
|
2011-10-26 08:56:27 +08:00
|
|
|
}
|
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
void OptionGroupFormat::OptionParsingStarting(
|
|
|
|
ExecutionContext *execution_context) {
|
2011-04-28 06:04:39 +08:00
|
|
|
m_format.Clear();
|
2011-10-25 14:44:01 +08:00
|
|
|
m_byte_size.Clear();
|
|
|
|
m_count.Clear();
|
2013-01-22 03:20:50 +08:00
|
|
|
m_has_gdb_format = false;
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|