summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Syromyatnikov <evgsyr@gmail.com>2021-08-07 17:38:40 +0200
committerDmitry V. Levin <ldv@strace.io>2021-08-14 01:25:12 +0000
commit0b2ce39e0b7321b1cb9f4bc8c87b6836d5f6db88 (patch)
treeb2358f6717ab8a6e2813e41177c13aa3e812c6ec
parent344a3fae75563aa7844da37b1bc0df3660e503ce (diff)
downloadstrace-0b2ce39e0b7321b1cb9f4bc8c87b6836d5f6db88.tar.gz
xlat: add auxval mode to sprintflags_ex
sprintflags is often used to decode flag set returned by a syscall; it, however, looks somewhat ugly when collided with xlat styles (and even without it, somewhat superfluous[1] when values that do not match any flags are printed). Introduce a special mode that makes sprintflags output more akin to XLAT_STYLE_VERBOSE comment (except when XLAT_STYLE_RAW is used). [1] It may be seen useful as the default return value format is decimal and sprintflags uses hex, but at least fcntl always prints flags in return values as RVAL_HEX anyway. * src/defs.h (enum xlat_style_private_flag_bits) <SPFF_AUXSTR_MODE_BIT>: New flag bit. (enum xlat_style_private_flags) <SPFF_AUXSTR_MODE>: New flag. * src/xlat.c (sprintflags_ex): Handle SPFF_AUXSTR_MODE flag in style.
-rw-r--r--src/defs.h6
-rw-r--r--src/xlat.c19
2 files changed, 18 insertions, 7 deletions
diff --git a/src/defs.h b/src/defs.h
index 340368396..b2dcd0350 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -844,6 +844,9 @@ enum xlat_style_private_flag_bits {
/* print_xlat */
PXF_DEFAULT_STR_BIT,
+
+ /* sprintflags_ex */
+ SPFF_AUXSTR_MODE_BIT,
};
enum xlat_style_private_flags {
@@ -853,6 +856,9 @@ enum xlat_style_private_flags {
/* print_xlat */
FLAG(PXF_DEFAULT_STR),
+
+ /* sprintflags_ex */
+ FLAG(SPFF_AUXSTR_MODE),
};
/**
diff --git a/src/xlat.c b/src/xlat.c
index e3e632eee..7e2d2baa6 100644
--- a/src/xlat.c
+++ b/src/xlat.c
@@ -324,7 +324,7 @@ sprintflags_ex(const char *prefix, const struct xlat *xlat, uint64_t flags,
style = get_xlat_style(style);
if (xlat_verbose(style) == XLAT_STYLE_RAW) {
- if (!flags)
+ if (!flags || ((style & SPFF_AUXSTR_MODE) && !sep))
return NULL;
if (sep)
@@ -338,7 +338,8 @@ sprintflags_ex(const char *prefix, const struct xlat *xlat, uint64_t flags,
if (flags == 0 && xlat->data->val == 0 && xlat->data->str) {
if (sep)
*outptr++ = sep;
- if (xlat_verbose(style) == XLAT_STYLE_VERBOSE) {
+ if (xlat_verbose(style) == XLAT_STYLE_VERBOSE &&
+ !(style & SPFF_AUXSTR_MODE)) {
outptr = xappendstr(outstr, outptr, "0 /* %s */",
xlat->data->str);
} else {
@@ -348,7 +349,8 @@ sprintflags_ex(const char *prefix, const struct xlat *xlat, uint64_t flags,
return outstr;
}
- if (xlat_verbose(style) == XLAT_STYLE_VERBOSE && flags) {
+ if (xlat_verbose(style) == XLAT_STYLE_VERBOSE && flags &&
+ !(style & SPFF_AUXSTR_MODE)) {
if (sep) {
*outptr++ = sep;
sep = '\0';
@@ -362,7 +364,8 @@ sprintflags_ex(const char *prefix, const struct xlat *xlat, uint64_t flags,
&& (flags & xlat->data[idx].val) == xlat->data[idx].val) {
if (sep) {
*outptr++ = sep;
- } else if (xlat_verbose(style) == XLAT_STYLE_VERBOSE) {
+ } else if (xlat_verbose(style) == XLAT_STYLE_VERBOSE &&
+ !(style & SPFF_AUXSTR_MODE)) {
outptr = stpcpy(outptr, " /* ");
}
@@ -376,7 +379,8 @@ sprintflags_ex(const char *prefix, const struct xlat *xlat, uint64_t flags,
if (flags) {
if (sep)
*outptr++ = sep;
- if (found || xlat_verbose(style) != XLAT_STYLE_VERBOSE)
+ if (found || (xlat_verbose(style) != XLAT_STYLE_VERBOSE &&
+ (!(style & SPFF_AUXSTR_MODE) || sep)))
outptr = xappendstr(outstr, outptr, "%s",
sprint_xlat_val(flags, style));
} else {
@@ -384,10 +388,11 @@ sprintflags_ex(const char *prefix, const struct xlat *xlat, uint64_t flags,
return NULL;
}
- if (found && xlat_verbose(style) == XLAT_STYLE_VERBOSE)
+ if (found && xlat_verbose(style) == XLAT_STYLE_VERBOSE &&
+ !(style & SPFF_AUXSTR_MODE))
outptr = stpcpy(outptr, " */");
- return outstr;
+ return outptr != outstr ? outstr : NULL;
}
/**