Improve the debug parsing to allow flags to be added and subtracted

from the existing set.

Submitted by:	rea@freebsd.org
This commit is contained in:
Scott Long 2017-10-01 15:35:21 +00:00
parent 9e63610e82
commit cfd6fd5ad1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=324162
4 changed files with 69 additions and 2 deletions

View File

@ -354,6 +354,11 @@ All
variables can be named by either an integer value or a text string.
Multiple values can be specified together by either ORing the
integer values or by providing a comma-separated list of names.
A text string prefixed by
.Qq +
adds the specified debug levels to the existing set, while the prefix
.Qq -
removes them from the existing set.
The current
.Va debug_level
status is reported in both formats for convenience.

View File

@ -330,6 +330,11 @@ All
variables can be named by either an integer value or a text string.
Multiple values can be specified together by either ORing the
integer values or by providing a comma-separated list of names.
A text string prefixed by
.Qq +
adds the specified debug levels to the existing set, while the prefix
.Qq -
removes them from the existing set.
The current
.Va debug_level
status is reported in both formats for convenience.

View File

@ -1834,6 +1834,12 @@ static struct mpr_debug_string {
{"trace", MPR_TRACE}
};
enum mpr_debug_level_combiner {
COMB_NONE,
COMB_ADD,
COMB_SUB
};
static int
mpr_debug_sysctl(SYSCTL_HANDLER_ARGS)
{
@ -1885,6 +1891,7 @@ static void
mpr_parse_debug(struct mpr_softc *sc, char *list)
{
struct mpr_debug_string *string;
enum mpr_debug_level_combiner op;
char *token, *endtoken;
size_t sz;
int flags, i;
@ -1892,6 +1899,17 @@ mpr_parse_debug(struct mpr_softc *sc, char *list)
if (list == NULL || *list == '\0')
return;
if (*list == '+') {
op = COMB_ADD;
list++;
} else if (*list == '-') {
op = COMB_SUB;
list++;
} else
op = COMB_NONE;
if (*list == '\0')
return;
flags = 0;
sz = sizeof(mpr_debug_strings) / sizeof(mpr_debug_strings[0]);
while ((token = strsep(&list, ":,")) != NULL) {
@ -1911,7 +1929,17 @@ mpr_parse_debug(struct mpr_softc *sc, char *list)
}
}
sc->mpr_debug = flags;
switch (op) {
case COMB_NONE:
sc->mpr_debug = flags;
break;
case COMB_ADD:
sc->mpr_debug |= flags;
break;
case COMB_SUB:
sc->mpr_debug &= (~flags);
break;
}
return;
}

View File

@ -1696,6 +1696,12 @@ static struct mps_debug_string {
{"trace", MPS_TRACE}
};
enum mps_debug_level_combiner {
COMB_NONE,
COMB_ADD,
COMB_SUB
};
static int
mps_debug_sysctl(SYSCTL_HANDLER_ARGS)
{
@ -1747,6 +1753,7 @@ static void
mps_parse_debug(struct mps_softc *sc, char *list)
{
struct mps_debug_string *string;
enum mps_debug_level_combiner op;
char *token, *endtoken;
size_t sz;
int flags, i;
@ -1754,6 +1761,17 @@ mps_parse_debug(struct mps_softc *sc, char *list)
if (list == NULL || *list == '\0')
return;
if (*list == '+') {
op = COMB_ADD;
list++;
} else if (*list == '-') {
op = COMB_SUB;
list++;
} else
op = COMB_NONE;
if (*list == '\0')
return;
flags = 0;
sz = sizeof(mps_debug_strings) / sizeof(mps_debug_strings[0]);
while ((token = strsep(&list, ":,")) != NULL) {
@ -1773,7 +1791,18 @@ mps_parse_debug(struct mps_softc *sc, char *list)
}
}
sc->mps_debug = flags;
switch (op) {
case COMB_NONE:
sc->mps_debug = flags;
break;
case COMB_ADD:
sc->mps_debug |= flags;
break;
case COMB_SUB:
sc->mps_debug &= (~flags);
break;
}
return;
}