From patchwork Fri Aug 28 13:37:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 275280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1801C433E2 for ; Fri, 28 Aug 2020 13:39:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 890FC207DF for ; Fri, 28 Aug 2020 13:39:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 890FC207DF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBebe-0007nm-Pi for qemu-devel@archiver.kernel.org; Fri, 28 Aug 2020 09:39:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBeZy-0003aW-7J for qemu-devel@nongnu.org; Fri, 28 Aug 2020 09:38:06 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:33647) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBeZv-0007Ff-PF for qemu-devel@nongnu.org; Fri, 28 Aug 2020 09:38:05 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M91Tq-1kHj7G3K3a-006Ajc; Fri, 28 Aug 2020 15:38:01 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 07/18] linux-user: Add an api to print enumareted argument values with strace Date: Fri, 28 Aug 2020 15:37:42 +0200 Message-Id: <20200828133753.2622286-8-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200828133753.2622286-1-laurent@vivier.eu> References: <20200828133753.2622286-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:teg7T1ZpbtEYbF07Jalqw4AtCRvsrrgutS8qSyUTo3fL6jAeRWs dNHivROgimG4DadCM2JGOf0zNVKYAgA+PRbBGGLsJPCq5yhOG+hp0H0yg3FamX5KFKVjZ8t tW0mgdUudgG8GMX/rpDdkW3Kak8OfAsPgqXUGmcfGnTvKkT8jIiPgPtLcKE9W+Yj4p0EPiy 70m1dpr9JQmDiCHbVUyuQ== X-UI-Out-Filterresults: notjunk:1; V03:K0:JZNyc35OxHk=:ZbQt2dDPnLBlsF32uoNs4/ 5NHGiksm2mh15ezsusLeBDxBirdkkP+LKFLGHdZTLYBU6jaXGJieOzKENf1R2WZTMnJquS492 HLL9PsyvSzruJpJaYmJqwRz+gVOinwEtkgVVLiY4yR2EDEdXHHMM7cgGvc+tHEcBs2N1hgk9t uBvHYuT4uzk/iV6Jbk1OOqLcRnpgbomWaQIe/n/9CBquPhdG0GtM1VCKcUZ08sNKy9Nl7LDY9 vqTTNyf8u6ICOtC8p5FMS1hKMxSw/GzpPqUmRQ8INV5rJXUqO+fMr6nodL1/DI4w1hSa3TvKq F4n1dT8APDMl0aflB7uI4M1cp9uemGo6QhVf03NOFQ7yRvyUYHmekzkjawaLvJpXTkUD0njvZ R48FAlrJxhj+gv53saClul9QC1uEBLWTP3oPCsq6n9IZqmW7ETMogeF5bb9MspNDT8++xNgpk 8yLj5svdvl+eRR0V0cSzxBkuw/dBzxiQjKp/a44z++jkPWO+fR/myTspRJlXvnAKXPchq9Xw8 Lx0CyM0Qe31GMcyBJFxR4aJ3RM0GbvqYNJkYYRmpBX6WxqPUmWNZHx89wavBBVCEEHFPs3PhO 4wmKBPpMNoa2+wPsFi7y3UaoMJDUYJxns2N2MxKs0J9+M86rd5ZgsLFzfrqdxih47X4CuUaNF h289ma7FKvDDQX69cuOusL8IdfHUBnUR+qvBmGzp8sVoZEi95D/NnAK+OQeI8wvdf5sigBT9n dPdDETQqtGDYrfCh/Lex903+bDnoTzUeEK1XR2BemrXM5D3ZgMKxsqPtU1Cg4YgbaTNGnIdEN lm4ltXLPiBoagl1Noh2dxayV/D0uXCw6v9l/moe8IlKXm1J8dcR1veVXSdUAe3NrNhknyDM Received-SPF: none client-ip=212.227.126.134; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/28 09:38:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta This patch introduces a type 'struct enums' and function 'print_enums()' that can be used to print enumerated argument values of some syscalls in strace. This can be used in future strace implementations. Also, macros 'ENUM_GENERIC()', 'ENUM_TARGET()' and 'ENUM_END', are introduced to enable automatic generation of aproppriate enumarated values and their repsective string representations (these macros are exactly the same as 'FLAG_GENERIC()', 'FLAG_TARGET()' and 'FLAG_END'). Future patches are planned to modify all existing print functions in 'strace.c' that print arguments of syscalls with enumerated values to use this new api. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200811164553.27713-5-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/strace.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/linux-user/strace.c b/linux-user/strace.c index 4ac54ecffe9c..d0731b888d29 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -52,9 +52,23 @@ struct flags { /* end of flags array */ #define FLAG_END { 0, NULL } +/* Structure used to translate enumerated values into strings */ +struct enums { + abi_long e_value; /* enum value */ + const char *e_string; /* stringified enum */ +}; + +/* common enums for all architectures */ +#define ENUM_GENERIC(name) { name, #name } +/* target specific enums */ +#define ENUM_TARGET(name) { TARGET_ ## name, #name } +/* end of enums array */ +#define ENUM_END { 0, NULL } + UNUSED static const char *get_comma(int); UNUSED static void print_pointer(abi_long, int); UNUSED static void print_flags(const struct flags *, abi_long, int); +UNUSED static void print_enums(const struct enums *, abi_long, int); UNUSED static void print_at_dirfd(abi_long, int); UNUSED static void print_file_mode(abi_long, int); UNUSED static void print_open_flags(abi_long, int); @@ -1252,6 +1266,23 @@ print_flags(const struct flags *f, abi_long flags, int last) } } +static void +print_enums(const struct enums *e, abi_long enum_arg, int last) +{ + for (; e->e_string != NULL; e++) { + if (e->e_value == enum_arg) { + qemu_log("%s", e->e_string); + break; + } + } + + if (e->e_string == NULL) { + qemu_log("%#x", (unsigned int)enum_arg); + } + + qemu_log("%s", get_comma(last)); +} + static void print_at_dirfd(abi_long dirfd, int last) {