Message ID | 20200616103927.20222-2-filip.bozuta@syrmia.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add strace support for printing arguments of selected syscalls | expand |
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
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); @@ -783,18 +799,13 @@ print_syscall_ret_newselect(const struct syscallname *name, abi_long ret) #define TARGET_TIME_ERROR 5 /* clock not synchronized */ #ifdef TARGET_NR_adjtimex static void -print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret) +print_syscall_ret_adjtimex(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; + print_syscall_err(ret); - qemu_log(" = "); - if (ret < 0) { - qemu_log("-1 errno=%d", errno); - errstr = target_strerror(-ret); - if (errstr) { - qemu_log(" (%s)", errstr); - } - } else { + if (ret >= 0) { qemu_log(TARGET_ABI_FMT_ld, ret); switch (ret) { case TARGET_TIME_OK: @@ -2847,25 +2858,25 @@ print_syscall(int num, void -print_syscall_ret(int num, abi_long ret) +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) { int i; - const char *errstr = NULL; for(i=0;i<nsyscalls;i++) if( scnames[i].nr == num ) { if( scnames[i].result != NULL ) { - scnames[i].result(&scnames[i], ret); + scnames[i].result(&scnames[i], ret, + arg1, arg2, arg3, + arg4, arg5, arg6); } else { - if (ret < 0) { - errstr = target_strerror(-ret); - } - if (errstr) { - qemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", - -ret, errstr); - } else { - qemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); + print_syscall_err(ret); + + if (ret >= 0) { + qemu_log(TARGET_ABI_FMT_ld, ret); } + qemu_log("\n"); } break; } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 05f03919ff..009bb67422 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -12441,7 +12441,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, arg5, arg6, arg7, arg8); if (unlikely(qemu_loglevel_mask(LOG_STRACE))) { - print_syscall_ret(num, ret); + print_syscall_ret(num, ret, arg1, arg2, arg3, arg4, arg5, arg6); } record_syscall_return(cpu, num, ret);