Message ID | 20200722200437.312767-5-Filip.Bozuta@syrmia.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add strace support for printing arguments for a group of selected syscalls | expand |
Le 22/07/2020 à 22:04, Filip Bozuta a écrit : > This patch introduces a type 'struct enums' and function 'print_enums()' > that can be used to print enumerated argument values of some syscalls > in strace. This can be used in future strace implementations. > > Also, macros 'ENUM_GENERIC()', 'ENUM_TARGET()' and 'ENUM_END', are > introduced to enable automatic generation of aproppriate enumarated > values and their repsective string representations (these macros are > exactly the same as 'FLAG_GENERIC()', 'FLAG_TARGET()' and 'FLAG_END'). > > Future patches are planned to modify all existing print functions in > 'strace.c' that print arguments of syscalls with enumerated values to > use this new api. > > Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> > --- > linux-user/strace.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/linux-user/strace.c b/linux-user/strace.c > index 40f863c6e2..def92c4d73 100644 > --- a/linux-user/strace.c > +++ b/linux-user/strace.c > @@ -52,9 +52,23 @@ struct flags { > /* end of flags array */ > #define FLAG_END { 0, NULL } > > +/* Structure used to translate enumerated values into strings */ > +struct enums { > + abi_long e_value; /* enum value */ > + const char *e_string; /* stringified enum */ > +}; > + > +/* common enums for all architectures */ > +#define ENUM_GENERIC(name) { name, #name } > +/* target specific enums */ > +#define ENUM_TARGET(name) { TARGET_ ## name, #name } > +/* end of enums array */ > +#define ENUM_END { 0, NULL } > + > UNUSED static const char *get_comma(int); > UNUSED static void print_pointer(abi_long, int); > UNUSED static void print_flags(const struct flags *, abi_long, int); > +UNUSED static void print_enums(const struct enums *, abi_long, int); > UNUSED static void print_at_dirfd(abi_long, int); > UNUSED static void print_file_mode(abi_long, int); > UNUSED static void print_open_flags(abi_long, int); > @@ -1248,6 +1262,23 @@ print_flags(const struct flags *f, abi_long flags, int last) > } > } > > +static void > +print_enums(const struct enums *e, abi_long enum_arg, int last) > +{ > + for (; e->e_string != NULL; e++) { > + if (e->e_value == enum_arg) { > + qemu_log("%s", e->e_string); > + break; > + } > + } > + > + if (e->e_string == NULL) { > + qemu_log("%#x", (unsigned int)enum_arg); > + } > + > + qemu_log("%s", get_comma(last)); > +} > + > static void > print_at_dirfd(abi_long dirfd, int last) > { > Reviewed-by: Laurent Vivier <laurent@vivier.eu>
diff --git a/linux-user/strace.c b/linux-user/strace.c index 40f863c6e2..def92c4d73 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -52,9 +52,23 @@ struct flags { /* end of flags array */ #define FLAG_END { 0, NULL } +/* Structure used to translate enumerated values into strings */ +struct enums { + abi_long e_value; /* enum value */ + const char *e_string; /* stringified enum */ +}; + +/* common enums for all architectures */ +#define ENUM_GENERIC(name) { name, #name } +/* target specific enums */ +#define ENUM_TARGET(name) { TARGET_ ## name, #name } +/* end of enums array */ +#define ENUM_END { 0, NULL } + UNUSED static const char *get_comma(int); UNUSED static void print_pointer(abi_long, int); UNUSED static void print_flags(const struct flags *, abi_long, int); +UNUSED static void print_enums(const struct enums *, abi_long, int); UNUSED static void print_at_dirfd(abi_long, int); UNUSED static void print_file_mode(abi_long, int); UNUSED static void print_open_flags(abi_long, int); @@ -1248,6 +1262,23 @@ print_flags(const struct flags *f, abi_long flags, int last) } } +static void +print_enums(const struct enums *e, abi_long enum_arg, int last) +{ + for (; e->e_string != NULL; e++) { + if (e->e_value == enum_arg) { + qemu_log("%s", e->e_string); + break; + } + } + + if (e->e_string == NULL) { + qemu_log("%#x", (unsigned int)enum_arg); + } + + qemu_log("%s", get_comma(last)); +} + static void print_at_dirfd(abi_long dirfd, int last) {
This patch introduces a type 'struct enums' and function 'print_enums()' that can be used to print enumerated argument values of some syscalls in strace. This can be used in future strace implementations. Also, macros 'ENUM_GENERIC()', 'ENUM_TARGET()' and 'ENUM_END', are introduced to enable automatic generation of aproppriate enumarated values and their repsective string representations (these macros are exactly the same as 'FLAG_GENERIC()', 'FLAG_TARGET()' and 'FLAG_END'). Future patches are planned to modify all existing print functions in 'strace.c' that print arguments of syscalls with enumerated values to use this new api. Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> --- linux-user/strace.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)