@@ -64,7 +64,10 @@ UNUSED static void print_string(abi_long, int);
UNUSED static void print_buf(abi_long addr, abi_long len, int last);
UNUSED static void print_raw_param(const char *, abi_long, int);
UNUSED static void print_timeval(abi_ulong, int);
+UNUSED static void print_timespec(abi_ulong, int);
UNUSED static void print_timezone(abi_ulong, int);
+UNUSED static void print_itimer_type(abi_ulong, int);
+UNUSED static void print_itimerval(abi_ulong, int);
UNUSED static void print_number(abi_long, int);
UNUSED static void print_signal(abi_ulong, int);
UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
@@ -829,6 +832,89 @@ print_syscall_ret_adjtimex(void *cpu_env, const struct syscallname *name,
}
#endif
+#if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
+static void
+print_syscall_ret_clock_gettime(void *cpu_env, 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(TARGET_ABI_FMT_ld, ret);
+ qemu_log(" (");
+ print_timespec(arg1, 1);
+ qemu_log(")");
+ }
+
+ qemu_log("\n");
+}
+#define print_syscall_ret_clock_getres print_syscall_ret_clock_gettime
+#endif
+
+#ifdef TARGET_NR_gettimeofday
+static void
+print_syscall_ret_gettimeofday(void *cpu_env, 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(TARGET_ABI_FMT_ld, ret);
+ qemu_log(" (");
+ print_timeval(arg0, 0);
+ print_timezone(arg1, 1);
+ qemu_log(")");
+ }
+
+ qemu_log("\n");
+}
+#endif
+
+#ifdef TARGET_NR_getitimer
+static void
+print_syscall_ret_getitimer(void *cpu_env, 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(TARGET_ABI_FMT_ld, ret);
+ qemu_log(" (");
+ print_itimerval(arg1, 1);
+ qemu_log(")");
+ }
+
+ qemu_log("\n");
+}
+#endif
+
+
+#ifdef TARGET_NR_getitimer
+static void
+print_syscall_ret_setitimer(void *cpu_env, 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(TARGET_ABI_FMT_ld, ret);
+ qemu_log(" (old_value = ");
+ print_itimerval(arg2, 1);
+ qemu_log(")");
+ }
+
+ qemu_log("\n");
+}
+#endif
+
#if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
|| defined(TARGGET_NR_flistxattr)
static void
@@ -1408,13 +1494,34 @@ print_timeval(abi_ulong tv_addr, int last)
print_pointer(tv_addr, last);
return;
}
- qemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
- tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
+ qemu_log("{tv_sec = " TARGET_ABI_FMT_ld
+ ",tv_usec = " TARGET_ABI_FMT_ld "}%s",
+ tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
unlock_user(tv, tv_addr, 0);
} else
qemu_log("NULL%s", get_comma(last));
}
+static void
+print_timespec(abi_ulong ts_addr, int last)
+{
+ if (ts_addr) {
+ struct target_timespec *ts;
+
+ ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
+ if (!ts) {
+ print_pointer(ts_addr, last);
+ return;
+ }
+ qemu_log("{tv_sec = " TARGET_ABI_FMT_ld
+ ",tv_nsec = " TARGET_ABI_FMT_ld "}%s",
+ tswapal(ts->tv_sec), tswapal(ts->tv_nsec), get_comma(last));
+ unlock_user(ts, ts_addr, 0);
+ } else {
+ qemu_log("NULL%s", get_comma(last));
+ }
+}
+
static void
print_timezone(abi_ulong tz_addr, int last)
{
@@ -1434,6 +1541,36 @@ print_timezone(abi_ulong tz_addr, int last)
}
}
+static void
+print_itimer_type(abi_ulong itimer, int last)
+{
+ switch (itimer) {
+ case ITIMER_REAL:
+ qemu_log("ITIMER_REAL,"); break;
+ case ITIMER_VIRTUAL:
+ qemu_log("ITIMER_VIRTUAL,"); break;
+ case ITIMER_PROF:
+ qemu_log("ITIMER_PROF,"); break;
+ default:
+ print_raw_param("%#x", itimer, 0);
+ }
+ qemu_log("%s", get_comma(last));
+}
+
+static void
+print_itimerval(abi_ulong it_addr, int last)
+{
+ if (it_addr) {
+ qemu_log("{it_interval=");
+ print_timeval(it_addr, 0);
+ qemu_log("it_value=");
+ print_timeval(it_addr + sizeof(struct target_timeval), 1);
+ qemu_log("}%s", get_comma(last));
+ } else {
+ qemu_log("NULL%s", get_comma(last));
+ }
+}
+
#undef UNUSED
#ifdef TARGET_NR_accept
@@ -1876,6 +2013,19 @@ print_futimesat(void *cpu_env, const struct syscallname *name,
}
#endif
+#ifdef TARGET_NR_gettimeofday
+static void
+print_gettimeofday(void *cpu_env, 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_pointer(arg0, 0);
+ print_pointer(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
#ifdef TARGET_NR_settimeofday
static void
print_settimeofday(void *cpu_env, const struct syscallname *name,
@@ -1889,6 +2039,60 @@ print_settimeofday(void *cpu_env, const struct syscallname *name,
}
#endif
+#if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
+static void
+print_clock_gettime(void *cpu_env, 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_clockid(arg0, 0);
+ print_pointer(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#define print_clock_getres print_clock_gettime
+#endif
+
+#ifdef TARGET_NR_clock_settime
+static void
+print_clock_settime(void *cpu_env, 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_clockid(arg0, 0);
+ print_timespec(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_getitimer
+static void
+print_getitimer(void *cpu_env, 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_itimer_type(arg0, 0);
+ print_pointer(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_setitimer
+static void
+print_setitimer(void *cpu_env, 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_itimer_type(arg0, 0);
+ print_itimerval(arg1, 0);
+ print_pointer(arg2, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
#ifdef TARGET_NR_link
static void
print_link(void *cpu_env, const struct syscallname *name,
@@ -83,16 +83,18 @@
{ TARGET_NR_clock_adjtime, "clock_adjtime" , NULL, print_clock_adjtime, NULL },
#endif
#ifdef TARGET_NR_clock_getres
-{ TARGET_NR_clock_getres, "clock_getres" , NULL, NULL, NULL },
+{ TARGET_NR_clock_getres, "clock_getres" , NULL, print_clock_getres,
+ print_syscall_ret_clock_getres },
#endif
#ifdef TARGET_NR_clock_gettime
-{ TARGET_NR_clock_gettime, "clock_gettime" , NULL, NULL, NULL },
+{ TARGET_NR_clock_gettime, "clock_gettime" , NULL, print_clock_gettime,
+ print_syscall_ret_clock_gettime },
#endif
#ifdef TARGET_NR_clock_nanosleep
{ TARGET_NR_clock_nanosleep, "clock_nanosleep" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_clock_settime
-{ TARGET_NR_clock_settime, "clock_settime" , NULL, NULL, NULL },
+{ TARGET_NR_clock_settime, "clock_settime" , NULL, print_clock_settime, NULL },
#endif
#ifdef TARGET_NR_clone
{ TARGET_NR_clone, "clone" , NULL, print_clone, NULL },
@@ -315,7 +317,8 @@
{ TARGET_NR_gethostname, "gethostname" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_getitimer
-{ TARGET_NR_getitimer, "getitimer" , NULL, NULL, NULL },
+{ TARGET_NR_getitimer, "getitimer" , NULL, print_getitimer,
+ print_syscall_ret_getitimer },
#endif
#ifdef TARGET_NR_get_kernel_syms
{ TARGET_NR_get_kernel_syms, "get_kernel_syms" , NULL, NULL, NULL },
@@ -388,7 +391,8 @@
{ TARGET_NR_gettid, "gettid" , "%s()", NULL, NULL },
#endif
#ifdef TARGET_NR_gettimeofday
-{ TARGET_NR_gettimeofday, "gettimeofday" , NULL, NULL, NULL },
+{ TARGET_NR_gettimeofday, "gettimeofday" , NULL, print_gettimeofday,
+ print_syscall_ret_gettimeofday },
#endif
#ifdef TARGET_NR_getuid
{ TARGET_NR_getuid, "getuid" , "%s()", NULL, NULL },
@@ -1291,7 +1295,8 @@
{ TARGET_NR_sethostname, "sethostname" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_setitimer
-{ TARGET_NR_setitimer, "setitimer" , NULL, NULL, NULL },
+{ TARGET_NR_setitimer, "setitimer" , NULL, print_setitimer,
+ print_syscall_ret_setitimer },
#endif
#ifdef TARGET_NR_set_mempolicy
{ TARGET_NR_set_mempolicy, "set_mempolicy" , NULL, NULL, NULL },
This patch implements strace argument printing functionality for following syscalls: * clock_getres, clock_gettime, clock_settime - clock and time functions int clock_getres(clockid_t clockid, struct timespec *res) int clock_gettime(clockid_t clockid, struct timespec *tp) int clock_settime(clockid_t clockid, const struct timespec *tp) man page: https://man7.org/linux/man-pages/man2/clock_getres.2.html * gettimeofday - get time int gettimeofday(struct timeval *tv, struct timezone *tz) man page: https://man7.org/linux/man-pages/man2/gettimeofday.2.html * getitimer, setitimer - get or set value of an interval timer int getitimer(int which, struct itimerval *curr_value) int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value) man page: https://man7.org/linux/man-pages/man2/getitimer.2.html Implementation notes: All of the syscalls have some structue types as argument types and thus a separate printing function was stated in file "strace.list" for each of them. All of these functions use existing functions for their appropriate structure types ("print_timeval()" and "print_timezone()"). Functions "print_timespec()" and "print_itimerval()" were added in this patch so that they can be used to print types "struct timespec" and "struct itimerval" used by some of the syscalls. Function "print_itimerval()" uses the existing function "print_timeval()" to print fields of the structure "struct itimerval" that are of type "struct timeval". Function "print_itimer_type()" was added to print the type of the interval typer which is the firt argument of "getitimer()" and "setitimer()". Also, the existing function "print_timeval()" was changed a little so that it prints the field names beside the values. Syscalls "clock_getres()" and "clocK_gettime()" have the same number and types of arguments and thus their print functions "print_clock_getres" and "print_clock_gettime" shate a common definition in file "strace.c". Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> --- linux-user/strace.c | 208 ++++++++++++++++++++++++++++++++++++++++- linux-user/strace.list | 17 ++-- 2 files changed, 217 insertions(+), 8 deletions(-)