2011-07-07 12:38:25 +08:00
|
|
|
//===-- OptionGroupVariable.cpp -----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionGroupVariable.h"
|
|
|
|
|
2013-01-29 07:47:25 +08:00
|
|
|
#include "lldb/DataFormatters/DataVisualization.h"
|
2017-03-23 07:33:16 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2011-07-07 12:38:25 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2013-01-29 07:47:25 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2011-07-07 12:38:25 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// if you add any options here, remember to update the counters in
|
|
|
|
// OptionGroupVariable::GetNumDefinitions()
|
2018-09-27 02:50:19 +08:00
|
|
|
static constexpr OptionDefinition g_variable_options[] = {
|
2016-09-07 04:57:50 +08:00
|
|
|
{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',
|
2018-09-27 02:50:19 +08:00
|
|
|
OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
|
2016-09-07 04:57:50 +08:00
|
|
|
"Omit function arguments."},
|
2018-10-31 12:00:22 +08:00
|
|
|
{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-recognized-args", 't',
|
|
|
|
OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
|
|
|
|
"Omit recognized function arguments."},
|
2016-09-07 04:57:50 +08:00
|
|
|
{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',
|
2018-09-27 02:50:19 +08:00
|
|
|
OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
|
2016-09-07 04:57:50 +08:00
|
|
|
"Omit local variables."},
|
|
|
|
{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',
|
2018-09-27 02:50:19 +08:00
|
|
|
OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
|
2016-09-07 04:57:50 +08:00
|
|
|
"Show the current frame source file global and static variables."},
|
|
|
|
{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',
|
2018-09-27 02:50:19 +08:00
|
|
|
OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
|
2016-09-07 04:57:50 +08:00
|
|
|
"Show variable declaration information (source file and line where the "
|
|
|
|
"variable was declared)."},
|
|
|
|
{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r',
|
2018-09-27 02:50:19 +08:00
|
|
|
OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeRegularExpression,
|
2016-09-07 04:57:50 +08:00
|
|
|
"The <variable-name> argument for name lookups are regular expressions."},
|
|
|
|
{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',
|
2018-09-27 02:50:19 +08:00
|
|
|
OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
|
2016-09-07 04:57:50 +08:00
|
|
|
"Show variable scope (argument, local, global, static)."},
|
|
|
|
{LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,
|
2018-09-27 02:50:19 +08:00
|
|
|
nullptr, {}, 0, eArgTypeName,
|
2016-09-07 04:57:50 +08:00
|
|
|
"Specify the summary that the variable output should use."},
|
|
|
|
{LLDB_OPT_SET_2, false, "summary-string", 'z',
|
2018-09-27 02:50:19 +08:00
|
|
|
OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeName,
|
2016-09-07 04:57:50 +08:00
|
|
|
"Specify a summary string to use to format the variable output."},
|
2011-07-07 12:38:25 +08:00
|
|
|
};
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
static Status ValidateNamedSummary(const char *str, void *) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!str || !str[0])
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("must specify a valid named summary");
|
2016-09-07 04:57:50 +08:00
|
|
|
TypeSummaryImplSP summary_sp;
|
2018-12-15 08:15:33 +08:00
|
|
|
if (!DataVisualization::NamedSummaryFormats::GetSummaryFormat(
|
|
|
|
ConstString(str), summary_sp))
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("must specify a valid named summary");
|
|
|
|
return Status();
|
2013-01-18 04:24:11 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
static Status ValidateSummaryString(const char *str, void *) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!str || !str[0])
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("must specify a non-empty summary string");
|
|
|
|
return Status();
|
2013-01-18 04:24:11 +08:00
|
|
|
}
|
2011-07-07 12:38:25 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
|
|
|
|
: OptionGroup(), include_frame_options(show_frame_options),
|
|
|
|
summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
|
|
|
|
|
|
|
|
OptionGroupVariable::~OptionGroupVariable() {}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status
|
|
|
|
OptionGroupVariable::SetOptionValue(uint32_t option_idx,
|
|
|
|
llvm::StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!include_frame_options)
|
|
|
|
option_idx += 3;
|
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
|
|
|
const int short_option = g_variable_options[option_idx].short_option;
|
2016-09-07 04:57:50 +08:00
|
|
|
switch (short_option) {
|
|
|
|
case 'r':
|
|
|
|
use_regex = true;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
show_args = false;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
show_locals = false;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
show_globals = true;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
show_decl = true;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
show_scope = true;
|
|
|
|
break;
|
2018-10-31 12:00:22 +08:00
|
|
|
case 't':
|
|
|
|
show_recognized_args = false;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
case 'y':
|
|
|
|
error = summary.SetCurrentValue(option_arg);
|
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
error = summary_string.SetCurrentValue(option_arg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error.SetErrorStringWithFormat("unrecognized short option '%c'",
|
|
|
|
short_option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
2011-07-07 12:38:25 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void OptionGroupVariable::OptionParsingStarting(
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
show_args = true; // Frame option only
|
2018-10-31 12:00:22 +08:00
|
|
|
show_recognized_args = true; // Frame option only
|
2016-09-07 04:57:50 +08:00
|
|
|
show_locals = true; // Frame option only
|
|
|
|
show_globals = false; // Frame option only
|
|
|
|
show_decl = false;
|
|
|
|
use_regex = false;
|
|
|
|
show_scope = false;
|
|
|
|
summary.Clear();
|
|
|
|
summary_string.Clear();
|
2011-07-07 12:38:25 +08:00
|
|
|
}
|
|
|
|
|
2011-09-10 09:19:01 +08:00
|
|
|
#define NUM_FRAME_OPTS 3
|
2011-07-07 12:38:25 +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> OptionGroupVariable::GetDefinitions() {
|
2016-09-23 05:06:13 +08:00
|
|
|
auto result = llvm::makeArrayRef(g_variable_options);
|
2018-05-01 00:49:04 +08:00
|
|
|
// Show the "--no-args", "--no-locals" and "--show-globals" options if we are
|
|
|
|
// showing frame specific options
|
2016-09-07 04:57:50 +08:00
|
|
|
if (include_frame_options)
|
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-07-07 12:38:25 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Skip the "--no-args", "--no-locals" and "--show-globals" options if we are
|
|
|
|
// not showing frame specific options (globals only)
|
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.drop_front(NUM_FRAME_OPTS);
|
2011-07-07 12:38:25 +08:00
|
|
|
}
|