qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 1/6] linux-user: Extend strace support to enable argument


From: Laurent Vivier
Subject: Re: [PATCH v4 1/6] linux-user: Extend strace support to enable argument printing after syscall execution
Date: Thu, 18 Jun 2020 16:35:56 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

Le 16/06/2020 à 12:39, Filip Bozuta a écrit :
> From: Filip Bozuta <Filip.Bozuta@syrmia.com>
> 
>     Structure "struct syscallname" in file "strace.c" is used for "-strace"
>     to print arguments and return values of syscalls. The last field of
>     this structure "result" represents the calling function that prints the
>     return values. This field was extended in this patch so that this function
>     takes all syscalls arguments beside the return value. In this way, it 
> enables
>     "-strace" to print arguments of syscalls that have changed after the 
> syscall
>     execution. This extension will be useful as there are many syscalls that
>     return values inside their arguments (i.e. listxattr() that returns the 
> list
>     of extended attributes inside the "list" argument).
> 
> Implementation notes:
> 
>     Since there are already three existing "print_syscall_ret*" functions 
> inside
>     "strace.c" ("print_syscall_ret_addr()", "print_syscall_ret_adjtimex()",
>     "print_syscall_ret_newselect()"), they were changed to have all syscall 
> arguments
>     beside the return value. This was done so that these functions don't 
> cause build
>     errors (even though syscall arguments are not used in these functions).
>     There is code repetition in these functions for checking the return value
>     and printing the approppriate error message (this code is also located in
>     print_syscall_ret() at the end of "strace.c"). That is the reason why a
>     function "syscall_print_err()" was added for this code and put inside 
> these
>     functions.
> 
> Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
> ---
>  linux-user/qemu.h    |  4 ++-
>  linux-user/strace.c  | 67 ++++++++++++++++++++++++++------------------
>  linux-user/syscall.c |  2 +-
>  3 files changed, 43 insertions(+), 30 deletions(-)
> 
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index ce902f5132..8f938b8105 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -383,7 +383,9 @@ int host_to_target_waitstatus(int status);
>  void print_syscall(int num,
>                     abi_long arg1, abi_long arg2, abi_long arg3,
>                     abi_long arg4, abi_long arg5, abi_long arg6);
> -void print_syscall_ret(int num, abi_long arg1);
> +void print_syscall_ret(int num, abi_long ret,
> +                       abi_long arg1, abi_long arg2, abi_long arg3,
> +                       abi_long arg4, abi_long arg5, abi_long arg6);
>  /**
>   * print_taken_signal:
>   * @target_signum: target signal being taken
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index 0d9095c674..805fcb9fd1 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -19,7 +19,9 @@ struct syscallname {
>      void (*call)(const struct syscallname *,
>                   abi_long, abi_long, abi_long,
>                   abi_long, abi_long, abi_long);
> -    void (*result)(const struct syscallname *, abi_long);
> +    void (*result)(const struct syscallname *, abi_long,
> +                   abi_long, abi_long, abi_long,
> +                   abi_long, abi_long, abi_long);
>  };
>  
>  #ifdef __GNUC__
> @@ -736,17 +738,29 @@ print_ipc(const struct syscallname *name,
>   */
>  
>  static void
> -print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
> +print_syscall_err(abi_long ret)
>  {
>      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);
> +        }
>      }
> -    if (errstr) {
> -        qemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
> -    } else {
> -        qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
> +}
> +
> +static void
> +print_syscall_ret_addr(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)
> +{
> +    print_syscall_err(ret);
> +
> +    if (ret >= 0) {
> +        qemu_log("0x" TARGET_ABI_FMT_lx "\n", ret);
>      }
>  }
>  
> @@ -760,7 +774,9 @@ print_syscall_ret_raw(struct syscallname *name, abi_long 
> ret)
>  
>  #ifdef TARGET_NR__newselect
>  static void
> -print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
> +print_syscall_ret_newselect(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)
>  {
>      qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
>      print_fdset(newselect_arg1,newselect_arg2);

print_syscall_ret_newselect() was already displaying arg1...arg5 by
storing them before the call in some global variables.
Now, you can remove these global variables and use the value from the
function parameters.

Thanks,
Laurent



reply via email to

[Prev in Thread] Current Thread [Next in Thread]