--- title: "DynamoRIO Option Parser" layout: default permalink: /page_droption.html ---
DynamoRIO
|
The droption
DynamoRIO Extension provides easy-to-use option declaration and parsing for both clients and standalone programs.
To use droption
with your client simply include this line in your client's CMakeLists.txt
file:
That will automatically set up the include path. Then include the header file:
To use droption
with a non-client, for example with a tool frontend or other standalone application, simply include the droption.h header file.
Simply declare a global instance of droption_t
of the desired option value type for each option you wish to support. Typical value types are bool
, integers, or std::string
. For example:
Then, ask for the droption_t
instances to be filled in from the passed-in arguments from the user. In a client using dr_client_main()
, or from a standalone application, invoke parse_argv():
A standalone application should pass DROPTION_SCOPE_FRONTEND
rather than DROPTION_SCOPE_CLIENT
.
In a client using the legacy dr_init()
, use the dr_parse_options()
function:
A boolean option foo
can be negated on the command line using any of the following prefixes:
Option values are retrieved with get_value:
The value set on the command line can be overridden with the set_value
function.
droption
only supports the following standard value types for options:
droption
also provides some custom value types for options:
To produced automated documentation with the long-format descriptions, we recommend building a small program that looks something like this:
This program can be built and run at documentation generation time to produce HTML that can then be embedded into Doxygen or other documentation.
To support multiple strings to trigger the same option, pass a vector of strings as the name, with the primary name (the one used in usage reports) listed first, like this:
For options that accumulate values (DROPTION_FLAG_ACCUMULATE), a re-attach with a statically linked client will keep the old value from the prior attach. The droption_parser_t::clear_values()
function can be called from the client on exit or initialization to clear all the values.