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"
12 #include "lldb/DataFormatters/DataVisualization.h"
13 #include "lldb/Host/OptionParser.h"
14 #include "lldb/Interpreter/CommandInterpreter.h"
15 #include "lldb/Target/Target.h"
16 #include "lldb/Utility/Status.h"
19 using namespace lldb_private;
21 // if you add any options here, remember to update the counters in
22 // OptionGroupVariable::GetNumDefinitions()
23 static constexpr OptionDefinition g_variable_options[] = {
24 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',
25 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
26 "Omit function arguments."},
27 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-recognized-args", 't',
28 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
29 "Omit recognized function arguments."},
30 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',
31 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
32 "Omit local variables."},
33 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',
34 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
35 "Show the current frame source file global and static variables."},
36 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',
37 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
38 "Show variable declaration information (source file and line where the "
39 "variable was declared)."},
40 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r',
41 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeRegularExpression,
42 "The <variable-name> argument for name lookups are regular expressions."},
43 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',
44 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
45 "Show variable scope (argument, local, global, static)."},
46 {LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,
47 nullptr, {}, 0, eArgTypeName,
48 "Specify the summary that the variable output should use."},
49 {LLDB_OPT_SET_2, false, "summary-string", 'z',
50 OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeName,
51 "Specify a summary string to use to format the variable output."},
54 static Status ValidateNamedSummary(const char *str, void *) {
56 return Status("must specify a valid named summary");
57 TypeSummaryImplSP summary_sp;
58 if (!DataVisualization::NamedSummaryFormats::GetSummaryFormat(
59 ConstString(str), summary_sp))
60 return Status("must specify a valid named summary");
64 static Status ValidateSummaryString(const char *str, void *) {
66 return Status("must specify a non-empty summary string");
70 OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
71 : OptionGroup(), include_frame_options(show_frame_options),
72 summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
74 OptionGroupVariable::~OptionGroupVariable() {}
77 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 show_recognized_args = false;
107 error = summary.SetCurrentValue(option_arg);
110 error = summary_string.SetCurrentValue(option_arg);
113 error.SetErrorStringWithFormat("unrecognized short option '%c'",
121 void OptionGroupVariable::OptionParsingStarting(
122 ExecutionContext *execution_context) {
123 show_args = true; // Frame option only
124 show_recognized_args = true; // Frame option only
125 show_locals = true; // Frame option only
126 show_globals = false; // Frame option only
131 summary_string.Clear();
134 #define NUM_FRAME_OPTS 3
136 llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {
137 auto result = llvm::makeArrayRef(g_variable_options);
138 // Show the "--no-args", "--no-locals" and "--show-globals" options if we are
139 // showing frame specific options
140 if (include_frame_options)
143 // Skip the "--no-args", "--no-locals" and "--show-globals" options if we are
144 // not showing frame specific options (globals only)
145 return result.drop_front(NUM_FRAME_OPTS);