From patchwork Tue Aug 15 14:51:26 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: 713781 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp1822541wrp; Tue, 15 Aug 2023 07:52:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3t7xovjJRQZv606F6ZZ97HI9F+DCZtf/Q07keW84mUf+Ghbd3HuLPRBmUEm4CSV5k9JjV X-Received: by 2002:a05:620a:40d4:b0:767:dcca:7c35 with SMTP id g20-20020a05620a40d400b00767dcca7c35mr17527395qko.9.1692111178569; Tue, 15 Aug 2023 07:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692111178; cv=none; d=google.com; s=arc-20160816; b=n0R/1eeYoI7jAEbXA5/0BDeh0MLFA51NcgcZSwdMMtHpHbrCFSiU2rIb61AYgv7Dhw ag7r/4ttv7LD5PCO55P6gI6dGZbsiNYmsl9SDzrZv8ljjqZ4aOmktOR1fkLjttR1jO0E kaG4KIKI9FtxHYcCzRUIF7ZdZQb2glYJ+nwB6QS5g5mn8rZ9gzOiaoo+2cPNp1BWx5cQ N1HBo3SkKoLNg6sxO2PJfluBGcs58sbwnr6jiGSeBiUzusVFs830T3dY2UgR13T573xT ib7aMSc9W/wDjuiTeobRMZcfPnZWpf8PfSU7RZo4gEluI9xVWu4nLA3X7Byj6LYHUXXA C0nw== 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=UnhFXoZukvu0YTKINuH5NG1+Wifue15VPIsTSt2x950=; fh=04/pGBQSKxP/VRM1dOX7r60Lg6gNaLrLAuVAoZSSo70=; b=sT5yADxdgUjFffoonf4cHZJqIonWBptyK1UVLyvMTYjDZUMWrdu/MPAyD/gXZ4tiKk +CkrDqeYMdbV7ibyPYBmq4+2NfdauY+ivTANPSlDYKHT44RUwYRSZGpae2HqPTL700tT e6SjrJcV8Tc8k0yjBfg0dJg7XxqNg/c8B5niLwQy1zC70oLVVXFJPSk7SHgYUGDPOd32 HABFgqBdrXfPj4brOp9AFZOQnpof9p17VA9TftqbcDdv5gnIurF2zwf4/eIn+PAeb+Ez YMGwQyH80lLb4iGPxcEaayw2gJfcXWgeTFee1dwOzlJ9l+2iP+CadJ++/PAIMG+xWHPJ +L8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NyWwrUJu; 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 s3-20020a05620a080300b0076810112e5csi7028340qks.112.2023.08.15.07.52.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Aug 2023 07:52:58 -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=NyWwrUJu; 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 1qVvOw-0006A8-18; Tue, 15 Aug 2023 10:52:07 -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 1qVvOf-0005uW-0l for qemu-devel@nongnu.org; Tue, 15 Aug 2023 10:51:49 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qVvOP-0006HM-TH for qemu-devel@nongnu.org; Tue, 15 Aug 2023 10:51:48 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-317716a4622so4849034f8f.1 for ; Tue, 15 Aug 2023 07:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692111091; x=1692715891; 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=UnhFXoZukvu0YTKINuH5NG1+Wifue15VPIsTSt2x950=; b=NyWwrUJuXI47oT1v3vectwWeFS1dHpFy7c+RG+EoyQUAaGP2yyIrjBN35TY1+9xjA9 azgh/Y082aH5ogcj7sL7wlapH3IrqyzmijpMNTt7k4UQiAo/DhJMKsf20eIrcy7fgUXt lXZV7MR0UsvL/HyZafZB/UYX17DCe1CCX9EfbQ0Mka2Kelz3LWXuXL0EHuPvsMJqqb50 YdMJYJwc0Txiw096WepY7ICdoxZf8VvVlJBKq1bcg0LIh3UYMPXjw1fAMl5HlHEC4yTN xAPT1D2Wc1Nnji3jwUjl3fLgcgN87tZbDT25eHgBUtaVxJwzS5TeduFzAi4uCiA0LrG7 Wpvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692111091; x=1692715891; 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=UnhFXoZukvu0YTKINuH5NG1+Wifue15VPIsTSt2x950=; b=QpqSNeGU8elYJmKNVB7PfSKKd0M0uQbnGT1nOhM3lw58raZK81t+vZvUGoLzSP4F8L s4H6u3Rfiohb3VADdMd8PPeZLzO//06n8pPC6QBdoSog91U5KSMNARxSYZ75wicquIKc H788ss+7hYGtiyeEQPR33WLZzJDcKeyhx2YEjY6Zz8iNVi4gXvZPF27d4bvyMe0ljMXM euk2MHJBLRkYRAulQmGSiDfzmgrROksBWAwduLDYXo/c02wf1fPZl8bFSxQRxIf7zO6i IXMFI4aoq8vH024Un7arSQrmF7LFYtyXiiEidFZBdQnzoI7l+6IoF0inmBHkXT2lLNCx mYQA== X-Gm-Message-State: AOJu0Yywz/jYye51lPUNSzRaSSP0EwNGjrFTg52gAHVVgYZy28xMgrjg cGw+Hd5W5yS4rXyrmCXvqKYJJA== X-Received: by 2002:adf:e685:0:b0:317:6a7c:6e07 with SMTP id r5-20020adfe685000000b003176a7c6e07mr9683309wrm.32.1692111091141; Tue, 15 Aug 2023 07:51:31 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id j8-20020a5d4528000000b0031779a6b451sm18191537wra.83.2023.08.15.07.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 07:51:29 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id EE8A71FFC3; Tue, 15 Aug 2023 15:51:27 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Beraldo Leal , Wainer dos Santos Moschetta , Peter Maydell , Akihiko Odaki , Thomas Huth , David Hildenbrand , Yonggang Luo , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, Daniel Henrique Barboza , David Gibson , Greg Kurz , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Richard Henderson , qemu-s390x@nongnu.org, Ilya Leoshkevich , qemu-ppc@nongnu.org, =?utf-8?q?Philip?= =?utf-8?q?pe_Mathieu-Daud=C3=A9?= , Nicholas Piggin Subject: [PATCH 9/9] gdbstub: replace global gdb_has_xml with a function Date: Tue, 15 Aug 2023 15:51:26 +0100 Message-Id: <20230815145126.3444183-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815145126.3444183-1-alex.bennee@linaro.org> References: <20230815145126.3444183-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.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 Try and make the self reported global hack a little less hackish by providing a query function instead. As gdb_has_xml was always set if we negotiated XML we can now use the presence of ->target_xml as the test instead. Signed-off-by: Alex Bennée --- gdbstub/internals.h | 1 + include/exec/gdbstub.h | 10 +++++----- gdbstub/gdbstub.c | 12 +++++++----- gdbstub/softmmu.c | 1 - gdbstub/user.c | 1 - target/arm/gdbstub.c | 8 ++++---- target/ppc/gdbstub.c | 4 ++-- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 4876ebd74f..fee243081f 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -33,6 +33,7 @@ typedef struct GDBProcess { uint32_t pid; bool attached; + /* If gdb sends qXfer:features:read:target.xml this will be populated */ char *target_xml; } GDBProcess; diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 7d743fe1e9..0ee39cfdd1 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -31,12 +31,12 @@ int gdbserver_start(const char *port_or_device); void gdb_set_stop_cpu(CPUState *cpu); /** - * gdb_has_xml: - * This is an ugly hack to cope with both new and old gdb. - * If gdb sends qXfer:features:read then assume we're talking to a newish - * gdb that understands target descriptions. + * gdb_has_xml() - report of gdb supports modern target descriptions + * + * This will report true if the gdb negotiated qXfer:features:read + * target descriptions. */ -extern bool gdb_has_xml; +bool gdb_has_xml(void); /* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */ extern const char *const xml_builtin[][2]; diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 0f9032d793..88a4b6a06b 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -75,8 +75,6 @@ void gdb_init_gdbserver_state(void) gdbserver_state.sstep_flags &= gdbserver_state.supported_sstep_flags; } -bool gdb_has_xml; - /* writes 2*len+1 bytes in buf */ void gdb_memtohex(GString *buf, const uint8_t *mem, int len) { @@ -351,6 +349,11 @@ static CPUState *gdb_get_cpu(uint32_t pid, uint32_t tid) } } +bool gdb_has_xml(void) +{ + return !!gdb_get_cpu_process(gdbserver_state.g_cpu)->target_xml; +} + static const char *get_feature_xml(const char *p, const char **newp, GDBProcess *process) { @@ -1079,7 +1082,7 @@ static void handle_set_reg(GArray *params, void *user_ctx) { int reg_size; - if (!gdb_has_xml) { + if (!gdb_get_cpu_process(gdbserver_state.g_cpu)->target_xml) { gdb_put_packet(""); return; } @@ -1100,7 +1103,7 @@ static void handle_get_reg(GArray *params, void *user_ctx) { int reg_size; - if (!gdb_has_xml) { + if (!gdb_get_cpu_process(gdbserver_state.g_cpu)->target_xml) { gdb_put_packet(""); return; } @@ -1567,7 +1570,6 @@ static void handle_query_xfer_features(GArray *params, void *user_ctx) return; } - gdb_has_xml = true; p = get_param(params, 0)->data; xml = get_feature_xml(p, &p, process); if (!xml) { diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index f509b7285d..9f0b8b5497 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -97,7 +97,6 @@ static void gdb_chr_event(void *opaque, QEMUChrEvent event) vm_stop(RUN_STATE_PAUSED); replay_gdb_attached(); - gdb_has_xml = false; break; default: break; diff --git a/gdbstub/user.c b/gdbstub/user.c index 5b375be1d9..7ab6e5d975 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -198,7 +198,6 @@ static void gdb_accept_init(int fd) gdbserver_state.c_cpu = gdb_first_attached_cpu(); gdbserver_state.g_cpu = gdbserver_state.c_cpu; gdbserver_user_state.fd = fd; - gdb_has_xml = false; } static bool gdb_accept_socket(int gdb_fd) diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index f421c5d041..8fc8351df7 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -48,7 +48,7 @@ int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) } if (n < 24) { /* FPA registers. */ - if (gdb_has_xml) { + if (gdb_has_xml()) { return 0; } return gdb_get_zeroes(mem_buf, 12); @@ -56,7 +56,7 @@ int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) switch (n) { case 24: /* FPA status register. */ - if (gdb_has_xml) { + if (gdb_has_xml()) { return 0; } return gdb_get_reg32(mem_buf, 0); @@ -102,7 +102,7 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) } if (n < 24) { /* 16-23 */ /* FPA registers (ignored). */ - if (gdb_has_xml) { + if (gdb_has_xml()) { return 0; } return 12; @@ -110,7 +110,7 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) switch (n) { case 24: /* FPA status register (ignored). */ - if (gdb_has_xml) { + if (gdb_has_xml()) { return 0; } return 4; diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index ca39efdc35..2ad11510bf 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -56,7 +56,7 @@ static int ppc_gdb_register_len(int n) return sizeof(target_ulong); case 32 ... 63: /* fprs */ - if (gdb_has_xml) { + if (gdb_has_xml()) { return 0; } return 8; @@ -76,7 +76,7 @@ static int ppc_gdb_register_len(int n) return sizeof(target_ulong); case 70: /* fpscr */ - if (gdb_has_xml) { + if (gdb_has_xml()) { return 0; } return sizeof(target_ulong);