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 functions
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 generic
function SYSCALL_RET_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 | 71 ++++++++++++++++++++++++++------------------
linux-user/syscall.c | 2 +-
3 files changed, 46 insertions(+), 31 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..8678a2aeac 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__
@@ -735,18 +737,29 @@ print_ipc(const struct syscallname *name,
* Variants for the return value output function
*/
+#define SYSCALL_RET_ERR(ret, errstr) \
+{ \
+ qemu_log(" = "); \
+ if (ret < 0) { \
+ qemu_log("-1 errno=%d", errno); \
+ errstr = target_strerror(-ret); \
+ if (errstr) { \
+ qemu_log(" (%s)", errstr); \
+ } \
+ } \
+}
+
static void
-print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
+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)
{
const char *errstr = NULL;
- if (ret < 0) {
- errstr = target_strerror(-ret);
- }
- if (errstr) {
- qemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
- } else {
- qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
+ SYSCALL_RET_ERR(ret, errstr);
+
+ if (ret >= 0) {
+ qemu_log("0x" TARGET_ABI_FMT_lx "\n", ret);
}
}
@@ -760,7 +773,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 +798,15 @@ 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;
- qemu_log(" = ");
- if (ret < 0) {
- qemu_log("-1 errno=%d", errno);
- errstr = target_strerror(-ret);
- if (errstr) {
- qemu_log(" (%s)", errstr);
- }
- } else {
+ SYSCALL_RET_ERR(ret, errstr);
+
+ if (ret >= 0) {
qemu_log(TARGET_ABI_FMT_ld, ret);
switch (ret) {
case TARGET_TIME_OK:
@@ -2847,7 +2859,9 @@ 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;
@@ -2855,17 +2869,16 @@ print_syscall_ret(int num, abi_long ret)
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);
+ SYSCALL_RET_ERR(ret, errstr);
+
+ 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);
--
2.17.1
Le 11/06/2020 à 17:51, 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 functions
> 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 generic
> function SYSCALL_RET_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 | 71 ++++++++++++++++++++++++++------------------
> linux-user/syscall.c | 2 +-
> 3 files changed, 46 insertions(+), 31 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..8678a2aeac 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__
> @@ -735,18 +737,29 @@ print_ipc(const struct syscallname *name,
> * Variants for the return value output function
> */
>
> +#define SYSCALL_RET_ERR(ret, errstr) \
> +{ \
> + qemu_log(" = "); \
> + if (ret < 0) { \
> + qemu_log("-1 errno=%d", errno); \
> + errstr = target_strerror(-ret); \
> + if (errstr) { \
> + qemu_log(" (%s)", errstr); \
> + } \
> + } \
> +}
You should move the declaration of errstr into this block, and then I
think it would be better to have function rather than a macro.
Thanks,
Laurent
© 2016 - 2026 Red Hat, Inc.