diff mbox series

linux-user: Trace rt_sigprocmask's sigsets

Message ID 20241017091449.443799-1-iii@linux.ibm.com (mailing list archive)
State New
Headers show
Series linux-user: Trace rt_sigprocmask's sigsets | expand

Commit Message

Ilya Leoshkevich Oct. 17, 2024, 9:14 a.m. UTC
Add a function for formatting target sigsets. It can be useful for
other syscalls in the future, so put it into the beginning of strace.c.
For simplicity, do not implement the strace's ~[] output syntax.

Add a rt_sigprocmask return handler.

Example outputs:

    4072707 rt_sigprocmask(SIG_BLOCK,[SIGHUP SIGINT SIGQUIT SIGALRM SIGTERM SIGTSTP SIGTTIN SIGTTOU],[],8) = 0
    4072853 rt_sigprocmask(SIG_UNBLOCK,[32 33],NULL,8) = 0

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 linux-user/strace.c    | 84 ++++++++++++++++++++++++++++++++++++------
 linux-user/strace.list |  3 +-
 2 files changed, 75 insertions(+), 12 deletions(-)

Comments

Richard Henderson Oct. 22, 2024, 1:50 a.m. UTC | #1
On 10/17/24 02:14, Ilya Leoshkevich wrote:
> @@ -3312,10 +3358,26 @@ print_rt_sigprocmask(CPUArchState *cpu_env, const struct syscallname *name,
>       case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
>       }
>       qemu_log("%s,", how);
> -    print_pointer(arg1, 0);
> -    print_pointer(arg2, 0);
> +    print_target_sigset_t(arg1, arg3, 0);
> +}
> +
> +static void
> +print_rt_sigprocmask_ret(CPUArchState *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)
> +{
> +    if (is_error(ret)) {
> +        print_pointer(arg2, 0);
> +    } else {
> +        print_target_sigset_t(arg2, arg3, 0);
> +    }
>       print_raw_param("%u", arg3, 1);
>       print_syscall_epilogue(name);

I'm not keen on splitting operands across syscall completion.
There are a few existing syscalls for which we print such results afterward:

   clock_gettime
   clock_getres
   wait4
   waitpid

but we're certainly not consistent about it.


r~
Ilya Leoshkevich Oct. 22, 2024, 9:41 a.m. UTC | #2
On Mon, 2024-10-21 at 18:50 -0700, Richard Henderson wrote:
> On 10/17/24 02:14, Ilya Leoshkevich wrote:
> > @@ -3312,10 +3358,26 @@ print_rt_sigprocmask(CPUArchState *cpu_env,
> > const struct syscallname *name,
> >       case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
> >       }
> >       qemu_log("%s,", how);
> > -    print_pointer(arg1, 0);
> > -    print_pointer(arg2, 0);
> > +    print_target_sigset_t(arg1, arg3, 0);
> > +}
> > +
> > +static void
> > +print_rt_sigprocmask_ret(CPUArchState *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)
> > +{
> > +    if (is_error(ret)) {
> > +        print_pointer(arg2, 0);
> > +    } else {
> > +        print_target_sigset_t(arg2, arg3, 0);
> > +    }
> >       print_raw_param("%u", arg3, 1);
> >       print_syscall_epilogue(name);
> 
> I'm not keen on splitting operands across syscall completion.
> There are a few existing syscalls for which we print such results
> afterward:
> 
>    clock_gettime
>    clock_getres
>    wait4
>    waitpid
> 
> but we're certainly not consistent about it.
> 
> 
> r~

I wanted to stay as close as possible to strace here, but I don't
really have a strong preference. I will send a v2.
diff mbox series

Patch

diff --git a/linux-user/strace.c b/linux-user/strace.c
index c3eb3a2706a..1fdbd9854ba 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -161,19 +161,20 @@  static const char * const target_signal_name[] = {
 };
 
 static void
-print_signal(abi_ulong arg, int last)
+print_signal_1(abi_ulong arg)
 {
-    const char *signal_name = NULL;
-
     if (arg < ARRAY_SIZE(target_signal_name)) {
-        signal_name = target_signal_name[arg];
+        qemu_log("%s", target_signal_name[arg]);
+    } else {
+        qemu_log(TARGET_ABI_FMT_lu, arg);
     }
+}
 
-    if (signal_name == NULL) {
-        print_raw_param("%ld", arg, last);
-        return;
-    }
-    qemu_log("%s%s", signal_name, get_comma(last));
+static void
+print_signal(abi_ulong arg, int last)
+{
+    print_signal_1(arg);
+    qemu_log("%s", get_comma(last));
 }
 
 static void print_si_code(int arg)
@@ -718,6 +719,51 @@  print_ipc(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_rt_sigprocmask
+static void print_target_sigset_t_1(target_sigset_t *set, int last)
+{
+    bool first = true;
+    int i, sig = 1;
+
+    qemu_log("[");
+    for (i = 0; i < TARGET_NSIG_WORDS; i++) {
+        abi_ulong bits = 0;
+        int j;
+
+        __get_user(bits, &set->sig[i]);
+        for (j = 0; j < sizeof(bits) * 8; j++) {
+            if (bits & ((abi_ulong)1 << j)) {
+                if (first) {
+                    first = false;
+                } else {
+                    qemu_log(" ");
+                }
+                print_signal_1(sig);
+            }
+            sig++;
+        }
+    }
+    qemu_log("]%s", get_comma(last));
+}
+
+static void print_target_sigset_t(abi_ulong addr, abi_ulong size, int last)
+{
+    if (addr && size == sizeof(target_sigset_t)) {
+        target_sigset_t *set;
+
+        set = lock_user(VERIFY_READ, addr, sizeof(target_sigset_t), 1);
+        if (set) {
+            print_target_sigset_t_1(set, last);
+            unlock_user(set, addr, 0);
+        } else {
+            print_pointer(addr, last);
+        }
+    } else {
+        print_pointer(addr, last);
+    }
+}
+#endif
+
 /*
  * Variants for the return value output function
  */
@@ -3312,10 +3358,26 @@  print_rt_sigprocmask(CPUArchState *cpu_env, const struct syscallname *name,
     case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
     }
     qemu_log("%s,", how);
-    print_pointer(arg1, 0);
-    print_pointer(arg2, 0);
+    print_target_sigset_t(arg1, arg3, 0);
+}
+
+static void
+print_rt_sigprocmask_ret(CPUArchState *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)
+{
+    if (is_error(ret)) {
+        print_pointer(arg2, 0);
+    } else {
+        print_target_sigset_t(arg2, arg3, 0);
+    }
     print_raw_param("%u", arg3, 1);
     print_syscall_epilogue(name);
+    if (!print_syscall_err(ret)) {
+        qemu_log(TARGET_ABI_FMT_ld, ret);
+    }
+    qemu_log("\n");
 }
 #endif
 
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 0d69fb3150d..fdf94ef32ad 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1189,7 +1189,8 @@ 
 { TARGET_NR_rt_sigpending, "rt_sigpending" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_rt_sigprocmask
-{ TARGET_NR_rt_sigprocmask, "rt_sigprocmask" , NULL, print_rt_sigprocmask, NULL },
+{ TARGET_NR_rt_sigprocmask, "rt_sigprocmask" , NULL, print_rt_sigprocmask,
+                            print_rt_sigprocmask_ret },
 #endif
 #ifdef TARGET_NR_rt_sigqueueinfo
 { TARGET_NR_rt_sigqueueinfo, "rt_sigqueueinfo" , NULL, print_rt_sigqueueinfo, NULL },