diff options
author | Pavel Labath <pavel@labath.sk> | 2019-07-10 17:09:47 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-07-10 17:09:47 +0000 |
commit | 1abaeece719c99ad9b408257b71c19c62db438cc (patch) | |
tree | 49f9511a7195ebcdaf27a8c9444181bfcb7bf8a5 /lldb/source/Host/common/OptionParser.cpp | |
parent | 8728e457065365f8f6fbbf86a665885d9dde082a (diff) | |
download | bcm5719-llvm-1abaeece719c99ad9b408257b71c19c62db438cc.tar.gz bcm5719-llvm-1abaeece719c99ad9b408257b71c19c62db438cc.zip |
Options: Reduce code duplication
Summary:
While investigating breakages caused by D63110, I noticed we were
building the short options strings in three places. Some of them used a
leading ':' to detect missing arguments, and some didn't. This was the
indirect cause of D63110. Here, I move the common code into a utility
function.
Also, unify the code which appends the sentinel value at the end of the
option vector, and make it harder for users to pass invalid argc-argv
combos to getopt (another component of D63110) by having the
OptionParser::Parse function take a (Mutable)ArrayRef.
This unification has uncovered that we don't handle missing arguments
while building aliases, However, it's not possible to write an effective
test for this, as right now it is not possible to return an error out of
the alias parsing code (which means we are printing the generic
"failure" message even after this patch).
Reviewers: mgorny, aprantl
Reviewed By: mgorny
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D63770
llvm-svn: 365665
Diffstat (limited to 'lldb/source/Host/common/OptionParser.cpp')
-rw-r--r-- | lldb/source/Host/common/OptionParser.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lldb/source/Host/common/OptionParser.cpp b/lldb/source/Host/common/OptionParser.cpp index 92ff6f63d95..1e76f9b8f9f 100644 --- a/lldb/source/Host/common/OptionParser.cpp +++ b/lldb/source/Host/common/OptionParser.cpp @@ -27,8 +27,9 @@ void OptionParser::Prepare(std::unique_lock<std::mutex> &lock) { void OptionParser::EnableError(bool error) { opterr = error ? 1 : 0; } -int OptionParser::Parse(int argc, char *const argv[], llvm::StringRef optstring, - const Option *longopts, int *longindex) { +int OptionParser::Parse(llvm::MutableArrayRef<char *> argv, + llvm::StringRef optstring, const Option *longopts, + int *longindex) { std::vector<option> opts; while (longopts->definition != nullptr) { option opt; @@ -41,7 +42,8 @@ int OptionParser::Parse(int argc, char *const argv[], llvm::StringRef optstring, } opts.push_back(option()); std::string opt_cstr = optstring; - return getopt_long_only(argc, argv, opt_cstr.c_str(), &opts[0], longindex); + return getopt_long_only(argv.size() - 1, argv.data(), opt_cstr.c_str(), + &opts[0], longindex); } char *OptionParser::GetOptionArgument() { return optarg; } |