21 Commits

Author SHA1 Message Date
Eugene Syromyatnikov
3a7d7d8f8c xlat.c: handle NULL xlat in lookup routines as incremental search
This is going to be used later in IFLA_AF_SPEC decoding.

* xlat.c (xlookup): Add static variable pos, store xlat there when it is
non-NULL, use pos for lookup.
(xlat_search, xlat_idx): Add static variables pos and memb_left, store
xlat and nmemb there when xlat is non-NULL, use them for lookup.
(printxvals_ex): Store the last non-NULL xlat in static variable "last".
If the first xlat argument is NULL, use "last" instead.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-06-05 11:04:09 +00:00
Eugene Syromyatnikov
9fd42fc53a xlat.c: cleanup printxvals_ex a bit
* xlat.c (printxvals_ex): Change "str" variable visibility to the whole
function, jump to va_end instead of duplicating call and return, return
!!str.
2018-06-05 11:04:09 +00:00
Eugene Syromyatnikov
3869880887 xlat: add support for xlat_styles in printxval_dispatch
* defs.h (printxval_dispatch_ex): Rename from printxval_dispatch, add
style argument.
(printxval_dispatch): New static inline function, a thin wrapper around
printxval_dispatch_ex.
* xlat.c (printxval_dispatch): Rename to printxval_dispatch_ex, add
style argument, handle it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-05-21 11:02:54 +00:00
Eugene Syromyatnikov
947627ed15 Make printxval_dispatch publicly available
* evdev.c (enum xlat_type, printxval_dispatch): Move elsewhere.
* defs.h (enum_xlat_type): Move from evdev.c.
(printxval_dispatch): New declaration.
* xlat.c (printxval_dispatch): Move from evdev.c, drop static qualifier.
2018-05-21 11:02:54 +00:00
4e0c0becf9 time: use indexed lookups
* defs.h (xlat_idx): New prototype.
* xlat.c (xlat_idx): Remove static qualifier.
* time.c (do_adjtimex): Use xlat_idx instead of xlookup.
(SYS_FUNC(getitimer), SYS_FUNC(setitimer)): Use printxval_index
instead of printxval.
[ALPHA] (SYS_FUNC(osf_getitimer), SYS_FUNC(osf_setitimer)): Likewise.
(printclockname) [CLOCKID_TO_FD]: Likewise.
* xlat/adjtimex_state.in: Add "#value_indexed" directive.
* xlat/clocknames.in: Likewise.
* xlat/cpuclocknames.in: Add "#value_indexed" directive, add default
values to constants.
* xlat/itimer_which.in: Likewise.
2018-05-15 21:41:47 +00:00
Eugene Syromyatnikov
25d6ed1600 Add support for value-indexed xlats
There are quite a few xlats that start from 0 and not too sparse,
we can push the search time for them down to O(1).

* defs.h (printxval_indexn_ex): New declaration.
(printxval_indexn, printxval_index, printxval_index_ex): New macros.
* xlat.c (printxval_sized): Rename from printxval_searchn_ex,
add fn argument, call it instead of xlat_search.
(printxval_searchn_ex): Implement as a thin wrapper around
printxval_sized using xlat_search as a search function.
(xlat_idx): New function.
(printxval_indexn_ex): New function, a thin wrapper around
printxval_sized using xlat_idx as a search function.
* xlat/gen.sh: Add support for "#value_indexed" directive.
2018-04-27 00:56:25 +00:00
Eugene Syromyatnikov
69b958656e xlat: handle NULL str in print_xlat_ex
It allows to use the following code pattern:

	print_xlat_ex(val, xlookup(xlat, val), XLAT_STYLE_FMT_D);

* xlat.c (print_xlat_ex): Handle str being NULL: print val instead.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-27 00:56:25 +00:00
Eugene Syromyatnikov
eaabf55ad2 Move xlat_verbose and xlat_format from xlat.c to defs.h
As it will be used elsewhere.

* xlat.c (xlat_verbose, xlat_format): Move...
* defs.h: ...here.
2018-04-24 00:35:27 +00:00
Eugene Syromyatnikov
78be7e9d8a xlat: introduce XLAT_STYLE_FMT_D
As there are some possible users for it, apparently.

* defs.h (XLAT_STYLE_FORMAT_MASK): Update the value in order to
accommodate XLAT_STYLE_FMT_D.
(enum xlat_style) <XLAT_STYLE_FMT_D>: New enumeration entity.
(printxval64_d, printxval_d): New function, a shorthand for
printxvals_ex with a single xlat and XLAT_STYLE_FMT_D xlat style.
* xlat.c (sprint_xlat_val): Handle XLAT_STYLE_FMT_D.
2018-04-13 01:00:10 +02:00
Eugene Syromyatnikov
039717c2e6 Add support for various xlat formats
Since xlat printing routines now have a notion of "style" that should be
used for printing xlat values, we can also employ this argument for
passing information about number printing format (unsigned decimal
or hexadecimal, so far).

