xlat: add ability to provide default string to print_xlat_ex

In order to avoid dealing with xlat verbosity styles outside xlat code
as much as possible.

* defs.h (xlat_style_private_flag_bits): Rename from
print_array_flag_bits, add PXF_DEFAULT_STR_BIT.
(xlat_style_private_flags): Rename from print_array_flags, add
FLAG_(PXF_DEFAULT_STR).
* xlat.c (print_xlat_ex): Handle PXF_DEFAULT_STR by interpreting str
as a default value (print both value and str in XLAT_STYLE_ABBREV).
This commit is contained in:
Eugene Syromyatnikov 2018-08-19 19:55:15 +02:00
parent 9f25e7a911
commit 39a77ad205
2 changed files with 31 additions and 16 deletions

39
defs.h
View File

@ -735,6 +735,30 @@ printxval_dispatch(const struct xlat *xlat, size_t xlat_size, uint64_t val,
XLAT_STYLE_DEFAULT);
}
enum xlat_style_private_flag_bits {
/* print_array */
PAF_PRINT_INDICES_BIT = XLAT_STYLE_SPEC_BITS + 1,
PAF_INDEX_XLAT_SORTED_BIT,
PAF_INDEX_XLAT_VALUE_INDEXED_BIT,
/* print_xlat */
PXF_DEFAULT_STR_BIT,
};
#define FLAG_(name_) name_ = 1 << name_##_BIT
enum xlat_style_private_flags {
/* print_array */
FLAG_(PAF_PRINT_INDICES),
FLAG_(PAF_INDEX_XLAT_SORTED),
FLAG_(PAF_INDEX_XLAT_VALUE_INDEXED),
/* print_xlat */
FLAG_(PXF_DEFAULT_STR),
};
#undef FLAG_
/** Print a value in accordance with xlat formatting settings. */
extern void print_xlat_ex(uint64_t val, const char *str, enum xlat_style style);
#define print_xlat(val_) \
@ -786,21 +810,6 @@ typedef bool (*tfetch_mem_fn)(struct tcb *, kernel_ulong_t addr,
typedef bool (*print_fn)(struct tcb *, void *elem_buf,
size_t elem_size, void *opaque_data);
enum print_array_flag_bits {
PAF_PRINT_INDICES_BIT = XLAT_STYLE_SPEC_BITS + 1,
PAF_INDEX_XLAT_SORTED_BIT,
PAF_INDEX_XLAT_VALUE_INDEXED_BIT,
};
#define FLAG_(name_) name_ = 1 << name_##_BIT
enum print_array_flags {
FLAG_(PAF_PRINT_INDICES),
FLAG_(PAF_INDEX_XLAT_SORTED),
FLAG_(PAF_INDEX_XLAT_VALUE_INDEXED),
};
#undef FLAG_
/**
* @param flags Combination of xlat style settings and additional flags from

8
xlat.c
View File

@ -466,12 +466,18 @@ printflags_ex(uint64_t flags, const char *dflt, enum xlat_style style,
void
print_xlat_ex(const uint64_t val, const char *str, enum xlat_style style)
{
bool default_str = style & PXF_DEFAULT_STR;
style = get_xlat_style(style);
switch (xlat_verbose(style)) {
case XLAT_STYLE_ABBREV:
if (str) {
tprints(str);
if (default_str) {
print_xlat_val(val, style);
tprints_comment(str);
} else {
tprints(str);
}
break;
}
ATTRIBUTE_FALLTHROUGH;