Skip to content

Commit d384c37

Browse files
authored
[lldb] Prevent mutation of CommandAlias::GetOptionArguments (#6806)
Fix a mutation of `CommandAlias::m_option_args_sp`, which resulted in cases where aliases would fail to run on second, and subsequent times. For example, an alias such as: ``` command alias p1 p 1 ``` When run the second time, the following error would be reported to the user: ``` error: expression failed to parse: error: <user expression 1>:1:1: expression is not assignable -- 1 ^ ~ ``` To fix this, `CommandAlias::Desugar` now constructs options to a freshly constructed vector, rather than by appending to the results of `GetOptionArguments`. rdar://107770836 Differential Revision: https://reviews.llvm.org/D150078 (cherry picked from commit 7652377)
1 parent dbfd484 commit d384c37

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lldb/source/Interpreter/CommandAlias.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "lldb/Interpreter/CommandAlias.h"
1010

11+
#include "llvm/ADT/STLExtras.h"
1112
#include "llvm/Support/ErrorHandling.h"
1213

1314
#include "lldb/Interpreter/CommandInterpreter.h"
@@ -211,9 +212,9 @@ std::pair<lldb::CommandObjectSP, OptionArgVectorSP> CommandAlias::Desugar() {
211212
// FIXME: This doesn't work if the original alias fills a slot in the
212213
// underlying alias, since this just appends the two lists.
213214
auto desugared = ((CommandAlias *)underlying.get())->Desugar();
214-
auto options = GetOptionArguments();
215-
options->insert(options->begin(), desugared.second->begin(),
216-
desugared.second->end());
215+
OptionArgVectorSP options = std::make_shared<OptionArgVector>();
216+
llvm::append_range(*options, *desugared.second);
217+
llvm::append_range(*options, *GetOptionArguments());
217218
return {desugared.first, options};
218219
}
219220

lldb/test/API/commands/command/nested_alias/TestNestedAlias.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,7 @@ def cleanup():
101101
self.expect('command alias two expr -- 2')
102102
self.expect('command alias add_two two +')
103103
self.expect('add_two 3', patterns=[' = 5$'])
104+
# Check that aliases to aliases to raw input commands work the second
105+
# and subsequent times.
106+
self.expect('add_two 3', patterns=[' = 5$'])
107+
self.expect('add_two 3', patterns=[' = 5$'])

0 commit comments

Comments
 (0)