[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 27/40] bsd-user/strace.c: print_taken_signal
From: |
Warner Losh |
Subject: |
[PATCH v3 27/40] bsd-user/strace.c: print_taken_signal |
Date: |
Fri, 28 Jan 2022 16:27:52 -0700 |
print_taken_signal() prints signals when we're tracing signals.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Kyle Evans <kevans@freebsd.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/qemu.h | 10 +++++
bsd-user/strace.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+)
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 8ed1bfbca89..a7964776fdb 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -204,6 +204,16 @@ print_openbsd_syscall(int num,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6);
void print_openbsd_syscall_ret(int num, abi_long ret);
+/**
+ * print_taken_signal:
+ * @target_signum: target signal being taken
+ * @tinfo: target_siginfo_t which will be passed to the guest for the signal
+ *
+ * Print strace output indicating that this signal is being taken by the guest,
+ * in a format similar to:
+ * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
+ */
+void print_taken_signal(int target_signum, const target_siginfo_t *tinfo);
extern int do_strace;
/* mmap.c */
diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index be40b8a20cf..a77d10dd6b6 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -31,6 +31,24 @@ int do_strace;
/*
* Utility functions
*/
+static const char *
+get_comma(int last)
+{
+ return (last) ? "" : ",";
+}
+
+/*
+ * Prints out raw parameter using given format. Caller needs
+ * to do byte swapping if needed.
+ */
+static void
+print_raw_param(const char *fmt, abi_long param, int last)
+{
+ char format[64];
+
+ (void)snprintf(format, sizeof(format), "%s%s", fmt, get_comma(last));
+ gemu_log(format, param);
+}
static void print_sysctl(const struct syscallname *name, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5,
@@ -239,3 +257,82 @@ void print_openbsd_syscall_ret(int num, abi_long ret)
print_syscall_ret(num, ret, openbsd_scnames, ARRAY_SIZE(openbsd_scnames));
}
+
+static void
+print_signal(abi_ulong arg, int last)
+{
+ const char *signal_name = NULL;
+ switch (arg) {
+ case TARGET_SIGHUP:
+ signal_name = "SIGHUP";
+ break;
+ case TARGET_SIGINT:
+ signal_name = "SIGINT";
+ break;
+ case TARGET_SIGQUIT:
+ signal_name = "SIGQUIT";
+ break;
+ case TARGET_SIGILL:
+ signal_name = "SIGILL";
+ break;
+ case TARGET_SIGABRT:
+ signal_name = "SIGABRT";
+ break;
+ case TARGET_SIGFPE:
+ signal_name = "SIGFPE";
+ break;
+ case TARGET_SIGKILL:
+ signal_name = "SIGKILL";
+ break;
+ case TARGET_SIGSEGV:
+ signal_name = "SIGSEGV";
+ break;
+ case TARGET_SIGPIPE:
+ signal_name = "SIGPIPE";
+ break;
+ case TARGET_SIGALRM:
+ signal_name = "SIGALRM";
+ break;
+ case TARGET_SIGTERM:
+ signal_name = "SIGTERM";
+ break;
+ case TARGET_SIGUSR1:
+ signal_name = "SIGUSR1";
+ break;
+ case TARGET_SIGUSR2:
+ signal_name = "SIGUSR2";
+ break;
+ case TARGET_SIGCHLD:
+ signal_name = "SIGCHLD";
+ break;
+ case TARGET_SIGCONT:
+ signal_name = "SIGCONT";
+ break;
+ case TARGET_SIGSTOP:
+ signal_name = "SIGSTOP";
+ break;
+ case TARGET_SIGTTIN:
+ signal_name = "SIGTTIN";
+ break;
+ case TARGET_SIGTTOU:
+ signal_name = "SIGTTOU";
+ break;
+ }
+ if (signal_name == NULL) {
+ print_raw_param("%ld", arg, last);
+ return;
+ }
+ gemu_log("%s%s", signal_name, get_comma(last));
+}
+
+void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
+{
+ /*
+ * Print the strace output for a signal being taken:
+ * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
+ */
+ gemu_log("%d ", getpid());
+ gemu_log("--- ");
+ print_signal(target_signum, 1);
+ gemu_log(" ---\n");
+}
--
2.33.1
- [PATCH v3 23/40] bsd-user: Add trace events for bsd-user, (continued)
- [PATCH v3 23/40] bsd-user: Add trace events for bsd-user, Warner Losh, 2022/01/28
- [PATCH v3 28/40] bsd-user/signal.c: Implement dump_core_and_abort, Warner Losh, 2022/01/28
- [PATCH v3 32/40] bsd-user/signal.c: handle_pending_signal, Warner Losh, 2022/01/28
- [PATCH v3 40/40] bsd-user/freebsd/target_os_ucontext.h: Prefer env as arg name for CPUArchState args, Warner Losh, 2022/01/28
- [PATCH v3 39/40] bsd-user: Rename arg name for target_cpu_reset to env, Warner Losh, 2022/01/28
- [PATCH v3 30/40] bsd-user/signal.c: sigset manipulation routines., Warner Losh, 2022/01/28
- [PATCH v3 37/40] bsd-user/signal.c: do_sigaltstack, Warner Losh, 2022/01/28
- [PATCH v3 19/40] bsd-user/host/arm/host-signal.h: Implement host_signal_*, Warner Losh, 2022/01/28
- [PATCH v3 29/40] bsd-user/signal.c: Fill in queue_signal, Warner Losh, 2022/01/28
- [PATCH v3 31/40] bsd-user/signal.c: setup_frame, Warner Losh, 2022/01/28
- [PATCH v3 27/40] bsd-user/strace.c: print_taken_signal,
Warner Losh <=
- [PATCH v3 33/40] bsd-user/signal.c: tswap_siginfo, Warner Losh, 2022/01/28
- [PATCH v3 34/40] bsd-user/signal.c: process_pending_signals, Warner Losh, 2022/01/28
- [PATCH v3 38/40] MAINTAINERS: Add tests/vm/*bsd to the list to get reviews on, Warner Losh, 2022/01/28