From patchwork Mon Jul 1 02:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 808822 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp1376376wrr; Sun, 30 Jun 2024 19:51:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWf3OaAmfTZgrcC/bMeeWTfwZxTvVsVh/42VPhY4Vb0zKM2CIIDIObhSdM7OjOjILVlbxDSGiKfIBxLX4OAW+Y8 X-Google-Smtp-Source: AGHT+IH6QdFlZG9nJTL2X7HZWhWMfwFV+xskDXn3D6mPKCdUtgf3Jkw+HQeAS1Rozc71JfE5rsR6 X-Received: by 2002:a81:9215:0:b0:618:2f6d:ca80 with SMTP id 00721157ae682-64c71802f91mr49244107b3.12.1719802308446; Sun, 30 Jun 2024 19:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719802308; cv=none; d=google.com; s=arc-20160816; b=lwqSprIHu3D0QaewcKmj3JQiVtVzn9hDAmxGMYd5jqbOrqjzg5QDh5LdSj9mBqDI/2 oCV4VUVF6w2Xfb5V7edXWcuW4DAyGmB5cCO80x8cTYCjUgMOaaiKlhFgfHJqJvjUJnw2 /FEcKYz9RINs2Pv25UQPP3Amz3TRIFt7nFWZos7qHctyAhe1lDjV3zMf4Vv6cVDD0JhV TjcVfZsG6uew3gY/cVn7O4T7373IWJZA8mRVVxusSq4cLVUDkKTsiR3nKUrrxmyrUUDx r7LcZFiHMUOu2SOLDxF622aZZM7Y3SpHU4CJKfBmR7chde0vVJtL85n/YftdlTbd3t4z iCxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=mPMDVI+D07uyiyyk8Iq5xR3y1Ye6RQN5Bs9ydJnDyA0=; fh=3mEp7FusppN5Drq2PN08R8D/9xXM9YdbtG5TkJxJBiE=; b=M1xKuocbL7MIW7U/uOUWMDNlKibu18Dh8E/wMbqklHRA+LOS8vCPf4twi2lcFBPfOM o0Ibj/txRQIZYxlqa6Ki457WL3RbSoY0RQK0n2nuzL2N7TXEI/2m4EAXTan13OSgKbWn rUhKDH23Wwnc6DseEJ5005vj4NGlzTioYjcHiTUAHInumIxZWSW9/K0QGB4qu6RF2EMn +LKm+/Yq+GB91B0zsKo7JOeVT5Vjm3FDp47GMmRJuMo+abmKcTDyYRPhun8RwESe8pwd cOCbFfhbSBQlVCyyTcVZhFR35kA0oBoZs3Qf5IQUFE8T5Z7oqQCGby+uov2xOAfeCF0v GLMQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Az0Twaeh; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4465148a11dsi71407751cf.242.2024.06.30.19.51.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 30 Jun 2024 19:51:48 -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=Az0Twaeh; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO78V-0002xn-1R; Sun, 30 Jun 2024 22:51:23 -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 1sO78T-0002tw-An for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:21 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sO78R-0008Vn-EK for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:21 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7066f68e22cso1474730b3a.2 for ; Sun, 30 Jun 2024 19:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719802278; x=1720407078; 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=mPMDVI+D07uyiyyk8Iq5xR3y1Ye6RQN5Bs9ydJnDyA0=; b=Az0Twaeh5w2XSbykktmKCOSS43tx9AFv10//13yy3pktqNsOUwUDGE/4iygAuK5+gu CDroVflXbZzxsni9I//OoEJANSS9ndItebNECqLM+OcSzCrk1E4NQRUznwwPeR0ZNld4 0Lt6Sei0iyNy7hcwEr2Ia6/HF4C5RKitxsihM6DI/N6GfJJZGIW/KLBlNybGA6iKvPEI +siVbGDdDS9Yx+1BQL/O5oQYMOY2/ossUoF4p0Kp0ZgV73cy7vewwE/wJTPA0VPuFa2M ugsnKH+cZbrxJxVe08YN23AdUpKB/ygt4HHG3zISJaayJdJ6HVDpOYS5fW7LEumCloHb EOxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719802278; x=1720407078; 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=mPMDVI+D07uyiyyk8Iq5xR3y1Ye6RQN5Bs9ydJnDyA0=; b=V9mIqYOJGzG/Fc6LLkOGqCwHjiTct1JbFbMOLQH4D3JKFY+EAD4oJQD3lmmqr6Aktp LPquhBNKmOhD9I+Bf9ogOeMgZNB71qkaXs0RHWrY8XGJFrvsuQE2QkKVs61CTVjEZSvm HNROP4uSCYABuKb9VTGI75u4Ykq6fVpXjtfwClmJeVZixuI78BN2hMEZQOPQXgiiJsQo 08H0Se5IlANvZ3PkpRz68PHVc0Dl7NvLMO8/r5fxAEo/wUX61zF0bFZ6CIE2MuGQJclq qa5eMO03/GRnhk5GRT0j3kEMOt6PSqCYjvk8117k3k+GJ4Nc5D6qbf2kSkWqekO7zY1I tr2Q== X-Gm-Message-State: AOJu0YxA4inUURr14lorGRrrXIUKPbS8HvCrBtmTEurKtbFG8IrKsrA2 xgpVkqK4yjJBKdwTPebO8U3DTjiSs6kzD3OI+fi85Bi1VDZDjYZDhSeG8Qrkgs78AxZv7qfJdMh F X-Received: by 2002:a05:6a20:7fa9:b0:1bd:253e:28e with SMTP id adf61e73a8af0-1bef61398b1mr3590112637.16.1719802277424; Sun, 30 Jun 2024 19:51:17 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3b9349sm5531698a91.37.2024.06.30.19.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 19:51:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 1/5] target/i386: Tidy cc_op_str usage Date: Sun, 30 Jun 2024 19:51:11 -0700 Message-Id: <20240701025115.1265117-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240701025115.1265117-1-richard.henderson@linaro.org> References: <20240701025115.1265117-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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 Make const. Use the read-only strings directly; do not copy them into an on-stack buffer with snprintf. Allow for holes in the cc_op_str array, now present with CC_OP_POPCNT. Fixes: 460231ad369 ("target/i386: give CC_OP_POPCNT low bits corresponding to MO_TL") Signed-off-by: Richard Henderson --- target/i386/cpu-dump.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c index 3bb8e44091..dc6723aede 100644 --- a/target/i386/cpu-dump.c +++ b/target/i386/cpu-dump.c @@ -27,7 +27,7 @@ /***********************************************************/ /* x86 debug */ -static const char *cc_op_str[CC_OP_NB] = { +static const char * const cc_op_str[] = { [CC_OP_DYNAMIC] = "DYNAMIC", [CC_OP_EFLAGS] = "EFLAGS", @@ -347,7 +347,6 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; int eflags, i, nb; - char cc_op_name[32]; static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" }; eflags = cpu_compute_eflags(env); @@ -456,10 +455,16 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) env->dr[6], env->dr[7]); } if (flags & CPU_DUMP_CCOP) { - if ((unsigned)env->cc_op < CC_OP_NB) - snprintf(cc_op_name, sizeof(cc_op_name), "%s", cc_op_str[env->cc_op]); - else - snprintf(cc_op_name, sizeof(cc_op_name), "[%d]", env->cc_op); + const char *cc_op_name = NULL; + char cc_op_buf[32]; + + if ((unsigned)env->cc_op < ARRAY_SIZE(cc_op_str)) { + cc_op_name = cc_op_str[env->cc_op]; + } + if (cc_op_name == NULL) { + snprintf(cc_op_buf, sizeof(cc_op_buf), "[%d]", env->cc_op); + cc_op_name = cc_op_buf; + } #ifdef TARGET_X86_64 if (env->hflags & HF_CS64_MASK) { qemu_fprintf(f, "CCS=%016" PRIx64 " CCD=%016" PRIx64 " CCO=%s\n",