Message ID | Y9lNbFNyRSUhhrHa@p100 (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | linux-user: Provide print_raw_param64() for 64-bit values | expand |
Le 31/01/2023 à 18:18, Helge Deller a écrit : > Add a new function print_raw_param64() to print 64-bit values in the > same way as print_raw_param(). This prevents that qemu_log() is used to > work around the problem that print_raw_param() can only print 32-bit > values when compiled for 32-bit targets. > > Additionally convert the existing 64-bit users in print_timespec64(), > print_rlimit64() and print_preadwrite64() over to this new function and > drop some unneccessary spaces. > > Suggested-by: Laurent Vivier <laurent@vivier.eu> > Signed-off-by: Helge Deller <deller@gmx.de> > > > diff --git a/linux-user/strace.c b/linux-user/strace.c > index 379536f5c9..35d22be027 100644 > --- a/linux-user/strace.c > +++ b/linux-user/strace.c > @@ -81,6 +81,7 @@ UNUSED static void print_syscall_epilogue(const struct syscallname *); > 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_raw_param64(const char *, long long, int last); > UNUSED static void print_timeval(abi_ulong, int); > UNUSED static void print_timespec(abi_ulong, int); > UNUSED static void print_timespec64(abi_ulong, int); > @@ -1615,6 +1616,19 @@ print_raw_param(const char *fmt, abi_long param, int last) > qemu_log(format, param); > } > > +/* > + * Same as print_raw_param() but prints out raw 64-bit parameter. > + */ > +static void > +print_raw_param64(const char *fmt, long long param, int last) > +{ > + char format[64]; > + > + (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last)); > + qemu_log(format, param); > +} > + > + > static void > print_pointer(abi_long p, int last) > { > @@ -1691,10 +1705,8 @@ print_timespec64(abi_ulong ts_addr, int last) > print_pointer(ts_addr, last); > return; > } > - qemu_log("{tv_sec = %lld" > - ",tv_nsec = %lld}%s", > - (long long)tswap64(ts->tv_sec), (long long)tswap64(ts->tv_nsec), > - get_comma(last)); > + print_raw_param64("{tv_sec=%" PRId64, tswap64(ts->tv_sec), 0); > + print_raw_param64("tv_nsec=%" PRId64 "}", tswap64(ts->tv_nsec), last); > unlock_user(ts, ts_addr, 0); > } else { > qemu_log("NULL%s", get_comma(last)); > @@ -3814,10 +3826,9 @@ print_rlimit64(abi_ulong rlim_addr, int last) > print_pointer(rlim_addr, last); > return; > } > - qemu_log("{rlim_cur = %lld, rlim_max = %lld}%s", > - (long long)tswap64(rl->rlim_cur), > - (long long)tswap64(rl->rlim_max), > - get_comma(last)); > + print_raw_param64("{rlim_cur=%" PRId64, tswap64(rl->rlim_cur), 0); > + print_raw_param64("rlim_max=%" PRId64 "}", tswap64(rl->rlim_max), > + last); > unlock_user(rl, rlim_addr, 0); > } else { > qemu_log("NULL%s", get_comma(last)); > @@ -3838,7 +3849,7 @@ print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name, > print_raw_param("%d", arg0, 0); > print_pointer(arg1, 0); > print_raw_param("%d", arg2, 0); > - qemu_log("%lld", (long long)target_offset64(arg3, arg4)); > + print_raw_param64("%" PRId64, target_offset64(arg3, arg4), 1); > print_syscall_epilogue(name); > } > #endif > Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Le 31/01/2023 à 18:18, Helge Deller a écrit : > Add a new function print_raw_param64() to print 64-bit values in the > same way as print_raw_param(). This prevents that qemu_log() is used to > work around the problem that print_raw_param() can only print 32-bit > values when compiled for 32-bit targets. > > Additionally convert the existing 64-bit users in print_timespec64(), > print_rlimit64() and print_preadwrite64() over to this new function and > drop some unneccessary spaces. > > Suggested-by: Laurent Vivier <laurent@vivier.eu> > Signed-off-by: Helge Deller <deller@gmx.de> > > > diff --git a/linux-user/strace.c b/linux-user/strace.c > index 379536f5c9..35d22be027 100644 > --- a/linux-user/strace.c > +++ b/linux-user/strace.c > @@ -81,6 +81,7 @@ UNUSED static void print_syscall_epilogue(const struct syscallname *); > 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_raw_param64(const char *, long long, int last); > UNUSED static void print_timeval(abi_ulong, int); > UNUSED static void print_timespec(abi_ulong, int); > UNUSED static void print_timespec64(abi_ulong, int); > @@ -1615,6 +1616,19 @@ print_raw_param(const char *fmt, abi_long param, int last) > qemu_log(format, param); > } > > +/* > + * Same as print_raw_param() but prints out raw 64-bit parameter. > + */ > +static void > +print_raw_param64(const char *fmt, long long param, int last) > +{ > + char format[64]; > + > + (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last)); > + qemu_log(format, param); > +} > + > + > static void > print_pointer(abi_long p, int last) > { > @@ -1691,10 +1705,8 @@ print_timespec64(abi_ulong ts_addr, int last) > print_pointer(ts_addr, last); > return; > } > - qemu_log("{tv_sec = %lld" > - ",tv_nsec = %lld}%s", > - (long long)tswap64(ts->tv_sec), (long long)tswap64(ts->tv_nsec), > - get_comma(last)); > + print_raw_param64("{tv_sec=%" PRId64, tswap64(ts->tv_sec), 0); > + print_raw_param64("tv_nsec=%" PRId64 "}", tswap64(ts->tv_nsec), last); > unlock_user(ts, ts_addr, 0); > } else { > qemu_log("NULL%s", get_comma(last)); > @@ -3814,10 +3826,9 @@ print_rlimit64(abi_ulong rlim_addr, int last) > print_pointer(rlim_addr, last); > return; > } > - qemu_log("{rlim_cur = %lld, rlim_max = %lld}%s", > - (long long)tswap64(rl->rlim_cur), > - (long long)tswap64(rl->rlim_max), > - get_comma(last)); > + print_raw_param64("{rlim_cur=%" PRId64, tswap64(rl->rlim_cur), 0); > + print_raw_param64("rlim_max=%" PRId64 "}", tswap64(rl->rlim_max), > + last); > unlock_user(rl, rlim_addr, 0); > } else { > qemu_log("NULL%s", get_comma(last)); > @@ -3838,7 +3849,7 @@ print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name, > print_raw_param("%d", arg0, 0); > print_pointer(arg1, 0); > print_raw_param("%d", arg2, 0); > - qemu_log("%lld", (long long)target_offset64(arg3, arg4)); > + print_raw_param64("%" PRId64, target_offset64(arg3, arg4), 1); > print_syscall_epilogue(name); > } > #endif > Applied to my linux-user-for-8.0 branch. Thanks, Laurent
diff --git a/linux-user/strace.c b/linux-user/strace.c index 379536f5c9..35d22be027 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -81,6 +81,7 @@ UNUSED static void print_syscall_epilogue(const struct syscallname *); 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_raw_param64(const char *, long long, int last); UNUSED static void print_timeval(abi_ulong, int); UNUSED static void print_timespec(abi_ulong, int); UNUSED static void print_timespec64(abi_ulong, int); @@ -1615,6 +1616,19 @@ print_raw_param(const char *fmt, abi_long param, int last) qemu_log(format, param); } +/* + * Same as print_raw_param() but prints out raw 64-bit parameter. + */ +static void +print_raw_param64(const char *fmt, long long param, int last) +{ + char format[64]; + + (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last)); + qemu_log(format, param); +} + + static void print_pointer(abi_long p, int last) { @@ -1691,10 +1705,8 @@ print_timespec64(abi_ulong ts_addr, int last) print_pointer(ts_addr, last); return; } - qemu_log("{tv_sec = %lld" - ",tv_nsec = %lld}%s", - (long long)tswap64(ts->tv_sec), (long long)tswap64(ts->tv_nsec), - get_comma(last)); + print_raw_param64("{tv_sec=%" PRId64, tswap64(ts->tv_sec), 0); + print_raw_param64("tv_nsec=%" PRId64 "}", tswap64(ts->tv_nsec), last); unlock_user(ts, ts_addr, 0); } else { qemu_log("NULL%s", get_comma(last)); @@ -3814,10 +3826,9 @@ print_rlimit64(abi_ulong rlim_addr, int last) print_pointer(rlim_addr, last); return; } - qemu_log("{rlim_cur = %lld, rlim_max = %lld}%s", - (long long)tswap64(rl->rlim_cur), - (long long)tswap64(rl->rlim_max), - get_comma(last)); + print_raw_param64("{rlim_cur=%" PRId64, tswap64(rl->rlim_cur), 0); + print_raw_param64("rlim_max=%" PRId64 "}", tswap64(rl->rlim_max), + last); unlock_user(rl, rlim_addr, 0); } else { qemu_log("NULL%s", get_comma(last)); @@ -3838,7 +3849,7 @@ print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name, print_raw_param("%d", arg0, 0); print_pointer(arg1, 0); print_raw_param("%d", arg2, 0); - qemu_log("%lld", (long long)target_offset64(arg3, arg4)); + print_raw_param64("%" PRId64, target_offset64(arg3, arg4), 1); print_syscall_epilogue(name); } #endif
Add a new function print_raw_param64() to print 64-bit values in the same way as print_raw_param(). This prevents that qemu_log() is used to work around the problem that print_raw_param() can only print 32-bit values when compiled for 32-bit targets. Additionally convert the existing 64-bit users in print_timespec64(), print_rlimit64() and print_preadwrite64() over to this new function and drop some unneccessary spaces. Suggested-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Helge Deller <deller@gmx.de>