From patchwork Mon Jul 31 08:43: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: 1814827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=V9GBWiHm; dkim-atps=neutral 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 4RDsHL17BYz20GB for ; Mon, 31 Jul 2023 18:44:30 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQOVo-00076N-RS; Mon, 31 Jul 2023 04:44:20 -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 1qQOVn-00075x-74 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 04:44:19 -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 1qQOVj-0004Nc-Jl for qemu-devel@nongnu.org; Mon, 31 Jul 2023 04:44:18 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-686b9920362so2901292b3a.1 for ; Mon, 31 Jul 2023 01:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1690793054; x=1691397854; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CBn+i5nj20vvN0ekUr/AiX4JA2kgmu05HbHSUNBFeTE=; b=V9GBWiHm1vCm4A0HIEdbicQblVSB987/OTAQ55TLD+v23IHgofdMKY2WwzeTAUUjO0 ZzUwN8RH6uXfKYThqw2k1aEKQ2EGBwRu6NmLu0eh+PNfGgvthJpE1AjdVpSQHLxtDkSv gmc4KgeSps1Xic6zekDFWnJraBIeSVVFMLFUiamgmMQbJ2cR7B77+kRZh1zYr+ZCsMcm 7Mf/HmNEhHzFOqYPBiaJm+mUk15WKTK2JTv1N93SX1wIvr9n6kkNG18rioChyPDdBBzL Cdh59pEEwjZjuOPfxD1UA5YCLAg1QMFXcCeiSE98EgrALwiZaVB813HHZgL2M//TXtBr K0YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690793054; x=1691397854; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CBn+i5nj20vvN0ekUr/AiX4JA2kgmu05HbHSUNBFeTE=; b=WrvzOT5ZyqjyYKvz5vN+lo52Z8/EQmTYg9EHjsJGfsIabYtjUa2rXqx8+lARPUDtKG 4ea1yJ9D6aJVCGeiz094tQjxStU9XT7JIgCCMItF30VclQh16PeeIwbZocl7bXKfUBZs aJWecncRxydgLbih9qeE+PQC1R3qqb7u1hSjlS3DaF09gTIZ4q3ZjuAISuNbkc7uwEfm AAMaSviiNOUINww6LK1ggrHIs8wUb+mfrdJMFiQw40lcd5ghwj66q6g6Z5oy8Zk7x08p /Ma4NYWGuc7gf0pZgBHDTZzSPfmxPugRfyPVWj4nlhSamK0zrH91/h7HSZ5OGeZttz2z 4dCQ== X-Gm-Message-State: ABy/qLaUNZHWq+Jhujft262az0NoJ6yUDhwQa70XnoE6nUoMR8F+ULwU 1zLHTbZ2YV5tvW6SOA/dhmxLNQ== X-Google-Smtp-Source: APBJJlHulO+9bai7HM3TBxkUIvH3l9LLnEnsQZGnhN06uQCpPeOidJV3P7w69UsLksZ6xmGGkGuiFg== X-Received: by 2002:a05:6a00:1947:b0:680:6d16:8f8c with SMTP id s7-20020a056a00194700b006806d168f8cmr9407058pfk.32.1690793054114; Mon, 31 Jul 2023 01:44:14 -0700 (PDT) Received: from alarm.. ([157.82.204.253]) by smtp.gmail.com with ESMTPSA id u19-20020aa78493000000b00666e649ca46sm7075563pfn.101.2023.07.31.01.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 01:44: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_Be?= =?utf-8?q?rrang=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, Akihiko Odaki Subject: [RFC PATCH 00/24] plugins: Allow to read registers Date: Mon, 31 Jul 2023 17:43:27 +0900 Message-ID: <20230731084354.115015-1-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 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, T_SCC_BODY_TEXT_LINE=-0.01 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 I and other people in the University of Tokyo, where I research processor design, found TCG plugins are very useful for processor design exploration. The feature we find missing is the capability to read registers from plugins. In this series, I propose to add such a capability by reusing gdbstub code. The reuse of gdbstub code ensures the long-term stability of the TCG plugin interface for register access without incurring a burden to maintain yet another interface for register access. This process to add TCG plugin involves four major changes. The first one is to add GDBFeature structure that represents a GDB feature, which usually includes registers. GDBFeature can be generated from static XML files or dynamically generated by architecture-specific code. In fact, this is a refactoring independent of the feature this series adds, and potentially it's benefitial even without the plugin feature. The plugin feature will utilize this new structure to describe registers exposed to plugins. The second one is to make gdb_read_register/gdb_write_register usable outside of gdbstub context. The third one is to actually make registers readable for plugins. The last one is to allow to implement a QEMU plugin in C++. A plugin that I'll describe later is written in C++. The below is a summary of patches: Patch 01 fixes a bug in execlog plugin. Patch [02, 13] introduces GDBFeature. Patch [14, 17] adds information useful for plugins to GDBFeature. Patch [18, 20] makes registers readable outside of gdbstub context. Patch [21, 22] adds the feature to read registers from plugins. Patch [23, 24] makes it possible to write plugins in C++. The execlog plugin will have new options to demonstrate the new feature. I also have a plugin that uses this new feature to generate execution traces for Sniper processor simulator, which is available at: https://github.com/shioya-lab/sniper/tree/akihikodaki/bb Akihiko Odaki (24): contrib/plugins: Use GRWLock in execlog gdbstub: Introduce GDBFeature structure gdbstub: Add num_regs member to GDBFeature gdbstub: Introduce gdb_find_static_feature() target/arm: Move the reference to arm-core.xml hw/core/cpu: Replace gdb_core_xml_file with gdb_core_feature target/arm: Use GDBFeature for dynamic XML target/ppc: Use GDBFeature for dynamic XML target/riscv: Use GDBFeature for dynamic XML gdbstub: Use GDBFeature for gdb_register_coprocessor gdbstub: Use GDBFeature for GDBRegisterState gdbstub: Simplify XML lookup hw/core/cpu: Remove gdb_get_dynamic_xml member gdbstub: Add members to identify registers to GDBFeature target/arm: Fill new members of GDBFeature target/ppc: Fill new members of GDBFeature target/riscv: Fill new members of GDBFeature hw/core/cpu: Add a parameter to gdb_read_register/gdb_write_register gdbstub: Hide gdb_has_xml gdbstub: Expose functions to read registers plugins: Allow to read registers contrib/plugins: Allow to log registers plugins: Support C++ contrib/plugins: Add cc plugin MAINTAINERS | 2 +- docs/devel/tcg-plugins.rst | 18 +++- configure | 15 ++- meson.build | 2 +- gdbstub/internals.h | 8 ++ include/exec/gdbstub.h | 30 +++--- include/hw/core/cpu.h | 15 ++- include/qemu/qemu-plugin.h | 69 +++++++++++++- target/alpha/cpu.h | 6 +- target/arm/cpu.h | 37 ++++---- target/arm/internals.h | 2 +- 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-qom.h | 3 +- target/ppc/cpu.h | 15 +-- target/riscv/cpu.h | 10 +- target/rx/cpu.h | 6 +- target/s390x/cpu.h | 2 - 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 +- contrib/plugins/execlog.c | 140 ++++++++++++++++++++------- cpu.c | 11 --- gdbstub/gdbstub.c | 100 ++++++++++++-------- hw/core/cpu-common.c | 16 +++- plugins/api.c | 40 ++++++++ stubs/gdbstub.c | 6 +- target/alpha/gdbstub.c | 6 +- target/arm/cpu.c | 6 +- target/arm/cpu64.c | 4 +- target/arm/gdbstub.c | 172 ++++++++++++++++++---------------- target/arm/gdbstub64.c | 55 +++++++---- target/arm/tcg/cpu32.c | 3 +- target/avr/cpu.c | 4 +- target/avr/gdbstub.c | 6 +- target/cris/gdbstub.c | 9 +- target/hexagon/cpu.c | 5 +- target/hexagon/gdbstub.c | 6 +- target/hppa/gdbstub.c | 6 +- target/i386/cpu.c | 7 +- target/i386/gdbstub.c | 10 +- target/loongarch/cpu.c | 4 +- target/loongarch/gdbstub.c | 8 +- target/m68k/cpu.c | 7 +- target/m68k/gdbstub.c | 6 +- target/m68k/helper.c | 6 +- target/microblaze/cpu.c | 9 +- target/microblaze/gdbstub.c | 6 +- target/mips/gdbstub.c | 6 +- target/nios2/cpu.c | 6 +- target/openrisc/gdbstub.c | 6 +- target/ppc/cpu_init.c | 9 +- target/ppc/gdbstub.c | 62 ++++++------ target/riscv/cpu.c | 21 +---- target/riscv/gdbstub.c | 68 +++++++++----- target/rx/cpu.c | 4 +- target/rx/gdbstub.c | 6 +- target/s390x/cpu.c | 4 +- target/s390x/gdbstub.c | 34 +++---- target/sh4/gdbstub.c | 6 +- target/sparc/gdbstub.c | 6 +- target/tricore/gdbstub.c | 6 +- target/xtensa/gdbstub.c | 6 +- contrib/plugins/Makefile | 5 + contrib/plugins/cc.cc | 15 +++ plugins/qemu-plugins.symbols | 2 + scripts/feature_to_c.py | 98 +++++++++++++++++++ scripts/feature_to_c.sh | 69 -------------- tests/tcg/Makefile.target | 3 + 79 files changed, 904 insertions(+), 529 deletions(-) create mode 100644 contrib/plugins/cc.cc create mode 100755 scripts/feature_to_c.py delete mode 100644 scripts/feature_to_c.sh