[Lldb-commits] [PATCH] D54682: [Driver] Extract option parsing and option processing.

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Nov 18 19:17:38 PST 2018

JDevlieghere created this revision.
JDevlieghere added reviewers: clayborg, labath, zturner, jingham.
JDevlieghere added a project: LLDB.

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.




-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54682.174554.patch
Type: text/x-patch
Size: 24386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181119/c2ff7cc7/attachment-0001.bin>

More information about the lldb-commits mailing list