In order to deal consistently with global state in LLDB, the reproducer feature affects LLDB's initialization. For example, when replaying, the FileSystem singleton is initialized with a virtual file system.
This is a problem for the driver because it initialized the debugger before parsing command line options. The reason is that the driver, among other things, checks whether files exists (e.g. core files, target, files to be sourced). It also relies on the debugger to parse things like the (scripting) language, the architecture, etc.
In an initial attempt I tried to populate the OptionData before the debugger is initialized. This proved to be complicated, because of the sanity checks that are performed by calling into the debugger of the filesystem. Although it would be possible to perform these checks after parsing, it would cause errors to no longer appear in the same order as specified by the user, but in an arbitrary order specified by the driver implementation. Although I like the idea conceptually I don't believe this is an acceptable regression.
Implemented in this patch is a new ArgParser class that extracts the existing argument parsing logic. Basically it calls getopt_long_only repeatedly and populates a list with the short option and its value. Because the ArgParser is dumb it can do all its work before the debugger is initialized. Afterwards the driver iterates over the options from the argparser (instead of calling getopt_long_only every time) and do whatever is needed.