Skip to contentSkip to conversation

linux-user: Improve strace output of pread64() and pwrite64()

PATCH In review Helge Deller 3 participants 7 messages Jan 27, 2023 – Jan 31, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 linux-user: Improve strace output of pread64() and pwrite64()

Make the strace look nicer for those two syscalls.

---
v2: Use regpairs_aligned() and target_offset64(), noticed by Laurent Vivier

linux-user/strace.c +19 -0
index 82dc1a1e20..379536f5c9 100644
@@ -3824,6 +3824,25 @@ print_rlimit64(abi_ulong rlim_addr, int last)
     }
 }
 
+#if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64)
+static void
+print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name,
+           abi_long arg0, abi_long arg1, abi_long arg2,
+           abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    if (regpairs_aligned(cpu_env, TARGET_NR_pread64)) {
+        arg3 = arg4;
+        arg4 = arg5;
+    }
+    print_syscall_prologue(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_syscall_epilogue(name);
+}
+#endif
+
 static void
 print_prlimit64(CPUArchState *cpu_env, const struct syscallname *name,
            abi_long arg0, abi_long arg1, abi_long arg2,
linux-user/strace.list +2 -2
index 909298099e..4ae60e5e87 100644
@@ -1061,7 +1061,7 @@
 { TARGET_NR_prctl, "prctl" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_pread64
-{ TARGET_NR_pread64, "pread64" , NULL, NULL, NULL },
+{ TARGET_NR_pread64, "pread64" , NULL, print_preadwrite64, NULL },
 #endif
 #ifdef TARGET_NR_preadv
 { TARGET_NR_preadv, "preadv" , NULL, NULL, NULL },
@@ -1092,7 +1092,7 @@
 { TARGET_NR_putpmsg, "putpmsg" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_pwrite64
-{ TARGET_NR_pwrite64, "pwrite64" , NULL, NULL, NULL },
+{ TARGET_NR_pwrite64, "pwrite64" , NULL, print_preadwrite64, NULL },
 #endif
 #ifdef TARGET_NR_pwritev
 { TARGET_NR_pwritev, "pwritev" , NULL, NULL, NULL },
#2 lore raw
In reply to Helge Deller

Le 27/01/2023 à 21:58, Helge Deller a écrit :

Quoted 19 lines

Make the strace look nicer for those two syscalls.

---
v2: Use regpairs_aligned() and target_offset64(), noticed by Laurent Vivier

linux-user/strace.c +5 -0
index 82dc1a1e20..379536f5c9 100644
@@ -3824,6 +3824,25 @@ print_rlimit64(abi_ulong rlim_addr, int last)
      }
  }
 
+#if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64)
+static void
+print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name,
+           abi_long arg0, abi_long arg1, abi_long arg2,
+           abi_long arg3, abi_long arg4, abi_long arg5)

linux-user/strace.c print_rlimit64(abi_ulong rlim_addr, int last) · line 3841

Quoted 10 lines
linux-user/strace.c +10 -0
+{
+    if (regpairs_aligned(cpu_env, TARGET_NR_pread64)) {
+        arg3 = arg4;
+        arg4 = arg5;
+    }
+    print_syscall_prologue(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));

better to use:

print_raw_param("%" PRIu64, target_offset64(arg3, arg4), 1);

Thanks,
Laurent

#3 lore raw
Quoted 33 lines · Laurent Vivier

Le 27/01/2023 à 21:58, Helge Deller a écrit :

Quoted 19 lines

Make the strace look nicer for those two syscalls.

---
v2: Use regpairs_aligned() and target_offset64(), noticed by Laurent Vivier

linux-user/strace.c +5 -0
index 82dc1a1e20..379536f5c9 100644
@@ -3824,6 +3824,25 @@ print_rlimit64(abi_ulong rlim_addr, int last)
       }
   }
 
+#if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64)
+static void
+print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name,
+           abi_long arg0, abi_long arg1, abi_long arg2,
+           abi_long arg3, abi_long arg4, abi_long arg5)

linux-user/strace.c print_rlimit64(abi_ulong rlim_addr, int last) · line 3841

Quoted 10 lines
linux-user/strace.c +10 -0
+{
+    if (regpairs_aligned(cpu_env, TARGET_NR_pread64)) {
+        arg3 = arg4;
+        arg4 = arg5;
+    }
+    print_syscall_prologue(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));

better to use:

Quoted 1 line

print_raw_param("%" PRIu64, target_offset64(arg3, arg4), 1);

I thought of that as well, but that won't work, as print_raw_param() takes an "abi_long" value, which is just a 32-bit value on 32-bit targets. See print_rlimit64(), it's used there with qemu_log() as well.

Helge

#4 lore raw

Le 30/01/2023 à 23:11, Helge Deller a écrit :

Quoted 34 lines · Laurent Vivier
Quoted 33 lines

Le 27/01/2023 à 21:58, Helge Deller a écrit :

Quoted 19 lines

Make the strace look nicer for those two syscalls.

---
v2: Use regpairs_aligned() and target_offset64(), noticed by Laurent Vivier

linux-user/strace.c +5 -0
index 82dc1a1e20..379536f5c9 100644
@@ -3824,6 +3824,25 @@ print_rlimit64(abi_ulong rlim_addr, int last)
       }
   }
 
+#if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64)
+static void
+print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name,
+           abi_long arg0, abi_long arg1, abi_long arg2,
+           abi_long arg3, abi_long arg4, abi_long arg5)

