From patchwork Wed Jun 13 12:55:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 138468 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp702253lji; Wed, 13 Jun 2018 06:08:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKEM06kg02ohNHEU3Q0WK3MBvbBJg8O5xcJvtdmkSRgxk/EneHTkwGlzuy6CAy2S9dP1cd4 X-Received: by 2002:a0c:bca9:: with SMTP id l41-v6mr4224720qvg.178.1528895337542; Wed, 13 Jun 2018 06:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528895337; cv=none; d=google.com; s=arc-20160816; b=hyW4khL57F4hOpmLg+CoNkafTTFOKr8s1H5pR9CkiiKbQVCom9JqIpKZn2IC41WTo+ i3/wl072hCq2efZyC1AqCt+ty5MhU9+hrU7RFxq36A3ejyEUY5hvhhl5uhlFeoax9+Sk r5OLrPQN8sWsjmAH98R5ZLvgj3q4p9Zx6yq7ywfV1x+uzqWRdjOOV6NuDPVh0OT6OuPE ChI1YMzceeWSKD/xuDhchHQ9YGRvOkUDzCNSuALZl0fAEy46+b4/e8KGGoosToc+BKOw GFX0sSfZE3eyel4NeYhA+nX8GMqVx0BPrcHQcbSBlWMHL4CmvncbZ96fF19rGNgSUUb8 c/fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Bp/1YbPML67ffji3kuZga7TLev+DhxX9wc1+8T4FSYo=; b=qAc+fsssLL9EfhrnNaVoLfg+1JBgm673ZBRDwGugvk5h8rGWkB4AJZuJ7Py9MJPj5j /ANwXyX+R2Sq7gA3Arte1TUlSlfMSX0BsWyNwpD5Fkx/ztLxkCsJcRb5wrtF4FLHM4k8 O48pOSmLsSMShtwy48fetD/kI8dLhpnOi2wCJq84/oqPt8fUL+HZxyn6z5/fTV2aOvtz MjQ8v7PzZrt/0GJ9RowizXqMddvpcR2m4xERhzOLtxP0K+pg138SFETjyKA9ZagSohaN Vv33C8ZzV+HjhFmS8ovBeedzxatogynBr+88PAjkSRkyR4Rs8z0+ObARBxg0sByLroUL ebsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ECj7tu4f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x189-v6si2667184qkc.119.2018.06.13.06.08.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Jun 2018 06:08:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ECj7tu4f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34100 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT5WD-0004MF-0V for patch@linaro.org; Wed, 13 Jun 2018 09:08:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT5SH-0001Wu-8Q for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fT5SE-0005SI-Ry for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:53 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35194) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fT5SE-0005PE-J1 for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:50 -0400 Received: by mail-wm0-x236.google.com with SMTP id j15-v6so5322957wme.0 for ; Wed, 13 Jun 2018 06:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bp/1YbPML67ffji3kuZga7TLev+DhxX9wc1+8T4FSYo=; b=ECj7tu4fjh4/8D9TnUj4U3q9JfAeovlW40BMCtdoXVmWCtEEPbC2Ql3KTY2vvt3TQb fj1hu5UZj8TaNNmtnF0E6txsC9QC0+T1Np6YrGdBEL4ThYmrruTEN12aRG9BVg9/TKUc DhPxoadhLxFmb5hn98SL4uup3nsA0uWRuaNlw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bp/1YbPML67ffji3kuZga7TLev+DhxX9wc1+8T4FSYo=; b=FV6835pbhRaRdz7neEklvW2lEnlMopqiss0i/5RJNEx1nYZCnMgZSoG9QEQu/RybKQ 4QwbLEeE+7jAfffiz3Eq41krurQIjoQ15gFKL+ONrCXwuXvlilSZXPyNbWa5AqS3ZNan aI21Ewkj6t1KsitET9Waudu25tmLH4s7X3hHZuFkPondAum8mlvDbIIf7sHiJFVOEG8f OmdWLqJlO5/hN8Nh1JkVrZjzOe7Wdx0x3UXi2+4pSKjCUHBa1KnTfJqkEHCRbOSU+mpn dpCZaWYWb7YcCMKyAyhoongEtExUaII0YfhMIt9n1zALJvwqYDRAQTGXugWwc4qLiFVp igqQ== X-Gm-Message-State: APt69E0uUL9hrs325ys4Cxy3HQRXPIYAAeHsghMCq+hhTFbvJDPv7sex 0+YFtAzuTcyBf5ItFACj8LbCtg== X-Received: by 2002:a1c:d650:: with SMTP id n77-v6mr3704750wmg.140.1528895089453; Wed, 13 Jun 2018 06:04:49 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id h7-v6sm1736493wmb.48.2018.06.13.06.04.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jun 2018 06:04:45 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id DB8EC3E12A1; Wed, 13 Jun 2018 13:56:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Wed, 13 Jun 2018 13:55:53 +0100 Message-Id: <20180613125601.14371-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180613125601.14371-1-alex.bennee@linaro.org> References: <20180613125601.14371-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::236 Subject: [Qemu-devel] [RISU PATCH v3 14/22] risu: add process_arch_opt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Allows the backend to do more that just set a flag when it comes to processing options. Signed-off-by: Richard Henderson [AJB: tweaked order, added stdlib includes] Signed-off-by: Alex Bennée --- risu.c | 33 +++++++++++---------------------- risu.h | 7 +++++-- risu_reginfo_aarch64.c | 10 ++++++++-- risu_reginfo_arm.c | 14 ++++++++++---- risu_reginfo_m68k.c | 10 ++++++++-- risu_reginfo_ppc64.c | 10 ++++++++-- 6 files changed, 50 insertions(+), 34 deletions(-) -- 2.17.1 diff --git a/risu.c b/risu.c index 18de351..01525d2 100644 --- a/risu.c +++ b/risu.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -27,7 +26,6 @@ #include #include "config.h" - #include "risu.h" void *memblock; @@ -287,7 +285,7 @@ void usage(void) } } -struct option * setup_options(char **short_opts) +static struct option * setup_options(char **short_opts) { static struct option default_longopts[] = { {"help", no_argument, 0, '?'}, @@ -303,20 +301,19 @@ struct option * setup_options(char **short_opts) if (arch_long_opts) { const size_t osize = sizeof(struct option); - const int default_count = ARRAY_SIZE(default_longopts); - struct option *dptr; - int extra_count = 0; + const int default_count = ARRAY_SIZE(default_longopts) - 1; + int arch_count; /* count additional opts */ - dptr = arch_long_opts; - do {} while (dptr[extra_count++].name); + for (arch_count = 0; arch_long_opts[arch_count].name; arch_count++) { + continue; + } - lopts = calloc(default_count + extra_count, osize); + lopts = calloc(default_count + arch_count + 1, osize); /* Copy default opts + extra opts */ memcpy(lopts, default_longopts, default_count * osize); - dptr = &lopts[default_count - 1]; - memcpy(dptr, arch_long_opts, extra_count * osize); + memcpy(lopts + default_count, arch_long_opts, arch_count * osize); } return lopts; @@ -343,34 +340,26 @@ int main(int argc, char **argv) switch (c) { case 0: - { /* flag set by getopt_long, do nothing */ break; - } case 't': - { trace_fn = optarg; trace = 1; break; - } case 'h': - { hostname = optarg; break; - } case 'p': - { /* FIXME err handling */ port = strtol(optarg, 0, 10); break; - } case '?': - { usage(); exit(1); - } default: - abort(); + assert(c >= FIRST_ARCH_OPT); + process_arch_opt(c, optarg); + break; } } diff --git a/risu.h b/risu.h index 89811f4..48c50d9 100644 --- a/risu.h +++ b/risu.h @@ -16,10 +16,13 @@ #include #include #include +#include /* Extra option processing for architectures */ -extern void *arch_long_opts; -extern char *arch_extra_help; +extern const struct option * const arch_long_opts; +extern const char * const arch_extra_help; +void process_arch_opt(int opt, const char *arg); +#define FIRST_ARCH_OPT 0x100 /* GCC computed include to pull in the correct risu_reginfo_*.h for * the architecture. diff --git a/risu_reginfo_aarch64.c b/risu_reginfo_aarch64.c index ab12270..c270e0b 100644 --- a/risu_reginfo_aarch64.c +++ b/risu_reginfo_aarch64.c @@ -14,12 +14,18 @@ #include #include #include /* for FPSIMD_MAGIC */ +#include #include "risu.h" #include "risu_reginfo_aarch64.h" -void *arch_long_opts; -char *arch_extra_help; +const struct option * const arch_long_opts; +const char * const arch_extra_help; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} /* reginfo_init: initialize with a ucontext */ void reginfo_init(struct reginfo *ri, ucontext_t *uc) diff --git a/risu_reginfo_arm.c b/risu_reginfo_arm.c index 5acad02..12ad0ef 100644 --- a/risu_reginfo_arm.c +++ b/risu_reginfo_arm.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include "risu.h" #include "risu_reginfo_arm.h" @@ -22,13 +22,19 @@ extern int insnsize(ucontext_t *uc); /* Should we test for FP exception status bits? */ static int test_fp_exc; -static struct option extra_opts[] = { +static const struct option extra_opts[] = { {"test-fp-exc", no_argument, &test_fp_exc, 1}, {0, 0, 0, 0} }; -void *arch_long_opts = &extra_opts[0]; -char *arch_extra_help = " --test-fp-exc Check FP exception bits when comparing\n"; +const struct option * const arch_long_opts = &extra_opts[0]; +const char * const arch_extra_help = + " --test-fp-exc Check FP exception bits when comparing\n"; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} static void reginfo_init_vfp(struct reginfo *ri, ucontext_t *uc) { diff --git a/risu_reginfo_m68k.c b/risu_reginfo_m68k.c index d429502..7a1c5a9 100644 --- a/risu_reginfo_m68k.c +++ b/risu_reginfo_m68k.c @@ -10,12 +10,18 @@ #include #include #include +#include #include "risu.h" #include "risu_reginfo_m68k.h" -void *arch_long_opts; -char *arch_extra_help; +const struct option * const arch_long_opts; +const char * const arch_extra_help; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} /* reginfo_init: initialize with a ucontext */ void reginfo_init(struct reginfo *ri, ucontext_t *uc) diff --git a/risu_reginfo_ppc64.c b/risu_reginfo_ppc64.c index 395111c..4b70460 100644 --- a/risu_reginfo_ppc64.c +++ b/risu_reginfo_ppc64.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "risu.h" #include "risu_reginfo_ppc64.h" @@ -22,8 +23,13 @@ #define XER 37 #define CCR 38 -void *arch_long_opts; -char *arch_extra_help; +const struct option * const arch_long_opts; +const char * const arch_extra_help; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} /* reginfo_init: initialize with a ucontext */ void reginfo_init(struct reginfo *ri, ucontext_t *uc)