* defs.h (XLAT_STYLE_FORMAT_SHIFT, XLAT_STYLE_FORMAT_MASK): New macro
constant.
(enum xlat_style) <XLAT_STYLE_FMT_X, XLAT_STYLE_FMT_U>: New enumeration
entities.
* xlat.c (xlat_verbose, xlat_format): New macro for checking specific
aspect of style argument.
(get_xlat_style): Use xlat_verbose for checking xlat verbosity style.
(sprint_xlat_val, print_xlat_val): New function, for easing printing
raw constant number with respect to printing format style.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex,
printxval_searchn_ex, sprintflags_ex, printflags_ex, print_xlat_ex):
Use xlat_verbose macro for xlat verbosity style checks. Use
print_xlat_val instead of direct raw xlat value printing.
2018-04-13 01:00:10 +02:00
Eugene Syromyatnikov
6ece6574d2 Introduce print_xlat and print_xlat_ex
print_xlat_ex prints a named constant in accordance with xlat style
provided, print_xlat is a thin wrapper around print_xlat_ex that passes
stringified constant name as a string and XLAT_STYLE_DEFAULT as a style.

* defs.h (print_xlat_ex): New function prototype.
(print_xlat): New macro, a thin wrapper around print_xlat_ex.
* xlat.c (print_xlat_ex): New function.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-13 00:25:13 +02:00
Eugene Syromyatnikov
b9fcbe6112 Introduce XLAT_STYLE_DEFAULT
This will be needed later, with the introduction of user-configurable
xlat style setting (stored in xlat_verbosity variable).

* defs.h (XLAT_STYLE_VERBOSITY_MASK): New macro constant.
(enum xlat_style) <XLAT_STYLE_DEFAULT>: New enumeration entity.
(xlat_verbosity): New external declaration.
(printxvals, printxval_searchn, printxval_search_ex, sprintxval,
sprintflags, printflags64): Use XLAT_STYLE_DEFAULT instead of
XLAT_STYLE_ABBREV.
* strace.c (xlat_verbosity): New variable.
* xlat.c (get_xlat_style): New function.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex, sprintflags_ex,
printflags_ex): Use it.
2018-04-13 00:25:13 +02:00
Eugene Syromyatnikov
e8c3f34edd Introduce xlat verbosity styles
* defs.h (printxvals_ex): Rename from printxvals, add style argument.
(enum xlat_style): New enumeration.
(printxvals): New macro, a wrapper for printxvals_ex.
(printxval_searchn_ex): Rename from printxval_searchn, add style
argument.
(printxval_searchn): New macro, a wrapper for printxval_searchn_ex.
(printxval_search_ex): New macro, a wrapper for printxval_searchn_ex.
(sprintxval_ex): Rename from sprintxval, add style argument.
(sprintxval): New macro, a wrapper for sprintxval_ex.
(printflags_ex): Add style argument.
(sprintflags_ex): Rename from sprintflags, add style argument.
(sprintflags): New macro, a wrapper for sprintflags_ex.
(printflags64): Pass XLAT_STYLE_ABBREV as a style in printflags_ex call.
* netlink.c (decode_nlmsg_flags): Pass XLAT_STYLE_ABBREV as a style in
printflags_ex call.
* xlat.c (printxvals_ex): Rename from printxvals, add style argument,
handle it.
(sprintxval_ex): Rename from sprintxval, add style argument, handle it.
(printxval_searchn_ex): Rename from printxval_searchn, add style
argument, handle it.
(sprintflags_ex): Rename from sprintflags, add style argument,
handle it.
(printflags_ex): Add style argument, handle it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
References: https://github.com/strace/strace/issues/27
2018-04-13 00:25:13 +02:00
Eugene Syromyatnikov
3744bc73f7 Remove addflags
It has only single user and implementation of xlat styles for it would
lead to lots of code duplication.

* defs.h (addflags): Remove declaration.
* mem.c (print_mmap_flags): Convert addflags call into printflags64 with
non-zeroeness flags check.
* xlat.c (addflags): Remove.
2018-04-01 13:14:15 +00:00
daaf8ab7fe Update copyright headers
Headers updated automatically using maint/update_copyright_years.sh
script.
2018-02-13 22:00:00 +00:00
Eugene Syromyatnikov
0863915a0a xlat.c: return NULL in sprintflags if there are no flags
Otherwise the auxstr is rather ugly at times.

* xlat.c (sprintflags): Return NULL if no flags were printed.
2018-02-10 13:52:42 +00:00
Eugene Syromyatnikov
0b803f8edd Use xappendstr instead of xsnprintf where suitable
Replace occurrences of

    outptr += xsnprintf(outptr, sizeof(outstr) - (outptr - outstr), ...)

with much more sleek

    outptr = xappendstr(outstr, outptr, ...)

* desc.c (decode_select): Replace xsnprintf with xappendstr.
* open.c (sprint_open_modes): Likewise.
* poll.c (decode_poll_exiting): Likewise.
* signal.c (sprintsigmask_n): Likewise.
* xlat.c (sprintflags): Likewise.
2018-01-11 15:54:33 +00:00
Eugene Syromiatnikov
a907f4a126 xlat.c: add sprintxval for printing xval to string
* defs.h (sprintxval): New declaration.
(sprintxval): New function.
2018-01-07 00:05:42 +00:00
6e67a2b71e xlat.c: use xsnprintf instead of sprintf
* xlat.c: Include "xstring.h".
(sprintflags): Replace sprintf with xsnprintf.
2018-01-07 00:05:42 +00:00
184e94ba05 Fix a few spacing style issues
Reported by kernel's checkpatch.pl script.
2017-06-17 22:54:08 +00:00
88a34fa6da Move xlat related functions to a separate file
* util.c (xlookup, xlat_bsearch_compare, xlat_search, printxvals,
printxval_searchn, addflags, sprintflags, printflags_ex): Move ...
* xlat.c: ... to this new file.
* Makefile.am (strace_SOURCES): Add it.
2017-06-12 16:44:45 +00:00