diff --git a/lldb/include/lldb/Host/OptionParser.h b/lldb/include/lldb/Host/OptionParser.h index ca0594645645..b03eeb74ec4e 100644 --- a/lldb/include/lldb/Host/OptionParser.h +++ b/lldb/include/lldb/Host/OptionParser.h @@ -1,50 +1,54 @@ //===-- OptionParser.h ------------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef liblldb_OptionParser_h_ #define liblldb_OptionParser_h_ #include #include #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/ArrayRef.h" struct option; namespace lldb_private { struct OptionDefinition; struct Option { // The definition of the option that this refers to. const OptionDefinition *definition; // if not NULL, set *flag to val when option found int *flag; // if flag not NULL, value to set *flag to; else return value int val; }; class OptionParser { public: enum OptionArgument { eNoArgument = 0, eRequiredArgument, eOptionalArgument }; static void Prepare(std::unique_lock &lock); static void EnableError(bool error); - static int Parse(int argc, char *const argv[], llvm::StringRef optstring, - const Option *longopts, int *longindex); + /// Argv must be an argument vector "as passed to main", i.e. terminated with + /// a nullptr. + static int Parse(llvm::MutableArrayRef argv, + llvm::StringRef optstring, const Option *longopts, + int *longindex); static char *GetOptionArgument(); static int GetOptionIndex(); static int GetOptionErrorCause(); static std::string GetShortOptionString(struct option *long_options); }; } #endif // liblldb_OptionParser_h_ diff --git a/lldb/source/Host/common/OptionParser.cpp b/lldb/source/Host/common/OptionParser.cpp index 92ff6f63d951..1e76f9b8f9f1 100644 --- a/lldb/source/Host/common/OptionParser.cpp +++ b/lldb/source/Host/common/OptionParser.cpp @@ -1,81 +1,83 @@ //===-- source/Host/common/OptionParser.cpp ---------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "lldb/Host/OptionParser.h" #include "lldb/Host/HostGetOpt.h" #include "lldb/lldb-private-types.h" #include using namespace lldb_private; void OptionParser::Prepare(std::unique_lock &lock) { static std::mutex g_mutex; lock = std::unique_lock(g_mutex); #ifdef __GLIBC__ optind = 0; #else optreset = 1; optind = 1; #endif } 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 argv, + llvm::StringRef optstring, const Option *longopts, + int *longindex) { std::vector