From nobody Mon May 6 13:26:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097802240107.5058413763769; Wed, 8 Sep 2021 03:43:22 -0700 (PDT) Received: from localhost ([::1]:39946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNv33-00035Z-5F for importer@patchew.org; Wed, 08 Sep 2021 06:43:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxE-00009e-PU for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26722) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxC-0003r4-1P for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-196-9zUKwunhNdS9fVDzaEGNEw-1; Wed, 08 Sep 2021 06:37:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4ED681023F4E; Wed, 8 Sep 2021 10:37:15 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.192.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9BA05C1BB; Wed, 8 Sep 2021 10:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631097437; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0LaGWGHRKF4KyGLUeIWs7LfNT8ZIwfCo3FPBs0wLOR4=; b=N/5Cr5rqaF5Vg6YdY7gEPavDEWky+dGvV0i5cHZ4kZDn764UXJncLfIPsCVE84uzMpeXxv vyPWE6tnfFzBq7oajO66RVdERutrEXemjKs0i3ajcIURifoWcf59GdU+IaxBkCZVlJN8UA UHI+nI53P/Ft8iR+8qZFz8UbrgQ/VhE= X-MC-Unique: 9zUKwunhNdS9fVDzaEGNEw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/5] docs/devel: document expectations for QAPI data modelling for QMP Date: Wed, 8 Sep 2021 11:37:07 +0100 Message-Id: <20210908103711.683940-2-berrange@redhat.com> In-Reply-To: <20210908103711.683940-1-berrange@redhat.com> References: <20210908103711.683940-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097803355100003 Traditionally we have required that newly added QMP commands will model any returned data using fine grained QAPI types. This is good for commands that are intended to be consumed by machines, where clear data representation is very important. Commands that don't satisfy this have generally been added to HMP only. In effect the decision of whether to add a new command to QMP vs HMP has been used as a proxy for the decision of whether the cost of designing a fine grained QAPI type is justified by the potential benefits. As a result the commands present in QMP and HMP are non-overlapping sets, although HMP comamnds can be accessed indirectly via the QMP command 'human-monitor-command'. One of the downsides of 'human-monitor-command' is that the QEMU monitor APIs remain tied into various internal parts of the QEMU code. For example any exclusively HMP command will need to use 'monitor_printf' to get data out. It would be desirable to be able to fully isolate the monitor implementation from QEMU internals, however, this is only possible if all commands are exclusively based on QAPI with direct QMP exposure. The way to achieve this desired end goal is to finese the requirements for QMP command design. For cases where the output of a command is only intended for human consumption, it is reasonable to want to simplify the implementation by returning a plain string containing formatted data instead of designing a fine grained QAPI data type. This can be permitted if-and-only-if the command is exposed under the 'x-' name prefix. This indicates that the command data format is liable to future change and that it is not following QAPI design best practice. The poster child example for this would be the 'info registers' HMP command which returns printf formatted data representing CPU state. This information varies enourmously across target architectures and changes relatively frequently as new CPU features are implemented. It is there as debugging data for human operators, and any machine usage would treat it as an opaque blob. It is thus reasonable to expose this in QMP as 'x-query-registers' returning a 'str' field. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- docs/devel/writing-qmp-commands.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/devel/writing-qmp-commands.rst b/docs/devel/writing-qmp-c= ommands.rst index 6a10a06c48..d032daa62d 100644 --- a/docs/devel/writing-qmp-commands.rst +++ b/docs/devel/writing-qmp-commands.rst @@ -350,6 +350,31 @@ In this section we will focus on user defined types. P= lease, check the QAPI documentation for information about the other types. =20 =20 +Modelling data in QAPI +~~~~~~~~~~~~~~~~~~~~~~ + +For a QMP command that to be considered stable and supported long term the= re +is a requirement returned data should be explicitly modelled using fine gr= ained +QAPI types. As a general guide, a caller of the QMP command should never n= eed +to parse individual returned data fields. If a field appears to need parsi= ng, +them it should be split into separate fields corresponding to each distinct +data item. This should be the common case for any new QMP command that is +intended to be used by machines, as opposed to exclusively human operators. + +Some QMP commands, however, are only intended as adhoc debugging aids for = human +operators. While they may return large amounts of formatted data, it is not +expected that machines will need to parse the result. The overhead of defi= ning +a fine grained QAPI type for the data may not be justified by the potential +benefit. In such cases, it is permitted to have a command return a simple = string +that contains formatted data, however, it is mandatory for the command to = use +the 'x-' name prefix. This indicates that the command is not guaranteed to= be +long term stable / liable to change in future and is not following QAPI de= sign +best practices. An example where this approach is taken is the QMP command +"x-query-registers". This returns a printf formatted dump of the architect= ure +specific CPU state. The way the data is formatted varies across QEMU targe= ts, +is liable to change over time, and is only intended to be consumed as an o= paque +string by machines. + User Defined Types ~~~~~~~~~~~~~~~~~~ =20 --=20 2.31.1 From nobody Mon May 6 13:26:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631098197019609.2980525875273; Wed, 8 Sep 2021 03:49:57 -0700 (PDT) Received: from localhost ([::1]:60626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNv9Q-0000FX-1u for importer@patchew.org; Wed, 08 Sep 2021 06:49:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxF-0000Ba-6n for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32640) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxD-0003rw-Dv for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-574-z2mHo6-XPy6_HWSPpv7Jbw-1; Wed, 08 Sep 2021 06:37:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9C1F101F000; Wed, 8 Sep 2021 10:37:16 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.192.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87CD55C1BB; Wed, 8 Sep 2021 10:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631097438; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rKnaBwFCCJX9ZX6cv7A4ifx+XIL+7QBX+qDEATc0WKY=; b=EbWhV21Bb8bQrZ4nIacHh93WUp5CZ2YeRFNhwtYxSJ0UmComjP69Pua1cZV9k0P/XIuTzK RuP+L68Q+2mZtSjO9YX4r34p/XyYDls4Y3uQrJRc1yd6hhNBJv2AB/RdM+Vv7+LYQ8hWdq pQwuqJV+x0wIuw1fy6QJ9gOnT64Dl+c= X-MC-Unique: z2mHo6-XPy6_HWSPpv7Jbw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 2/5] hw/core: introduce 'format_state' callback to replace 'dump_state' Date: Wed, 8 Sep 2021 11:37:08 +0100 Message-Id: <20210908103711.683940-3-berrange@redhat.com> In-Reply-To: <20210908103711.683940-1-berrange@redhat.com> References: <20210908103711.683940-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631098198454100001 The 'dump_state' callback assumes it will be outputting to a FILE object. This is fine for HMP, but not so useful for QMP. Introduce a new 'format_state' callback that returns a formatted GString instead. Signed-off-by: Daniel P. Berrang=C3=A9 --- hw/core/cpu-common.c | 15 +++++++++++++++ include/hw/core/cpu.h | 13 ++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index e2f5a64604..c2cd33a817 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -106,6 +106,21 @@ void cpu_dump_state(CPUState *cpu, FILE *f, int flags) if (cc->dump_state) { cpu_synchronize_state(cpu); cc->dump_state(cpu, f, flags); + } else if (cc->format_state) { + g_autoptr(GString) buf =3D g_string_new(""); + cpu_synchronize_state(cpu); + cc->format_state(cpu, buf, flags); + qemu_fprintf(f, "%s", buf->str); + } +} + +void cpu_format_state(CPUState *cpu, GString *buf, int flags) +{ + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + if (cc->format_state) { + cpu_synchronize_state(cpu); + cc->format_state(cpu, buf, flags); } } =20 diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index bc864564ce..1599ef9df3 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -91,7 +91,8 @@ struct SysemuCPUOps; * @reset_dump_flags: #CPUDumpFlags to use for reset logging. * @has_work: Callback for checking if there is work to do. * @memory_rw_debug: Callback for GDB memory access. - * @dump_state: Callback for dumping state. + * @dump_state: Callback for dumping state. Deprecated, use @format_state. + * @format_state: Callback for formatting state. * @get_arch_id: Callback for getting architecture-dependent CPU ID. * @set_pc: Callback for setting the Program Counter register. This * should have the semantics used by the target architecture when @@ -136,6 +137,7 @@ struct CPUClass { int (*memory_rw_debug)(CPUState *cpu, vaddr addr, uint8_t *buf, int len, bool is_write); void (*dump_state)(CPUState *cpu, FILE *, int flags); + void (*format_state)(CPUState *cpu, GString *buf, int flags); int64_t (*get_arch_id)(CPUState *cpu); void (*set_pc)(CPUState *cpu, vaddr value); int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg); @@ -537,6 +539,15 @@ enum CPUDumpFlags { */ void cpu_dump_state(CPUState *cpu, FILE *f, int flags); =20 +/** + * cpu_format_state: + * @cpu: The CPU whose state is to be formatted. + * @buf: buffer to format state into + * + * Formats the CPU state. + */ +void cpu_format_state(CPUState *cpu, GString *buf, int flags); + #ifndef CONFIG_USER_ONLY /** * cpu_get_phys_page_attrs_debug: --=20 2.31.1 From nobody Mon May 6 13:26:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631098387552345.5047534659211; Wed, 8 Sep 2021 03:53:07 -0700 (PDT) Received: from localhost ([::1]:40610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNvCU-0005tV-A2 for importer@patchew.org; Wed, 08 Sep 2021 06:53:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxK-0000Wu-7O for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxH-0003vV-M5 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-l0GtYP3-NLSeySeFg3ujmw-1; Wed, 08 Sep 2021 06:37:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 403C780196C; Wed, 8 Sep 2021 10:37:21 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.192.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3ECC65C1BB; Wed, 8 Sep 2021 10:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631097443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V4XMjbf0Qs0FB8YqPIkbCZeFcIvgV7JjtV9qnc3KVqY=; b=LNtQenB+1KuBhooOWxpZThUOhvNQhMPUzo2dKbK1l3RyUkU4heg+oV3Wd3LOaVspo5NOYz 900FdJyssQXR+DvVjFQEpzppW3xh0OjH+sFHOgcpXngV3+6oUluVsw9F7hjfKcjna30Gdv hTWJCV0knwBHRmivYwY7HN6l66CgC3I= X-MC-Unique: l0GtYP3-NLSeySeFg3ujmw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/5] target/i386: convert to use format_state instead of dump_state Date: Wed, 8 Sep 2021 11:37:09 +0100 Message-Id: <20210908103711.683940-4-berrange@redhat.com> In-Reply-To: <20210908103711.683940-1-berrange@redhat.com> References: <20210908103711.683940-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631098388931100001 Signed-off-by: Daniel P. Berrang=C3=A9 --- target/i386/cpu-dump.c | 325 ++++++++++++++++++++++------------------- target/i386/cpu.c | 2 +- target/i386/cpu.h | 2 +- 3 files changed, 174 insertions(+), 155 deletions(-) diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c index 02b635a52c..8e19485a20 100644 --- a/target/i386/cpu-dump.c +++ b/target/i386/cpu-dump.c @@ -94,41 +94,45 @@ static const char *cc_op_str[CC_OP_NB] =3D { }; =20 static void -cpu_x86_dump_seg_cache(CPUX86State *env, FILE *f, +cpu_x86_dump_seg_cache(CPUX86State *env, GString *buf, const char *name, struct SegmentCache *sc) { #ifdef TARGET_X86_64 if (env->hflags & HF_CS64_MASK) { - qemu_fprintf(f, "%-3s=3D%04x %016" PRIx64 " %08x %08x", name, - sc->selector, sc->base, sc->limit, - sc->flags & 0x00ffff00); + g_string_append_printf(buf, "%-3s=3D%04x %016" PRIx64 " %08x %08x"= , name, + sc->selector, sc->base, sc->limit, + sc->flags & 0x00ffff00); } else #endif { - qemu_fprintf(f, "%-3s=3D%04x %08x %08x %08x", name, sc->selector, - (uint32_t)sc->base, sc->limit, - sc->flags & 0x00ffff00); + g_string_append_printf(buf, "%-3s=3D%04x %08x %08x %08x", + name, sc->selector, + (uint32_t)sc->base, sc->limit, + sc->flags & 0x00ffff00); } =20 if (!(env->hflags & HF_PE_MASK) || !(sc->flags & DESC_P_MASK)) goto done; =20 - qemu_fprintf(f, " DPL=3D%d ", + g_string_append_printf(buf, " DPL=3D%d ", (sc->flags & DESC_DPL_MASK) >> DESC_DPL_SHIFT); if (sc->flags & DESC_S_MASK) { if (sc->flags & DESC_CS_MASK) { - qemu_fprintf(f, (sc->flags & DESC_L_MASK) ? "CS64" : - ((sc->flags & DESC_B_MASK) ? "CS32" : "CS16")); - qemu_fprintf(f, " [%c%c", (sc->flags & DESC_C_MASK) ? 'C' : '-= ', - (sc->flags & DESC_R_MASK) ? 'R' : '-'); + g_string_append_printf(buf, (sc->flags & DESC_L_MASK) ? "CS64"= : + ((sc->flags & DESC_B_MASK) ? "CS32" : "= CS16")); + g_string_append_printf(buf, " [%c%c", + (sc->flags & DESC_C_MASK) ? 'C' : '-', + (sc->flags & DESC_R_MASK) ? 'R' : '-'); } else { - qemu_fprintf(f, (sc->flags & DESC_B_MASK + g_string_append_printf(buf, (sc->flags & DESC_B_MASK || env->hflags & HF_LMA_MASK) ? "DS " : "DS16"); - qemu_fprintf(f, " [%c%c", (sc->flags & DESC_E_MASK) ? 'E' : '-= ', - (sc->flags & DESC_W_MASK) ? 'W' : '-'); + g_string_append_printf(buf, " [%c%c", + (sc->flags & DESC_E_MASK) ? 'E' : '-', + (sc->flags & DESC_W_MASK) ? 'W' : '-'); } - qemu_fprintf(f, "%c]", (sc->flags & DESC_A_MASK) ? 'A' : '-'); + g_string_append_printf(buf, "%c]", + (sc->flags & DESC_A_MASK) ? 'A' : '-'); } else { static const char *sys_type_name[2][16] =3D { { /* 32 bit mode */ @@ -144,12 +148,12 @@ cpu_x86_dump_seg_cache(CPUX86State *env, FILE *f, "Reserved", "IntGate64", "TrapGate64" } }; - qemu_fprintf(f, "%s", - sys_type_name[(env->hflags & HF_LMA_MASK) ? 1 : 0] - [(sc->flags & DESC_TYPE_MASK) >> DESC_TYPE_SHIFT]); + g_string_append_printf(buf, "%s", + sys_type_name[(env->hflags & HF_LMA_MASK) ?= 1 : 0] + [(sc->flags & DESC_TYPE_MASK) >> DESC_TYPE_= SHIFT]); } done: - qemu_fprintf(f, "\n"); + g_string_append_printf(buf, "\n"); } =20 #ifndef CONFIG_USER_ONLY @@ -344,7 +348,7 @@ void x86_cpu_dump_local_apic_state(CPUState *cs, int fl= ags) #define DUMP_CODE_BYTES_TOTAL 50 #define DUMP_CODE_BYTES_BACKWARD 20 =20 -void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) +void x86_cpu_format_state(CPUState *cs, GString *buf, int flags) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; @@ -355,107 +359,116 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int = flags) eflags =3D cpu_compute_eflags(env); #ifdef TARGET_X86_64 if (env->hflags & HF_CS64_MASK) { - qemu_fprintf(f, "RAX=3D%016" PRIx64 " RBX=3D%016" PRIx64 " RCX=3D%= 016" PRIx64 " RDX=3D%016" PRIx64 "\n" - "RSI=3D%016" PRIx64 " RDI=3D%016" PRIx64 " RBP=3D%016= " PRIx64 " RSP=3D%016" PRIx64 "\n" - "R8 =3D%016" PRIx64 " R9 =3D%016" PRIx64 " R10=3D%016= " PRIx64 " R11=3D%016" PRIx64 "\n" - "R12=3D%016" PRIx64 " R13=3D%016" PRIx64 " R14=3D%016= " PRIx64 " R15=3D%016" PRIx64 "\n" - "RIP=3D%016" PRIx64 " RFL=3D%08x [%c%c%c%c%c%c%c] CPL= =3D%d II=3D%d A20=3D%d SMM=3D%d HLT=3D%d\n", - env->regs[R_EAX], - env->regs[R_EBX], - env->regs[R_ECX], - env->regs[R_EDX], - env->regs[R_ESI], - env->regs[R_EDI], - env->regs[R_EBP], - env->regs[R_ESP], - env->regs[8], - env->regs[9], - env->regs[10], - env->regs[11], - env->regs[12], - env->regs[13], - env->regs[14], - env->regs[15], - env->eip, eflags, - eflags & DF_MASK ? 'D' : '-', - eflags & CC_O ? 'O' : '-', - eflags & CC_S ? 'S' : '-', - eflags & CC_Z ? 'Z' : '-', - eflags & CC_A ? 'A' : '-', - eflags & CC_P ? 'P' : '-', - eflags & CC_C ? 'C' : '-', - env->hflags & HF_CPL_MASK, - (env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1, - (env->a20_mask >> 20) & 1, - (env->hflags >> HF_SMM_SHIFT) & 1, - cs->halted); + g_string_append_printf(buf, "RAX=3D%016" PRIx64 " RBX=3D%016" PRIx= 64 + " RCX=3D%016" PRIx64 " RDX=3D%016" PRIx64 "= \n" + "RSI=3D%016" PRIx64 " RDI=3D%016" PRIx64 + " RBP=3D%016" PRIx64 " RSP=3D%016" PRIx64 "= \n" + "R8 =3D%016" PRIx64 " R9 =3D%016" PRIx64 + " R10=3D%016" PRIx64 " R11=3D%016" PRIx64 "= \n" + "R12=3D%016" PRIx64 " R13=3D%016" PRIx64 + " R14=3D%016" PRIx64 " R15=3D%016" PRIx64 "= \n" + "RIP=3D%016" PRIx64 " RFL=3D%08x [%c%c%c%c%= c%c%c] " + "CPL=3D%d II=3D%d A20=3D%d SMM=3D%d HLT=3D%= d\n", + env->regs[R_EAX], + env->regs[R_EBX], + env->regs[R_ECX], + env->regs[R_EDX], + env->regs[R_ESI], + env->regs[R_EDI], + env->regs[R_EBP], + env->regs[R_ESP], + env->regs[8], + env->regs[9], + env->regs[10], + env->regs[11], + env->regs[12], + env->regs[13], + env->regs[14], + env->regs[15], + env->eip, eflags, + eflags & DF_MASK ? 'D' : '-', + eflags & CC_O ? 'O' : '-', + eflags & CC_S ? 'S' : '-', + eflags & CC_Z ? 'Z' : '-', + eflags & CC_A ? 'A' : '-', + eflags & CC_P ? 'P' : '-', + eflags & CC_C ? 'C' : '-', + env->hflags & HF_CPL_MASK, + (env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1, + (env->a20_mask >> 20) & 1, + (env->hflags >> HF_SMM_SHIFT) & 1, + cs->halted); } else #endif { - qemu_fprintf(f, "EAX=3D%08x EBX=3D%08x ECX=3D%08x EDX=3D%08x\n" - "ESI=3D%08x EDI=3D%08x EBP=3D%08x ESP=3D%08x\n" - "EIP=3D%08x EFL=3D%08x [%c%c%c%c%c%c%c] CPL=3D%d II= =3D%d A20=3D%d SMM=3D%d HLT=3D%d\n", - (uint32_t)env->regs[R_EAX], - (uint32_t)env->regs[R_EBX], - (uint32_t)env->regs[R_ECX], - (uint32_t)env->regs[R_EDX], - (uint32_t)env->regs[R_ESI], - (uint32_t)env->regs[R_EDI], - (uint32_t)env->regs[R_EBP], - (uint32_t)env->regs[R_ESP], - (uint32_t)env->eip, eflags, - eflags & DF_MASK ? 'D' : '-', - eflags & CC_O ? 'O' : '-', - eflags & CC_S ? 'S' : '-', - eflags & CC_Z ? 'Z' : '-', - eflags & CC_A ? 'A' : '-', - eflags & CC_P ? 'P' : '-', - eflags & CC_C ? 'C' : '-', - env->hflags & HF_CPL_MASK, - (env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1, - (env->a20_mask >> 20) & 1, - (env->hflags >> HF_SMM_SHIFT) & 1, - cs->halted); + g_string_append_printf(buf, "EAX=3D%08x EBX=3D%08x ECX=3D%08x EDX= =3D%08x\n" + "ESI=3D%08x EDI=3D%08x EBP=3D%08x ESP=3D%08= x\n" + "EIP=3D%08x EFL=3D%08x [%c%c%c%c%c%c%c] " + "CPL=3D%d II=3D%d A20=3D%d SMM=3D%d HLT=3D%= d\n", + (uint32_t)env->regs[R_EAX], + (uint32_t)env->regs[R_EBX], + (uint32_t)env->regs[R_ECX], + (uint32_t)env->regs[R_EDX], + (uint32_t)env->regs[R_ESI], + (uint32_t)env->regs[R_EDI], + (uint32_t)env->regs[R_EBP], + (uint32_t)env->regs[R_ESP], + (uint32_t)env->eip, eflags, + eflags & DF_MASK ? 'D' : '-', + eflags & CC_O ? 'O' : '-', + eflags & CC_S ? 'S' : '-', + eflags & CC_Z ? 'Z' : '-', + eflags & CC_A ? 'A' : '-', + eflags & CC_P ? 'P' : '-', + eflags & CC_C ? 'C' : '-', + env->hflags & HF_CPL_MASK, + (env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1, + (env->a20_mask >> 20) & 1, + (env->hflags >> HF_SMM_SHIFT) & 1, + cs->halted); } =20 for(i =3D 0; i < 6; i++) { - cpu_x86_dump_seg_cache(env, f, seg_name[i], &env->segs[i]); + cpu_x86_dump_seg_cache(env, buf, seg_name[i], &env->segs[i]); } - cpu_x86_dump_seg_cache(env, f, "LDT", &env->ldt); - cpu_x86_dump_seg_cache(env, f, "TR", &env->tr); + cpu_x86_dump_seg_cache(env, buf, "LDT", &env->ldt); + cpu_x86_dump_seg_cache(env, buf, "TR", &env->tr); =20 #ifdef TARGET_X86_64 if (env->hflags & HF_LMA_MASK) { - qemu_fprintf(f, "GDT=3D %016" PRIx64 " %08x\n", - env->gdt.base, env->gdt.limit); - qemu_fprintf(f, "IDT=3D %016" PRIx64 " %08x\n", - env->idt.base, env->idt.limit); - qemu_fprintf(f, "CR0=3D%08x CR2=3D%016" PRIx64 " CR3=3D%016" PRIx6= 4 " CR4=3D%08x\n", - (uint32_t)env->cr[0], - env->cr[2], - env->cr[3], - (uint32_t)env->cr[4]); + g_string_append_printf(buf, "GDT=3D %016" PRIx64 " %08x\n", + env->gdt.base, env->gdt.limit); + g_string_append_printf(buf, "IDT=3D %016" PRIx64 " %08x\n", + env->idt.base, env->idt.limit); + g_string_append_printf(buf, "CR0=3D%08x CR2=3D%016" PRIx64 + " CR3=3D%016" PRIx64 " CR4=3D%08x\n", + (uint32_t)env->cr[0], + env->cr[2], + env->cr[3], + (uint32_t)env->cr[4]); for(i =3D 0; i < 4; i++) - qemu_fprintf(f, "DR%d=3D%016" PRIx64 " ", i, env->dr[i]); - qemu_fprintf(f, "\nDR6=3D%016" PRIx64 " DR7=3D%016" PRIx64 "\n", - env->dr[6], env->dr[7]); + g_string_append_printf(buf, "DR%d=3D%016" PRIx64 " ", i, env->= dr[i]); + g_string_append_printf(buf, "\nDR6=3D%016" PRIx64 " DR7=3D%016" PR= Ix64 "\n", + env->dr[6], env->dr[7]); } else #endif { - qemu_fprintf(f, "GDT=3D %08x %08x\n", - (uint32_t)env->gdt.base, env->gdt.limit); - qemu_fprintf(f, "IDT=3D %08x %08x\n", - (uint32_t)env->idt.base, env->idt.limit); - qemu_fprintf(f, "CR0=3D%08x CR2=3D%08x CR3=3D%08x CR4=3D%08x\n", - (uint32_t)env->cr[0], - (uint32_t)env->cr[2], - (uint32_t)env->cr[3], - (uint32_t)env->cr[4]); + g_string_append_printf(buf, "GDT=3D %08x %08x\n", + (uint32_t)env->gdt.base, env->gdt.limit); + g_string_append_printf(buf, "IDT=3D %08x %08x\n", + (uint32_t)env->idt.base, env->idt.limit); + g_string_append_printf(buf, "CR0=3D%08x CR2=3D%08x CR3=3D%08x CR4= =3D%08x\n", + (uint32_t)env->cr[0], + (uint32_t)env->cr[2], + (uint32_t)env->cr[3], + (uint32_t)env->cr[4]); for(i =3D 0; i < 4; i++) { - qemu_fprintf(f, "DR%d=3D" TARGET_FMT_lx " ", i, env->dr[i]); + g_string_append_printf(buf, "DR%d=3D" TARGET_FMT_lx + " ", i, env->dr[i]); } - qemu_fprintf(f, "\nDR6=3D" TARGET_FMT_lx " DR7=3D" TARGET_FMT_lx "= \n", - env->dr[6], env->dr[7]); + g_string_append_printf(buf, "\nDR6=3D" TARGET_FMT_lx + " DR7=3D" TARGET_FMT_lx "\n", + env->dr[6], env->dr[7]); } if (flags & CPU_DUMP_CCOP) { if ((unsigned)env->cc_op < CC_OP_NB) @@ -464,18 +477,19 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int fl= ags) snprintf(cc_op_name, sizeof(cc_op_name), "[%d]", env->cc_op); #ifdef TARGET_X86_64 if (env->hflags & HF_CS64_MASK) { - qemu_fprintf(f, "CCS=3D%016" PRIx64 " CCD=3D%016" PRIx64 " CCO= =3D%-8s\n", - env->cc_src, env->cc_dst, - cc_op_name); + g_string_append_printf(buf, "CCS=3D%016" PRIx64 + " CCD=3D%016" PRIx64 " CCO=3D%-8s\n", + env->cc_src, env->cc_dst, + cc_op_name); } else #endif { - qemu_fprintf(f, "CCS=3D%08x CCD=3D%08x CCO=3D%-8s\n", - (uint32_t)env->cc_src, (uint32_t)env->cc_dst, - cc_op_name); + g_string_append_printf(buf, "CCS=3D%08x CCD=3D%08x CCO=3D%-8s\= n", + (uint32_t)env->cc_src, (uint32_t)env->c= c_dst, + cc_op_name); } } - qemu_fprintf(f, "EFER=3D%016" PRIx64 "\n", env->efer); + g_string_append_printf(buf, "EFER=3D%016" PRIx64 "\n", env->efer); if (flags & CPU_DUMP_FPU) { int fptag; const uint64_t avx512_mask =3D XSTATE_OPMASK_MASK | \ @@ -488,64 +502,68 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int fl= ags) fptag |=3D ((!env->fptags[i]) << i); } update_mxcsr_from_sse_status(env); - qemu_fprintf(f, "FCW=3D%04x FSW=3D%04x [ST=3D%d] FTW=3D%02x MXCSR= =3D%08x\n", - env->fpuc, - (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11, - env->fpstt, - fptag, - env->mxcsr); + g_string_append_printf( + buf, "FCW=3D%04x FSW=3D%04x [ST=3D%d] FTW=3D%02x MXCSR=3D%08x\= n", + env->fpuc, + (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11, + env->fpstt, + fptag, + env->mxcsr); for(i=3D0;i<8;i++) { CPU_LDoubleU u; u.d =3D env->fpregs[i].d; - qemu_fprintf(f, "FPR%d=3D%016" PRIx64 " %04x", - i, u.l.lower, u.l.upper); + g_string_append_printf(buf, "FPR%d=3D%016" PRIx64 " %04x", + i, u.l.lower, u.l.upper); if ((i & 1) =3D=3D 1) - qemu_fprintf(f, "\n"); + g_string_append_printf(buf, "\n"); else - qemu_fprintf(f, " "); + g_string_append_printf(buf, " "); } - if ((env->xcr0 & avx512_mask) =3D=3D avx512_mask) { /* XSAVE enabled AVX512 */ for (i =3D 0; i < NB_OPMASK_REGS; i++) { - qemu_fprintf(f, "Opmask%02d=3D%016"PRIx64"%s", i, - env->opmask_regs[i], ((i & 3) =3D=3D 3) ? "\n= " : " "); + g_string_append_printf(buf, "Opmask%02d=3D%016"PRIx64"%s",= i, + env->opmask_regs[i], + ((i & 3) =3D=3D 3) ? "\n" : " "); } =20 nb =3D (env->hflags & HF_CS64_MASK) ? 32 : 8; for (i =3D 0; i < nb; i++) { - qemu_fprintf(f, "ZMM%02d=3D%016"PRIx64" %016"PRIx64" %016"= PRIx64 - " %016"PRIx64" %016"PRIx64" %016"PRIx64 - " %016"PRIx64" %016"PRIx64"\n", - i, - env->xmm_regs[i].ZMM_Q(7), - env->xmm_regs[i].ZMM_Q(6), - env->xmm_regs[i].ZMM_Q(5), - env->xmm_regs[i].ZMM_Q(4), - env->xmm_regs[i].ZMM_Q(3), - env->xmm_regs[i].ZMM_Q(2), - env->xmm_regs[i].ZMM_Q(1), - env->xmm_regs[i].ZMM_Q(0)); + g_string_append_printf(buf, "ZMM%02d=3D%016"PRIx64 + " %016"PRIx64" %016"PRIx64 + " %016"PRIx64" %016"PRIx64" %016"PR= Ix64 + " %016"PRIx64" %016"PRIx64"\n", + i, + env->xmm_regs[i].ZMM_Q(7), + env->xmm_regs[i].ZMM_Q(6), + env->xmm_regs[i].ZMM_Q(5), + env->xmm_regs[i].ZMM_Q(4), + env->xmm_regs[i].ZMM_Q(3), + env->xmm_regs[i].ZMM_Q(2), + env->xmm_regs[i].ZMM_Q(1), + env->xmm_regs[i].ZMM_Q(0)); } } else if ((env->xcr0 & avx_mask) =3D=3D avx_mask) { /* XSAVE enabled AVX */ nb =3D env->hflags & HF_CS64_MASK ? 16 : 8; for (i =3D 0; i < nb; i++) { - qemu_fprintf(f, "YMM%02d=3D%016"PRIx64" %016"PRIx64" %016"= PRIx64 - " %016"PRIx64"\n", i, - env->xmm_regs[i].ZMM_Q(3), - env->xmm_regs[i].ZMM_Q(2), - env->xmm_regs[i].ZMM_Q(1), - env->xmm_regs[i].ZMM_Q(0)); + g_string_append_printf(buf, "YMM%02d=3D%016"PRIx64 + " %016"PRIx64" %016"PRIx64 + " %016"PRIx64"\n", i, + env->xmm_regs[i].ZMM_Q(3), + env->xmm_regs[i].ZMM_Q(2), + env->xmm_regs[i].ZMM_Q(1), + env->xmm_regs[i].ZMM_Q(0)); } } else { /* SSE and below cases */ nb =3D env->hflags & HF_CS64_MASK ? 16 : 8; for (i =3D 0; i < nb; i++) { - qemu_fprintf(f, "XMM%02d=3D%016"PRIx64" %016"PRIx64"%s", - i, - env->xmm_regs[i].ZMM_Q(1), - env->xmm_regs[i].ZMM_Q(0), - (i & 1) ? "\n" : " "); + g_string_append_printf(buf, + "XMM%02d=3D%016"PRIx64" %016"PRIx64= "%s", + i, + env->xmm_regs[i].ZMM_Q(1), + env->xmm_regs[i].ZMM_Q(0), + (i & 1) ? "\n" : " "); } } } @@ -555,16 +573,17 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int fl= ags) uint8_t code; char codestr[3]; =20 - qemu_fprintf(f, "Code=3D"); + g_string_append_printf(buf, "Code=3D"); for (i =3D 0; i < DUMP_CODE_BYTES_TOTAL; i++) { if (cpu_memory_rw_debug(cs, base - offs + i, &code, 1, 0) =3D= =3D 0) { snprintf(codestr, sizeof(codestr), "%02x", code); } else { snprintf(codestr, sizeof(codestr), "??"); } - qemu_fprintf(f, "%s%s%s%s", i > 0 ? " " : "", - i =3D=3D offs ? "<" : "", codestr, i =3D=3D offs = ? ">" : ""); + g_string_append_printf(buf, "%s%s%s%s", i > 0 ? " " : "", + i =3D=3D offs ? "<" : "", codestr, + i =3D=3D offs ? ">" : ""); } - qemu_fprintf(f, "\n"); + g_string_append_printf(buf, "\n"); } } diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 97e250e876..f31a304abb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6757,7 +6757,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc= , void *data) cc->class_by_name =3D x86_cpu_class_by_name; cc->parse_features =3D x86_cpu_parse_featurestr; cc->has_work =3D x86_cpu_has_work; - cc->dump_state =3D x86_cpu_dump_state; + cc->format_state =3D x86_cpu_format_state; cc->set_pc =3D x86_cpu_set_pc; cc->gdb_read_register =3D x86_cpu_gdb_read_register; cc->gdb_write_register =3D x86_cpu_gdb_write_register; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 6c50d3ab4f..01ca4e715d 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1821,7 +1821,7 @@ int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunctio= n f, CPUState *cpu, void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, Error **errp); =20 -void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags); +void x86_cpu_format_state(CPUState *cs, GString *buf, int flags); =20 hwaddr x86_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); --=20 2.31.1 From nobody Mon May 6 13:26:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631098510100290.8075910697245; Wed, 8 Sep 2021 03:55:10 -0700 (PDT) Received: from localhost ([::1]:47040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNvES-0001mU-VA for importer@patchew.org; Wed, 08 Sep 2021 06:55:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxL-0000ca-Lz for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxJ-0003x3-DY for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-152-nOZSJRwVMpqTpBT3P88lCw-1; Wed, 08 Sep 2021 06:37:23 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF29680196C; Wed, 8 Sep 2021 10:37:22 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.192.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87E0F5C1BB; Wed, 8 Sep 2021 10:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631097444; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q0zamBHuSyhxCwxRjHzc1VsYhStYmDG6F1Vgs4R3B4U=; b=HhxlkGRy2yWQWTG2dXTAgC30OceyR6BzW7ehaq8oYxrdnjx6HzL1BCZKLaRMDl2Nn7ZcZ5 TjsSOBrNirTReKPBKyQp6htKB45zUmpGfjfZf6nL9uW1PPnltzCLJLtzw5aQLLLRaquO4J c35TpnJLw9pMXLz8yM8eI6cZtmv5+ZM= X-MC-Unique: nOZSJRwVMpqTpBT3P88lCw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 4/5] qapi: introduce x-query-registers QMP command Date: Wed, 8 Sep 2021 11:37:10 +0100 Message-Id: <20210908103711.683940-5-berrange@redhat.com> In-Reply-To: <20210908103711.683940-1-berrange@redhat.com> References: <20210908103711.683940-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631098511971100001 This is a counterpart to the HMP "info registers" command. It is being added with an "x-" prefix because this QMP command is intended as an adhoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. Signed-off-by: Daniel P. Berrang=C3=A9 --- hw/core/machine-qmp-cmds.c | 28 ++++++++++++++++++++++++++++ qapi/machine.json | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index 216fdfaf3a..0d9943ff60 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -204,3 +204,31 @@ MemdevList *qmp_query_memdev(Error **errp) object_child_foreach(obj, query_memdev, &list); return list; } + +RegisterInfo *qmp_x_query_registers(bool has_cpu, int64_t cpu, Error **err= p) +{ + RegisterInfo *info =3D g_new0(RegisterInfo, 1); + g_autoptr(GString) buf =3D g_string_new(""); + CPUState *cs =3D NULL, *tmp; + + if (has_cpu) { + CPU_FOREACH(tmp) { + if (cpu =3D=3D tmp->cpu_index) { + cs =3D tmp; + } + } + if (!cs) { + error_setg(errp, "CPU %"PRId64" not available", cpu); + return NULL; + } + cpu_format_state(cs, buf, CPU_DUMP_FPU); + } else { + CPU_FOREACH(cs) { + g_string_append_printf(buf, "\nCPU#%d\n", cs->cpu_index); + cpu_format_state(cs, buf, CPU_DUMP_FPU); + } + } + + info->state =3D g_steal_pointer(&buf->str); + return info; +} diff --git a/qapi/machine.json b/qapi/machine.json index 157712f006..27b922f2ce 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1312,3 +1312,40 @@ '*cores': 'int', '*threads': 'int', '*maxcpus': 'int' } } + +## +# @RegisterParams: +# +# Information about the CPU to query state of +# +# @cpu: the CPU number to query. If omitted, queries all CPUs +# +# Since: 6.2.0 +# +## +{ 'struct': 'RegisterParams', 'data': {'*cpu': 'int' } } + +## +# @RegisterInfo: +# +# Information about the CPU state +# +# @state: the CPU state in an architecture specific format +# +# Since: 6.2.0 +# +## +{ 'struct': 'RegisterInfo', 'data': {'state': 'str' } } + +## +# @x-query-registers: +# +# Return information on the CPU registers +# +# Returns: the CPU state +# +# Since: 6.2.0 +## +{ 'command': 'x-query-registers', + 'data': 'RegisterParams', + 'returns': 'RegisterInfo' } --=20 2.31.1 From nobody Mon May 6 13:26:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631098114495982.3948340806495; Wed, 8 Sep 2021 03:48:34 -0700 (PDT) Received: from localhost ([::1]:54752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNv83-0004nU-Sb for importer@patchew.org; Wed, 08 Sep 2021 06:48:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxO-0000p5-Vb for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56241) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuxL-0003yQ-Uu for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:37:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-595-MQLjeFkuP_GG6N4XQmx-CQ-1; Wed, 08 Sep 2021 06:37:25 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A8717835DE0; Wed, 8 Sep 2021 10:37:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.192.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44EE35C1BB; Wed, 8 Sep 2021 10:37:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631097446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gr3ePbRsec0D0Q8wPR3TkoswcYi2RmAmEO3Z1GwQXjo=; b=IM/8aqK9BYVCa/h3UqNO5Y8ms3vj3JIn9ZlWxwxze67PbhjLZf5HuzEGlumFGEwG303CFX PnO6/loJt69BJyCZiVBMEeMXxaxAZxhoI4d0g8fmGy0LQK3epxcDS8LAKedzarQoq5IWJc Pb9rPdJFKCNzllbHZGGm0pFCpOgED6U= X-MC-Unique: MQLjeFkuP_GG6N4XQmx-CQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 5/5] monitor: rewrite 'info registers' in terms of 'x-query-registers' Date: Wed, 8 Sep 2021 11:37:11 +0100 Message-Id: <20210908103711.683940-6-berrange@redhat.com> In-Reply-To: <20210908103711.683940-1-berrange@redhat.com> References: <20210908103711.683940-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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: pass client-ip=216.205.24.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631098114949100001 Now that we have a QMP command 'x-query-registers', the HMP counterpart 'info registers' can be refactored to call the former. Signed-off-by: Daniel P. Berrang=C3=A9 --- monitor/misc.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/monitor/misc.c b/monitor/misc.c index ffe7966870..f0b94c3084 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -67,6 +67,7 @@ #include "block/block-hmp-cmds.h" #include "qapi/qapi-commands-char.h" #include "qapi/qapi-commands-control.h" +#include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-qom.h" @@ -301,23 +302,29 @@ int monitor_get_cpu_index(Monitor *mon) static void hmp_info_registers(Monitor *mon, const QDict *qdict) { bool all_cpus =3D qdict_get_try_bool(qdict, "cpustate_all", false); - CPUState *cs; + bool has_cpu =3D !all_cpus; + int64_t cpu =3D 0; + Error *local_err =3D NULL; + g_autoptr(RegisterInfo) info =3D NULL; =20 - if (all_cpus) { - CPU_FOREACH(cs) { - monitor_printf(mon, "\nCPU#%d\n", cs->cpu_index); - cpu_dump_state(cs, NULL, CPU_DUMP_FPU); - } - } else { - cs =3D mon_get_cpu(mon); + if (has_cpu) { + CPUState *cs =3D mon_get_cpu(mon); =20 if (!cs) { monitor_printf(mon, "No CPU available\n"); return; } =20 - cpu_dump_state(cs, NULL, CPU_DUMP_FPU); + cpu =3D cs->cpu_index; + } + + info =3D qmp_x_query_registers(has_cpu, cpu, &local_err); + if (!info) { + error_report_err(local_err); + return; } + + monitor_printf(mon, "%s", info->state); } =20 static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict) --=20 2.31.1