From patchwork Sat Oct 5 23:33:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 833025 Delivered-To: patch@linaro.org Received: by 2002:adf:8b52:0:b0:367:895a:4699 with SMTP id v18csp1380263wra; Sat, 5 Oct 2024 16:36:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXfqOBqJyfcmqUu1IS5BJCzKVqwWSq10HgvN5A5khxLO3Rh4JZQC7K1Wg8y6A+43fYJnIlc8A==@linaro.org X-Google-Smtp-Source: AGHT+IFbig4yRxz9MIN378KphPxztoC9fFpC1OPEiWRukCZAtFEeJd2bQFj7QXChE2npykgoMaKi X-Received: by 2002:ac8:5809:0:b0:45d:8684:4324 with SMTP id d75a77b69052e-45d9bb3a95cmr124044811cf.58.1728171361740; Sat, 05 Oct 2024 16:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728171361; cv=none; d=google.com; s=arc-20240605; b=BoFRoFaI55y3zvP2nRSgVR2si89WWBaX/36BLjPhNs6lSB+pJe7ShrXdAX+BxEqlub tQyCUYIU0QElHPR5ookZ+cOoGx36F01jC83L8b//gKzN5eGvyf1ZtRcWAorfTjq/tvsa PI6kND/DVqWdBhLAk2Lh3fjCRQJ3tiIRb6pZqwSyNREig5KM8pm4DnFyifVbMBwXmqJx WAKBKenAN+4Ye6qZvsc8GHYmam+LO2Je6Jyzv3f+c/UhquhPDbBXlCt2jCqk9S+nO6LI fLwrhVcPKhWCFBPKcbzsmiBNMhW2t3c6KzWS3WaZlLOfjerbzv5nZzzPWGpVNvwVetpW 5AKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=o3MlKySkLCqcubwj2AlCHtEZtre6EurFM45v8Ib7p+Y=; fh=o2XzhdKG+B45MJCghEfnYoypmHvLX2hd4SL6yXeiyXI=; b=GbBR8+/fW4sB1xE6Q0enxNsc28Iid3xuaDoYLe6iC364l5My2fLspoHOTHjo+4xcdT /NB/Ry90dHgKwxVXElEcRkGPZm6OSB8LkfjAqqw0avASrER7Fe75aWZSTV8oupJp2bix gQXqXdJ9RCithMO6ziGXLTrkaCgIvmXcsErOY3RLkHVzqlRd4iYS9ODw90D6H4qyGxpn zX/cC4ph1JURz/CaB3QftAm+E0w03XzUyUHPK5oURlSy6FTFjVFcqa61E5ZEc5Y1gFDw qKS4s+IW+EA3BdY0gjogM9yKp0MuEL3KwbeQxSCmr1O47ZZm8C6DtI4FdJ0ZUZRiBK6h tGQw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EcBr3RRO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45da75e418bsi29271351cf.330.2024.10.05.16.36.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Oct 2024 16:36:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EcBr3RRO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxEHa-0006BY-IW; Sat, 05 Oct 2024 19:33:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxEHY-0006AT-3b for qemu-devel@nongnu.org; Sat, 05 Oct 2024 19:33:52 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sxEHW-0004DL-Av for qemu-devel@nongnu.org; Sat, 05 Oct 2024 19:33:51 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2e082bf1c7fso2329947a91.3 for ; Sat, 05 Oct 2024 16:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728171229; x=1728776029; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o3MlKySkLCqcubwj2AlCHtEZtre6EurFM45v8Ib7p+Y=; b=EcBr3RROnng+Kwd7MidtFRmZhKsqTueJzo3ri8MjfFdWzInTss+j+LgDjdM2yzcDbw EUWs8WCI6A+zN6eApZYTel26gk0+/ljcwywAiIjGMgZKtHR9yMMUojX+swUmXGnJZ2ge Ob5+Xiw6BS94Eb9HtlidcHVITF3ceU0AmajrGowx/laz6jFkWKkroNUd1ugP8nFFkPb1 XGhwE9RNvvNnKFbukjCQ+4JCbEZnWrDnjtktN9sAztfulnJmYEDy1iRfdOGA99Fcm742 T5XlRZJAzMSMCPWe6Kz9/zo3IeXYu1KMqUTTZMlpHbPQORaM0fuXmpwwvuGzau7qMaNp yEVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728171229; x=1728776029; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o3MlKySkLCqcubwj2AlCHtEZtre6EurFM45v8Ib7p+Y=; b=iKrHh/4CGFytxbNo+sVwAUtPqSiB/OyUfBNNmdx+4TMeanbkdf0Rw54OOxTgYWSgYV T6DPyxCr+S0iS3+UFN4DDqKh7WZLgJm4zqM3nw140U/7oGD/R6zECaU6uqd/CYiNppcS 4s/cfOghsf1CFG2Eyeg3aiuvxhlePeLMNghe+kMR5qzsKqKKibJDoDIWlMVu6Sy2HaMS 1g9EAdDPKbJE0h1OQYZrzjQKmLeKD2ocOQqf8hzt+lC+s+ANZhupogGB9tmL5OhRNltB s1nThVgpBfUEpAXxy+ululWdbF07Y59F2GaPYHV/11nPZX2kFC2Q+kyu235rxBFyqYXl 0xxg== X-Gm-Message-State: AOJu0Yyu1J5XRwV9dt741uoxW/akjTjgYs0WCngvBbAS/ZrTRNHeEFgl Nk1qwsSM2y/IYVRUDf3kFMA14uXLaPFEY98iHOF0r5I5mgFIoxf3D/Fp0dr/MU6080Q0mprPtDV W X-Received: by 2002:a17:90a:c82:b0:2e0:80e8:a312 with SMTP id 98e67ed59e1d1-2e1e63bb8a8mr8356508a91.34.1728171229044; Sat, 05 Oct 2024 16:33:49 -0700 (PDT) Received: from stoup.. (174-21-81-121.tukw.qwest.net. [174.21.81.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e20b129cc2sm2394600a91.51.2024.10.05.16.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2024 16:33:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PATCH 05/10] linux-user: Trace wait4()'s and waitpid()'s wstatus Date: Sat, 5 Oct 2024 16:33:38 -0700 Message-ID: <20241005233343.503426-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241005233343.503426-1-richard.henderson@linaro.org> References: <20241005233343.503426-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich Borrow the code for formatting the most frequent WIFEXITED() and WIFSIGNALED() special cases from from the strace's printstatus(). Output examples: 474729 wait4(-1,0x7f00767ff0a0,0,(nil)) = 474733 (wstatus={WIFEXITED(s) && WEXITSTATUS(s) == 1}) 475833 wait4(-1,0x7f7de61ff0a0,0,(nil)) = 475837 (wstatus={WIFSIGNALED(s) && WTERMSIG(s) == SIGKILL}) 1168 waitpid(1171,0x7f44eea00340,0) = 1171 (wstatus={WIFSIGNALED(s) && WTERMSIG(s) == SIGKILL}) Signed-off-by: Ilya Leoshkevich Message-ID: <20241001193244.14939-1-iii@linux.ibm.com> [rth: Drop extra output for NULL wstatus or error reading.] Signed-off-by: Richard Henderson --- linux-user/strace.c | 57 ++++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 6 +++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index d3cdd09dc1..cf9eaf71c9 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -4215,6 +4215,63 @@ print_ioctl(CPUArchState *cpu_env, const struct syscallname *name, } #endif +#if defined(TARGET_NR_wait4) || defined(TARGET_NR_waitpid) +static void print_wstatus(int wstatus) +{ + if (WIFSIGNALED(wstatus)) { + qemu_log("{WIFSIGNALED(s) && WTERMSIG(s) == "); + print_signal(WTERMSIG(wstatus), 1); + if (WCOREDUMP(wstatus)) { + qemu_log(" && WCOREDUMP(s)"); + } + qemu_log("}"); + } else if (WIFEXITED(wstatus)) { + qemu_log("{WIFEXITED(s) && WEXITSTATUS(s) == %d}", + WEXITSTATUS(wstatus)); + } else { + print_number(wstatus, 1); + } +} + +static void print_ret_wstatus(abi_long ret, abi_long wstatus_addr) +{ + int wstatus; + + if (!print_syscall_err(ret) + && wstatus_addr + && get_user_s32(wstatus, wstatus_addr)) { + qemu_log(TARGET_ABI_FMT_ld " (wstatus=", ret); + print_wstatus(wstatus); + qemu_log(")"); + } + qemu_log("\n"); +} +#endif + +#ifdef TARGET_NR_wait4 +static void +print_syscall_ret_wait4(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) +{ + print_ret_wstatus(ret, arg1); +} +#endif + +#ifdef TARGET_NR_waitpid +static void +print_syscall_ret_waitpid(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) +{ + print_ret_wstatus(ret, arg1); +} +#endif + /* * An array of all of the syscalls we know about */ diff --git a/linux-user/strace.list b/linux-user/strace.list index ef658224fc..f8899710b5 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1662,13 +1662,15 @@ { TARGET_NR_vserver, "vserver" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_wait4 -{ TARGET_NR_wait4, "wait4" , "%s(%d,%p,%d,%p)", NULL, NULL }, +{ TARGET_NR_wait4, "wait4" , "%s(%d,%p,%d,%p)", NULL, + print_syscall_ret_wait4 }, #endif #ifdef TARGET_NR_waitid { TARGET_NR_waitid, "waitid" , "%s(%#x,%d,%p,%#x)", NULL, NULL }, #endif #ifdef TARGET_NR_waitpid -{ TARGET_NR_waitpid, "waitpid" , "%s(%d,%p,%#x)", NULL, NULL }, +{ TARGET_NR_waitpid, "waitpid", "%s(%d,%p,%#x)", NULL, + print_syscall_ret_waitpid }, #endif #ifdef TARGET_NR_write { TARGET_NR_write, "write" , "%s(%d,%#x,%d)", NULL, NULL },