From patchwork Wed Aug 16 14:51:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821881 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=IS98RPSo; 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 4RQrjn6jxWz1xrk for ; Thu, 17 Aug 2023 00:53:33 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHst-0005uW-Pj; Wed, 16 Aug 2023 10:52:31 -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 1qWHss-0005uG-GW for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:52:30 -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 1qWHsp-0001D1-J1 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:52:29 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-687ca37628eso6275639b3a.1 for ; Wed, 16 Aug 2023 07:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197546; x=1692802346; 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=IS98RPSoM3bHM532wB3kGFtMQpyITAnx71ZNLFCE00bUEp/cSqOVhZ1K0iA5kpihq6 BRLl2OXfqX34J2J2L2cfhhPuHdiPtzE0pMl77seizCPTDrduCZc5IGAliHm4cIAN758F sFUPNr4oDH5YHSqKjOH4VlyvNm8MAorVsGECwc3Q7HLkGmeWJWX2mV4IcqbNmKDfGJT9 WoO7X0hH2DLxMNn8lj3jzOz3Fn1ZijU8o0LXT7V7w8TwQ2fOJ2S1Ij/ZY07bdTyREdMb KF/9+vHP9w/LU8V7D8rUYw8p9YphgfDHAiJwSE68BRzJ+TJzDWoCrgFT+FPO15FtI9af 3MuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197546; x=1692802346; 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=PlU3v0eyS162cSnuf0B7J9GxTLz9gOx7d6vP3dGwZcfQYFpQiF7bRSGlGeDMGTQFtD hDBC/3LBEvAjVt4gmff91dYau6+3gIN1bywCZHJaStwMAbZUS6cz3sIUlgMieO7A/lB5 fJ1nSDlI/Y4QiwkwDgHaCV0K3YBbUGNelplW1lDU9iUzRU7CP7D67xMaAjgIq1C1Kkan k57CEK/eZT5iQSfhL1qFpiM0IMgbVbPWc3A429oK1OGLuy33IEMeiPxlT7WwImjI4mqz J3FLUaOjPtOxBXwEkn7p9G/N76KYQMSNJ5/VXbE9vqMV6iIUtWo4KX/jr2gfTo90JLFT 06MQ== X-Gm-Message-State: AOJu0Yz3EaAkKT2A2pNwcE73q4ARkI8mIVPePzSzw6MYJQk5DRIFCM22 X+RsIn2Q9ZfzMauh7iqRVvAbmw== X-Google-Smtp-Source: AGHT+IGvqTVlRSSkvBFQxZQ6Oytspddpo1IsISOp9PrJWZtteCsFnXnUM/ejoMkcxYQmUWq95f9M6g== X-Received: by 2002:a05:6a20:5485:b0:133:be9d:a9e6 with SMTP id i5-20020a056a20548500b00133be9da9e6mr3463895pzk.17.1692197546383; Wed, 16 Aug 2023 07:52:26 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:52:26 -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 v4 01/25] contrib/plugins: Use GRWLock in execlog Date: Wed, 16 Aug 2023 23:51:22 +0900 Message-ID: <20230816145155.21049-2-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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=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 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 14:51:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821930 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=A0rVR86W; 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 4RQryF0jwnz1yNr for ; Thu, 17 Aug 2023 01:04:21 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHt6-00062L-4N; Wed, 16 Aug 2023 10:52:44 -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 1qWHt1-00060m-UP for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:52:40 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHsz-0001IK-4f for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:52:39 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6887480109bso1312830b3a.0 for ; Wed, 16 Aug 2023 07:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197556; x=1692802356; 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=A0rVR86WvkthxoccAWepRnLPAptzSghRtySvEczDArmrBUlQEuHZ7IoDWUB8vxCY+m OEi2gB7zubQnjRlKeMy6BNyXSEk/ASB+0kgY4ZNhTWc1/u9dGY4KpcoXzgTcMUjgn+2Q UXivVlCAgdYM42P72Kr7OjjqVe6Y2HboeyuBAP2/mZBLUP6pd2TlC+xD+/LAgMGjaCtl paetGOL7V8XxpQ2Su9xCMqF5R4s9G8qOnnFD8IFBo45FsVzMz9pVZj74IrcFHz9ADM4D nH3RJ/LEVVdby/yue6Vd7ht/73Y2z+20DFjMR8WWFAzUI+M8wpFTwbWoZrbp8xBSebtR FHOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197556; x=1692802356; 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=AtHoO8HVs/Zj6rWkOtdvKGriV5dF5DhaPxqD1QL0zJIaBeNct4s08cPqVf0zupDhGW vSXE3mRGYrZiCn+UbC5gY7GCtDaWovTT7BU1zhEheiTRiqcmITanUi4mY/RN8XYZmKSL Kc1VhDy4+SfwU7KpzZy9poTynUuQK5WDtIhenTWQ8Gg3TCwiMXr2ZTWYc/M23VVF/YFe +ZimWQoTcyTppEEO7Eja3+XBw7X3AMF1RTf1WlW78YrIsSqX6Jg+kJc+u0+RCwmQeow4 26O1HPjlDJHtzz9O0buuTDuP5PbuyHVOT4FhewFY15FQ3C1aW4Cs9mMxZCMVP2sG6ubx aqFA== X-Gm-Message-State: AOJu0Yz+IX0udnMBwRN+AYK3HxW4otwxwioWa8XF+uEwQkE/Lc811YGv A/h76T/1P8xoKT48HK/F2QyDLQ== X-Google-Smtp-Source: AGHT+IFOA7TUNrLul0QhFJNL9pHkUvSyr/4aUbIVMpIq1AWpXe19cJ7YF4GOm085M+5r7kOMhrj2/Q== X-Received: by 2002:a05:6a20:f3a4:b0:137:23a2:2b3c with SMTP id qr36-20020a056a20f3a400b0013723a22b3cmr2409995pzb.49.1692197555726; Wed, 16 Aug 2023 07:52:35 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:52: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 v4 02/25] gdbstub: Introduce GDBFeature structure Date: Wed, 16 Aug 2023 23:51:23 +0900 Message-ID: <20230816145155.21049-3-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::429; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x429.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 Reviewed-by: Richard Henderson --- 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 14:51: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: 1821922 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=Y0/1peXz; 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 4RQrt52Vmwz1yNr for ; Thu, 17 Aug 2023 01:00:45 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHtK-0006B4-A1; Wed, 16 Aug 2023 10:52:59 -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 1qWHtC-000667-Ps for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:52:52 -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 1qWHt9-0001Jh-Pd for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:52:50 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-687ca37628eso6276053b3a.1 for ; Wed, 16 Aug 2023 07:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197565; x=1692802365; 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=Y0/1peXzSs4juY9ymgumb5RiSvn27fHcwAKJy2ZTGrBeRn819iCH4nljP47QRA4Vxg 40x7+5r+XfiPGBkZXcnfvCQ9uqAFHzUNWAZpDhpHzdbT5Q0nIPXG8HErXfQZIjQjJfzv o0ItrgPHttMEcQB6Ux7G0YWWB1snPmmHP09fH/D3ReCsxce+1ZGkAsn2LDchA7RblP7n zQ/cIUgkuVMazDBweDx5VH2Ni2/6l5M60vOYncc9S+Jr+UsKJY0wS2yFjb4rxeLRb9r7 2SoVeos2JmEswJDmRGDnFADAa1IbdAN+sRrSues6d3ioN23P8fJUmNUYv4v/qLMC8lB4 jhlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197565; x=1692802365; 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=dSuHq8Fu3wyKLE2qhVo/YmlYX7QV7+PPrQBvowz0D1/xzn1D60PkUZ5iOTfUHO027s ROZbGqsD1yMRbQGgKzU4VnoCEFAJlvEXq91r3OaFDs1qysQAg98h4FiqNiQfTE+S1LVH rdjD6cQsLnQhMe06cvXujd6ma3znG8lqJlYxgEs1NZhSfx1DCFXzEDRnQxXW05s93KfR b/Ov0l3MktXBK3ojAZ7gWn8+sfWPAcOe33KYXCt/iWaySTTyUO2DByLf0ANogX8UqtDX RswIYBNDc+o3HLDVHQ8yRqww8OgXqPRWVCs2MlikE2HBM2RxRthx39Ul7D7mB+Cddbyg Iihg== X-Gm-Message-State: AOJu0YytWck5gOhhwV0W2LNLFMLq6pQC/lTlZnoELGK0ojIg7Hmws3g8 5UrTarYoxypziFDBGMvY7k7hng== X-Google-Smtp-Source: AGHT+IEhJ4BtQBo9Fd+dpB+PERq1IPryRWmwgf25koKSBcnkGRiPIJLkSwaQcvy/u89B/gdB6Kif/A== X-Received: by 2002:a05:6a00:24c7:b0:67a:8fc7:1b61 with SMTP id d7-20020a056a0024c700b0067a8fc71b61mr2510244pfv.11.1692197565072; Wed, 16 Aug 2023 07:52:45 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:52: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 v4 03/25] gdbstub: Add num_regs member to GDBFeature Date: Wed, 16 Aug 2023 23:51:24 +0900 Message-ID: <20230816145155.21049-4-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 14:51:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821891 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=g5gIZwU6; 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 4RQrm74f6Sz1yNm for ; Thu, 17 Aug 2023 00:55:35 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHtR-0006Nf-Ur; Wed, 16 Aug 2023 10:53:05 -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 1qWHtN-0006GM-2w for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:01 -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 1qWHtJ-0001LC-0y for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:00 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6884310ee75so2434847b3a.1 for ; Wed, 16 Aug 2023 07:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197574; x=1692802374; 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=g5gIZwU6UwCQWXPmS+5P+fF94QVoM6wZggI9uprZGCRsS1BeWizVJSq8VgrcyPkZWR NzvKlI6AbZ5z+3le5KoHsQW2K3sj8c0aKS0Nt2OtoaXrzRKP+z4hYZrmAuV75LEL+qIw LottnaIjQ619Drz1cIfpkQdwU/81eIMB+EFtoakoHrNWL+hO4HvT3rGI8SQgYL1WUBgR V1EX8uuhVeP4AbBOINNBnrwIA15Jz0BUrm7YgvpoLkmZLmhkJZvLmLmuI7grNPIT0+9z 81SysbcziYUVKsAVk3RFbuyMpdH6PRMMeUBelM/DWJpuPn1xNssTHairK4nLGH4N28tG ynlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197574; x=1692802374; 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=GVO8RY4+4pP9KQYT2eau2uZQD4Lc4Fi6rqSzoWTMiJC57FfdpSox+Zz0BjcjZs7tuR 6Vvpiwxtwh7Las8JNrOiHrhFE9NnI5SuwBmA500TlGhZmBdvz/uwhn8XqU2+MkHDZlxl CO4LzKpNh4VeoSxWCuzbmwBR3QCAOpiwZXh+EbeYLHygg565qiXtMOHFVyJzDEfeAmgF JM4SMDHSUV8GVEirriNuIxNzwOF/3yIQY4xgAVkTaP9HzMyWJWwiQNyY5ieCb+pCAad1 XVI0gtmojrajJM1c7rvATqOt583HU/Rez+5jV9SoRHWgNemd4R2WbVVl9FN31fSkep0r HiJQ== X-Gm-Message-State: AOJu0Yxgh0w1G9c+k390F9IFA0lv7j4SKOqoZH5F5RO9DXHUr/95E7vT Ksh8gGl5/avcfyW5kA9t6vRRiQ== X-Google-Smtp-Source: AGHT+IELSulh/oz6ixtFLkZnD+ZZTF7a4OEbk5wN+eGCSB625pWQA9nU9mWM2B5J89v0SG1HND+jRA== X-Received: by 2002:a05:6a20:7da4:b0:133:6816:c889 with SMTP id v36-20020a056a207da400b001336816c889mr2729018pzj.40.1692197574627; Wed, 16 Aug 2023 07:52:54 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:52:54 -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 v4 04/25] gdbstub: Introduce gdb_find_static_feature() Date: Wed, 16 Aug 2023 23:51:25 +0900 Message-ID: <20230816145155.21049-5-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 Reviewed-by: Richard Henderson --- 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 14:51: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: 1821879 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=xCImB5v5; 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 4RQrjZ1nBwz1yXY for ; Thu, 17 Aug 2023 00:53:22 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHtW-0006Xy-Sz; Wed, 16 Aug 2023 10:53:10 -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 1qWHtV-0006Ux-7n for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:09 -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 1qWHtR-0001NO-8h for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:08 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68891000f34so484901b3a.0 for ; Wed, 16 Aug 2023 07:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197584; x=1692802384; 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=xCImB5v5maAEizBxYrL++QyPLtpfkKhGwmGWVebpN15hlVtBjPauFwhD5ixf0KBwMk sIKtdNEvH2wQOesAAQsf5FA98L5Cmi2AghDnnPAoOuxLtMM7ibKpgdHsFNIM00eg4/eV M1Tng7gTNhUmHYwJX70f3otQYGkNNwuQuq7syuxlkaO6YrFSDji2yMTCxo0WVlQtAL2o v1Z0Jr1xQBYUXURz0ACmoVGysez/cKx5aJbnABv+4zFDs9kHTRrdfTZCOMm0E5S39pdT e5tMSJaK1udB5tB7QP3qYBYwR2hwFor9AeW0hebaEERIXsqlDoOJsUKL8JA9ty0t2Na1 0Q9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197584; x=1692802384; 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=ZVg/DhOunMpvoIdMkv1pWDJySTFP07JzKq0b3ru2fBS6bKhQ+m5jeqJ7txTIDr+uTN katGAILXt4MD3iVHbTD1kGcwL7JN7lT64mSZYHo7Smhl2M6fz3mPH33uMTNjsnIirzVY wkheUXkshak30GPT4iSVmiLb3IpjoNg6lQkbJE5ev0+Fw1Es1hZvDyqwFsCbqNelnvUh qUBj41Qt8dSdyY4vDU3oBXwanWRTJzZNwTcC/3s2H0XDjJuRsgBQDSFGNlrnQAVELmti 6xL6JGG+gqbQy1ETGPBj9DTM5UMQUipNzpxLeGX09VAWfc2L6czXo1hxL8Cmh0bhkPja QT8A== X-Gm-Message-State: AOJu0Yy5CFu+qyZWUl5xlxJTirjuAix+4zyF/rZZyYS2DP7IkqKifF9x /bncV/wb5rDaL8Lh0KLL8Px9Yw== X-Google-Smtp-Source: AGHT+IF136Ut7u8F19vMuGhsXspxaXkVuzAyk+qpMrK6l25QgUWT+DrFPsCrMtLv5a3md/bGqcreAw== X-Received: by 2002:a05:6a00:1587:b0:687:1c2c:7cf7 with SMTP id u7-20020a056a00158700b006871c2c7cf7mr2738945pfk.19.1692197583989; Wed, 16 Aug 2023 07:53:03 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:53: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 v4 05/25] target/arm: Move the reference to arm-core.xml Date: Wed, 16 Aug 2023 23:51:26 +0900 Message-ID: <20230816145155.21049-6-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 Reviewed-by: Richard Henderson --- 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 14:51: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: 1821933 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=rO5eo+mk; 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 4RQryX0PzLz1yXY for ; Thu, 17 Aug 2023 01:04:36 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHtj-0006gm-BE; Wed, 16 Aug 2023 10:53:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWHte-0006bJ-Va for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:19 -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 1qWHta-0001PU-Iy for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:17 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6887c3aac15so796262b3a.2 for ; Wed, 16 Aug 2023 07:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197593; x=1692802393; 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=rO5eo+mkBbcjFdnpeKsEjAegx1QyJXJnAgeueGDrPLxrzIEvrGeNo0Krz3fG2zyHlZ QAnl6fV+QGNxDriqOYal7H3iTcVJbr3Vz4puSSp2Gf8no97PafYYezoUzdgXPys/1usm PMnu2H2AzfVrr0kPqGApkZuNEY4G7wtzcZmARfB7MiJQRLnGBB8HkZQOiuDrFmeahqEl avHVbbor2/GFzeXrYOOq5TrIeBuYyk5Yhcfq+P/JgO7T8ORH3MdKkHb0VVzftkxGa7fM fzHZiHjH/b6ks6K2merN+KT1rUSFLNbIsi0lHutpJgBO3pS1bGGQD6SjCD/3BtmHbOkI f4PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197593; x=1692802393; 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=gtfJah5BmJMWeWNqcCemi7B4AGLmiCN4mvkeZcYe+ympKjwGdGJRLjBVuOlLz4FG23 0UJFvZn2xIZyoJNwLUzAkoGPiLwUdobflm4OyEyEB6vIb/IdA6+kAMGWytAnW4dQqwaI JU7jK/KW84ScgQWDTFSPuHXPYC/HyTX4x0PtEER8uyEksVvF98vwp32VWFRWnkPh34lg 3x9RBGXsvB3O5SQW9kM/pjp7kSa5DyzTorIPyy8Yg8rLqGU4+U01yOqhuu4F74rgaviv i1RMjcf8vvpU7qJ1r+bexog6ae+4a5MHxrfFB0Oj4wxBf1N/5i6P/DrPa+wLDpi93uvG amYg== X-Gm-Message-State: AOJu0YztLeXbxSYLY2AxBv3as5XMoP0a9Em90Es270kOLh/RD4UPr7v4 D//3NubXkJZXIp3PrRFepoTYOA== X-Google-Smtp-Source: AGHT+IGwyBmwMhc365pz0/+KNuPhhZjDl+XocVrBcEf5Q0nlmoKssbf5kf9rF2QBRlUXw1eSXfB01A== X-Received: by 2002:a05:6a21:7888:b0:140:f6c4:aa71 with SMTP id bf8-20020a056a21788800b00140f6c4aa71mr3214808pzc.8.1692197593358; Wed, 16 Aug 2023 07:53:13 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:53:13 -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 v4 06/25] hw/core/cpu: Replace gdb_core_xml_file with gdb_core_feature Date: Wed, 16 Aug 2023 23:51:27 +0900 Message-ID: <20230816145155.21049-7-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 14:51: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: 1821935 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=gfFw4qr8; 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 4RQrzX1Lffz1xrk for ; Thu, 17 Aug 2023 01:05:28 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHtx-00071d-6I; Wed, 16 Aug 2023 10:53: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 1qWHtn-0006nr-JH for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:28 -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 1qWHtl-0001SQ-6o for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:27 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6887059f121so1243847b3a.3 for ; Wed, 16 Aug 2023 07:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197603; x=1692802403; 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=gfFw4qr8LDWF1d1l/4miCiNDCiq2IoTts+WSF/QH8PvGN3nlEzusIhWtbB2yKAurEB kWyNQeGCSjkgJ7dc0EH9fC4EQ6r8dkAirfCGALUXqIPAIbxd8QO73r06ylEmuZHiYXUg BaFiHo0FLky+/NQPmKpqhMXqR/UpvUxgdBpJ2r9rdOzBKyFwkISCPg7qjhDLTCjQQf0r YniiR9wFE35q9FVM8zEuWimhA9FncKYotdiwqpLTnBtTZWFsvnpoW+X6s6GiqOLgw504 f95I5OEmoNVbYGMDrWkGw8RANvlS6MFsFXrlW7mqfcVwExbUKluvXU66PTydPmTHfVbP LWpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197603; x=1692802403; 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=RUiCzGGpzuScXHBA5sItReoyZ96CX+qhJn0zXD4VwBM4liWxR6apDcCesNWj4tlz2s 852AJEUedyH409n2F07U0maRwgxhqF8BJe4/FjVmvQUolmPUVNASQknbbmUwdY7a70Lt fhRALcYRNcbuCackGzrs1bYGYp5Ly1qs+hGr3wCUmIZvKSZ7b4z8qWcp8dTOgbAf2a8n YyxmjRKuiC2H3Tkk4BTXUv6/M2W//R5rjzAnrq8PFtMbUEjwxj3H5qWGZzo8AM72WygG 5pJiWahMSLfrQYczbKbkJhJ7RLbfSG9bh+POFxfUrELjPg9UlAjVW9mCruSEskT+fh2J jRLg== X-Gm-Message-State: AOJu0YxjW9SHN/Maj1JcmtWHobSlkOBv7sWL97sTcN6fEm/Ckll/TQaU 10bFABSKYjtSF0K21OxrKz4PQA== X-Google-Smtp-Source: AGHT+IEEMG2c43+TNdQ7c3Mam5hWpMlOmIAcudDAOrh4ILxOYg6x5LtKX8o5uOctFiF5N99D3j59Hw== X-Received: by 2002:a05:6a00:23cd:b0:687:4fcf:8fcd with SMTP id g13-20020a056a0023cd00b006874fcf8fcdmr2485594pfc.18.1692197603048; Wed, 16 Aug 2023 07:53:23 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:53:22 -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 v4 07/25] gdbstub: Introduce GDBFeatureBuilder Date: Wed, 16 Aug 2023 23:51:28 +0900 Message-ID: <20230816145155.21049-8-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 GDBFeatureBuilder unifies the logic to generate dynamic GDBFeature. Signed-off-by: Akihiko Odaki Reviewed-by: Richard Henderson --- 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 14:51: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: 1821911 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=Dl3/Wz1T; 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 4RQrrY3wRgz1yXY for ; Thu, 17 Aug 2023 00:59:25 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHu3-0007V0-Ht; Wed, 16 Aug 2023 10:53:43 -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 1qWHtz-0007Gs-8R for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:39 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHtu-0001TY-Er for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:37 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-688779ffc0aso1059859b3a.3 for ; Wed, 16 Aug 2023 07:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197612; x=1692802412; 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=Dl3/Wz1Tnh2j3ldsZ7iFg43X4rvJHsv5oYWH7Rht6O152qpDbUJlhO7ZVSGn8juFEJ XCdpxDNzQnfXUaqSR1JwnRMxfzAoU3TlURoHVHahUqi0h8OIUhcyFYEyElbK8sHIKd4y f8OrIRh1Ta0fOjToMMBqcr9PkbWZIi1IjsSJSTbXVy6Jui/xYKeOID9LmigwN8sRJmGo tl943bPrgkw2tbv4Vf9zafa7OYkwTEJpA/c9JMZbCAykZYNa2uwooJnYzgT0epBAMTCg 3oqL//ZC16GXHh+IBPmrjkWPriqWWHbVCvqh9redUA0YI0WATWDDHTJywwtDE37uZypz AdQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197612; x=1692802412; 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=UOgZLtWxNDT823ee+HOn2I/pX3c0b3xj8oJXJGUX2tVbGV+c2UZnX2mJ7IJMNlnjfn xFDFNlBCUXfpAz92vGwjvQCm2m0NPHobxkNots524jInHix1Zw2D+Z8CY2xWnKckO9OT dJ8ltuX12gWn/blgfw4fqAYzkncZoFRwU/dsdIx2pNQXNcVMfNcqIkJLfh/idXHB9Shw cOosMgr6eTzHQT64sTdZ4xqE/rJ/tcfjCVj4aor47dgdewTgxCW79Wj1LjzkApJXVG/C 7pJv0g9QQyWhXKBZTUhXtsKeLFgipX0ulyrbF+pMbEqQB3+sXg5BSJoki/KRQaaO18Ng teLw== X-Gm-Message-State: AOJu0YxHg8KRIIrp8aaaA0+fRsk14vooEBcBk5K+GfxTYBrEUq0d3vrz vJUkKg1Zlf/6kQmnFCc/vrx5pg== X-Google-Smtp-Source: AGHT+IHIEJuIQEs0GmF6Bx7zTltN5LIkiewknDu0vT3kWqdLWC25yKaOPOhJtr5V6C0NQHH3AedqEQ== X-Received: by 2002:a05:6a20:dd89:b0:133:86c:e805 with SMTP id kw9-20020a056a20dd8900b00133086ce805mr1898427pzb.10.1692197612492; Wed, 16 Aug 2023 07:53:32 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:53:32 -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 v4 08/25] target/arm: Use GDBFeature for dynamic XML Date: Wed, 16 Aug 2023 23:51:29 +0900 Message-ID: <20230816145155.21049-9-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::429; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x429.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 Acked-by: Richard Henderson --- 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 14:51: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: 1821885 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=hH3/fXw+; 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 4RQrl36Xqgz1xrk for ; Thu, 17 Aug 2023 00:54:39 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHu9-00081K-Kn; Wed, 16 Aug 2023 10:53:49 -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 1qWHu8-0007x1-8Q for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:48 -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 1qWHu3-0001VQ-Jk for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:47 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-686bc261111so4691757b3a.3 for ; Wed, 16 Aug 2023 07:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197622; x=1692802422; 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=hH3/fXw+D9GIpBxo6VDA6N7a8xLZouGQ5dubWF2mANy3HgkwAdSLv3GvfoV4SV9NF9 PiEfIQSjWjPjkC6Bc4Xj06OtD2gtkEhXkpUdZaa/6Bl03zZ61r82rVku4U3wbPerDn/r on5RGYr/R+9mJd5kX8NFUp+Sl7FuMUF4OdLeXIWpABRukG229dLSDpyk79YOThzrocYc DwQbk+WG3QAVL1o6D07ACkzTsdCmExDFXIIXaOeaGE3JBHUCozlad6nj+kVzuSuJfs3f y6RYrvv7t5Yx01sIhHfeDf8Qbxgb6JPt92vC+1y2P1a/vupNEGI/hrVm9bARhiRXP56W ndsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197622; x=1692802422; 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=QmPM3V3B4mRWtZ+kQrrP/zrz29LUfjXXM/p/fvLHKOOPv3Ziphcjse/hZjzyFAtohT CGArtdaefClMS92NG5pKXyt66+Atlj71sQcqB13RL0aw/4UGFsMmGRvMPdr2JrNKKlbF PUKXU1nASy2hdY0qfpr5c51a7H2iFFPCpByWbcDpxIvtCjE2ZoOlZXEC/L9g/ZUVDQlg wtj5R3ZahJ6BlxsTX/FNPpHDdigSnUtorW1WSBhHT6UIoE3dw1XBsvAfCbvesYWFfFS1 KI0oar7ZdGeEReSxe+ooFa2fwMmQewCtbJV4/lqqCpiFK+vMbqDGNABQ8L6zlO4Usvzz aSvQ== X-Gm-Message-State: AOJu0YwL7U2bs4XzrV2L1lh6GgDttC5zaXa4nDxsLYhHGCbIcgRyogNG 75NPKSKoH0yGGu1W28O+Ra49yg== X-Google-Smtp-Source: AGHT+IEMOEShkqLuKZ4Za79QLuj7c+axaOCpkpvZz3YCMFwOMkxY6VmMJYHSRE9vdmX7KrhoixOzVg== X-Received: by 2002:a05:6a20:431c:b0:13e:23bc:f4cc with SMTP id h28-20020a056a20431c00b0013e23bcf4ccmr2578458pzk.37.1692197621739; Wed, 16 Aug 2023 07:53:41 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:53:41 -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 v4 09/25] target/ppc: Use GDBFeature for dynamic XML Date: Wed, 16 Aug 2023 23:51:30 +0900 Message-ID: <20230816145155.21049-10-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 Reviewed-by: Richard Henderson --- 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 14:51: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: 1821887 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=vY30qZfe; 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 4RQrlk11sSz1yNm for ; Thu, 17 Aug 2023 00:55:14 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHuJ-00008p-FH; Wed, 16 Aug 2023 10:53:59 -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 1qWHuH-0008VF-Sb for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:57 -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 1qWHuD-0001Xs-6v for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:53:57 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-688142a392eso5304468b3a.3 for ; Wed, 16 Aug 2023 07:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197632; x=1692802432; 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=vY30qZfeyDncbmANt3wuXXEplqvjyz2VG86gC9yGGgSga+bT4bQbISEfw6nyZeWHYO B3BMpJgwPN7OS9wqIqSGIvzoXD5093/4uKSYzZfQvsjXl84Bb81O2SllOoYtAWS3Gulh qOGYa3YpLlYlUrzcmO6tYOtCE+ZZq4nvE+JnISlGMJsnRXqjxpeyeXsRo1wSrpt9W0dj tfbtCgu/UyOIZHWsq0IOyd0MXMl39XmMfBYpDkTlHK0Fg3OcUDAUXNn+UBd6kUFvVBhU EjSg2Zle6UO4TscKKt1A4q4vBdoDblEwDMM/henz1IdIghrXyVUczgzYjgVCx65Ak7LB X4mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197632; x=1692802432; 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=TtnkAYibpjMVWAqL+WefPKiKviG6F+4LjDqGmvga0sVoZ1tMDFisgLvispD4kx7M7r Ul+3a+z5esoEXpiawYSR7wrQAy40c2D8Eu9qtiNwOiqEut2l+ImHd71RpyPhygyrF5G9 mHB9QJ6p82uwhFGG2LIWobYylJfMm9CMZAGwTU1Q6SlBWfuZoIfiyO5SvhAZaMy8BSIl e9bVCPCAZNGYgZ8uvHHS1r0otaiuntr3n1Qghy0a6QzCwbmPXKUt5oDgU0sCc89jwZvg A6W7CfAxXTEbMn2xXQiIM0FjERKPHGonmW1pkge7yXKRwHo5v7muJ52rHo7DGQNzxArH 324Q== X-Gm-Message-State: AOJu0Yyj0Hz9WO2M7if7v32CK/WMuaUANOT1F1Bgs6yxwdDEBUokadXA /1JiCuktsNm6yqCznMKA/1zMLQ== X-Google-Smtp-Source: AGHT+IEQq3EvaycYEIMAWHJ2guJpdhzlUdWPiJzCrsy2FVTqEnGNKmiIPrAXAmST6DwnZI0CMidbrQ== X-Received: by 2002:a05:6a00:b56:b0:687:82f9:3d89 with SMTP id p22-20020a056a000b5600b0068782f93d89mr2326707pfo.24.1692197631904; Wed, 16 Aug 2023 07:53:51 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:53:51 -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 v4 10/25] target/riscv: Use GDBFeature for dynamic XML Date: Wed, 16 Aug 2023 23:51:31 +0900 Message-ID: <20230816145155.21049-11-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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=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 14:51:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821890 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=JB/y87xY; 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 4RQrm44ygmz1yNm for ; Thu, 17 Aug 2023 00:55:32 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHuc-0000a8-5n; Wed, 16 Aug 2023 10:54:19 -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 1qWHuU-0000Nc-Qe for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:11 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHuO-0001at-ME for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:10 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-688142a392eso5304611b3a.3 for ; Wed, 16 Aug 2023 07:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197642; x=1692802442; 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=JB/y87xYhHfangC6N/TokBgr4xYwoOAwe6dBdZp4VCTqwuuYUyWf7Mk0nLzosh64WT 4JWE0dXiBsdpWIojTWl4/L3gih4jgQslxANi1mW35j/86hDf8G+IgMwtPjMKRqAdeRyX Rzbwcq75fCiw/AazS515UhemJOZ8S170gEGhxNfsT9GSyXJx+cZmfp2gISPbC1o0RHh5 XPp+9TTGHtaqOsTzNZouyE7YA8RxWEat+sTuDlD5l9Zn3c2IPWfk4NLMUhougKF7ABwX lTYLa6KBxjbFt5lY2SlxNUSxb1UudFWtse7N/v+xTEJWK5ymhjhWtanQA6oP0RZKcdaz AQfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197642; x=1692802442; 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=UPtoKqyAan9vRLwkvScuRfPxemjIXU8L5nIegJAyDIeoAdjFoxL1vvOyEcrxEvA5Iw s+6t9K6SVPaGAgBkJnezonkNYMr0qNaoAgdK+o33Iv3ycUVdV7xv3pQHNSmuf+M/DRl7 OxMokyN3nwwFiFTzKBLODPqVDOIKCnmqllhDDAS/cv5T0ZP1/kkg46Va6DxTLgpjflV2 SAarxZF5VEGKsWz2GPjrc6SX/hspdqGRiHdNrJ+BEwC4c+cr0AxmT6C5kc8FbLbDfNI7 pFVUBHIZcKh7vbT7w+zypgP2qxMZ9VXdOi6MlBJvwWyfzoXUNNu+ws7ImhF935W9RYwW 4BWA== X-Gm-Message-State: AOJu0YwX0Q2TOLyPAm4soc4vYWWpBHfKZsLdXh2toHvWoxtdiZDGkau4 W1DrKUekeTQ975F/kz3RdeejZA== X-Google-Smtp-Source: AGHT+IFT4dwQvcyv9MrbZ7kkyZ314Yl/K8D49ah7BOaL4B8w8snyUS1Q6cSEe3u/WgeRFCGkX9KOig== X-Received: by 2002:aa7:8885:0:b0:680:2b80:8479 with SMTP id z5-20020aa78885000000b006802b808479mr2827211pfe.19.1692197641375; Wed, 16 Aug 2023 07:54:01 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:54:00 -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 v4 11/25] gdbstub: Use GDBFeature for gdb_register_coprocessor Date: Wed, 16 Aug 2023 23:51:32 +0900 Message-ID: <20230816145155.21049-12-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42b.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 14:51: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: 1821888 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=Rx1Bfyqj; 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 4RQrm2445Nz1yNm for ; Thu, 17 Aug 2023 00:55:30 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHuh-0000tj-2e; Wed, 16 Aug 2023 10:54:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWHuZ-0000Wk-DT for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:16 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHuW-0001ff-Q8 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:15 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-51b4ef5378bso4934597a12.1 for ; Wed, 16 Aug 2023 07:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197651; x=1692802451; 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=Rx1Bfyqj41542uex+VPI4aGu0lvRXaDqdWplXr2QPoOr85I2DcJhaNpSiwxIYeDrXX zUae+GVMeLTr+pjLfabmWIbPOOU8pwCi//v2P8wGVrzy8AFGpwnu4A1I67TSwxeBMY3C g7tiuCMwMCrBS5xzp2F5NQUDCAgPH2MND5jID2UAjO4YxKWNWTwjZYHfcl+bAzY84Cp4 DbHKZvbKIm4+zGfTal9r71hx49SE+BSGlSrna4veZvC1d1n+JCI/cDT/2ZqCyBXKVWmB ZTvqRwFzShAddVWv+lKADLAgIdVKensSPNoEGMx2ATXi4xpBqzHeN8tpvQGpX7rXJ7uR xurA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197651; x=1692802451; 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=ILZfMst/c75RXEUj/QCzeUeABrSeViqsmJx7NQ3d+zfipEbaZDMBHKYcLGVxg6n8rU jvQE9WBr0fXMo45eOdcJiLoCSv8LEC8MFTN+NeNpGxDN4uoYfKWV3yfwX1OW8DmAQIxe uwbS8fR6u7xTQi4nU9htdxMVB2R10Klh0Uu5wcG11LZdGpmQgosnmBNwhplLIyR5iSFx naQxIBgQV6Vd5DER+FVlE37RUKcWL6eYyQARzZL50qOVWKTnC9RzKwwk2SA7lCg3c0oD kRCRmcACipZttkAVpGnohIz6QWJWiU9BLCSEBKKUnhigZZJPO1iQDM1jgKFvXaznT/xX irNg== X-Gm-Message-State: AOJu0YxACKQbvrg2bs+iN70H8ZSqBc2Gzd6NrppQ6W7VIUHXk83Qt1Jm J3iVtYEOW3oGYvS5onfvB8CRIQ== X-Google-Smtp-Source: AGHT+IGNi1WnSDyEFaWSAnuE5JXmQGx9lONzm6CcNOGws+VTx0jUXZ9NMfg/hTFNrnDcImP1TBnYwA== X-Received: by 2002:a05:6a20:7f8f:b0:134:8d7f:f4d9 with SMTP id d15-20020a056a207f8f00b001348d7ff4d9mr3395955pzj.52.1692197651399; Wed, 16 Aug 2023 07:54:11 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:54:11 -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 v4 12/25] gdbstub: Use GDBFeature for GDBRegisterState Date: Wed, 16 Aug 2023 23:51:33 +0900 Message-ID: <20230816145155.21049-13-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::532; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x532.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 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 14:51: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: 1821945 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=wdJ1Gcyc; 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 4RQs2C6KZYz1xrk for ; Thu, 17 Aug 2023 01:07:47 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHum-0001Qg-54; Wed, 16 Aug 2023 10:54:28 -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 1qWHuk-0001Mu-VC for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:27 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHuf-0001k8-Qr for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:26 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-688779ffc0aso1061089b3a.3 for ; Wed, 16 Aug 2023 07:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197660; x=1692802460; 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=wdJ1GcycS0B7jPU3gptHjauMo+4W/Tj0chrY5DQgRnWaQP/mpoIErYTtDcWR7zPG55 lMacHdkbqypLFQlpNKiIlmr5rMH8VSpV+d8XFGR7O3AV7dWR3gt3R1ZWIwZRwTaMzmHH WkF+5rUDNfOPux13mqNhby8eczHgGNIobxD6//gyMxqPdrC0c32JOwXPfd3S4CQ84Vwo 9edmmZ7IPWCGL8cRgoBFir/mrIdkAG4IHp3ZVZ0KZebHw/lwM6Bf38a43kDXV69EHZLe J1Tn5Y5htppdpsvPlB8dv8WYHKK0X55V1OsvkoTem1uC8mBMpvNQIf+OUJKgPfCoWckF Ropg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197660; x=1692802460; 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=NaNtEq0bl0pK5aUhR/3gSTwanMbN5w5Nv4/Q0DVnX2P46tuOe+YJvHNAVTV2JJq/Xd rrGCCrlfiFN+Z2k2tKeZ5e8u2t19jR+Wv8VWpnDb+dieyDwihFdHL5Qz+Ih06pKTIS8h oHyLsLuuqHZsvfU1PkhWSj82UriDcCwys8cPeuIj0zLicI30h9qo9pjmK068wVP3Ed9V UgRBshtPvdxU81AynrSh/zpxlZJN+DSJNPujU9TFY+r+gZA1C7PutZ/w+4d3fTI1+580 LLtZTZ642iS2+u9u0FU0+fLbWukbCjsPUqTVynNQ1BPf/8od5qKBVvamBzVVycQVK4KK jjlg== X-Gm-Message-State: AOJu0Yx3LibBULSRHGkfIEd9Bv3XEQ9zIIC7oNji0m+GWd3lu9hsh7a2 SRHwiUv3qK+/DuZflCU5uFI/jg== X-Google-Smtp-Source: AGHT+IF1l1tQQLztLCAqEGo4eDgTvVDkLuOEZ5c9+BW08dC/LndNeQ5KniawAZF+FOrefPAqPivAXA== X-Received: by 2002:a05:6a21:66c5:b0:133:e3e3:dc07 with SMTP id ze5-20020a056a2166c500b00133e3e3dc07mr2397513pzb.49.1692197660639; Wed, 16 Aug 2023 07:54:20 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:54: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 v4 13/25] hw/core/cpu: Return static value with gdb_arch_name() Date: Wed, 16 Aug 2023 23:51:34 +0900 Message-ID: <20230816145155.21049-14-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::429; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x429.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 14:51:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821900 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=p7h56q3C; 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 4RQrpB1yLmz1yNm for ; Thu, 17 Aug 2023 00:57:22 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHut-0001nq-3T; Wed, 16 Aug 2023 10:54: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 1qWHur-0001jz-KV for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:33 -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 1qWHup-0001pB-9M for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:33 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-688787570ccso976244b3a.2 for ; Wed, 16 Aug 2023 07:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197670; x=1692802470; 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=p7h56q3CN2y8bvdvqL0phOohINho2V/FibzQb1lltju1EiT2zLmC1HQ9pizZMKV3+7 i2aFlBgr4o6wwf6zp1FuC9yndANOhYBWTu6/+iMev76NiZqPnbKvDhOIqDD6c9DRdWVW sW84MGflqovhFBaAEc2BMD7NJbj1UpXGPidJR6pLK9FKNZ0PvkakGuPRyR0262PWz4lV w4v02iB1E4qWovAAB0ETkgcAnYDQi+sejEqU9FKNRUSZUZDhJkuooxxC66MLA84y8+bt PLVTLcc/kUEYy2IKX8YzINp0TKWSYCr+JFtjYXMno2+2+XOD2tJhmEAGZXzbjTIEcYO8 5b5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197670; x=1692802470; 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=Pbgn5imK9kcpfYuTSeo1TKUBiEgqmgXw+IEkKfyq8qxwMo/hdsW/EmSyiXtBLqA31U v2DHqW+fmATgiseXyhGiifLVedPmQNJYuz6/MmdNDutusXTZJPlZIvhR5lllRpljdDCh tlcs9zb0lwd6yJqjsiW+rbqJ5GF1ronr3cM/7rOIEVRtReHmoM6DXgJBs4yHfW+z91FX 1NdFtbMPxouYKgYKu4hjDMebUhTGncWooSxh/Vj2n3NqJBmHsvBHZdKo/VLDEawuHoIp 6SQpeRsIwRiyFYYXFlv4Hjeqd5aJpTuXlPPQDcc6sbpcvjHz80hg9oGocQWRUatrz4jV Z72w== X-Gm-Message-State: AOJu0YxwH4YFMH53R61s8Lc6R/9NTpqwZlQaFCQbgO+ZwWH38n9s1JHR 1YNRz8vHVg7OczSsgs18Dudleg== X-Google-Smtp-Source: AGHT+IFv0NlGFErZfdbOhCNMu5daHrtilRFSc7CzUk7SLsVwSyRnmZ/wL9gOiGBfSe0fbHUPZ2Zljw== X-Received: by 2002:a05:6a00:ad2:b0:668:711a:7d93 with SMTP id c18-20020a056a000ad200b00668711a7d93mr2147423pfl.19.1692197670102; Wed, 16 Aug 2023 07:54:30 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:54: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 v4 14/25] gdbstub: Dynamically allocate target.xml buffer Date: Wed, 16 Aug 2023 23:51:35 +0900 Message-ID: <20230816145155.21049-15-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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=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 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 14:51:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821913 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=nH9UgICP; 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 4RQrrc5m3cz1yNm for ; Thu, 17 Aug 2023 00:59:28 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHv2-0002Ee-7Z; Wed, 16 Aug 2023 10:54:44 -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 1qWHv0-0002Ba-UW for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:42 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHuy-0001uz-Kg for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:42 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-688779ffc0aso1061351b3a.3 for ; Wed, 16 Aug 2023 07:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197679; x=1692802479; 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=nH9UgICPSZPMBB2TAomDXd61ub61DSLwDGgUQoSEJktzo6LJlfceql7QkgJUIP1FXN 8G1hfxPctzwTB1/8C97mnY/qHlLviw/jO53Pl4vpIWcBavasylzrb+yoUceA9sHFLBv0 S1X3QzSujamv4neruk/LEHKZu6xaGlc8Mu6vRV7jUCjTO8+TqNikIkDczv+0V1mI5BTs 2lgvc6ip+yqbLo6UcYaevT8VCIzJDkE6sswVwD6dC9Q9UnUQT8famLevNKXMLK7vATcQ I46L2/kUGvTtTycGT4fZCwXvIfhsNDoTTOGQjY3/xd+eQtAjHmhNeEZfXNtYQl1huh/3 2Nbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197679; x=1692802479; 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=YNiSVLohEjZ3qeQVDfyHffLDdOCtZE8MU0g35/2eOAWSv3epjrdeDAZJAQqSo3cB+U OilIU0gYnpXgzk8b8y6QK4I6zAPLKcK1AzDYmi+LmR99TTqYIXz+By9gl385dcxEGQh1 I6OVq176ag8f0dWb/z5bOhiZIVGWzBJEmgYzhrat2E6t7tmXwl/UXfFlo1mcSJl5YXWH O8Uhi4R9UAp3nKMgFdQQMd4ivZIkYQla1wBIbwF3L5v6VNaPLAdglHU5+NKvSYtdRsLr C5ltTSkYqeUrZeAcNt2bRSZb3syY62ZGN8NR1zBzUnbUjIg6xqb3TsNxT7aKJ1gIEAT1 tsLw== X-Gm-Message-State: AOJu0YwiW1MfEGJmlT136rlIpPfnUt8PgQKNBn1ddE0Pq5wt4fBRQCGz GSt0st5Jn6NxSpXLEfBxyUiAFw== X-Google-Smtp-Source: AGHT+IEr+MipfTzGICMdOQPRyXw9XZy0/xK4s3F9uNvZiKuAPhCcA2HHEFaTcsN4wEbaC4QLks/meg== X-Received: by 2002:a05:6a00:22d3:b0:687:2be1:e335 with SMTP id f19-20020a056a0022d300b006872be1e335mr2448422pfj.2.1692197679494; Wed, 16 Aug 2023 07:54:39 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.54.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:54:39 -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 v4 15/25] gdbstub: Simplify XML lookup Date: Wed, 16 Aug 2023 23:51:36 +0900 Message-ID: <20230816145155.21049-16-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::429; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x429.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 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 14:51:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821923 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=BA4DY5Qh; 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 4RQrt64Lncz1yNr for ; Thu, 17 Aug 2023 01:00:46 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHvc-0002z8-VZ; Wed, 16 Aug 2023 10:55:22 -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 1qWHvD-0002Ze-HR for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:55 -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 1qWHv8-0001wf-Op for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:54:55 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6887ccba675so602320b3a.3 for ; Wed, 16 Aug 2023 07:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197689; x=1692802489; 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=BA4DY5Qh98ZxOZQW5lmEIxYZxcJFJfHns/k0/rHhsc+v9N6/qu8hi6VE10JWsF9wfa aZzOgQ+wVwzG/qW0JlY9WXpvUNGV7vKxQGQRBLKtZpOaRGkBWtaj33CWxzjRXIvAyutD MGXwURiN4InOdghAoVskP5q+E3fhCggki9S4D4YL4LpxG5irT4DkAeZ7tvTRs1/vBDTl kUyVUoLdloMkOKlxNK8vfMNqp2MMyfE7Bd/frZ7XD/2ewK1kaCnaRpYZOueCEClrxxA/ lZE/GtYZQwruEf6dr7BiM4ymK7vctQ81CVWQb7DyEZcvRrXbNF5m2SnuS2JgNnbsj6pj A/Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197689; x=1692802489; 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=j6Zo3OtcHpefpb6mAj/jtlJr5iYJ7aQEx1PyG0NFP1UfOg9C6YKPNLTmtjcKSn/uC/ Ayt7LXO25x23//bTpOZ/y8Z8BA4CW/IZxOgX4ebE4QiWib4YE4gRoYODuxQvRT9svf8K iAjbaUhfE5QDLk6krfmTTXwScThC0nF7+x88E2MJHvzdr71a/To5JwVavRNzbEGjULUC 8CVGCnlBh/epRaoqAmgz9zPvMzw0DJByFPw4WQ7q6vmlLfRYfz1BW76YG6tSTCXmqolS 18625QE3X8NwrF0WXBLlck2/2VuBV0+gyxGHG3MpOTPRZw3vmE7AcfAxmdVXbFXQeg8D dJ8g== X-Gm-Message-State: AOJu0YwKfx7vQ+X0ac5V1M6z/nJZyEc2qLf05XYJaLu05X8pVk79Ha/I R7qSPaAeBnbqapeh79cBeacYTg== X-Google-Smtp-Source: AGHT+IEdYU8lWth02xzr7iryTg5Fxt8kHkoQH1OPe4em05J1mppza8xr0eOgv10dhn/kgybj53Bm2w== X-Received: by 2002:a05:6a00:2391:b0:687:20d6:fae5 with SMTP id f17-20020a056a00239100b0068720d6fae5mr1993395pfc.24.1692197689614; Wed, 16 Aug 2023 07:54:49 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:54:49 -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 v4 16/25] hw/core/cpu: Remove gdb_get_dynamic_xml member Date: Wed, 16 Aug 2023 23:51:37 +0900 Message-ID: <20230816145155.21049-17-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 14:51:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821895 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=Brp3Z2k7; 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 4RQrmQ0W4Hz1yNm for ; Thu, 17 Aug 2023 00:55:50 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHvk-0003RA-IA; Wed, 16 Aug 2023 10:55:28 -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 1qWHvL-0002gP-TC for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:10 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHvI-0001y8-Ut for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:03 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-68879c7f5easo896577b3a.1 for ; Wed, 16 Aug 2023 07:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197699; x=1692802499; 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=Brp3Z2k7g8vqxTbdVQ/dJfcjW0h+j3yDqeIGxnVuhim7kQCZLaF8dhiHLfZEjP0Mvs 6pyDN3b8PLLFlz8ZIIfYw+ZZjrU4jk730W8u3s7aELABk7mpaIM+iiNmSSoTe7DMQgz8 Zb0EUeprTaEyY8JklH0qzNum4Oh2TbvP283SEOTbH/0jeTLaN9Atd1KQ+PfvJPv4NWm2 xk7GpEyfp8ew3V29WzyeVLEu1cs7/aT+WzEviBiAbnLlz2U8IrtJFLQ3kcGVYhUl1IMZ 3rQoQdrDV7OixVtw1szynCb0qGIMCLjSNdm6YCKgg5vIKwaXy0uKzdR5kwtu3ZgvE8a2 ZqGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197699; x=1692802499; 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=TEFx+M7yw7HE9mG8AQphFuK3sgUoAPGzgfaGvnbk/j7YEV0DpFT9oTn7PIdOfLtqhA o4nDljlkdT2Zf5C6+VugtfipzBWKKQZXZxaKx4gQF2HsT8P1MUh1s78mfuh62+U06eJA aUfnANuG/W3EH6WaEGKJCO30dWTZ66ehqsqBZty305dsFhzAE1Attn/2FGzI3VZzHxZl XnMvDQdRb9rQ/Ry0djx722/htU3zUtJJKUWoiMcxUvpQNgHftIsVAEbwymUsUGUfb0yQ TOb9xC6glNSxnPzH9mLhwXND+yuWTY+tuHU4wOCJE5v0ddBOqL+blZ8ZX/h7RQ1E9lCg 3bZw== X-Gm-Message-State: AOJu0Yyz/U8SV7zcYTmsE5Ee9jRNOdXQMI+3ReZha4jCAXPIV6KIwTVO r16fglgapn/Q4+1JdJSBaO5Qpw== X-Google-Smtp-Source: AGHT+IEis8qqHjy39MXx9xGdlx82+/3PxpX6nkH6Ik1MHFYleCZFpA59/fYnIBPFIBGb4Mw284yU7A== X-Received: by 2002:a05:6a20:a123:b0:13e:6447:ce45 with SMTP id q35-20020a056a20a12300b0013e6447ce45mr2385259pzk.43.1692197698996; Wed, 16 Aug 2023 07:54:58 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:54:58 -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 v4 17/25] gdbstub: Add members to identify registers to GDBFeature Date: Wed, 16 Aug 2023 23:51:38 +0900 Message-ID: <20230816145155.21049-18-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::429; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x429.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 14:51:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821918 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=iH2nnH3o; 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 4RQrs45Py2z1yNm for ; Thu, 17 Aug 2023 00:59:52 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHvl-0003ZY-7t; Wed, 16 Aug 2023 10:55: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 1qWHvc-00032g-4m for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:22 -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 1qWHvT-0002AQ-C1 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:19 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68871bbfe33so1233927b3a.0 for ; Wed, 16 Aug 2023 07:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197709; x=1692802509; 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=iH2nnH3ocQeNFrdKcNfMifkXgMTqutFFQem8mp7A4DoIbF+tDoep6iKXxZziZMa7mx hy6fUPrywtQhqrluyRvnD6BAbCMNwejsCtaQ6Ktbcf9JNJY8dVLpzwOKTrExOcnnx1Bq qxME2RWLTmwJOmkn7fV5W75aN3ZyWSxsR/7VYMTsD4U+rq5T7bBNe2v7bojQFZRqFVEy fVrME3IrFsSTieiewDFWmNzT+5InCtOc3qeJeO7KrD0tRetUrP5E1x9ClCe1QljDX/Yv RnQ6/wCDS9c6ONPiWsxVIi+GKek1lEuom7b69NW3mC3djvp9kzcLzR4ccHS7t7dHzrF2 My1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197709; x=1692802509; 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=d1QjQ+iall5vUbDB+7hdlZF/IMJt2jZUp9K4rUyY0vPFT3/QPyJ6DWobG/pDj0AJu8 PqD/fMV8TAxvG/m7GIruu118GxsuOBomZDpNF3E0hNy31Rx3/cPE9qt2+1mfOuFFW094 DEZOQ9rAg+S/3RzQxxYmZ372ZG2pAPREfDwMzRev5yE8/Esrpuc5s/EE8HW0P4xRVOsP zH+UynFCC7Bqnj5RO0e05wm2lTSljwsRx9/KhjhDmLHP3DAxWdLHe7xWZcsqLkrn6ZmS SkQFJz/fYFZBACBTuSGEu0sD78XoBOQtnhvE0sJvBtnfdijqu/A1MLeSNSLEQ43jZ173 0jLw== X-Gm-Message-State: AOJu0Yyo08LlHm6rZ++aAiaNLeuuD/zjorKd1LASVwH8GwYsJF+2XUzO 4iUB6n2WPAYRCG7BSxpYmK6HlA== X-Google-Smtp-Source: AGHT+IEHmm4MreK6s4Bu6OLMXl1aQdJDjH6CcJMqN+0f9nqE/NOH+wSErUNCAnWqnvG1wmM82iqCGg== X-Received: by 2002:a05:6a20:9189:b0:13d:bf07:7444 with SMTP id v9-20020a056a20918900b0013dbf077444mr2527271pzd.0.1692197708607; Wed, 16 Aug 2023 07:55:08 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:55:08 -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 v4 18/25] hw/core/cpu: Add a parameter to gdb_read_register/gdb_write_register Date: Wed, 16 Aug 2023 23:51:39 +0900 Message-ID: <20230816145155.21049-19-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 14:51:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821914 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=DHC6QvsX; 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 4RQrrk6rrsz1yNm for ; Thu, 17 Aug 2023 00:59:34 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHvl-0003cE-Mc; Wed, 16 Aug 2023 10:55: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 1qWHve-00035l-Io for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:23 -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 1qWHvb-0002Ce-CY for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:22 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-68876bbecb6so1087966b3a.1 for ; Wed, 16 Aug 2023 07:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197718; x=1692802518; 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=DHC6QvsXMwzP6kUAzxhTYkh3wTmVgrznFgoy0saZicOI8SHxSdbNtbIRUHQMbA8Mxy Qu1j8xafi/vCdvC7oei3fiPsocvvqf4zhGLWu+LT9mvExZvwNIArOerQm0oyuNPOdeTp X2/lQlkAiyE5+e3bNnJReG2S4uFRDtiFmiU1qDD9g2d94JVEiVIZm9VVPbtT8H1LMGUi 943ygkK5D9LDZ9l2ONiwhthNE6WTdn7HAqXAn0wlUKqZegswl6oDHaXQGTqNV+8Dl6hK mvboHvrQrjIo672IDeYwu7F4Ud1YHu/535oofx1LwGzdXIrc/m8AI8BM5qkaSp/S0lVM kIGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197718; x=1692802518; 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=XN6/vCpOchdp8jn7ZnOsDkScGFRJFitsQcy7rI1k1CHR4fdTL6PpcfcRo0gEUZPl0c Uuiu8Gmd+Cgd5iHNzl9G+Y9AD+GnmvuLYUihZVnxC6dEXGkfnFTb6jFjlJ68NsBfqElT GcRy71G5VeEcojGCzIy7Bd0JE2rjlzJ/7ilmiO+3vO4TLBLOBda508KxXR1ZIOcrcJ2s OREjHT86z4g3b6qLsLQurqPsZTY0YfBvzsL5wMV/GzEm8tnJIZkBGVfOO/kpZhSbw3Vb UJjd7vJZcpqF9DuA29CoIXAR8fMjezqqDVp3xooN4l3emYVmQdwCWzUkzFVGi2ziLytU 6/tQ== X-Gm-Message-State: AOJu0YxXPcw+QoJhpyIUFhejnz2wdSQ6MbieHmHw7ZEFxsES4mcd0mzK IYgu/SDugAiACV1LwkC9b3nCNQ== X-Google-Smtp-Source: AGHT+IEtjZjqTnQ3l/wWXx0Upn/5qqZU2aHAU1nn5/EZzbAD68qY9B6sozJ2N6ojGbda2xA9HTPWag== X-Received: by 2002:a05:6a00:1407:b0:64f:7a9c:cb15 with SMTP id l7-20020a056a00140700b0064f7a9ccb15mr2048291pfu.11.1692197718221; Wed, 16 Aug 2023 07:55:18 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:55:17 -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 v4 19/25] gdbstub: Hide gdb_has_xml Date: Wed, 16 Aug 2023 23:51:40 +0900 Message-ID: <20230816145155.21049-20-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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=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 14:51:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821897 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=QOSq8rSM; 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 4RQrnN2b7Vz1yNm for ; Thu, 17 Aug 2023 00:56:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHvq-0004Mm-Fl; Wed, 16 Aug 2023 10:55:34 -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 1qWHvo-00041E-7L for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:32 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHvk-0002Hv-Rj for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:31 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6887ccba675so603024b3a.3 for ; Wed, 16 Aug 2023 07:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197727; x=1692802527; 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=QOSq8rSMJwCw4yT4RfS9VQKbsGnKKehRFFaAay8FJlNj+QmUEgOYx51+RRipyd2e+e QhrJ1+xX1tm7EFsLJ2GT/iY48GrfpaRQqt1cieHhxtHUut497ZSmhmoRw605pv+Mlx6W /Y7w6CSKdWxoRwhRiO9E5EyX5jxFhRgqRDsJmlbbRPz9+KNv1JHQN+YBcMN20yemn348 sbkgLmE5nQuaDC/TEmywgnUJbaIsGTUoUlQAIXw5x81t0RAJUu6tA1Q1404pu8chbMZP if1Vrfb0majla/SBGZFm782mFxEUJANdiXfnSpbG9kpo1/idiPdscn4D1lDi7NeeZbTN Lgxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197727; x=1692802527; 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=gPs3/etxeRqARyKJQkKjXRIbrti9o1aJ4sS9Ye2SqvLHnHtNRAxWrKUX9o00Yq+alH TfBOKVcLMts8thAfEL0cVccBbq1JI4TECdDuBmbtimVGsLipPH3OD7yUvHQjIu5oiM7l DFOXMneTIbwvr0QmKIk/+q3/TZ5qv2b9xLcp/qHToPeBGHy5fr8yBstvRdoFDNrQw0w4 sC+4Y3S2qWnT+jbypGCEjaRO48SaqIMbOpyZz3AktZs5dzMNksDUFvHbkDo47C9rKyTV Vvtfmb96/Iv2JkoHwOmrg6ozxIBU2A9wBOj9OGc+9hmqNtEHh8p9lp1nZTQULGgN0yIC HhKw== X-Gm-Message-State: AOJu0YyvVIx2svItqXPqPAQNESCDs9mINjt2dT6pcN0DyunxF8g9mcK6 JwZ6ehvzTUfLqWBF75ylgQgMzg== X-Google-Smtp-Source: AGHT+IFJPQo0CowNAlPgDFOH/Tnco/aRBZ747oI79WYdwq3oVrGEE5tawYIyCoDbuI9xrw7iAk4seA== X-Received: by 2002:a05:6300:8082:b0:12f:1f1f:b506 with SMTP id ap2-20020a056300808200b0012f1f1fb506mr1843860pzc.21.1692197727672; Wed, 16 Aug 2023 07:55:27 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:55: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 v4 20/25] gdbstub: Expose functions to read registers Date: Wed, 16 Aug 2023 23:51:41 +0900 Message-ID: <20230816145155.21049-21-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::431; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x431.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 14:51:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821916 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=2L6AVfTz; 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 4RQrrt4TNYz1yNm for ; Thu, 17 Aug 2023 00:59:42 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHvz-0005MI-Uw; Wed, 16 Aug 2023 10:55:43 -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 1qWHvy-0005ES-F3 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:42 -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 1qWHvu-0002KN-8E for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:42 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6887ccba675so603249b3a.3 for ; Wed, 16 Aug 2023 07:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197737; x=1692802537; 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=2L6AVfTz8CvAuULFJ42gQy1cf81eTocVTR9UQPe1fZA45I6oVAj44sl+BwBrM78/VK HUFfz3K443rrxYfy5KN2ngwKcKC60/Ui3zZs/BoXrxAm1ocq4NC8GNYkfB6hdnzL0BHI /JKw/tUOcQSKCGXzNY5SHv2+yb1j5/evBRsoonu7IYBSSQfgCQQRrPly2NlcwYhWru4Q 7hbwGsWwzSuKfjdmsPQPoDZC5iUPONhwx357Qu+/XtVOcIzPKuuE1JigqsYBC1mYMU3r yCaOe62NjZTsz6SmSOS8kJCn0auKsjtQ4xYc837Bix9YbhG7UrntGc9K+RBD5XFKXdBm IkDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197737; x=1692802537; 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=BPLCyJjTgDE4v7q0rUd3+PMV3Ba4/7iTLpGGu2whwyJhfiQ7J7K0+tYapvYBGBy+8N L7D+Q2vj5EsQIThT9J9UhEPMSUgMaAoamfLwE3AOUszdtzRYckZtJoNp5SbEy/QEEbrp EtmeecLNAaXqE/iWVgWj8MUu06REIT2RQALlmeP5CGZx0FwmYStbPNQx0cqH2SvW2Xim HejWGueAr+R6apg4nSjTLNxrayeGaboIZBMUqa0mra9HzWW6NyDFNzXBbUS+ojt4mDOr VEn7JdE+NjQnuCejHllDREKVp3GnpQo1QC6rExTEshwHyKcY1zjRwToPYaR2/U4dez7a 0SEg== X-Gm-Message-State: AOJu0YwKoJ3cq5eyxi7d8XvZnJlSCjUOMLERRT7i41Ncpgd4our52e4h iPjtE7fo5i+Hw+uysQi78OUw8g== X-Google-Smtp-Source: AGHT+IHaIIuGZ2gUrulonpwa65Nz3Io06fPnbVxiGrNLkLfEmh35nLZt8QKhsSDdZF7/OhNxd0e1YQ== X-Received: by 2002:a05:6a20:9189:b0:134:2b31:e2a9 with SMTP id v9-20020a056a20918900b001342b31e2a9mr2356825pzd.0.1692197737066; Wed, 16 Aug 2023 07:55:37 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:55:36 -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 v4 21/25] cpu: Call plugin hooks only when ready Date: Wed, 16 Aug 2023 23:51:42 +0900 Message-ID: <20230816145155.21049-22-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 14:51:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821899 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=ahhJqL98; 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 4RQrp50QVdz1yNm for ; Thu, 17 Aug 2023 00:57:16 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHwB-0006Ho-6w; Wed, 16 Aug 2023 10:55: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 1qWHw9-00065T-2K for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55: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 1qWHw3-0002Mw-SK for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:52 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68896d7eb1eso96083b3a.3 for ; Wed, 16 Aug 2023 07:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197746; x=1692802546; 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=ahhJqL98SrjrpitIUULnpSHdGHZv+FSrDn9tw3jOc46EU7AVLmObtEW2EWVkP1rQ/+ E0M/b0YV4LdeTkhglnRO4sSzr5QDX5dS0tLNtZaErzjSYG1ppmToAPvbPUj7w7zECQfI gM45ky9mpG77TmlEc4m/J52Cl7AH1TTtWzrYC1fkwNMDa7Se84LR6rfX981tzD5a39zb cU4x/nSyrBm32BZDKX85tG3U3yX3hnRi5amQk0840dQDboF4h5XYMKE8DvY1taKgQgmY wUMOcrKXNwfBznpAlz3Htvb+BgZJTXiVs+AjTp2Pm1KjyMk4hdFpcME5m2w58LZLPD46 tbSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197747; x=1692802547; 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=CPgEga559F4MytUcQx01Aknjp3gsocIbW+k3kqDQgEJ0IqfTGgGZPwe1jm1ihL+amx W+3yB37EPfQBpaD6Cps+MBxQ9xZEqPaL/N9XRzU+Rksbgo2jS4K3OGzm6ZzGOqsielyY fiy/F/EG5GOWjin5n9S9pCOjJ1Coew8QqVdABybW3O7r3OrbSGCEXjjFFkHr/eNm0RXJ EJRzpnnlNIDBYsEtfN0kk/wFqwxgL9ohSgo03VJ1rnbFbhqpn9fx5Bs+3srwODWKk613 ZDLpY1kB5AjtBWOAVl3ULqUhcrFkUniYYEvrypXEYBKgcLfFQqh2BXVtWdbLG0vp4JOa jyJw== X-Gm-Message-State: AOJu0YyQxb8HbnKC2irDmHJsR9EW1GTenzUJw8JLuTDLfIYbYgbtpdDp JETiR2aQW40TON4pQl1QygCi8A== X-Google-Smtp-Source: AGHT+IGS4N50kGKiT86POZzhLUpaEWSqPkAJa5EUaXWrZHIlB0BNHPgWOPMGg3dnYGtW2UPKg+36rA== X-Received: by 2002:a05:6a00:248e:b0:66f:578c:59fb with SMTP id c14-20020a056a00248e00b0066f578c59fbmr2322837pfv.10.1692197746610; Wed, 16 Aug 2023 07:55:46 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:55: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 v4 22/25] plugins: Allow to read registers Date: Wed, 16 Aug 2023 23:51:43 +0900 Message-ID: <20230816145155.21049-23-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 14:51:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821924 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=JHgzyGlr; 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 4RQrt64Qlfz1yXY for ; Thu, 17 Aug 2023 01:00:46 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHwL-0006it-BN; Wed, 16 Aug 2023 10:56:05 -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 1qWHwH-0006Ze-32 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:56:01 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWHwD-0002Uu-9f for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:59 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686f94328a4so4511755b3a.0 for ; Wed, 16 Aug 2023 07:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197756; x=1692802556; 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=a4lfc+3ofMUnScOCPQ0mHvnxSSki1D/PoIMD/TM/ubo=; b=JHgzyGlrmLOyKd4XtnUZUHBIfeiHMT+n0LYQ2qbdFVdrS8JCds68NqNTuR+wGU30LC STGHmqfkS0Yhuh1sdDT8IAIj+e4hII52TW0mj9RN58U2UHTBiSQ0Rmsdb4J9jEJNQsYu zLBaNxAsktU+UHgWTFNK4DjYkXfwKZ1inTtBA/F65do01uuIBA7m0B1/65yG3J2ZDnXz iVxgGmToAYv/hxjO0PQK4PNnaNWJcwLdJ8KmCfph6J55OgV5BT8Q40kSwU8W8wz6ZCfQ v/PafK3dVyBri+mEaYnQ3Nhmy2PeXa24DYlhExZoEi0FhwDPWrtsY/0W2Nv/8uTNnHgZ PRnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197756; x=1692802556; 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=a4lfc+3ofMUnScOCPQ0mHvnxSSki1D/PoIMD/TM/ubo=; b=kxkcC+pDFzuqduz8gA2z1WIGYF9J6VETjytx3eLqKGRaog1kyumvCJONYlEH2wC3w4 3H2qL4s8o0v9Y8BfeJCDjR9aJt7L9wyf9NbxpHnGnjKH0e23fhw7Dazp/M4PFv6IHoSw AvUAqWweIPqFpOTUkp94HfR9tGVtpdDGBr/KJhqnkdfuJAouLCeD6iR8MdgRG+KlzT73 0AhRVn3iG/b4udfSMTa9nS0C8ReCI+eUPwsb0ETWtD+wVAtzFN055PAjcR6m2nsqiczf SWqDWIqi970pDZJUjNvQAhdRUBADPuDBaoMa45LAEDnUedK7ycd+nbAJyfnuhEsftXJD SKDQ== X-Gm-Message-State: AOJu0YyxVLWziQVhsk5ZaD+O2fwu0viGmxakkitRMiWGB+YdpZmhGfFF THerBMKNiAMLxbmNh9z/ikR6dw== X-Google-Smtp-Source: AGHT+IG++B0TbJUOezPMWxtLZ5ibdzjcE0GQONt/uzZ5WKwJbtlHvJkyaqAk2M4oATOMNd2boKTHbg== X-Received: by 2002:a05:6a00:c83:b0:688:47d5:ede with SMTP id a3-20020a056a000c8300b0068847d50edemr2988788pfv.6.1692197756021; Wed, 16 Aug 2023 07:55:56 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:55:55 -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 v4 23/25] contrib/plugins: Allow to log registers Date: Wed, 16 Aug 2023 23:51:44 +0900 Message-ID: <20230816145155.21049-24-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::429; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x429.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 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 | 142 ++++++++++++++++++++++++++++--------- 2 files changed, 118 insertions(+), 34 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..aa05840fd0 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,42 @@ 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; + 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); - g_rw_lock_reader_unlock(&expand_array_lock); /* Print previous instruction in cache */ - if (s->len) { - qemu_plugin_outs(s->str); + if (cpus[cpu_index].last_exec->len) { + if (cpus[cpu_index].reg >= 0) { + GByteArray *current = cpus[cpu_index].reg_history[0]; + GByteArray *last = cpus[cpu_index].reg_history[1]; + + g_byte_array_set_size(current, 0); + n = qemu_plugin_read_register(current, cpus[cpu_index].reg); + + if (n != last->len || memcmp(current->data, last->data, n)) { + g_string_append(cpus[cpu_index].last_exec, ", reg,"); + for (i = 0; i < n; i++) { + g_string_append_printf(cpus[cpu_index].last_exec, " %02x", + current->data[i]); + } + } + + cpus[cpu_index].reg_history[0] = last; + cpus[cpu_index].reg_history[1] = current; + } + + qemu_plugin_outs(cpus[cpu_index].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(cpus[cpu_index].last_exec, "%u, ", cpu_index); + g_string_append(cpus[cpu_index].last_exec, (char *)udata); + + g_rw_lock_reader_unlock(&expand_array_lock); } /** @@ -167,8 +197,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 +209,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 +292,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 +302,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 14:51:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821929 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=ECQssLGS; 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 4RQrwj1r1Wz1yNr for ; Thu, 17 Aug 2023 01:03:01 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHwU-0007Ef-Ic; Wed, 16 Aug 2023 10:56:14 -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 1qWHwP-00077X-Mq for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:56:11 -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 1qWHwN-0002X9-Ep for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:56:09 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-68842ebdcf7so2387340b3a.0 for ; Wed, 16 Aug 2023 07:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197766; x=1692802566; 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=ECQssLGShkIKdoxhZZy+LMWwlFqzcHtixQxWIMYm/BPslYVE6MlU4GZhw3MNDXuZ9z WgTVohXHGd3s7Osjiq8VtBmd1ehLOZ+Lcck+3DergPXyd7OEOXfTVCQfH1SLt3/bWrse EOeRQvrMwHLxs/tj15RZ8wQrYSzwNh0hy7hp189kvrqwewMsv4jMN/fNIcmgeYfg7pGI HbQ++YqfVJpORyNTZPPAXzBTx/IF4obY8Au80rf06+Q+BhYYew7CNTlcAj9uMPQr0w2C ivi/42OGXK1MoeC3yoEzFx5k2zwhcUV25Ss2YSGm5fVtf7Q8eJ8Llc0gO4wpzmtaHafn oMPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197766; x=1692802566; 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=k5rhMft2W1bi2Zl0um457WJDFOH7tHJbvxKVRHh3ZKoAbfpJch+pvNafkAv9BY++ol 8s3hpzap4AmrGGc6TxPiN9Hf2F3XSJmZdEvL5PxaMcW1EfaFSMItxG28VG5tD0d4fjKA krb6pwtQgxZw2n/6+67LGIUhegFmkyxyLiQ/rAGh7EQyzBjzjRxOsnxXjgOT3sFZOa2k Nu3v8fbnYWpbnAWj6KXTSZIYCLINJiONMSLgWD+kyv9RYkQK/k997JC+MqJP9fOn2C33 iXUQgZqZz6HE+gNqjtsE5esXtOGrNS1/pIX/pUyEgyllpdwdEBvi6LZz0ZPgMKXxfG06 5mKQ== X-Gm-Message-State: AOJu0YwY/V6JUIhFocUw2szbzLJUO1YxHxKX6BhV2mRg820dvE+prEgc wsPO13puoctKuixOrLexvrJBQw== X-Google-Smtp-Source: AGHT+IFuJWXKBYrZNfpQaIXVCLG0U/O4pHpCtQJ7JkWj+6RHSYVf1WjURL0J7PYM9I6jSgpFz0yl7g== X-Received: by 2002:a05:6a00:10d2:b0:687:5c3f:d834 with SMTP id d18-20020a056a0010d200b006875c3fd834mr2605176pfu.11.1692197766339; Wed, 16 Aug 2023 07:56:06 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:56: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 v4 24/25] plugins: Support C++ Date: Wed, 16 Aug 2023 23:51:45 +0900 Message-ID: <20230816145155.21049-25-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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 14:51:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821921 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=evpaiYh/; 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 4RQrsw2kLhz1yNr for ; Thu, 17 Aug 2023 01:00:36 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHww-0008WH-2O; Wed, 16 Aug 2023 10:56:42 -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 1qWHwc-0008Bz-FB for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:56:24 -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 1qWHwX-0002aN-7w for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:56:22 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68872ca740bso1375045b3a.2 for ; Wed, 16 Aug 2023 07:56:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197776; x=1692802576; 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=evpaiYh/kzubkZR2LEvG4VlfEB/+ESUZhQuzvrqv2FzLZUi1ZlVlbKPTl5+Y3WJ5IF GwP+wG31rpKCLZfDT7PYLZUoPzqFpGsQ6Mr4WKwU3ev1ygDpQX9mj4ipp2W+R09w8pU+ h7tEu96huRYEiWlqDrz0nVEH+nu+saeNniyUWEmG0e0DAytYRi6sLQeST+uCfLeyEBnw 6OA9jAw53g2Z1IRiT//KYq7XieIJlCUj51C62gG80/A2axYkPKvtN10wvpaPN9AbiGqe smVL78kfe78kZPQz8VL5RPmGFycS9NeTizVcHE0hF+xdJ7Te0ApNheyoN6FbJ1Wij0TJ HAAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197776; x=1692802576; 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=HFtHKpgU2+MSipPyjNFKjxllVkHJIJDu5e38PNg0pAByZVxQ0YJS5gRkBy7Th+THNg uJooQ2o7j47pi5LR6S3PnsDTkYeKMrZvkmDGiLXNmEtde3XYRcCGzD7In3yjQpIkHTjd BKul1/sQVdk3Zw8HVlkpUiDPqzIUGJydyPJI9Y5LITKpyBIkDSDinkVZHEJ9mVTsU0b8 jIokGbPjiVfndDet2ELhhzlOhtsshJoeKv+xJBRHA2btwT9TaHwu2USo/IObpbxAiIS6 WTos6WlHbryjwIljQ/piv60ndVxfmeJEXTGnukyvgz37amU803CZ3UupF+KEywDDtWVe BNOA== X-Gm-Message-State: AOJu0YyjglvOqjKzVGyG+0nSv36WqHJeF2tNJn0c1NDUHm3IuJSGVT0s ln14UN8m+1LpHOm46UGygGsbCQ== X-Google-Smtp-Source: AGHT+IHj4VBiL9fQbCA+nA6FwRS2UMbMOMWOEgPU/2w5xIqhCbB4vG5kAFwTaWFAHVek209udKZFAQ== X-Received: by 2002:a05:6a21:998f:b0:140:d536:d435 with SMTP id ve15-20020a056a21998f00b00140d536d435mr3070477pzb.38.1692197775828; Wed, 16 Aug 2023 07:56:15 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:56:15 -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 v4 25/25] contrib/plugins: Add cc plugin Date: Wed, 16 Aug 2023 23:51:46 +0900 Message-ID: <20230816145155.21049-26-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-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 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