Skip to content

Commit 1232964

Browse files
[lldb] Omit --show-globals in help target var (#85855)
This option doesn't exist. It is currently displayed by `help target var` due to a bug introduced by 41ae8e7 in 2018. Some code for `target var` and `frame var` is shared, and some hard-code constants are used in order to filter out options that belong only to `frame var`. However, the aforementioned commit failed to update these constants properly. This patch addresses the issue by having a _single_ place where the filtering of options needs to be done.
1 parent 3fbac79 commit 1232964

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

lldb/source/Interpreter/OptionGroupVariable.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ static constexpr OptionDefinition g_variable_options[] = {
5050
"Specify a summary string to use to format the variable output."},
5151
};
5252

53+
static constexpr auto g_num_frame_options = 4;
54+
static const auto g_variable_options_noframe =
55+
llvm::ArrayRef<OptionDefinition>(g_variable_options)
56+
.drop_front(g_num_frame_options);
57+
5358
static Status ValidateNamedSummary(const char *str, void *) {
5459
if (!str || !str[0])
5560
return Status("must specify a valid named summary");
@@ -77,9 +82,9 @@ OptionGroupVariable::SetOptionValue(uint32_t option_idx,
7782
llvm::StringRef option_arg,
7883
ExecutionContext *execution_context) {
7984
Status error;
80-
if (!include_frame_options)
81-
option_idx += 3;
82-
const int short_option = g_variable_options[option_idx].short_option;
85+
llvm::ArrayRef<OptionDefinition> variable_options =
86+
include_frame_options ? g_variable_options : g_variable_options_noframe;
87+
const int short_option = variable_options[option_idx].short_option;
8388
switch (short_option) {
8489
case 'r':
8590
use_regex = true;
@@ -128,16 +133,9 @@ void OptionGroupVariable::OptionParsingStarting(
128133
summary_string.Clear();
129134
}
130135

131-
#define NUM_FRAME_OPTS 3
132-
133136
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)
138-
return result;
139-
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);
137+
// Show the "--no-args", "--no-recognized-args", "--no-locals" and
138+
// "--show-globals" options if we are showing frame specific options
139+
return include_frame_options ? g_variable_options
140+
: g_variable_options_noframe;
143141
}

lldb/test/API/functionalities/target_var/TestTargetVar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ class targetCommandTestCase(TestBase):
1515
def testTargetVarExpr(self):
1616
self.build()
1717
lldbutil.run_to_name_breakpoint(self, "main")
18+
self.expect(
19+
"help target variable",
20+
substrs=[
21+
"--no-args",
22+
"--no-recognized-args",
23+
"--no-locals",
24+
"--show-globals",
25+
],
26+
matching=False,
27+
)
1828
self.expect("target variable i", substrs=["i", "42"])
1929
self.expect(
2030
"target variable var", patterns=["\(incomplete \*\) var = 0[xX](0)*dead"]

0 commit comments

Comments
 (0)