1 //===-- OptionGroupVariable.cpp -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Interpreter/OptionGroupVariable.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Error.h"
17 #include "lldb/DataFormatters/DataVisualization.h"
18 #include "lldb/Interpreter/CommandInterpreter.h"
19 #include "lldb/Target/Target.h"
20 #include "lldb/Utility/Utils.h"
23 using namespace lldb_private;
25 // if you add any options here, remember to update the counters in
26 // OptionGroupVariable::GetNumDefinitions()
27 static OptionDefinition g_variable_options[] = {
28 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',
29 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
30 "Omit function arguments."},
31 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',
32 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
33 "Omit local variables."},
34 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',
35 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
36 "Show the current frame source file global and static variables."},
37 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',
38 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
39 "Show variable declaration information (source file and line where the "
40 "variable was declared)."},
41 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r',
42 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
43 "The <variable-name> argument for name lookups are regular expressions."},
44 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',
45 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
46 "Show variable scope (argument, local, global, static)."},
47 {LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,
48 nullptr, nullptr, 0, eArgTypeName,
49 "Specify the summary that the variable output should use."},
50 {LLDB_OPT_SET_2, false, "summary-string", 'z',
51 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName,
52 "Specify a summary string to use to format the variable output."},
55 static Error ValidateNamedSummary(const char *str, void *) {
57 return Error("must specify a valid named summary");
58 TypeSummaryImplSP summary_sp;
59 if (DataVisualization::NamedSummaryFormats::GetSummaryFormat(
60 ConstString(str), summary_sp) == false)
61 return Error("must specify a valid named summary");
65 static Error ValidateSummaryString(const char *str, void *) {
67 return Error("must specify a non-empty summary string");
71 OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
72 : OptionGroup(), include_frame_options(show_frame_options),
73 summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
75 OptionGroupVariable::~OptionGroupVariable() {}
77 Error OptionGroupVariable::SetOptionValue(uint32_t option_idx,
78 llvm::StringRef option_arg,
79 ExecutionContext *execution_context) {
81 if (!include_frame_options)
83 const int short_option = g_variable_options[option_idx].short_option;
84 switch (short_option) {
104 error = summary.SetCurrentValue(option_arg);
107 error = summary_string.SetCurrentValue(option_arg);
110 error.SetErrorStringWithFormat("unrecognized short option '%c'",
118 void OptionGroupVariable::OptionParsingStarting(
119 ExecutionContext *execution_context) {
120 show_args = true; // Frame option only
121 show_locals = true; // Frame option only
122 show_globals = false; // Frame option only
127 summary_string.Clear();
130 #define NUM_FRAME_OPTS 3
132 llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {
133 auto result = llvm::makeArrayRef(g_variable_options);
134 // Show the "--no-args", "--no-locals" and "--show-globals"
135 // options if we are showing frame specific options
136 if (include_frame_options)
139 // Skip the "--no-args", "--no-locals" and "--show-globals"
140 // options if we are not showing frame specific options (globals only)
141 return result.drop_front(NUM_FRAME_OPTS);