linux-user/strace.c print_rlimit64(abi_ulong rlim_addr, int last) · line 3841

Quoted 10 lines
linux-user/strace.c +10 -0
+{
+    if (regpairs_aligned(cpu_env, TARGET_NR_pread64)) {
+        arg3 = arg4;
+        arg4 = arg5;
+    }
+    print_syscall_prologue(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));

better to use:

Quoted 5 lines
Quoted 1 line

print_raw_param("%" PRIu64, target_offset64(arg3, arg4), 1);

I thought of that as well, but that won't work, as print_raw_param() takes an "abi_long" value, which is just a 32-bit value on 32-bit targets. See print_rlimit64(), it's used there with qemu_log() as well.

Yes, you're right.

But even with qemu_log() I would prefer you use "%"PRIu64 rather than %lld.

Or better define a print_raw_param64() (or similar) and update print_fallocate(), print_truncate64() and print_ftruncate64().

Thanks,
Laurent

#6 lore raw
In reply to Helge Deller

Le 31/01/2023 à 14:08, Helge Deller a écrit :

Quoted 44 lines · Laurent Vivier
Quoted 43 lines

Le 30/01/2023 à 23:11, Helge Deller a écrit :

Quoted 34 lines · Laurent Vivier
Quoted 33 lines

Le 27/01/2023 à 21:58, Helge Deller a écrit :

Quoted 19 lines

Make the strace look nicer for those two syscalls.

---
v2: Use regpairs_aligned() and target_offset64(), noticed by Laurent Vivier

linux-user/strace.c +5 -0
index 82dc1a1e20..379536f5c9 100644
@@ -3824,6 +3824,25 @@ print_rlimit64(abi_ulong rlim_addr, int last)
       }
   }
 
+#if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64)
+static void
+print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name,
+           abi_long arg0, abi_long arg1, abi_long arg2,
+           abi_long arg3, abi_long arg4, abi_long arg5)

linux-user/strace.c print_rlimit64(abi_ulong rlim_addr, int last) · line 3841

Quoted 10 lines
linux-user/strace.c +10 -0
+{
+    if (regpairs_aligned(cpu_env, TARGET_NR_pread64)) {
+        arg3 = arg4;
+        arg4 = arg5;
+    }
+    print_syscall_prologue(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));

better to use:

Quoted 5 lines
Quoted 1 line

print_raw_param("%" PRIu64, target_offset64(arg3, arg4), 1);

I thought of that as well, but that won't work, as print_raw_param() takes an "abi_long" value, which is just a 32-bit value on 32-bit targets. See print_rlimit64(), it's used there with qemu_log() as well.

Yes, you're right.

Quoted 7 lines
Quoted 2 lines

But even with qemu_log() I would prefer you use "%"PRIu64 rather than %lld.
Or better define a print_raw_param64() (or similar) and update print_fallocate(), print_truncate64() and print_ftruncate64().

As adding such define is a unrelated change to this patch, I'd propose that I send a follow-up patch on top of this one which adds print_raw_param64() (or similar) and replaces all usages of qemu_log() with 64-bit values and use "%"PRIu64 then.
Ok?

yes

Quoted 2 lines

If yes, should that define include the last 0/1 parameter to print the "," ? I think so, because then it's consistent with print_raw_param().

you're right.

Thanks,
Laurent

Quoted 3 lines

Helge

#5 lore raw
In reply to Laurent Vivier
Quoted 37 lines · Laurent Vivier

Le 30/01/2023 à 23:11, Helge Deller a écrit :

Quoted 36 lines · Laurent Vivier
Quoted 34 lines

Le 27/01/2023 à 21:58, Helge Deller a écrit :

Quoted 19 lines

Make the strace look nicer for those two syscalls.

---
v2: Use regpairs_aligned() and target_offset64(), noticed by Laurent Vivier

linux-user/strace.c +5 -0
index 82dc1a1e20..379536f5c9 100644
@@ -3824,6 +3824,25 @@ print_rlimit64(abi_ulong rlim_addr, int last)
       }
   }
 
+#if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64)
+static void
+print_preadwrite64(CPUArchState *cpu_env, const struct syscallname *name,
+           abi_long arg0, abi_long arg1, abi_long arg2,
+           abi_long arg3, abi_long arg4, abi_long arg5)

linux-user/strace.c print_rlimit64(abi_ulong rlim_addr, int last) · line 3841

Quoted 10 lines
linux-user/strace.c +10 -0
+{
+    if (regpairs_aligned(cpu_env, TARGET_NR_pread64)) {
+        arg3 = arg4;
+        arg4 = arg5;
+    }
+    print_syscall_prologue(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));

better to use:

print_raw_param("%" PRIu64, target_offset64(arg3, arg4), 1);

Quoted 8 lines
Quoted 3 lines

I thought of that as well, but that won't work, as print_raw_param() takes an "abi_long" value, which is just a 32-bit value on 32-bit targets. See print_rlimit64(), it's used there with qemu_log() as well.

Yes, you're right.

But even with qemu_log() I would prefer you use "%"PRIu64 rather than %lld.
Or better define a print_raw_param64() (or similar) and update print_fallocate(), print_truncate64() and print_ftruncate64().

As adding such define is a unrelated change to this patch, I'd propose that I send a follow-up patch on top of this one which adds print_raw_param64() (or similar) and replaces all usages of qemu_log() with 64-bit values and use "%"PRIu64 then.
Ok?
If yes, should that define include the last 0/1 parameter to print the "," ?
I think so, because then it's consistent with print_raw_param().

Helge