From patchwork Wed Oct 11 10:33:18 2023 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: 731942 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp326249wrv; Wed, 11 Oct 2023 03:35:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIGCqZKvseseboXDLDD8qlW2LXGAocPHYdE9T1EGlGR5G+SQ/AHhWx3XMgRKyO9J3UaoX5 X-Received: by 2002:a81:4854:0:b0:5a7:bf2b:dc27 with SMTP id v81-20020a814854000000b005a7bf2bdc27mr4708309ywa.14.1697020547975; Wed, 11 Oct 2023 03:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697020547; cv=none; d=google.com; s=arc-20160816; b=rOHu23Yq+pGjihVtAM+rWAkjZUVyrAUkoIR3TnYvrqBUcZf/BA6mnm/BAXue6pH7O3 nei8A++fG+jlM5nBHLUv4+/Hr1fOdZv8mAbx9Y1Sx5FjN5KX4yYHrb58x9jbh/68eHC5 2qFCcmTdCSGv5rKBQ6hqVNYt/m5L/KkPQa/JZyO9rIKlT60g5M23eh0AMN3T/7zMGLmp sAZMereiyjel3y2hHJNkyVJGOd8wWoIKnBtwf1qPN6wtcwH/0srtCbbdNSe6GKeyL8w2 BZSBPKx6xL1gt1U3rZ3pDHzhz1mwmR0lTqF93OK09mB/nXANzjJoiJ01nCfshFETIhKq LMdA== 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=Jt1UXVJ9g1e9zBvoXUT5QK8FO+jhEnDupj0uz8RWS3E=; fh=IbUqTVN6VYwKhToyTxhvsHddAIdqCrQdQpZv42YoYsY=; b=z21ZHoDC+0uKs4yGBKQPBazd0wS3JVFV87A297LKm8tu+OvO8yuUkW37DOnBRZpDz9 rNtik6rDnCshY57j6NeaYUElOYi19no02cSCam4PyWJS2USlonCqXHqLIJ06LDk9KvlJ 6t0u6Hn/TweBi5QuYjrHtpxMEyYm4b+RiAg2MW1J47J7fdDRYdUB0X15F5z2VGiIgXpW Oik3PS+yhct8ziABERDG22gIQIZllYLms3vc2qrpoPPzynFDtduWHBHaYL2swK4KkGuZ HvL0pGH7ihimPsqh6I2iJdFJu1mKU6qAzR7c1uF0hG+QMgT0qrvJl92yVjsAt2/9E+Da GiIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JZCFaGk8; 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 j19-20020a37ef13000000b0076daeaded07si8696903qkk.74.2023.10.11.03.35.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Oct 2023 03:35:47 -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=JZCFaGk8; 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 1qqWXJ-0001ac-Gr; Wed, 11 Oct 2023 06:33:53 -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 1qqWX8-0001LU-Ag for qemu-devel@nongnu.org; Wed, 11 Oct 2023 06:33:42 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqWX5-0005Fp-DO for qemu-devel@nongnu.org; Wed, 11 Oct 2023 06:33:42 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40651a726acso61653875e9.1 for ; Wed, 11 Oct 2023 03:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697020418; x=1697625218; 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=Jt1UXVJ9g1e9zBvoXUT5QK8FO+jhEnDupj0uz8RWS3E=; b=JZCFaGk8yhL81twwBfn0bod0eTaQcY6OFU2NcfFEDQLMYKcTp6Du8x+Q7qWFtjAJNk QJMAwUVaXnw4mjln6FZZF5C5Q5FMYeC9siyJbid0KLM5Rou5AuvJFv3QI1R3bHArx8UF k8AEHhTDiy1nr3iNFbki6CBeyAD4miw6+i+MfbAVJeiLFl4lfiOyzFW/HKkvgUpNv79G EgEwJV6I7Y/aH5jNdMYW6dwJxhI4NZVTpLItbcivkKL70Lv7ePJePFtI/a9OtjarjgzR dkfu/tz7/XzweabqAbSLTg/zLS6rhJcGsrjgLzxQyvnI6rDNV/aUd5vKvkfTL0OZp5ck otsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697020418; x=1697625218; 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=Jt1UXVJ9g1e9zBvoXUT5QK8FO+jhEnDupj0uz8RWS3E=; b=YZ/gxwQOsMZGUDEJk+7eFAOQbIIeuI3q4zlfBdUCkAuaa23nUMCQR7OAPMm3oykzcX WpsRp9zmr3f8y5bDWBj6d2BmPujwxm1juYqFAEnvATQmXrrpZdHd7UNma5rEYhYotG9l 7ZIebeEkueOTD+WLiP86Mjm9RjH4onxDutgsru7QN8NhuF1Qkrn0WGZb8TsOU6kSW8/j PJ1gR/vDXjtIQQpoYFTWGhaUdjJWCVpzGYHLmqx26YqaJjjI0c8jYSBJ8FBotvL9AKPi 4vDIujj2jdxnibcgfarEOneUwjMqB7a9BcOrktLtnrO8SdpAWKEOCoCPTaweUX5pYjFq v66A== X-Gm-Message-State: AOJu0YzalFwNLaTEq6a+7xsu8hgpNuZRJ9jr5DekiLY3KpnObZI1b/ai 4udWIbQ20wLioDSXYHk1A+1tmg== X-Received: by 2002:adf:edc3:0:b0:321:56af:5ef9 with SMTP id v3-20020adfedc3000000b0032156af5ef9mr15095927wro.70.1697020417859; Wed, 11 Oct 2023 03:33:37 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id t11-20020a5d534b000000b003232380ffd5sm15085477wrv.106.2023.10.11.03.33.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 03:33:35 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BC4111FFC6; Wed, 11 Oct 2023 11:33:31 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , =?utf-8?q?Alex_Benn=C3=A9e?= , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Peter Maydell , Song Gao , Xiaojuan Yang , Nicholas Piggin , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Palmer Dabbelt , Bin Meng , Weiwei Li , Liu Zhiwei , Thomas Huth , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Bastian Koppelmann , qemu-arm@nongnu.org (open list:ARM TCG CPUs), qemu-ppc@nongnu.org (open list:PowerPC TCG CPUs), qemu-riscv@nongnu.org (open list:RISC-V TCG CPUs), qemu-s390x@nongnu.org (open list:S390 general arch...) Subject: [PULL 14/25] hw/core/cpu: Return static value with gdb_arch_name() Date: Wed, 11 Oct 2023 11:33:18 +0100 Message-Id: <20231011103329.670525-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011103329.670525-1-alex.bennee@linaro.org> References: <20231011103329.670525-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x332.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=unavailable 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: Akihiko Odaki All implementations of gdb_arch_name() returns dynamic duplicates of static strings. It's also unlikely that there will be an implementation of gdb_arch_name() that returns a truly dynamic value due to the nature of the function returning a well-known identifiers. Qualify the value gdb_arch_name() with const and make all of its implementations return static strings. Signed-off-by: Akihiko Odaki Reviewed-by: Alex Bennée Reviewed-by: Alistair Francis Message-Id: <20230912224107.29669-8-akihiko.odaki@daynix.com> Signed-off-by: Alex Bennée Message-Id: <20231009164104.369749-15-alex.bennee@linaro.org> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index e02bc5980f..7b8347ed5a 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -165,7 +165,7 @@ struct CPUClass { vaddr (*gdb_adjust_breakpoint)(CPUState *cpu, vaddr addr); const char *gdb_core_xml_file; - gchar * (*gdb_arch_name)(CPUState *cpu); + const gchar * (*gdb_arch_name)(CPUState *cpu); const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname); void (*disas_set_info)(CPUState *cpu, disassemble_info *info); diff --git a/target/ppc/internal.h b/target/ppc/internal.h index 15803bc313..c881c67a8b 100644 --- a/target/ppc/internal.h +++ b/target/ppc/internal.h @@ -221,7 +221,7 @@ void destroy_ppc_opcodes(PowerPCCPU *cpu); /* gdbstub.c */ void ppc_gdb_init(CPUState *cs, PowerPCCPUClass *ppc); -gchar *ppc_gdb_arch_name(CPUState *cs); +const gchar *ppc_gdb_arch_name(CPUState *cs); /** * prot_for_access_type: diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index bba2640293..a20169c27b 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -380,10 +380,9 @@ static const char *get_feature_xml(const char *p, const char **newp, ""); if (cc->gdb_arch_name) { - g_autofree gchar *arch = cc->gdb_arch_name(cpu); g_string_append_printf(xml, "%s", - arch); + cc->gdb_arch_name(cpu)); } g_string_append(xml, "gdb_core_xml_file); diff --git a/target/arm/cpu.c b/target/arm/cpu.c index b65e8cfea3..6c6c551573 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2319,15 +2319,15 @@ static Property arm_cpu_properties[] = { DEFINE_PROP_END_OF_LIST() }; -static gchar *arm_gdb_arch_name(CPUState *cs) +static const gchar *arm_gdb_arch_name(CPUState *cs) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; if (arm_feature(env, ARM_FEATURE_IWMMXT)) { - return g_strdup("iwmmxt"); + return "iwmmxt"; } - return g_strdup("arm"); + return "arm"; } #ifndef CONFIG_USER_ONLY diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 811f3b38c2..1cb9d5b81a 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -781,9 +781,9 @@ static void aarch64_cpu_finalizefn(Object *obj) { } -static gchar *aarch64_gdb_arch_name(CPUState *cs) +static const gchar *aarch64_gdb_arch_name(CPUState *cs) { - return g_strdup("aarch64"); + return "aarch64"; } static void aarch64_cpu_class_init(ObjectClass *oc, void *data) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index cec5d2b7b6..3aab05ddad 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5916,12 +5916,12 @@ static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model) memset(&env->user_features, 0, sizeof(env->user_features)); } -static gchar *x86_gdb_arch_name(CPUState *cs) +static const gchar *x86_gdb_arch_name(CPUState *cs) { #ifdef TARGET_X86_64 - return g_strdup("i386:x86-64"); + return "i386:x86-64"; #else - return g_strdup("i386"); + return "i386"; #endif } diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index 2bea7ca5d5..ef1bf89dac 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -766,9 +766,9 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data) #endif } -static gchar *loongarch32_gdb_arch_name(CPUState *cs) +static const gchar *loongarch32_gdb_arch_name(CPUState *cs) { - return g_strdup("loongarch32"); + return "loongarch32"; } static void loongarch32_cpu_class_init(ObjectClass *c, void *data) @@ -780,9 +780,9 @@ static void loongarch32_cpu_class_init(ObjectClass *c, void *data) cc->gdb_arch_name = loongarch32_gdb_arch_name; } -static gchar *loongarch64_gdb_arch_name(CPUState *cs) +static const gchar *loongarch64_gdb_arch_name(CPUState *cs) { - return g_strdup("loongarch64"); + return "loongarch64"; } static void loongarch64_cpu_class_init(ObjectClass *c, void *data) diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index 2ad11510bf..778ef73bd7 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -589,12 +589,12 @@ static int gdb_set_vsx_reg(CPUPPCState *env, uint8_t *mem_buf, int n) return 0; } -gchar *ppc_gdb_arch_name(CPUState *cs) +const gchar *ppc_gdb_arch_name(CPUState *cs) { #if defined(TARGET_PPC64) - return g_strdup("powerpc:common64"); + return "powerpc:common64"; #else - return g_strdup("powerpc:common"); + return "powerpc:common"; #endif } diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index ac2b94b6a6..f5572704de 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -2004,17 +2004,17 @@ static Property riscv_cpu_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static gchar *riscv_gdb_arch_name(CPUState *cs) +static const gchar *riscv_gdb_arch_name(CPUState *cs) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; switch (riscv_cpu_mxl(env)) { case MXL_RV32: - return g_strdup("riscv:rv32"); + return "riscv:rv32"; case MXL_RV64: case MXL_RV128: - return g_strdup("riscv:rv64"); + return "riscv:rv64"; default: g_assert_not_reached(); } diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 4f7599d72c..6093ab0a12 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -282,9 +282,9 @@ static void s390_cpu_initfn(Object *obj) #endif } -static gchar *s390_gdb_arch_name(CPUState *cs) +static const gchar *s390_gdb_arch_name(CPUState *cs) { - return g_strdup("s390:64-bit"); + return "s390:64-bit"; } static Property s390x_cpu_properties[] = { diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index d1477622e6..5ca666ee12 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -29,9 +29,9 @@ static inline void set_feature(CPUTriCoreState *env, int feature) env->features |= 1ULL << feature; } -static gchar *tricore_gdb_arch_name(CPUState *cs) +static const gchar *tricore_gdb_arch_name(CPUState *cs) { - return g_strdup("tricore"); + return "tricore"; } static void tricore_cpu_set_pc(CPUState *cs, vaddr value)