From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31A4EC4167D for ; Wed, 13 Dec 2023 06:45:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rDIy4-0002aF-4Y; Wed, 13 Dec 2023 01:43:40 -0500 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 1rDIxm-00026d-Of for qemu-devel@nongnu.org; Wed, 13 Dec 2023 01:43:24 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rDIxi-0005gS-0Q for qemu-devel@nongnu.org; Wed, 13 Dec 2023 01:43:21 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d3470496e2so9365135ad.1 for ; Tue, 12 Dec 2023 22:43:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1702449796; x=1703054596; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=T4p6vSO8CKdC89ov95w+SL3j0ix/l04dcknZHk45s30=; b=K86fEAyO9/9IlxYnj4+3AxgRW0H33Pzl8YEeYCmJeFGjyztG1RsDz2oFzEZU8GU/AV k/Yl3j+ew9cwFTEUdZeqh2qO++xngxTWr3U/eSzz31+qQr6xWfKQbLW0HefU7jgo5D1M bunazcHMTLV4U8F25kno5ltysafu4Z8JxspmF+fvLgluQy0LG0odsstS+pZgCV1p/cuK c2uGe1rRIMHlL2HjDky7wOzDHIlDoXBC4+W3vaRM8V3mm21rc+AyAf6kRYD6nn+cQOfj Y1LF5gamU3rhnNhox5W8qZddToP8WZC5MA9zkyuApn/l7W1G7LnvwyB2waK0pOJz4bmr Covg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702449796; x=1703054596; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T4p6vSO8CKdC89ov95w+SL3j0ix/l04dcknZHk45s30=; b=KmMQmPHSKRY9KHjsHAUb8FBZdcMKFtB7JkxiW5Mgn9ixbJpEonC15z7wY6j3MRFvzX ghL5SJ5I5PZIVLW/xFIc033AjFDbDImoycd446zJAR6weCsLZagO2l01Pb7l/sEuYP4h PA3WEqAr99LjXyKYM+CBaehydfjmWljp7uv9mj9a4FRNDvOG0G09YJl89a+KwcRTv95z V0IT7P2GXTnT2hMre7nf0dfXbZFH5Hoc4hxUXTmEMwpUuDA3NZzhVihx0Hb99DPMLJ15 gBv23X0RTOLz8HNutp4wu9yCre3FpYxrfRdM4DY44kaE2/12YM0OO/LNvQiqBXqyeB+s 6UuA== X-Gm-Message-State: AOJu0Yzmgy0Ff4RXQtOVgPGOJhG/Voil40dRoGc2OuOtJc4DsYjTb5AS eY//rlISxEbyHfxojpwR5REcow== X-Google-Smtp-Source: AGHT+IFNoDHwOBz4h+l24N2R9FDR52U2pp6CZ0JrZXT4MdxTrKcLBJx0wzIXJSGFPkOWiUFb8/gA6Q== X-Received: by 2002:a17:902:ab4e:b0:1d3:4fa1:9dc with SMTP id ij14-20020a170902ab4e00b001d34fa109dcmr528944plb.79.1702449796608; Tue, 12 Dec 2023 22:43:16 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id x10-20020a1709029a4a00b001d34796c1e9sm1151266plv.119.2023.12.12.22.43.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Dec 2023 22:43:16 -0800 (PST) From: Akihiko Odaki Date: Wed, 13 Dec 2023 15:41:12 +0900 Subject: [PATCH v17 13/14] plugins: Allow to read registers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231213-gdb-v17-13-777047380591@daynix.com> References: <20231213-gdb-v17-0-777047380591@daynix.com> In-Reply-To: <20231213-gdb-v17-0-777047380591@daynix.com> To: Peter Maydell , Nicholas Piggin , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brian Cain , Song Gao , Laurent Vivier , "Edgar E. Iglesias" , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Thomas Huth , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Michael Rolnik , Paolo Bonzini , Yoshinori Sato , John Snow , Cleber Rosa , Alexandre Iooss , Mahmoud Mandour , Mikhail Tyutin , Aleksandr Anenkov Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, 20231213-riscv-v7-0-a760156a337f@daynix.com, Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 | 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 4daab6efd291..e7e21c9ee5b7 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 @@ -227,8 +228,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, @@ -708,4 +709,49 @@ uint64_t qemu_plugin_end_code(void); QEMU_PLUGIN_API uint64_t qemu_plugin_entry_code(void); +/** + * 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 negative + * 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 *name); + +/** + * 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 ac39cdea0b35..3eaad5bf4187 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -35,10 +35,12 @@ */ #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 *name) +{ + 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 71f6c90549d4..977f1fcfcbfb 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; }; -- 2.43.0