From patchwork Wed Aug 16 13:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821813 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=Y4Z3JSLb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq8n5HzTz1yNr for ; Wed, 16 Aug 2023 23:43:21 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGlW-0004p7-A2; Wed, 16 Aug 2023 09:40:50 -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 1qWGlK-0004ib-Vh for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:40 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGlF-0000ga-ED for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:38 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68871bbfe33so1148193b3a.0 for ; Wed, 16 Aug 2023 06:40:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193219; x=1692798019; 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=nZll0H6CXaAKys7cBNNrlAZQAX9ewDlJMrzDsStORGc=; b=Y4Z3JSLbbqp6hcAm2g65/9NPsKe+m5HP5VKCqWSvbY/ILGUWUrwDCcyAJnEXpW/X2E Vm7PQ66C34wKVMqRTr+wBcFKMvDgGkkZbOPgLrPNT+RWdIqrgqV0/wdowOSRjQuLH93s tpFgNBJBYW7XCVjdxSsYRLWDyDrjq804ox7Ghbg3GwOa9o+rhgvukqhyoF7AVyv8k+/m pA4rGVOYxZegGiavhU6F9cNzPdL6vH+FNK4iXBXcVm0A/LsoZ/wju97U8t6FXNU6QNQg sR1mjzJanLGKi0yGKcv7k06zES/gRCJMxEBqsTTbhH/sryAzFhWe9wrjoMonriw49Aun besw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193219; x=1692798019; 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=nZll0H6CXaAKys7cBNNrlAZQAX9ewDlJMrzDsStORGc=; b=X1W5m+G5HcIvtAFDiDxwqORGxAEvdkqcqbePlNHl4thLUqLG2GvUn0+bQqjIKB11iP mDS1d8dVhi8lRRkcH5FQCqSAXzJb7dPa8raa30C+5IacwKXg7/ucOxBZCTVptCSkpFpw ESFWtpwBKPlypEK4VeU0S5EdeErSXcjcxP3GocIqs5QlAvLpwpuZWmhvPN69aOkh/j0L kK1ZufL62YInoG9+RsDXEU6et9yjaTm4aVLeJm8Qc3zy9JcHQtURVtVRtlrP1dPn4EXc RAPgcoGzkAPd31/KhRQLJKG8BJ2ThNoxLWv+dK51Xw5lUyIzpZqmJvfCnxRTCIIIUXvj N8YQ== X-Gm-Message-State: AOJu0Yyh7313qHQuILnD/noPgA6JFCdZVp+MqKGXjfdl5tcI/hDwj7Gs tS5dhpfZqVvN25om9B8zqCSlfw== X-Google-Smtp-Source: AGHT+IH2Qr0VtfkmLBVF4SUA4/1JXblF7+YhrxctQPDO4368U0x1iYdOjTpgRfUqhAp2aGWIa5/0Qg== X-Received: by 2002:a05:6a21:3d86:b0:131:5995:340 with SMTP id bj6-20020a056a213d8600b0013159950340mr1857560pzc.20.1692193218657; Wed, 16 Aug 2023 06:40:18 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:40:18 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 01/25] contrib/plugins: Use GRWLock in execlog Date: Wed, 16 Aug 2023 22:39:11 +0900 Message-ID: <20230816133938.18310-2-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42f.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org execlog had the following comment: > As we could have multiple threads trying to do this we need to > serialise the expansion under a lock. Threads accessing already > created entries can continue without issue even if the ptr array > gets reallocated during resize. However, when the ptr array gets reallocated, the other threads may have a stale reference to the old buffer. This results in use-after-free. Use GRWLock to properly fix this issue. Fixes: 3d7caf145e ("contrib/plugins: add execlog to log instruction execution and memory access") Signed-off-by: Akihiko Odaki Reviewed-by: Alex Bennée --- contrib/plugins/execlog.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c index 7129d526f8..ce67acf145 100644 --- a/contrib/plugins/execlog.c +++ b/contrib/plugins/execlog.c @@ -19,7 +19,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; /* Store last executed instruction on each vCPU as a GString */ static GPtrArray *last_exec; -static GMutex expand_array_lock; +static GRWLock expand_array_lock; static GPtrArray *imatches; static GArray *amatches; @@ -28,18 +28,16 @@ static GArray *amatches; * Expand last_exec array. * * As we could have multiple threads trying to do this we need to - * serialise the expansion under a lock. Threads accessing already - * created entries can continue without issue even if the ptr array - * gets reallocated during resize. + * serialise the expansion under a lock. */ static void expand_last_exec(int cpu_index) { - g_mutex_lock(&expand_array_lock); + g_rw_lock_writer_unlock(&expand_array_lock); while (cpu_index >= last_exec->len) { GString *s = g_string_new(NULL); g_ptr_array_add(last_exec, s); } - g_mutex_unlock(&expand_array_lock); + g_rw_lock_writer_unlock(&expand_array_lock); } /** @@ -51,8 +49,10 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info, GString *s; /* Find vCPU in array */ + g_rw_lock_reader_lock(&expand_array_lock); g_assert(cpu_index < last_exec->len); s = g_ptr_array_index(last_exec, cpu_index); + g_rw_lock_reader_unlock(&expand_array_lock); /* Indicate type of memory access */ if (qemu_plugin_mem_is_store(info)) { @@ -80,10 +80,14 @@ static void vcpu_insn_exec(unsigned int cpu_index, void *udata) GString *s; /* Find or create vCPU in array */ + g_rw_lock_reader_lock(&expand_array_lock); if (cpu_index >= last_exec->len) { + g_rw_lock_reader_unlock(&expand_array_lock); expand_last_exec(cpu_index); + g_rw_lock_reader_lock(&expand_array_lock); } s = g_ptr_array_index(last_exec, cpu_index); + g_rw_lock_reader_unlock(&expand_array_lock); /* Print previous instruction in cache */ if (s->len) { From patchwork Wed Aug 16 13:39:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=lWcfeNWS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqDB2Pm9z1yNm for ; Wed, 16 Aug 2023 23:46:18 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGlW-0004p4-6R; Wed, 16 Aug 2023 09:40:50 -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 1qWGlM-0004ij-O5 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:42 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGlF-0000u9-CL for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:38 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-688769faa09so1036440b3a.2 for ; Wed, 16 Aug 2023 06:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193228; x=1692798028; 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=vSruWoyKlAWxyFcMWhzZ8sPLB2mqbg+J6UjZbva0yr8=; b=lWcfeNWSrilioV4K6gVit7/JTo4Khtsb5o+k6wAWxbYrbpaMosJuNUmrvyqzDwcEI5 VgqCHcafMzAb/A5VzYfAvshcflKOdfp/EDj9Ye/HdX90mPQ23vO3Zxa/iIM08Gi2n0e6 /OQYvKwkSAE9zz0Wx6mU+iG+NOB6DtXM/K7bOKZwQMthViV4uceTHZKUsJ9RulnkiOcq n4gMOs6l9HtfevCwPCEIesSbg614X0nkv4TlQIUGlZr82KdESdvKYD1aK5EO6sqBG5Xo gHxFztB9AhDjnbxHkVfW7j6hK/1Zp3bTKe123XSzJ9BUP5Opxkqf45o5jO0xkSChLgvL pOTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193228; x=1692798028; 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=vSruWoyKlAWxyFcMWhzZ8sPLB2mqbg+J6UjZbva0yr8=; b=cSA9lyMK+He8ICQpwqFYWEZtAlTpuvpQEF93mJSTrh2VZUv83bld5UYMEgNP+A3MkD u82YBmPWdyp3RiuUMD1c3Vd+iEiFsB8VwFS6AJmVTsQJBf+Q+VWCTelrEbRCV1m4BtuL AXwxWvVIOrD5Gt6MqCaZO/pdsgnAwIUaTV0pjL9iWmsKwfBUrltpSwCGVES+2mdkwXPk 2t1lueaISSdhX3yHUusOJ8WkRv8RBEBbdyAHZ/DtP/bCMC1WN+Ra36qCiwtcyWV+j/0e 9G7xoygiK73D7oNy9Cc0Gu4qLhF8OjCDpSEKthxqGEGXaVAKz9d3AbAHNSw2/LKWOeJ1 C0dg== X-Gm-Message-State: AOJu0YzGUzCtH00L7pWarh5f1XqdXQBufXgWhHl0/fY+DXJaHljKPQb2 A1t1g7uysHwX81Egjy3TQ4sptQ== X-Google-Smtp-Source: AGHT+IHAxYSdSjQWaGmfG9c0nFiZZfUmg2yI3S0ZsR/2ei02wINQceyfl6kmnA3FV7lgzOHG9mRCkA== X-Received: by 2002:a05:6a00:17a2:b0:667:85e6:4e9 with SMTP id s34-20020a056a0017a200b0066785e604e9mr2033162pfg.24.1692193228050; Wed, 16 Aug 2023 06:40:28 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:40:27 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 02/25] gdbstub: Introduce GDBFeature structure Date: Wed, 16 Aug 2023 22:39:12 +0900 Message-ID: <20230816133938.18310-3-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::435; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x435.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Before this change, the information from a XML file was stored in an array that is not descriptive. Introduce a dedicated structure type to make it easier to understand and to extend with more fields. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- MAINTAINERS | 2 +- meson.build | 2 +- include/exec/gdbstub.h | 9 ++++-- gdbstub/gdbstub.c | 4 +-- stubs/gdbstub.c | 6 ++-- scripts/feature_to_c.py | 48 ++++++++++++++++++++++++++++ scripts/feature_to_c.sh | 69 ----------------------------------------- 7 files changed, 62 insertions(+), 78 deletions(-) create mode 100755 scripts/feature_to_c.py delete mode 100644 scripts/feature_to_c.sh diff --git a/MAINTAINERS b/MAINTAINERS index 12e59b6b27..514ac74101 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2826,7 +2826,7 @@ F: include/exec/gdbstub.h F: include/gdbstub/* F: gdb-xml/ F: tests/tcg/multiarch/gdbstub/ -F: scripts/feature_to_c.sh +F: scripts/feature_to_c.py F: scripts/probe-gdb-support.py Memory API diff --git a/meson.build b/meson.build index 98e68ef0b1..5c633f7e01 100644 --- a/meson.build +++ b/meson.build @@ -3683,7 +3683,7 @@ common_all = static_library('common', dependencies: common_all.dependencies(), name_suffix: 'fa') -feature_to_c = find_program('scripts/feature_to_c.sh') +feature_to_c = find_program('scripts/feature_to_c.py') if targetos == 'darwin' entitlement = find_program('scripts/entitlement.sh') diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 7d743fe1e9..3f08093321 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -10,6 +10,11 @@ #define GDB_WATCHPOINT_READ 3 #define GDB_WATCHPOINT_ACCESS 4 +typedef struct GDBFeature { + const char *xmlname; + const char *xml; +} GDBFeature; + /* Get or set a register. Returns the size of the register. */ typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg); @@ -38,7 +43,7 @@ void gdb_set_stop_cpu(CPUState *cpu); */ extern bool gdb_has_xml; -/* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */ -extern const char *const xml_builtin[][2]; +/* in gdbstub-xml.c, generated by scripts/feature_to_c.py */ +extern const GDBFeature gdb_static_features[]; #endif diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 6911b73c07..2772f07bbe 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -407,11 +407,11 @@ static const char *get_feature_xml(const char *p, const char **newp, } } for (i = 0; ; i++) { - name = xml_builtin[i][0]; + name = gdb_static_features[i].xmlname; if (!name || (strncmp(name, p, len) == 0 && strlen(name) == len)) break; } - return name ? xml_builtin[i][1] : NULL; + return name ? gdb_static_features[i].xml : NULL; } static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) diff --git a/stubs/gdbstub.c b/stubs/gdbstub.c index 2b7aee50d3..580e20702b 100644 --- a/stubs/gdbstub.c +++ b/stubs/gdbstub.c @@ -1,6 +1,6 @@ #include "qemu/osdep.h" -#include "exec/gdbstub.h" /* xml_builtin */ +#include "exec/gdbstub.h" /* gdb_static_features */ -const char *const xml_builtin[][2] = { - { NULL, NULL } +const GDBFeature gdb_static_features[] = { + { NULL } }; diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py new file mode 100755 index 0000000000..bcbcb83beb --- /dev/null +++ b/scripts/feature_to_c.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later + +import os, sys + +def writeliteral(indent, bytes): + sys.stdout.write(' ' * indent) + sys.stdout.write('"') + quoted = True + + for c in bytes: + if not quoted: + sys.stdout.write('\n') + sys.stdout.write(' ' * indent) + sys.stdout.write('"') + quoted = True + + if c == b'"'[0]: + sys.stdout.write('\\"') + elif c == b'\\'[0]: + sys.stdout.write('\\\\') + elif c == b'\n'[0]: + sys.stdout.write('\\n"') + quoted = False + elif c >= 32 and c < 127: + sys.stdout.write(c.to_bytes(1, 'big').decode()) + else: + sys.stdout.write(f'\{c:03o}') + + if quoted: + sys.stdout.write('"') + +sys.stdout.write('#include "qemu/osdep.h"\n' \ + '#include "exec/gdbstub.h"\n' \ + '\n' + 'const GDBFeature gdb_static_features[] = {\n') + +for input in sys.argv[1:]: + with open(input, 'rb') as file: + read = file.read() + + sys.stdout.write(' {\n') + writeliteral(8, bytes(os.path.basename(input), 'utf-8')) + sys.stdout.write(',\n') + writeliteral(8, read) + sys.stdout.write('\n },\n') + +sys.stdout.write(' { NULL }\n};\n') diff --git a/scripts/feature_to_c.sh b/scripts/feature_to_c.sh deleted file mode 100644 index c1f67c8f6a..0000000000 --- a/scripts/feature_to_c.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh - -# Convert text files to compilable C arrays. -# -# Copyright (C) 2007 Free Software Foundation, Inc. -# -# This file is part of GDB. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see . - -if test -z "$1"; then - echo "Usage: $0 INPUTFILE..." - exit 1 -fi - -for input; do - arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g') - - ${AWK:-awk} 'BEGIN { n = 0 - printf "#include \"qemu/osdep.h\"\n" - print "static const char '$arrayname'[] = {" - for (i = 0; i < 255; i++) - _ord_[sprintf("%c", i)] = i - } { - split($0, line, ""); - printf " " - for (i = 1; i <= length($0); i++) { - c = line[i] - if (c == "'\''") { - printf "'\''\\'\'''\'', " - } else if (c == "\\") { - printf "'\''\\\\'\'', " - } else if (_ord_[c] >= 32 && _ord_[c] < 127) { - printf "'\''%s'\'', ", c - } else { - printf "'\''\\%03o'\'', ", _ord_[c] - } - if (i % 10 == 0) - printf "\n " - } - printf "'\''\\n'\'', \n" - } END { - print " 0 };" - }' < $input -done - -echo -echo '#include "exec/gdbstub.h"' -echo "const char *const xml_builtin[][2] = {" - -for input; do - basename=$(echo $input | sed 's,.*/,,') - arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g') - echo " { \"$basename\", $arrayname }," -done - -echo " { (char *)0, (char *)0 }" -echo "};" From patchwork Wed Aug 16 13:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=gY0LUUSG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq7y4f6mz1yNr for ; Wed, 16 Aug 2023 23:42:38 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGlX-0004rY-OU; Wed, 16 Aug 2023 09:40:51 -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 1qWGlR-0004ko-Sg for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:46 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGlM-0000wj-GE for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:43 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6887c3aac15so712657b3a.2 for ; Wed, 16 Aug 2023 06:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193237; x=1692798037; 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=lqwUBKCsJIu6Kok3irpDq8wqJUl9JGbLYq58wXaDnQ0=; b=gY0LUUSGh878mt5smGpgdgYPFPElzs8fVItt6x0bjxRUXamcfrVdISPRs+l6xc1eAt 5wxxyS1JafsvBcTGdyURyNNrrNAqCPp7ePjIlJQ3S0IT7ewQlujAh3j6BBb5s7slL/C3 ztpXYLMLVROiVP50cFrlZ8X/yAu16JkngzSsJluxf95vab2p6j1StAjKIu6dAT3MJg1T nDrpXdCBv7Sso71eVinNEEF2/RCXyJTRvl6t79k4L/4gLP39l9Z9IuAoKUh5k4Hs26/P GF4l0xuMK5zKJV2xmq7wP17TnI4x+NcCz7kntgHQq3KFJsKDRmwu0nKumMMzX/BlbRKd DB9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193237; x=1692798037; 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=lqwUBKCsJIu6Kok3irpDq8wqJUl9JGbLYq58wXaDnQ0=; b=OiSu0EtpOLY8+QTjnDg4bMBXq391VJJfrNQeFaqbzw9v4GI0vbOCMo2dLxnIBjF+z4 NdcfXwMEmwTejn4Vt8flbnKAfNtg0mzJOCn+LLQlfhEKaC/VXNxEdxRYwgUf/BYivOSt KtSbDuS3/yPkAvc09Sl1QSD3L6zVW0iN35MIL/fpppwLaN6uIoC0JyNrxMoLehxaZHyI /ccfWog1ZcYMAMXBkd4dBlCgsys1aBck+C/I45bYxF4VEvmWIjs4frDFnrIiBxEcs5yW KFN7HZd4Ngg1N9Kw12NAnWhSr6D6+API0PofAOZ1wI5lgFvrSTVYEgJET/cwPiQ+FVJn VMbg== X-Gm-Message-State: AOJu0Yx/S8yyX+2TzApMuS3i3EzJ1r7OvfRfGcQ6yz9SFWJyw9xEkO2a 2mLojxeUVlAXkUPPxM4i5Aceow== X-Google-Smtp-Source: AGHT+IEykPySooFxFAxt3OcAgaH+Rek1l5Fkz+ca6srVwpZib+NnSN+yTrTByAjkHjNExY23hbCkBg== X-Received: by 2002:a05:6a20:748b:b0:140:a6ec:b55d with SMTP id p11-20020a056a20748b00b00140a6ecb55dmr2814715pzd.15.1692193237642; Wed, 16 Aug 2023 06:40:37 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:40:37 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 03/25] gdbstub: Add num_regs member to GDBFeature Date: Wed, 16 Aug 2023 22:39:13 +0900 Message-ID: <20230816133938.18310-4-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::436; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x436.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently the number of registers exposed to GDB is written as magic numbers in code. Derive the number of registers GDB actually see from XML files to replace the magic numbers in code later. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- include/exec/gdbstub.h | 1 + scripts/feature_to_c.py | 46 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 3f08093321..9b484d7eef 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -13,6 +13,7 @@ typedef struct GDBFeature { const char *xmlname; const char *xml; + int num_regs; } GDBFeature; diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py index bcbcb83beb..e04d6b2df7 100755 --- a/scripts/feature_to_c.py +++ b/scripts/feature_to_c.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-or-later -import os, sys +import os, sys, xml.etree.ElementTree def writeliteral(indent, bytes): sys.stdout.write(' ' * indent) @@ -39,10 +39,52 @@ def writeliteral(indent, bytes): with open(input, 'rb') as file: read = file.read() + parser = xml.etree.ElementTree.XMLPullParser(['start', 'end']) + parser.feed(read) + events = parser.read_events() + event, element = next(events) + if event != 'start': + sys.stderr.write(f'unexpected event: {event}\n') + exit(1) + if element.tag != 'feature': + sys.stderr.write(f'unexpected start tag: {element.tag}\n') + exit(1) + + regnum = 0 + regnums = [] + tags = ['feature'] + for event, element in events: + if event == 'end': + if element.tag != tags[len(tags) - 1]: + sys.stderr.write(f'unexpected end tag: {element.tag}\n') + exit(1) + + tags.pop() + if element.tag == 'feature': + break + elif event == 'start': + if len(tags) < 2 and element.tag == 'reg': + if 'regnum' in element.attrib: + regnum = int(element.attrib['regnum']) + + regnums.append(regnum) + regnum += 1 + + tags.append(element.tag) + else: + raise Exception(f'unexpected event: {event}\n') + + if len(tags): + sys.stderr.write('unterminated feature tag\n') + exit(1) + + base_reg = min(regnums) + num_regs = max(regnums) - base_reg + 1 if len(regnums) else 0 + sys.stdout.write(' {\n') writeliteral(8, bytes(os.path.basename(input), 'utf-8')) sys.stdout.write(',\n') writeliteral(8, read) - sys.stdout.write('\n },\n') + sys.stdout.write(f',\n {num_regs},\n }},\n') sys.stdout.write(' { NULL }\n};\n') From patchwork Wed Aug 16 13:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=vwCKtoyf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqHx1p3Pz1yNm for ; Wed, 16 Aug 2023 23:49:33 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGlZ-0004sV-1C; Wed, 16 Aug 2023 09:40: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 1qWGlX-0004r8-HZ for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:51 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGlU-0000zn-BP for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:51 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-688142a392eso5215368b3a.3 for ; Wed, 16 Aug 2023 06:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193247; x=1692798047; 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=Q7pUOq6IPFvx1k2W2dQWmkO3YzfVeoPk1QwhHtWlA7g=; b=vwCKtoyfrrk42/4HH+3+hSvBoqmzUBm5MLSxVppI2oq2egx0NnB9Vs4S7e+YN1dZZF 2JkO4VguFG0rI04pEkZzQR/GWxBEFdNpY/tjO7CmFIWOFQY7Hw2ABL5oP9iHS1ZV0ARG MQkx05gDzEyY0XHiSQrpE1fgdyw9En/Vzb0/VCZX9kmy7i1AUJR46tNu3GTpXAz2/l/c yIG96kA5Jv2MSkm04324GUE3uFsxejmO/QlNfFJH2wmUpb9jjJjB25sbZRThglVzM06r TLUWu6Ypt7hDdQLDxAE6mbOqo1TRqnX0TfObSg1qXSmGwFXZdswGyUY9b7+sid03ndMO BXrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193247; x=1692798047; 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=Q7pUOq6IPFvx1k2W2dQWmkO3YzfVeoPk1QwhHtWlA7g=; b=PM9+Ra+nUYbSRzFlGD+5NuzjpeV+XGGsAMig/2yZLPY0eBs+jQFLxYF8OiijsLBAcm uY/EzyHyDZMtvn/qaMOSVic9IkXgep7G+HVAj/Fbxy2d+ADjALLFe/cArvGu7O9SPXDW 2/Ew2xKDcJcS7wSDTi6FGTAJVzrp0uIsENYUibE9EiCig/E8Gc2vdK79NvoFe0SJpuEu CIlpwf76K6ky+PGaHQh3SPgPMKXIiHiMe3z6KRDYDCviqUHO3KPn6DCkguJL11SwbAEV lJTJ/GAQ7tka8d+ENIr8cwnfZc2j6+N35VI5Rb2+pvKo+5GQKIMu7mW63rm3aZn6wVXf 5OuA== X-Gm-Message-State: AOJu0Ywj0Pslb5uc6C2tH/1U66eb14AYLJEP3rRcKN/npS82d0IzZqon hSnyoU1uG6X+1d7/udpTaXW+aw== X-Google-Smtp-Source: AGHT+IF73ab4ODGSTuDdXiRfCqRWNV8FCLniM5IHFM4TtcBfNVUdVkYCHtTIOwZ/arFkLGT/B3a1yg== X-Received: by 2002:a05:6a20:7f8f:b0:134:8d7f:f4d9 with SMTP id d15-20020a056a207f8f00b001348d7ff4d9mr3116593pzj.52.1692193247152; Wed, 16 Aug 2023 06:40:47 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:40:46 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 04/25] gdbstub: Introduce gdb_find_static_feature() Date: Wed, 16 Aug 2023 22:39:14 +0900 Message-ID: <20230816133938.18310-5-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This function is useful to determine the number of registers exposed to GDB from the XML name. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- include/exec/gdbstub.h | 2 ++ gdbstub/gdbstub.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 9b484d7eef..d0dcc99ed4 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -34,6 +34,8 @@ void gdb_register_coprocessor(CPUState *cpu, */ int gdbserver_start(const char *port_or_device); +const GDBFeature *gdb_find_static_feature(const char *xmlname); + void gdb_set_stop_cpu(CPUState *cpu); /** diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 2772f07bbe..5829e82073 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -414,6 +414,19 @@ static const char *get_feature_xml(const char *p, const char **newp, return name ? gdb_static_features[i].xml : NULL; } +const GDBFeature *gdb_find_static_feature(const char *xmlname) +{ + const GDBFeature *feature; + + for (feature = gdb_static_features; feature->xmlname; feature++) { + if (!strcmp(feature->xmlname, xmlname)) { + return feature; + } + } + + abort(); +} + static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) { CPUClass *cc = CPU_GET_CLASS(cpu); From patchwork Wed Aug 16 13:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821809 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=KB+ZhSsG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq7z57rLz1yXY for ; Wed, 16 Aug 2023 23:42:39 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGli-0004ym-CD; Wed, 16 Aug 2023 09:41:02 -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 1qWGlf-0004xE-UZ for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:59 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGld-00012F-EF for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:40:59 -0400 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3a800814122so2455771b6e.0 for ; Wed, 16 Aug 2023 06:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193256; x=1692798056; 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=Z8QC8ufyB7xcDBCvHI4qa5+GakxSnSbOuWxZo6h21Sw=; b=KB+ZhSsGWWNlUgmIiGVU0IV0uRlGbkE0kmuM4ahSNEAyMhCiiqtQF3EQPd1ytNNqgt 1YbbUWh4AMCoAPRH/+3M1xUlzNZkdTIKph5hITkFWf7cs29YkoAl6T8Eqgu4qPmBLpsU 1mT8L7hRfqPMtAT6usZMQGNnVJ//UJyFjB+AEPBssrQKUlqJ/ADHCBT6V55rafUNUFMW hLz2WgrbB+QDCCuBbXp8Shjog3Qui4Ed04new4IG+CpoflWWLtb8vTEWckf6zWsEDtNo cw/z6sk1enaKaFbGcHE0ZE+bTtaV16MtLS5G3HK52QBFEKUWJfnd4tO8vWYEA8pl44rj +L7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193256; x=1692798056; 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=Z8QC8ufyB7xcDBCvHI4qa5+GakxSnSbOuWxZo6h21Sw=; b=KvlVKmjpUUxRHljGRkJa8x7ajA0yBdOHJ0Ml+4V28xxUN1W64EwP1sYIKZiaSUwi0j OUnHExgIR54VpZ42hDIRfAD3lCE6FPrSmIwPQL9FBlu38tDvoAJx+ODZB+qCZFndstJs TdYGCdLgrAe8J/ldvkXf4vvzpnlj3E79ZOK/psFyy2OUX89AficKPoUbNdvhF1Ug+U6a MECHUB1PeUgCZQVMoJWf9rZ8Jn45fHlQiAgVYT7bTcPkh23DQ+IyWRsUct9VCFSlFOF4 pdyCJ7sjwUi1eMtgM+oxxz9SM8ZMevHMEIOmBo/hXQHwT1Rfi/auoJ5oVe4pPgyG2/yX AXWg== X-Gm-Message-State: AOJu0YyYECviaDNGwVOrGUGZ8co54xCFEkbgBkmNEpYcZ9XOz5u8lExy UVhL4xHYsbu19JpgtnPnsDY0TA== X-Google-Smtp-Source: AGHT+IFTUvui/nl/vsy6zAXPwCT3gqu/lH1t7o2otH3xEHC7Ko4K5o8auN7iMm8kKlAKxvkKSQvHpg== X-Received: by 2002:a05:6808:3c2:b0:3a7:6213:6898 with SMTP id o2-20020a05680803c200b003a762136898mr2007034oie.12.1692193256475; Wed, 16 Aug 2023 06:40:56 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:40:56 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 05/25] target/arm: Move the reference to arm-core.xml Date: Wed, 16 Aug 2023 22:39:15 +0900 Message-ID: <20230816133938.18310-6-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::233; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x233.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Some subclasses overwrite gdb_core_xml_file member but others don't. Always initialize the member in the subclasses for consistency. This especially helps for AArch64; in a following change, the file specified by gdb_core_xml_file is always looked up even if it's going to be overwritten later. Looking up arm-core.xml results in an error as it will not be embedded in the AArch64 build. Signed-off-by: Akihiko Odaki --- target/arm/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 93c28d50e5..d71a162070 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2354,7 +2354,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->sysemu_ops = &arm_sysemu_ops; #endif cc->gdb_num_core_regs = 26; - cc->gdb_core_xml_file = "arm-core.xml"; cc->gdb_arch_name = arm_gdb_arch_name; cc->gdb_get_dynamic_xml = arm_gdb_get_dynamic_xml; cc->gdb_stop_before_watchpoint = true; @@ -2376,8 +2375,10 @@ static void arm_cpu_instance_init(Object *obj) static void cpu_register_class_init(ObjectClass *oc, void *data) { ARMCPUClass *acc = ARM_CPU_CLASS(oc); + CPUClass *cc = CPU_CLASS(acc); acc->info = data; + cc->gdb_core_xml_file = "arm-core.xml"; } void arm_cpu_register(const ARMCPUInfo *info) From patchwork Wed Aug 16 13:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821802 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=MZX0oirT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq7T2NLzz1yXY for ; Wed, 16 Aug 2023 23:42:13 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGlw-0005OC-4Q; Wed, 16 Aug 2023 09:41:16 -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 1qWGlt-0005Ds-Ao for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:13 -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 1qWGln-00014S-00 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:12 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68842ebdcf7so2300643b3a.0 for ; Wed, 16 Aug 2023 06:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193266; x=1692798066; 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=XSHgKYDM5nqqpbfGFDD27ORwPMLsaAwE61VkUu9Q96w=; b=MZX0oirTK8UEhj+fXDd+WmXgdlaxx+7Qkg9NoyeimJkrJmgjq+aM/4zylWHC6SFsPX rWGpleNPfr6xotB+AG9KpoEI5pXAzWA/RgAxz+XucOMDmtcqH0vLbRLnrn5zI/+s4+il Y9YurObar1mGQCd+o7I/AlbqqRdmyJcIXe5L7JMcH7m1CcqCP8mN/AzmLZ5ikgrk3Fw+ 3Xdk+No6C/OSqIHUSCCHd+53xWFYie5zBkD7xFJcxOAs4Olqg1tBbg2WmqYbOWXgNaAJ OfP1t37s/Mc9YB0xMYtTD8Qc3hLx/XN7yekLUGEO7cfQRkAdqEvfSlMrjdtzSiOl4rUV uT2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193266; x=1692798066; 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=XSHgKYDM5nqqpbfGFDD27ORwPMLsaAwE61VkUu9Q96w=; b=Db1/6Gp/h1aWbvMMnP3xUrcQ+yIhg+q8KNwBaXMmXfHLjv+cAnTSykBY1+v3nlD28E CuweCbqDuBtV8RYbGw32OXoYDm9o3D4kDdEm7c0QUaHZMrPNvBo+f/9VHDVOaceFhkne keY9CckS2V9bJgoKAVVwCYHvQLm6xKq0e1uAe7+VX9GNSkd2eoYUmUCuInSh9Ed7FCNb ZOpaXBeGB1F9xD+ZIvabDL0SsL0Ie5jrIZlz12LgFhkyTOOoqIhLZY8GdsJ/wGSf/DHs 8j9huyS8zNUudwualqNuitBqWDR3WFuLtVUO4905h9/9Z95A9DQnREmOdE1rzcfuqZZw 07yg== X-Gm-Message-State: AOJu0YxMG9P0oyvGpiG8zBeTIOHS+uyAV9lhF0Q+JmfwFRbxCM8ThbZq 95rKk/cwj1P0CzQ0TEjnsH/k0Q== X-Google-Smtp-Source: AGHT+IE1nFVd0GzP9rGhym2nHZILGCwlM+EZ/d3LwT7SlK/PD3i+UlMqTIVuE0RVqnp7E5ugRYpnHQ== X-Received: by 2002:a05:6a20:7f93:b0:13e:427e:ff18 with SMTP id d19-20020a056a207f9300b0013e427eff18mr2567225pzj.62.1692193265760; Wed, 16 Aug 2023 06:41:05 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:41:05 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 06/25] hw/core/cpu: Replace gdb_core_xml_file with gdb_core_feature Date: Wed, 16 Aug 2023 22:39:16 +0900 Message-ID: <20230816133938.18310-7-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is a tree-wide change to replace gdb_core_xml_file, the path to GDB XML file with gdb_core_feature, the pointer to GDBFeature. This also replaces the values assigned to gdb_num_core_regs with the num_regs member of GDBFeature where applicable to remove magic numbers. A following change will utilize additional information provided by GDBFeature to simplify XML file lookup. Signed-off-by: Akihiko Odaki --- include/hw/core/cpu.h | 5 +++-- target/s390x/cpu.h | 2 -- gdbstub/gdbstub.c | 6 +++--- target/arm/cpu.c | 4 ++-- target/arm/cpu64.c | 4 ++-- target/arm/tcg/cpu32.c | 3 ++- target/avr/cpu.c | 4 ++-- target/hexagon/cpu.c | 2 +- target/i386/cpu.c | 7 +++---- target/loongarch/cpu.c | 4 ++-- target/m68k/cpu.c | 7 ++++--- target/microblaze/cpu.c | 4 ++-- target/ppc/cpu_init.c | 4 ++-- target/riscv/cpu.c | 7 ++++--- target/rx/cpu.c | 4 ++-- target/s390x/cpu.c | 4 ++-- 16 files changed, 36 insertions(+), 35 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index fdcbe87352..84219c1885 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -23,6 +23,7 @@ #include "hw/qdev-core.h" #include "disas/dis-asm.h" #include "exec/cpu-common.h" +#include "exec/gdbstub.h" #include "exec/hwaddr.h" #include "exec/memattrs.h" #include "qapi/qapi-types-run-state.h" @@ -127,7 +128,7 @@ struct SysemuCPUOps; * breakpoint. Used by AVR to handle a gdb mis-feature with * its Harvard architecture split code and data. * @gdb_num_core_regs: Number of core registers accessible to GDB. - * @gdb_core_xml_file: File name for core registers GDB XML description. + * @gdb_core_feature: GDB core feature description. * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop * before the insn which triggers a watchpoint rather than after it. * @gdb_arch_name: Optional callback that returns the architecture name known @@ -163,7 +164,7 @@ struct CPUClass { int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg); vaddr (*gdb_adjust_breakpoint)(CPUState *cpu, vaddr addr); - const char *gdb_core_xml_file; + const GDBFeature *gdb_core_feature; gchar * (*gdb_arch_name)(CPUState *cpu); const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname); diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index eb5b65b7d3..c5bac3230c 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -451,8 +451,6 @@ static inline void cpu_get_tb_cpu_state(CPUS390XState *env, vaddr *pc, #define S390_R13_REGNUM 15 #define S390_R14_REGNUM 16 #define S390_R15_REGNUM 17 -/* Total Core Registers. */ -#define S390_NUM_CORE_REGS 18 static inline void setcc(S390CPU *cpu, uint64_t cc) { diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 5829e82073..293e8ea439 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -386,7 +386,7 @@ static const char *get_feature_xml(const char *p, const char **newp, g_free(arch); } pstrcat(buf, buf_sz, "gdb_core_xml_file); + pstrcat(buf, buf_sz, cc->gdb_core_feature->xmlname); pstrcat(buf, buf_sz, "\"/>"); for (r = cpu->gdb_regs; r; r = r->next) { pstrcat(buf, buf_sz, "gdb_core_xml_file) { + if (cc->gdb_core_feature) { g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+"); } @@ -1548,7 +1548,7 @@ static void handle_query_xfer_features(GArray *params, void *user_ctx) process = gdb_get_cpu_process(gdbserver_state.g_cpu); cc = CPU_GET_CLASS(gdbserver_state.g_cpu); - if (!cc->gdb_core_xml_file) { + if (!cc->gdb_core_feature) { gdb_put_packet(""); return; } diff --git a/target/arm/cpu.c b/target/arm/cpu.c index d71a162070..a206ab6b1b 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2353,7 +2353,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) #ifndef CONFIG_USER_ONLY cc->sysemu_ops = &arm_sysemu_ops; #endif - cc->gdb_num_core_regs = 26; cc->gdb_arch_name = arm_gdb_arch_name; cc->gdb_get_dynamic_xml = arm_gdb_get_dynamic_xml; cc->gdb_stop_before_watchpoint = true; @@ -2378,7 +2377,8 @@ static void cpu_register_class_init(ObjectClass *oc, void *data) CPUClass *cc = CPU_CLASS(acc); acc->info = data; - cc->gdb_core_xml_file = "arm-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("arm-core.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; } void arm_cpu_register(const ARMCPUInfo *info) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 96158093cc..9c2a226159 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -754,8 +754,8 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = aarch64_cpu_gdb_read_register; cc->gdb_write_register = aarch64_cpu_gdb_write_register; - cc->gdb_num_core_regs = 34; - cc->gdb_core_xml_file = "aarch64-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("aarch64-core.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; cc->gdb_arch_name = aarch64_gdb_arch_name; object_class_property_add_bool(oc, "aarch64", aarch64_cpu_get_aarch64, diff --git a/target/arm/tcg/cpu32.c b/target/arm/tcg/cpu32.c index 47d2e8e781..49a823ad58 100644 --- a/target/arm/tcg/cpu32.c +++ b/target/arm/tcg/cpu32.c @@ -1040,7 +1040,8 @@ static void arm_v7m_class_init(ObjectClass *oc, void *data) acc->info = data; cc->tcg_ops = &arm_v7m_tcg_ops; - cc->gdb_core_xml_file = "arm-m-profile.xml"; + cc->gdb_core_feature = gdb_find_static_feature("arm-m-profile.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; } #ifndef TARGET_AARCH64 diff --git a/target/avr/cpu.c b/target/avr/cpu.c index 8f741f258c..217adc64cb 100644 --- a/target/avr/cpu.c +++ b/target/avr/cpu.c @@ -246,8 +246,8 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = avr_cpu_gdb_read_register; cc->gdb_write_register = avr_cpu_gdb_write_register; cc->gdb_adjust_breakpoint = avr_cpu_gdb_adjust_breakpoint; - cc->gdb_num_core_regs = 35; - cc->gdb_core_xml_file = "avr-cpu.xml"; + cc->gdb_core_feature = gdb_find_static_feature("avr-cpu.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; cc->tcg_ops = &avr_tcg_ops; } diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index f155936289..b54162cbeb 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -391,7 +391,7 @@ static void hexagon_cpu_class_init(ObjectClass *c, void *data) cc->gdb_write_register = hexagon_gdb_write_register; cc->gdb_num_core_regs = TOTAL_PER_THREAD_REGS; cc->gdb_stop_before_watchpoint = true; - cc->gdb_core_xml_file = "hexagon-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("hexagon-core.xml"); cc->disas_set_info = hexagon_cpu_disas_set_info; cc->tcg_ops = &hexagon_tcg_ops; } diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 97ad229d8b..069410985f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7963,12 +7963,11 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->gdb_arch_name = x86_gdb_arch_name; #ifdef TARGET_X86_64 - cc->gdb_core_xml_file = "i386-64bit.xml"; - cc->gdb_num_core_regs = 66; + cc->gdb_core_feature = gdb_find_static_feature("i386-64bit.xml"); #else - cc->gdb_core_xml_file = "i386-32bit.xml"; - cc->gdb_num_core_regs = 50; + cc->gdb_core_feature = gdb_find_static_feature("i386-32bit.xml"); #endif + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; cc->disas_set_info = x86_disas_set_info; dc->user_creatable = true; diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index ad93ecac92..b204cb279d 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -722,8 +722,8 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data) cc->gdb_read_register = loongarch_cpu_gdb_read_register; cc->gdb_write_register = loongarch_cpu_gdb_write_register; cc->disas_set_info = loongarch_cpu_disas_set_info; - cc->gdb_num_core_regs = 35; - cc->gdb_core_xml_file = "loongarch-base64.xml"; + cc->gdb_core_feature = gdb_find_static_feature("loongarch-base64.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; cc->gdb_stop_before_watchpoint = true; cc->gdb_arch_name = loongarch_gdb_arch_name; diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index 70d58471dc..2bd7238aa8 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -572,7 +572,6 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) #endif cc->disas_set_info = m68k_cpu_disas_set_info; - cc->gdb_num_core_regs = 18; cc->tcg_ops = &m68k_tcg_ops; } @@ -580,7 +579,8 @@ static void m68k_cpu_class_init_cf_core(ObjectClass *c, void *data) { CPUClass *cc = CPU_CLASS(c); - cc->gdb_core_xml_file = "cf-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("cf-core.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; } #define DEFINE_M68K_CPU_TYPE_CF(model) \ @@ -595,7 +595,8 @@ static void m68k_cpu_class_init_m68k_core(ObjectClass *c, void *data) { CPUClass *cc = CPU_CLASS(c); - cc->gdb_core_xml_file = "m68k-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("m68k-core.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; } #define DEFINE_M68K_CPU_TYPE_M68K(model) \ diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c index 03c2c4db1f..47f37c2519 100644 --- a/target/microblaze/cpu.c +++ b/target/microblaze/cpu.c @@ -428,8 +428,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) cc->sysemu_ops = &mb_sysemu_ops; #endif device_class_set_props(dc, mb_properties); - cc->gdb_num_core_regs = 32 + 25; - cc->gdb_core_xml_file = "microblaze-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("microblaze-core.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; cc->disas_set_info = mb_disas_set_info; cc->tcg_ops = &mb_tcg_ops; diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 02b7aad9b0..eb56226865 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -7381,9 +7381,9 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_arch_name = ppc_gdb_arch_name; #if defined(TARGET_PPC64) - cc->gdb_core_xml_file = "power64-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("power64-core.xml"); #else - cc->gdb_core_xml_file = "power-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("power-core.xml"); #endif cc->disas_set_info = ppc_disas_set_info; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 6b93b04453..36de35270d 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1031,11 +1031,11 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) #ifdef TARGET_RISCV64 case MXL_RV64: case MXL_RV128: - cc->gdb_core_xml_file = "riscv-64bit-cpu.xml"; + cc->gdb_core_feature = gdb_find_static_feature("riscv-64bit-cpu.xml"); break; #endif case MXL_RV32: - cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; + cc->gdb_core_feature = gdb_find_static_feature("riscv-32bit-cpu.xml"); break; default: g_assert_not_reached(); @@ -1045,6 +1045,8 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) error_setg(errp, "misa_mxl_max must be equal to misa_mxl"); return; } + + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; } /* @@ -2138,7 +2140,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->get_pc = riscv_cpu_get_pc; cc->gdb_read_register = riscv_cpu_gdb_read_register; cc->gdb_write_register = riscv_cpu_gdb_write_register; - cc->gdb_num_core_regs = 33; cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info; #ifndef CONFIG_USER_ONLY diff --git a/target/rx/cpu.c b/target/rx/cpu.c index 157e57da0f..b139265728 100644 --- a/target/rx/cpu.c +++ b/target/rx/cpu.c @@ -239,8 +239,8 @@ static void rx_cpu_class_init(ObjectClass *klass, void *data) cc->gdb_write_register = rx_cpu_gdb_write_register; cc->disas_set_info = rx_cpu_disas_set_info; - cc->gdb_num_core_regs = 26; - cc->gdb_core_xml_file = "rx-core.xml"; + cc->gdb_core_feature = gdb_find_static_feature("rx-core.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; cc->tcg_ops = &rx_tcg_ops; } diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index df167493c3..2a2ff8cbdc 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -348,8 +348,8 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) s390_cpu_class_init_sysemu(cc); #endif cc->disas_set_info = s390_cpu_disas_set_info; - cc->gdb_num_core_regs = S390_NUM_CORE_REGS; - cc->gdb_core_xml_file = "s390x-core64.xml"; + cc->gdb_core_feature = gdb_find_static_feature("s390x-core64.xml"); + cc->gdb_num_core_regs = cc->gdb_core_feature->num_regs; cc->gdb_arch_name = s390_gdb_arch_name; s390_cpu_model_class_register_props(oc); From patchwork Wed Aug 16 13:39:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821801 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=hJ3MtACN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq7S3htjz1yNr for ; Wed, 16 Aug 2023 23:42:12 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGm9-0005Yz-QX; Wed, 16 Aug 2023 09:41:29 -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 1qWGlz-0005UX-PC for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:23 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGlw-000179-Bx for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:19 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6889288a31fso353326b3a.1 for ; Wed, 16 Aug 2023 06:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193275; x=1692798075; 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=J9NUjmmUVHXy03kGyd299wa55TND6+t1PgSeJs0BSLU=; b=hJ3MtACN1nsYq7/mQuEIGAyZ6Xu+bHrXQmY69YkIEWwkBy9gSDTe/8KWy++BTsnj94 GsumDoEGwNqEXtb9HUo6TK3QdOsiIvrzaaacFhxO+mXdSbgoUngZh5LA6hvJL9vBOXwS i2HNr/lik65Jc0FOO6LBbfNnwDWZhAAbCqlx4A8Ivg3k+oT6VJo0hbe0OOEXDX+axQ7w MxKfEMuiadaaa063XGdvse5ytKZfMctm0CRAsmQYoiVzuW67VF8a3G91DxhcJIxjeppk jqk6zTLH0D7qCuJnJzsv8uUhq1bd822+ddcxxW6BpBO1hI8m7rEgB+9MwevjkzSBA6dM A5nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193275; x=1692798075; 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=J9NUjmmUVHXy03kGyd299wa55TND6+t1PgSeJs0BSLU=; b=a/pdI4+58NdvWOXcFmfsdDQA75Imp/xT573taPn46ICtKJ3PJxLek4zKMeU0XJBo0+ gdLNxJUiswBO8b37x0i9klIbnv8BN8I2JpjzqTsg84VXEgsJy8+tNDYR/qFBWbhRee1K 7QZBKNczeeDaDst12CUJTuR9E/AzCyQwRJAie7sG7rW+flLzPjm1d8fH3CVElrUDpI6+ qZiSL57Fp+uRH0OrrVIMYxg5w7GpVt6P++Kkzj4hADB9ATYUlKi1TVhdOh6xK6FozDFk 7PRakHhmuwJAkVqlpXABBXhos91UIXLKanQL3c8373oa4JPkyT3drXekIn6z458Kqpoz 0xNw== X-Gm-Message-State: AOJu0YxLX4sxTm+F7GJ5gXXDvy5kg1N6UooPl28pvb9h7a2a4FFApxCD rR4qptQTi/oa6evpF/aReXxdGw== X-Google-Smtp-Source: AGHT+IHIYHv/NqJ9AysQA1Z2e/44Ks9b3BqgNgwtM+Rpgb/FcX0fjx+O4zRWsadS63qu4efnBJeojQ== X-Received: by 2002:a05:6a00:23d5:b0:666:c1ab:d6e5 with SMTP id g21-20020a056a0023d500b00666c1abd6e5mr2386984pfc.16.1692193275064; Wed, 16 Aug 2023 06:41:15 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:41:14 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 07/25] gdbstub: Introduce GDBFeatureBuilder Date: Wed, 16 Aug 2023 22:39:17 +0900 Message-ID: <20230816133938.18310-8-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::435; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x435.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org GDBFeatureBuilder unifies the logic to generate dynamic GDBFeature. Signed-off-by: Akihiko Odaki --- include/exec/gdbstub.h | 20 ++++++++++++++ gdbstub/gdbstub.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index d0dcc99ed4..1f4608d4f9 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -16,6 +16,11 @@ typedef struct GDBFeature { int num_regs; } GDBFeature; +typedef struct GDBFeatureBuilder { + GDBFeature *feature; + GPtrArray *xml; +} GDBFeatureBuilder; + /* Get or set a register. Returns the size of the register. */ typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg); @@ -34,6 +39,21 @@ void gdb_register_coprocessor(CPUState *cpu, */ int gdbserver_start(const char *port_or_device); +void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature, + const char *name, const char *xmlname); + +void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder, + const char *format, ...) + G_GNUC_PRINTF(2, 3); + +void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, + const char *name, + int bitsize, + const char *type, + const char *group); + +void gdb_feature_builder_end(const GDBFeatureBuilder *builder); + const GDBFeature *gdb_find_static_feature(const char *xmlname); void gdb_set_stop_cpu(CPUState *cpu); diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 293e8ea439..32e88de431 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -414,6 +414,65 @@ static const char *get_feature_xml(const char *p, const char **newp, return name ? gdb_static_features[i].xml : NULL; } +void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature, + const char *name, const char *xmlname) +{ + char *header = g_markup_printf_escaped( + "" + "" + "", + name); + + builder->feature = feature; + builder->xml = g_ptr_array_new(); + g_ptr_array_add(builder->xml, header); + feature->xmlname = xmlname; + feature->num_regs = 0; +} + +void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder, + const char *format, ...) +{ + va_list ap; + va_start(ap, format); + g_ptr_array_add(builder->xml, g_markup_vprintf_escaped(format, ap)); + va_end(ap); +} + +void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, + const char *name, + int bitsize, + const char *type, + const char *group) +{ + if (group) { + gdb_feature_builder_append_tag( + builder, + "", + name, bitsize, type, group); + } else { + gdb_feature_builder_append_tag( + builder, "", + name, bitsize, type); + } + + builder->feature->num_regs++; +} + +void gdb_feature_builder_end(const GDBFeatureBuilder *builder) +{ + g_ptr_array_add(builder->xml, (void *)""); + g_ptr_array_add(builder->xml, NULL); + + builder->feature->xml = g_strjoinv(NULL, (void *)builder->xml->pdata); + + for (guint i = 0; i < builder->xml->len - 2; i++) { + g_free(g_ptr_array_index(builder->xml, i)); + } + + g_ptr_array_free(builder->xml, TRUE); +} + const GDBFeature *gdb_find_static_feature(const char *xmlname) { const GDBFeature *feature; From patchwork Wed Aug 16 13:39:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821805 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=kVKtbCn4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq7V6pzgz1yXY for ; Wed, 16 Aug 2023 23:42:14 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGmF-0005vq-MQ; Wed, 16 Aug 2023 09:41:35 -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 1qWGmB-0005ni-MA for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:32 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGm5-0001ER-SG for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:31 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6884310ee75so2347604b3a.1 for ; Wed, 16 Aug 2023 06:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193284; x=1692798084; 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=jqWNIkwcZSVNzr6/NyVx5h4fvkfjOlvCRcjVS6Segls=; b=kVKtbCn4QNxRTUXt5jnMz+nj2tVArqz2doz8cyn367F19yOmMchrQo/IIws9BGiR4W sOfPyQO5Agx4m5ZaO4KRZXojf9Mop3FsPOUkLdyKHYqaEcPx5YW4JmbwYJ/1i8+HzG8S p4qUkc7W/E2ztmV37JD8Ic1363llRB8wUtgZWtrQMkg4F/HVzpUeN0j+Kk4yWNnf+Jfn w4iStjo6Q1Kbg26tK/7CLL9FSIWfSDmLZus8MU2qlV+6i46rremZGfhE/hJBp+Z6WtYV 6bE468c51Jvtapx5P+5aZkNESzmt0bdL29Z8SYritg7PE2luRzh0rvM3O6Lx3XKksLZT toqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193284; x=1692798084; 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=jqWNIkwcZSVNzr6/NyVx5h4fvkfjOlvCRcjVS6Segls=; b=GJ2jAJ7pznhpg8f5LPBRMkPDTQ5QgV3Cea7yNUrimpIxymmqdxMdpvAeQH7ibxriMu L/0mjh02m5a872eLUns6SJTAVkjrBHm56OeizmcoYejH5inin1pDMvzIq1WmLJXu3Tdv v90h4oMLHdREq1p5KYejhkHL29zicQ7pRB5+Uj+n/6YwXCKLyXbH1p1zsMaoXIh4w+ma eOq6KBUcPHRpSJNJSr0/GLjfZokVdi0sS8QbPAxDHbef6fY2VQi0qKVy36crsYHSGcpE Nvho66J9PVBz5b9KWaw0JLNxvHAm4f03pzMvrL8q6yFGZQDy502qj2nQOnsjtbCDj9QI fo4g== X-Gm-Message-State: AOJu0YxtMOy4S4zTJT+E8JTPAPCo3OUtX62IKj5pZgNTbZbknqLEEagL cgG/Ov1vq7wBP6E8/s5sBRlHJQ== X-Google-Smtp-Source: AGHT+IFXMUGAbTnz3zPKQ9ky4zF9JFp9PogYQIzamFHt7k5wRyeQwYJ4qosmYrgnPuDZmxusIOmlIA== X-Received: by 2002:a05:6300:800a:b0:133:be16:509 with SMTP id an10-20020a056300800a00b00133be160509mr2289491pzc.34.1692193284396; Wed, 16 Aug 2023 06:41:24 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:41:24 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 08/25] target/arm: Use GDBFeature for dynamic XML Date: Wed, 16 Aug 2023 22:39:18 +0900 Message-ID: <20230816133938.18310-9-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42d.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In preparation for a change to use GDBFeature as a parameter of gdb_register_coprocessor(), convert the internal representation of dynamic feature from plain XML to GDBFeature. Signed-off-by: Akihiko Odaki --- target/arm/cpu.h | 20 +++--- target/arm/internals.h | 2 +- target/arm/gdbstub.c | 134 ++++++++++++++++++----------------------- target/arm/gdbstub64.c | 90 ++++++++++++--------------- 4 files changed, 108 insertions(+), 138 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 88e5accda6..d6c2378d05 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -136,23 +136,21 @@ enum { */ /** - * DynamicGDBXMLInfo: - * @desc: Contains the XML descriptions. - * @num: Number of the registers in this XML seen by GDB. + * DynamicGDBFeatureInfo: + * @desc: Contains the feature descriptions. * @data: A union with data specific to the set of registers * @cpregs_keys: Array that contains the corresponding Key of * a given cpreg with the same order of the cpreg * in the XML description. */ -typedef struct DynamicGDBXMLInfo { - char *desc; - int num; +typedef struct DynamicGDBFeatureInfo { + GDBFeature desc; union { struct { uint32_t *keys; } cpregs; } data; -} DynamicGDBXMLInfo; +} DynamicGDBFeatureInfo; /* CPU state for each instance of a generic timer (in cp15 c14) */ typedef struct ARMGenericTimer { @@ -881,10 +879,10 @@ struct ArchCPU { uint64_t *cpreg_vmstate_values; int32_t cpreg_vmstate_array_len; - DynamicGDBXMLInfo dyn_sysreg_xml; - DynamicGDBXMLInfo dyn_svereg_xml; - DynamicGDBXMLInfo dyn_m_systemreg_xml; - DynamicGDBXMLInfo dyn_m_secextreg_xml; + DynamicGDBFeatureInfo dyn_sysreg_feature; + DynamicGDBFeatureInfo dyn_svereg_feature; + DynamicGDBFeatureInfo dyn_m_systemreg_feature; + DynamicGDBFeatureInfo dyn_m_secextreg_feature; /* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS]; diff --git a/target/arm/internals.h b/target/arm/internals.h index 0f01bc32a8..ca20e4fd1e 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1388,7 +1388,7 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env) } #ifdef TARGET_AARCH64 -int arm_gen_dynamic_svereg_xml(CPUState *cpu, int base_reg); +GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cpu); int aarch64_gdb_get_sve_reg(CPUARMState *env, GByteArray *buf, int reg); int aarch64_gdb_set_sve_reg(CPUARMState *env, uint8_t *buf, int reg); int aarch64_gdb_get_fpu_reg(CPUARMState *env, GByteArray *buf, int reg); diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index f421c5d041..daa68ead66 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -25,11 +25,10 @@ #include "internals.h" #include "cpregs.h" -typedef struct RegisterSysregXmlParam { +typedef struct RegisterSysregFeatureParam { CPUState *cs; - GString *s; - int n; -} RegisterSysregXmlParam; + GDBFeatureBuilder builder; +} RegisterSysregFeatureParam; /* Old gdb always expect FPA registers. Newer (xml-aware) gdb only expect whatever the target description contains. Due to a historical mishap @@ -243,7 +242,7 @@ static int arm_gdb_get_sysreg(CPUARMState *env, GByteArray *buf, int reg) const ARMCPRegInfo *ri; uint32_t key; - key = cpu->dyn_sysreg_xml.data.cpregs.keys[reg]; + key = cpu->dyn_sysreg_feature.data.cpregs.keys[reg]; ri = get_arm_cp_reginfo(cpu->cp_regs, key); if (ri) { if (cpreg_field_is_64bit(ri)) { @@ -260,34 +259,32 @@ static int arm_gdb_set_sysreg(CPUARMState *env, uint8_t *buf, int reg) return 0; } -static void arm_gen_one_xml_sysreg_tag(GString *s, DynamicGDBXMLInfo *dyn_xml, +static void arm_gen_one_feature_sysreg(GDBFeatureBuilder *builder, + DynamicGDBFeatureInfo *dyn_feature, ARMCPRegInfo *ri, uint32_t ri_key, - int bitsize, int regnum) + int bitsize) { - g_string_append_printf(s, "name); - g_string_append_printf(s, " bitsize=\"%d\"", bitsize); - g_string_append_printf(s, " regnum=\"%d\"", regnum); - g_string_append_printf(s, " group=\"cp_regs\"/>"); - dyn_xml->data.cpregs.keys[dyn_xml->num] = ri_key; - dyn_xml->num++; + dyn_feature->data.cpregs.keys[dyn_feature->desc.num_regs] = ri_key; + + gdb_feature_builder_append_reg(builder, ri->name, bitsize, + "int", "cp_regs"); } -static void arm_register_sysreg_for_xml(gpointer key, gpointer value, - gpointer p) +static void arm_register_sysreg_for_feature(gpointer key, gpointer value, + gpointer p) { uint32_t ri_key = (uintptr_t)key; ARMCPRegInfo *ri = value; - RegisterSysregXmlParam *param = (RegisterSysregXmlParam *)p; - GString *s = param->s; + RegisterSysregFeatureParam *param = p; ARMCPU *cpu = ARM_CPU(param->cs); CPUARMState *env = &cpu->env; - DynamicGDBXMLInfo *dyn_xml = &cpu->dyn_sysreg_xml; + DynamicGDBFeatureInfo *dyn_feature = &cpu->dyn_sysreg_feature; if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_NO_GDB))) { if (arm_feature(env, ARM_FEATURE_AARCH64)) { if (ri->state == ARM_CP_STATE_AA64) { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64, - param->n++); + arm_gen_one_feature_sysreg(¶m->builder, dyn_feature, + ri, ri_key, 64); } } else { if (ri->state == ARM_CP_STATE_AA32) { @@ -296,32 +293,31 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value, return; } if (ri->type & ARM_CP_64BIT) { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64, - param->n++); + arm_gen_one_feature_sysreg(¶m->builder, dyn_feature, + ri, ri_key, 64); } else { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 32, - param->n++); + arm_gen_one_feature_sysreg(¶m->builder, dyn_feature, + ri, ri_key, 32); } } } } } -static int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg) +static GDBFeature *arm_gen_dynamic_sysreg_feature(CPUState *cs) { ARMCPU *cpu = ARM_CPU(cs); - GString *s = g_string_new(NULL); - RegisterSysregXmlParam param = {cs, s, base_reg}; - - cpu->dyn_sysreg_xml.num = 0; - cpu->dyn_sysreg_xml.data.cpregs.keys = g_new(uint32_t, g_hash_table_size(cpu->cp_regs)); - g_string_printf(s, ""); - g_string_append_printf(s, ""); - g_string_append_printf(s, ""); - g_hash_table_foreach(cpu->cp_regs, arm_register_sysreg_for_xml, ¶m); - g_string_append_printf(s, ""); - cpu->dyn_sysreg_xml.desc = g_string_free(s, false); - return cpu->dyn_sysreg_xml.num; + RegisterSysregFeatureParam param = {cs}; + gsize num_regs = g_hash_table_size(cpu->cp_regs); + + gdb_feature_builder_init(¶m.builder, + &cpu->dyn_sysreg_feature.desc, + "org.qemu.gdb.arm.sys.regs", + "system-registers.xml"); + cpu->dyn_sysreg_feature.data.cpregs.keys = g_new(uint32_t, num_regs); + g_hash_table_foreach(cpu->cp_regs, arm_register_sysreg_for_feature, ¶m); + gdb_feature_builder_end(¶m.builder); + return &cpu->dyn_sysreg_feature.desc; } #ifdef CONFIG_TCG @@ -413,31 +409,26 @@ static int arm_gdb_set_m_systemreg(CPUARMState *env, uint8_t *buf, int reg) return 0; /* TODO */ } -static int arm_gen_dynamic_m_systemreg_xml(CPUState *cs, int orig_base_reg) +static GDBFeature *arm_gen_dynamic_m_systemreg_feature(CPUState *cs) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; - GString *s = g_string_new(NULL); - int base_reg = orig_base_reg; + GDBFeatureBuilder builder; int i; - g_string_printf(s, ""); - g_string_append_printf(s, ""); - g_string_append_printf(s, "\n"); + gdb_feature_builder_init(&builder, &cpu->dyn_m_systemreg_feature.desc, + "org.gnu.gdb.arm.m-system", "arm-m-system.xml"); for (i = 0; i < ARRAY_SIZE(m_sysreg_def); i++) { if (arm_feature(env, m_sysreg_def[i].feature)) { - g_string_append_printf(s, - "\n", - m_sysreg_def[i].name, base_reg++); + gdb_feature_builder_append_reg(&builder, m_sysreg_def[i].name, 32, + "int", NULL); } } - g_string_append_printf(s, ""); - cpu->dyn_m_systemreg_xml.desc = g_string_free(s, false); - cpu->dyn_m_systemreg_xml.num = base_reg - orig_base_reg; + gdb_feature_builder_end(&builder); - return cpu->dyn_m_systemreg_xml.num; + return &cpu->dyn_m_systemreg_feature.desc; } #ifndef CONFIG_USER_ONLY @@ -455,31 +446,26 @@ static int arm_gdb_set_m_secextreg(CPUARMState *env, uint8_t *buf, int reg) return 0; /* TODO */ } -static int arm_gen_dynamic_m_secextreg_xml(CPUState *cs, int orig_base_reg) +static GDBFeature *arm_gen_dynamic_m_secextreg_feature(CPUState *cs) { ARMCPU *cpu = ARM_CPU(cs); - GString *s = g_string_new(NULL); - int base_reg = orig_base_reg; + GDBFeatureBuilder builder; + char *name; int i; - g_string_printf(s, ""); - g_string_append_printf(s, ""); - g_string_append_printf(s, "\n"); + gdb_feature_builder_init(&builder, &cpu->dyn_m_secextreg_feature.desc, + "org.gnu.gdb.arm.secext", "arm-m-secext.xml"); for (i = 0; i < ARRAY_SIZE(m_sysreg_def); i++) { - g_string_append_printf(s, - "\n", - m_sysreg_def[i].name, base_reg++); - g_string_append_printf(s, - "\n", - m_sysreg_def[i].name, base_reg++); + name = g_strconcat(m_sysreg_def[i].name, "_ns", NULL); + gdb_feature_builder_append_reg(&builder, name, 32, "int", NULL); + name = g_strconcat(m_sysreg_def[i].name, "_s", NULL); + gdb_feature_builder_append_reg(&builder, name, 32, "int", NULL); } - g_string_append_printf(s, ""); - cpu->dyn_m_secextreg_xml.desc = g_string_free(s, false); - cpu->dyn_m_secextreg_xml.num = base_reg - orig_base_reg; + gdb_feature_builder_end(&builder); - return cpu->dyn_m_secextreg_xml.num; + return &cpu->dyn_m_secextreg_feature.desc; } #endif #endif /* CONFIG_TCG */ @@ -489,14 +475,14 @@ const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) ARMCPU *cpu = ARM_CPU(cs); if (strcmp(xmlname, "system-registers.xml") == 0) { - return cpu->dyn_sysreg_xml.desc; + return cpu->dyn_sysreg_feature.desc.xml; } else if (strcmp(xmlname, "sve-registers.xml") == 0) { - return cpu->dyn_svereg_xml.desc; + return cpu->dyn_svereg_feature.desc.xml; } else if (strcmp(xmlname, "arm-m-system.xml") == 0) { - return cpu->dyn_m_systemreg_xml.desc; + return cpu->dyn_m_systemreg_feature.desc.xml; #ifndef CONFIG_USER_ONLY } else if (strcmp(xmlname, "arm-m-secext.xml") == 0) { - return cpu->dyn_m_secextreg_xml.desc; + return cpu->dyn_m_secextreg_feature.desc.xml; #endif } return NULL; @@ -514,7 +500,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) */ #ifdef TARGET_AARCH64 if (isar_feature_aa64_sve(&cpu->isar)) { - int nreg = arm_gen_dynamic_svereg_xml(cs, cs->gdb_num_regs); + int nreg = arm_gen_dynamic_svereg_feature(cs)->num_regs; gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg, aarch64_gdb_set_sve_reg, nreg, "sve-registers.xml", 0); @@ -560,20 +546,20 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) 1, "arm-m-profile-mve.xml", 0); } gdb_register_coprocessor(cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, - arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_regs), + arm_gen_dynamic_sysreg_feature(cs)->num_regs, "system-registers.xml", 0); #ifdef CONFIG_TCG if (arm_feature(env, ARM_FEATURE_M) && tcg_enabled()) { gdb_register_coprocessor(cs, arm_gdb_get_m_systemreg, arm_gdb_set_m_systemreg, - arm_gen_dynamic_m_systemreg_xml(cs, cs->gdb_num_regs), + arm_gen_dynamic_m_systemreg_feature(cs)->num_regs, "arm-m-system.xml", 0); #ifndef CONFIG_USER_ONLY if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { gdb_register_coprocessor(cs, arm_gdb_get_m_secextreg, arm_gdb_set_m_secextreg, - arm_gen_dynamic_m_secextreg_xml(cs, cs->gdb_num_regs), + arm_gen_dynamic_m_secextreg_feature(cs)->num_regs, "arm-m-secext.xml", 0); } #endif diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index d7b79a6589..632ac2a520 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -247,7 +247,7 @@ int aarch64_gdb_set_pauth_reg(CPUARMState *env, uint8_t *buf, int reg) return 0; } -static void output_vector_union_type(GString *s, int reg_width, +static void output_vector_union_type(GDBFeatureBuilder *builder, int reg_width, const char *name) { struct TypeSize { @@ -282,10 +282,10 @@ static void output_vector_union_type(GString *s, int reg_width, /* First define types and totals in a whole VL */ for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { - g_string_append_printf(s, - "", - name, vec_lanes[i].sz, vec_lanes[i].suffix, - vec_lanes[i].gdb_type, reg_width / vec_lanes[i].size); + gdb_feature_builder_append_tag( + builder, "", + name, vec_lanes[i].sz, vec_lanes[i].suffix, + vec_lanes[i].gdb_type, reg_width / vec_lanes[i].size); } /* @@ -296,86 +296,72 @@ static void output_vector_union_type(GString *s, int reg_width, for (i = 0; i < ARRAY_SIZE(suf); i++) { int bits = 8 << i; - g_string_append_printf(s, "", name, suf[i]); + gdb_feature_builder_append_tag(builder, "", + name, suf[i]); for (j = 0; j < ARRAY_SIZE(vec_lanes); j++) { if (vec_lanes[j].size == bits) { - g_string_append_printf(s, "", - vec_lanes[j].suffix, name, - vec_lanes[j].sz, vec_lanes[j].suffix); + gdb_feature_builder_append_tag( + builder, "", + vec_lanes[j].suffix, name, + vec_lanes[j].sz, vec_lanes[j].suffix); } } - g_string_append(s, ""); + gdb_feature_builder_append_tag(builder, ""); } /* And now the final union of unions */ - g_string_append_printf(s, "", name); + gdb_feature_builder_append_tag(builder, "", name); for (i = ARRAY_SIZE(suf) - 1; i >= 0; i--) { - g_string_append_printf(s, "", - suf[i], name, suf[i]); + gdb_feature_builder_append_tag(builder, + "", + suf[i], name, suf[i]); } - g_string_append(s, ""); + gdb_feature_builder_append_tag(builder, ""); } -int arm_gen_dynamic_svereg_xml(CPUState *cs, int orig_base_reg) +GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs) { ARMCPU *cpu = ARM_CPU(cs); - GString *s = g_string_new(NULL); - DynamicGDBXMLInfo *info = &cpu->dyn_svereg_xml; int reg_width = cpu->sve_max_vq * 128; int pred_width = cpu->sve_max_vq * 16; - int base_reg = orig_base_reg; + GDBFeatureBuilder builder; + char *name; int i; - g_string_printf(s, ""); - g_string_append_printf(s, ""); - g_string_append_printf(s, ""); + gdb_feature_builder_init(&builder, &cpu->dyn_svereg_feature.desc, + "org.gnu.gdb.aarch64.sve", "sve-registers.xml"); /* Create the vector union type. */ - output_vector_union_type(s, reg_width, "svev"); + output_vector_union_type(&builder, reg_width, "svev"); /* Create the predicate vector type. */ - g_string_append_printf(s, - "", - pred_width / 8); + gdb_feature_builder_append_tag( + &builder, "", + pred_width / 8); /* Define the vector registers. */ for (i = 0; i < 32; i++) { - g_string_append_printf(s, - "", - i, reg_width, base_reg++); + name = g_strdup_printf("z%d", i); + gdb_feature_builder_append_reg(&builder, name, reg_width, "svev", NULL); } /* fpscr & status registers */ - g_string_append_printf(s, "", base_reg++); - g_string_append_printf(s, "", base_reg++); + gdb_feature_builder_append_reg(&builder, "fpsr", 32, "int", "float"); + gdb_feature_builder_append_reg(&builder, "fpcr", 32, "int", "float"); /* Define the predicate registers. */ for (i = 0; i < 16; i++) { - g_string_append_printf(s, - "", - i, pred_width, base_reg++); + name = g_strdup_printf("p%d", i); + gdb_feature_builder_append_reg(&builder, name, pred_width, + "svep", NULL); } - g_string_append_printf(s, - "", - pred_width, base_reg++); + gdb_feature_builder_append_reg(&builder, "ffr", pred_width, + "svep", "vector"); /* Define the vector length pseudo-register. */ - g_string_append_printf(s, - "", - base_reg++); + gdb_feature_builder_append_reg(&builder, "vg", 64, "int", NULL); - g_string_append_printf(s, ""); + gdb_feature_builder_end(&builder); - info->desc = g_string_free(s, false); - info->num = base_reg - orig_base_reg; - return info->num; + return &cpu->dyn_svereg_feature.desc; } From patchwork Wed Aug 16 13:39:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=deTjKnOS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq7V4hssz1yNr for ; Wed, 16 Aug 2023 23:42:14 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGmJ-0006HV-UU; Wed, 16 Aug 2023 09:41:39 -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 1qWGmI-00068I-0o for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:38 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGmE-0001Gi-RZ for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:37 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-686bc261111so4609088b3a.3 for ; Wed, 16 Aug 2023 06:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193294; x=1692798094; 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=jj8XEMKTKizRIsIUeuKfRN/fxn5DPOE9jMPRlwlycR0=; b=deTjKnOS5iyh/BjVsLwfTclFyBrnCqUKn9rBN0JsVTkd9ludoooER+EtgWvDje+tDe 4nSg64XEfAIAulvTIgNXHfyjoquJ1lJuzc8cl7yB4oWeYYBP5FKqP/PVLUzVgJt5KQog uMo9CLGekkvMY7pwgSXXk17s6Deo0psWga5UCf0uQUV0aCa8BXUZzLpJCV28AAunCCsj g3BICpVR9sZIagHyv1fuJ5e2SwARQsM3DxgO+6qRzVXoQm1j7FPYXV/1KOJ43wPl3/Ik NKYhhPJsv0NUhSJurfkoOBThnGH+DnChiyLj2GHKrn4vqGCbCZ6qeDR2pTSqo7GWVlyi GLUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193294; x=1692798094; 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=jj8XEMKTKizRIsIUeuKfRN/fxn5DPOE9jMPRlwlycR0=; b=WcpKlVN0EhtYslXlLPsXTZUYkR5NPxtlKhqnBIrX/Ga6AKwz4XbYCORLmiGVDxjhcB WbD8W2ovIHBUmJzibj6ZBcOO9/yspugJ8Nhb0rVRY3esNMVSUnw1rvv66icdaIyBHvla mBy+QHxlQgsD9iStB9kLMNWlB51/QUAS6vFtkaCrOOUjTkF3nz1K7IxbP5DAcgw04h/A aWKfWYceoPn+LfuI4Q5mBmyTRHY7y4ZM17/x3dXbTBJSwzgvs5+gtf1mCevICYMxx6B1 Z2Wh1pJJ3hod+agBg2l5KhsHJvCVcoDgH51B6HGEb6Z9tbK+yZFii25Vv+zlcnkKYII8 19fw== X-Gm-Message-State: AOJu0Yy0obfWUTGeYc7XtjYVlVKHSRF0ScU0/lm1jOixBdKlIJMG5D6/ qWvrTen1ojle5AYqWVTpUG67HA== X-Google-Smtp-Source: AGHT+IHvP4tk8BcT8Uk54LMH0+JuCIkezE9W7gtYrcz27+yXORlK4bskCsC9mYkhtPC7NJdHYac3Vw== X-Received: by 2002:a05:6a00:850:b0:686:b94a:3879 with SMTP id q16-20020a056a00085000b00686b94a3879mr1937906pfk.18.1692193293702; Wed, 16 Aug 2023 06:41:33 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:41:33 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 09/25] target/ppc: Use GDBFeature for dynamic XML Date: Wed, 16 Aug 2023 22:39:19 +0900 Message-ID: <20230816133938.18310-10-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42d.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In preparation for a change to use GDBFeature as a parameter of gdb_register_coprocessor(), convert the internal representation of dynamic feature from plain XML to GDBFeature. Signed-off-by: Akihiko Odaki --- target/ppc/cpu-qom.h | 3 +-- target/ppc/cpu.h | 2 +- target/ppc/cpu_init.c | 2 +- target/ppc/gdbstub.c | 45 ++++++++++++++----------------------------- 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/target/ppc/cpu-qom.h b/target/ppc/cpu-qom.h index be33786bd8..633fb402b5 100644 --- a/target/ppc/cpu-qom.h +++ b/target/ppc/cpu-qom.h @@ -186,8 +186,7 @@ struct PowerPCCPUClass { int bfd_mach; uint32_t l1_dcache_size, l1_icache_size; #ifndef CONFIG_USER_ONLY - unsigned int gdb_num_sprs; - const char *gdb_spr_xml; + GDBFeature gdb_spr; #endif const PPCHash64Options *hash64_opts; struct ppc_radix_page_info *radix_page_info; diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 25fac9577a..5f251bdffe 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1381,7 +1381,7 @@ int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg); #ifndef CONFIG_USER_ONLY hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -void ppc_gdb_gen_spr_xml(PowerPCCPU *cpu); +void ppc_gdb_gen_spr_feature(PowerPCCPU *cpu); const char *ppc_gdb_get_dynamic_xml(CPUState *cs, const char *xml_name); #endif int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index eb56226865..938cd2b7e1 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6673,7 +6673,7 @@ static void init_ppc_proc(PowerPCCPU *cpu) (*pcc->init_proc)(env); #if !defined(CONFIG_USER_ONLY) - ppc_gdb_gen_spr_xml(cpu); + ppc_gdb_gen_spr_feature(cpu); #endif /* MSR bits & flags consistency checks */ diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index ca39efdc35..0ef484dbee 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -318,15 +318,21 @@ int ppc_cpu_gdb_write_register_apple(CPUState *cs, uint8_t *mem_buf, int n) } #ifndef CONFIG_USER_ONLY -void ppc_gdb_gen_spr_xml(PowerPCCPU *cpu) +void ppc_gdb_gen_spr_feature(PowerPCCPU *cpu) { PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); CPUPPCState *env = &cpu->env; - GString *xml; - char *spr_name; + GDBFeatureBuilder builder; unsigned int num_regs = 0; int i; + if (pcc->gdb_spr.xml) { + return; + } + + gdb_feature_builder_init(&builder, &pcc->gdb_spr, + "org.qemu.power.spr", "power-spr.xml"); + for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) { ppc_spr_t *spr = &env->spr_cb[i]; @@ -344,35 +350,12 @@ void ppc_gdb_gen_spr_xml(PowerPCCPU *cpu) */ spr->gdb_id = num_regs; num_regs++; - } - - if (pcc->gdb_spr_xml) { - return; - } - - xml = g_string_new(""); - g_string_append(xml, ""); - g_string_append(xml, ""); - for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) { - ppc_spr_t *spr = &env->spr_cb[i]; - - if (!spr->name) { - continue; - } - - spr_name = g_ascii_strdown(spr->name, -1); - g_string_append_printf(xml, ""); + gdb_feature_builder_append_reg(&builder, g_ascii_strdown(spr->name, -1), + TARGET_LONG_BITS, "int", "spr"); } - g_string_append(xml, ""); - - pcc->gdb_num_sprs = num_regs; - pcc->gdb_spr_xml = g_string_free(xml, false); + gdb_feature_builder_end(&builder); } const char *ppc_gdb_get_dynamic_xml(CPUState *cs, const char *xml_name) @@ -380,7 +363,7 @@ const char *ppc_gdb_get_dynamic_xml(CPUState *cs, const char *xml_name) PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs); if (strcmp(xml_name, "power-spr.xml") == 0) { - return pcc->gdb_spr_xml; + return pcc->gdb_spr.xml; } return NULL; } @@ -618,6 +601,6 @@ void ppc_gdb_init(CPUState *cs, PowerPCCPUClass *pcc) } #ifndef CONFIG_USER_ONLY gdb_register_coprocessor(cs, gdb_get_spr_reg, gdb_set_spr_reg, - pcc->gdb_num_sprs, "power-spr.xml", 0); + pcc->gdb_spr.num_regs, "power-spr.xml", 0); #endif } From patchwork Wed Aug 16 13:39:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821849 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=b53WH+N/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqJ44y4gz1yNm for ; Wed, 16 Aug 2023 23:49:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGmV-0006VH-23; Wed, 16 Aug 2023 09:41:51 -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 1qWGmS-0006R9-CV for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:48 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGmO-0001Ix-LH for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:48 -0400 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-565ece9636eso817091a12.1 for ; Wed, 16 Aug 2023 06:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193303; x=1692798103; 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=KFJeOlUoAVVZiQ1qte2B9EXE3G1/GABPnVcBdJPoN+Y=; b=b53WH+N/IkEDYOl+KFUVBjqYd1hN923hhGmur2TH966akayL4l2GOlpNHcKriT4boA GEBdQ2q+HOZ7OwoY6iTlEL/0prKqHl8QN+kkohbMPs6L+lkQHs4rKDgGqqioyeEMMrUc ZYtx/tEWdnBp7hoAD8Mao8wSW/iUkPhSRn2xCuiwcp7AaeoTX7uNwY4GD+z6Hcl/93JO DHZcxgIRwv7QsfKkBZWGYVOEEBmFS/kyzxrsBeJHRUZxbBNbHVNV+DXSNtqXVW3avogM VbZ1yWR0GHGrea2y0GioxikDafAklvZzHyQkOOQEBpoeXywtdogLQk1568JLbJMQOD2A f2iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193303; x=1692798103; 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=KFJeOlUoAVVZiQ1qte2B9EXE3G1/GABPnVcBdJPoN+Y=; b=OMBrYfNKqE3f8Em9MCYcFKy/VEREcQuJAu6dYC8+7l+oKFBYhyl6/USRWIaVoPmZdD pUzuMPVW88mVtabpX2CS2nuXfmwOYatnMnT8oeV2OQta5UJ5rxzwqCMqQJOkOHKtoHp9 iFFNISN137FoVXrlI/e5BajZn7KlOukOS1xToTlHF21HlXGJ+PofUFb0Unp2gZRYXBVD QoPkwb+i9JrD/5jk6zYXQpPFKnmXFsFMITrcsKh9ywaOGZWspON3B/Qgqvs4lajFjPNm MOE06D8/s9ipKxfup2F5QjqF3+R4Qc6156rNp/hq+AmLecZJj9KeoYIbZFPxbfm4kTii latg== X-Gm-Message-State: AOJu0YzK3Qu2UHrmdjTxm/g4WDMCI05ROKB3E/5g1Ej5lLdrIslQ/1Zd NylLSWXPyl4VRQokEvqWUbCyAw== X-Google-Smtp-Source: AGHT+IH03K+c1nXropL+IqIXoRQAv5P5qSCXhNOovR8dC0XmnmUQZ4fTiOKaQi2i1CPbTFbcchZJTw== X-Received: by 2002:a05:6a20:321b:b0:134:198b:84e9 with SMTP id hl27-20020a056a20321b00b00134198b84e9mr1694935pzc.61.1692193303021; Wed, 16 Aug 2023 06:41:43 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:41:42 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 10/25] target/riscv: Use GDBFeature for dynamic XML Date: Wed, 16 Aug 2023 22:39:20 +0900 Message-ID: <20230816133938.18310-11-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::534; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x534.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In preparation for a change to use GDBFeature as a parameter of gdb_register_coprocessor(), convert the internal representation of dynamic feature from plain XML to GDBFeature. Signed-off-by: Akihiko Odaki --- target/riscv/cpu.h | 4 +-- target/riscv/cpu.c | 4 +-- target/riscv/gdbstub.c | 75 +++++++++++++++++------------------------- 3 files changed, 35 insertions(+), 48 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6ea22e0eea..f67751d5b7 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -391,8 +391,8 @@ struct ArchCPU { CPUNegativeOffsetState neg; CPURISCVState env; - char *dyn_csr_xml; - char *dyn_vreg_xml; + GDBFeature dyn_csr_feature; + GDBFeature dyn_vreg_feature; /* Configuration Settings */ RISCVCPUConfig cfg; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 36de35270d..ceca40cdd9 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1962,9 +1962,9 @@ static const char *riscv_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) RISCVCPU *cpu = RISCV_CPU(cs); if (strcmp(xmlname, "riscv-csr.xml") == 0) { - return cpu->dyn_csr_xml; + return cpu->dyn_csr_feature.xml; } else if (strcmp(xmlname, "riscv-vector.xml") == 0) { - return cpu->dyn_vreg_xml; + return cpu->dyn_vreg_feature.xml; } return NULL; diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 524bede865..fb8d92bcbe 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -212,12 +212,13 @@ static int riscv_gdb_set_virtual(CPURISCVState *cs, uint8_t *mem_buf, int n) return 0; } -static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg) +static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; - GString *s = g_string_new(NULL); + GDBFeatureBuilder builder; riscv_csr_predicate_fn predicate; + const char *name; int bitsize = 16 << env->misa_mxl_max; int i; @@ -230,9 +231,8 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg) bitsize = 64; } - g_string_printf(s, ""); - g_string_append_printf(s, ""); - g_string_append_printf(s, ""); + gdb_feature_builder_init(&builder, &cpu->dyn_csr_feature, + "org.gnu.gdb.riscv.csr", "riscv-csr.xml"); for (i = 0; i < CSR_TABLE_SIZE; i++) { if (env->priv_ver < csr_ops[i].min_priv_ver) { @@ -240,72 +240,61 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg) } predicate = csr_ops[i].predicate; if (predicate && (predicate(env, i) == RISCV_EXCP_NONE)) { - if (csr_ops[i].name) { - g_string_append_printf(s, "", base_reg + i); + + gdb_feature_builder_append_reg(&builder, name, bitsize, + "int", NULL); } } - g_string_append_printf(s, ""); - - cpu->dyn_csr_xml = g_string_free(s, false); + gdb_feature_builder_end(&builder); #if !defined(CONFIG_USER_ONLY) env->debugger = false; #endif - return CSR_TABLE_SIZE; + return &cpu->dyn_csr_feature; } -static int ricsv_gen_dynamic_vector_xml(CPUState *cs, int base_reg) +static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs) { RISCVCPU *cpu = RISCV_CPU(cs); - GString *s = g_string_new(NULL); - g_autoptr(GString) ts = g_string_new(""); + GDBFeatureBuilder builder; int reg_width = cpu->cfg.vlen; - int num_regs = 0; int i; - g_string_printf(s, ""); - g_string_append_printf(s, ""); - g_string_append_printf(s, ""); + gdb_feature_builder_init(&builder, &cpu->dyn_vreg_feature, + "org.gnu.gdb.riscv.vector", "riscv-vector.xml"); /* First define types and totals in a whole VL */ for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { int count = reg_width / vec_lanes[i].size; - g_string_printf(ts, "%s", vec_lanes[i].id); - g_string_append_printf(s, - "", - ts->str, vec_lanes[i].gdb_type, count); + gdb_feature_builder_append_tag( + &builder, "", + vec_lanes[i].id, vec_lanes[i].gdb_type, count); } /* Define unions */ - g_string_append_printf(s, ""); + gdb_feature_builder_append_tag(&builder, ""); for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { - g_string_append_printf(s, "", - vec_lanes[i].suffix, - vec_lanes[i].id); + gdb_feature_builder_append_tag(&builder, + "", + vec_lanes[i].suffix, vec_lanes[i].id); } - g_string_append(s, ""); + gdb_feature_builder_append_tag(&builder, ""); /* Define vector registers */ for (i = 0; i < 32; i++) { - g_string_append_printf(s, - "", - i, reg_width, base_reg++); - num_regs++; + gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i), + reg_width, "riscv_vector", "vector"); } - g_string_append_printf(s, ""); + gdb_feature_builder_end(&builder); - cpu->dyn_vreg_xml = g_string_free(s, false); - return num_regs; + return &cpu->dyn_vreg_feature; } void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) @@ -320,10 +309,9 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) 32, "riscv-32bit-fpu.xml", 0); } if (env->misa_ext & RVV) { - int base_reg = cs->gdb_num_regs; gdb_register_coprocessor(cs, riscv_gdb_get_vector, riscv_gdb_set_vector, - ricsv_gen_dynamic_vector_xml(cs, base_reg), + ricsv_gen_dynamic_vector_feature(cs)->num_regs, "riscv-vector.xml", 0); } switch (env->misa_mxl_max) { @@ -343,9 +331,8 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) } if (cpu->cfg.ext_icsr) { - int base_reg = cs->gdb_num_regs; gdb_register_coprocessor(cs, riscv_gdb_get_csr, riscv_gdb_set_csr, - riscv_gen_dynamic_csr_xml(cs, base_reg), + riscv_gen_dynamic_csr_feature(cs)->num_regs, "riscv-csr.xml", 0); } } From patchwork Wed Aug 16 13:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=sEMhf4p2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq9H6wXmz1yNr for ; Wed, 16 Aug 2023 23:43:47 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGmf-0006pa-MP; Wed, 16 Aug 2023 09:42:01 -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 1qWGmd-0006o4-Ef for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:59 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGmX-0001LL-Rz for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:41:59 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-68879c7f5easo809209b3a.1 for ; Wed, 16 Aug 2023 06:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193312; x=1692798112; 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=1u571RruQOJ3fpgBhUASOeY/7nulXNd6EbhSG141CNI=; b=sEMhf4p2Q0eIPcH6UdkbwZo9oJ8IBDICzLTlppoL7/kEeQxmXHe3w3GEQL5bE/X+m+ KhTBNn1smGSjB6fDWaXMVxc/V82ChouNa6KrcnlHmeGWwppnH7HqnTKT0JDXns4vLzU0 JXE0v8wzszwY895N8+qblELxt+KDkHd6P4ti06RbLSG92W5JRL10xnFIlxh/Nafcc54z xdK/mxwCcF0g7V1iQcYfYoleNe+ddrTiNdjY3V5yBr3CMWHrzUkKseCJKSggdxjA51tU rcST9xTkKUhxXTOekiKoqd0Qj9JzuTOe7Uf+GJb6T5Fj9Ge9N3AL4bUQZQxiM7u8HkQA HGlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193312; x=1692798112; 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=1u571RruQOJ3fpgBhUASOeY/7nulXNd6EbhSG141CNI=; b=CL5KUlY+OVCcU9RZqaAlv98FidzqK6RLgIF+uK/X9r5bF/IYPK3dT4F6jsoVFVdIKc 4WWgRFanlnEgRLXOe2jC6GoSQQ9OyN57B8Q7BKgK1O7gcWO1rX/zWBvkGwewR2ziaDbE yEvLIy3axLNjBEipdEm3TTOXSKXPHEMA6SHXO0JdO/8hEc74iOHd7VjY83Ft3L9tQbme zBuE4gnJieRRymRLrb9dWSK20ACytc0Ux4bSjxm03m4TN+f5uWXDk5zGnlh6pTynPazL Rpghn2TsUjmFBwbCtbR8eL3xT5KgGeVFCl3/fb8WzCUmAh4mx6P0lFjB8QtZze9w6hCA zaoA== X-Gm-Message-State: AOJu0YzPpAi+s6NBFLUxgyNaTJzEtk4sBorUyaSgORitnj0v3fn7UagA CdXkNkbM4n5WmerVnnAprkkGrw== X-Google-Smtp-Source: AGHT+IFkGbcL4/4gGPQr4Pm/KgNoU028gbzzx9a0TfMyR8ybcmS9ZuiZ1jc5xqGMQV8CvY0CTEVRZw== X-Received: by 2002:a05:6a00:2e98:b0:686:baf2:35f4 with SMTP id fd24-20020a056a002e9800b00686baf235f4mr2148442pfb.29.1692193312357; Wed, 16 Aug 2023 06:41:52 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:41:52 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 11/25] gdbstub: Use GDBFeature for gdb_register_coprocessor Date: Wed, 16 Aug 2023 22:39:21 +0900 Message-ID: <20230816133938.18310-12-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::436; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x436.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is a tree-wide change to introduce GDBFeature parameter to gdb_register_coprocessor(). The new parameter just replaces num_regs and xml parameters for now. GDBFeature will be utilized to simplify XML lookup in a following change. Signed-off-by: Akihiko Odaki Acked-by: Alex Bennée --- include/exec/gdbstub.h | 2 +- gdbstub/gdbstub.c | 13 +++++++------ target/arm/gdbstub.c | 34 ++++++++++++++++++---------------- target/hexagon/cpu.c | 3 +-- target/loongarch/gdbstub.c | 2 +- target/m68k/helper.c | 6 +++--- target/microblaze/cpu.c | 5 +++-- target/ppc/gdbstub.c | 11 ++++++----- target/riscv/gdbstub.c | 18 ++++++++++-------- target/s390x/gdbstub.c | 28 +++++++--------------------- 10 files changed, 57 insertions(+), 65 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 1f4608d4f9..572abada63 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -27,7 +27,7 @@ typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg); typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg); void gdb_register_coprocessor(CPUState *cpu, gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg, - int num_regs, const char *xml, int g_pos); + const GDBFeature *feature, int g_pos); /** * gdbserver_start: start the gdb server diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 32e88de431..7fa4b8b51f 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -530,7 +530,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) void gdb_register_coprocessor(CPUState *cpu, gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg, - int num_regs, const char *xml, int g_pos) + const GDBFeature *feature, int g_pos) { GDBRegisterState *s; GDBRegisterState **p; @@ -538,25 +538,26 @@ void gdb_register_coprocessor(CPUState *cpu, p = &cpu->gdb_regs; while (*p) { /* Check for duplicates. */ - if (strcmp((*p)->xml, xml) == 0) + if (strcmp((*p)->xml, feature->xmlname) == 0) return; p = &(*p)->next; } s = g_new0(GDBRegisterState, 1); s->base_reg = cpu->gdb_num_regs; - s->num_regs = num_regs; + s->num_regs = feature->num_regs; s->get_reg = get_reg; s->set_reg = set_reg; - s->xml = xml; + s->xml = feature->xml; /* Add to end of list. */ - cpu->gdb_num_regs += num_regs; + cpu->gdb_num_regs += feature->num_regs; *p = s; if (g_pos) { if (g_pos != s->base_reg) { error_report("Error: Bad gdb register numbering for '%s', " - "expected %d got %d", xml, g_pos, s->base_reg); + "expected %d got %d", feature->xml, + g_pos, s->base_reg); } else { cpu->gdb_num_g_regs = cpu->gdb_num_regs; } diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index daa68ead66..791784dffe 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -500,14 +500,14 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) */ #ifdef TARGET_AARCH64 if (isar_feature_aa64_sve(&cpu->isar)) { - int nreg = arm_gen_dynamic_svereg_feature(cs)->num_regs; + GDBFeature *feature = arm_gen_dynamic_svereg_feature(cs); gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg, - aarch64_gdb_set_sve_reg, nreg, - "sve-registers.xml", 0); + aarch64_gdb_set_sve_reg, feature, 0); } else { gdb_register_coprocessor(cs, aarch64_gdb_get_fpu_reg, aarch64_gdb_set_fpu_reg, - 34, "aarch64-fpu.xml", 0); + gdb_find_static_feature("aarch64-fpu.xml"), + 0); } /* * Note that we report pauth information via the feature name @@ -518,19 +518,22 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) if (isar_feature_aa64_pauth(&cpu->isar)) { gdb_register_coprocessor(cs, aarch64_gdb_get_pauth_reg, aarch64_gdb_set_pauth_reg, - 4, "aarch64-pauth.xml", 0); + gdb_find_static_feature("aarch64-pauth.xml"), + 0); } #endif } else { if (arm_feature(env, ARM_FEATURE_NEON)) { gdb_register_coprocessor(cs, vfp_gdb_get_reg, vfp_gdb_set_reg, - 49, "arm-neon.xml", 0); + gdb_find_static_feature("arm-neon.xml"), + 0); } else if (cpu_isar_feature(aa32_simd_r32, cpu)) { gdb_register_coprocessor(cs, vfp_gdb_get_reg, vfp_gdb_set_reg, - 33, "arm-vfp3.xml", 0); + gdb_find_static_feature("arm-vfp3.xml"), + 0); } else if (cpu_isar_feature(aa32_vfp_simd, cpu)) { gdb_register_coprocessor(cs, vfp_gdb_get_reg, vfp_gdb_set_reg, - 17, "arm-vfp.xml", 0); + gdb_find_static_feature("arm-vfp.xml"), 0); } if (!arm_feature(env, ARM_FEATURE_M)) { /* @@ -538,29 +541,28 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) * expose to gdb. */ gdb_register_coprocessor(cs, vfp_gdb_get_sysreg, vfp_gdb_set_sysreg, - 2, "arm-vfp-sysregs.xml", 0); + gdb_find_static_feature("arm-vfp-sysregs.xml"), + 0); } } if (cpu_isar_feature(aa32_mve, cpu) && tcg_enabled()) { gdb_register_coprocessor(cs, mve_gdb_get_reg, mve_gdb_set_reg, - 1, "arm-m-profile-mve.xml", 0); + gdb_find_static_feature("arm-m-profile-mve.xml"), + 0); } gdb_register_coprocessor(cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, - arm_gen_dynamic_sysreg_feature(cs)->num_regs, - "system-registers.xml", 0); + arm_gen_dynamic_sysreg_feature(cs), 0); #ifdef CONFIG_TCG if (arm_feature(env, ARM_FEATURE_M) && tcg_enabled()) { gdb_register_coprocessor(cs, arm_gdb_get_m_systemreg, arm_gdb_set_m_systemreg, - arm_gen_dynamic_m_systemreg_feature(cs)->num_regs, - "arm-m-system.xml", 0); + arm_gen_dynamic_m_systemreg_feature(cs), 0); #ifndef CONFIG_USER_ONLY if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { gdb_register_coprocessor(cs, arm_gdb_get_m_secextreg, arm_gdb_set_m_secextreg, - arm_gen_dynamic_m_secextreg_feature(cs)->num_regs, - "arm-m-secext.xml", 0); + arm_gen_dynamic_m_secextreg_feature(cs), 0); } #endif } diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index b54162cbeb..6732efc5de 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -342,8 +342,7 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp) gdb_register_coprocessor(cs, hexagon_hvx_gdb_read_register, hexagon_hvx_gdb_write_register, - NUM_VREGS + NUM_QREGS, - "hexagon-hvx.xml", 0); + gdb_find_static_feature("hexagon-hvx.xml"), 0); qemu_init_vcpu(cs); cpu_reset(cs); diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c index 0752fff924..2886b106bb 100644 --- a/target/loongarch/gdbstub.c +++ b/target/loongarch/gdbstub.c @@ -101,5 +101,5 @@ static int loongarch_gdb_set_fpu(CPULoongArchState *env, void loongarch_cpu_register_gdb_regs_for_features(CPUState *cs) { gdb_register_coprocessor(cs, loongarch_gdb_get_fpu, loongarch_gdb_set_fpu, - 41, "loongarch-fpu.xml", 0); + gdb_find_static_feature("loongarch-fpu.xml"), 0); } diff --git a/target/m68k/helper.c b/target/m68k/helper.c index 0a1544cd68..675f2dcd5a 100644 --- a/target/m68k/helper.c +++ b/target/m68k/helper.c @@ -152,10 +152,10 @@ void m68k_cpu_init_gdb(M68kCPU *cpu) if (m68k_feature(env, M68K_FEATURE_CF_FPU)) { gdb_register_coprocessor(cs, cf_fpu_gdb_get_reg, cf_fpu_gdb_set_reg, - 11, "cf-fp.xml", 18); + gdb_find_static_feature("cf-fp.xml"), 18); } else if (m68k_feature(env, M68K_FEATURE_FPU)) { - gdb_register_coprocessor(cs, m68k_fpu_gdb_get_reg, - m68k_fpu_gdb_set_reg, 11, "m68k-fp.xml", 18); + gdb_register_coprocessor(cs, m68k_fpu_gdb_get_reg, m68k_fpu_gdb_set_reg, + gdb_find_static_feature("m68k-fp.xml"), 18); } /* TODO: Add [E]MAC registers. */ } diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c index 47f37c2519..c804622ab9 100644 --- a/target/microblaze/cpu.c +++ b/target/microblaze/cpu.c @@ -298,8 +298,9 @@ static void mb_cpu_initfn(Object *obj) cpu_set_cpustate_pointers(cpu); gdb_register_coprocessor(CPU(cpu), mb_cpu_gdb_read_stack_protect, - mb_cpu_gdb_write_stack_protect, 2, - "microblaze-stack-protect.xml", 0); + mb_cpu_gdb_write_stack_protect, + gdb_find_static_feature("microblaze-stack-protect.xml"), + 0); set_float_rounding_mode(float_round_nearest_even, &env->fp_status); diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index 0ef484dbee..70cac919e0 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -585,22 +585,23 @@ void ppc_gdb_init(CPUState *cs, PowerPCCPUClass *pcc) { if (pcc->insns_flags & PPC_FLOAT) { gdb_register_coprocessor(cs, gdb_get_float_reg, gdb_set_float_reg, - 33, "power-fpu.xml", 0); + gdb_find_static_feature("power-fpu.xml"), 0); } if (pcc->insns_flags & PPC_ALTIVEC) { gdb_register_coprocessor(cs, gdb_get_avr_reg, gdb_set_avr_reg, - 34, "power-altivec.xml", 0); + gdb_find_static_feature("power-altivec.xml"), + 0); } if (pcc->insns_flags & PPC_SPE) { gdb_register_coprocessor(cs, gdb_get_spe_reg, gdb_set_spe_reg, - 34, "power-spe.xml", 0); + gdb_find_static_feature("power-spe.xml"), 0); } if (pcc->insns_flags2 & PPC2_VSX) { gdb_register_coprocessor(cs, gdb_get_vsx_reg, gdb_set_vsx_reg, - 32, "power-vsx.xml", 0); + gdb_find_static_feature("power-vsx.xml"), 0); } #ifndef CONFIG_USER_ONLY gdb_register_coprocessor(cs, gdb_get_spr_reg, gdb_set_spr_reg, - pcc->gdb_spr.num_regs, "power-spr.xml", 0); + &pcc->gdb_spr, 0); #endif } diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index fb8d92bcbe..a2ec9a3701 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -303,28 +303,31 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) CPURISCVState *env = &cpu->env; if (env->misa_ext & RVD) { gdb_register_coprocessor(cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu, - 32, "riscv-64bit-fpu.xml", 0); + gdb_find_static_feature("riscv-64bit-fpu.xml"), + 0); } else if (env->misa_ext & RVF) { gdb_register_coprocessor(cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu, - 32, "riscv-32bit-fpu.xml", 0); + gdb_find_static_feature("riscv-32bit-fpu.xml"), + 0); } if (env->misa_ext & RVV) { gdb_register_coprocessor(cs, riscv_gdb_get_vector, riscv_gdb_set_vector, - ricsv_gen_dynamic_vector_feature(cs)->num_regs, - "riscv-vector.xml", 0); + ricsv_gen_dynamic_vector_feature(cs), 0); } switch (env->misa_mxl_max) { case MXL_RV32: gdb_register_coprocessor(cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, - 1, "riscv-32bit-virtual.xml", 0); + gdb_find_static_feature("riscv-32bit-virtual.xml"), + 0); break; case MXL_RV64: case MXL_RV128: gdb_register_coprocessor(cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, - 1, "riscv-64bit-virtual.xml", 0); + gdb_find_static_feature("riscv-64bit-virtual.xml"), + 0); break; default: g_assert_not_reached(); @@ -332,7 +335,6 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) if (cpu->cfg.ext_icsr) { gdb_register_coprocessor(cs, riscv_gdb_get_csr, riscv_gdb_set_csr, - riscv_gen_dynamic_csr_feature(cs)->num_regs, - "riscv-csr.xml", 0); + riscv_gen_dynamic_csr_feature(cs), 0); } } diff --git a/target/s390x/gdbstub.c b/target/s390x/gdbstub.c index 6fbfd41bc8..02c388dc32 100644 --- a/target/s390x/gdbstub.c +++ b/target/s390x/gdbstub.c @@ -69,8 +69,6 @@ int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) /* the values represent the positions in s390-acr.xml */ #define S390_A0_REGNUM 0 #define S390_A15_REGNUM 15 -/* total number of registers in s390-acr.xml */ -#define S390_NUM_AC_REGS 16 static int cpu_read_ac_reg(CPUS390XState *env, GByteArray *buf, int n) { @@ -98,8 +96,6 @@ static int cpu_write_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n) #define S390_FPC_REGNUM 0 #define S390_F0_REGNUM 1 #define S390_F15_REGNUM 16 -/* total number of registers in s390-fpr.xml */ -#define S390_NUM_FP_REGS 17 static int cpu_read_fp_reg(CPUS390XState *env, GByteArray *buf, int n) { @@ -132,8 +128,6 @@ static int cpu_write_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n) #define S390_V15L_REGNUM 15 #define S390_V16_REGNUM 16 #define S390_V31_REGNUM 31 -/* total number of registers in s390-vx.xml */ -#define S390_NUM_VREGS 32 static int cpu_read_vreg(CPUS390XState *env, GByteArray *buf, int n) { @@ -172,8 +166,6 @@ static int cpu_write_vreg(CPUS390XState *env, uint8_t *mem_buf, int n) /* the values represent the positions in s390-cr.xml */ #define S390_C0_REGNUM 0 #define S390_C15_REGNUM 15 -/* total number of registers in s390-cr.xml */ -#define S390_NUM_C_REGS 16 #ifndef CONFIG_USER_ONLY static int cpu_read_c_reg(CPUS390XState *env, GByteArray *buf, int n) @@ -206,8 +198,6 @@ static int cpu_write_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n) #define S390_VIRT_CPUTM_REGNUM 1 #define S390_VIRT_BEA_REGNUM 2 #define S390_VIRT_PREFIX_REGNUM 3 -/* total number of registers in s390-virt.xml */ -#define S390_NUM_VIRT_REGS 4 static int cpu_read_virt_reg(CPUS390XState *env, GByteArray *mem_buf, int n) { @@ -254,8 +244,6 @@ static int cpu_write_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n) #define S390_VIRT_KVM_PFT_REGNUM 1 #define S390_VIRT_KVM_PFS_REGNUM 2 #define S390_VIRT_KVM_PFC_REGNUM 3 -/* total number of registers in s390-virt-kvm.xml */ -#define S390_NUM_VIRT_KVM_REGS 4 static int cpu_read_virt_kvm_reg(CPUS390XState *env, GByteArray *mem_buf, int n) { @@ -303,8 +291,6 @@ static int cpu_write_virt_kvm_reg(CPUS390XState *env, uint8_t *mem_buf, int n) #define S390_GS_GSD_REGNUM 1 #define S390_GS_GSSM_REGNUM 2 #define S390_GS_GSEPLA_REGNUM 3 -/* total number of registers in s390-gs.xml */ -#define S390_NUM_GS_REGS 4 static int cpu_read_gs_reg(CPUS390XState *env, GByteArray *buf, int n) { @@ -322,33 +308,33 @@ void s390_cpu_gdb_init(CPUState *cs) { gdb_register_coprocessor(cs, cpu_read_ac_reg, cpu_write_ac_reg, - S390_NUM_AC_REGS, "s390-acr.xml", 0); + gdb_find_static_feature("s390-acr.xml"), 0); gdb_register_coprocessor(cs, cpu_read_fp_reg, cpu_write_fp_reg, - S390_NUM_FP_REGS, "s390-fpr.xml", 0); + gdb_find_static_feature("s390-fpr.xml"), 0); gdb_register_coprocessor(cs, cpu_read_vreg, cpu_write_vreg, - S390_NUM_VREGS, "s390-vx.xml", 0); + gdb_find_static_feature("s390-vx.xml"), 0); gdb_register_coprocessor(cs, cpu_read_gs_reg, cpu_write_gs_reg, - S390_NUM_GS_REGS, "s390-gs.xml", 0); + gdb_find_static_feature("s390-gs.xml"), 0); #ifndef CONFIG_USER_ONLY gdb_register_coprocessor(cs, cpu_read_c_reg, cpu_write_c_reg, - S390_NUM_C_REGS, "s390-cr.xml", 0); + gdb_find_static_feature("s390-cr.xml"), 0); gdb_register_coprocessor(cs, cpu_read_virt_reg, cpu_write_virt_reg, - S390_NUM_VIRT_REGS, "s390-virt.xml", 0); + gdb_find_static_feature("s390-virt.xml"), 0); if (kvm_enabled()) { gdb_register_coprocessor(cs, cpu_read_virt_kvm_reg, cpu_write_virt_kvm_reg, - S390_NUM_VIRT_KVM_REGS, "s390-virt-kvm.xml", + gdb_find_static_feature("s390-virt-kvm.xml"), 0); } #endif From patchwork Wed Aug 16 13:39:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=KHgEaARY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq7s0tqDz1yNr for ; Wed, 16 Aug 2023 23:42:33 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGmo-0006zp-AE; Wed, 16 Aug 2023 09:42:11 -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 1qWGmj-0006rp-8u for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:05 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGmh-0001OE-0l for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:05 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6887b3613e4so810148b3a.3 for ; Wed, 16 Aug 2023 06:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193322; x=1692798122; 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=06lruvuER2JmmjzWPkvhn7tl3HrqMHtHO/EfWEPYAug=; b=KHgEaARYbzVy5//3CQO+8mLbySWKl5KXD+/DxQlrlW3n1VVyT/EX5Jk+/dYZVxlx/Z mFKdLnoV2S8qJ+wZ6OQsTgSf6ZhIPNq5WNdT6KTMPPYtl1Y5IWF6ajl5fKq62/O32/KC 6xTCakQxdKWmHrYyqOvF460ZMAXqpxj72A5OzoCbAce5e76z3yzMiDp7OHh0WEU+Ljo3 4SZV3Xw/ogdAE7MVsxQQ8Q7j8C3UHy94NWymKV6/CuYLkDtQidttqd0AlK516b5HecAT wahBy8I+XtGqybbRBEGhNBh8AR7EbP0MLy86veISNKqUoCPAv2iecGgP/tV/YFD4+6Vf dxrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193322; x=1692798122; 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=06lruvuER2JmmjzWPkvhn7tl3HrqMHtHO/EfWEPYAug=; b=PsA5wbfdWINFkbsQPeVGKUadbzd19lUC2YcodD/NmRMVnjMvgK9AU/wqqyNwtt3Iu5 WREh5HmKYmOT4DN+k35Sc6cv81d4HZtpYQ13yvY3NalTW7o2LAIDXowc7dsqgSsMiqK0 VeqK0yCXub7vp6R+UFZx9Bk3id/YzM4gG1dFLzjBAT3wWznfCPjSHoGNhyepkj+PLFOg xmngNuLqG1fMKfrJvrccWdrIHQJvwv/wDbbMtetPEViKVmGBxxf8dwmxAiElW4fVSxmB QIlRKQVAz0Uz68uqbEDDitccQ2di7rOGatnrK3hb14VJHIoK0iETexFWOgTzlDvO5DL6 fsfQ== X-Gm-Message-State: AOJu0YwrDSeFbMekX+CBksDocGvM3oX3S9ADtE5rdQhnV8xUU0rhUdkZ URCbjxz+NwWNyNkqsxiohmkg1A== X-Google-Smtp-Source: AGHT+IGNro2yIoJ0WZ8sctDWlgSib5Lb+HgRigNfIkyW3NPrJXQ8shmsCYWNtyqJjfol+h5imo2xtw== X-Received: by 2002:a05:6a20:2587:b0:134:1011:8582 with SMTP id k7-20020a056a20258700b0013410118582mr2718835pzd.47.1692193321696; Wed, 16 Aug 2023 06:42:01 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:42:01 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 12/25] gdbstub: Use GDBFeature for GDBRegisterState Date: Wed, 16 Aug 2023 22:39:22 +0900 Message-ID: <20230816133938.18310-13-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42d.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Simplify GDBRegisterState by replacing num_regs and xml members with one member that points to GDBFeature. Signed-off-by: Akihiko Odaki --- gdbstub/gdbstub.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 7fa4b8b51f..7a4775633e 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -47,10 +47,9 @@ typedef struct GDBRegisterState { int base_reg; - int num_regs; gdb_get_reg_cb get_reg; gdb_set_reg_cb set_reg; - const char *xml; + const GDBFeature *feature; struct GDBRegisterState *next; } GDBRegisterState; @@ -390,7 +389,7 @@ static const char *get_feature_xml(const char *p, const char **newp, pstrcat(buf, buf_sz, "\"/>"); for (r = cpu->gdb_regs; r; r = r->next) { pstrcat(buf, buf_sz, "xml); + pstrcat(buf, buf_sz, r->feature->xmlname); pstrcat(buf, buf_sz, "\"/>"); } pstrcat(buf, buf_sz, ""); @@ -497,7 +496,7 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) } for (r = cpu->gdb_regs; r; r = r->next) { - if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { + if (r->base_reg <= reg && reg < r->base_reg + r->feature->num_regs) { return r->get_reg(env, buf, reg - r->base_reg); } } @@ -515,7 +514,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) } for (r = cpu->gdb_regs; r; r = r->next) { - if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { + if (r->base_reg <= reg && reg < r->base_reg + r->feature->num_regs) { return r->set_reg(env, mem_buf, reg - r->base_reg); } } @@ -538,17 +537,16 @@ void gdb_register_coprocessor(CPUState *cpu, p = &cpu->gdb_regs; while (*p) { /* Check for duplicates. */ - if (strcmp((*p)->xml, feature->xmlname) == 0) + if ((*p)->feature == feature) return; p = &(*p)->next; } s = g_new0(GDBRegisterState, 1); s->base_reg = cpu->gdb_num_regs; - s->num_regs = feature->num_regs; s->get_reg = get_reg; s->set_reg = set_reg; - s->xml = feature->xml; + s->feature = feature; /* Add to end of list. */ cpu->gdb_num_regs += feature->num_regs; From patchwork Wed Aug 16 13:39:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821816 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=RXtGwsg5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQq9217tYz1yNr for ; Wed, 16 Aug 2023 23:43:34 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGnF-0007dc-Ak; Wed, 16 Aug 2023 09:42:37 -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 1qWGn1-0007Ck-BP for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:28 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGms-0001SN-Hp for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:22 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-688779ffcfdso993024b3a.1 for ; Wed, 16 Aug 2023 06:42:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193331; x=1692798131; 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=9A/irVSRNTDRyAMd8tbb4ofq2py6oa1gC/mUH/zNkC4=; b=RXtGwsg5pby9WTBTMSsEUOHX7sR8mLpM2Lm2Q4IXOwDl7Lj+f5ugcnwaws56/pXC30 OknE6+WKhDh/W1eUTobkq9Znfdrl5CvzPRMFYcv/HpIesCOziGVogfELde7eswNfkwdH oSLHGS+Iczk7MCSwAgEsaoAYTXGcCHRwpR9if+pu3Zdpg8uLEjVgPHHEMvvkLG9TkJCw 2EJBPyLUjWZMAAuO2HO40QxZa2LEsgKqmqsRLUICjLimlfethuBPGcPqQnrdBoWyR0NF U0F8yJixoNdmDfXBDbuFN+nXx94w8LN9K3lepo9HHpKhZQUoDLBV2yfJ2U0LNSg8wPO7 tdGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193331; x=1692798131; 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=9A/irVSRNTDRyAMd8tbb4ofq2py6oa1gC/mUH/zNkC4=; b=U4mrz5zfxtaA8b9zUNE9ceC8wj9Sgp/zyQKClRKVT4SsVJAPt7nGuXgijbJwfnccA+ GIbPNyoT/e9rzGNLa80Y6dKwnC0TwbefnMp7lUeVpaTyhMxQ+cJYyTvw8u3ACGu41bdW iURNz1mJZZROugx6b4q1G5jo4EWIcNP4pz/qy+TTGnfxagZ+xO3RJO6hO+2yREE6YIlB NrTyxLE0HMrOYF+cAAwEaIB7yDfuSEOzsBw0L7qO339eeFNmZApT/FAPdzF1EMJOdBSa BUhy3Gyf3SeIY6d+tAYB3+OCWjbyOvOeV9UXSFKTraeHbfXx59gUAg6xXkVIE9PXHWET j8HA== X-Gm-Message-State: AOJu0YyOm81zkNULyl2yKF9AVX9lQqEEdfUDOph8yTYsW18FWNFzpB3K 2pOdunPcdqmb4Te/kG/hcOQOgQ== X-Google-Smtp-Source: AGHT+IGMnsNwR3XxlKpzLxkw5OnepSQkNyPIWR8D/6668xVGijq4J2qWt1gSnf3Nh8JrSJOdcwC7uQ== X-Received: by 2002:a05:6a20:3d95:b0:13d:315f:26b7 with SMTP id s21-20020a056a203d9500b0013d315f26b7mr2238965pzi.1.1692193331082; Wed, 16 Aug 2023 06:42:11 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:42:10 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 13/25] hw/core/cpu: Return static value with gdb_arch_name() Date: Wed, 16 Aug 2023 22:39:23 +0900 Message-ID: <20230816133938.18310-14-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42e.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- include/hw/core/cpu.h | 2 +- target/ppc/internal.h | 2 +- gdbstub/gdbstub.c | 4 +--- target/arm/cpu.c | 6 +++--- target/arm/cpu64.c | 4 ++-- target/i386/cpu.c | 6 +++--- target/loongarch/cpu.c | 4 ++-- target/ppc/gdbstub.c | 6 +++--- target/riscv/cpu.c | 6 +++--- target/s390x/cpu.c | 4 ++-- target/tricore/cpu.c | 4 ++-- 11 files changed, 23 insertions(+), 25 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 84219c1885..09f1aca624 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 GDBFeature *gdb_core_feature; - 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 57acb3212c..974b37aa60 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 7a4775633e..c2ce970c98 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -378,11 +378,9 @@ static const char *get_feature_xml(const char *p, const char **newp, "" ""); if (cc->gdb_arch_name) { - gchar *arch = cc->gdb_arch_name(cpu); pstrcat(buf, buf_sz, ""); - pstrcat(buf, buf_sz, arch); + pstrcat(buf, buf_sz, cc->gdb_arch_name(cpu)); pstrcat(buf, buf_sz, ""); - g_free(arch); } pstrcat(buf, buf_sz, "gdb_core_feature->xmlname); diff --git a/target/arm/cpu.c b/target/arm/cpu.c index a206ab6b1b..5f07133419 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2281,15 +2281,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 9c2a226159..65f84bfb18 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -743,9 +743,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 069410985f..c1a7667f4a 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5910,12 +5910,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 b204cb279d..6c76d14e43 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -692,9 +692,9 @@ static const struct SysemuCPUOps loongarch_sysemu_ops = { }; #endif -static gchar *loongarch_gdb_arch_name(CPUState *cs) +static const gchar *loongarch_gdb_arch_name(CPUState *cs) { - return g_strdup("loongarch64"); + return "loongarch64"; } static void loongarch_cpu_class_init(ObjectClass *c, void *data) diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index 70cac919e0..dbdee7d56e 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -572,12 +572,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 ceca40cdd9..86a477bfc0 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1941,17 +1941,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 2a2ff8cbdc..ca356c2b86 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -284,9 +284,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 133a9ac70e..44e3ba6f0e 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) From patchwork Wed Aug 16 13:39:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=dL0piSXX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqFd6D9Vz1yNm for ; Wed, 16 Aug 2023 23:47:33 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGnH-0007ui-49; Wed, 16 Aug 2023 09:42:39 -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 1qWGn5-0007EL-47 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:28 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGn1-0001W3-4G for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:25 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-68874269df4so1064336b3a.2 for ; Wed, 16 Aug 2023 06:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193340; x=1692798140; 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=LoU2pS/znq+kjt+yrgvrxMpANXrwQzKAPttvmhpfpts=; b=dL0piSXXpBJvuNXShqVnu09g1FrmM45clKUEBwID7vM0Z9U06VBkhTlyPwVmE9naWP oazBoP9wnM5Pthb6ZpU4+w4b5SKxa+vljLaQgZ/mbEiePaUTqGK3Hh8CEWA66PgXlb3x Td972ZLI3rJ2IWpzjMEFkKzRQagAkSORs0uoayv967cE6aPZLc6kDRLYVXM0d0z4Jwgc 2UkvnHqhzA8eQ9snjyeUpuSmVLyi+Jm+E0IxjH5B6L2rpP+5QOVV8gMdNUzvvAoh3SeX tbehLN4Y5EGzwLvwOfN7o29dbhaHHnSlyPTmAHbvA6V4+vRFamvOrZx4fbXJatEFx6Tj Goug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193340; x=1692798140; 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=LoU2pS/znq+kjt+yrgvrxMpANXrwQzKAPttvmhpfpts=; b=C2Rf0pNylTAHIyOVS8BYs2k6htWH9aG1HXIKlRldxkZ3Q628PGi/I9Z6RXyvYE9Yd+ OeAMoQAkcZ7SXaMhxTIuu96lVma8BzqaFwMi+qDndBLmq/KT683Qv+ZkYcnkrjCxijIJ ZbI7ENsv2VNYqLPvIOlV66ltlEpfSyDW5roAdN86/okbHeLP8hPXR4X2wTDBsu6dDwbM 74hBEs9ox/qx5I1sFAXupHzaGDJeDmzeLc1t6svE18YR1czaRk1XVQ2Rzdo3ci6cxJJA Lx+Uq/p4dRUxC+cfp5MGXNYgnm8Z9D2rGeUAHiMYm+dU+q7XUABqt8/nux0HZiciZWpR 1NBA== X-Gm-Message-State: AOJu0YwKHD4+SgKISc1557AXwUrj9qLoHtwrX5V0JyV/Z3Dp50GeA3go 2QFvOcXtSKmdxvlGH/KNW7kWcQ== X-Google-Smtp-Source: AGHT+IFLp2aEC2TKIdJM1ahnC1nevUCd8qPpGWVeOoVFE918g8rIKGLF3x7hTxd7IWZjmNejkW0fRA== X-Received: by 2002:a05:6a21:35c8:b0:143:51ee:b142 with SMTP id ba8-20020a056a2135c800b0014351eeb142mr1735537pzc.59.1692193340436; Wed, 16 Aug 2023 06:42:20 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.42.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:42:20 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 14/25] gdbstub: Dynamically allocate target.xml buffer Date: Wed, 16 Aug 2023 22:39:24 +0900 Message-ID: <20230816133938.18310-15-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org There is no guarantee that target.xml fits in 1024 bytes, and the fixed buffer length requires tedious buffer overflow check. Dynamically allocate the target.xml buffer to resolve these problems. Suggested-by: Alex Bennée Signed-off-by: Akihiko Odaki --- gdbstub/internals.h | 2 +- gdbstub/gdbstub.c | 44 ++++++++++++++++++++++++-------------------- gdbstub/softmmu.c | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index f2b46cce41..4876ebd74f 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -33,7 +33,7 @@ typedef struct GDBProcess { uint32_t pid; bool attached; - char target_xml[1024]; + char *target_xml; } GDBProcess; enum RSState { diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index c2ce970c98..452b5bf0ef 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -366,33 +366,37 @@ static const char *get_feature_xml(const char *p, const char **newp, name = NULL; if (strncmp(p, "target.xml", len) == 0) { - char *buf = process->target_xml; - const size_t buf_sz = sizeof(process->target_xml); - /* Generate the XML description for this CPU. */ - if (!buf[0]) { + if (!process->target_xml) { + g_autoptr(GPtrArray) a = g_ptr_array_new_with_free_func(g_free); GDBRegisterState *r; - pstrcat(buf, buf_sz, - "" - "" - ""); + g_ptr_array_add( + a, + g_strdup("" + "" + "")); if (cc->gdb_arch_name) { - pstrcat(buf, buf_sz, ""); - pstrcat(buf, buf_sz, cc->gdb_arch_name(cpu)); - pstrcat(buf, buf_sz, ""); + g_ptr_array_add( + a, + g_markup_printf_escaped("%s", + cc->gdb_arch_name(cpu))); } - pstrcat(buf, buf_sz, "gdb_core_feature->xmlname); - pstrcat(buf, buf_sz, "\"/>"); + g_ptr_array_add( + a, + g_markup_printf_escaped("", + cc->gdb_core_feature->xmlname)); for (r = cpu->gdb_regs; r; r = r->next) { - pstrcat(buf, buf_sz, "feature->xmlname); - pstrcat(buf, buf_sz, "\"/>"); + g_ptr_array_add( + a, + g_markup_printf_escaped("", + r->feature->xmlname)); } - pstrcat(buf, buf_sz, ""); + g_ptr_array_add(a, g_strdup("")); + g_ptr_array_add(a, NULL); + process->target_xml = g_strjoinv(NULL, (void *)a->pdata); } - return buf; + return process->target_xml; } if (cc->gdb_get_dynamic_xml) { char *xmlname = g_strndup(p, len); @@ -2270,6 +2274,6 @@ void gdb_create_default_process(GDBState *s) process = &s->processes[s->process_num - 1]; process->pid = pid; process->attached = false; - process->target_xml[0] = '\0'; + process->target_xml = NULL; } diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index f509b7285d..5282324764 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -293,7 +293,7 @@ static int find_cpu_clusters(Object *child, void *opaque) assert(cluster->cluster_id != UINT32_MAX); process->pid = cluster->cluster_id + 1; process->attached = false; - process->target_xml[0] = '\0'; + process->target_xml = NULL; return 0; } From patchwork Wed Aug 16 13:39:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=0ASrDq0r; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqDR35W2z1yNm for ; Wed, 16 Aug 2023 23:46:31 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGnG-0007tV-Pr; Wed, 16 Aug 2023 09:42:38 -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 1qWGnD-0007PL-Bt for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:35 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGn9-0001dd-CO for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:35 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bda9207132so51997135ad.0 for ; Wed, 16 Aug 2023 06:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193349; x=1692798149; 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=43Yk2hXc6r+OrDwdQwqhs9KvazgS/8QnDpHDJGpmDuU=; b=0ASrDq0r9JysnWjn9k1w4ooZZqYKSKcLGqqvkvzezH2N09UIG4iehrElXzPXHOnkQB S4cig/tcVryiytc5Z3HGOrRuVAjrrS3Ab39DN/xmqlpmpofznpHyeDSEX/wFRk4VReCn 34/mqHbQ60UpZyH629jX0X6MzqPCZ5k8LbYlt2GnSfBac1scSM2ANxO8n4gtH1F11ygC 61qESBXy6bmx+EMUjGqg6dW9GQ53miBycB0v9EvoOLQJKDbpLJZKmZdUx5RoxGWy0e/U skPiQT2ldMYz7BWAes1ON64aOc+UjRXh+/SIpT4V5qD1Sf1DH5yHlsLB3dhzkWhh9/we rWXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193349; x=1692798149; 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=43Yk2hXc6r+OrDwdQwqhs9KvazgS/8QnDpHDJGpmDuU=; b=WdhSTt2AlzLwfFsc1m9kO0x+gNB2O+mMVbbS3+UzZpueKCEZJOhKODEZEu0M5Lbksu yjZB1oW1xkhHbBEafgTQrxclx2kEz24Bda230TAPWg7Ppop/WQPXUvVm+Rlx1i3oUwzh NiIAmy0DJTZP2UEcqan/6l8leEnWi4uyd7WFR3DLjw8eZbp7cawWd/hN2kICAlSdYzNS rdnITnZgZtuLCsXxm0oKPvWiCW5O/gy441YSd/FmWQligiOR5NAILr5cqCZ3UOvkOq5g 0lsIjmjP5rvGCQyOnD3tBKuzjjETxJB+OdCyEkGHSgeqwURjn464c/bO7ylpY+1Ua4h1 /0Aw== X-Gm-Message-State: AOJu0YwE4KIEoyChCxsbUOhDO8mhxENOEXGib8Vx+Q+OLuEIV+FT6Q2h p34CKD3Oz7hG//5pZUdErxlHaA== X-Google-Smtp-Source: AGHT+IE2yHozSLxxdi7bHea3fIA9c6K4gdSPYAbmb7Ge/3f7H0CfUdDz5XgUsWgHwnrb7J1kutikAQ== X-Received: by 2002:a17:902:ef92:b0:1bb:c69b:6f6b with SMTP id iz18-20020a170902ef9200b001bbc69b6f6bmr1686515plb.6.1692193349728; Wed, 16 Aug 2023 06:42:29 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:42:29 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 15/25] gdbstub: Simplify XML lookup Date: Wed, 16 Aug 2023 22:39:25 +0900 Message-ID: <20230816133938.18310-16-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::62b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Now we know all instances of GDBFeature that is used in CPU so we can traverse them to find XML. This removes the need for a CPU-specific lookup function for dynamic XMLs. Signed-off-by: Akihiko Odaki --- gdbstub/gdbstub.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 452b5bf0ef..ccb4ed9d4b 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -354,8 +354,7 @@ static const char *get_feature_xml(const char *p, const char **newp, GDBProcess *process) { size_t len; - int i; - const char *name; + GDBRegisterState *r; CPUState *cpu = gdb_get_first_cpu_in_process(process); CPUClass *cc = CPU_GET_CLASS(cpu); @@ -364,7 +363,6 @@ static const char *get_feature_xml(const char *p, const char **newp, len++; *newp = p + len; - name = NULL; if (strncmp(p, "target.xml", len) == 0) { /* Generate the XML description for this CPU. */ if (!process->target_xml) { @@ -398,21 +396,15 @@ static const char *get_feature_xml(const char *p, const char **newp, } return process->target_xml; } - if (cc->gdb_get_dynamic_xml) { - char *xmlname = g_strndup(p, len); - const char *xml = cc->gdb_get_dynamic_xml(cpu, xmlname); - - g_free(xmlname); - if (xml) { - return xml; - } + if (strncmp(p, cc->gdb_core_feature->xmlname, len) == 0) { + return cc->gdb_core_feature->xml; } - for (i = 0; ; i++) { - name = gdb_static_features[i].xmlname; - if (!name || (strncmp(name, p, len) == 0 && strlen(name) == len)) - break; + for (r = cpu->gdb_regs; r; r = r->next) { + if (strncmp(p, r->feature->xmlname, len) == 0) { + return r->feature->xml; + } } - return name ? gdb_static_features[i].xml : NULL; + return NULL; } void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature, From patchwork Wed Aug 16 13:39:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=uA0vbzOg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqJK1gtTz1yNm for ; Wed, 16 Aug 2023 23:49:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGnV-0000Bw-Hw; Wed, 16 Aug 2023 09:42:55 -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 1qWGnK-0008MY-Rg for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:44 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGnI-0001jn-4O for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:42 -0400 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3a76d882080so5531789b6e.2 for ; Wed, 16 Aug 2023 06:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193359; x=1692798159; 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=GG+pfP5pv1xqEwFfnKQ6TBE99udBp33hdNPK6bQ51/o=; b=uA0vbzOgFggojb8JrPdDIKFavnBv6DhcL4VpCB9FkJKsvQwcOSS3+/+IjGhy3eZ3YL ByJIKryICXjUWC8AgMJB0UEn+XR5KPktTG3gPay2oj/INxp7cn7k0mkKfGRZEnOiShai TKKGdIiNyN7lbb81DAQzJw/82G95hWrzBNZHagMJFjoVvwjA6viSiu7NnPIhVuJ/a6c6 /qheRwJYLkMouejPkvDt3n2fyLty73MdNNxG+cdZgdgWhsqtdqgpThSR2IQSLBNSG79O riQ2zjaykLK1kxGXu+y8cSgUrROYHLSRx5ZSuC4cKP+C/71KQ73SuZB6av0p34KDO1eB 0EQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193359; x=1692798159; 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=GG+pfP5pv1xqEwFfnKQ6TBE99udBp33hdNPK6bQ51/o=; b=j2PkcUw9HQaSEFKrk7l8r75MLBGykYoA1NjjKR+XIYD1Vd/F179AT1eXgkDmiawhGZ rB4r5lrWKhvc7SGcApD1ZC1S13tj4Lft0iQn6HFUBu6O6K9jAEY2Cd/YmJT6d9YbQUyM Cz2AklzImq3kz4NMTFP6QB2SI5dtgKyFlJwmDUKYDDW58TTTRP17X5C0Ji5Akk9dr2Dm xUTKCP0GXJvb3d/cuxTkTLS+f5WhCdkAt5lsmB0Mve3VCBqCzXaI8OPz4nXkk9kyEpfU CEpyIsD8hB9beJYbIpL+dZlcFRE4dR99aadev8TrtX6/S9RkbGTkNeIykaVmNCRhDR1p 8NcA== X-Gm-Message-State: AOJu0Yzr+Ayrx/omBujuBNi44RABkK3H1xMxqRUhTmGUEzqd2M9fN3Ew g4s4oRHtT8B6fs2fWSaXXm90EA== X-Google-Smtp-Source: AGHT+IGg3SNEbeCVRAXr+lJ0fXMsXgM5SH1yyDaMlZwyyj67hiea4W3tXcR4HNOr/fFZEQXky7D43w== X-Received: by 2002:a05:6808:152c:b0:3a7:3ea1:b596 with SMTP id u44-20020a056808152c00b003a73ea1b596mr2780191oiw.47.1692193359017; Wed, 16 Aug 2023 06:42:39 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:42:38 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 16/25] hw/core/cpu: Remove gdb_get_dynamic_xml member Date: Wed, 16 Aug 2023 22:39:26 +0900 Message-ID: <20230816133938.18310-17-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::22c; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22c.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This function is no longer used. Signed-off-by: Akihiko Odaki --- include/hw/core/cpu.h | 4 ---- target/arm/cpu.h | 6 ------ target/ppc/cpu.h | 1 - target/arm/cpu.c | 1 - target/arm/gdbstub.c | 18 ------------------ target/ppc/cpu_init.c | 3 --- target/ppc/gdbstub.c | 10 ---------- target/riscv/cpu.c | 14 -------------- 8 files changed, 57 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 09f1aca624..8fc9a1a140 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -133,9 +133,6 @@ struct SysemuCPUOps; * before the insn which triggers a watchpoint rather than after it. * @gdb_arch_name: Optional callback that returns the architecture name known * to GDB. The caller must free the returned string with g_free. - * @gdb_get_dynamic_xml: Callback to return dynamically generated XML for the - * gdb stub. Returns a pointer to the XML contents for the specified XML file - * or NULL if the CPU doesn't have a dynamically generated content for it. * @disas_set_info: Setup architecture specific components of disassembly info * @adjust_watchpoint_address: Perform a target-specific adjustment to an * address before attempting to match it against watchpoints. @@ -166,7 +163,6 @@ struct CPUClass { const GDBFeature *gdb_core_feature; 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/arm/cpu.h b/target/arm/cpu.h index d6c2378d05..09bf82034d 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1131,12 +1131,6 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, int arm_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); -/* Returns the dynamically generated XML for the gdb stub. - * Returns a pointer to the XML contents for the specified XML file or NULL - * if the XML name doesn't match the predefined one. - */ -const char *arm_gdb_get_dynamic_xml(CPUState *cpu, const char *xmlname); - int arm_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, DumpState *s); int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 5f251bdffe..3dc6e545e3 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1382,7 +1382,6 @@ int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg); #ifndef CONFIG_USER_ONLY hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); void ppc_gdb_gen_spr_feature(PowerPCCPU *cpu); -const char *ppc_gdb_get_dynamic_xml(CPUState *cs, const char *xml_name); #endif int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, DumpState *s); diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 5f07133419..f26c0ded18 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2354,7 +2354,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->sysemu_ops = &arm_sysemu_ops; #endif cc->gdb_arch_name = arm_gdb_arch_name; - cc->gdb_get_dynamic_xml = arm_gdb_get_dynamic_xml; cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = arm_disas_set_info; diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 791784dffe..fc5ed89e80 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -470,24 +470,6 @@ static GDBFeature *arm_gen_dynamic_m_secextreg_feature(CPUState *cs) #endif #endif /* CONFIG_TCG */ -const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) -{ - ARMCPU *cpu = ARM_CPU(cs); - - if (strcmp(xmlname, "system-registers.xml") == 0) { - return cpu->dyn_sysreg_feature.desc.xml; - } else if (strcmp(xmlname, "sve-registers.xml") == 0) { - return cpu->dyn_svereg_feature.desc.xml; - } else if (strcmp(xmlname, "arm-m-system.xml") == 0) { - return cpu->dyn_m_systemreg_feature.desc.xml; -#ifndef CONFIG_USER_ONLY - } else if (strcmp(xmlname, "arm-m-secext.xml") == 0) { - return cpu->dyn_m_secextreg_feature.desc.xml; -#endif - } - return NULL; -} - void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) { CPUState *cs = CPU(cpu); diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 938cd2b7e1..a3153c4e9f 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -7370,9 +7370,6 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) #endif cc->gdb_num_core_regs = 71; -#ifndef CONFIG_USER_ONLY - cc->gdb_get_dynamic_xml = ppc_gdb_get_dynamic_xml; -#endif #ifdef USE_APPLE_GDB cc->gdb_read_register = ppc_cpu_gdb_read_register_apple; cc->gdb_write_register = ppc_cpu_gdb_write_register_apple; diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index dbdee7d56e..c86b7055ca 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -357,16 +357,6 @@ void ppc_gdb_gen_spr_feature(PowerPCCPU *cpu) gdb_feature_builder_end(&builder); } - -const char *ppc_gdb_get_dynamic_xml(CPUState *cs, const char *xml_name) -{ - PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs); - - if (strcmp(xml_name, "power-spr.xml") == 0) { - return pcc->gdb_spr.xml; - } - return NULL; -} #endif #if !defined(CONFIG_USER_ONLY) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 86a477bfc0..e12b6ef7f6 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1957,19 +1957,6 @@ static const gchar *riscv_gdb_arch_name(CPUState *cs) } } -static const char *riscv_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - - if (strcmp(xmlname, "riscv-csr.xml") == 0) { - return cpu->dyn_csr_feature.xml; - } else if (strcmp(xmlname, "riscv-vector.xml") == 0) { - return cpu->dyn_vreg_feature.xml; - } - - return NULL; -} - #ifndef CONFIG_USER_ONLY static int64_t riscv_get_arch_id(CPUState *cs) { @@ -2147,7 +2134,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->get_arch_id = riscv_get_arch_id; #endif cc->gdb_arch_name = riscv_gdb_arch_name; - cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; cc->tcg_ops = &riscv_tcg_ops; object_class_property_add(c, "mvendorid", "uint32", cpu_get_mvendorid, From patchwork Wed Aug 16 13:39:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=p4jIPIW8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqCj1zRzz1yNm for ; Wed, 16 Aug 2023 23:45:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGne-0000gc-EP; Wed, 16 Aug 2023 09:43:02 -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 1qWGnU-0000CF-Gi for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:53 -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 1qWGnR-0001nJ-Ey for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:42:52 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6887ccba675so516253b3a.3 for ; Wed, 16 Aug 2023 06:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193368; x=1692798168; 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=6gfAeaNLA+PIokoYBBdAB0dQ8PQLZuwdbWdYv4LmQmA=; b=p4jIPIW8F7FZ15gXgrZC0bslxfBNgPtWNcSyqtzraoqaroZwOzPaiIInO0TSmMYZzO 9xAqaEfDmfZLwfb0fnEmPtLVcNT+DUGPC5gaywX8DrZ9xm9zvJJCjA47A7K4jQknlo9Q bw55ibQKAIbh2jEjcBVBBUQ+B9oRxSvDmd21LavG8NQCug3VsVYYb7C04lCLDPStO3Ur SUNHiyFzPZcXQkAP1l0Yx2ti90H2QwtO6vSvoT/IJR6nuhxmi081YviOJ6fshy4827Qj XKTVZlG5YmKTwzhJ9yms+S+wW1FS3/eCQpdtxn25EG8JmapGcoacFSG3jht+MVs/91o/ gmtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193368; x=1692798168; 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=6gfAeaNLA+PIokoYBBdAB0dQ8PQLZuwdbWdYv4LmQmA=; b=O3DB5C/18aUkevU/JfJVffBE2p7qS7g7g3/wn6hXec5ll4/El+7KWuULJWaRM5V2Bs 7ZJAsRP3hRxGKj1RqD7ySOTCsswlwbOyU4p0SKoDY39t+lblVE6lfwr++SUBdq2el71i 7GnL1hn7EK9sV+7H1i8nCcNCyPb4ec1rLXRvX9j9VtN0ZY5y/58Papqb87xp0qfEMhjh Z4fysQxmhqVK3fP4A9MAaaArnnnLd1PC7Lsgj0Iy0LHZO3VP9yM0lzlxGa++wd2mw0zu rlXZINcWmwXB5HVPcs8azuTBboOmG7PCKKyVklrRjfXodLGPeVR/jFTF9HYXsqbvOLjh WTFQ== X-Gm-Message-State: AOJu0YxfTZDplzQUwU5ktVJTQ3zCZG1JpjFiF6c9UzKnF7CwUfQq8H/p B3B/gbawgPvcHNFb87+QG3wF6Q== X-Google-Smtp-Source: AGHT+IG/nPYMSYK6MQ6Gu1ZAPxNnHYFIvZlhimH4Pb3Ek6ZXKHGwleUsB56z7RG7mu/EGmUiIRX2Hg== X-Received: by 2002:a05:6a20:258a:b0:125:f3d8:e65b with SMTP id k10-20020a056a20258a00b00125f3d8e65bmr2046108pzd.18.1692193368270; Wed, 16 Aug 2023 06:42:48 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:42:48 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 17/25] gdbstub: Add members to identify registers to GDBFeature Date: Wed, 16 Aug 2023 22:39:27 +0900 Message-ID: <20230816133938.18310-18-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org These members will be used to help plugins to identify registers. The added members in instances of GDBFeature dynamically generated by CPUs will be filled in later changes. Signed-off-by: Akihiko Odaki --- include/exec/gdbstub.h | 3 +++ gdbstub/gdbstub.c | 8 ++++++-- target/arm/gdbstub.c | 2 +- scripts/feature_to_c.py | 14 +++++++++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 572abada63..f3f2c40b1a 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -13,12 +13,15 @@ typedef struct GDBFeature { const char *xmlname; const char *xml; + const char *name; + const char * const *regs; int num_regs; } GDBFeature; typedef struct GDBFeatureBuilder { GDBFeature *feature; GPtrArray *xml; + GPtrArray *regs; } GDBFeatureBuilder; diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index ccb4ed9d4b..e4fbdebca4 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -418,9 +418,10 @@ void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature, builder->feature = feature; builder->xml = g_ptr_array_new(); + builder->regs = g_ptr_array_new(); g_ptr_array_add(builder->xml, header); feature->xmlname = xmlname; - feature->num_regs = 0; + feature->name = name; } void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder, @@ -449,7 +450,7 @@ void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, name, bitsize, type); } - builder->feature->num_regs++; + g_ptr_array_add(builder->regs, (void *)name); } void gdb_feature_builder_end(const GDBFeatureBuilder *builder) @@ -464,6 +465,9 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder) } g_ptr_array_free(builder->xml, TRUE); + + builder->feature->num_regs = builder->regs->len; + builder->feature->regs = (void *)g_ptr_array_free(builder->regs, FALSE); } const GDBFeature *gdb_find_static_feature(const char *xmlname) diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index fc5ed89e80..dbc396a88b 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -264,7 +264,7 @@ static void arm_gen_one_feature_sysreg(GDBFeatureBuilder *builder, ARMCPRegInfo *ri, uint32_t ri_key, int bitsize) { - dyn_feature->data.cpregs.keys[dyn_feature->desc.num_regs] = ri_key; + dyn_feature->data.cpregs.keys[builder->regs->len] = ri_key; gdb_feature_builder_append_reg(builder, ri->name, bitsize, "int", "cp_regs"); diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py index e04d6b2df7..807af0e685 100755 --- a/scripts/feature_to_c.py +++ b/scripts/feature_to_c.py @@ -50,7 +50,9 @@ def writeliteral(indent, bytes): sys.stderr.write(f'unexpected start tag: {element.tag}\n') exit(1) + feature_name = element.attrib['name'] regnum = 0 + regnames = [] regnums = [] tags = ['feature'] for event, element in events: @@ -67,6 +69,7 @@ def writeliteral(indent, bytes): if 'regnum' in element.attrib: regnum = int(element.attrib['regnum']) + regnames.append(element.attrib['name']) regnums.append(regnum) regnum += 1 @@ -85,6 +88,15 @@ def writeliteral(indent, bytes): writeliteral(8, bytes(os.path.basename(input), 'utf-8')) sys.stdout.write(',\n') writeliteral(8, read) - sys.stdout.write(f',\n {num_regs},\n }},\n') + sys.stdout.write(',\n') + writeliteral(8, bytes(feature_name, 'utf-8')) + sys.stdout.write(',\n (const char * const []) {\n') + + for index, regname in enumerate(regnames): + sys.stdout.write(f' [{regnums[index] - base_reg}] =\n') + writeliteral(16, bytes(regname, 'utf-8')) + sys.stdout.write(',\n') + + sys.stdout.write(f' }},\n {num_regs},\n }},\n') sys.stdout.write(' { NULL }\n};\n') From patchwork Wed Aug 16 13:39:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=ArfWnY0n; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqDV1C6rz1yNm for ; Wed, 16 Aug 2023 23:46:34 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGni-0001EC-6f; Wed, 16 Aug 2023 09:43:06 -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 1qWGng-0000yN-3T for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:04 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGnb-00021I-4C for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:03 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6887059f121so1170645b3a.3 for ; Wed, 16 Aug 2023 06:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193378; x=1692798178; 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=DVVdooKF8qtbYGXqlxxO6sXjrL0xj5j1SeLsuJ84KLY=; b=ArfWnY0n1rQCZoJyyGWuLSvMixW26EZm/obCUq5Bfv33MUPLbrFdSzmx1BzJ7sEDPv uWnVthZKDMPsk1M81EzWLezZbq9OGrNFl2DqjeXeyI8kKz9bcTaH1DholTAvinua0WLg ejcW18L4NtADYIltjyTaoelqHVOvUWimaO6SBnzoCN9548P42UTMwA6WW9FlZtl95zTD R3KQZyrxIBzZwV7odTBMJUazOwsWiTK+uiRtkaX6M++ePig8s71IqOQ1X2qFSJLhqa4N hmBG9J/bgFiSxoUvIpKxgihizqbrxHkO3nRBEIWRJu9+6AsoeIkhnOr9V94SSumlvPmv w6/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193378; x=1692798178; 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=DVVdooKF8qtbYGXqlxxO6sXjrL0xj5j1SeLsuJ84KLY=; b=Gn0eQvFhJIMS3YHYqM5K1BStXWTTTo5UA2X8Npzrmm1ncoBa0TM49+lwVSbwSS43jR V+gZ6rVaUoWqIr6/0j6BvRzZ2AW4lO+uK1wsvVwVUFTrP/NAlGbsydis1TYVto+jS5Qh zWbalA15VliPGTv386xK2xvqkRBRsZtfvvKd6JEt/AV0WDs1kFmGasanIHMw9OVSCTXM sjpq32XD6QHLv4rZy8Lsld89Owprl25BC8/0SIEkRV2lKzViWul/VFNAQZDEZJbmgaKG 7jRXWhbtIvNo4OFMrEV4pgjuB+I9ozjnV3Imih+4umFw2EQ+SvZ4XL+2Ug6TnxKNZCWT VESA== X-Gm-Message-State: AOJu0Ywpf3qwZ2c6CPlcwhoM1fh9sSVpnPl0Vk1dPT0chPdNaOxRawlN sIQcD3yDU9mT3qA5EVBJgGSY3w== X-Google-Smtp-Source: AGHT+IGXqcNWv6HNSZwt3pztxZFMxOVMeJoAhLnsboRWfd/DhDuUzaVPwH2+JWJUd7FlqmAq184E6Q== X-Received: by 2002:a05:6a20:d426:b0:122:cb38:636a with SMTP id il38-20020a056a20d42600b00122cb38636amr1646338pzb.33.1692193377725; Wed, 16 Aug 2023 06:42:57 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:42:57 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 18/25] hw/core/cpu: Add a parameter to gdb_read_register/gdb_write_register Date: Wed, 16 Aug 2023 22:39:28 +0900 Message-ID: <20230816133938.18310-19-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org gdbstub has a static variable named gdb_has_xml that tells if workarounds for old GDB versions are required when manipulating registers for GDB. Now we are reusing the infrastructure to manipulate registers for plugins. Plugins will not need these workarounds even when an old GDB is attached. Converting the static variable to a function parameter would allow to apply or not to apply workarounds depending on the context. This change adds the new parameter and replaces references to gdb_has_xml with it. New code to pass different values to the functions will be added later. Signed-off-by: Akihiko Odaki --- include/hw/core/cpu.h | 6 ++++-- target/alpha/cpu.h | 6 ++++-- target/arm/cpu.h | 13 +++++++++---- target/avr/cpu.h | 6 ++++-- target/cris/cpu.h | 9 ++++++--- target/hexagon/internal.h | 6 ++++-- target/hppa/cpu.h | 6 ++++-- target/i386/cpu.h | 6 ++++-- target/loongarch/internals.h | 6 ++++-- target/m68k/cpu.h | 6 ++++-- target/microblaze/cpu.h | 6 ++++-- target/mips/internal.h | 6 ++++-- target/openrisc/cpu.h | 6 ++++-- target/ppc/cpu.h | 12 ++++++++---- target/riscv/cpu.h | 6 ++++-- target/rx/cpu.h | 6 ++++-- target/s390x/s390x-internal.h | 6 ++++-- target/sh4/cpu.h | 6 ++++-- target/sparc/cpu.h | 6 ++++-- target/tricore/cpu.h | 6 ++++-- target/xtensa/cpu.h | 6 ++++-- gdbstub/gdbstub.c | 4 ++-- hw/core/cpu-common.c | 6 ++++-- target/alpha/gdbstub.c | 6 ++++-- target/arm/gdbstub.c | 14 ++++++++------ target/arm/gdbstub64.c | 6 ++++-- target/avr/gdbstub.c | 6 ++++-- target/cris/gdbstub.c | 9 ++++++--- target/hexagon/gdbstub.c | 6 ++++-- target/hppa/gdbstub.c | 6 ++++-- target/i386/gdbstub.c | 10 +++++----- target/loongarch/gdbstub.c | 6 ++++-- target/m68k/gdbstub.c | 6 ++++-- target/microblaze/gdbstub.c | 6 ++++-- target/mips/gdbstub.c | 6 ++++-- target/nios2/cpu.c | 6 ++++-- target/openrisc/gdbstub.c | 6 ++++-- target/ppc/gdbstub.c | 22 +++++++++++++--------- target/riscv/gdbstub.c | 6 ++++-- target/rx/gdbstub.c | 6 ++++-- target/s390x/gdbstub.c | 6 ++++-- target/sh4/gdbstub.c | 6 ++++-- target/sparc/gdbstub.c | 6 ++++-- target/tricore/gdbstub.c | 6 ++++-- target/xtensa/gdbstub.c | 6 ++++-- 45 files changed, 205 insertions(+), 110 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 8fc9a1a140..bb0f96d733 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -157,8 +157,10 @@ struct CPUClass { int64_t (*get_arch_id)(CPUState *cpu); void (*set_pc)(CPUState *cpu, vaddr value); vaddr (*get_pc)(CPUState *cpu); - int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg); - int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg); + int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); + int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); vaddr (*gdb_adjust_breakpoint)(CPUState *cpu, vaddr addr); const GDBFeature *gdb_core_feature; diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h index 13306665af..46bd9bc37b 100644 --- a/target/alpha/cpu.h +++ b/target/alpha/cpu.h @@ -279,8 +279,10 @@ bool alpha_cpu_exec_interrupt(CPUState *cpu, int int_req); hwaddr alpha_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); #endif /* !CONFIG_USER_ONLY */ void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags); -int alpha_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int alpha_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int alpha_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int alpha_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); #define cpu_list alpha_cpu_list diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 09bf82034d..3dfa29c3aa 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1128,8 +1128,11 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); #endif /* !CONFIG_USER_ONLY */ -int arm_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int arm_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); + +int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); int arm_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, DumpState *s); @@ -1137,8 +1140,10 @@ int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, DumpState *s); #ifdef TARGET_AARCH64 -int aarch64_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int aarch64_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int aarch64_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int aarch64_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq); void aarch64_sve_change_el(CPUARMState *env, int old_el, int new_el, bool el0_a64); diff --git a/target/avr/cpu.h b/target/avr/cpu.h index 7225174668..006e79e018 100644 --- a/target/avr/cpu.h +++ b/target/avr/cpu.h @@ -157,8 +157,10 @@ extern const struct VMStateDescription vms_avr_cpu; void avr_cpu_do_interrupt(CPUState *cpu); bool avr_cpu_exec_interrupt(CPUState *cpu, int int_req); hwaddr avr_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int avr_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int avr_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int avr_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int avr_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); int avr_print_insn(bfd_vma addr, disassemble_info *info); vaddr avr_cpu_gdb_adjust_breakpoint(CPUState *cpu, vaddr addr); diff --git a/target/cris/cpu.h b/target/cris/cpu.h index 8e37c6e50d..d3a62c5480 100644 --- a/target/cris/cpu.h +++ b/target/cris/cpu.h @@ -198,9 +198,12 @@ hwaddr cris_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags); -int crisv10_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int cris_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int cris_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int crisv10_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int cris_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int cris_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); void cris_initialize_tcg(void); void cris_initialize_crisv10_tcg(void); diff --git a/target/hexagon/internal.h b/target/hexagon/internal.h index d732b6bb3c..cdd4bb7d26 100644 --- a/target/hexagon/internal.h +++ b/target/hexagon/internal.h @@ -31,8 +31,10 @@ } \ } while (0) -int hexagon_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int hexagon_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int hexagon_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int hexagon_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); int hexagon_hvx_gdb_read_register(CPUHexagonState *env, GByteArray *mem_buf, int n); int hexagon_hvx_gdb_write_register(CPUHexagonState *env, uint8_t *mem_buf, int n); diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h index 9fe79b1242..a983540dd2 100644 --- a/target/hppa/cpu.h +++ b/target/hppa/cpu.h @@ -321,8 +321,10 @@ static inline void cpu_hppa_change_prot_id(CPUHPPAState *env) { } void cpu_hppa_change_prot_id(CPUHPPAState *env); #endif -int hppa_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int hppa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int hppa_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int hppa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); void hppa_cpu_dump_state(CPUState *cs, FILE *f, int); #ifndef CONFIG_USER_ONLY hwaddr hppa_cpu_get_phys_page_debug(CPUState *cs, vaddr addr); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index e0771a1043..d177f500b8 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2057,8 +2057,10 @@ void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags); -int x86_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int x86_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int x86_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int x86_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); void x86_cpu_list(void); int cpu_x86_support_mca_broadcast(CPUX86State *env); diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h index 7b0f29c942..a2ff8b3e3d 100644 --- a/target/loongarch/internals.h +++ b/target/loongarch/internals.h @@ -77,8 +77,10 @@ hwaddr loongarch_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); uint64_t read_fcc(CPULoongArchState *env); void write_fcc(CPULoongArchState *env, uint64_t val); -int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n); -int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n); +int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml); +int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml); void loongarch_cpu_register_gdb_regs_for_features(CPUState *cs); #endif diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index cf70282717..b59d076c0c 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -179,8 +179,10 @@ bool m68k_cpu_exec_interrupt(CPUState *cpu, int int_req); hwaddr m68k_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); #endif /* !CONFIG_USER_ONLY */ void m68k_cpu_dump_state(CPUState *cpu, FILE *f, int flags); -int m68k_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int m68k_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int m68k_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int m68k_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); void m68k_tcg_init(void); void m68k_cpu_init_gdb(M68kCPU *cpu); diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h index f6cab6ce19..8840bf17f3 100644 --- a/target/microblaze/cpu.h +++ b/target/microblaze/cpu.h @@ -368,8 +368,10 @@ G_NORETURN void mb_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr); void mb_cpu_dump_state(CPUState *cpu, FILE *f, int flags); -int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int mb_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int mb_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); int mb_cpu_gdb_read_stack_protect(CPUArchState *cpu, GByteArray *buf, int reg); int mb_cpu_gdb_write_stack_protect(CPUArchState *cpu, uint8_t *buf, int reg); diff --git a/target/mips/internal.h b/target/mips/internal.h index 1d0c026c7d..b5462f53a9 100644 --- a/target/mips/internal.h +++ b/target/mips/internal.h @@ -92,8 +92,10 @@ extern const char fregnames[32][4]; extern const struct mips_def_t mips_defs[]; extern const int mips_defs_number; -int mips_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int mips_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int mips_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int mips_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); #define USEG_LIMIT ((target_ulong)(int32_t)0x7FFFFFFFUL) #define KSEG0_BASE ((target_ulong)(int32_t)0x80000000UL) diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h index ce4d605eb7..8c2089db92 100644 --- a/target/openrisc/cpu.h +++ b/target/openrisc/cpu.h @@ -312,8 +312,10 @@ struct ArchCPU { void cpu_openrisc_list(void); void openrisc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); -int openrisc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int openrisc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int openrisc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int openrisc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); void openrisc_translate_init(void); int print_insn_or1k(bfd_vma addr, disassemble_info *info); diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 3dc6e545e3..0849ee6e1f 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1375,10 +1375,14 @@ static inline bool vhyp_cpu_in_nested(PowerPCCPU *cpu) #endif /* CONFIG_USER_ONLY */ void ppc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); -int ppc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int ppc_cpu_gdb_read_register_apple(CPUState *cpu, GByteArray *buf, int reg); -int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); -int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg); +int ppc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int ppc_cpu_gdb_read_register_apple(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); +int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); #ifndef CONFIG_USER_ONLY hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); void ppc_gdb_gen_spr_feature(PowerPCCPU *cpu); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f67751d5b7..46b06b1962 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -421,8 +421,10 @@ int riscv_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, DumpState *s); int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, DumpState *s); -int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); int riscv_cpu_hviprio_index2irq(int index, int *out_irq, int *out_rdzero); uint8_t riscv_cpu_default_priority(int irq); uint64_t riscv_cpu_all_pending(CPURISCVState *env); diff --git a/target/rx/cpu.h b/target/rx/cpu.h index 7f03ffcfed..d1a099cf72 100644 --- a/target/rx/cpu.h +++ b/target/rx/cpu.h @@ -126,8 +126,10 @@ bool rx_cpu_exec_interrupt(CPUState *cpu, int int_req); hwaddr rx_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); #endif /* !CONFIG_USER_ONLY */ void rx_cpu_dump_state(CPUState *cpu, FILE *f, int flags); -int rx_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int rx_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int rx_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int rx_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); void rx_translate_init(void); void rx_cpu_list(void); diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index 825252d728..4c2bb30358 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -316,8 +316,10 @@ uint16_t float128_dcmask(CPUS390XState *env, float128 f1); /* gdbstub.c */ -int s390_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int s390_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int s390_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int s390_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); void s390_cpu_gdb_init(CPUState *cs); diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h index 1399d3840f..74c8f0f574 100644 --- a/target/sh4/cpu.h +++ b/target/sh4/cpu.h @@ -214,8 +214,10 @@ struct ArchCPU { void superh_cpu_dump_state(CPUState *cpu, FILE *f, int flags); -int superh_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int superh_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int superh_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int superh_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); G_NORETURN void superh_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr); diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h index 98044572f2..b03174938c 100644 --- a/target/sparc/cpu.h +++ b/target/sparc/cpu.h @@ -573,8 +573,10 @@ hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); #endif void sparc_cpu_do_interrupt(CPUState *cpu); -int sparc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int sparc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int sparc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int sparc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); G_NORETURN void sparc_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, int mmu_idx, diff --git a/target/tricore/cpu.h b/target/tricore/cpu.h index 3708405be8..7da6c88a15 100644 --- a/target/tricore/cpu.h +++ b/target/tricore/cpu.h @@ -361,8 +361,10 @@ enum { uint32_t psw_read(CPUTriCoreState *env); void psw_write(CPUTriCoreState *env, uint32_t val); -int tricore_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n); -int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n); +int tricore_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml); +int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml); void fpu_set_state(CPUTriCoreState *env); diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index 87fe992ba6..093593eb0c 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -581,8 +581,10 @@ hwaddr xtensa_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); void xtensa_cpu_dump_state(CPUState *cpu, FILE *f, int flags); void xtensa_count_regs(const XtensaConfig *config, unsigned *n_regs, unsigned *n_core_regs); -int xtensa_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); -int xtensa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int xtensa_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml); +int xtensa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml); G_NORETURN void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr); diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index e4fbdebca4..5974af7c8f 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -490,7 +490,7 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) GDBRegisterState *r; if (reg < cc->gdb_num_core_regs) { - return cc->gdb_read_register(cpu, buf, reg); + return cc->gdb_read_register(cpu, buf, reg, gdb_has_xml); } for (r = cpu->gdb_regs; r; r = r->next) { @@ -508,7 +508,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) GDBRegisterState *r; if (reg < cc->gdb_num_core_regs) { - return cc->gdb_write_register(cpu, mem_buf, reg); + return cc->gdb_write_register(cpu, mem_buf, reg, gdb_has_xml); } for (r = cpu->gdb_regs; r; r = r->next) { diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index ced66c2b34..549f52f46f 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -89,12 +89,14 @@ void cpu_exit(CPUState *cpu) qatomic_set(&cpu->icount_decr_ptr->u16.high, -1); } -static int cpu_common_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) +static int cpu_common_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, + bool has_xml) { return 0; } -static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg) +static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg, + bool has_xml) { return 0; } diff --git a/target/alpha/gdbstub.c b/target/alpha/gdbstub.c index 0f8fa150f8..c5b4a190f3 100644 --- a/target/alpha/gdbstub.c +++ b/target/alpha/gdbstub.c @@ -21,7 +21,8 @@ #include "cpu.h" #include "gdbstub/helpers.h" -int alpha_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int alpha_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { AlphaCPU *cpu = ALPHA_CPU(cs); CPUAlphaState *env = &cpu->env; @@ -57,7 +58,8 @@ int alpha_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return gdb_get_regl(mem_buf, val); } -int alpha_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int alpha_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { AlphaCPU *cpu = ALPHA_CPU(cs); CPUAlphaState *env = &cpu->env; diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index dbc396a88b..7a17dc923d 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -36,7 +36,8 @@ typedef struct RegisterSysregFeatureParam { We hack round this by giving the FPA regs zero size when talking to a newer gdb. */ -int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; @@ -47,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 (has_xml) { return 0; } return gdb_get_zeroes(mem_buf, 12); @@ -55,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 (has_xml) { return 0; } return gdb_get_reg32(mem_buf, 0); @@ -71,7 +72,8 @@ int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; @@ -101,7 +103,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 (has_xml) { return 0; } return 12; @@ -109,7 +111,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 (has_xml) { return 0; } return 4; diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index 632ac2a520..23f95534d2 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -22,7 +22,8 @@ #include "internals.h" #include "gdbstub/helpers.h" -int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; @@ -43,7 +44,8 @@ int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int aarch64_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int aarch64_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; diff --git a/target/avr/gdbstub.c b/target/avr/gdbstub.c index 150344d8b9..c40f4ecd4b 100644 --- a/target/avr/gdbstub.c +++ b/target/avr/gdbstub.c @@ -21,7 +21,8 @@ #include "qemu/osdep.h" #include "gdbstub/helpers.h" -int avr_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int avr_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { AVRCPU *cpu = AVR_CPU(cs); CPUAVRState *env = &cpu->env; @@ -51,7 +52,8 @@ int avr_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int avr_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int avr_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { AVRCPU *cpu = AVR_CPU(cs); CPUAVRState *env = &cpu->env; diff --git a/target/cris/gdbstub.c b/target/cris/gdbstub.c index 25c0ca33a5..2b5c0d5f14 100644 --- a/target/cris/gdbstub.c +++ b/target/cris/gdbstub.c @@ -21,7 +21,8 @@ #include "cpu.h" #include "gdbstub/helpers.h" -int crisv10_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int crisv10_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { CRISCPU *cpu = CRIS_CPU(cs); CPUCRISState *env = &cpu->env; @@ -53,7 +54,8 @@ int crisv10_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int cris_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int cris_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { CRISCPU *cpu = CRIS_CPU(cs); CPUCRISState *env = &cpu->env; @@ -88,7 +90,8 @@ int cris_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int cris_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int cris_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { CRISCPU *cpu = CRIS_CPU(cs); CPUCRISState *env = &cpu->env; diff --git a/target/hexagon/gdbstub.c b/target/hexagon/gdbstub.c index 54d37e006e..42fa563fc4 100644 --- a/target/hexagon/gdbstub.c +++ b/target/hexagon/gdbstub.c @@ -20,7 +20,8 @@ #include "cpu.h" #include "internal.h" -int hexagon_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int hexagon_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { HexagonCPU *cpu = HEXAGON_CPU(cs); CPUHexagonState *env = &cpu->env; @@ -40,7 +41,8 @@ int hexagon_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) g_assert_not_reached(); } -int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { HexagonCPU *cpu = HEXAGON_CPU(cs); CPUHexagonState *env = &cpu->env; diff --git a/target/hppa/gdbstub.c b/target/hppa/gdbstub.c index 48a514384f..44a1869d54 100644 --- a/target/hppa/gdbstub.c +++ b/target/hppa/gdbstub.c @@ -21,7 +21,8 @@ #include "cpu.h" #include "gdbstub/helpers.h" -int hppa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int hppa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { HPPACPU *cpu = HPPA_CPU(cs); CPUHPPAState *env = &cpu->env; @@ -146,7 +147,8 @@ int hppa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) } } -int hppa_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int hppa_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { HPPACPU *cpu = HPPA_CPU(cs); CPUHPPAState *env = &cpu->env; diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c index ebb000df6a..56c9aedd6b 100644 --- a/target/i386/gdbstub.c +++ b/target/i386/gdbstub.c @@ -32,9 +32,7 @@ static const int gpr_map[16] = { static const int gpr_map32[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; /* - * Keep these in sync with assignment to - * gdb_num_core_regs in target/i386/cpu.c - * and with the machine description + * Keep these in sync with the machine description */ /* @@ -96,7 +94,8 @@ static int gdb_write_reg_cs64(uint32_t hflags, uint8_t *buf, target_ulong *val) return 4; } -int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; @@ -248,7 +247,8 @@ static int x86_cpu_gdb_load_seg(X86CPU *cpu, X86Seg sreg, uint8_t *mem_buf) return 4; } -int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c index 2886b106bb..6b14f73084 100644 --- a/target/loongarch/gdbstub.c +++ b/target/loongarch/gdbstub.c @@ -30,7 +30,8 @@ void write_fcc(CPULoongArchState *env, uint64_t val) } } -int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { LoongArchCPU *cpu = LOONGARCH_CPU(cs); CPULoongArchState *env = &cpu->env; @@ -48,7 +49,8 @@ int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { LoongArchCPU *cpu = LOONGARCH_CPU(cs); CPULoongArchState *env = &cpu->env; diff --git a/target/m68k/gdbstub.c b/target/m68k/gdbstub.c index 1e5f033a12..24e636cddc 100644 --- a/target/m68k/gdbstub.c +++ b/target/m68k/gdbstub.c @@ -21,7 +21,8 @@ #include "cpu.h" #include "gdbstub/helpers.h" -int m68k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int m68k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { M68kCPU *cpu = M68K_CPU(cs); CPUM68KState *env = &cpu->env; @@ -48,7 +49,8 @@ int m68k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int m68k_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int m68k_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { M68kCPU *cpu = M68K_CPU(cs); CPUM68KState *env = &cpu->env; diff --git a/target/microblaze/gdbstub.c b/target/microblaze/gdbstub.c index 29ac6e9c0f..71962b98de 100644 --- a/target/microblaze/gdbstub.c +++ b/target/microblaze/gdbstub.c @@ -46,7 +46,8 @@ enum { GDB_SP_SHR, }; -int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); CPUClass *cc = CPU_GET_CLASS(cs); @@ -111,7 +112,8 @@ int mb_cpu_gdb_read_stack_protect(CPUMBState *env, GByteArray *mem_buf, int n) return gdb_get_reg32(mem_buf, val); } -int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); CPUClass *cc = CPU_GET_CLASS(cs); diff --git a/target/mips/gdbstub.c b/target/mips/gdbstub.c index 62d7b72407..9022fc5375 100644 --- a/target/mips/gdbstub.c +++ b/target/mips/gdbstub.c @@ -23,7 +23,8 @@ #include "gdbstub/helpers.h" #include "fpu_helper.h" -int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { MIPSCPU *cpu = MIPS_CPU(cs); CPUMIPSState *env = &cpu->env; @@ -76,7 +77,8 @@ int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { MIPSCPU *cpu = MIPS_CPU(cs); CPUMIPSState *env = &cpu->env; diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index bc5cbf81c2..5015866b4d 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -280,7 +280,8 @@ static void nios2_cpu_disas_set_info(CPUState *cpu, disassemble_info *info) info->print_insn = print_insn_nios2; } -static int nios2_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +static int nios2_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { Nios2CPU *cpu = NIOS2_CPU(cs); CPUNios2State *env = &cpu->env; @@ -305,7 +306,8 @@ static int nios2_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return gdb_get_reg32(mem_buf, val); } -static int nios2_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +static int nios2_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { Nios2CPU *cpu = NIOS2_CPU(cs); CPUClass *cc = CPU_GET_CLASS(cs); diff --git a/target/openrisc/gdbstub.c b/target/openrisc/gdbstub.c index d1074a0581..5ac841e52a 100644 --- a/target/openrisc/gdbstub.c +++ b/target/openrisc/gdbstub.c @@ -21,7 +21,8 @@ #include "cpu.h" #include "gdbstub/helpers.h" -int openrisc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int openrisc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { OpenRISCCPU *cpu = OPENRISC_CPU(cs); CPUOpenRISCState *env = &cpu->env; @@ -46,7 +47,8 @@ int openrisc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int openrisc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int openrisc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { OpenRISCCPU *cpu = OPENRISC_CPU(cs); CPUClass *cc = CPU_GET_CLASS(cs); diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index c86b7055ca..d66a35d432 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -48,7 +48,7 @@ static int ppc_gdb_register_len_apple(int n) } } -static int ppc_gdb_register_len(int n) +static int ppc_gdb_register_len(int n, bool has_xml) { switch (n) { case 0 ... 31: @@ -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 (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 (has_xml) { return 0; } return sizeof(target_ulong); @@ -118,12 +118,13 @@ void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len) * the FP regs zero size when talking to a newer gdb. */ -int ppc_cpu_gdb_read_register(CPUState *cs, GByteArray *buf, int n) +int ppc_cpu_gdb_read_register(CPUState *cs, GByteArray *buf, int n, + bool has_xml) { PowerPCCPU *cpu = POWERPC_CPU(cs); CPUPPCState *env = &cpu->env; uint8_t *mem_buf; - int r = ppc_gdb_register_len(n); + int r = ppc_gdb_register_len(n, has_xml); if (!r) { return r; @@ -168,7 +169,8 @@ int ppc_cpu_gdb_read_register(CPUState *cs, GByteArray *buf, int n) return r; } -int ppc_cpu_gdb_read_register_apple(CPUState *cs, GByteArray *buf, int n) +int ppc_cpu_gdb_read_register_apple(CPUState *cs, GByteArray *buf, int n, + bool has_xml) { PowerPCCPU *cpu = POWERPC_CPU(cs); CPUPPCState *env = &cpu->env; @@ -222,11 +224,12 @@ int ppc_cpu_gdb_read_register_apple(CPUState *cs, GByteArray *buf, int n) return r; } -int ppc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int ppc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { PowerPCCPU *cpu = POWERPC_CPU(cs); CPUPPCState *env = &cpu->env; - int r = ppc_gdb_register_len(n); + int r = ppc_gdb_register_len(n, has_xml); if (!r) { return r; @@ -269,7 +272,8 @@ int ppc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) } return r; } -int ppc_cpu_gdb_write_register_apple(CPUState *cs, uint8_t *mem_buf, int n) +int ppc_cpu_gdb_write_register_apple(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { PowerPCCPU *cpu = POWERPC_CPU(cs); CPUPPCState *env = &cpu->env; diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index a2ec9a3701..8d583f7f70 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -47,7 +47,8 @@ static const struct TypeSize vec_lanes[] = { { "uint8", "bytes", 8, 'b' }, }; -int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; @@ -73,7 +74,8 @@ int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; diff --git a/target/rx/gdbstub.c b/target/rx/gdbstub.c index d7e0e6689b..57d5ed11eb 100644 --- a/target/rx/gdbstub.c +++ b/target/rx/gdbstub.c @@ -19,7 +19,8 @@ #include "cpu.h" #include "gdbstub/helpers.h" -int rx_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int rx_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { RXCPU *cpu = RX_CPU(cs); CPURXState *env = &cpu->env; @@ -51,7 +52,8 @@ int rx_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int rx_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int rx_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { RXCPU *cpu = RX_CPU(cs); CPURXState *env = &cpu->env; diff --git a/target/s390x/gdbstub.c b/target/s390x/gdbstub.c index 02c388dc32..57871e3b24 100644 --- a/target/s390x/gdbstub.c +++ b/target/s390x/gdbstub.c @@ -28,7 +28,8 @@ #include "sysemu/hw_accel.h" #include "sysemu/tcg.h" -int s390_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int s390_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { S390CPU *cpu = S390_CPU(cs); CPUS390XState *env = &cpu->env; @@ -44,7 +45,8 @@ int s390_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { S390CPU *cpu = S390_CPU(cs); CPUS390XState *env = &cpu->env; diff --git a/target/sh4/gdbstub.c b/target/sh4/gdbstub.c index d8e199fc06..9afe6fc116 100644 --- a/target/sh4/gdbstub.c +++ b/target/sh4/gdbstub.c @@ -24,7 +24,8 @@ /* Hint: Use "set architecture sh4" in GDB to see fpu registers */ /* FIXME: We should use XML for this. */ -int superh_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int superh_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { SuperHCPU *cpu = SUPERH_CPU(cs); CPUSH4State *env = &cpu->env; @@ -74,7 +75,8 @@ int superh_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { SuperHCPU *cpu = SUPERH_CPU(cs); CPUSH4State *env = &cpu->env; diff --git a/target/sparc/gdbstub.c b/target/sparc/gdbstub.c index a1c8fdc4d5..288cf7d6f7 100644 --- a/target/sparc/gdbstub.c +++ b/target/sparc/gdbstub.c @@ -27,7 +27,8 @@ #define gdb_get_rega(buf, val) gdb_get_regl(buf, val) #endif -int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { SPARCCPU *cpu = SPARC_CPU(cs); CPUSPARCState *env = &cpu->env; @@ -104,7 +105,8 @@ int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int sparc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int sparc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { SPARCCPU *cpu = SPARC_CPU(cs); CPUSPARCState *env = &cpu->env; diff --git a/target/tricore/gdbstub.c b/target/tricore/gdbstub.c index e8f8e5e6ea..a06e590344 100644 --- a/target/tricore/gdbstub.c +++ b/target/tricore/gdbstub.c @@ -104,7 +104,8 @@ static void tricore_cpu_gdb_write_csfr(CPUTriCoreState *env, int n, } -int tricore_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int tricore_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { TriCoreCPU *cpu = TRICORE_CPU(cs); CPUTriCoreState *env = &cpu->env; @@ -119,7 +120,8 @@ int tricore_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { TriCoreCPU *cpu = TRICORE_CPU(cs); CPUTriCoreState *env = &cpu->env; diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c index 4b3bfb7e59..81d97b51b8 100644 --- a/target/xtensa/gdbstub.c +++ b/target/xtensa/gdbstub.c @@ -63,7 +63,8 @@ void xtensa_count_regs(const XtensaConfig *config, } } -int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n, + bool has_xml) { XtensaCPU *cpu = XTENSA_CPU(cs); CPUXtensaState *env = &cpu->env; @@ -118,7 +119,8 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) } } -int xtensa_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +int xtensa_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n, + bool has_xml) { XtensaCPU *cpu = XTENSA_CPU(cs); CPUXtensaState *env = &cpu->env; From patchwork Wed Aug 16 13:39:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=JtIyGV+4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqCX5b68z1yXY for ; Wed, 16 Aug 2023 23:45:44 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGnr-0002Dk-6d; Wed, 16 Aug 2023 09:43:15 -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 1qWGno-00020o-Lb for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:12 -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 1qWGnk-00022b-Hq for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:12 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68871bbfe33so1153425b3a.0 for ; Wed, 16 Aug 2023 06:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193387; x=1692798187; 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=HIuVW7uU8pKm/ZM9OO2H7cmvCoPILSMWzBsLAGD3J2U=; b=JtIyGV+4bVExhFhA3ZpKVrBPbjQht11hqwkd2un1A+4kw2Mq7hd1+uMmox57TOSLdm QrflKhubCd/vI+k8fli97dd2y+Aj2ZSPxBODJhBSTGcBlgp0U3MdsLq4zHj6sBYZ2Y4c mqfly2SrAAQgvgouQguDcS0J9PET3sIcua6slk9TVYCyiyeuUckcAtkdJ6I0PWtsGXqV 7sl46N9VLxoBAur++EMQwll6rnHJSBod+FIXwp42Hln6D5QFszPjgFbMBADlVtnKIv15 u4b4COG8U7+w82Dkkke6xa7I1zy5p7mTIUQjKSE0g4TN5hxNPVcCSgDykuwclBKa9fVs U2OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193387; x=1692798187; 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=HIuVW7uU8pKm/ZM9OO2H7cmvCoPILSMWzBsLAGD3J2U=; b=SCrYNipik2Nrnd4ecoDG3s1hglAhTQYFClXTM+KqnJ8FXvKw215YNYXePhqfPFi/BC SthPu2YxxTN6QQWKZJ9uelRUGrO0MR4jVJhVO8hK/ggHQxTzhbDwzUb8OsJNtxchSiCb 3fPRKGvd5fNqE22cfqbiKO4tgGbAEAJrDAmMUGALO+KWPYFPdBCfHjEfhM4kKIH9ewVH uoCn/kcC+PPAmhp8VXdPUkQyfSeiarluinuj6yzdhgdqxKdmo/rdmyRFCVjWbY9t7vMr 5uEHyi8fSJC/0tDl74eFmnHB7eTcf+PPnWULJblVNcArobkDT4D/pqQDpXyxFKeaL63Q GuJw== X-Gm-Message-State: AOJu0YySjDhL8WU+4TioTQjpIko+l63GhnwqB2D3n26rJudLp1MaQFLH ez8o3zWhrFzD5EGHeOSNKpj4bw== X-Google-Smtp-Source: AGHT+IHSIbpHy9EZmfqyKOWW/BetSq7GSqyFo1udVLMxGclFE8UqSnzkfq7NQtaLTj3IBcFSsmTUUA== X-Received: by 2002:a05:6a20:8421:b0:133:2fb2:917d with SMTP id c33-20020a056a20842100b001332fb2917dmr2663262pzd.5.1692193387232; Wed, 16 Aug 2023 06:43:07 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:43:06 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 19/25] gdbstub: Hide gdb_has_xml Date: Wed, 16 Aug 2023 22:39:29 +0900 Message-ID: <20230816133938.18310-20-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org gdb_has_xml is no longer referenced by the other components. Signed-off-by: Akihiko Odaki --- gdbstub/internals.h | 8 ++++++++ include/exec/gdbstub.h | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 4876ebd74f..6a7c512766 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -234,4 +234,12 @@ void gdb_breakpoint_remove_all(CPUState *cs); int gdb_target_memory_rw_debug(CPUState *cs, hwaddr addr, uint8_t *buf, int len, bool is_write); +/** + * 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. + */ +extern bool gdb_has_xml; + #endif /* GDBSTUB_INTERNALS_H */ diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index f3f2c40b1a..5cba2933d2 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -61,14 +61,6 @@ const GDBFeature *gdb_find_static_feature(const char *xmlname); 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. - */ -extern bool gdb_has_xml; - /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */ extern const GDBFeature gdb_static_features[]; From patchwork Wed Aug 16 13:39:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=zG4Vpa+1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqBz1ls7z1yNm for ; Wed, 16 Aug 2023 23:45:15 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGo0-0002q5-6X; Wed, 16 Aug 2023 09:43:24 -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 1qWGny-0002a8-E8 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:22 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGnu-00028Q-8h for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:22 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6886d6895a9so1161354b3a.0 for ; Wed, 16 Aug 2023 06:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193396; x=1692798196; 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=FeKiYP9xrSKexWAO9b8A0nNhOs6FhnCu3ht5OqePfRY=; b=zG4Vpa+1bHJWs5uT7JEFhopN09hzSdvwrr51pIbR8uIWP2z+tTju1TsfSnRPUjLSGg l7SBDjihWmYWtMsT/jahQBi8dTX8SikraOjSzkx41dbNwRvbS7ma2rWOS7brJk0YEDfq WWvFXN4c6J08+uIo7cyXWo2w4A7czuzVmoqq8vtSCh7Z7EGduVavIMxrtxnGIp0mGjcz Lg0WjAIRPgaaTwrEI96mhVCKa0/12yKd7FME8gHhvmJLS92U9kqf1RRmhFb1RH9wLNoH FQvP4/AbEDTmGMAnXtjEBHoHLuDM+6IHt4DAZxi2RiNQtfHMs3v7gKCH1TTTl/5H+DT3 Zb1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193396; x=1692798196; 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=FeKiYP9xrSKexWAO9b8A0nNhOs6FhnCu3ht5OqePfRY=; b=VH/7kWnqYEH01tMs0eDmRaF28PeRkHv4u1cN5elWLGXnLi8CKJJUTfT4BH90RVdYKH W+GreXdtPSQfjlAWujx+tX/rN1KaC9y3Tq9fwoPCA/l4CMJjEkvaRrQUXkZUhLRzGw2y NV3GMIRGXse3h5De6l53u/33jV2tncA9sLPabs4dJD8MLXP8uHZIkRtMTPkTSLoXEILB IEasa0r8C+3mZLyl+J0rzQ2VHGaz52cBHEhkW4Latcouxbexn7aWaFU2mD3X1SrnkX41 FfQxK1Vpp6eaVA8Su76FFMEW0efp1V6rov89Fc3oPH+sBcfOxFZc8RDyvYGqcvHp5PUf iqLw== X-Gm-Message-State: AOJu0Yw/TW1f2Ls0qLa8KRnxqc7wn8xvDu6+Omp6iq1EGyxpWfrWkGsg 8kH1Xa1mNZ+B5ihE1JCA8iReag== X-Google-Smtp-Source: AGHT+IGtEhNmlyU4gpOyiAuSErTWEb4DF6l1/uj7/5GgR03iJXKDK9tbyR4hSxGerYyDp1LAsF5JjA== X-Received: by 2002:a05:6a20:3953:b0:140:6979:295d with SMTP id r19-20020a056a20395300b001406979295dmr2266571pzg.2.1692193396610; Wed, 16 Aug 2023 06:43:16 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:43:16 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 20/25] gdbstub: Expose functions to read registers Date: Wed, 16 Aug 2023 22:39:30 +0900 Message-ID: <20230816133938.18310-21-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::433; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x433.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org gdb_foreach_feature() enumerates features that are useful to identify registers. gdb_read_register() actually reads registers. Signed-off-by: Akihiko Odaki --- include/exec/gdbstub.h | 6 ++++++ gdbstub/gdbstub.c | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 5cba2933d2..151e9e81c6 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -59,6 +59,12 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder); const GDBFeature *gdb_find_static_feature(const char *xmlname); +void gdb_foreach_feature(CPUState *cpu, + void (* callback)(void *, const GDBFeature *, int), + void *opaque); + +int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, bool has_xml); + void gdb_set_stop_cpu(CPUState *cpu); /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */ diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 5974af7c8f..e395a58db4 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -483,14 +483,32 @@ const GDBFeature *gdb_find_static_feature(const char *xmlname) abort(); } -static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) +void gdb_foreach_feature(CPUState *cpu, + void (* callback)(void *, const GDBFeature *, int), + void *opaque) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + GDBRegisterState *r; + + if (!cc->gdb_core_feature) { + return; + } + + callback(opaque, cc->gdb_core_feature, 0); + + for (r = cpu->gdb_regs; r; r = r->next) { + callback(opaque, r->feature, r->base_reg); + } +} + +int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg, bool has_xml) { CPUClass *cc = CPU_GET_CLASS(cpu); CPUArchState *env = cpu->env_ptr; GDBRegisterState *r; if (reg < cc->gdb_num_core_regs) { - return cc->gdb_read_register(cpu, buf, reg, gdb_has_xml); + return cc->gdb_read_register(cpu, buf, reg, has_xml); } for (r = cpu->gdb_regs; r; r = r->next) { @@ -501,14 +519,15 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) return 0; } -static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) +static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg, + bool has_xml) { CPUClass *cc = CPU_GET_CLASS(cpu); CPUArchState *env = cpu->env_ptr; GDBRegisterState *r; if (reg < cc->gdb_num_core_regs) { - return cc->gdb_write_register(cpu, mem_buf, reg, gdb_has_xml); + return cc->gdb_write_register(cpu, mem_buf, reg, has_xml); } for (r = cpu->gdb_regs; r; r = r->next) { @@ -1134,7 +1153,7 @@ static void handle_set_reg(GArray *params, void *user_ctx) reg_size = strlen(get_param(params, 1)->data) / 2; gdb_hextomem(gdbserver_state.mem_buf, get_param(params, 1)->data, reg_size); gdb_write_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf->data, - get_param(params, 0)->val_ull); + get_param(params, 0)->val_ull, gdb_has_xml); gdb_put_packet("OK"); } @@ -1154,7 +1173,8 @@ static void handle_get_reg(GArray *params, void *user_ctx) reg_size = gdb_read_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf, - get_param(params, 0)->val_ull); + get_param(params, 0)->val_ull, + gdb_has_xml); if (!reg_size) { gdb_put_packet("E14"); return; @@ -1241,7 +1261,8 @@ static void handle_write_all_regs(GArray *params, void *user_ctx) for (reg_id = 0; reg_id < gdbserver_state.g_cpu->gdb_num_g_regs && len > 0; reg_id++) { - reg_size = gdb_write_register(gdbserver_state.g_cpu, registers, reg_id); + reg_size = gdb_write_register(gdbserver_state.g_cpu, registers, reg_id, + gdb_has_xml); len -= reg_size; registers += reg_size; } @@ -1259,7 +1280,8 @@ static void handle_read_all_regs(GArray *params, void *user_ctx) for (reg_id = 0; reg_id < gdbserver_state.g_cpu->gdb_num_g_regs; reg_id++) { len += gdb_read_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf, - reg_id); + reg_id, + gdb_has_xml); } g_assert(len == gdbserver_state.mem_buf->len); From patchwork Wed Aug 16 13:39:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=s6ES09GX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqHG44BTz1yNm for ; Wed, 16 Aug 2023 23:48:58 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGo6-0003JO-UU; Wed, 16 Aug 2023 09:43:30 -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 1qWGo5-0003Hr-Eq for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:29 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGo3-0002Ev-59 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:29 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-68872ca740bso1291493b3a.2 for ; Wed, 16 Aug 2023 06:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193406; x=1692798206; 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=0qn3f+dV41vakExUKDLgOPwYM5dZMF/vR3FB6T+MC1c=; b=s6ES09GXwAd0fqEkEwKu0lX63fhQI9WnvlcsRwm0KOPq4BMPK6+3GGxt2sOrfc4bSN mh8Cjgz0SrBGhwDqgfkI1u2h8D8Cb7dV9icQwv+Wn+ALCp/vahe1MQtYDoj1yjZHz2eB JjXvhnIpMbDGDBLMdMedb+Ydbo4nYqCHD6/QnHJHkiP/LEe1/gjMx8Nn09EOvTAJnHLw h482DyCdO4NgtXe1F/oW7WXnZkREyrsCe9ag2suMUeI8+Dl4oWCCJYKZN8yTPwfSre0w 6T5217hBqZRuvb/V8SgnX6x25yaL1Y+yiXUbdcRmH4MvB0bQkGSsXcy8opHyDsVLDA8P IsAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193406; x=1692798206; 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=0qn3f+dV41vakExUKDLgOPwYM5dZMF/vR3FB6T+MC1c=; b=bb/XZP1gdnTJAwO3UFVNZoUR8YwB9hPI0CNU6T0CQhtXoYLqyq63UE1Oug77Yn9Ykb y3sTUtFalOEWXNcBPzX0YJvhX7ZPQT0gV5H11kajsfgIG5NwmG2eJrc5XxPlIFAtQRkP yJkp6JF/f1dsQQW+UtQfvMg0h8CaHDnOxfo4pHQGa6a6X/nIAdBB+E8VIfHx3oOU8jT2 fS8j2UbRZ0HVo4VT/+9zhXs+xP1XnIKNZx6J5bqbaWL8kWSfpUyIw+jWyQvNngUhA5m1 uvKVAyZQpkxXWpcVmztmZYaIggULDB/H0QoYI3Kz5Hjib6CvDYjjLvBJySupH6Upf6v/ 7YRg== X-Gm-Message-State: AOJu0YzmadyOIKj+sZkcJFXD+NUW6Nbe7/iz1dYmmWWaTUn6yAKXEnsV IhIdPtxNN42uu2F0lLn7JW2MVQ== X-Google-Smtp-Source: AGHT+IEE6zg1iisf/BY2GI7OfzNzFpNOMNhKi2CMjEzPXIMNiLOzvHWmfvFey3Dqe/KWNFVdtTdkKg== X-Received: by 2002:a05:6a20:3d07:b0:13b:7848:9515 with SMTP id y7-20020a056a203d0700b0013b78489515mr2597217pzi.13.1692193405971; Wed, 16 Aug 2023 06:43:25 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:43:25 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 21/25] cpu: Call plugin hooks only when ready Date: Wed, 16 Aug 2023 22:39:31 +0900 Message-ID: <20230816133938.18310-22-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::430; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x430.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The initialization and exit hooks will not affect the state of vCPU, but they may depend on the state of vCPU. Therefore, it's better to call plugin hooks after the vCPU state is fully initialized and before it gets uninitialized. Signed-off-by: Akihiko Odaki --- cpu.c | 11 ----------- hw/core/cpu-common.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cpu.c b/cpu.c index 1c948d1161..2552c85249 100644 --- a/cpu.c +++ b/cpu.c @@ -42,7 +42,6 @@ #include "hw/core/accel-cpu.h" #include "trace/trace-root.h" #include "qemu/accel.h" -#include "qemu/plugin.h" uintptr_t qemu_host_page_size; intptr_t qemu_host_page_mask; @@ -148,11 +147,6 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) /* Wait until cpu initialization complete before exposing cpu. */ cpu_list_add(cpu); - /* Plugin initialization must wait until cpu_index assigned. */ - if (tcg_enabled()) { - qemu_plugin_vcpu_init_hook(cpu); - } - #ifdef CONFIG_USER_ONLY assert(qdev_get_vmsd(DEVICE(cpu)) == NULL || qdev_get_vmsd(DEVICE(cpu))->unmigratable); @@ -179,11 +173,6 @@ void cpu_exec_unrealizefn(CPUState *cpu) } #endif - /* Call the plugin hook before clearing cpu->cpu_index in cpu_list_remove */ - if (tcg_enabled()) { - qemu_plugin_vcpu_exit_hook(cpu); - } - cpu_list_remove(cpu); /* * Now that the vCPU has been removed from the RCU list, we can call diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 549f52f46f..e06a70007a 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -211,6 +211,11 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) cpu_resume(cpu); } + /* Plugin initialization must wait until the cpu is fully realized. */ + if (tcg_enabled()) { + qemu_plugin_vcpu_init_hook(cpu); + } + /* NOTE: latest generic point where the cpu is fully realized */ } @@ -218,6 +223,11 @@ static void cpu_common_unrealizefn(DeviceState *dev) { CPUState *cpu = CPU(dev); + /* Call the plugin hook before clearing the cpu is fully unrealized */ + if (tcg_enabled()) { + qemu_plugin_vcpu_exit_hook(cpu); + } + /* NOTE: latest generic point before the cpu is fully unrealized */ cpu_exec_unrealizefn(cpu); } From patchwork Wed Aug 16 13:39:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=nUCDKArR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqCq4p5fz1yNm for ; Wed, 16 Aug 2023 23:45:59 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGoH-0003ZB-7B; Wed, 16 Aug 2023 09:43:41 -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 1qWGoF-0003Vf-Ks for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:39 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGoC-0002IU-PQ for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:39 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bdbbede5d4so43340375ad.2 for ; Wed, 16 Aug 2023 06:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193415; x=1692798215; 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=Ooo/7eLq9itYFqdnqUN26ru787FfDZXdivlCemb0cOg=; b=nUCDKArRqGVbsQ5Hzgmhfkz/hmvo0+n5RwjsRc7Z4L3wS3WM5LI8pU1rAnoXgYjQ/C qgcHFW+hduDk59OOH7wC4kpT7/8zx95VUr+QaMi2Mkp5T+uBA2rhjqWf0YIgcP653JNr gucC/qMFsgzP5g7Sg3GtgvFjOBOQjxpYw9OEa7XiwpYl7k5SpaP990iVPITwzURCcReX TqS/EM+LIhaDXY5m8NVO5EpnXZnHl/FlbSN8sbSh8mBHc5D9yxJTqaQs8/Peg6sFU6JE BF+pkG4mGUQp1SznvCBCk6y/8Ep2MnLmaAMy61u7+RPPxCD2MbtXSImspPfxeMo2wK7+ 7Bew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193415; x=1692798215; 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=Ooo/7eLq9itYFqdnqUN26ru787FfDZXdivlCemb0cOg=; b=W+Mu0pZ4xL+NjNnNQyYUOvl3i+cslNSxdIkdZe7+6IAcezIYSLg0cZsYeheK6EkSRJ rkFf7xHeHBVOpxwPbUd6HiolUV0sVyPTyx08WBcbwTL6a9dqdi3DlUGIZCINfRVNeLDo umcawltg+Vwz08ObzzE99q1qgWXlE40Dar9a1xrUNKXriIOfXIbHkgr4fpQmwLnq1cgj Zsp8ZmaXpu7BHh3Vy+iPDS9sEn8QhzTZ3f/2VlIVuLj4TIQ86m8OmzDdaMfWPkWjvE3+ 2XM7hturILs/krMWHaT8F5lyNpJuz2BPlFX8Upi0ik5+o92HBv490iKZLSqOHZUJf+M2 UELQ== X-Gm-Message-State: AOJu0YzBu09GI1F/DZWrdacR+OhBV8p9cDmMzzblZR+jaxOZpkxZGYs9 DM+flA/anR2Z6zLIPLkLELHcqg== X-Google-Smtp-Source: AGHT+IGkKU+IfbA472bMTeH6Mvj9KprIuL9ogHkQ1onVBuXRaR0W0TdVChFbo8Xp605UBo2c1Gsyaw== X-Received: by 2002:a17:902:7798:b0:1bd:d6b5:a54f with SMTP id o24-20020a170902779800b001bdd6b5a54fmr2066959pll.55.1692193415283; Wed, 16 Aug 2023 06:43:35 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:43:35 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 22/25] plugins: Allow to read registers Date: Wed, 16 Aug 2023 22:39:32 +0900 Message-ID: <20230816133938.18310-23-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::62d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62d.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It is based on GDB protocol to ensure interface stability. The timing of the vcpu init hook is also changed so that the hook will get called after GDB features are initialized. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706 Signed-off-by: Akihiko Odaki --- include/qemu/qemu-plugin.h | 65 ++++++++++++++++++++++++++++++++++-- plugins/api.c | 40 ++++++++++++++++++++++ plugins/qemu-plugins.symbols | 2 ++ 3 files changed, 104 insertions(+), 3 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 50a9957279..214b12bfd6 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -11,6 +11,7 @@ #ifndef QEMU_QEMU_PLUGIN_H #define QEMU_QEMU_PLUGIN_H +#include #include #include #include @@ -51,7 +52,7 @@ typedef uint64_t qemu_plugin_id_t; extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; -#define QEMU_PLUGIN_VERSION 1 +#define QEMU_PLUGIN_VERSION 2 /** * struct qemu_info_t - system information for plugins @@ -218,8 +219,8 @@ struct qemu_plugin_insn; * @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs * @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs * - * Note: currently unused, plugins cannot read or change system - * register state. + * Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change + * system register state. */ enum qemu_plugin_cb_flags { QEMU_PLUGIN_CB_NO_REGS, @@ -664,4 +665,62 @@ uint64_t qemu_plugin_end_code(void); */ uint64_t qemu_plugin_entry_code(void); +/** + * struct qemu_plugin_register_file_t - register information + * + * This structure identifies registers. The identifiers included in this + * structure are identical with names used in GDB's standard target features + * with some extensions. For details, see: + * https://sourceware.org/gdb/onlinedocs/gdb/Standard-Target-Features.html + * + * A register is uniquely identified with the combination of a feature name + * and a register name or a register number. It is recommended to derive + * register numbers from feature names and register names each time a new vcpu + * starts. + * + * To derive the register number from a feature name and a register name, + * first look up qemu_plugin_register_file_t with the feature name, and then + * look up the register name in its @regs. The sum of the @base_reg and the + * index in the @reg is the register number. + * + * Note that @regs may have holes; some elements of @regs may be NULL. + */ +typedef struct qemu_plugin_register_file_t { + /** @name: feature name */ + const char *name; + /** @regs: register names */ + const char * const *regs; + /** @base_reg: the base identified number */ + int base_reg; + /** @num_regs: the number of elements in @regs */ + int num_regs; +} qemu_plugin_register_file_t; + +/** + * qemu_plugin_get_register_files() - returns register information + * + * @vcpu_index: the index of the vcpu context + * @size: the pointer to the variable to hold the number of returned elements + * + * Returns an array of qemu_plugin_register_file_t. The user should g_free() + * the array once no longer needed. + */ +qemu_plugin_register_file_t * +qemu_plugin_get_register_files(unsigned int vcpu_index, int *size); + +/** + * qemu_plugin_read_register() - read register + * + * @buf: the byte array to append the read register content to. + * @reg: the register identifier determined with + * qemu_plugin_get_register_files(). + * + * This function is only available in a context that register read access is + * explicitly requested. + * + * Returns the size of the read register. The content of @buf is in target byte + * order. + */ +int qemu_plugin_read_register(GByteArray *buf, int reg); + #endif /* QEMU_QEMU_PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index 2078b16edb..dd7ff5067b 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -35,6 +35,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" #include "tcg/tcg.h" @@ -442,3 +443,42 @@ uint64_t qemu_plugin_entry_code(void) #endif return entry; } + +static void count_gdb_feature(void *opaque, const GDBFeature *feature, + int base_reg) +{ + (*(int *)opaque)++; +} + +static void map_gdb_feature(void *opaque, const GDBFeature *feature, + int base_reg) +{ + qemu_plugin_register_file_t **cursor = opaque; + (*cursor)->name = feature->name; + (*cursor)->regs = feature->regs; + (*cursor)->base_reg = base_reg; + (*cursor)->num_regs = feature->num_regs; + (*cursor)++; +} + +qemu_plugin_register_file_t * +qemu_plugin_get_register_files(unsigned int vcpu_index, int *size) +{ + QEMU_IOTHREAD_LOCK_GUARD(); + + *size = 0; + gdb_foreach_feature(qemu_get_cpu(vcpu_index), count_gdb_feature, size); + + qemu_plugin_register_file_t *files = + g_new(qemu_plugin_register_file_t, *size); + + qemu_plugin_register_file_t *cursor = files; + gdb_foreach_feature(qemu_get_cpu(vcpu_index), map_gdb_feature, &cursor); + + return files; +} + +int qemu_plugin_read_register(GByteArray *buf, int reg) +{ + return gdb_read_register(current_cpu, buf, reg, true); +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549..4ed9e70e47 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -42,4 +42,6 @@ qemu_plugin_tb_vaddr; qemu_plugin_uninstall; qemu_plugin_vcpu_for_each; + qemu_plugin_get_register_files; + qemu_plugin_read_register; }; From patchwork Wed Aug 16 13:39:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=Al1gNmgw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqG413Hwz1yNm for ; Wed, 16 Aug 2023 23:47:56 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGoQ-0004Fn-8n; Wed, 16 Aug 2023 09:43:50 -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 1qWGoO-0004BA-J5 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:48 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGoL-0002L7-OK for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:48 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3a7d15fb7b1so3621118b6e.0 for ; Wed, 16 Aug 2023 06:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193424; x=1692798224; 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=5zIcJuxbGAgDC3LnJtGglsWAa27I1AZ8jTEBgk7e2vQ=; b=Al1gNmgwlxzQKBcFA2RoxAIxe9zPotGnWabz9Q6Z1lz1wbTDU6RarLfcFO4EoYfD6e 0Zn3hU5tlnG3GzTbdpRh4UpDIgn6nKu+Kw9dKDQ4TKSA9+WU/BSy6MGA+dJETUIV9mb6 Qe/p35SCAr6TSl6WypA7iv7hgpOeHRw4VdDMJ9yFyGV1ly5t/Z620lM6IZapYbeiU6WQ /9x8DcRYv/5dRcqrIFYSVueqsN3d1KnZ7Kbzre92hsmummoxcKRjA+nbx/HrM1onVguA w7jOCQtMUv/wHkOcmTG8SvVWKMpk3bFztYlUFtytWXB5lfbTmSgSS6k+7TsYxkQQR2mB y6zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193424; x=1692798224; 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=5zIcJuxbGAgDC3LnJtGglsWAa27I1AZ8jTEBgk7e2vQ=; b=e+jVnmQRvYxWPuSCJgTw9maj1cATyKGbbKciQjNJXk2uhVdWsEk/KV0ckzu0HaEhhM WVNKPuVPe22calr3zLWb2cNbYRW/Vlo6o6b2V843NQDcvL9tOWlxfPGNhUU9R2nsimaX knO0aw+2O3e8VMB3cqKX6rYMxxwvgq3ooeQSaQc1kZ+7fXA5WbsNK7WE25Eg8fbd18RH 441Z3VNWFRSd0STu0B0IHRDD7cSmwZmT0QpCQaCS+8wdk6eOTwif3i6g7wGDE8OiCl+L k0FDY01GvAoYkuW3PUFxwiIiSlhQ4jPglb5a9tsp1zzatxYAQRRtp56SaPO3u7hLDoM2 s2hQ== X-Gm-Message-State: AOJu0YzUklSk9QXN2hV2/crKq7JLCHRlqnIutAIMCOQi6gsHM0LYbItX JkmVAPfL9mRgQkqJ9ERtxu6SUw== X-Google-Smtp-Source: AGHT+IGP0tz4+26OjG0kAfvXU7oBgSEOeX+dQ6AccUX+7KHWvKdK/x4xzshTFe3WiAEsuLLRsw6CUQ== X-Received: by 2002:a05:6808:1783:b0:3a7:550c:635d with SMTP id bg3-20020a056808178300b003a7550c635dmr2312547oib.56.1692193424662; Wed, 16 Aug 2023 06:43:44 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:43:44 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 23/25] contrib/plugins: Allow to log registers Date: Wed, 16 Aug 2023 22:39:33 +0900 Message-ID: <20230816133938.18310-24-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::22b; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This demonstrates how a register can be read from a plugin. Signed-off-by: Akihiko Odaki --- docs/devel/tcg-plugins.rst | 10 ++- contrib/plugins/execlog.c | 140 +++++++++++++++++++++++++++++-------- 2 files changed, 118 insertions(+), 32 deletions(-) diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index 81dcd43a61..c9f8b27590 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -497,6 +497,15 @@ arguments if required:: $ qemu-system-arm $(QEMU_ARGS) \ -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin +This plugin can also dump a specified register. The specification of register +follows `GDB standard target features `__. + +Specify the name of the feature that contains the register and the name of the +register with ``rfile`` and ``reg`` options, respectively:: + + $ qemu-system-arm $(QEMU_ARGS) \ + -plugin ./contrib/plugins/libexeclog.so,rfile=org.gnu.gdb.arm.core,reg=sp -d plugin + - contrib/plugins/cache.c Cache modelling plugin that measures the performance of a given L1 cache @@ -583,4 +592,3 @@ The following API is generated from the inline documentation in include the full kernel-doc annotations. .. kernel-doc:: include/qemu/qemu-plugin.h - diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c index ce67acf145..21b92ab1b3 100644 --- a/contrib/plugins/execlog.c +++ b/contrib/plugins/execlog.c @@ -15,27 +15,43 @@ #include +typedef struct CPU { + /* Store last executed instruction on each vCPU as a GString */ + GString *last_exec; + GByteArray *reg_history[2]; + + int reg; +} CPU; + QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -/* Store last executed instruction on each vCPU as a GString */ -static GPtrArray *last_exec; +static CPU *cpus; +static int num_cpus; static GRWLock expand_array_lock; static GPtrArray *imatches; static GArray *amatches; +static char *rfile_name; +static char *reg_name; + /* - * Expand last_exec array. + * Expand cpu array. * * As we could have multiple threads trying to do this we need to * serialise the expansion under a lock. */ -static void expand_last_exec(int cpu_index) +static void expand_cpu(int cpu_index) { - g_rw_lock_writer_unlock(&expand_array_lock); - while (cpu_index >= last_exec->len) { - GString *s = g_string_new(NULL); - g_ptr_array_add(last_exec, s); + g_rw_lock_writer_lock(&expand_array_lock); + if (cpu_index >= num_cpus) { + cpus = g_realloc_n(cpus, cpu_index + 1, sizeof(*cpus)); + while (cpu_index >= num_cpus) { + cpus[num_cpus].last_exec = g_string_new(NULL); + cpus[num_cpus].reg_history[0] = g_byte_array_new(); + cpus[num_cpus].reg_history[1] = g_byte_array_new(); + num_cpus++; + } } g_rw_lock_writer_unlock(&expand_array_lock); } @@ -50,8 +66,8 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info, /* Find vCPU in array */ g_rw_lock_reader_lock(&expand_array_lock); - g_assert(cpu_index < last_exec->len); - s = g_ptr_array_index(last_exec, cpu_index); + g_assert(cpu_index < num_cpus); + s = cpus[cpu_index].last_exec; g_rw_lock_reader_unlock(&expand_array_lock); /* Indicate type of memory access */ @@ -77,28 +93,44 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info, */ static void vcpu_insn_exec(unsigned int cpu_index, void *udata) { - GString *s; + CPU cpu; + int n; + int i; /* Find or create vCPU in array */ g_rw_lock_reader_lock(&expand_array_lock); - if (cpu_index >= last_exec->len) { - g_rw_lock_reader_unlock(&expand_array_lock); - expand_last_exec(cpu_index); - g_rw_lock_reader_lock(&expand_array_lock); - } - s = g_ptr_array_index(last_exec, cpu_index); + cpu = cpus[cpu_index]; g_rw_lock_reader_unlock(&expand_array_lock); /* Print previous instruction in cache */ - if (s->len) { - qemu_plugin_outs(s->str); + if (cpu.last_exec->len) { + qemu_plugin_outs(cpu.last_exec->str); qemu_plugin_outs("\n"); } /* Store new instruction in cache */ /* vcpu_mem will add memory access information to last_exec */ - g_string_printf(s, "%u, ", cpu_index); - g_string_append(s, (char *)udata); + g_string_printf(cpu.last_exec, "%u, ", cpu_index); + g_string_append(cpu.last_exec, (char *)udata); + + if (cpu.reg >= 0) { + GByteArray *current = cpu.reg_history[0]; + GByteArray *last = cpu.reg_history[1]; + + g_byte_array_set_size(current, 0); + n = qemu_plugin_read_register(current, cpu.reg); + + if (n != last->len || memcmp(current->data, last->data, n)) { + g_string_append(cpu.last_exec, ", reg,"); + for (i = 0; i < n; i++) { + g_string_append_printf(cpu.last_exec, " %02X", + current->data[i]); + } + } + + cpu.reg_history[0] = last; + cpu.reg_history[1] = current; + } } /** @@ -167,8 +199,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) QEMU_PLUGIN_MEM_RW, NULL); /* Register callback on instruction */ - qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec, - QEMU_PLUGIN_CB_NO_REGS, output); + qemu_plugin_register_vcpu_insn_exec_cb( + insn, vcpu_insn_exec, + rfile_name ? QEMU_PLUGIN_CB_R_REGS : QEMU_PLUGIN_CB_NO_REGS, + output); /* reset skip */ skip = (imatches || amatches); @@ -177,17 +211,53 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) } } +static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + int reg = 0; + bool found = false; + + expand_cpu(vcpu_index); + + if (rfile_name) { + int i; + int j; + int n; + + qemu_plugin_register_file_t *rfiles = + qemu_plugin_get_register_files(vcpu_index, &n); + + for (i = 0; i < n; i++) { + if (g_strcmp0(rfiles[i].name, rfile_name) == 0) { + for (j = 0; j < rfiles[i].num_regs; j++) { + if (g_strcmp0(rfiles[i].regs[j], reg_name) == 0) { + reg += j; + found = true; + break; + } + } + break; + } + + reg += rfiles[i].num_regs; + } + + g_free(rfiles); + } + + g_rw_lock_writer_lock(&expand_array_lock); + cpus[vcpu_index].reg = found ? reg : -1; + g_rw_lock_writer_unlock(&expand_array_lock); +} + /** * On plugin exit, print last instruction in cache */ static void plugin_exit(qemu_plugin_id_t id, void *p) { guint i; - GString *s; - for (i = 0; i < last_exec->len; i++) { - s = g_ptr_array_index(last_exec, i); - if (s->str) { - qemu_plugin_outs(s->str); + for (i = 0; i < num_cpus; i++) { + if (cpus[i].last_exec->str) { + qemu_plugin_outs(cpus[i].last_exec->str); qemu_plugin_outs("\n"); } } @@ -224,9 +294,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, * we don't know the size before emulation. */ if (info->system_emulation) { - last_exec = g_ptr_array_sized_new(info->system.max_vcpus); - } else { - last_exec = g_ptr_array_new(); + cpus = g_new(CPU, info->system.max_vcpus); } for (int i = 0; i < argc; i++) { @@ -236,13 +304,23 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, parse_insn_match(tokens[1]); } else if (g_strcmp0(tokens[0], "afilter") == 0) { parse_vaddr_match(tokens[1]); + } else if (g_strcmp0(tokens[0], "rfile") == 0) { + rfile_name = g_strdup(tokens[1]); + } else if (g_strcmp0(tokens[0], "reg") == 0) { + reg_name = g_strdup(tokens[1]); } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; } } + if ((!rfile_name) != (!reg_name)) { + fputs("file and reg need to be set at the same time\n", stderr); + return -1; + } + /* Register translation block and exit callbacks */ + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); From patchwork Wed Aug 16 13:39:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=lU0HwLHL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqC04j83z1yNm for ; Wed, 16 Aug 2023 23:45:16 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGom-0004W5-AX; Wed, 16 Aug 2023 09:44:13 -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 1qWGoY-0004Qi-Q4 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:44:04 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGoV-0002ND-9N for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:43:57 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5650ef42f6dso4011795a12.0 for ; Wed, 16 Aug 2023 06:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193434; x=1692798234; 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=3o76KcQlFp/MuUPscQNwseGhYtySE7hW349U50r8SMs=; b=lU0HwLHLEahkhhIIrOxAKwPSL2Cvjx2wpLCco5heXqC3PNZm4os91oplWyHM22FVCK kEJSzHefztvho7JRs5n5oAJZ6rdhNiQTJ07rrysBU5h59y09Wly8kYNz7ZD0Zuc1KTQb IXQjS8WZJBtcBYs0rpEQBW47Hcg1yH0nCk4cygFktKpZtqpDn/+RBwhMGwpaM7OHs6HC LAljrLw+uOn2CkgJZlexM9pGYSFEGoMGIV71Pxjb1ECLcFaYq8XPWs0l9CNP/AqJNZJ+ TExeK6McHrbC25B32KN6qi2W4wSKznZiuxqTfLzHpydnFgpX5EEk/giLBaXV3pytbqc9 X/iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193434; x=1692798234; 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=3o76KcQlFp/MuUPscQNwseGhYtySE7hW349U50r8SMs=; b=TZIIhb1FRxUcvFgzKR5idOZKlN7Zd+BCLHpXKqTxVkaxo5jFUJE7uDbgs7ZMS5Rhk2 cVj9ib3lC/Po8vUkIieFKM6mjAYaJCLipv9M1aRZtzkmrD6kk9Vtz33WUrFYcumyj3xy oFbt+DjdJEzkwY0dVCsHDWeXwJwz7Li5z/l2MswNw8rTGXMWT1OHmNSMi5+Ese7bpJre x96SZenKbiLIkFCxz+1a8kzykBZIEZtPBxaY45WCEU1pnaE+LYl86kBU92HpzcxCE9gt Trg2rAZ8CcYty+jVM245bv4sT93DbRTV+CPk3RWBeXXSZg0YLcRsQVBnerd9uMobJjJk xJQg== X-Gm-Message-State: AOJu0YyhayVgGuvfD4v8uw1bxToF/ztRve8Yb+2kobHHyosb1fMPN3p7 QVbec2E4gqy6SmOHqspPF3J8UQ== X-Google-Smtp-Source: AGHT+IFQLZBLAKQEvnfK4L6F2IWDmnkcOBA0cSVcj4jC/pDXzUIC2LH4XHeYp++FOHCLZU6XibLkmg== X-Received: by 2002:a17:90b:fcf:b0:269:7eea:d7f6 with SMTP id gd15-20020a17090b0fcf00b002697eead7f6mr1094012pjb.49.1692193434042; Wed, 16 Aug 2023 06:43:54 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:43:53 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 24/25] plugins: Support C++ Date: Wed, 16 Aug 2023 22:39:34 +0900 Message-ID: <20230816133938.18310-25-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::529; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x529.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make qemu-plugin.h consumable for C++ platform. Signed-off-by: Akihiko Odaki --- include/qemu/qemu-plugin.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 214b12bfd6..8637e3d8cf 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -16,6 +16,8 @@ #include #include +G_BEGIN_DECLS + /* * For best performance, build the plugin with -fvisibility=hidden so that * QEMU_PLUGIN_LOCAL is implicit. Then, just mark qemu_plugin_install with @@ -723,4 +725,6 @@ qemu_plugin_get_register_files(unsigned int vcpu_index, int *size); */ int qemu_plugin_read_register(GByteArray *buf, int reg); +G_END_DECLS + #endif /* QEMU_QEMU_PLUGIN_H */ From patchwork Wed Aug 16 13:39:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=apjasUEC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqFz6mlxz1yNm for ; Wed, 16 Aug 2023 23:47:51 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGp9-0005CP-Qe; Wed, 16 Aug 2023 09:44:35 -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 1qWGom-0004Yk-FC for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:44:13 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGoj-0002Oa-0f for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:44:12 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68706b39c4cso4750809b3a.2 for ; Wed, 16 Aug 2023 06:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193443; x=1692798243; 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=kNR+2DDMQySc8psqEDhnZbBav2KTV36MZCBGyLQQO2o=; b=apjasUECty4E3j3H1yWaQ2ypXdq1EM5noHQtAyFyRpHIcMP4TRKtUC/1XY60F4FFa7 /o/R6gD8qU7/9t9bsvMOchXDJ+zatKQFeUkQ2JrbEtYZ8EnRuByS4QhQGc+MhgCAbvbW 2aupMn0dvFec+wHuaetOnIrdn2MNs1wS95We/4KDB0fd/agMWEv2ycQezGVEsU5jHJqs Iq11kjqZdGQIJ2o+eF20sztGK+sGIKMuRI44JTpYajjibD2B8MrU75pdizStXG9Gw39g 8T+pAtqe+RFyGH9CwpPBTNRF7YzL8HM58tluFUbxEWhRnQFIlcoa4S7xrYd6tdKhhpQc 0XFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193443; x=1692798243; 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=kNR+2DDMQySc8psqEDhnZbBav2KTV36MZCBGyLQQO2o=; b=EbUXaP8At9GpPXE/M6sRyOCAl0kqKc3AnZKvwDG6jyX9rpOvYthyjKMeaxaqr4PJ7s v5Fsnfq2lap14BiO1OrPD/zTVm1S3zfG2OEo0eO2+mq1qjIEoIu4ddMhMF8w2JfMBoW2 rrEehD9yHCj9rPOwcy+yM2xLrGmXWYuEe7DTUa9obUlFyqg0dS3Ppa5zR08YCjZn5OMg fKC2FVvNi9dK34ZhoP6ImJ8+/En+g2BgY5iAJlikMJTa0Td81f5KIz9x5e0uuqs7cNQn imZRDRVezrUoX56FyMEJlbipNqP11ssR1OGbuCyD3KCV6fT0YC11rSagbkLz06qkbOtc VK5A== X-Gm-Message-State: AOJu0YxKC6EVo9A5zQb9aEXURBI/raQ1N0hTh+jQmVqmf9YjW0j7GDo2 S9f2rBI3JmXPrPp242YWxIiydA== X-Google-Smtp-Source: AGHT+IHrpTXk7bmJEfe0yYLFA3VDDTCbJD8Nw5TkYQRy67Dy8S3RZxehlcveaw6g63mji3enpJP6Cg== X-Received: by 2002:a05:6a00:8d1:b0:67a:8f2a:2cb2 with SMTP id s17-20020a056a0008d100b0067a8f2a2cb2mr1985856pfu.20.1692193443324; Wed, 16 Aug 2023 06:44:03 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:44:03 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 25/25] contrib/plugins: Add cc plugin Date: Wed, 16 Aug 2023 22:39:35 +0900 Message-ID: <20230816133938.18310-26-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::434; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x434.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This demonstrates how to write a plugin in C++. Signed-off-by: Akihiko Odaki --- docs/devel/tcg-plugins.rst | 8 ++++++++ configure | 15 ++++++++++++--- contrib/plugins/Makefile | 5 +++++ contrib/plugins/cc.cc | 17 +++++++++++++++++ tests/tcg/Makefile.target | 3 +++ 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 contrib/plugins/cc.cc diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index c9f8b27590..0a11f8036c 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -584,6 +584,14 @@ The plugin has a number of arguments, all of them are optional: configuration arguments implies ``l2=on``. (default: N = 2097152 (2MB), B = 64, A = 16) +- contrib/plugins/cc.cc + +cc plugin demonstrates how to write a plugin in C++. It simply outputs +"hello, world" to the plugin log:: + + $ qemu-system-arm $(QEMU_ARGS) \ + -plugin ./contrib/plugins/libcc.so -d plugin + API --- diff --git a/configure b/configure index 26ec5e4f54..0065b0dfe0 100755 --- a/configure +++ b/configure @@ -293,10 +293,18 @@ else cc="${CC-${cross_prefix}gcc}" fi -if test -z "${CXX}${cross_prefix}"; then - cxx="c++" +if test -n "${CXX+x}"; then + cxx="$CXX" else - cxx="${CXX-${cross_prefix}g++}" + if test -n "${cross_prefix}"; then + cxx="${cross_prefix}g++" + else + cxx="c++" + fi + + if ! has "$cxx"; then + cxx= + fi fi # Preferred ObjC compiler: @@ -1702,6 +1710,7 @@ echo "MESON=$meson" >> $config_host_mak echo "NINJA=$ninja" >> $config_host_mak echo "PKG_CONFIG=${pkg_config}" >> $config_host_mak echo "CC=$cc" >> $config_host_mak +echo "CXX=$cxx" >> $config_host_mak echo "EXESUF=$EXESUF" >> $config_host_mak # use included Linux headers diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index b2b9db9f51..93d86b3d07 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -21,6 +21,9 @@ NAMES += lockstep NAMES += hwprofile NAMES += cache NAMES += drcov +ifneq ($(CXX),) +NAMES += cc +endif SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) @@ -31,6 +34,8 @@ CFLAGS += -fPIC -Wall CFLAGS += $(if $(CONFIG_DEBUG_TCG), -ggdb -O0) CFLAGS += -I$(SRC_PATH)/include/qemu +CXXFLAGS := $(CFLAGS) + all: $(SONAMES) %.o: %.c diff --git a/contrib/plugins/cc.cc b/contrib/plugins/cc.cc new file mode 100644 index 0000000000..83a5528db0 --- /dev/null +++ b/contrib/plugins/cc.cc @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include + +extern "C" { + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, int argc, + char **argv) +{ + qemu_plugin_outs("hello, world\n"); + return 0; +} + +}; diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 462289f47c..3d7837d3b8 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -149,6 +149,9 @@ PLUGIN_SRC=$(SRC_PATH)/tests/plugin PLUGIN_LIB=../../plugin VPATH+=$(PLUGIN_LIB) PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c))) +ifneq ($(CXX),) +PLUGINS+=$(patsubst %.cc, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.cc))) +endif # We need to ensure expand the run-plugin-TEST-with-PLUGIN # pre-requistes manually here as we can't use stems to handle it. We