Skip to contentSkip to conversation

linux-user: Trace sendto/recvfrom

PATCH Superseded Philippe Mathieu-Daudé 2 participants 8 messages Aug 7, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover linux-user: Trace sendto/recvfrom

Strace format added while debugging
https://gitlab.com/qemu-project/qemu/-/issues/2485

Philippe Mathieu-Daudé (3):
linux-user: Display sockaddr buffer as pointer
linux-user: Add strace for sendto()
linux-user: Add strace for recvfrom()

 linux-user/strace.c    | 38 ++++++++++++++++++++++++++++++++++++--
 linux-user/strace.list |  4 ++--
 2 files changed, 38 insertions(+), 4 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/3 linux-user: Display sockaddr buffer as pointer

Rather than 'raw param', display as pointer to get "NULL" instead of "0x00000000". Remove spurious space.

---
 linux-user/strace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/strace.c +2 -2
index b4d1098170..7064afb486 100644
@@ -434,9 +434,9 @@ print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
         }
         unlock_user(sa, addr, 0);
     } else {
-        print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
+        print_pointer(addr, 0);
     }
-    qemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
+    qemu_log(","TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
 }
 
 static void
Signature · 1 line
2.45.2
#3 lore raw

PATCH 2/3 linux-user: Add strace for sendto()

In reply to Philippe Mathieu-Daudé
---
 linux-user/strace.c    | 15 +++++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)
linux-user/strace.c +15 -0
index 7064afb486..f55b62f0c9 100644
@@ -3122,6 +3122,21 @@ print_bind(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_sendto
+static void
+print_sendto(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)
+{
+    print_syscall_prologue(name);
+    print_sockfd(arg0, 0);
+    print_buf(arg1, arg2, 0);
+    print_flags(msg_flags, arg3, 0);
+    print_sockaddr(arg4, arg5, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
     defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
 static void
linux-user/strace.list +1 -1
index dfd4237d14..5a86419e7d 100644
@@ -1285,7 +1285,7 @@
 { TARGET_NR_sendmsg, "sendmsg" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_sendto
-{ TARGET_NR_sendto, "sendto" , NULL, NULL, NULL },
+{ TARGET_NR_sendto, "sendto" , NULL, print_sendto, NULL },
 #endif
 #ifdef TARGET_NR_setdomainname
 { TARGET_NR_setdomainname, "setdomainname" , NULL, NULL, NULL },
Signature · 1 line
2.45.2
#4 lore raw

Re: [PATCH 2/3] linux-user: Add strace for sendto()

linux-user/strace.c print_bind(CPUArchState *cpu_env, const struct syscallname *name, · line 3133

Quoted 9 lines · Philippe Mathieu-Daudé
linux-user/strace.c +9 -0
+#ifdef TARGET_NR_sendto
+static void
+print_sendto(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)
+{
+    print_syscall_prologue(name);
+    print_sockfd(arg0, 0);
+    print_buf(arg1, arg2, 0);

You still need to log arg2.

r~

#5 lore raw

Re: [PATCH 2/3] linux-user: Add strace for sendto()

Quoted 12 lines · Richard Henderson

linux-user/strace.c print_bind(CPUArchState *cpu_env, const struct syscallname *name, · line 3133

Quoted 9 lines · Philippe Mathieu-Daudé
linux-user/strace.c +9 -0
+#ifdef TARGET_NR_sendto
+static void
+print_sendto(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)
+{
+    print_syscall_prologue(name);
+    print_sockfd(arg0, 0);
+    print_buf(arg1, arg2, 0);

You still need to log arg2.

Oops.

#6 lore raw

PATCH 3/3 linux-user: Add strace for recvfrom()

In reply to Philippe Mathieu-Daudé

---
RFC: Not sure about get_user_ualx() use here

---
 linux-user/strace.c    | 19 +++++++++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 20 insertions(+), 1 deletion(-)
linux-user/strace.c +19 -0
index f55b62f0c9..f03e4229d6 100644
@@ -3122,6 +3122,25 @@ print_bind(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_recvfrom
+static void
+print_recvfrom(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)
+{
+    abi_ulong addrlen;
+
+    get_user_ualx(addrlen, arg5, 0);
+
+    print_syscall_prologue(name);
+    print_sockfd(arg0, 0);
+    print_buf(arg1, arg2, 0);
+    print_flags(msg_flags, arg3, 0);
+    print_sockaddr(arg4, addrlen, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_sendto
 static void
 print_sendto(CPUArchState *cpu_env, const struct syscallname *name,
linux-user/strace.list +1 -1
index 5a86419e7d..77ca824f9c 100644
@@ -1135,7 +1135,7 @@
 { TARGET_NR_recv, "recv" , "%s(%d,%p,%u,%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_recvfrom
-{ TARGET_NR_recvfrom, "recvfrom" , NULL, NULL, NULL },
+{ TARGET_NR_recvfrom, "recvfrom" , NULL, print_recvfrom, NULL },
 #endif
 #ifdef TARGET_NR_recvmmsg
 { TARGET_NR_recvmmsg, "recvmmsg" , NULL, NULL, NULL },
Signature · 1 line
2.45.2
#7 lore raw

Re: [PATCH 3/3] linux-user: Add strace for recvfrom()

Quoted 4 lines · Philippe Mathieu-Daudé
linux-user/strace.c +4 -0
+#ifdef TARGET_NR_recvfrom
+static void
+print_recvfrom(CPUArchState *cpu_env, const struct syscallname *name,
+               abi_long arg0, abi_long arg1, abi_long arg2,

linux-user/strace.c print_bind(CPUArchState *cpu_env, const struct syscallname *name, · line 3138

Quoted 10 lines
linux-user/strace.c +10 -0
+               abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    abi_ulong addrlen;
+
+    get_user_ualx(addrlen, arg5, 0);
+
+    print_syscall_prologue(name);
+    print_sockfd(arg0, 0);
+    print_buf(arg1, arg2, 0);
+    print_flags(msg_flags, arg3, 0);

Log arg2.

r~