[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 3/6] linux-user: Add strace support for printing argument
From: |
Laurent Vivier |
Subject: |
Re: [PATCH v2 3/6] linux-user: Add strace support for printing argument of syscalls used for extended attributes |
Date: |
Wed, 10 Jun 2020 21:06:11 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 |
Le 08/06/2020 à 18:43, Filip Bozuta a écrit :
> From: Filip Bozuta <Filip.Bozuta@syrmia.com>
>
> This patch implements strace argument printing functionality for following
> syscalls:
>
> *getxattr, lgetxattr, fgetxattr - retrieve an extended attribute value
>
> ssize_t getxattr(const char *path, const char *name, void *value,
> size_t size)
> ssize_t lgetxattr(const char *path, const char *name, void *value,
> size_t size)
> ssize_t fgetxattr(int fd, const char *name, void *value, size_t size)
> man page: https://www.man7.org/linux/man-pages/man2/getxattr.2.html
>
> *listxattr, llistxattr, flistxattr - list extended attribute names
>
> ssize_t listxattr(const char *path, char *list, size_t size)
> ssize_t llistxattr(const char *path, char *list, size_t size)
> ssize_t flistxattr(int fd, char *list, size_t size)
> man page: https://www.man7.org/linux/man-pages/man2/listxattr.2.html
>
> *removexattr, lremovexattr, fremovexattr - remove an extended attribute
>
> int removexattr(const char *path, const char *name)
> int lremovexattr(const char *path, const char *name)
> int fremovexattr(int fd, const char *name)
> man page:
> https://www.man7.org/linux/man-pages/man2/removexattr.2.html
>
> Implementation notes:
>
> All of the syscalls have strings as argument types and thus a separate
> printing function was stated in file "strace.list" for every one of them.
> All of these printing functions were defined in "strace.c" using existing
> printing functions for appropriate argument types:
> "print_string()" - for (const char*) type
> "print_pointer()" - for (char*) and (void *) type
> "print_raw_param()" for (int) and (size_t) type
> Syscalls "getxattr()" and "lgetxattr()" have the same number and type of
> arguments and thus their print functions ("print_getxattr",
> "print_lgetxattr")
> share a same definition. The same statement applies to syscalls
> "listxattr()"
> and "llistxattr()".
> Function "print_syscall_ret_listxattr()" was added to print the returned
> list
> of extended attributes for syscalls and was listed as a "result" function
> in file
> "strace.list" for syscalls: "listxattr(), llistxattr(), flistxattr()".
>
> Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
> ---
> linux-user/strace.c | 126 +++++++++++++++++++++++++++++++++++++++++
> linux-user/strace.list | 21 ++++---
> 2 files changed, 138 insertions(+), 9 deletions(-)
>
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index f980451e3f..59fdb0a05f 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -830,6 +830,45 @@ print_syscall_ret_adjtimex(const struct syscallname
> *name, abi_long ret,
> }
> #endif
>
> +#if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
> + || defined(TARGGET_NR_flistxattr)
> +static void
> +print_syscall_ret_listxattr(const struct syscallname *name, abi_long ret,
> + abi_long arg0, abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> + const char *errstr = NULL;
> +
> + qemu_log(" = ");
> + if (ret < 0) {
> + qemu_log("-1 errno=%d", errno);
> + errstr = target_strerror(-ret);
> + if (errstr) {
> + qemu_log(" (%s)", errstr);
> + }
We have several time this kind of code in strace.c
(print_syscall_ret_addr, print_syscall_ret_adjtimex, print_syscall_ret)
perhaps it could be moved to generic function (in a previous patch)?
> + } else {
> + qemu_log(TARGET_ABI_FMT_ld, ret);
> + qemu_log(" (list = ");
> + if (arg1 != 0) {
> + abi_long attr = arg1;
> + for (;;) {
We should avoid an infinite loop, and it's easy as you now the size of
the buffer (ret).
> + print_string(attr, 1);
> + attr += target_strlen(attr) + 1;
> + if (target_strlen(attr) == 0) {
> + break;
> + }
> + qemu_log(",");
> + }
> + } else {
> + qemu_log("NULL");
> + }
> + qemu_log(")");
> + }
> +
> + qemu_log("\n");
> +}
You should do as for the entry functions, and define the ones for
llistxattr and flistxattr:
#define print_syscall_ret_flistxattr print_syscall_ret_listxattr
#define print_syscall_ret_xlistxattr print_syscall_ret_listxattr
I have no preference on that but it's to be homogeneous with the rest of
the code.
> +#endif
> +
> UNUSED static struct flags access_flags[] = {
> FLAG_GENERIC(F_OK),
> FLAG_GENERIC(R_OK),
> @@ -1637,6 +1676,93 @@ print_fcntl(const struct syscallname *name,
> #define print_fcntl64 print_fcntl
> #endif
>
> +#ifdef TARGET_NR_fgetxattr
> +static void
> +print_fgetxattr(const struct syscallname *name,
> + abi_long arg0, abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> + print_syscall_prologue(name);
> + print_raw_param("%d", arg0, 0);
> + print_string(arg1, 0);
> + print_pointer(arg2, 0);
> + print_raw_param(TARGET_FMT_lu, arg3, 1);
> + print_syscall_epilogue(name);
> +}
> +#endif
> +
> +#ifdef TARGET_NR_flistxattr
> +static void
> +print_flistxattr(const struct syscallname *name,
> + abi_long arg0, abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> + print_syscall_prologue(name);
> + print_raw_param("%d", arg0, 0);
> + print_pointer(arg1, 0);
> + print_raw_param(TARGET_FMT_lu, arg2, 1);
> + print_syscall_epilogue(name);
> +}
> +#endif
> +
> +#if defined(TARGET_NR_getxattr) || defined(TARGET_NR_lgetxattr)
> +static void
> +print_getxattr(const struct syscallname *name,
> + abi_long arg0, abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> + print_syscall_prologue(name);
> + print_string(arg0, 0);
> + print_string(arg1, 0);
> + print_pointer(arg2, 0);
> + print_raw_param(TARGET_FMT_lu, arg3, 1);
> + print_syscall_epilogue(name);
> +}
> +#define print_lgetxattr print_getxattr
> +#endif
> +
> +#if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr)
> +static void
> +print_listxattr(const struct syscallname *name,
> + abi_long arg0, abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> + print_syscall_prologue(name);
> + print_string(arg0, 0);
> + print_pointer(arg1, 0);
> + print_raw_param(TARGET_FMT_lu, arg2, 1);
> + print_syscall_epilogue(name);
> +}
> +#define print_llistxattr print_listxattr
> +#endif
> +
> +#if defined(TARGET_NR_fremovexattr)
> +static void
> +print_fremovexattr(const struct syscallname *name,
> + abi_long arg0, abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> + print_syscall_prologue(name);
> + print_raw_param("%d", arg0, 0);
> + print_string(arg1, 1);
> + print_syscall_epilogue(name);
> +}
> +#endif
> +
> +#if defined(TARGET_NR_removexattr) || defined(TARGET_NR_lremovexattr)
> +static void
> +print_removexattr(const struct syscallname *name,
> + abi_long arg0, abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> + print_syscall_prologue(name);
> + print_string(arg0, 0);
> + print_string(arg1, 1);
> + print_syscall_epilogue(name);
> +}
> +#define print_lremovexattr print_removexattr
> +#endif
> +
> #ifdef TARGET_NR_futimesat
> static void
> print_futimesat(const struct syscallname *name,
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index fb9799e7e6..05a72370c1 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -218,13 +218,14 @@
> { TARGET_NR_fdatasync, "fdatasync" , "%s(%d)", NULL, NULL },
> #endif
> #ifdef TARGET_NR_fgetxattr
> -{ TARGET_NR_fgetxattr, "fgetxattr" , NULL, NULL, NULL },
> +{ TARGET_NR_fgetxattr, "fgetxattr" , NULL, print_fgetxattr, NULL },
> #endif
> #ifdef TARGET_NR_finit_module
> { TARGET_NR_finit_module, "finit_module" , NULL, NULL, NULL },
> #endif
> #ifdef TARGET_NR_flistxattr
> -{ TARGET_NR_flistxattr, "flistxattr" , NULL, NULL, NULL },
> +{ TARGET_NR_flistxattr, "flistxattr" , NULL, print_flistxattr,
> + print_syscall_ret_listxattr},
print_syscall_ret_flistxattr
> #endif
> #ifdef TARGET_NR_flock
> { TARGET_NR_flock, "flock" , NULL, NULL, NULL },
> @@ -233,7 +234,7 @@
> { TARGET_NR_fork, "fork" , "%s()", NULL, NULL },
> #endif
> #ifdef TARGET_NR_fremovexattr
> -{ TARGET_NR_fremovexattr, "fremovexattr" , NULL, NULL, NULL },
> +{ TARGET_NR_fremovexattr, "fremovexattr" , NULL, print_fremovexattr, NULL },
> #endif
> #ifdef TARGET_NR_fsetxattr
> { TARGET_NR_fsetxattr, "fsetxattr" , NULL, NULL, NULL },
> @@ -396,7 +397,7 @@
> { TARGET_NR_getuid32, "getuid32" , NULL, NULL, NULL },
> #endif
> #ifdef TARGET_NR_getxattr
> -{ TARGET_NR_getxattr, "getxattr" , NULL, NULL, NULL },
> +{ TARGET_NR_getxattr, "getxattr" , NULL, print_getxattr, NULL },
> #endif
> #ifdef TARGET_NR_getxgid
> { TARGET_NR_getxgid, "getxgid" , NULL, NULL, NULL },
> @@ -480,7 +481,7 @@
> { TARGET_NR_lchown32, "lchown32" , NULL, NULL, NULL },
> #endif
> #ifdef TARGET_NR_lgetxattr
> -{ TARGET_NR_lgetxattr, "lgetxattr" , NULL, NULL, NULL },
> +{ TARGET_NR_lgetxattr, "lgetxattr" , NULL, print_lgetxattr, NULL },
> #endif
> #ifdef TARGET_NR_link
> { TARGET_NR_link, "link" , NULL, print_link, NULL },
> @@ -495,10 +496,12 @@
> { TARGET_NR_listen, "listen" , "%s(%d,%d)", NULL, NULL },
> #endif
> #ifdef TARGET_NR_listxattr
> -{ TARGET_NR_listxattr, "listxattr" , NULL, NULL, NULL },
> +{ TARGET_NR_listxattr, "listxattr" , NULL, print_listxattr,
> + print_syscall_ret_listxattr},
> #endif
> #ifdef TARGET_NR_llistxattr
> -{ TARGET_NR_llistxattr, "llistxattr" , NULL, NULL, NULL },
> +{ TARGET_NR_llistxattr, "llistxattr" , NULL, print_llistxattr,
> + print_syscall_ret_listxattr},
print_syscall_ret_llistxattr
> #endif
> #ifdef TARGET_NR__llseek
> { TARGET_NR__llseek, "_llseek" , NULL, print__llseek, NULL },
> @@ -510,7 +513,7 @@
> { TARGET_NR_lookup_dcookie, "lookup_dcookie" , NULL, NULL, NULL },
> #endif
> #ifdef TARGET_NR_lremovexattr
> -{ TARGET_NR_lremovexattr, "lremovexattr" , NULL, NULL, NULL },
> +{ TARGET_NR_lremovexattr, "lremovexattr" , NULL, print_lremovexattr, NULL },
> #endif
> #ifdef TARGET_NR_lseek
> { TARGET_NR_lseek, "lseek" , NULL, NULL, NULL },
> @@ -1116,7 +1119,7 @@
> { TARGET_NR_remap_file_pages, "remap_file_pages" , NULL, NULL, NULL },
> #endif
> #ifdef TARGET_NR_removexattr
> -{ TARGET_NR_removexattr, "removexattr" , NULL, NULL, NULL },
> +{ TARGET_NR_removexattr, "removexattr" , NULL, print_removexattr, NULL },
> #endif
> #ifdef TARGET_NR_rename
> { TARGET_NR_rename, "rename" , NULL, print_rename, NULL },
>
Thanks,
Laurent
- [PATCH v2 0/6] Add strace support for printing arguments of selected syscalls, Filip Bozuta, 2020/06/08
- [PATCH v2 1/6] linux-user: Extend strace support to enable argument printing after syscall execution, Filip Bozuta, 2020/06/08
- [PATCH v2 2/6] linux-user: Add strace support for a group of syscalls, Filip Bozuta, 2020/06/08
- [PATCH v2 3/6] linux-user: Add strace support for printing argument of syscalls used for extended attributes, Filip Bozuta, 2020/06/08
- Re: [PATCH v2 3/6] linux-user: Add strace support for printing argument of syscalls used for extended attributes,
Laurent Vivier <=
- [PATCH v2 4/6] linux-user: Add strace support for printing arguments of lseek(), Filip Bozuta, 2020/06/08
- [PATCH v2 5/6] linux-user: Add strace support for printing arguments of chown()/lchown(), Filip Bozuta, 2020/06/08
- [PATCH v2 6/6] linux-user: Add strace support for printing arguments of fallocate(), Filip Bozuta, 2020/06/08
- Re: [PATCH v2 0/6] Add strace support for printing arguments of selected syscalls, no-reply, 2020/06/08
- Re: [PATCH v2 0/6] Add strace support for printing arguments of selected syscalls, no-reply, 2020/06/08