int dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv);
A dcmd is implemented with a function similar to the dcmd() declaration. This function receives four arguments and returns an integer status. The function arguments are:
Current address, also called dot. At the start of the dcmd, this address corresponds to the value of the dot "." variable in the debugger.
Integer containing the logical OR of one or more of the following flags:
As a convenience, the DCMD_HDRSPEC() macro is provided to allow a dcmd to test its flags to determine if it should print a header line (that is, it was not invoked as part of a loop, or it was invoked as the first iteration of a loop or pipeline).
Number of arguments in the argv array.
Array of arguments specified to the right of ::dcmd on the command line. These arguments can be either strings or integer values.
The dcmd function is expected to return one of the following integer values, defined in <sys/mdb_modapi.h>.
Each dcmd consists of a function defined according to the example dcmd() prototype, and a corresponding mdb_dcmd_t structure, as defined in <sys/mdb_modapi.h>. This structure consists of the following fields:
The string name of the dcmd, without the leading "::". The name cannot contain any of the MDB meta-characters, such as $ or `.
An optional usage string for the dcmd, to be printed when the dcmd returns DCMD_USAGE. For example, if the dcmd accepts options –a and –b, dc_usage might be specified as "[–ab]". If the dcmd accepts no arguments, dc_usage can be set to NULL. If the usage string begins with ":", this is shorthand for indicating that the dcmd requires an explicit address (that is, it requires DCMD_ADDRSPEC to be set in its flags parameter). If the usage string begins with "?", this indicates that the dcmd optionally accepts an address. These hints modify the usage message accordingly. If the usage string begins with "|", this indicates that the dcmd's input must be from a pipe.
A string which describes how the dcmd may be invoked. If NULL, this is treated as an empty string. Certain aspects of the string determine how the dcmd must be invoked:
The dcmd requires an address (flags must include DCMD_ADDRSPEC)
The dcmd optionally takes an address (flags may include DCMD_ADDRSPEC)
The dcmd must have input from a pipe (flags must include DCMD_ADDRSPECand DCMD_PIPE)
The dcmd does not take an address (flags must not include DCMD_ADDRSPEC)
The dcmd supports outputting into a pipe (flags may include DCMD_PIPE_OUT)
The dcmd does not support outputting into a pipe (flags must not include DCMD_PIPE_OUT)
Other than ':', '?', '|', and whitespace. No arguments are allowed (argc must be zero). The specified characters will be stripped from the usage string before it is printed.
These restrictions will be reflected in the usage message printed for the dcmd. If MDB_MI_ENFORCE_USAGE is set in the mdb_modinfo_t's mi_flags field, and the "nostrict" MDB option is not set, these restrictions will be enforced by MDB before invoking the dcmd.
A mandatory description string, briefly explaining the purpose of the dcmd. This string should consist of only a single line of text.
A pointer to the function that will be called to execute the dcmd.
An optional function pointer to a help function for the dcmd. If this pointer is not NULL, this function will be called when the user executes ::help dcmd. This function can use mdb_printf() to display further information or examples.