[Lldb-commits] [PATCH] D43837: Move option parsing out of the Args class

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 27 15:52:32 PST 2018


labath created this revision.
labath added reviewers: davide, jingham, zturner.

The args class is used in plenty of places (a lot of them in the lower lldb
layers) for representing a list of arguments, and most of these places don't
care about option parsing. Moving the option parsing out of the class removes
the largest external dependency (there are a couple more, but these are in
static functions), and brings us closer to being able to move it to the
Utility module).

The new home for these functions is the Options class, which was already used
as an argument to the parse calls, so this just inverts the dependency between
the two.

The functions are themselves are mainly just copied -- the biggest functional
change I've made to them is to avoid modifying the input Args argument (getopt
likes to permute the argument vector), as it was weird to have another class
reorder the entries in Args class. So now the functions don't modify the input
arguments, and (for those where it makes sense) return a new Args vector
instead. I've also made the addition of a "fake arg0" (required for getopt
compatibility) an implementation detail rather than a part of interface.

While doing that I noticed that ParseForCompletion function was recording the
option indexes in the shuffled vector, but then the consumer was looking up the
entries in the unshuffled one. This manifested itself as us not being able to
complete "watchpoint set variable foo --" (because getopt would move "foo" to
the end). Surprisingly all other completions (e.g. "watchpoint set variable foo
--w") were not affected by this. However, I couldn't find a comprehensive test
for command argument completion, so I consolidated the existing tests and added
a bunch of new ones.


https://reviews.llvm.org/D43837

Files:
  include/lldb/Interpreter/Args.h
  include/lldb/Interpreter/Options.h
  packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py
  source/Commands/CommandObjectSettings.cpp
  source/Interpreter/Args.cpp
  source/Interpreter/CommandAlias.cpp
  source/Interpreter/CommandObject.cpp
  source/Interpreter/Options.cpp
  source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43837.136168.patch
Type: text/x-patch
Size: 57460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180227/bac05795/attachment-0001.bin>


More information about the lldb-commits mailing list