1 //===-- OptionGroupVariable.cpp -------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionGroupVariable.h"
11 #include "lldb/DataFormatters/DataVisualization.h"
12 #include "lldb/Host/OptionParser.h"
13 #include "lldb/Interpreter/CommandInterpreter.h"
14 #include "lldb/Target/Target.h"
15 #include "lldb/Utility/Status.h"
18 using namespace lldb_private
;
20 // if you add any options here, remember to update the counters in
21 // OptionGroupVariable::GetNumDefinitions()
22 static constexpr OptionDefinition g_variable_options
[] = {
23 {LLDB_OPT_SET_1
| LLDB_OPT_SET_2
, false, "no-args", 'a',
24 OptionParser::eNoArgument
, nullptr, {}, 0, eArgTypeNone
,
25 "Omit function arguments."},
26 {LLDB_OPT_SET_1
| LLDB_OPT_SET_2
, false, "no-recognized-args", 't',
27 OptionParser::eNoArgument
, nullptr, {}, 0, eArgTypeNone
,
28 "Omit recognized function arguments."},
29 {LLDB_OPT_SET_1
| LLDB_OPT_SET_2
, false, "no-locals", 'l',
30 OptionParser::eNoArgument
, nullptr, {}, 0, eArgTypeNone
,
31 "Omit local variables."},
32 {LLDB_OPT_SET_1
| LLDB_OPT_SET_2
, false, "show-globals", 'g',
33 OptionParser::eNoArgument
, nullptr, {}, 0, eArgTypeNone
,
34 "Show the current frame source file global and static variables."},
35 {LLDB_OPT_SET_1
| LLDB_OPT_SET_2
, false, "show-declaration", 'c',
36 OptionParser::eNoArgument
, nullptr, {}, 0, eArgTypeNone
,
37 "Show variable declaration information (source file and line where the "
38 "variable was declared)."},
39 {LLDB_OPT_SET_1
| LLDB_OPT_SET_2
, false, "regex", 'r',
40 OptionParser::eNoArgument
, nullptr, {}, 0, eArgTypeRegularExpression
,
41 "The <variable-name> argument for name lookups are regular expressions."},
42 {LLDB_OPT_SET_1
| LLDB_OPT_SET_2
, false, "scope", 's',
43 OptionParser::eNoArgument
, nullptr, {}, 0, eArgTypeNone
,
44 "Show variable scope (argument, local, global, static)."},
45 {LLDB_OPT_SET_1
, false, "summary", 'y', OptionParser::eRequiredArgument
,
46 nullptr, {}, 0, eArgTypeName
,
47 "Specify the summary that the variable output should use."},
48 {LLDB_OPT_SET_2
, false, "summary-string", 'z',
49 OptionParser::eRequiredArgument
, nullptr, {}, 0, eArgTypeName
,
50 "Specify a summary string to use to format the variable output."},
53 static Status
ValidateNamedSummary(const char *str
, void *) {
55 return Status("must specify a valid named summary");
56 TypeSummaryImplSP summary_sp
;
57 if (!DataVisualization::NamedSummaryFormats::GetSummaryFormat(
58 ConstString(str
), summary_sp
))
59 return Status("must specify a valid named summary");
63 static Status
ValidateSummaryString(const char *str
, void *) {
65 return Status("must specify a non-empty summary string");
69 OptionGroupVariable::OptionGroupVariable(bool show_frame_options
)
70 : include_frame_options(show_frame_options
), show_args(false),
71 show_recognized_args(false), show_locals(false), show_globals(false),
72 use_regex(false), show_scope(false), show_decl(false),
73 summary(ValidateNamedSummary
), summary_string(ValidateSummaryString
) {}
76 OptionGroupVariable::SetOptionValue(uint32_t option_idx
,
77 llvm::StringRef option_arg
,
78 ExecutionContext
*execution_context
) {
80 if (!include_frame_options
)
82 const int short_option
= g_variable_options
[option_idx
].short_option
;
83 switch (short_option
) {
103 show_recognized_args
= false;
106 error
= summary
.SetCurrentValue(option_arg
);
109 error
= summary_string
.SetCurrentValue(option_arg
);
112 llvm_unreachable("Unimplemented option");
118 void OptionGroupVariable::OptionParsingStarting(
119 ExecutionContext
*execution_context
) {
120 show_args
= true; // Frame option only
121 show_recognized_args
= true; // Frame option only
122 show_locals
= true; // Frame option only
123 show_globals
= false; // Frame option only
128 summary_string
.Clear();
131 #define NUM_FRAME_OPTS 3
133 llvm::ArrayRef
<OptionDefinition
> OptionGroupVariable::GetDefinitions() {
134 auto result
= llvm::ArrayRef(g_variable_options
);
135 // Show the "--no-args", "--no-locals" and "--show-globals" options if we are
136 // showing frame specific options
137 if (include_frame_options
)
140 // Skip the "--no-args", "--no-locals" and "--show-globals" options if we are
141 // not showing frame specific options (globals only)
142 return result
.drop_front(NUM_FRAME_OPTS
);