PStack  2.0
Stack trace printer for MSVC and GCC binaries
addr2ln::addr2ln_options Class Referencefinal

Parse and maintain options that alter the execution of Addr2Ln. More...

#include <addr2ln_options.hpp>

Inheritance diagram for addr2ln::addr2ln_options:
Collaboration diagram for addr2ln::addr2ln_options:

Classes

struct  options_data
 The full set of options information available to addr2ln::addr2ln_options. More...
 

Type Definitions

using address_list = std::set< psystem::address_t >
 The a container for list of user-supplied addresses to look up.
 

Option Observers

static psystem::address_t const * get_module_base_address () noexcept
 Access the address to use as the module-base address for look-ups. More...
 
static address_list const & get_address_list () noexcept
 Access the list of addresses for Addr2Ln to process. More...
 
static std::string const & get_module_name () noexcept
 Access the name of the desired executable module that will be examined. More...
 

Informational Functions

static void print_usage () noexcept
 Print command-line help information to the screen. More...
 
static void print_version_info () noexcept
 Output information about the Addr2Ln's version to the screen. More...
 
static void print_usage (const char *const prog_name) noexcept
 Print command-line help information to the screen. More...
 

Construction / Destruction

 addr2ln_options (int argc, char const *argv[])
 Construct the addr2ln_options instance. More...
 
 ~addr2ln_options () noexcept
 Deallocate the options instance. More...
 

Private Utilities

static void dump_arguments (addr2ln_options::options_data const &d) noexcept
 Output all the command-line data to stdout. More...
 
int try_switch (int i, int argc, char const *argv[])
 Try to alter the options data based on a single character CLI switch. More...
 

Member Data

std::unique_ptr< options_datam_data
 A pointer to the options data (PImpl pattern).
 

Additional Inherited Members

- Private Member Functions inherited from psystem::not_copyable
 not_copyable (not_copyable const &)=delete
 Delete the copy constructor.
 
not_copyableoperator= (not_copyable const &)=delete
 Delete the assignment operator.
 
constexpr not_copyable () noexcept
 A simple CTOR suitable for noexcept and constexpr uses.
 
 ~not_copyable () noexcept
 A simple CTOR suitable for noexcept uses.
 

Detailed Description

Parse and maintain options that alter the execution of Addr2Ln.

None of the "Option Observers" will function in this interface until one (and only one) instance of addr2ln_options has been instantiated. Only the main method is allowed to construct an instance of this class. This addr2ln_options is a singleton, and the lifetime is limited to a predictable scope in main.

Since this uses the PImpl pattern, we will make this class not_copyable, rather than redefining the copy constructor to do a deep copy of the "impl." Copying isn't useful at the moment anyway.

Author
Matt Bisson
Date
14 August, 2016
Since
Addr2ln 0.1
Version
Addr2ln 0.1

Constructor & Destructor Documentation

addr2ln::addr2ln_options::addr2ln_options ( int  argc,
char const *  argv[] 
)
private

Construct the addr2ln_options instance.

This method is private because it is only intended to be called from the main function (main is a friend of this class). This is because the constructor has a side-effect of populating a global (singleton) pointer with this. When main allocates the addr2ln_options instance, we at least know the lifetime of the singleton coincides with it.

Parameters
[in]argcThe command-line argument count.
[in]argvThe array of command-line arguments.
Exceptions
psystem::exception::ui_exceptionUnder the following conditions:
  • If an argument should be an address, but is not convertable (lexically) from a string to a hexadecimal integer, or is out of the range of [0, ULONG_MAX).
  • If an argument is a switch that is not valid for Addr2Ln.
  • If no module or addresses were specified after all arguments are processed.
falseIn the event of a non-fatal operation that interrupts the option parsing (e.g., printing the help screen), this method throws a bool with the value false.
Postcondition
Invoking the static interface is possible after successful completion of the constructor.
Warning
Only main can create and destroy the options data. Make sure to do both operations in a single-threaded context. This assumption prevents us from having to guard the global data, check for nullptr, and so on.
addr2ln::addr2ln_options::~addr2ln_options ( )
noexcept

Deallocate the options instance.

Postcondition
Invoking the static interface results in undefined behavior.

Member Function Documentation

void addr2ln::addr2ln_options::dump_arguments ( addr2ln_options::options_data const &  d)
staticprivatenoexcept

Output all the command-line data to stdout.

Parameters
[in]dThe internal data of the addr2ln_options instance.
addr2ln_options::address_list const & addr2ln::addr2ln_options::get_address_list ( )
staticnoexcept

Access the list of addresses for Addr2Ln to process.

Returns
A collection of addresses. It is valid for the lifetime of the addr2ln_options instance.
psystem::address_t const * addr2ln::addr2ln_options::get_module_base_address ( )
staticnoexcept

Access the address to use as the module-base address for look-ups.

Returns
This may be nullptr if unspecified.
std::string const & addr2ln::addr2ln_options::get_module_name ( )
staticnoexcept

Access the name of the desired executable module that will be examined.

Returns
The module name. It is valid for the lifetime of the addr2ln_options instance.
void addr2ln::addr2ln_options::print_usage ( )
staticnoexcept

Print command-line help information to the screen.

Essentially, this is instructing the user what parameters this addr2ln_options class understands.

void addr2ln::addr2ln_options::print_usage ( const char *const  prog_name)
staticprivatenoexcept

Print command-line help information to the screen.

Essentially, this is instructing the user what parameters this addr2ln_options class understands. Because print_usage() relies on the option instance being initialized, this version exists to provide the required information without the requirement. The presence of prog_name is illogical as a public API, hence the private access restriction.

Parameters
[in]prog_nameThe name of the application from the command-line.
void addr2ln::addr2ln_options::print_version_info ( )
staticnoexcept

Output information about the Addr2Ln's version to the screen.

This also displays PSystem information, as Addr2Ln relies upon that system.

int addr2ln::addr2ln_options::try_switch ( int  i,
int  argc,
char const *  argv[] 
)
private

Try to alter the options data based on a single character CLI switch.

If the user asks for version information or command-line option help, this method will print that to the command line.

Parameters
[in]iThe index (in argv) to the command-line parameter that should be examined.
[in]argcThe total count of arguments that exist within argv.
[in]argvThe array of character arrays that represent what the user passed to Addr2Ln on the command-line.
Returns
The new index to examine after try_switch returns. Some switches may require n extra command-line arguments. In those cases, this method will examine the extra arguments, and return i + n. In all other cases, it will simply return i.
Exceptions
psystem::exception::ui_exceptionIf the user specified a switch that is not valid for Addr2Ln.
falseIn the event of a non-fatal operation that interrupts the option parsing (e.g., printing the help screen), this method throws a bool with the value false.
Precondition
i must be less than argc, and argv[i] must contain at least two characters.

The documentation for this class was generated from the following files: