From nobody Thu Jan 1 07:24:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1698226427; cv=none; d=zohomail.com; s=zohoarc; b=XGv/hjjsnv/3QqGbgPumg7Fk3B/mUBF4dtPEyEvNKcd3LqEcG/qUyxH0JPTANJl2R4gNFqKNj4pev/wio94d+97+J2vebPK58h1zLie7kl4dC+4PzTUNsVtIN/fdFNHATa0YRG8J4gAh72EWd0pn2FB+AutG8nwFwUR5N0ORzog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698226427; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=vBUBp+Evkj+zkoxn3FVgKIrs/5i8foEUdffnEcGBefA=; b=f+K6EJv/oTaDWkJRdnhsCLFtBHGurlXurJJxVNx9HVphyLpDCYzTkG+WqFXtsdMhx3mUeYfNaJDN6D7EtFvvNMYEN2kTcJK8ekS377IGcK8nP8JdFIZESc4q0zcfjDj9xrPLMreN/54OWLXjEB+dsaJDeUik3r54RDySXTdaHEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1698226427055700.7938377680385; Wed, 25 Oct 2023 02:33:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvaGK-0007UL-T7; Wed, 25 Oct 2023 05:33:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvaGJ-0007L3-B7 for qemu-devel@nongnu.org; Wed, 25 Oct 2023 05:33:15 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvaGH-0002XC-GT for qemu-devel@nongnu.org; Wed, 25 Oct 2023 05:33:15 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1ca215cc713so35682705ad.3 for ; Wed, 25 Oct 2023 02:33:13 -0700 (PDT) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id i13-20020a170902eb4d00b001c3e732b8dbsm8851737pli.168.2023.10.25.02.33.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Oct 2023 02:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1698226392; x=1698831192; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vBUBp+Evkj+zkoxn3FVgKIrs/5i8foEUdffnEcGBefA=; b=GkrsOz4ukY+RxlzsVk4vqP6g+N15lHnAYIhvR+/DAXuXb2Il9HxSw/wMEdbQKldpUT YBdNrt2ggLbUHYFGJbVyji5P6vHB3glUSALaUuPcVgMzt+mD2WpyHThWEOas+VURF0pT /7wYD2O01I6dJ5kCV7rS6IqxzY3i4Ug47PszLwhj+MeT1ofc1iqVOEubJ8APp8J04zUr RLaI5dnxlMFACEE6r9brAaQJItI7aLAthly3Lw/mGs73sOmthYB1qESf0/+1yGwc58ag I45Va2tlfMauqDonM6OYUfrAbKQY7tRDRmJjbl65CILx+xiEmBLzkuRi5Vdxm4a66rDe /7nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698226392; x=1698831192; 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=vBUBp+Evkj+zkoxn3FVgKIrs/5i8foEUdffnEcGBefA=; b=toV5D3GTEyAK2JswftlO1PIpvneBqahbnmPb3XMT8TxgLGGYn1f2p1wpeuGpw0wT2f fAYM+fcLMC2Cywu1B7DM5VbwZUPs3Dr4xwfqnBlnqGPSP8R6pJTUdZc5cJgZYvCN0nKh +JxbsVHpw4E/A9T4wD4TwVTkb2d7KVNWX9FzZ6U37J0Q9pLK7i7xiumn9SEJbgdH++1m ZkQpJL2OoILBUc8uL5g4tSNk/Fd5B1EcJ/Li1mkq8XRfCIynOwUMZFlKq49UnJTsohn5 CmZd1EVZbx7m+x3F2ZsxowJ4BZAnJI9tcMi0M53XC2BUBlMbdkaLuLiQO707D7cYh9la Ebig== X-Gm-Message-State: AOJu0YwzViXjqmwKZ9xX97lpDCZtRgXwrfuotDk46bjg3HKqY9xl1UHd 9y8T+H0rETIaA7GSk5qICwvIJQ== X-Google-Smtp-Source: AGHT+IFN58idTP/+RROaPzf+OTCi6ewVNGHPRjW/4JQiNufmakoqi2cJgaB5wJQ0fjtVN2A+QxMc4w== X-Received: by 2002:a17:902:f245:b0:1c9:deb8:bdc5 with SMTP id j5-20020a170902f24500b001c9deb8bdc5mr10629514plc.34.1698226392106; Wed, 25 Oct 2023 02:33:12 -0700 (PDT) From: Akihiko Odaki To: Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Akihiko Odaki , Alexandre Iooss , Mahmoud Mandour Subject: [PATCH v16 17/18] plugins: Allow to read registers Date: Wed, 25 Oct 2023 18:31:17 +0900 Message-ID: <20231025093128.33116-18-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231025093128.33116-1-akihiko.odaki@daynix.com> References: <20231025093128.33116-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::634; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x634.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1698226429051100015 Content-Type: text/plain; charset="utf-8" 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 | 50 ++++++++++++++++++++++++++++++++++-- plugins/api.c | 20 +++++++++++++++ plugins/qemu-plugins.symbols | 3 +++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 50a9957279..c0ce700258 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 =20 +#include #include #include #include @@ -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,49 @@ uint64_t qemu_plugin_end_code(void); */ uint64_t qemu_plugin_entry_code(void); =20 +/** + * qemu_plugin_find_register_file() - find register file + * + * @vcpu_index: the index of the vcpu context + * @name: the name of the register file. + * + * Returns the identifier of the register file if it was found, and a nega= tive + * value otherwise. + * + * The names of register files are identical with names of GDB's standard + * target features with some extensions. For details, see: + * https://sourceware.org/gdb/onlinedocs/gdb/Standard-Target-Features.html + */ +int qemu_plugin_find_register_file(unsigned int vcpu_index, const char *na= me); + +/** + * qemu_plugin_find_register() - find register + * + * @vcpu_index: the index of the vcpu context + * @file: the register file identifier determined with + * qemu_plugin_find_register_file(). + * @name: the name of the register. + * + * The names of register 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 + */ +int qemu_plugin_find_register(unsigned int vcpu_index, int file, + const char *name); + +/** + * 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_find_register(). + * + * 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 ac39cdea0b..3eaad5bf41 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -35,10 +35,12 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "exec/gdbstub.h" #include "exec/ram_addr.h" #include "disas/disas.h" #include "plugin.h" @@ -435,3 +437,21 @@ uint64_t qemu_plugin_entry_code(void) #endif return entry; } + +int qemu_plugin_find_register_file(unsigned int vcpu_index, const char *na= me) +{ + QEMU_IOTHREAD_LOCK_GUARD(); + return gdb_find_feature(qemu_get_cpu(vcpu_index), name); +} + +int qemu_plugin_find_register(unsigned int vcpu_index, int file, + const char *name) +{ + QEMU_IOTHREAD_LOCK_GUARD(); + return gdb_find_feature_register(qemu_get_cpu(vcpu_index), file, name); +} + +int qemu_plugin_read_register(GByteArray *buf, int reg) +{ + return gdb_read_register(current_cpu, buf, reg); +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549..977f1fcfcb 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -42,4 +42,7 @@ qemu_plugin_tb_vaddr; qemu_plugin_uninstall; qemu_plugin_vcpu_for_each; + qemu_plugin_find_register_file; + qemu_plugin_find_register; + qemu_plugin_read_register; }; --=20 2.42.0