Skip to contentSkip to conversation

monitor: explicitly permit QMP commands to be added for all use cases

PATCH Superseded Daniel P. Berrangé 12 participants 108 messages Sep 14, 2021 – Sep 22, 2021 RISC-V

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover monitor: explicitly permit QMP commands to be added for all use cases

Previous postings:

v1: https://lists.gnu.org/archive/html/qemu-devel/2021-09/msg02295.html

We are still adding HMP commands without any QMP counterparts. This is done because there are a reasonable number of scenarios where the cost of designing a QAPI data type for the command is not justified.

This has the downside, however, that we will never be able to fully isolate the monitor code from the remainder of QEMU internals. It is desirable to be able to get to a point where subsystems in QEMU are exclusively implemented using QAPI types and never need to have any knowledge of the monitor.

The way to get there is to stop adding commands to HMP only. All commands must be implemented using QMP and any HMP equivalent be a shim around the QMP implemetation. We don't want to compromise our supportability of QMP long term though.

This series proposes that we relax our requirements around fine grained QAPI data design, but with the caveat that any command taking this design approach is mandated to use the 'x-' name prefix. This tradeoff should be suitable for any commands we have been adding exclusively to HMP in recent times, and thus mean we have mandate QMP support for all new commands going forward.

The series then converts the following HMP commands to be QMP shims.

info opcount
info jit
info tlb
info irq
info lapic
info cmma
info skeys
info ramblock
info rdma
info usb
info numa
info profile
info roms
info registers

After doing this conversion

- All except 1 usage of qemu_fprintf is eliminated
- 50% of calls to qemu_printf are eliminated
- 75 calls to monitor_printf are eliminated

Ultimately it should be possible to entirely eliminate qemu_fprintf and qemu_printf, and confine monitor_printf calls exclusively to the top level HMP command handlers.

A full conversion would also enable HMP to be emulated entirely outside QEMU. This could be interesting if we introduce a new QEMU system emulator binary which is legacy free and 100% controlled via QMP, as it would let us provide HMP backcompat around it without the burden of HMP being integrated directly.

There are still 48 HMP commands with no QMP counterpart after this series.

- A few are not relevant to port as they directly reflect HMP functionality (help, info history).
- A few are sort of available in QMP but look quite different (drive_add vs blockdev_add)
- A few are complicated. "info usbhost" is a dynamically loaded HMP command inside a loadable module and we don't have a way to dynamically register QMP handlers at runtime.
- Most are just tedious gruntwork.

Changed in v2:

- Improved documentation in response to feedback
- Finished "info registers" conversion on all targets
- Got a bit carried away and converted many many more commands

Daniel P. Berrangé (53):
docs/devel: rename file for writing monitor commands docs/devel: tweak headings in monitor command docs docs/devel: document expectations for QAPI data modelling for QMP docs/devel: add example of command returning unstructured text docs/devel: document expectations for HMP commands in the future hw/core: introduce 'format_state' callback to replace 'dump_state' target/alpha: convert to use format_state instead of dump_state target/arm: convert to use format_state instead of dump_state target/avr: convert to use format_state instead of dump_state target/cris: convert to use format_state instead of dump_state target/hexagon: delete unused hexagon_debug() method target/hexagon: convert to use format_state instead of dump_state target/hppa: convert to use format_state instead of dump_state target/i386: convert to use format_state instead of dump_state target/m68k: convert to use format_state instead of dump_state target/microblaze: convert to use format_state instead of dump_state target/mips: convert to use format_state instead of dump_state target/nios2: convert to use format_state instead of dump_state target/openrisc: convert to use format_state instead of dump_state target/ppc: convert to use format_state instead of dump_state target/riscv: convert to use format_state instead of dump_state target/rx: convert to use format_state instead of dump_state target/s390x: convert to use format_state instead of dump_state target/sh: convert to use format_state instead of dump_state target/sparc: convert to use format_state instead of dump_state target/tricore: convert to use format_state instead of dump_state target/xtensa: convert to use format_state instead of dump_state
monitor: remove 'info ioapic' HMP command
qapi: introduce x-query-registers QMP command
qapi: introduce x-query-roms QMP command
qapi: introduce x-query-profile QMP command
qapi: introduce x-query-numa QMP command
qapi: introduce x-query-usb QMP command
qapi: introduce x-query-rdma QMP command
qapi: introduce x-query-ramblock QMP command
qapi: introduce x-query-skeys QMP command
qapi: introduce x-query-cmma QMP command
qapi: introduce x-query-lapic QMP command
qapi: introduce x-query-irq QMP command
hw/core: drop "dump_state" callback from CPU targets hw/core: drop support for NULL pointer for FILE * in cpu_dump_state hw/core: introduce a 'format_tlb' callback
target/i386: convert to use format_tlb callback target/m68k: convert to use format_tlb callback target/nios2: convert to use format_tlb callback target/ppc: convert to use format_tlb callback target/sh4: convert to use format_tlb callback target/sparc: convert to use format_tlb callback target/xtensa: convert to use format_tlb callback
monitor: merge duplicate "info tlb" handlers
qapi: introduce x-query-tlb QMP command
qapi: introduce x-query-jit QMP command
qapi: introduce x-query-opcount QMP command

 accel/tcg/cpu-exec.c                          |  56 +-
 accel/tcg/hmp.c                               |  24 +-
 accel/tcg/translate-all.c                     |  84 +--
 docs/devel/index.rst                          |   2 +-
 ...mands.rst => writing-monitor-commands.rst} | 136 ++++-
 hmp-commands-info.hx                          |  18 -
 hw/core/cpu-common.c                          |  27 +-
 hw/core/loader.c                              |  55 +-
 hw/core/machine-hmp-cmds.c                    |  33 +-
 hw/core/machine-qmp-cmds.c                    |  94 ++++
 hw/rdma/rdma_rm.c                             | 104 ++--
 hw/rdma/rdma_rm.h                             |   2 +-
 hw/rdma/vmw/pvrdma_main.c                     |  31 +-
 hw/s390x/s390-skeys.c                         |  37 +-
 hw/s390x/s390-stattrib.c                      |  58 ++-
 hw/usb/bus.c                                  |  38 +-
 include/exec/cpu-all.h                        |   6 +-
 include/exec/ramlist.h                        |   2 +-
 include/hw/core/cpu.h                         |  36 +-
 include/hw/rdma/rdma.h                        |   2 +-
 include/monitor/hmp-target.h                  |   2 -
 include/tcg/tcg.h                             |   4 +-
 monitor/hmp-cmds.c                            |  81 +--
 monitor/misc.c                                |  68 ++-
 monitor/qmp-cmds.c                            | 127 +++++
 qapi/common.json                              |  11 +
 qapi/machine-target.json                      |  58 +++
 qapi/machine.json                             | 140 +++++
 softmmu/physmem.c                             |  19 +-
 stubs/usb-dev-stub.c                          |   8 +
 target/alpha/cpu.c                            |   2 +-
 target/alpha/cpu.h                            |   2 +-
 target/alpha/helper.c                         |  28 +-
 target/arm/cpu.c                              | 152 +++---
 target/avr/cpu.c                              |  57 +-
 target/cris/cpu.c                             |   2 +-
 target/cris/cpu.h                             |   2 +-
 target/cris/translate.c                       |  33 +-
 target/hexagon/cpu.c                          |  70 ++-
 target/hexagon/internal.h                     |   1 -
 target/hppa/cpu.c                             |   2 +-
 target/hppa/cpu.h                             |   2 +-
 target/hppa/helper.c                          |  25 +-
 target/i386/cpu-dump.c                        | 489 ++++++++++--------
 target/i386/cpu.c                             |   5 +-
 target/i386/cpu.h                             |   7 +-
 target/i386/monitor.c                         | 142 ++---
 target/m68k/cpu.c                             |   5 +-
 target/m68k/cpu.h                             |   5 +-
 target/m68k/helper.c                          | 132 ++---
 target/m68k/monitor.c                         |  14 +-
 target/m68k/translate.c                       |  92 ++--
 target/microblaze/cpu.c                       |   2 +-
 target/microblaze/cpu.h                       |   2 +-
 target/microblaze/translate.c                 |  45 +-
 target/mips/cpu.c                             |  85 +--
 target/nios2/cpu.c                            |   5 +-
 target/nios2/cpu.h                            |   4 +-
 target/nios2/mmu.c                            |  37 +-
 target/nios2/monitor.c                        |   7 -
 target/nios2/translate.c                      |  20 +-
 target/openrisc/cpu.c                         |   2 +-
 target/openrisc/cpu.h                         |   2 +-
 target/openrisc/translate.c                   |   8 +-
 target/ppc/cpu.h                              |   5 +-
 target/ppc/cpu_init.c                         | 215 ++++----
 target/ppc/mmu-hash64.c                       |   8 +-
 target/ppc/mmu-hash64.h                       |   2 +-
 target/ppc/mmu_common.c                       | 167 +++---
 target/ppc/monitor.c                          |  11 -
 target/riscv/cpu.c                            | 105 ++--
 target/rx/cpu.c                               |   2 +-
 target/rx/cpu.h                               |   2 +-
 target/rx/translate.c                         |  14 +-
 target/s390x/cpu-dump.c                       |  43 +-
 target/s390x/cpu.c                            |   2 +-
 target/s390x/s390x-internal.h                 |   2 +-
 target/sh4/cpu.c                              |   5 +-
 target/sh4/cpu.h                              |   3 +-
 target/sh4/monitor.c                          |  41 +-
 target/sh4/translate.c                        |  36 +-
 target/sparc/cpu.c                            |  86 +--
 target/sparc/cpu.h                            |   3 +-
 target/sparc/mmu_helper.c                     |  43 +-
 target/sparc/monitor.c                        |  12 -
 target/tricore/cpu.c                          |   2 +-
 target/tricore/cpu.h                          |   2 +-
 target/tricore/translate.c                    |  24 +-
 target/xtensa/cpu.c                           |   2 +-
 target/xtensa/cpu.h                           |   4 +-
 target/xtensa/mmu_helper.c                    | 126 +++--
 target/xtensa/monitor.c                       |  11 -
 target/xtensa/translate.c                     |  45 +-
 tcg/tcg.c                                     |  98 ++--
 tests/qtest/qmp-cmd-test.c                    |   8 +
 95 files changed, 2429 insertions(+), 1551 deletions(-)
 rename docs/devel/{writing-qmp-commands.rst => writing-monitor-commands.rst} (78%)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/53 docs/devel: rename file for writing monitor commands

The file already covers writing new style HMP commands, in addition to the QMP commands, so it deserves a more general name.

---
 docs/devel/index.rst                                        | 2 +-
 ...riting-qmp-commands.rst => writing-monitor-commands.rst} | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
 rename docs/devel/{writing-qmp-commands.rst => writing-monitor-commands.rst} (99%)
docs/devel/index.rst +1 -1
index f95df10b3e..7c25177c5d 100644
@@ -44,4 +44,4 @@ modifying QEMU's source code.
    ebpf_rss
    vfio-migration
    qapi-code-gen
-   writing-qmp-commands
+   writing-monitor-commands
docs/devel/writing-monitor-commands.rst renamed from docs/devel/writing-qmp-commands.rst +3 -3
similarity index 99%
rename from docs/devel/writing-qmp-commands.rst
rename to docs/devel/writing-monitor-commands.rst
index 6a10a06c48..497c9ce0d5 100644
@@ -1,8 +1,8 @@
-How to write QMP commands using the QAPI framework
-==================================================
+How to write monitor commands
+=============================
 
 This document is a step-by-step guide on how to write new QMP commands using
-the QAPI framework. It also shows how to implement new style HMP commands.
+the QAPI framework and new style HMP commands.
 
 This document doesn't discuss QMP protocol level details, nor does it dive
 into the QAPI framework implementation.
Signature · 1 line
2.31.1
#4 lore raw

PATCH v2 2/53 docs/devel: tweak headings in monitor command docs

In reply to Daniel P. Berrangé

The new headings reflect the intended structure of the document and will better suit additions that follow.

---
 docs/devel/writing-monitor-commands.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
docs/devel/writing-monitor-commands.rst +4 -4
index 497c9ce0d5..cddb36fb74 100644
@@ -85,8 +85,8 @@ any data". Now you're ready to enter the QMP example commands as explained in
 the following sections.
 
 
-Writing a command that doesn't return data
-------------------------------------------
+Writing a simple command: hello-world
+-------------------------------------
 
 That's the most simple QMP command that can be written. Usually, this kind of
 command carries some meaningful action in QEMU but here it will just print
@@ -340,8 +340,8 @@ Please, check the "-monitor" command-line option to know how to open a user
 monitor.
 
 
-Writing a command that returns data
------------------------------------
+Writing more complex commands
+-----------------------------
 
 A QMP command is capable of returning any data the QAPI supports like integers,
 strings, booleans, enumerations and user defined types.
Signature · 1 line
2.31.1
#6 lore raw

PATCH v2 3/53 docs/devel: document expectations for QAPI data modelling for QMP

In reply to Daniel P. Berrangé

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.

---
 docs/devel/writing-monitor-commands.rst | 27 +++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
docs/devel/writing-monitor-commands.rst +27 -0
index cddb36fb74..d68c552fdd 100644
@@ -350,6 +350,33 @@ In this section we will focus on user defined types. Please, check the QAPI
 documentation for information about the other types.
 
 
+Modelling data in QAPI
+~~~~~~~~~~~~~~~~~~~~~~
+
+For a QMP command that to be considered stable and supported long term,
+there is a requirement returned data should be explicitly modelled
+using fine-grained QAPI types. As a general guide, a caller of the QMP
+command should never need to parse individual returned data fields. If
+a field appears to need parsing, then 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 ad hoc 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 defining 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 design
+best practices. An example where this approach is taken is the QMP
+command "x-query-registers". This returns a formatted dump of the
+architecture specific CPU state. The way the data is formatted varies
+across QEMU targets, is liable to change over time, and is only
+intended to be consumed as an opaque string by machines.
+
 User Defined Types
 ~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.31.1
#8 lore raw

PATCH v2 4/53 docs/devel: add example of command returning unstructured text

In reply to Daniel P. Berrangé

This illustrates how to add a QMP command returning unstructured text, following the guidelines added in the previous patch. The example uses a simplified version of 'info roms'.

---
 docs/devel/writing-monitor-commands.rst | 85 +++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
docs/devel/writing-monitor-commands.rst +85 -0
index d68c552fdd..4cf51ab557 100644
@@ -647,3 +647,88 @@ has to traverse the list, it's shown below for reference::
 
      qapi_free_TimerAlarmMethodList(method_list);
  }
+
+Writing a debugging aid returning unstructured text
+---------------------------------------------------
+
+As discussed at the start of the previous example, it is required that
+commands expecting machine usage be using fine-grained QAPI data types.
+The exception to this rule applies when the command is solely intended
+as a debugging aid and allows for returning unstructured text. This is
+commonly needed for query commands that report aspects of QEMU's
+internal state that are useful to human operators.
+
+In this example we will consider a simplified variant of the HMP
+command ``info roms``. Following the earlier rules, this command will
+need to live under the ``x-`` name prefix, so its QMP implementation
+will be called ``x-query-roms``. It will have no parameters and will
+return a single text string::
+
+ { 'struct': 'HumanReadableText',
+   'data': { 'human-readable-text': 'str' } }
+
+ { 'command': 'x-query-roms',
+   'returns': 'HumanReadableText' }
+
+The ``HumanReadableText`` struct is intended to be used for all
+commands, under the ``x-`` name prefix that are returning unstructured
+text targetted at humans. It should never be used for commands outside
+the ``x-`` name prefix, as those should be using structured QAPI types.
+
+Implementing the QMP command
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The QMP implementation will typically involve creating a ``GString``
+object and printing formatted data into it::
+
+ HumanReadableText *qmp_x_query_roms(Error **errp)
+ {
+     GString buf = g_string_new("");
+     HumanReadableText ret = g_new0(HumanReadableText, 1);
+     Rom *rom;
+
+     QTAILQ_FOREACH(rom, &roms, next) {
+        g_string_append_printf("%s size=0x%06zx name=\"%s\"\n",
+                               memory_region_name(rom->mr),
+                               rom->romsize,
+                               rom->name);
+     }
+
+     ret->human_readable_text = g_string_free(buf, FALSE);
+
+     return ret;
+ }
+
+
+Implementing the HMP command
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Now that the QMP command is in place, we can also make it available in
+the human monitor (HMP) as shown in previous examples. The HMP
+implementations will all look fairly similar, as all they need do is
+invoke the QMP command and then print the resulting text or error
+message. Here's the implementation of the "info roms" HMP command::
+
+ void hmp_info_roms(Monitor *mon, const QDict *qdict)
+ {
+     Error err = NULL;
+     g_autoptr(HumanReadableText) info = qmp_x_query_roms(&err);
+     if (err) {
+         error_report_err(err);
+         return;
+     }
+     monitor_printf(mon, "%s\n", info->human_readable_text);
+ }
+
+Also, you have to add the function's prototype to the hmp.h file.
+
+There's one last step to actually make the command available to
+monitor users, we should add it to the hmp-commands-info.hx file::
+
+    {
+        .name       = "roms",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show roms",
+        .cmd        = hmp_info_roms,
+    },
Signature · 1 line
2.31.1
#10 lore raw

PATCH v2 5/53 docs/devel: document expectations for HMP commands in the future

In reply to Daniel P. Berrangé

We no longer wish to have commands implemented in HMP only. All commands should start with a QMP implementation and the HMP merely be a shim around this. To reduce the burden of implementing QMP commands where there is low expectation of machine usage, requirements for QAPI modelling are relaxed provided the command is under the "x-" name prefix.

---
 docs/devel/writing-monitor-commands.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
docs/devel/writing-monitor-commands.rst +10 -0
index 4cf51ab557..983130a793 100644
@@ -11,6 +11,16 @@ For an in-depth introduction to the QAPI framework, please refer to
 docs/devel/qapi-code-gen.txt. For documentation about the QMP protocol,
 start with docs/interop/qmp-intro.txt.
 
+Historically QEMU has permitted new monitor commands to be implemented in HMP
+only, QMP only, or both, depending on whether they needed to be accessible to
+human operators, machines, or both. When both QMP and HMP are implemented it
+is expected the HMP implementation is a shim around the QMP implementation.
+Going forward, the expectation is that new commands are implemented in QMP
+only, or both QMP and HMP. No further commands are to be added to HMP only.
+The long term goal is that all HMP commands will be implemented in terms of
+their QMP equivalent, enabling internals of QEMU to be fully isolated from
+the HMP implementation. Refer to the later topic on modelling data in QAPI
+for further guidance on commands that would have traditionally been HMP only.
 
 Overview
 --------
Signature · 1 line
2.31.1
#13 lore raw

PATCH v2 6/53 hw/core: introduce 'format_state' callback to replace 'dump_state'

In reply to Daniel P. Berrangé

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.

---
 hw/core/cpu-common.c  | 15 +++++++++++++++
 include/hw/core/cpu.h | 13 ++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)
hw/core/cpu-common.c +15 -0
index e2f5a64604..c2cd33a817 100644
@@ -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 = 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 = CPU_GET_CLASS(cpu);
+
+    if (cc->format_state) {
+        cpu_synchronize_state(cpu);
+        cc->format_state(cpu, buf, flags);
     }
 }
 
include/hw/core/cpu.h +12 -1
index bc864564ce..1599ef9df3 100644
@@ -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);
 
+/**
+ * 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:
Signature · 1 line
2.31.1
#18 lore raw

PATCH v2 8/53 target/arm: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/arm/cpu.c | 152 +++++++++++++++++++++++++----------------------
 1 file changed, 81 insertions(+), 71 deletions(-)
target/arm/cpu.c +81 -71
index d631c4683c..5999277e67 100644
@@ -798,7 +798,7 @@ static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
 
 #ifdef TARGET_AARCH64
 
-static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static void aarch64_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     ARMCPU *cpu = ARM_CPU(cs);
     CPUARMState *env = &cpu->env;
@@ -807,13 +807,14 @@ static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     int el = arm_current_el(env);
     const char *ns_status;
 
-    qemu_fprintf(f, " PC=%016" PRIx64 " ", env->pc);
+    g_string_append_printf(buf, " PC=%016" PRIx64 " ", env->pc);
     for (i = 0; i < 32; i++) {
         if (i == 31) {
-            qemu_fprintf(f, " SP=%016" PRIx64 "\n", env->xregs[i]);
+            g_string_append_printf(buf, " SP=%016" PRIx64 "\n", env->xregs[i]);
         } else {
-            qemu_fprintf(f, "X%02d=%016" PRIx64 "%s", i, env->xregs[i],
-                         (i + 2) % 3 ? " " : "\n");
+            g_string_append_printf(buf, "X%02d=%016" PRIx64 "%s",
+                                   i, env->xregs[i],
+                                   (i + 2) % 3 ? " " : "\n");
         }
     }
 
@@ -822,29 +823,29 @@ static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     } else {
         ns_status = "";
     }
-    qemu_fprintf(f, "PSTATE=%08x %c%c%c%c %sEL%d%c",
-                 psr,
-                 psr & PSTATE_N ? 'N' : '-',
-                 psr & PSTATE_Z ? 'Z' : '-',
-                 psr & PSTATE_C ? 'C' : '-',
-                 psr & PSTATE_V ? 'V' : '-',
-                 ns_status,
-                 el,
-                 psr & PSTATE_SP ? 'h' : 't');
+    g_string_append_printf(buf, "PSTATE=%08x %c%c%c%c %sEL%d%c",
+                           psr,
+                           psr & PSTATE_N ? 'N' : '-',
+                           psr & PSTATE_Z ? 'Z' : '-',
+                           psr & PSTATE_C ? 'C' : '-',
+                           psr & PSTATE_V ? 'V' : '-',
+                           ns_status,
+                           el,
+                           psr & PSTATE_SP ? 'h' : 't');
 
     if (cpu_isar_feature(aa64_bti, cpu)) {
-        qemu_fprintf(f, "  BTYPE=%d", (psr & PSTATE_BTYPE) >> 10);
+        g_string_append_printf(buf, "  BTYPE=%d", (psr & PSTATE_BTYPE) >> 10);
     }
     if (!(flags & CPU_DUMP_FPU)) {
-        qemu_fprintf(f, "\n");
+        g_string_append_printf(buf, "\n");
         return;
     }
     if (fp_exception_el(env, el) != 0) {
-        qemu_fprintf(f, "    FPU disabled\n");
+        g_string_append_printf(buf, "    FPU disabled\n");
         return;
     }
-    qemu_fprintf(f, "     FPCR=%08x FPSR=%08x\n",
-                 vfp_get_fpcr(env), vfp_get_fpsr(env));
+    g_string_append_printf(buf, "     FPCR=%08x FPSR=%08x\n",
+                           vfp_get_fpcr(env), vfp_get_fpsr(env));
 
     if (cpu_isar_feature(aa64_sve, cpu) && sve_exception_el(env, el) == 0) {
         int j, zcr_len = sve_zcr_len_for_el(env, el);
@@ -852,11 +853,11 @@ static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         for (i = 0; i <= FFR_PRED_NUM; i++) {
             bool eol;
             if (i == FFR_PRED_NUM) {
-                qemu_fprintf(f, "FFR=");
+                g_string_append_printf(buf, "FFR=");
                 /* It's last, so end the line.  */
                 eol = true;
             } else {
-                qemu_fprintf(f, "P%02d=", i);
+                g_string_append_printf(buf, "P%02d=", i);
                 switch (zcr_len) {
                 case 0:
                     eol = i % 8 == 7;
@@ -881,76 +882,84 @@ static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
                 } else {
                     digits = (zcr_len % 4 + 1) * 4;
                 }
-                qemu_fprintf(f, "%0*" PRIx64 "%s", digits,
-                             env->vfp.pregs[i].p[j],
-                             j ? ":" : eol ? "\n" : " ");
+                g_string_append_printf(buf, "%0*" PRIx64 "%s", digits,
+                                       env->vfp.pregs[i].p[j],
+                                       j ? ":" : eol ? "\n" : " ");
             }
         }
 
         for (i = 0; i < 32; i++) {
             if (zcr_len == 0) {
-                qemu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64 "%s",
-                             i, env->vfp.zregs[i].d[1],
-                             env->vfp.zregs[i].d[0], i & 1 ? "\n" : " ");
+                g_string_append_printf(buf, "Z%02d=%016" PRIx64
+                                       ":%016" PRIx64 "%s",
+                                       i, env->vfp.zregs[i].d[1],
+                                       env->vfp.zregs[i].d[0],
+                                       i & 1 ? "\n" : " ");
             } else if (zcr_len == 1) {
-                qemu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64
-                             ":%016" PRIx64 ":%016" PRIx64 "\n",
-                             i, env->vfp.zregs[i].d[3], env->vfp.zregs[i].d[2],
-                             env->vfp.zregs[i].d[1], env->vfp.zregs[i].d[0]);
+                g_string_append_printf(buf, "Z%02d=%016" PRIx64 ":%016" PRIx64
+                                       ":%016" PRIx64 ":%016" PRIx64 "\n",
+                                       i, env->vfp.zregs[i].d[3],
+                                       env->vfp.zregs[i].d[2],
+                                       env->vfp.zregs[i].d[1],
+                                       env->vfp.zregs[i].d[0]);
             } else {
                 for (j = zcr_len; j >= 0; j--) {
                     bool odd = (zcr_len - j) % 2 != 0;
                     if (j == zcr_len) {
-                        qemu_fprintf(f, "Z%02d[%x-%x]=", i, j, j - 1);
+                        g_string_append_printf(buf, "Z%02d[%x-%x]=",
+                                               i, j, j - 1);
                     } else if (!odd) {
                         if (j > 0) {
-                            qemu_fprintf(f, "   [%x-%x]=", j, j - 1);
+                            g_string_append_printf(buf, "   [%x-%x]=",
+                                                   j, j - 1);
                         } else {
-                            qemu_fprintf(f, "     [%x]=", j);
+                            g_string_append_printf(buf, "     [%x]=", j);
                         }
                     }
-                    qemu_fprintf(f, "%016" PRIx64 ":%016" PRIx64 "%s",
-                                 env->vfp.zregs[i].d[j * 2 + 1],
-                                 env->vfp.zregs[i].d[j * 2],
-                                 odd || j == 0 ? "\n" : ":");
+                    g_string_append_printf(buf,
+                                           "%016" PRIx64 ":%016" PRIx64 "%s",
+                                           env->vfp.zregs[i].d[j * 2 + 1],
+                                           env->vfp.zregs[i].d[j * 2],
+                                           odd || j == 0 ? "\n" : ":");
                 }
             }
         }
     } else {
         for (i = 0; i < 32; i++) {
             uint64_t *q = aa64_vfp_qreg(env, i);
-            qemu_fprintf(f, "Q%02d=%016" PRIx64 ":%016" PRIx64 "%s",
-                         i, q[1], q[0], (i & 1 ? "\n" : " "));
+            g_string_append_printf(buf, "Q%02d=%016" PRIx64 ":%016" PRIx64 "%s",
+                                   i, q[1], q[0], (i & 1 ? "\n" : " "));
         }
     }
 }
 
 #else
 
-static inline void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static inline void
+aarch64_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     g_assert_not_reached();
 }
 
 #endif
 
-static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static void arm_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     ARMCPU *cpu = ARM_CPU(cs);
     CPUARMState *env = &cpu->env;
     int i;
 
     if (is_a64(env)) {
-        aarch64_cpu_dump_state(cs, f, flags);
+        aarch64_cpu_format_state(cs, buf, flags);
         return;
     }
 
     for (i = 0; i < 16; i++) {
-        qemu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
+        g_string_append_printf(buf, "R%02d=%08x", i, env->regs[i]);
         if ((i % 4) == 3) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         } else {
-            qemu_fprintf(f, " ");
+            g_string_append_printf(buf, " ");
         }
     }
 
@@ -973,15 +982,15 @@ static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
             }
         }
 
-        qemu_fprintf(f, "XPSR=%08x %c%c%c%c %c %s%s\n",
-                     xpsr,
-                     xpsr & XPSR_N ? 'N' : '-',
-                     xpsr & XPSR_Z ? 'Z' : '-',
-                     xpsr & XPSR_C ? 'C' : '-',
-                     xpsr & XPSR_V ? 'V' : '-',
-                     xpsr & XPSR_T ? 'T' : 'A',
-                     ns_status,
-                     mode);
+        g_string_append_printf(buf, "XPSR=%08x %c%c%c%c %c %s%s\n",
+                               xpsr,
+                               xpsr & XPSR_N ? 'N' : '-',
+                               xpsr & XPSR_Z ? 'Z' : '-',
+                               xpsr & XPSR_C ? 'C' : '-',
+                               xpsr & XPSR_V ? 'V' : '-',
+                               xpsr & XPSR_T ? 'T' : 'A',
+                               ns_status,
+                               mode);
     } else {
         uint32_t psr = cpsr_read(env);
         const char *ns_status = "";
@@ -991,15 +1000,15 @@ static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
             ns_status = env->cp15.scr_el3 & SCR_NS ? "NS " : "S ";
         }
 
-        qemu_fprintf(f, "PSR=%08x %c%c%c%c %c %s%s%d\n",
-                     psr,
-                     psr & CPSR_N ? 'N' : '-',
-                     psr & CPSR_Z ? 'Z' : '-',
-                     psr & CPSR_C ? 'C' : '-',
-                     psr & CPSR_V ? 'V' : '-',
-                     psr & CPSR_T ? 'T' : 'A',
-                     ns_status,
-                     aarch32_mode_name(psr), (psr & 0x10) ? 32 : 26);
+        g_string_append_printf(buf, "PSR=%08x %c%c%c%c %c %s%s%d\n",
+                               psr,
+                               psr & CPSR_N ? 'N' : '-',
+                               psr & CPSR_Z ? 'Z' : '-',
+                               psr & CPSR_C ? 'C' : '-',
+                               psr & CPSR_V ? 'V' : '-',
+                               psr & CPSR_T ? 'T' : 'A',
+                               ns_status,
+                               aarch32_mode_name(psr), (psr & 0x10) ? 32 : 26);
     }
 
     if (flags & CPU_DUMP_FPU) {
@@ -1011,14 +1020,15 @@ static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         }
         for (i = 0; i < numvfpregs; i++) {
             uint64_t v = *aa32_vfp_dreg(env, i);
-            qemu_fprintf(f, "s%02d=%08x s%02d=%08x d%02d=%016" PRIx64 "\n",
-                         i * 2, (uint32_t)v,
-                         i * 2 + 1, (uint32_t)(v >> 32),
-                         i, v);
+            g_string_append_printf(buf, "s%02d=%08x s%02d=%08x d%02d=%016"
+                                   PRIx64 "\n",
+                                   i * 2, (uint32_t)v,
+                                   i * 2 + 1, (uint32_t)(v >> 32),
+                                   i, v);
         }
-        qemu_fprintf(f, "FPSCR: %08x\n", vfp_get_fpscr(env));
+        g_string_append_printf(buf, "FPSCR: %08x\n", vfp_get_fpscr(env));
         if (cpu_isar_feature(aa32_mve, cpu)) {
-            qemu_fprintf(f, "VPR: %08x\n", env->v7m.vpr);
+            g_string_append_printf(buf, "VPR: %08x\n", env->v7m.vpr);
         }
     }
 }
@@ -2039,7 +2049,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = arm_cpu_class_by_name;
     cc->has_work = arm_cpu_has_work;
-    cc->dump_state = arm_cpu_dump_state;
+    cc->format_state = arm_cpu_format_state;
     cc->set_pc = arm_cpu_set_pc;
     cc->gdb_read_register = arm_cpu_gdb_read_register;
     cc->gdb_write_register = arm_cpu_gdb_write_register;
Signature · 1 line
2.31.1
#19 lore raw

PATCH v2 9/53 target/avr: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 28 deletions(-)
target/avr/cpu.c +29 -28
index ea14175ca5..17ff21f8be 100644
@@ -145,43 +145,44 @@ static ObjectClass *avr_cpu_class_by_name(const char *cpu_model)
     return oc;
 }
 
-static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static void avr_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     AVRCPU *cpu = AVR_CPU(cs);
     CPUAVRState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "\n");
-    qemu_fprintf(f, "PC:    %06x\n", env->pc_w * 2); /* PC points to words */
-    qemu_fprintf(f, "SP:      %04x\n", env->sp);
-    qemu_fprintf(f, "rampD:     %02x\n", env->rampD >> 16);
-    qemu_fprintf(f, "rampX:     %02x\n", env->rampX >> 16);
-    qemu_fprintf(f, "rampY:     %02x\n", env->rampY >> 16);
-    qemu_fprintf(f, "rampZ:     %02x\n", env->rampZ >> 16);
-    qemu_fprintf(f, "EIND:      %02x\n", env->eind >> 16);
-    qemu_fprintf(f, "X:       %02x%02x\n", env->r[27], env->r[26]);
-    qemu_fprintf(f, "Y:       %02x%02x\n", env->r[29], env->r[28]);
-    qemu_fprintf(f, "Z:       %02x%02x\n", env->r[31], env->r[30]);
-    qemu_fprintf(f, "SREG:    [ %c %c %c %c %c %c %c %c ]\n",
-                 env->sregI ? 'I' : '-',
-                 env->sregT ? 'T' : '-',
-                 env->sregH ? 'H' : '-',
-                 env->sregS ? 'S' : '-',
-                 env->sregV ? 'V' : '-',
-                 env->sregN ? '-' : 'N', /* Zf has negative logic */
-                 env->sregZ ? 'Z' : '-',
-                 env->sregC ? 'I' : '-');
-    qemu_fprintf(f, "SKIP:    %02x\n", env->skip);
-
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
+    /* PC points to words */
+    g_string_append_printf(buf, "PC:    %06x\n", env->pc_w * 2);
+    g_string_append_printf(buf, "SP:      %04x\n", env->sp);
+    g_string_append_printf(buf, "rampD:     %02x\n", env->rampD >> 16);
+    g_string_append_printf(buf, "rampX:     %02x\n", env->rampX >> 16);
+    g_string_append_printf(buf, "rampY:     %02x\n", env->rampY >> 16);
+    g_string_append_printf(buf, "rampZ:     %02x\n", env->rampZ >> 16);
+    g_string_append_printf(buf, "EIND:      %02x\n", env->eind >> 16);
+    g_string_append_printf(buf, "X:       %02x%02x\n", env->r[27], env->r[26]);
+    g_string_append_printf(buf, "Y:       %02x%02x\n", env->r[29], env->r[28]);
+    g_string_append_printf(buf, "Z:       %02x%02x\n", env->r[31], env->r[30]);
+    g_string_append_printf(buf, "SREG:    [ %c %c %c %c %c %c %c %c ]\n",
+                           env->sregI ? 'I' : '-',
+                           env->sregT ? 'T' : '-',
+                           env->sregH ? 'H' : '-',
+                           env->sregS ? 'S' : '-',
+                           env->sregV ? 'V' : '-',
+                           env->sregN ? '-' : 'N', /* Zf has negative logic */
+                           env->sregZ ? 'Z' : '-',
+                           env->sregC ? 'I' : '-');
+    g_string_append_printf(buf, "SKIP:    %02x\n", env->skip);
+
+    g_string_append_printf(buf, "\n");
     for (i = 0; i < ARRAY_SIZE(env->r); i++) {
-        qemu_fprintf(f, "R[%02d]:  %02x   ", i, env->r[i]);
+        g_string_append_printf(buf, "R[%02d]:  %02x   ", i, env->r[i]);
 
         if ((i % 8) == 7) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
 }
 
 #include "hw/core/sysemu-cpu-ops.h"
@@ -215,7 +216,7 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = avr_cpu_class_by_name;
 
     cc->has_work = avr_cpu_has_work;
-    cc->dump_state = avr_cpu_dump_state;
+    cc->format_state = avr_cpu_format_state;
     cc->set_pc = avr_cpu_set_pc;
     cc->memory_rw_debug = avr_cpu_memory_rw_debug;
     dc->vmsd = &vms_avr_cpu;
Signature · 1 line
2.31.1
#23 lore raw

PATCH v2 10/53 target/cris: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/cris/cpu.c       |  2 +-
 target/cris/cpu.h       |  2 +-
 target/cris/translate.c | 33 +++++++++++++++++----------------
 3 files changed, 19 insertions(+), 18 deletions(-)
target/cris/cpu.c +1 -1
index 70932b1f8c..5159cf6528 100644
@@ -295,7 +295,7 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = cris_cpu_class_by_name;
     cc->has_work = cris_cpu_has_work;
-    cc->dump_state = cris_cpu_dump_state;
+    cc->format_state = cris_cpu_format_state;
     cc->set_pc = cris_cpu_set_pc;
     cc->gdb_read_register = cris_cpu_gdb_read_register;
     cc->gdb_write_register = cris_cpu_gdb_write_register;
target/cris/cpu.h +1 -1
index d3b6492909..908cb051da 100644
@@ -191,7 +191,7 @@ void cris_cpu_do_interrupt(CPUState *cpu);
 void crisv10_cpu_do_interrupt(CPUState *cpu);
 bool cris_cpu_exec_interrupt(CPUState *cpu, int int_req);
 
-void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags);
+void cris_cpu_format_state(CPUState *cs, GString *buf, int flags);
 
 hwaddr cris_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 
target/cris/translate.c +17 -16
index a84b753349..6098693186 100644
@@ -3307,7 +3307,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
     translator_loop(&cris_tr_ops, &dc.base, cs, tb, max_insns);
 }
 
-void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void cris_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     CRISCPU *cpu = CRIS_CPU(cs);
     CPUCRISState *env = &cpu->env;
@@ -3326,40 +3326,41 @@ void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         regnames = regnames_v32;
     }
 
-    qemu_fprintf(f, "PC=%x CCS=%x btaken=%d btarget=%x\n"
-                 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
-                 env->pc, env->pregs[PR_CCS], env->btaken, env->btarget,
-                 env->cc_op,
-                 env->cc_src, env->cc_dest, env->cc_result, env->cc_mask);
+    g_string_append_printf(buf, "PC=%x CCS=%x btaken=%d btarget=%x\n"
+                           "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x "
+                           "cc_mask=%x\n",
+                           env->pc, env->pregs[PR_CCS], env->btaken,
+                           env->btarget, env->cc_op, env->cc_src,
+                           env->cc_dest, env->cc_result, env->cc_mask);
 
 
     for (i = 0; i < 16; i++) {
-        qemu_fprintf(f, "%s=%8.8x ", regnames[i], env->regs[i]);
+        g_string_append_printf(buf, "%s=%8.8x ", regnames[i], env->regs[i]);
         if ((i + 1) % 4 == 0) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
-    qemu_fprintf(f, "\nspecial regs:\n");
+    g_string_append_printf(buf, "\nspecial regs:\n");
     for (i = 0; i < 16; i++) {
-        qemu_fprintf(f, "%s=%8.8x ", pregnames[i], env->pregs[i]);
+        g_string_append_printf(buf, "%s=%8.8x ", pregnames[i], env->pregs[i]);
         if ((i + 1) % 4 == 0) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
     if (env->pregs[PR_VR] >= 32) {
         uint32_t srs = env->pregs[PR_SRS];
-        qemu_fprintf(f, "\nsupport function regs bank %x:\n", srs);
+        g_string_append_printf(buf, "\nsupport function regs bank %x:\n", srs);
         if (srs < ARRAY_SIZE(env->sregs)) {
             for (i = 0; i < 16; i++) {
-                qemu_fprintf(f, "s%2.2d=%8.8x ",
-                             i, env->sregs[srs][i]);
+                g_string_append_printf(buf, "s%2.2d=%8.8x ",
+                                       i, env->sregs[srs][i]);
                 if ((i + 1) % 4 == 0) {
-                    qemu_fprintf(f, "\n");
+                    g_string_append_printf(buf, "\n");
                 }
             }
         }
     }
-    qemu_fprintf(f, "\n\n");
+    g_string_append_printf(buf, "\n\n");
 
 }
 
Signature · 1 line
2.31.1
#16 lore raw

PATCH v2 7/53 target/alpha: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/alpha/cpu.c    |  2 +-
 target/alpha/cpu.h    |  2 +-
 target/alpha/helper.c | 28 ++++++++++++++++------------
 3 files changed, 18 insertions(+), 14 deletions(-)
target/alpha/cpu.c +1 -1
index 4871ad0c0a..d0cdda9554 100644
@@ -239,7 +239,7 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = alpha_cpu_class_by_name;
     cc->has_work = alpha_cpu_has_work;
-    cc->dump_state = alpha_cpu_dump_state;
+    cc->format_state = alpha_cpu_format_state;
     cc->set_pc = alpha_cpu_set_pc;
     cc->gdb_read_register = alpha_cpu_gdb_read_register;
     cc->gdb_write_register = alpha_cpu_gdb_write_register;
target/alpha/cpu.h +1 -1
index 82df108967..9e3c80ebcc 100644
@@ -278,7 +278,7 @@ extern const VMStateDescription vmstate_alpha_cpu;
 
 void alpha_cpu_do_interrupt(CPUState *cpu);
 bool alpha_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags);
+void alpha_cpu_format_state(CPUState *cs, GString *buf, int flags);
 hwaddr alpha_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/alpha/helper.c +16 -12
index 4f56fe4d23..6ed80e8a27 100644
@@ -451,7 +451,7 @@ bool alpha_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
     return false;
 }
 
-void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void alpha_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     static const char linux_reg_names[31][4] = {
         "v0",  "t0",  "t1", "t2",  "t3", "t4", "t5", "t6",
@@ -463,25 +463,29 @@ void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     CPUAlphaState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "PC      " TARGET_FMT_lx " PS      %02x\n",
-                 env->pc, extract32(env->flags, ENV_FLAG_PS_SHIFT, 8));
+    g_string_append_printf(buf,
+                           "PC      " TARGET_FMT_lx " PS      %02x\n",
+                           env->pc,
+                           extract32(env->flags, ENV_FLAG_PS_SHIFT, 8));
     for (i = 0; i < 31; i++) {
-        qemu_fprintf(f, "%-8s" TARGET_FMT_lx "%c",
-                     linux_reg_names[i], cpu_alpha_load_gr(env, i),
-                     (i % 3) == 2 ? '\n' : ' ');
+        g_string_append_printf(buf, "%-8s" TARGET_FMT_lx "%c",
+                               linux_reg_names[i], cpu_alpha_load_gr(env, i),
+                               (i % 3) == 2 ? '\n' : ' ');
     }
 
-    qemu_fprintf(f, "lock_a  " TARGET_FMT_lx " lock_v  " TARGET_FMT_lx "\n",
-                 env->lock_addr, env->lock_value);
+    g_string_append_printf(buf, "lock_a  " TARGET_FMT_lx
+                           " lock_v  " TARGET_FMT_lx "\n",
+                           env->lock_addr, env->lock_value);
 
     if (flags & CPU_DUMP_FPU) {
         for (i = 0; i < 31; i++) {
-            qemu_fprintf(f, "f%-7d%016" PRIx64 "%c", i, env->fir[i],
-                         (i % 3) == 2 ? '\n' : ' ');
+            g_string_append_printf(buf, "f%-7d%016" PRIx64 "%c", i, env->fir[i],
+                                   (i % 3) == 2 ? '\n' : ' ');
         }
-        qemu_fprintf(f, "fpcr    %016" PRIx64 "\n", cpu_alpha_load_fpcr(env));
+        g_string_append_printf(buf, "fpcr    %016" PRIx64 "\n",
+                               cpu_alpha_load_fpcr(env));
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
 }
 
 /* This should only be called from translate, via gen_excp.
Signature · 1 line
2.31.1
#25 lore raw

PATCH v2 11/53 target/hexagon: delete unused hexagon_debug() method

In reply to Daniel P. Berrangé

This method isn't used in any code and its functionality is already available via the 'info registers' HMP command.

---
 target/hexagon/cpu.c      | 5 -----
 target/hexagon/internal.h | 1 -
 2 files changed, 6 deletions(-)
target/hexagon/cpu.c +0 -5
index 3338365c16..14c628db7a 100644
@@ -169,11 +169,6 @@ static void hexagon_dump_state(CPUState *cs, FILE *f, int flags)
     hexagon_dump(env, f);
 }
 
-void hexagon_debug(CPUHexagonState *env)
-{
-    hexagon_dump(env, stdout);
-}
-
 static void hexagon_cpu_set_pc(CPUState *cs, vaddr value)
 {
     HexagonCPU *cpu = HEXAGON_CPU(cs);
target/hexagon/internal.h +0 -1
index 6b20affdfa..167e91026a 100644
@@ -31,7 +31,6 @@
 
 int hexagon_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
 int hexagon_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
-void hexagon_debug(CPUHexagonState *env);
 
 extern const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS];
 
Signature · 1 line
2.31.1
#28 lore raw

PATCH v2 12/53 target/hexagon: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/hexagon/cpu.c | 65 ++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 36 deletions(-)
target/hexagon/cpu.c +29 -36
index 14c628db7a..7802186ad7 100644
@@ -98,7 +98,7 @@ static target_ulong read_p3_0(CPUHexagonState *env)
     return control_reg;
 }
 
-static void print_reg(FILE *f, CPUHexagonState *env, int regnum)
+static void format_reg(GString *buf, CPUHexagonState *env, int regnum)
 {
     target_ulong value;
 
@@ -109,13 +109,14 @@ static void print_reg(FILE *f, CPUHexagonState *env, int regnum)
                             : env->gpr[regnum];
     }
 
-    qemu_fprintf(f, "  %s = 0x" TARGET_FMT_lx "\n",
-                 hexagon_regnames[regnum], value);
+    g_string_append_printf(buf, "  %s = 0x" TARGET_FMT_lx "\n",
+                           hexagon_regnames[regnum], value);
 }
 
-static void hexagon_dump(CPUHexagonState *env, FILE *f)
+static void hexagon_format_state(CPUState *cs, GString *buf, int flags)
 {
-    HexagonCPU *cpu = env_archcpu(env);
+    HexagonCPU *cpu = HEXAGON_CPU(cs);
+    CPUHexagonState *env = &cpu->env;
 
     if (cpu->lldb_compat) {
         /*
@@ -128,45 +129,37 @@ static void hexagon_dump(CPUHexagonState *env, FILE *f)
         env->last_pc_dumped = env->gpr[HEX_REG_PC];
     }
 
-    qemu_fprintf(f, "General Purpose Registers = {\n");
+    g_string_append_printf(buf, "General Purpose Registers = {\n");
     for (int i = 0; i < 32; i++) {
-        print_reg(f, env, i);
+        format_reg(buf, env, i);
     }
-    print_reg(f, env, HEX_REG_SA0);
-    print_reg(f, env, HEX_REG_LC0);
-    print_reg(f, env, HEX_REG_SA1);
-    print_reg(f, env, HEX_REG_LC1);
-    print_reg(f, env, HEX_REG_M0);
-    print_reg(f, env, HEX_REG_M1);
-    print_reg(f, env, HEX_REG_USR);
-    print_reg(f, env, HEX_REG_P3_0);
-    print_reg(f, env, HEX_REG_GP);
-    print_reg(f, env, HEX_REG_UGP);
-    print_reg(f, env, HEX_REG_PC);
+    format_reg(buf, env, HEX_REG_SA0);
+    format_reg(buf, env, HEX_REG_LC0);
+    format_reg(buf, env, HEX_REG_SA1);
+    format_reg(buf, env, HEX_REG_LC1);
+    format_reg(buf, env, HEX_REG_M0);
+    format_reg(buf, env, HEX_REG_M1);
+    format_reg(buf, env, HEX_REG_USR);
+    format_reg(buf, env, HEX_REG_P3_0);
+    format_reg(buf, env, HEX_REG_GP);
+    format_reg(buf, env, HEX_REG_UGP);
+    format_reg(buf, env, HEX_REG_PC);
 #ifdef CONFIG_USER_ONLY
     /*
      * Not modelled in user mode, print junk to minimize the diff's
      * with LLDB output
      */
-    qemu_fprintf(f, "  cause = 0x000000db\n");
-    qemu_fprintf(f, "  badva = 0x00000000\n");
-    qemu_fprintf(f, "  cs0 = 0x00000000\n");
-    qemu_fprintf(f, "  cs1 = 0x00000000\n");
+    g_string_append_printf(buf, "  cause = 0x000000db\n");
+    g_string_append_printf(buf, "  badva = 0x00000000\n");
+    g_string_append_printf(buf, "  cs0 = 0x00000000\n");
+    g_string_append_printf(buf, "  cs1 = 0x00000000\n");
 #else
-    print_reg(f, env, HEX_REG_CAUSE);
-    print_reg(f, env, HEX_REG_BADVA);
-    print_reg(f, env, HEX_REG_CS0);
-    print_reg(f, env, HEX_REG_CS1);
+    format_reg(buf, env, HEX_REG_CAUSE);
+    format_reg(buf, env, HEX_REG_BADVA);
+    format_reg(buf, env, HEX_REG_CS0);
+    format_reg(buf, env, HEX_REG_CS1);
 #endif
-    qemu_fprintf(f, "}\n");
-}
-
-static void hexagon_dump_state(CPUState *cs, FILE *f, int flags)
-{
-    HexagonCPU *cpu = HEXAGON_CPU(cs);
-    CPUHexagonState *env = &cpu->env;
-
-    hexagon_dump(env, f);
+    g_string_append_printf(buf, "}\n");
 }
 
 static void hexagon_cpu_set_pc(CPUState *cs, vaddr value)
@@ -283,7 +276,7 @@ static void hexagon_cpu_class_init(ObjectClass *c, void *data)
 
     cc->class_by_name = hexagon_cpu_class_by_name;
     cc->has_work = hexagon_cpu_has_work;
-    cc->dump_state = hexagon_dump_state;
+    cc->format_state = hexagon_format_state;
     cc->set_pc = hexagon_cpu_set_pc;
     cc->gdb_read_register = hexagon_gdb_read_register;
     cc->gdb_write_register = hexagon_gdb_write_register;
Signature · 1 line
2.31.1
#30 lore raw

PATCH v2 13/53 target/hppa: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/hppa/cpu.c    |  2 +-
 target/hppa/cpu.h    |  2 +-
 target/hppa/helper.c | 25 ++++++++++++++-----------
 3 files changed, 16 insertions(+), 13 deletions(-)
target/hppa/cpu.c +1 -1
index 2eace4ee12..f7fe7c49d6 100644
@@ -164,7 +164,7 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = hppa_cpu_class_by_name;
     cc->has_work = hppa_cpu_has_work;
-    cc->dump_state = hppa_cpu_dump_state;
+    cc->format_state = hppa_cpu_format_state;
     cc->set_pc = hppa_cpu_set_pc;
     cc->gdb_read_register = hppa_cpu_gdb_read_register;
     cc->gdb_write_register = hppa_cpu_gdb_write_register;
target/hppa/cpu.h +1 -1
index 748270bfa3..d4f1922545 100644
@@ -327,7 +327,7 @@ 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);
 void hppa_cpu_do_interrupt(CPUState *cpu);
 bool hppa_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void hppa_cpu_dump_state(CPUState *cs, FILE *f, int);
+void hppa_cpu_format_state(CPUState *cs, GString *buf, int);
 bool hppa_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
                        MMUAccessType access_type, int mmu_idx,
                        bool probe, uintptr_t retaddr);
target/hppa/helper.c +14 -11
index 1ccff5765a..6e30d1ea63 100644
@@ -76,7 +76,7 @@ void cpu_hppa_put_psw(CPUHPPAState *env, target_ureg psw)
     }
 }
 
-void hppa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void hppa_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     HPPACPU *cpu = HPPA_CPU(cs);
     CPUHPPAState *env = &cpu->env;
@@ -85,9 +85,10 @@ void hppa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     char psw_c[20];
     int i;
 
-    qemu_fprintf(f, "IA_F " TARGET_FMT_lx " IA_B " TARGET_FMT_lx "\n",
-                 hppa_form_gva_psw(psw, env->iasq_f, env->iaoq_f),
-                 hppa_form_gva_psw(psw, env->iasq_b, env->iaoq_b));
+    g_string_append_printf(buf,
+                           "IA_F " TARGET_FMT_lx " IA_B " TARGET_FMT_lx "\n",
+                           hppa_form_gva_psw(psw, env->iasq_f, env->iaoq_f),
+                           hppa_form_gva_psw(psw, env->iasq_b, env->iaoq_b));
 
     psw_c[0]  = (psw & PSW_W ? 'W' : '-');
     psw_c[1]  = (psw & PSW_E ? 'E' : '-');
@@ -110,20 +111,22 @@ void hppa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     psw_c[18] = '\0';
     psw_cb = ((env->psw_cb >> 4) & 0x01111111) | (env->psw_cb_msb << 28);
 
-    qemu_fprintf(f, "PSW  " TREG_FMT_lx " CB   " TREG_FMT_lx " %s\n",
-                 psw, psw_cb, psw_c);
+    g_string_append_printf(buf,
+                           "PSW  " TREG_FMT_lx " CB   " TREG_FMT_lx " %s\n",
+                           psw, psw_cb, psw_c);
 
     for (i = 0; i < 32; i++) {
-        qemu_fprintf(f, "GR%02d " TREG_FMT_lx "%c", i, env->gr[i],
-                     (i & 3) == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, "GR%02d " TREG_FMT_lx "%c", i, env->gr[i],
+                               (i & 3) == 3 ? '\n' : ' ');
     }
 #ifndef CONFIG_USER_ONLY
     for (i = 0; i < 8; i++) {
-        qemu_fprintf(f, "SR%02d %08x%c", i, (uint32_t)(env->sr[i] >> 32),
-                     (i & 3) == 3 ? '\n' : ' ');
+        g_string_append_printf(buf,
+                               "SR%02d %08x%c", i, (uint32_t)(env->sr[i] >> 32),
+                               (i & 3) == 3 ? '\n' : ' ');
     }
 #endif
-     qemu_fprintf(f, "\n");
+     g_string_append_printf(buf, "\n");
 
     /* ??? FR */
 }
Signature · 1 line
2.31.1
#32 lore raw

PATCH v2 14/53 target/i386: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/i386/cpu-dump.c | 328 ++++++++++++++++++++++-------------------
 target/i386/cpu.c      |   2 +-
 target/i386/cpu.h      |   2 +-
 3 files changed, 177 insertions(+), 155 deletions(-)
target/i386/cpu-dump.c +175 -153
index 02b635a52c..f30fbcb76e 100644
@@ -94,41 +94,46 @@ static const char *cc_op_str[CC_OP_NB] = {
 };
 
 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=%04x %016" PRIx64 " %08x %08x", name,
-                     sc->selector, sc->base, sc->limit,
-                     sc->flags & 0x00ffff00);
+        g_string_append_printf(buf, "%-3s=%04x %016" PRIx64 " %08x %08x", name,
+                               sc->selector, sc->base, sc->limit,
+                               sc->flags & 0x00ffff00);
     } else
 #endif
     {
-        qemu_fprintf(f, "%-3s=%04x %08x %08x %08x", name, sc->selector,
-                     (uint32_t)sc->base, sc->limit,
-                     sc->flags & 0x00ffff00);
+        g_string_append_printf(buf, "%-3s=%04x %08x %08x %08x",
+                               name, sc->selector,
+                               (uint32_t)sc->base, sc->limit,
+                               sc->flags & 0x00ffff00);
     }
 
     if (!(env->hflags & HF_PE_MASK) || !(sc->flags & DESC_P_MASK))
         goto done;
 
-    qemu_fprintf(f, " DPL=%d ",
+    g_string_append_printf(buf, " DPL=%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] = {
             { /* 32 bit mode */
@@ -144,12 +149,14 @@ 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");
 }
 
 #ifndef CONFIG_USER_ONLY
@@ -344,7 +351,7 @@ void x86_cpu_dump_local_apic_state(CPUState *cs, int flags)
 #define DUMP_CODE_BYTES_TOTAL    50
 #define DUMP_CODE_BYTES_BACKWARD 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 = X86_CPU(cs);
     CPUX86State *env = &cpu->env;
@@ -355,107 +362,116 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     eflags = cpu_compute_eflags(env);
 #ifdef TARGET_X86_64
     if (env->hflags & HF_CS64_MASK) {
-        qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" PRIx64 " RDX=%016" PRIx64 "\n"
-                     "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " RSP=%016" PRIx64 "\n"
-                     "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " R11=%016" PRIx64 "\n"
-                     "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " R15=%016" PRIx64 "\n"
-                     "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d A20=%d SMM=%d HLT=%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=%016" PRIx64 " RBX=%016" PRIx64
+                               " RCX=%016" PRIx64 " RDX=%016" PRIx64 "\n"
+                               "RSI=%016" PRIx64 " RDI=%016" PRIx64
+                               " RBP=%016" PRIx64 " RSP=%016" PRIx64 "\n"
+                               "R8 =%016" PRIx64 " R9 =%016" PRIx64
+                               " R10=%016" PRIx64 " R11=%016" PRIx64 "\n"
+                               "R12=%016" PRIx64 " R13=%016" PRIx64
+                               " R14=%016" PRIx64 " R15=%016" PRIx64 "\n"
+                               "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] "
+                               "CPL=%d II=%d A20=%d SMM=%d HLT=%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=%08x EBX=%08x ECX=%08x EDX=%08x\n"
-                     "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
-                     "EIP=%08x EFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d A20=%d SMM=%d HLT=%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=%08x EBX=%08x ECX=%08x EDX=%08x\n"
+                               "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
+                               "EIP=%08x EFL=%08x [%c%c%c%c%c%c%c] "
+                               "CPL=%d II=%d A20=%d SMM=%d HLT=%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);
     }
 
     for(i = 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);
 
 #ifdef TARGET_X86_64
     if (env->hflags & HF_LMA_MASK) {
-        qemu_fprintf(f, "GDT=     %016" PRIx64 " %08x\n",
-                     env->gdt.base, env->gdt.limit);
-        qemu_fprintf(f, "IDT=     %016" PRIx64 " %08x\n",
-                     env->idt.base, env->idt.limit);
-        qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " CR4=%08x\n",
-                     (uint32_t)env->cr[0],
-                     env->cr[2],
-                     env->cr[3],
-                     (uint32_t)env->cr[4]);
+        g_string_append_printf(buf, "GDT=     %016" PRIx64 " %08x\n",
+                               env->gdt.base, env->gdt.limit);
+        g_string_append_printf(buf, "IDT=     %016" PRIx64 " %08x\n",
+                               env->idt.base, env->idt.limit);
+        g_string_append_printf(buf, "CR0=%08x CR2=%016" PRIx64
+                               " CR3=%016" PRIx64 " CR4=%08x\n",
+                               (uint32_t)env->cr[0],
+                               env->cr[2],
+                               env->cr[3],
+                               (uint32_t)env->cr[4]);
         for(i = 0; i < 4; i++)
-            qemu_fprintf(f, "DR%d=%016" PRIx64 " ", i, env->dr[i]);
-        qemu_fprintf(f, "\nDR6=%016" PRIx64 " DR7=%016" PRIx64 "\n",
-                     env->dr[6], env->dr[7]);
+            g_string_append_printf(buf, "DR%d=%016" PRIx64 " ", i, env->dr[i]);
+        g_string_append_printf(buf, "\nDR6=%016" PRIx64 " DR7=%016" PRIx64 "\n",
+                               env->dr[6], env->dr[7]);
     } else
 #endif
     {
-        qemu_fprintf(f, "GDT=     %08x %08x\n",
-                     (uint32_t)env->gdt.base, env->gdt.limit);
-        qemu_fprintf(f, "IDT=     %08x %08x\n",
-                     (uint32_t)env->idt.base, env->idt.limit);
-        qemu_fprintf(f, "CR0=%08x CR2=%08x CR3=%08x CR4=%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=     %08x %08x\n",
+                               (uint32_t)env->gdt.base, env->gdt.limit);
+        g_string_append_printf(buf, "IDT=     %08x %08x\n",
+                               (uint32_t)env->idt.base, env->idt.limit);
+        g_string_append_printf(buf, "CR0=%08x CR2=%08x CR3=%08x CR4=%08x\n",
+                               (uint32_t)env->cr[0],
+                               (uint32_t)env->cr[2],
+                               (uint32_t)env->cr[3],
+                               (uint32_t)env->cr[4]);
         for(i = 0; i < 4; i++) {
-            qemu_fprintf(f, "DR%d=" TARGET_FMT_lx " ", i, env->dr[i]);
+            g_string_append_printf(buf, "DR%d=" TARGET_FMT_lx
+                                   " ", i, env->dr[i]);
         }
-        qemu_fprintf(f, "\nDR6=" TARGET_FMT_lx " DR7=" TARGET_FMT_lx "\n",
-                     env->dr[6], env->dr[7]);
+        g_string_append_printf(buf, "\nDR6=" TARGET_FMT_lx
+                               " DR7=" 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 +480,19 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)
             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=%016" PRIx64 " CCD=%016" PRIx64 " CCO=%-8s\n",
-                         env->cc_src, env->cc_dst,
-                         cc_op_name);
+            g_string_append_printf(buf, "CCS=%016" PRIx64
+                                   " CCD=%016" PRIx64 " CCO=%-8s\n",
+                                   env->cc_src, env->cc_dst,
+                                   cc_op_name);
         } else
 #endif
         {
-            qemu_fprintf(f, "CCS=%08x CCD=%08x CCO=%-8s\n",
-                         (uint32_t)env->cc_src, (uint32_t)env->cc_dst,
-                         cc_op_name);
+            g_string_append_printf(buf, "CCS=%08x CCD=%08x CCO=%-8s\n",
+                                   (uint32_t)env->cc_src, (uint32_t)env->cc_dst,
+                                   cc_op_name);
         }
     }
-    qemu_fprintf(f, "EFER=%016" PRIx64 "\n", env->efer);
+    g_string_append_printf(buf, "EFER=%016" PRIx64 "\n", env->efer);
     if (flags & CPU_DUMP_FPU) {
         int fptag;
         const uint64_t avx512_mask = XSTATE_OPMASK_MASK | \
@@ -488,64 +505,68 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)
             fptag |= ((!env->fptags[i]) << i);
         }
         update_mxcsr_from_sse_status(env);
-        qemu_fprintf(f, "FCW=%04x FSW=%04x [ST=%d] FTW=%02x MXCSR=%08x\n",
-                     env->fpuc,
-                     (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11,
-                     env->fpstt,
-                     fptag,
-                     env->mxcsr);
+        g_string_append_printf(
+            buf, "FCW=%04x FSW=%04x [ST=%d] FTW=%02x MXCSR=%08x\n",
+            env->fpuc,
+            (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11,
+            env->fpstt,
+            fptag,
+            env->mxcsr);
         for(i=0;i<8;i++) {
             CPU_LDoubleU u;
             u.d = env->fpregs[i].d;
-            qemu_fprintf(f, "FPR%d=%016" PRIx64 " %04x",
-                         i, u.l.lower, u.l.upper);
+            g_string_append_printf(buf, "FPR%d=%016" PRIx64 " %04x",
+                                   i, u.l.lower, u.l.upper);
             if ((i & 1) == 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) == avx512_mask) {
             /* XSAVE enabled AVX512 */
             for (i = 0; i < NB_OPMASK_REGS; i++) {
-                qemu_fprintf(f, "Opmask%02d=%016"PRIx64"%s", i,
-                             env->opmask_regs[i], ((i & 3) == 3) ? "\n" : " ");
+                g_string_append_printf(buf, "Opmask%02d=%016"PRIx64"%s", i,
+                                       env->opmask_regs[i],
+                                       ((i & 3) == 3) ? "\n" : " ");
             }
 
             nb = (env->hflags & HF_CS64_MASK) ? 32 : 8;
             for (i = 0; i < nb; i++) {
-                qemu_fprintf(f, "ZMM%02d=%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=%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));
             }
         } else if ((env->xcr0 & avx_mask)  == avx_mask) {
             /* XSAVE enabled AVX */
             nb = env->hflags & HF_CS64_MASK ? 16 : 8;
             for (i = 0; i < nb; i++) {
-                qemu_fprintf(f, "YMM%02d=%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=%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 = env->hflags & HF_CS64_MASK ? 16 : 8;
             for (i = 0; i < nb; i++) {
-                qemu_fprintf(f, "XMM%02d=%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=%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 +576,17 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         uint8_t code;
         char codestr[3];
 
-        qemu_fprintf(f, "Code=");
+        g_string_append_printf(buf, "Code=");
         for (i = 0; i < DUMP_CODE_BYTES_TOTAL; i++) {
             if (cpu_memory_rw_debug(cs, base - offs + i, &code, 1, 0) == 0) {
                 snprintf(codestr, sizeof(codestr), "%02x", code);
             } else {
                 snprintf(codestr, sizeof(codestr), "??");
             }
-            qemu_fprintf(f, "%s%s%s%s", i > 0 ? " " : "",
-                         i == offs ? "<" : "", codestr, i == offs ? ">" : "");
+            g_string_append_printf(buf, "%s%s%s%s", i > 0 ? " " : "",
+                                   i == offs ? "<" : "", codestr,
+                                   i == offs ? ">" : "");
         }
-        qemu_fprintf(f, "\n");
+        g_string_append_printf(buf, "\n");
     }
 }
target/i386/cpu.c +1 -1
index 6b029f1bdf..0a5c6a6d19 100644
@@ -6764,7 +6764,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = x86_cpu_class_by_name;
     cc->parse_features = x86_cpu_parse_featurestr;
     cc->has_work = x86_cpu_has_work;
-    cc->dump_state = x86_cpu_dump_state;
+    cc->format_state = x86_cpu_format_state;
     cc->set_pc = x86_cpu_set_pc;
     cc->gdb_read_register = x86_cpu_gdb_read_register;
     cc->gdb_write_register = x86_cpu_gdb_write_register;
target/i386/cpu.h +1 -1
index 71ae3141c3..d87c8808f6 100644
@@ -1825,7 +1825,7 @@ int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
 void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
                                 Error **errp);
 
-void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags);
+void x86_cpu_format_state(CPUState *cs, GString *buf, int flags);
 
 hwaddr x86_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
                                          MemTxAttrs *attrs);
Signature · 1 line
2.31.1
#33 lore raw

PATCH v2 15/53 target/m68k: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/m68k/cpu.c       |  2 +-
 target/m68k/cpu.h       |  2 +-
 target/m68k/translate.c | 92 ++++++++++++++++++++++-------------------
 3 files changed, 51 insertions(+), 45 deletions(-)
target/m68k/cpu.c +1 -1
index 72de6e9726..4ccf572a68 100644
@@ -536,7 +536,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
 
     cc->class_by_name = m68k_cpu_class_by_name;
     cc->has_work = m68k_cpu_has_work;
-    cc->dump_state = m68k_cpu_dump_state;
+    cc->format_state = m68k_cpu_format_state;
     cc->set_pc = m68k_cpu_set_pc;
     cc->gdb_read_register = m68k_cpu_gdb_read_register;
     cc->gdb_write_register = m68k_cpu_gdb_write_register;
target/m68k/cpu.h +1 -1
index 997d588911..b0641f6d0d 100644
@@ -168,7 +168,7 @@ struct M68kCPU {
 
 void m68k_cpu_do_interrupt(CPUState *cpu);
 bool m68k_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void m68k_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void m68k_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr m68k_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/m68k/translate.c +49 -43

124 lines not on this page · raw message

Signature · 1 line
2.31.1
#36 lore raw

PATCH v2 16/53 target/microblaze: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/microblaze/cpu.c       |  2 +-
 target/microblaze/cpu.h       |  2 +-
 target/microblaze/translate.c | 45 ++++++++++++++++++-----------------
 3 files changed, 25 insertions(+), 24 deletions(-)
target/microblaze/cpu.c +1 -1
index 72d8f2a0da..539b8964bd 100644
@@ -388,7 +388,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = mb_cpu_class_by_name;
     cc->has_work = mb_cpu_has_work;
 
-    cc->dump_state = mb_cpu_dump_state;
+    cc->format_state = mb_cpu_format_state;
     cc->set_pc = mb_cpu_set_pc;
     cc->gdb_read_register = mb_cpu_gdb_read_register;
     cc->gdb_write_register = mb_cpu_gdb_write_register;
target/microblaze/cpu.h +1 -1
index e4bba8a755..3e90970068 100644
@@ -360,7 +360,7 @@ bool mb_cpu_exec_interrupt(CPUState *cs, int int_req);
 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);
+void mb_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr mb_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
                                         MemTxAttrs *attrs);
 int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
target/microblaze/translate.c +23 -22

77 lines not on this page · raw message

Signature · 1 line
2.31.1
#40 lore raw

PATCH v2 17/53 target/mips: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/mips/cpu.c | 85 +++++++++++++++++++++++++----------------------
 1 file changed, 45 insertions(+), 40 deletions(-)
target/mips/cpu.c +45 -40
index d426918291..9ced90d810 100644
@@ -42,76 +42,81 @@ const char regnames[32][3] = {
     "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
 };
 
-static void fpu_dump_fpr(fpr_t *fpr, FILE *f, bool is_fpu64)
+static void fpu_dump_fpr(fpr_t *fpr, GString *buf, bool is_fpu64)
 {
     if (is_fpu64) {
-        qemu_fprintf(f, "w:%08x d:%016" PRIx64 " fd:%13g fs:%13g psu: %13g\n",
-                     fpr->w[FP_ENDIAN_IDX], fpr->d,
-                     (double)fpr->fd,
-                     (double)fpr->fs[FP_ENDIAN_IDX],
-                     (double)fpr->fs[!FP_ENDIAN_IDX]);
+        g_string_append_printf(buf, "w:%08x d:%016" PRIx64
+                               " fd:%13g fs:%13g psu: %13g\n",
+                               fpr->w[FP_ENDIAN_IDX], fpr->d,
+                               (double)fpr->fd,
+                               (double)fpr->fs[FP_ENDIAN_IDX],
+                               (double)fpr->fs[!FP_ENDIAN_IDX]);
     } else {
         fpr_t tmp;
 
         tmp.w[FP_ENDIAN_IDX] = fpr->w[FP_ENDIAN_IDX];
         tmp.w[!FP_ENDIAN_IDX] = (fpr + 1)->w[FP_ENDIAN_IDX];
-        qemu_fprintf(f, "w:%08x d:%016" PRIx64 " fd:%13g fs:%13g psu:%13g\n",
-                     tmp.w[FP_ENDIAN_IDX], tmp.d,
-                     (double)tmp.fd,
-                     (double)tmp.fs[FP_ENDIAN_IDX],
-                     (double)tmp.fs[!FP_ENDIAN_IDX]);
+        g_string_append_printf(buf, "w:%08x d:%016" PRIx64
+                               " fd:%13g fs:%13g psu:%13g\n",
+                               tmp.w[FP_ENDIAN_IDX], tmp.d,
+                               (double)tmp.fd,
+                               (double)tmp.fs[FP_ENDIAN_IDX],
+                               (double)tmp.fs[!FP_ENDIAN_IDX]);
     }
 }
 
-static void fpu_dump_state(CPUMIPSState *env, FILE *f, int flags)
+static void fpu_format_state(CPUMIPSState *env, GString *buf, int flags)
 {
     int i;
     bool is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
 
-    qemu_fprintf(f,
-                 "CP1 FCR0 0x%08x  FCR31 0x%08x  SR.FR %d  fp_status 0x%02x\n",
-                 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64,
-                 get_float_exception_flags(&env->active_fpu.fp_status));
+    g_string_append_printf(buf,
+                           "CP1 FCR0 0x%08x  FCR31 0x%08x  SR.FR %d "
+                           " fp_status 0x%02x\n",
+                           env->active_fpu.fcr0, env->active_fpu.fcr31,
+                           is_fpu64, get_float_exception_flags(
+                               &env->active_fpu.fp_status));
     for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
-        qemu_fprintf(f, "%3s: ", fregnames[i]);
-        fpu_dump_fpr(&env->active_fpu.fpr[i], f, is_fpu64);
+        g_string_append_printf(buf, "%3s: ", fregnames[i]);
+        fpu_dump_fpr(&env->active_fpu.fpr[i], buf, is_fpu64);
     }
 }
 
-static void mips_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static void mips_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     MIPSCPU *cpu = MIPS_CPU(cs);
     CPUMIPSState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx
-                 " LO=0x" TARGET_FMT_lx " ds %04x "
-                 TARGET_FMT_lx " " TARGET_FMT_ld "\n",
-                 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
-                 env->hflags, env->btarget, env->bcond);
+    g_string_append_printf(buf, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx
+                           " LO=0x" TARGET_FMT_lx " ds %04x "
+                           TARGET_FMT_lx " " TARGET_FMT_ld "\n",
+                           env->active_tc.PC, env->active_tc.HI[0],
+                           env->active_tc.LO[0],
+                           env->hflags, env->btarget, env->bcond);
     for (i = 0; i < 32; i++) {
         if ((i & 3) == 0) {
-            qemu_fprintf(f, "GPR%02d:", i);
+            g_string_append_printf(buf, "GPR%02d:", i);
         }
-        qemu_fprintf(f, " %s " TARGET_FMT_lx,
-                     regnames[i], env->active_tc.gpr[i]);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx,
+                               regnames[i], env->active_tc.gpr[i]);
         if ((i & 3) == 3) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
 
-    qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC    0x"
-                 TARGET_FMT_lx "\n",
-                 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
-    qemu_fprintf(f, "    Config0 0x%08x Config1 0x%08x LLAddr 0x%016"
-                 PRIx64 "\n",
-                 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
-    qemu_fprintf(f, "    Config2 0x%08x Config3 0x%08x\n",
-                 env->CP0_Config2, env->CP0_Config3);
-    qemu_fprintf(f, "    Config4 0x%08x Config5 0x%08x\n",
-                 env->CP0_Config4, env->CP0_Config5);
+    g_string_append_printf(buf, "CP0 Status  0x%08x Cause   0x%08x EPC    0x"
+                           TARGET_FMT_lx "\n",
+                           env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
+    g_string_append_printf(buf, "    Config0 0x%08x Config1 0x%08x LLAddr "
+                           "0x%016" PRIx64 "\n",
+                           env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
+    g_string_append_printf(buf, "    Config2 0x%08x Config3 0x%08x\n",
+                           env->CP0_Config2, env->CP0_Config3);
+    g_string_append_printf(buf, "    Config4 0x%08x Config5 0x%08x\n",
+                           env->CP0_Config4, env->CP0_Config5);
     if ((flags & CPU_DUMP_FPU) && (env->hflags & MIPS_HFLAG_FPU)) {
-        fpu_dump_state(env, f, flags);
+        fpu_format_state(env, buf, flags);
     }
 }
 
@@ -564,7 +569,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data)
 
     cc->class_by_name = mips_cpu_class_by_name;
     cc->has_work = mips_cpu_has_work;
-    cc->dump_state = mips_cpu_dump_state;
+    cc->format_state = mips_cpu_format_state;
     cc->set_pc = mips_cpu_set_pc;
     cc->gdb_read_register = mips_cpu_gdb_read_register;
     cc->gdb_write_register = mips_cpu_gdb_write_register;
Signature · 1 line
2.31.1
#42 lore raw

PATCH v2 18/53 target/nios2: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/nios2/cpu.c       |  2 +-
 target/nios2/cpu.h       |  2 +-
 target/nios2/translate.c | 20 ++++++++++----------
 3 files changed, 12 insertions(+), 12 deletions(-)
target/nios2/cpu.c +1 -1
index 5e37defef8..cbf15fb1c9 100644
@@ -241,7 +241,7 @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = nios2_cpu_class_by_name;
     cc->has_work = nios2_cpu_has_work;
-    cc->dump_state = nios2_cpu_dump_state;
+    cc->format_state = nios2_cpu_format_state;
     cc->set_pc = nios2_cpu_set_pc;
     cc->disas_set_info = nios2_cpu_disas_set_info;
 #ifndef CONFIG_USER_ONLY
target/nios2/cpu.h +1 -1
index 2ab82fdc71..3b16cd1f3c 100644
@@ -195,7 +195,7 @@ void nios2_tcg_init(void);
 void nios2_cpu_do_interrupt(CPUState *cs);
 int cpu_nios2_signal_handler(int host_signum, void *pinfo, void *puc);
 void dump_mmu(CPUNios2State *env);
-void nios2_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void nios2_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr nios2_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 void nios2_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
                                    MMUAccessType access_type,
target/nios2/translate.c +10 -10
index 08d7ac5398..a5f0f56e1a 100644
@@ -855,7 +855,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
     translator_loop(&nios2_tr_ops, &dc.base, cs, tb, max_insns);
 }
 
-void nios2_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void nios2_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     Nios2CPU *cpu = NIOS2_CPU(cs);
     CPUNios2State *env = &cpu->env;
@@ -865,22 +865,22 @@ void nios2_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         return;
     }
 
-    qemu_fprintf(f, "IN: PC=%x %s\n",
-                 env->regs[R_PC], lookup_symbol(env->regs[R_PC]));
+    g_string_append_printf(buf, "IN: PC=%x %s\n",
+                           env->regs[R_PC], lookup_symbol(env->regs[R_PC]));
 
     for (i = 0; i < NUM_CORE_REGS; i++) {
-        qemu_fprintf(f, "%9s=%8.8x ", regnames[i], env->regs[i]);
+        g_string_append_printf(buf, "%9s=%8.8x ", regnames[i], env->regs[i]);
         if ((i + 1) % 4 == 0) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
 #if !defined(CONFIG_USER_ONLY)
-    qemu_fprintf(f, " mmu write: VPN=%05X PID %02X TLBACC %08X\n",
-                 env->mmu.pteaddr_wr & CR_PTEADDR_VPN_MASK,
-                 (env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK) >> 4,
-                 env->mmu.tlbacc_wr);
+    g_string_append_printf(buf, " mmu write: VPN=%05X PID %02X TLBACC %08X\n",
+                           env->mmu.pteaddr_wr & CR_PTEADDR_VPN_MASK,
+                           (env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK) >> 4,
+                           env->mmu.tlbacc_wr);
 #endif
-    qemu_fprintf(f, "\n\n");
+    g_string_append_printf(buf, "\n\n");
 }
 
 void nios2_tcg_init(void)
Signature · 1 line
2.31.1
#44 lore raw

PATCH v2 19/53 target/openrisc: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/openrisc/cpu.c       | 2 +-
 target/openrisc/cpu.h       | 2 +-
 target/openrisc/translate.c | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
target/openrisc/cpu.c +1 -1
index bd34e429ec..d60d248958 100644
@@ -206,7 +206,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = openrisc_cpu_class_by_name;
     cc->has_work = openrisc_cpu_has_work;
-    cc->dump_state = openrisc_cpu_dump_state;
+    cc->format_state = openrisc_cpu_format_state;
     cc->set_pc = openrisc_cpu_set_pc;
     cc->gdb_read_register = openrisc_cpu_gdb_read_register;
     cc->gdb_write_register = openrisc_cpu_gdb_write_register;
target/openrisc/cpu.h +1 -1
index 82cbaeb4f8..112b845b10 100644
@@ -314,7 +314,7 @@ struct OpenRISCCPU {
 void cpu_openrisc_list(void);
 void openrisc_cpu_do_interrupt(CPUState *cpu);
 bool openrisc_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void openrisc_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void openrisc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/openrisc/translate.c +4 -4
index d6ea536744..0155f2b160 100644
@@ -1723,16 +1723,16 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
     translator_loop(&openrisc_tr_ops, &ctx.base, cs, tb, max_insns);
 }
 
-void openrisc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void openrisc_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     OpenRISCCPU *cpu = OPENRISC_CPU(cs);
     CPUOpenRISCState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "PC=%08x\n", env->pc);
+    g_string_append_printf(buf, "PC=%08x\n", env->pc);
     for (i = 0; i < 32; ++i) {
-        qemu_fprintf(f, "R%02d=%08x%c", i, cpu_get_gpr(env, i),
-                     (i % 4) == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, "R%02d=%08x%c", i, cpu_get_gpr(env, i),
+                               (i % 4) == 3 ? '\n' : ' ');
     }
 }
 
Signature · 1 line
2.31.1
#46 lore raw

PATCH v2 20/53 target/ppc: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/ppc/cpu.h      |   2 +-
 target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
 2 files changed, 126 insertions(+), 88 deletions(-)
target/ppc/cpu.h +1 -1
index 500205229c..c84ae29b98 100644
@@ -1256,7 +1256,7 @@ DECLARE_OBJ_CHECKERS(PPCVirtualHypervisor, PPCVirtualHypervisorClass,
 
 void ppc_cpu_do_interrupt(CPUState *cpu);
 bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void ppc_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void ppc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/ppc/cpu_init.c +125 -87

294 lines not on this page · raw message

Signature · 1 line
2.31.1
#49 lore raw

PATCH v2 21/53 target/riscv: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/riscv/cpu.c | 105 ++++++++++++++++++++++++++++-----------------
 1 file changed, 66 insertions(+), 39 deletions(-)
target/riscv/cpu.c +66 -39
index 1a2b03d579..7a9e013e32 100644
@@ -242,7 +242,7 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model)
     return oc;
 }
 
-static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static void riscv_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     RISCVCPU *cpu = RISCV_CPU(cs);
     CPURISCVState *env = &cpu->env;
@@ -250,71 +250,98 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
 
 #if !defined(CONFIG_USER_ONLY)
     if (riscv_has_ext(env, RVH)) {
-        qemu_fprintf(f, " %s %d\n", "V      =  ", riscv_cpu_virt_enabled(env));
+        g_string_append_printf(buf, " %s %d\n", "V      =  ",
+                               riscv_cpu_virt_enabled(env));
     }
 #endif
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "pc      ", env->pc);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "pc      ", env->pc);
 #ifndef CONFIG_USER_ONLY
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mhartid ", env->mhartid);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatus ", (target_ulong)env->mstatus);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mhartid ", env->mhartid);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mstatus ", (target_ulong)env->mstatus);
     if (riscv_cpu_is_32bit(env)) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatush ",
-                     (target_ulong)(env->mstatus >> 32));
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n", "mstatush ",
+                               (target_ulong)(env->mstatus >> 32));
     }
     if (riscv_has_ext(env, RVH)) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hstatus ", env->hstatus);
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus ",
-                     (target_ulong)env->vsstatus);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "hstatus ", env->hstatus);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "vsstatus ", (target_ulong)env->vsstatus);
     }
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mip     ", env->mip);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mie     ", env->mie);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mideleg ", env->mideleg);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mip     ", env->mip);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mie     ", env->mie);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mideleg ", env->mideleg);
     if (riscv_has_ext(env, RVH)) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hideleg ", env->hideleg);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "hideleg ", env->hideleg);
     }
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "medeleg ", env->medeleg);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "medeleg ", env->medeleg);
     if (riscv_has_ext(env, RVH)) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hedeleg ", env->hedeleg);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "hedeleg ", env->hedeleg);
     }
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtvec   ", env->mtvec);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stvec   ", env->stvec);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mtvec   ", env->mtvec);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "stvec   ", env->stvec);
     if (riscv_has_ext(env, RVH)) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vstvec  ", env->vstvec);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "vstvec  ", env->vstvec);
     }
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mepc    ", env->mepc);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "sepc    ", env->sepc);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mepc    ", env->mepc);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "sepc    ", env->sepc);
     if (riscv_has_ext(env, RVH)) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsepc   ", env->vsepc);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "vsepc   ", env->vsepc);
     }
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mcause  ", env->mcause);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "scause  ", env->scause);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mcause  ", env->mcause);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "scause  ", env->scause);
     if (riscv_has_ext(env, RVH)) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vscause ", env->vscause);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "vscause ", env->vscause);
     }
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval   ", env->mtval);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval   ", env->stval);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mtval   ", env->mtval);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "stval   ", env->stval);
     if (riscv_has_ext(env, RVH)) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval);
-        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "htval ", env->htval);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                               "mtval2 ", env->mtval2);
     }
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mscratch", env->mscratch);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "sscratch", env->sscratch);
-    qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "satp    ", env->satp);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "mscratch", env->mscratch);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "sscratch", env->sscratch);
+    g_string_append_printf(buf, " %s " TARGET_FMT_lx "\n",
+                           "satp    ", env->satp);
 #endif
 
     for (i = 0; i < 32; i++) {
-        qemu_fprintf(f, " %s " TARGET_FMT_lx,
-                     riscv_int_regnames[i], env->gpr[i]);
+        g_string_append_printf(buf, " %s " TARGET_FMT_lx,
+                               riscv_int_regnames[i], env->gpr[i]);
         if ((i & 3) == 3) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
     if (flags & CPU_DUMP_FPU) {
         for (i = 0; i < 32; i++) {
-            qemu_fprintf(f, " %s %016" PRIx64,
-                         riscv_fpr_regnames[i], env->fpr[i]);
+            g_string_append_printf(buf, " %s %016" PRIx64,
+                                   riscv_fpr_regnames[i], env->fpr[i]);
             if ((i & 3) == 3) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");
             }
         }
     }
@@ -667,7 +694,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
 
     cc->class_by_name = riscv_cpu_class_by_name;
     cc->has_work = riscv_cpu_has_work;
-    cc->dump_state = riscv_cpu_dump_state;
+    cc->format_state = riscv_cpu_format_state;
     cc->set_pc = riscv_cpu_set_pc;
     cc->gdb_read_register = riscv_cpu_gdb_read_register;
     cc->gdb_write_register = riscv_cpu_gdb_write_register;
Signature · 1 line
2.31.1
#50 lore raw

PATCH v2 22/53 target/rx: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/rx/cpu.c       |  2 +-
 target/rx/cpu.h       |  2 +-
 target/rx/translate.c | 14 ++++++++------
 3 files changed, 10 insertions(+), 8 deletions(-)
target/rx/cpu.c +1 -1
index 96cc96e514..f7f158cfa5 100644
@@ -207,7 +207,7 @@ static void rx_cpu_class_init(ObjectClass *klass, void *data)
 
     cc->class_by_name = rx_cpu_class_by_name;
     cc->has_work = rx_cpu_has_work;
-    cc->dump_state = rx_cpu_dump_state;
+    cc->format_state = rx_cpu_format_state;
     cc->set_pc = rx_cpu_set_pc;
 
 #ifndef CONFIG_USER_ONLY
target/rx/cpu.h +1 -1
index 0b4b998c7b..97fc1b9ed6 100644
@@ -126,7 +126,7 @@ typedef RXCPU ArchCPU;
 const char *rx_crname(uint8_t cr);
 void rx_cpu_do_interrupt(CPUState *cpu);
 bool rx_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void rx_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void rx_cpu_format_state(CPUState *cpu, GString *buf, 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);
 hwaddr rx_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
target/rx/translate.c +8 -6
index a3cf720455..2d3bdabce4 100644
@@ -125,7 +125,7 @@ static int bdsp_s(DisasContext *ctx, int d)
 /* Include the auto-generated decoder. */
 #include "decode-insns.c.inc"
 
-void rx_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void rx_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     RXCPU *cpu = RX_CPU(cs);
     CPURXState *env = &cpu->env;
@@ -133,12 +133,14 @@ void rx_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     uint32_t psw;
 
     psw = rx_cpu_pack_psw(env);
-    qemu_fprintf(f, "pc=0x%08x psw=0x%08x\n",
-                 env->pc, psw);
+    g_string_append_printf(buf, "pc=0x%08x psw=0x%08x\n",
+                           env->pc, psw);
     for (i = 0; i < 16; i += 4) {
-        qemu_fprintf(f, "r%d=0x%08x r%d=0x%08x r%d=0x%08x r%d=0x%08x\n",
-                     i, env->regs[i], i + 1, env->regs[i + 1],
-                     i + 2, env->regs[i + 2], i + 3, env->regs[i + 3]);
+        g_string_append_printf(buf,
+                               "r%d=0x%08x r%d=0x%08x r%d=0x%08x r%d=0x%08x\n",
+                               i, env->regs[i], i + 1, env->regs[i + 1],
+                               i + 2, env->regs[i + 2], i + 3,
+                               env->regs[i + 3]);
     }
 }
 
Signature · 1 line
2.31.1
#52 lore raw

PATCH v2 23/53 target/s390x: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/s390x/cpu-dump.c       | 43 ++++++++++++++++++-----------------
 target/s390x/cpu.c            |  2 +-
 target/s390x/s390x-internal.h |  2 +-
 3 files changed, 24 insertions(+), 23 deletions(-)
target/s390x/cpu-dump.c +22 -21
index 0f5c062994..9c6eaa9938 100644
@@ -25,66 +25,67 @@
 #include "qemu/qemu-print.h"
 #include "sysemu/tcg.h"
 
-void s390_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void s390_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     S390CPU *cpu = S390_CPU(cs);
     CPUS390XState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64,
-                 s390_cpu_get_psw_mask(env), env->psw.addr);
+    g_string_append_printf(buf, "PSW=mask %016" PRIx64 " addr %016" PRIx64,
+                           s390_cpu_get_psw_mask(env), env->psw.addr);
     if (!tcg_enabled()) {
-        qemu_fprintf(f, "\n");
+        g_string_append_printf(buf, "\n");
     } else if (env->cc_op > 3) {
-        qemu_fprintf(f, " cc %15s\n", cc_name(env->cc_op));
+        g_string_append_printf(buf, " cc %15s\n", cc_name(env->cc_op));
     } else {
-        qemu_fprintf(f, " cc %02x\n", env->cc_op);
+        g_string_append_printf(buf, " cc %02x\n", env->cc_op);
     }
 
     for (i = 0; i < 16; i++) {
-        qemu_fprintf(f, "R%02d=%016" PRIx64, i, env->regs[i]);
+        g_string_append_printf(buf, "R%02d=%016" PRIx64, i, env->regs[i]);
         if ((i % 4) == 3) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         } else {
-            qemu_fprintf(f, " ");
+            g_string_append_printf(buf, " ");
         }
     }
 
     if (flags & CPU_DUMP_FPU) {
         if (s390_has_feat(S390_FEAT_VECTOR)) {
             for (i = 0; i < 32; i++) {
-                qemu_fprintf(f, "V%02d=%016" PRIx64 "%016" PRIx64 "%c",
-                             i, env->vregs[i][0], env->vregs[i][1],
-                             i % 2 ? '\n' : ' ');
+                g_string_append_printf(buf,
+                                       "V%02d=%016" PRIx64 "%016" PRIx64 "%c",
+                                       i, env->vregs[i][0], env->vregs[i][1],
+                                       i % 2 ? '\n' : ' ');
             }
         } else {
             for (i = 0; i < 16; i++) {
-                qemu_fprintf(f, "F%02d=%016" PRIx64 "%c",
-                             i, *get_freg(env, i),
-                             (i % 4) == 3 ? '\n' : ' ');
+                g_string_append_printf(buf, "F%02d=%016" PRIx64 "%c",
+                                       i, *get_freg(env, i),
+                                       (i % 4) == 3 ? '\n' : ' ');
             }
         }
     }
 
 #ifndef CONFIG_USER_ONLY
     for (i = 0; i < 16; i++) {
-        qemu_fprintf(f, "C%02d=%016" PRIx64, i, env->cregs[i]);
+        g_string_append_printf(buf, "C%02d=%016" PRIx64, i, env->cregs[i]);
         if ((i % 4) == 3) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         } else {
-            qemu_fprintf(f, " ");
+            g_string_append_printf(buf, " ");
         }
     }
 #endif
 
 #ifdef DEBUG_INLINE_BRANCHES
     for (i = 0; i < CC_OP_MAX; i++) {
-        qemu_fprintf(f, "  %15s = %10ld\t%10ld\n", cc_name(i),
-                     inline_branch_miss[i], inline_branch_hit[i]);
+        g_string_append_printf(buf, "  %15s = %10ld\t%10ld\n", cc_name(i),
+                               inline_branch_miss[i], inline_branch_hit[i]);
     }
 #endif
 
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
 }
 
 const char *cc_name(enum cc_op cc_op)
target/s390x/cpu.c +1 -1
index 7b7b05f1d3..b6bf628074 100644
@@ -293,7 +293,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
     scc->reset = s390_cpu_reset;
     cc->class_by_name = s390_cpu_class_by_name,
     cc->has_work = s390_cpu_has_work;
-    cc->dump_state = s390_cpu_dump_state;
+    cc->format_state = s390_cpu_format_state;
     cc->set_pc = s390_cpu_set_pc;
     cc->gdb_read_register = s390_cpu_gdb_read_register;
     cc->gdb_write_register = s390_cpu_gdb_write_register;
target/s390x/s390x-internal.h +1 -1
index 7a6aa4dacc..0ee99b8b1e 100644
@@ -313,7 +313,7 @@ void s390_cpu_gdb_init(CPUState *cs);
 
 
 /* helper.c */
-void s390_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void s390_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 void do_restart_interrupt(CPUS390XState *env);
 #ifndef CONFIG_USER_ONLY
 void s390_cpu_recompute_watchpoints(CPUState *cs);
Signature · 1 line
2.31.1
#53 lore raw

PATCH v2 24/53 target/sh: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/sh4/cpu.c       |  2 +-
 target/sh4/cpu.h       |  2 +-
 target/sh4/translate.c | 36 ++++++++++++++++++++----------------
 3 files changed, 22 insertions(+), 18 deletions(-)
target/sh4/cpu.c +1 -1
index 8326922942..0ac881d6af 100644
@@ -259,7 +259,7 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = superh_cpu_class_by_name;
     cc->has_work = superh_cpu_has_work;
-    cc->dump_state = superh_cpu_dump_state;
+    cc->format_state = superh_cpu_format_state;
     cc->set_pc = superh_cpu_set_pc;
     cc->gdb_read_register = superh_cpu_gdb_read_register;
     cc->gdb_write_register = superh_cpu_gdb_write_register;
target/sh4/cpu.h +1 -1
index 01c4344082..6940ca417a 100644
@@ -206,7 +206,7 @@ struct SuperHCPU {
 
 void superh_cpu_do_interrupt(CPUState *cpu);
 bool superh_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void superh_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void superh_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr superh_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/sh4/translate.c +20 -16
index 8704fea1ca..f6fd8939b0 100644
@@ -156,32 +156,36 @@ void sh4_translate_init(void)
                                               fregnames[i]);
 }
 
-void superh_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void superh_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     SuperHCPU *cpu = SUPERH_CPU(cs);
     CPUSH4State *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "pc=0x%08x sr=0x%08x pr=0x%08x fpscr=0x%08x\n",
-                 env->pc, cpu_read_sr(env), env->pr, env->fpscr);
-    qemu_fprintf(f, "spc=0x%08x ssr=0x%08x gbr=0x%08x vbr=0x%08x\n",
-                 env->spc, env->ssr, env->gbr, env->vbr);
-    qemu_fprintf(f, "sgr=0x%08x dbr=0x%08x delayed_pc=0x%08x fpul=0x%08x\n",
-                 env->sgr, env->dbr, env->delayed_pc, env->fpul);
+    g_string_append_printf(buf, "pc=0x%08x sr=0x%08x pr=0x%08x fpscr=0x%08x\n",
+                           env->pc, cpu_read_sr(env), env->pr, env->fpscr);
+    g_string_append_printf(buf, "spc=0x%08x ssr=0x%08x gbr=0x%08x vbr=0x%08x\n",
+                           env->spc, env->ssr, env->gbr, env->vbr);
+    g_string_append_printf(buf, "sgr=0x%08x dbr=0x%08x delayed_pc=0x%08x "
+                           "fpul=0x%08x\n",
+                           env->sgr, env->dbr, env->delayed_pc, env->fpul);
     for (i = 0; i < 24; i += 4) {
-        qemu_printf("r%d=0x%08x r%d=0x%08x r%d=0x%08x r%d=0x%08x\n",
-		    i, env->gregs[i], i + 1, env->gregs[i + 1],
-		    i + 2, env->gregs[i + 2], i + 3, env->gregs[i + 3]);
+        g_string_append_printf(buf, "r%d=0x%08x r%d=0x%08x r%d=0x%08x "
+                               "r%d=0x%08x\n",
+                               i, env->gregs[i], i + 1, env->gregs[i + 1],
+                               i + 2, env->gregs[i + 2], i + 3,
+                               env->gregs[i + 3]);
     }
     if (env->flags & DELAY_SLOT) {
-        qemu_printf("in delay slot (delayed_pc=0x%08x)\n",
-		    env->delayed_pc);
+        g_string_append_printf(buf, "in delay slot (delayed_pc=0x%08x)\n",
+                               env->delayed_pc);
     } else if (env->flags & DELAY_SLOT_CONDITIONAL) {
-        qemu_printf("in conditional delay slot (delayed_pc=0x%08x)\n",
-		    env->delayed_pc);
+        g_string_append_printf(buf, "in conditional delay slot "
+                               "(delayed_pc=0x%08x)\n",
+                               env->delayed_pc);
     } else if (env->flags & DELAY_SLOT_RTE) {
-        qemu_fprintf(f, "in rte delay slot (delayed_pc=0x%08x)\n",
-                     env->delayed_pc);
+        g_string_append_printf(buf, "in rte delay slot (delayed_pc=0x%08x)\n",
+                               env->delayed_pc);
     }
 }
 
Signature · 1 line
2.31.1
#55 lore raw

PATCH v2 25/53 target/sparc: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
 target/sparc/cpu.h |  2 +-
 2 files changed, 47 insertions(+), 40 deletions(-)
target/sparc/cpu.c +46 -39
index da6b30ec74..9346a79239 100644
@@ -597,11 +597,11 @@ void sparc_cpu_list(void)
                 "fpu_version mmu_version nwindows\n");
 }
 
-static void cpu_print_cc(FILE *f, uint32_t cc)
+static void cpu_print_cc(GString *buf, uint32_t cc)
 {
-    qemu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
-                 cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
-                 cc & PSR_CARRY ? 'C' : '-');
+    g_string_append_printf(buf, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
+                           cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
+                           cc & PSR_CARRY ? 'C' : '-');
 }
 
 #ifdef TARGET_SPARC64
@@ -610,34 +610,36 @@ static void cpu_print_cc(FILE *f, uint32_t cc)
 #define REGS_PER_LINE 8
 #endif
 
-void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void sparc_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     SPARCCPU *cpu = SPARC_CPU(cs);
     CPUSPARCState *env = &cpu->env;
     int i, x;
 
-    qemu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
-                 env->npc);
+    g_string_append_printf(buf,
+                           "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n",
+                           env->pc, env->npc);
 
     for (i = 0; i < 8; i++) {
         if (i % REGS_PER_LINE == 0) {
-            qemu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
+            g_string_append_printf(buf, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
         }
-        qemu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
+        g_string_append_printf(buf, " " TARGET_FMT_lx, env->gregs[i]);
         if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
     for (x = 0; x < 3; x++) {
         for (i = 0; i < 8; i++) {
             if (i % REGS_PER_LINE == 0) {
-                qemu_fprintf(f, "%%%c%d-%d: ",
+                g_string_append_printf(buf, "%%%c%d-%d: ",
                              x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
                              i, i + REGS_PER_LINE - 1);
             }
-            qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
+            g_string_append_printf(buf, TARGET_FMT_lx " ",
+                                   env->regwptr[i + x * 8]);
             if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");
             }
         }
     }
@@ -645,42 +647,47 @@ void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     if (flags & CPU_DUMP_FPU) {
         for (i = 0; i < TARGET_DPREGS; i++) {
             if ((i & 3) == 0) {
-                qemu_fprintf(f, "%%f%02d: ", i * 2);
+                g_string_append_printf(buf, "%%f%02d: ", i * 2);
             }
-            qemu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
+            g_string_append_printf(buf, " %016" PRIx64, env->fpr[i].ll);
             if ((i & 3) == 3) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");
             }
         }
     }
 
 #ifdef TARGET_SPARC64
-    qemu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
+    g_string_append_printf(buf, "pstate: %08x ccr: %02x (icc: ", env->pstate,
                  (unsigned)cpu_get_ccr(env));
-    cpu_print_cc(f, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
-    qemu_fprintf(f, " xcc: ");
-    cpu_print_cc(f, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
-    qemu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl,
-                 env->psrpil, env->gl);
-    qemu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: "
-                 TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba);
-    qemu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
-                 "cleanwin: %d cwp: %d\n",
-                 env->cansave, env->canrestore, env->otherwin, env->wstate,
-                 env->cleanwin, env->nwindows - 1 - env->cwp);
-    qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: "
-                 TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs);
+    cpu_print_cc(buf, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
+    g_string_append_printf(buf, " xcc: ");
+    cpu_print_cc(buf, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
+    g_string_append_printf(buf, ") asi: %02x tl: %d pil: %x gl: %d\n",
+                           env->asi, env->tl, env->psrpil, env->gl);
+    g_string_append_printf(buf, "tbr: " TARGET_FMT_lx " hpstate: "
+                           TARGET_FMT_lx " htba: " TARGET_FMT_lx "\n",
+                           env->tbr, env->hpstate, env->htba);
+    g_string_append_printf(buf, "cansave: %d canrestore: %d "
+                           "otherwin: %d wstate: %d "
+                           "cleanwin: %d cwp: %d\n",
+                           env->cansave, env->canrestore,
+                           env->otherwin, env->wstate,
+                           env->cleanwin, env->nwindows - 1 - env->cwp);
+    g_string_append_printf(buf, "fsr: " TARGET_FMT_lx " y: "
+                           TARGET_FMT_lx " fprs: " TARGET_FMT_lx "\n",
+                           env->fsr, env->y, env->fprs);
 
 #else
-    qemu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
-    cpu_print_cc(f, cpu_get_psr(env));
-    qemu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
-                 env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
-                 env->wim);
-    qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
-                 env->fsr, env->y);
+    g_string_append_printf(buf, "psr: %08x (icc: ", cpu_get_psr(env));
+    cpu_print_cc(buf, cpu_get_psr(env));
+    g_string_append_printf(buf, " SPE: %c%c%c) wim: %08x\n",
+                           env->psrs ? 'S' : '-',
+                           env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
+                           env->wim);
+    g_string_append_printf(buf, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
+                           env->fsr, env->y);
 #endif
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
 }
 
 static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
@@ -889,7 +896,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = sparc_cpu_class_by_name;
     cc->parse_features = sparc_cpu_parse_features;
     cc->has_work = sparc_cpu_has_work;
-    cc->dump_state = sparc_cpu_dump_state;
+    cc->format_state = sparc_cpu_format_state;
 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
     cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
 #endif
target/sparc/cpu.h +1 -1
index ff8ae73002..65a01a7884 100644
@@ -571,7 +571,7 @@ extern const VMStateDescription vmstate_sparc_cpu;
 #endif
 
 void sparc_cpu_do_interrupt(CPUState *cpu);
-void sparc_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void sparc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
Signature · 1 line
2.31.1
#58 lore raw

PATCH v2 26/53 target/tricore: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/tricore/cpu.c       |  2 +-
 target/tricore/cpu.h       |  2 +-
 target/tricore/translate.c | 24 ++++++++++++------------
 3 files changed, 14 insertions(+), 14 deletions(-)
target/tricore/cpu.c +1 -1
index b95682b7f0..11f1a79247 100644
@@ -174,7 +174,7 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data)
     cc->gdb_num_core_regs = 44;
     cc->gdb_arch_name = tricore_gdb_arch_name;
 
-    cc->dump_state = tricore_cpu_dump_state;
+    cc->format_state = tricore_cpu_format_state;
     cc->set_pc = tricore_cpu_set_pc;
     cc->sysemu_ops = &tricore_sysemu_ops;
     cc->tcg_ops = &tricore_tcg_ops;
target/tricore/cpu.h +1 -1
index 4b61a2c03f..572bda55e7 100644
@@ -208,7 +208,7 @@ struct TriCoreCPU {
 
 
 hwaddr tricore_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
-void tricore_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void tricore_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 
 
 #define MASK_PCXI_PCPN 0xff000000
target/tricore/translate.c +12 -12
index a0cc0f1cb3..a1e56fba32 100644
@@ -86,7 +86,7 @@ enum {
     MODE_UU = 3,
 };
 
-void tricore_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void tricore_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     TriCoreCPU *cpu = TRICORE_CPU(cs);
     CPUTriCoreState *env = &cpu->env;
@@ -95,26 +95,26 @@ void tricore_cpu_dump_state(CPUState *cs, FILE *f, int flags)
 
     psw = psw_read(env);
 
-    qemu_fprintf(f, "PC: " TARGET_FMT_lx, env->PC);
-    qemu_fprintf(f, " PSW: " TARGET_FMT_lx, psw);
-    qemu_fprintf(f, " ICR: " TARGET_FMT_lx, env->ICR);
-    qemu_fprintf(f, "\nPCXI: " TARGET_FMT_lx, env->PCXI);
-    qemu_fprintf(f, " FCX: " TARGET_FMT_lx, env->FCX);
-    qemu_fprintf(f, " LCX: " TARGET_FMT_lx, env->LCX);
+    g_string_append_printf(buf, "PC: " TARGET_FMT_lx, env->PC);
+    g_string_append_printf(buf, " PSW: " TARGET_FMT_lx, psw);
+    g_string_append_printf(buf, " ICR: " TARGET_FMT_lx, env->ICR);
+    g_string_append_printf(buf, "\nPCXI: " TARGET_FMT_lx, env->PCXI);
+    g_string_append_printf(buf, " FCX: " TARGET_FMT_lx, env->FCX);
+    g_string_append_printf(buf, " LCX: " TARGET_FMT_lx, env->LCX);
 
     for (i = 0; i < 16; ++i) {
         if ((i & 3) == 0) {
-            qemu_fprintf(f, "\nGPR A%02d:", i);
+            g_string_append_printf(buf, "\nGPR A%02d:", i);
         }
-        qemu_fprintf(f, " " TARGET_FMT_lx, env->gpr_a[i]);
+        g_string_append_printf(buf, " " TARGET_FMT_lx, env->gpr_a[i]);
     }
     for (i = 0; i < 16; ++i) {
         if ((i & 3) == 0) {
-            qemu_fprintf(f, "\nGPR D%02d:", i);
+            g_string_append_printf(buf, "\nGPR D%02d:", i);
         }
-        qemu_fprintf(f, " " TARGET_FMT_lx, env->gpr_d[i]);
+        g_string_append_printf(buf, " " TARGET_FMT_lx, env->gpr_d[i]);
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
 }
 
 /*
Signature · 1 line
2.31.1
#60 lore raw

PATCH v2 27/53 target/xtensa: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
---
 target/xtensa/cpu.c       |  2 +-
 target/xtensa/cpu.h       |  2 +-
 target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
 3 files changed, 25 insertions(+), 24 deletions(-)
target/xtensa/cpu.c +1 -1
index 58ec3a0862..a5a416e0b3 100644
@@ -216,7 +216,7 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = xtensa_cpu_class_by_name;
     cc->has_work = xtensa_cpu_has_work;
-    cc->dump_state = xtensa_cpu_dump_state;
+    cc->format_state = xtensa_cpu_format_state;
     cc->set_pc = xtensa_cpu_set_pc;
     cc->gdb_read_register = xtensa_cpu_gdb_read_register;
     cc->gdb_write_register = xtensa_cpu_gdb_write_register;
target/xtensa/cpu.h +1 -1
index 2345cb59c7..97cd6892df 100644
@@ -572,7 +572,7 @@ void xtensa_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
                                       unsigned size, MMUAccessType access_type,
                                       int mmu_idx, MemTxAttrs attrs,
                                       MemTxResult response, uintptr_t retaddr);
-void xtensa_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void xtensa_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr xtensa_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 void xtensa_count_regs(const XtensaConfig *config,
                        unsigned *n_regs, unsigned *n_core_regs);
target/xtensa/translate.c +23 -22

92 lines not on this page · raw message

Signature · 1 line
2.31.1
#65 lore raw

PATCH v2 28/53 monitor: remove 'info ioapic' HMP command

In reply to Daniel P. Berrangé

This command was turned into a no-op four years ago in

commit 0c8465440d50c18a7bb13d0a866748f0593e193a
Author: Peter Xu <[email protected]>
Date: Fri Dec 29 15:31:04 2017 +0800

hmp: obsolete "info ioapic"

---
 hmp-commands-info.hx         | 15 ---------------
 include/monitor/hmp-target.h |  1 -
 target/i386/monitor.c        |  6 ------
 3 files changed, 22 deletions(-)
hmp-commands-info.hx +0 -15
index 27206ac049..f8312342cd 100644
@@ -127,21 +127,6 @@ SRST
     Show local APIC state
 ERST
 
-#if defined(TARGET_I386)
-    {
-        .name       = "ioapic",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show io apic state",
-        .cmd        = hmp_info_io_apic,
-    },
-#endif
-
-SRST
-  ``info ioapic``
-    Show io APIC state
-ERST
-
     {
         .name       = "cpus",
         .args_type  = "",
include/monitor/hmp-target.h +0 -1
index 60fc92722a..df79ad3355 100644
@@ -48,6 +48,5 @@ void hmp_info_mem(Monitor *mon, const QDict *qdict);
 void hmp_info_tlb(Monitor *mon, const QDict *qdict);
 void hmp_mce(Monitor *mon, const QDict *qdict);
 void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
-void hmp_info_io_apic(Monitor *mon, const QDict *qdict);
 
 #endif /* MONITOR_HMP_TARGET_H */
target/i386/monitor.c +0 -6
index 119211f0b0..19468c4e85 100644
@@ -669,12 +669,6 @@ void hmp_info_local_apic(Monitor *mon, const QDict *qdict)
     x86_cpu_dump_local_apic_state(cs, CPU_DUMP_FPU);
 }
 
-void hmp_info_io_apic(Monitor *mon, const QDict *qdict)
-{
-    monitor_printf(mon, "This command is obsolete and will be "
-                   "removed soon. Please use 'info pic' instead.\n");
-}
-
 SevInfo *qmp_query_sev(Error **errp)
 {
     SevInfo *info;
Signature · 1 line
2.31.1
#67 lore raw

PATCH v2 29/53 qapi: introduce x-query-registers QMP command

In reply to Daniel P. Berrangé

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 ad hoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.

---
 hw/core/machine-qmp-cmds.c | 30 ++++++++++++++++++++++++++++++
 monitor/misc.c             | 25 ++++++++++++++++---------
 qapi/common.json           | 11 +++++++++++
 qapi/machine.json          | 15 +++++++++++++++
 4 files changed, 72 insertions(+), 9 deletions(-)
hw/core/machine-qmp-cmds.c +30 -0
index 216fdfaf3a..c4e384f7d5 100644
@@ -204,3 +204,33 @@ MemdevList *qmp_query_memdev(Error **errp)
     object_child_foreach(obj, query_memdev, &list);
     return list;
 }
+
+HumanReadableText *qmp_x_query_registers(bool has_cpu, int64_t cpu,
+                                         Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cs = NULL, *tmp;
+
+    if (has_cpu) {
+        CPU_FOREACH(tmp) {
+            if (cpu == tmp->cpu_index) {
+                cs = 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);
+        }
+    }
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
monitor/misc.c +16 -9
index ffe7966870..f25801a1a3 100644
@@ -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 = qdict_get_try_bool(qdict, "cpustate_all", false);
-    CPUState *cs;
+    bool has_cpu = !all_cpus;
+    int64_t cpu = 0;
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = NULL;
 
-    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 = mon_get_cpu(mon);
+    if (has_cpu) {
+        CPUState *cs = mon_get_cpu(mon);
 
         if (!cs) {
             monitor_printf(mon, "No CPU available\n");
             return;
         }
 
-        cpu_dump_state(cs, NULL, CPU_DUMP_FPU);
+        cpu = cs->cpu_index;
     }
+
+    info = qmp_x_query_registers(has_cpu, cpu, &err);
+    if (err) {
+        error_report_err(err);
+        return;
+    }
+
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
qapi/common.json +11 -0
index 7c976296f0..de7614ca99 100644
@@ -197,3 +197,14 @@
 { 'enum': 'GrabToggleKeys',
   'data': [ 'ctrl-ctrl', 'alt-alt', 'shift-shift','meta-meta', 'scrolllock',
             'ctrl-scrolllock' ] }
+
+##
+# @HumanReadableText:
+#
+# @human-readable-text: Formatted output intended for humans.
+#
+# Since: 6.2.0
+#
+##
+{ 'struct': 'HumanReadableText',
+  'data': { 'human-readable-text': 'str' } }
qapi/machine.json +15 -0
index 157712f006..8737efa865 100644
@@ -1312,3 +1312,18 @@
      '*cores': 'int',
      '*threads': 'int',
      '*maxcpus': 'int' } }
+
+##
+# @x-query-registers:
+#
+# @cpu: the CPU number to query. If omitted, queries all CPUs
+#
+# Query information on the CPU registers
+#
+# Returns: CPU state in an architecture-specific format
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-registers',
+  'data': {'*cpu': 'int' },
+  'returns': 'HumanReadableText' }
Signature · 1 line
2.31.1
#71 lore raw

PATCH v2 30/53 qapi: introduce x-query-roms QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info roms" 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. The existing HMP command is rewritten to call the QMP command.

---
 hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
 qapi/machine.json | 12 +++++++++++
 2 files changed, 50 insertions(+), 17 deletions(-)
hw/core/loader.c +38 -17
index c623318b73..014d131847 100644
@@ -46,6 +46,7 @@
 #include "qemu-common.h"
 #include "qemu/datadir.h"
 #include "qapi/error.h"
+#include "qapi/qapi-commands-machine.h"
 #include "trace.h"
 #include "hw/hw.h"
 #include "disas/disas.h"
@@ -1472,32 +1473,52 @@ void *rom_ptr_for_as(AddressSpace *as, hwaddr addr, size_t size)
     return cbdata.rom;
 }
 
-void hmp_info_roms(Monitor *mon, const QDict *qdict)
+HumanReadableText *qmp_x_query_roms(Error **errp)
 {
     Rom *rom;
+    g_autoptr(GString) buf = g_string_new("");
+    HumanReadableText *ret;
 
     QTAILQ_FOREACH(rom, &roms, next) {
         if (rom->mr) {
-            monitor_printf(mon, "%s"
-                           " size=0x%06zx name=\"%s\"\n",
-                           memory_region_name(rom->mr),
-                           rom->romsize,
-                           rom->name);
+            g_string_append_printf(buf, "%s"
+                                   " size=0x%06zx name=\"%s\"\n",
+                                   memory_region_name(rom->mr),
+                                   rom->romsize,
+                                   rom->name);
         } else if (!rom->fw_file) {
-            monitor_printf(mon, "addr=" TARGET_FMT_plx
-                           " size=0x%06zx mem=%s name=\"%s\"\n",
-                           rom->addr, rom->romsize,
-                           rom->isrom ? "rom" : "ram",
-                           rom->name);
+            g_string_append_printf(buf, "addr=" TARGET_FMT_plx
+                                   " size=0x%06zx mem=%s name=\"%s\"\n",
+                                   rom->addr, rom->romsize,
+                                   rom->isrom ? "rom" : "ram",
+                                   rom->name);
         } else {
-            monitor_printf(mon, "fw=%s/%s"
-                           " size=0x%06zx name=\"%s\"\n",
-                           rom->fw_dir,
-                           rom->fw_file,
-                           rom->romsize,
-                           rom->name);
+            g_string_append_printf(buf, "fw=%s/%s"
+                                   " size=0x%06zx name=\"%s\"\n",
+                                   rom->fw_dir,
+                                   rom->fw_file,
+                                   rom->romsize,
+                                   rom->name);
         }
     }
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
+
+void hmp_info_roms(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = qmp_x_query_roms(&err);
+
+    if (err) {
+        error_report_err(err);
+        return;
+    }
+
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 typedef enum HexRecord HexRecord;
qapi/machine.json +12 -0
index 8737efa865..a4a1727589 100644
@@ -1327,3 +1327,15 @@
 { 'command': 'x-query-registers',
   'data': {'*cpu': 'int' },
   'returns': 'HumanReadableText' }
+
+##
+# @x-query-roms:
+#
+# Query information on the registered ROMS
+#
+# Returns: registered ROMs
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-roms',
+  'returns': 'HumanReadableText' }
Signature · 1 line
2.31.1
#74 lore raw

PATCH v2 31/53 qapi: introduce x-query-profile QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info profile" 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. The existing HMP command is rewritten to call the QMP command.

---
 monitor/misc.c             | 29 +++++++----------------------
 monitor/qmp-cmds.c         | 34 ++++++++++++++++++++++++++++++++++
 qapi/machine.json          | 12 ++++++++++++
 tests/qtest/qmp-cmd-test.c |  3 +++
 4 files changed, 56 insertions(+), 22 deletions(-)
monitor/misc.c +7 -22
index f25801a1a3..6b07efdddd 100644
@@ -936,32 +936,17 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
     mtree_info(flatview, dispatch_tree, owner, disabled);
 }
 
-#ifdef CONFIG_PROFILER
-
-int64_t dev_time;
-
 static void hmp_info_profile(Monitor *mon, const QDict *qdict)
 {
-    static int64_t last_cpu_exec_time;
-    int64_t cpu_exec_time;
-    int64_t delta;
-
-    cpu_exec_time = tcg_cpu_exec_time();
-    delta = cpu_exec_time - last_cpu_exec_time;
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = qmp_x_query_profile(&err);
 
-    monitor_printf(mon, "async time  %" PRId64 " (%0.3f)\n",
-                   dev_time, dev_time / (double)NANOSECONDS_PER_SECOND);
-    monitor_printf(mon, "qemu time   %" PRId64 " (%0.3f)\n",
-                   delta, delta / (double)NANOSECONDS_PER_SECOND);
-    last_cpu_exec_time = cpu_exec_time;
-    dev_time = 0;
-}
-#else
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
-{
-    monitor_printf(mon, "Internal profiler not compiled\n");
+    if (err) {
+        error_report_err(err);
+        return;
+    }
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
-#endif
 
 /* Capture support */
 static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
monitor/qmp-cmds.c +34 -0
index 5c0d5e116b..7bae0770a9 100644
@@ -350,3 +350,37 @@ void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)
         abort();
     }
 }
+
+#ifdef CONFIG_PROFILER
+
+int64_t dev_time;
+
+HumanReadableText *qmp_x_query_profile(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+    static int64_t last_cpu_exec_time;
+    int64_t cpu_exec_time;
+    int64_t delta;
+
+    cpu_exec_time = tcg_cpu_exec_time();
+    delta = cpu_exec_time - last_cpu_exec_time;
+
+    g_string_append_printf(buf, "async time  %" PRId64 " (%0.3f)\n",
+                           dev_time, dev_time / (double)NANOSECONDS_PER_SECOND);
+    g_string_append_printf(buf, "qemu time   %" PRId64 " (%0.3f)\n",
+                           delta, delta / (double)NANOSECONDS_PER_SECOND);
+    last_cpu_exec_time = cpu_exec_time;
+    dev_time = 0;
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+#else
+HumanReadableText *qmp_x_query_profile(Error **errp)
+{
+    error_setg(errp, "Internal profiler not compiled");
+    return NULL;
+}
+#endif
qapi/machine.json +12 -0
index a4a1727589..d74c3f3fef 100644
@@ -1313,6 +1313,18 @@
      '*threads': 'int',
      '*maxcpus': 'int' } }
 
+##
+# @x-query-profile:
+#
+# Query TCG profiling information
+#
+# Returns: profile information
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-profile',
+  'returns': 'HumanReadableText' }
+
 ##
 # @x-query-registers:
 #
tests/qtest/qmp-cmd-test.c +3 -0
index c98b78d033..fbd7ac10fb 100644
@@ -46,6 +46,9 @@ static int query_error_class(const char *cmd)
         { "query-balloon", ERROR_CLASS_DEVICE_NOT_ACTIVE },
         { "query-hotpluggable-cpus", ERROR_CLASS_GENERIC_ERROR },
         { "query-vm-generation-id", ERROR_CLASS_GENERIC_ERROR },
+#ifndef CONFIG_PROFILER
+        { "x-query-profile", ERROR_CLASS_GENERIC_ERROR },
+#endif
         { NULL, -1 }
     };
     int i;
Signature · 1 line
2.31.1
#75 lore raw

PATCH v2 32/53 qapi: introduce x-query-numa QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info numa" 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. The existing HMP command is rewritten to call the QMP command.

---
 hw/core/machine-hmp-cmds.c | 33 +++++-------------------------
 hw/core/machine-qmp-cmds.c | 42 ++++++++++++++++++++++++++++++++++++++
 qapi/machine.json          | 12 +++++++++++
 3 files changed, 59 insertions(+), 28 deletions(-)
hw/core/machine-hmp-cmds.c +5 -28
index 76b22b00d6..cfa01c6933 100644
@@ -134,35 +134,12 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
 void hmp_info_numa(Monitor *mon, const QDict *qdict)
 {
-    int i, nb_numa_nodes;
-    NumaNodeMem *node_mem;
-    CpuInfoFastList *cpu_list, *cpu;
-    MachineState *ms = MACHINE(qdev_get_machine());
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = qmp_x_query_numa(&err);
 
-    nb_numa_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0;
-    monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
-    if (!nb_numa_nodes) {
+    if (err) {
+        error_report_err(err);
         return;
     }
-
-    cpu_list = qmp_query_cpus_fast(&error_abort);
-    node_mem = g_new0(NumaNodeMem, nb_numa_nodes);
-
-    query_numa_node_mem(node_mem, ms);
-    for (i = 0; i < nb_numa_nodes; i++) {
-        monitor_printf(mon, "node %d cpus:", i);
-        for (cpu = cpu_list; cpu; cpu = cpu->next) {
-            if (cpu->value->has_props && cpu->value->props->has_node_id &&
-                cpu->value->props->node_id == i) {
-                monitor_printf(mon, " %" PRIi64, cpu->value->cpu_index);
-            }
-        }
-        monitor_printf(mon, "\n");
-        monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
-                       node_mem[i].node_mem >> 20);
-        monitor_printf(mon, "node %d plugged: %" PRId64 " MB\n", i,
-                       node_mem[i].node_plugged_mem >> 20);
-    }
-    qapi_free_CpuInfoFastList(cpu_list);
-    g_free(node_mem);
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
hw/core/machine-qmp-cmds.c +42 -0

45 lines not on this page · raw message

qapi/machine.json +12 -0
index d74c3f3fef..916f855e9b 100644
@@ -1313,6 +1313,18 @@
      '*threads': 'int',
      '*maxcpus': 'int' } }
 
+##
+# @x-query-numa:
+#
+# Query NUMA topology information
+#
+# Returns: topology information
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-numa',
+  'returns': 'HumanReadableText' }
+
 ##
 # @x-query-profile:
 #
Signature · 1 line
2.31.1
#77 lore raw

PATCH v2 34/53 qapi: introduce x-query-rdma QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info rdma" 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. The existing HMP command is rewritten to call the QMP command.

---
 hw/rdma/rdma_rm.c         | 104 +++++++++++++++++++-------------------
 hw/rdma/rdma_rm.h         |   2 +-
 hw/rdma/vmw/pvrdma_main.c |  31 ++++++------
 include/hw/rdma/rdma.h    |   2 +-
 monitor/hmp-cmds.c        |  29 +++--------
 monitor/qmp-cmds.c        |  35 +++++++++++++
 qapi/machine.json         |  12 +++++
 7 files changed, 125 insertions(+), 90 deletions(-)
hw/rdma/rdma_rm.c +52 -52
index 49141d4074..cfd85de3e6 100644
@@ -27,58 +27,58 @@
 #define PG_DIR_SZ { TARGET_PAGE_SIZE / sizeof(__u64) }
 #define PG_TBL_SZ { TARGET_PAGE_SIZE / sizeof(__u64) }
 
-void rdma_dump_device_counters(Monitor *mon, RdmaDeviceResources *dev_res)
-{
-    monitor_printf(mon, "\ttx               : %" PRId64 "\n",
-                   dev_res->stats.tx);
-    monitor_printf(mon, "\ttx_len           : %" PRId64 "\n",
-                   dev_res->stats.tx_len);
-    monitor_printf(mon, "\ttx_err           : %" PRId64 "\n",
-                   dev_res->stats.tx_err);
-    monitor_printf(mon, "\trx_bufs          : %" PRId64 "\n",
-                   dev_res->stats.rx_bufs);
-    monitor_printf(mon, "\trx_srq           : %" PRId64 "\n",
-                   dev_res->stats.rx_srq);
-    monitor_printf(mon, "\trx_bufs_len      : %" PRId64 "\n",
-                   dev_res->stats.rx_bufs_len);
-    monitor_printf(mon, "\trx_bufs_err      : %" PRId64 "\n",
-                   dev_res->stats.rx_bufs_err);
-    monitor_printf(mon, "\tcomps            : %" PRId64 "\n",
-                   dev_res->stats.completions);
-    monitor_printf(mon, "\tmissing_comps    : %" PRId32 "\n",
-                   dev_res->stats.missing_cqe);
-    monitor_printf(mon, "\tpoll_cq (bk)     : %" PRId64 "\n",
-                   dev_res->stats.poll_cq_from_bk);
-    monitor_printf(mon, "\tpoll_cq_ppoll_to : %" PRId64 "\n",
-                   dev_res->stats.poll_cq_ppoll_to);
-    monitor_printf(mon, "\tpoll_cq (fe)     : %" PRId64 "\n",
-                   dev_res->stats.poll_cq_from_guest);
-    monitor_printf(mon, "\tpoll_cq_empty    : %" PRId64 "\n",
-                   dev_res->stats.poll_cq_from_guest_empty);
-    monitor_printf(mon, "\tmad_tx           : %" PRId64 "\n",
-                   dev_res->stats.mad_tx);
-    monitor_printf(mon, "\tmad_tx_err       : %" PRId64 "\n",
-                   dev_res->stats.mad_tx_err);
-    monitor_printf(mon, "\tmad_rx           : %" PRId64 "\n",
-                   dev_res->stats.mad_rx);
-    monitor_printf(mon, "\tmad_rx_err       : %" PRId64 "\n",
-                   dev_res->stats.mad_rx_err);
-    monitor_printf(mon, "\tmad_rx_bufs      : %" PRId64 "\n",
-                   dev_res->stats.mad_rx_bufs);
-    monitor_printf(mon, "\tmad_rx_bufs_err  : %" PRId64 "\n",
-                   dev_res->stats.mad_rx_bufs_err);
-    monitor_printf(mon, "\tPDs              : %" PRId32 "\n",
-                   dev_res->pd_tbl.used);
-    monitor_printf(mon, "\tMRs              : %" PRId32 "\n",
-                   dev_res->mr_tbl.used);
-    monitor_printf(mon, "\tUCs              : %" PRId32 "\n",
-                   dev_res->uc_tbl.used);
-    monitor_printf(mon, "\tQPs              : %" PRId32 "\n",
-                   dev_res->qp_tbl.used);
-    monitor_printf(mon, "\tCQs              : %" PRId32 "\n",
-                   dev_res->cq_tbl.used);
-    monitor_printf(mon, "\tCEQ_CTXs         : %" PRId32 "\n",
-                   dev_res->cqe_ctx_tbl.used);
+void rdma_format_device_counters(RdmaDeviceResources *dev_res, GString *buf)
+{
+    g_string_append_printf(buf, "\ttx               : %" PRId64 "\n",
+                           dev_res->stats.tx);
+    g_string_append_printf(buf, "\ttx_len           : %" PRId64 "\n",
+                           dev_res->stats.tx_len);
+    g_string_append_printf(buf, "\ttx_err           : %" PRId64 "\n",
+                           dev_res->stats.tx_err);
+    g_string_append_printf(buf, "\trx_bufs          : %" PRId64 "\n",
+                           dev_res->stats.rx_bufs);
+    g_string_append_printf(buf, "\trx_srq           : %" PRId64 "\n",
+                           dev_res->stats.rx_srq);
+    g_string_append_printf(buf, "\trx_bufs_len      : %" PRId64 "\n",
+                           dev_res->stats.rx_bufs_len);
+    g_string_append_printf(buf, "\trx_bufs_err      : %" PRId64 "\n",
+                           dev_res->stats.rx_bufs_err);
+    g_string_append_printf(buf, "\tcomps            : %" PRId64 "\n",
+                           dev_res->stats.completions);
+    g_string_append_printf(buf, "\tmissing_comps    : %" PRId32 "\n",
+                           dev_res->stats.missing_cqe);
+    g_string_append_printf(buf, "\tpoll_cq (bk)     : %" PRId64 "\n",
+                           dev_res->stats.poll_cq_from_bk);
+    g_string_append_printf(buf, "\tpoll_cq_ppoll_to : %" PRId64 "\n",
+                           dev_res->stats.poll_cq_ppoll_to);
+    g_string_append_printf(buf, "\tpoll_cq (fe)     : %" PRId64 "\n",
+                           dev_res->stats.poll_cq_from_guest);
+    g_string_append_printf(buf, "\tpoll_cq_empty    : %" PRId64 "\n",
+                           dev_res->stats.poll_cq_from_guest_empty);
+    g_string_append_printf(buf, "\tmad_tx           : %" PRId64 "\n",
+                           dev_res->stats.mad_tx);
+    g_string_append_printf(buf, "\tmad_tx_err       : %" PRId64 "\n",
+                           dev_res->stats.mad_tx_err);
+    g_string_append_printf(buf, "\tmad_rx           : %" PRId64 "\n",
+                           dev_res->stats.mad_rx);
+    g_string_append_printf(buf, "\tmad_rx_err       : %" PRId64 "\n",
+                           dev_res->stats.mad_rx_err);
+    g_string_append_printf(buf, "\tmad_rx_bufs      : %" PRId64 "\n",
+                           dev_res->stats.mad_rx_bufs);
+    g_string_append_printf(buf, "\tmad_rx_bufs_err  : %" PRId64 "\n",
+                           dev_res->stats.mad_rx_bufs_err);
+    g_string_append_printf(buf, "\tPDs              : %" PRId32 "\n",
+                           dev_res->pd_tbl.used);
+    g_string_append_printf(buf, "\tMRs              : %" PRId32 "\n",
+                           dev_res->mr_tbl.used);
+    g_string_append_printf(buf, "\tUCs              : %" PRId32 "\n",
+                           dev_res->uc_tbl.used);
+    g_string_append_printf(buf, "\tQPs              : %" PRId32 "\n",
+                           dev_res->qp_tbl.used);
+    g_string_append_printf(buf, "\tCQs              : %" PRId32 "\n",
+                           dev_res->cq_tbl.used);
+    g_string_append_printf(buf, "\tCEQ_CTXs         : %" PRId32 "\n",
+                           dev_res->cqe_ctx_tbl.used);
 }
 
 static inline void res_tbl_init(const char *name, RdmaRmResTbl *tbl,
hw/rdma/rdma_rm.h +1 -1
index e8639909cd..d69a917795 100644
@@ -92,6 +92,6 @@ static inline union ibv_gid *rdma_rm_get_gid(RdmaDeviceResources *dev_res,
 {
     return &dev_res->port.gid_tbl[sgid_idx].gid;
 }
-void rdma_dump_device_counters(Monitor *mon, RdmaDeviceResources *dev_res);
+void rdma_format_device_counters(RdmaDeviceResources *dev_res, GString *buf);
 
 #endif
hw/rdma/vmw/pvrdma_main.c +16 -15
index 7c0c3551a8..91206dbb8e 100644
@@ -58,24 +58,25 @@ static Property pvrdma_dev_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void pvrdma_print_statistics(Monitor *mon, RdmaProvider *obj)
+static void pvrdma_format_statistics(RdmaProvider *obj, GString *buf)
 {
     PVRDMADev *dev = PVRDMA_DEV(obj);
     PCIDevice *pdev = PCI_DEVICE(dev);
 
-    monitor_printf(mon, "%s, %x.%x\n", pdev->name, PCI_SLOT(pdev->devfn),
-                   PCI_FUNC(pdev->devfn));
-    monitor_printf(mon, "\tcommands         : %" PRId64 "\n",
-                   dev->stats.commands);
-    monitor_printf(mon, "\tregs_reads       : %" PRId64 "\n",
-                   dev->stats.regs_reads);
-    monitor_printf(mon, "\tregs_writes      : %" PRId64 "\n",
-                   dev->stats.regs_writes);
-    monitor_printf(mon, "\tuar_writes       : %" PRId64 "\n",
-                   dev->stats.uar_writes);
-    monitor_printf(mon, "\tinterrupts       : %" PRId64 "\n",
-                   dev->stats.interrupts);
-    rdma_dump_device_counters(mon, &dev->rdma_dev_res);
+    g_string_append_printf(buf, "%s, %x.%x\n",
+                           pdev->name, PCI_SLOT(pdev->devfn),
+                           PCI_FUNC(pdev->devfn));
+    g_string_append_printf(buf, "\tcommands         : %" PRId64 "\n",
+                           dev->stats.commands);
+    g_string_append_printf(buf, "\tregs_reads       : %" PRId64 "\n",
+                           dev->stats.regs_reads);
+    g_string_append_printf(buf, "\tregs_writes      : %" PRId64 "\n",
+                           dev->stats.regs_writes);
+    g_string_append_printf(buf, "\tuar_writes       : %" PRId64 "\n",
+                           dev->stats.uar_writes);
+    g_string_append_printf(buf, "\tinterrupts       : %" PRId64 "\n",
+                           dev->stats.interrupts);
+    rdma_format_device_counters(&dev->rdma_dev_res, buf);
 }
 
 static void free_dev_ring(PCIDevice *pci_dev, PvrdmaRing *ring,
@@ -699,7 +700,7 @@ static void pvrdma_class_init(ObjectClass *klass, void *data)
     device_class_set_props(dc, pvrdma_dev_properties);
     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
 
-    ir->print_statistics = pvrdma_print_statistics;
+    ir->format_statistics = pvrdma_format_statistics;
 }
 
 static const TypeInfo pvrdma_info = {
include/hw/rdma/rdma.h +1 -1
index e77e43a170..80b2e531c4 100644
@@ -31,7 +31,7 @@ typedef struct RdmaProvider RdmaProvider;
 struct RdmaProviderClass {
     InterfaceClass parent;
 
-    void (*print_statistics)(Monitor *mon, RdmaProvider *obj);
+    void (*format_statistics)(RdmaProvider *obj, GString *buf);
 };
 
 #endif
monitor/hmp-cmds.c +8 -21
index e00255f7ee..d24a1683de 100644
@@ -54,7 +54,6 @@
 #include "qemu/error-report.h"
 #include "exec/ramlist.h"
 #include "hw/intc/intc.h"
-#include "hw/rdma/rdma.h"
 #include "migration/snapshot.h"
 #include "migration/misc.h"
 
@@ -850,30 +849,18 @@ void hmp_info_pic(Monitor *mon, const QDict *qdict)
                                    hmp_info_pic_foreach, mon);
 }
 
-static int hmp_info_rdma_foreach(Object *obj, void *opaque)
+void hmp_info_rdma(Monitor *mon, const QDict *qdict)
 {
-    RdmaProvider *rdma;
-    RdmaProviderClass *k;
-    Monitor *mon = opaque;
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = NULL;
 
-    if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
-        rdma = RDMA_PROVIDER(obj);
-        k = RDMA_PROVIDER_GET_CLASS(obj);
-        if (k->print_statistics) {
-            k->print_statistics(mon, rdma);
-        } else {
-            monitor_printf(mon, "RDMA statistics not available for %s.\n",
-                           object_get_typename(obj));
-        }
+    info = qmp_x_query_rdma(&err);
+    if (err) {
+        error_report_err(err);
+        return;
     }
 
-    return 0;
-}
-
-void hmp_info_rdma(Monitor *mon, const QDict *qdict)
-{
-    object_child_foreach_recursive(object_get_root(),
-                                   hmp_info_rdma_foreach, mon);
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 void hmp_info_pci(Monitor *mon, const QDict *qdict)
monitor/qmp-cmds.c +35 -0
index 7bae0770a9..9c2c1e4603 100644
@@ -39,6 +39,7 @@
 #include "qapi/qmp/qerror.h"
 #include "hw/mem/memory-device.h"
 #include "hw/acpi/acpi_dev_interface.h"
+#include "hw/rdma/rdma.h"
 
 NameInfo *qmp_query_name(Error **errp)
 {
@@ -384,3 +385,37 @@ HumanReadableText *qmp_x_query_profile(Error **errp)
     return NULL;
 }
 #endif
+
+static int qmp_x_query_rdma_foreach(Object *obj, void *opaque)
+{
+    RdmaProvider *rdma;
+    RdmaProviderClass *k;
+    GString *buf = opaque;
+
+    if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
+        rdma = RDMA_PROVIDER(obj);
+        k = RDMA_PROVIDER_GET_CLASS(obj);
+        if (k->format_statistics) {
+            k->format_statistics(rdma, buf);
+        } else {
+            g_string_append_printf(buf,
+                                   "RDMA statistics not available for %s.\n",
+                                   object_get_typename(obj));
+        }
+    }
+
+    return 0;
+}
+
+HumanReadableText *qmp_x_query_rdma(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+
+    object_child_foreach_recursive(object_get_root(),
+                                   qmp_x_query_rdma_foreach, buf);
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
qapi/machine.json +12 -0
index 39d800c2c1..0fe962d916 100644
@@ -1337,6 +1337,18 @@
 { 'command': 'x-query-profile',
   'returns': 'HumanReadableText' }
 
+##
+# @x-query-rdma:
+#
+# Query RDMA state
+#
+# Returns: RDMA state
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-rdma',
+  'returns': 'HumanReadableText' }
+
 ##
 # @x-query-registers:
 #
Signature · 1 line
2.31.1
#76 lore raw

PATCH v2 33/53 qapi: introduce x-query-usb QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info usb" 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. The existing HMP command is rewritten to call the QMP command.

---
 hw/usb/bus.c               | 38 +++++++++++++++++++++++++++++---------
 qapi/machine.json          | 12 ++++++++++++
 stubs/usb-dev-stub.c       |  8 ++++++++
 tests/qtest/qmp-cmd-test.c |  2 ++
 4 files changed, 51 insertions(+), 9 deletions(-)
hw/usb/bus.c +29 -9
index 07083349f5..f94d872429 100644
@@ -2,6 +2,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/usb.h"
 #include "qapi/error.h"
+#include "qapi/qapi-commands-machine.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "sysemu/sysemu.h"
@@ -631,15 +632,17 @@ static char *usb_get_fw_dev_path(DeviceState *qdev)
     return fw_path;
 }
 
-void hmp_info_usb(Monitor *mon, const QDict *qdict)
+HumanReadableText *qmp_x_query_usb(Error **errp)
 {
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
     USBBus *bus;
     USBDevice *dev;
     USBPort *port;
 
     if (QTAILQ_EMPTY(&busses)) {
-        monitor_printf(mon, "USB support not enabled\n");
-        return;
+        error_setg(errp, "USB support not enabled");
+        return NULL;
     }
 
     QTAILQ_FOREACH(bus, &busses, next) {
@@ -647,14 +650,31 @@ void hmp_info_usb(Monitor *mon, const QDict *qdict)
             dev = port->dev;
             if (!dev)
                 continue;
-            monitor_printf(mon, "  Device %d.%d, Port %s, Speed %s Mb/s, "
-                           "Product %s%s%s\n",
-                           bus->busnr, dev->addr, port->path,
-                           usb_speed(dev->speed), dev->product_desc,
-                           dev->qdev.id ? ", ID: " : "",
-                           dev->qdev.id ?: "");
+            g_string_append_printf(buf,
+                                   "  Device %d.%d, Port %s, Speed %s Mb/s, "
+                                   "Product %s%s%s\n",
+                                   bus->busnr, dev->addr, port->path,
+                                   usb_speed(dev->speed), dev->product_desc,
+                                   dev->qdev.id ? ", ID: " : "",
+                                   dev->qdev.id ?: "");
         }
     }
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
+void hmp_info_usb(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = qmp_x_query_usb(&err);
+
+    if (err) {
+        error_report_err(err);
+        return;
+    }
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 /* handle legacy -usbdevice cmd line option */
qapi/machine.json +12 -0
index 916f855e9b..39d800c2c1 100644
@@ -1363,3 +1363,15 @@
 ##
 { 'command': 'x-query-roms',
   'returns': 'HumanReadableText' }
+
+##
+# @x-query-usb:
+#
+# Query information on the USB devices
+#
+# Returns: USB device information
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-usb',
+  'returns': 'HumanReadableText' }
stubs/usb-dev-stub.c +8 -0
index b1adeeb454..aa557692b7 100644
@@ -8,6 +8,8 @@
 
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-machine.h"
 #include "sysemu/sysemu.h"
 #include "monitor/monitor.h"
 #include "hw/usb.h"
@@ -19,6 +21,12 @@ USBDevice *usbdevice_create(const char *driver)
     return NULL;
 }
 
+HumanReadableText *qmp_x_query_usb(Error **errp)
+{
+    error_setg(errp, "Support for USB devices not built-in");
+    return NULL;
+}
+
 void hmp_info_usb(Monitor *mon, const QDict *qdict)
 {
     monitor_printf(mon, "Support for USB devices not built-in\n");
tests/qtest/qmp-cmd-test.c +2 -0
index fbd7ac10fb..15875a14c6 100644
@@ -49,6 +49,8 @@ static int query_error_class(const char *cmd)
 #ifndef CONFIG_PROFILER
         { "x-query-profile", ERROR_CLASS_GENERIC_ERROR },
 #endif
+        /* Only valid with a USB bus added */
+        { "x-query-usb", ERROR_CLASS_GENERIC_ERROR },
         { NULL, -1 }
     };
     int i;
Signature · 1 line
2.31.1
#78 lore raw

PATCH v2 35/53 qapi: introduce x-query-ramblock QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info ramblock" 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. The existing HMP command is rewritten to call the QMP command.

---
 include/exec/ramlist.h |  2 +-
 monitor/hmp-cmds.c     | 12 ++++++++++--
 monitor/qmp-cmds.c     | 11 +++++++++++
 qapi/machine.json      | 12 ++++++++++++
 softmmu/physmem.c      | 19 +++++++++++--------
 5 files changed, 45 insertions(+), 11 deletions(-)
include/exec/ramlist.h +1 -1
index ece6497ee2..2ad2a81acc 100644
@@ -80,6 +80,6 @@ void ram_block_notify_add(void *host, size_t size, size_t max_size);
 void ram_block_notify_remove(void *host, size_t size, size_t max_size);
 void ram_block_notify_resize(void *host, size_t old_size, size_t new_size);
 
-void ram_block_dump(Monitor *mon);
+GString *ram_block_format(void);
 
 #endif /* RAMLIST_H */
monitor/hmp-cmds.c +10 -2
index d24a1683de..77533b2d8a 100644
@@ -52,7 +52,6 @@
 #include "ui/console.h"
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
-#include "exec/ramlist.h"
 #include "hw/intc/intc.h"
 #include "migration/snapshot.h"
 #include "migration/misc.h"
@@ -2188,7 +2187,16 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
 
 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
 {
-    ram_block_dump(mon);
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = NULL;
+
+    info = qmp_x_query_ramblock(&err);
+    if (err) {
+        error_report_err(err);
+        return;
+    }
+
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
monitor/qmp-cmds.c +11 -0
index 9c2c1e4603..b86fff823e 100644
@@ -37,6 +37,7 @@
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qapi/qmp/qerror.h"
+#include "exec/ramlist.h"
 #include "hw/mem/memory-device.h"
 #include "hw/acpi/acpi_dev_interface.h"
 #include "hw/rdma/rdma.h"
@@ -419,3 +420,13 @@ HumanReadableText *qmp_x_query_rdma(Error **errp)
     ret->human_readable_text = g_steal_pointer(&buf->str);
     return ret;
 }
+
+HumanReadableText *qmp_x_query_ramblock(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = ram_block_format();
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
qapi/machine.json +12 -0
index 0fe962d916..3ae7beb7cf 100644
@@ -1337,6 +1337,18 @@
 { 'command': 'x-query-profile',
   'returns': 'HumanReadableText' }
 
+##
+# @x-query-ramblock:
+#
+# Query system ramblock information
+#
+# Returns: system ramblock information
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-ramblock',
+  'returns': 'HumanReadableText' }
+
 ##
 # @x-query-rdma:
 #
softmmu/physmem.c +11 -8
index 23e77cb771..bc4a8354d3 100644
@@ -1298,23 +1298,26 @@ void qemu_mutex_unlock_ramlist(void)
     qemu_mutex_unlock(&ram_list.mutex);
 }
 
-void ram_block_dump(Monitor *mon)
+GString *ram_block_format(void)
 {
     RAMBlock *block;
     char *psize;
+    GString *buf = g_string_new("");
 
     RCU_READ_LOCK_GUARD();
-    monitor_printf(mon, "%24s %8s  %18s %18s %18s\n",
-                   "Block Name", "PSize", "Offset", "Used", "Total");
+    g_string_append_printf(buf, "%24s %8s  %18s %18s %18s\n",
+                           "Block Name", "PSize", "Offset", "Used", "Total");
     RAMBLOCK_FOREACH(block) {
         psize = size_to_str(block->page_size);
-        monitor_printf(mon, "%24s %8s  0x%016" PRIx64 " 0x%016" PRIx64
-                       " 0x%016" PRIx64 "\n", block->idstr, psize,
-                       (uint64_t)block->offset,
-                       (uint64_t)block->used_length,
-                       (uint64_t)block->max_length);
+        g_string_append_printf(buf, "%24s %8s  0x%016" PRIx64 " 0x%016" PRIx64
+                               " 0x%016" PRIx64 "\n", block->idstr, psize,
+                               (uint64_t)block->offset,
+                               (uint64_t)block->used_length,
+                               (uint64_t)block->max_length);
         g_free(psize);
     }
+
+    return buf;
 }
 
 #ifdef __linux__
Signature · 1 line
2.31.1
#79 lore raw

PATCH v2 36/53 qapi: introduce x-query-skeys QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info skeys" 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. The existing HMP command is rewritten to call the QMP command.

This command is unable to use the pre-existing HumanReadableText, because if 'common.json' is included into 'machine-target.json' the static marshalling method for HumanReadableText will be reported as unused by the compiler on all architectures except s390x.

Possible options were

1 Support 'if' conditionals on 'include' statements in QAPI 2 Add further commands to 'machine-target.json' that use
HumanReadableText, such that it has at least one usage on all architecture targets.
3 Duplicate HumanReadableText as TargetHumanReadableText
adding conditions

This patch takes option (3) in the belief that we will eventually get to a point where option (2) happens, and TargetHumanReadableText can be removed again.

---
 hw/s390x/s390-skeys.c    | 37 +++++++++++++++++++++++++++++--------
 qapi/machine-target.json | 27 +++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 8 deletions(-)
hw/s390x/s390-skeys.c +29 -8
index 5024faf411..3a404d0574 100644
@@ -15,6 +15,7 @@
 #include "hw/s390x/storage-keys.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qapi-commands-machine-target.h"
 #include "qapi/qmp/qdict.h"
 #include "qemu/error-report.h"
 #include "sysemu/memory_mapping.h"
@@ -73,34 +74,54 @@ static void write_keys(FILE *f, uint8_t *keys, uint64_t startgfn,
     }
 }
 
-void hmp_info_skeys(Monitor *mon, const QDict *qdict)
+TargetHumanReadableText *qmp_x_query_skeys(int64_t addr, Error **errp)
 {
+    TargetHumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
     S390SKeysState *ss = s390_get_skeys_device();
     S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss);
-    uint64_t addr = qdict_get_int(qdict, "addr");
     uint8_t key;
     int r;
 
     /* Quick check to see if guest is using storage keys*/
     if (!skeyclass->skeys_are_enabled(ss)) {
-        monitor_printf(mon, "Error: This guest is not using storage keys\n");
-        return;
+        error_setg(errp, "this guest is not using storage keys");
+        return NULL;
     }
 
     if (!address_space_access_valid(&address_space_memory,
                                     addr & TARGET_PAGE_MASK, TARGET_PAGE_SIZE,
                                     false, MEMTXATTRS_UNSPECIFIED)) {
-        monitor_printf(mon, "Error: The given address is not valid\n");
-        return;
+        error_setg(errp, "the given address is not valid");
+        return NULL;
     }
 
     r = skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key);
     if (r < 0) {
-        monitor_printf(mon, "Error: %s\n", strerror(-r));
+        error_setg_errno(errp, r, "unable to query storage keys");
+        return NULL;
+    }
+
+    g_string_append_printf(buf, "  key: 0x%X\n", key);
+
+    ret = g_new0(TargetHumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
+void hmp_info_skeys(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    g_autoptr(TargetHumanReadableText) info = NULL;
+    uint64_t addr = qdict_get_int(qdict, "addr");
+
+    info = qmp_x_query_skeys(addr, &err);
+    if (err) {
+        error_report_err(err);
         return;
     }
 
-    monitor_printf(mon, "  key: 0x%X\n", key);
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 void hmp_dump_skeys(Monitor *mon, const QDict *qdict)
qapi/machine-target.json +27 -0
index f5ec4bc172..00476bcdd4 100644
@@ -341,3 +341,30 @@
                    'TARGET_I386',
                    'TARGET_S390X',
                    'TARGET_MIPS' ] } }
+
+
+##
+# @TargetHumanReadableText:
+#
+# @human-readable-text: Formatted output intended for humans.
+#
+# Since: 6.2.0
+#
+##
+{ 'struct': 'TargetHumanReadableText',
+  'data': { 'human-readable-text': 'str' },
+  'if': 'TARGET_S390X' }
+
+##
+# @x-query-skeys:
+#
+# Query the value of a storage key
+#
+# Returns: storage key value
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-skeys',
+  'data': { 'addr': 'int' },
+  'returns': 'TargetHumanReadableText',
+  'if': 'TARGET_S390X' }
Signature · 1 line
2.31.1
#80 lore raw

PATCH v2 37/53 qapi: introduce x-query-cmma QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info cmma" 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. The existing HMP command is rewritten to call the QMP command.

This command is unable to use the pre-existing HumanReadableText, because if 'common.json' is included into 'machine-target.json' the static marshalling method for HumanReadableText will be reported as unused by the compiler on all architectures except s390x.

Possible options were

1 Support 'if' conditionals on 'include' statements in QAPI 2 Add further commands to 'machine-target.json' that use
HumanReadableText, such that it has at least one usage on all architecture targets.
3 Duplicate HumanReadableText as TargetHumanReadableText
adding conditions

This patch takes option (3) in the belief that we will eventually get to a point where option (2) happens, and TargetHumanReadableText can be removed again.

---
 hw/s390x/s390-stattrib.c | 58 +++++++++++++++++++++++++++-------------
 qapi/machine-target.json | 14 ++++++++++
 2 files changed, 54 insertions(+), 18 deletions(-)
hw/s390x/s390-stattrib.c +40 -18
index 9eda1c3b2a..1ff0142b10 100644
@@ -17,6 +17,7 @@
 #include "qemu/error-report.h"
 #include "exec/ram_addr.h"
 #include "qapi/error.h"
+#include "qapi/qapi-commands-machine-target.h"
 #include "qapi/qmp/qdict.h"
 
 /* 512KiB cover 2GB of guest memory */
@@ -67,41 +68,62 @@ void hmp_migrationmode(Monitor *mon, const QDict *qdict)
     }
 }
 
-void hmp_info_cmma(Monitor *mon, const QDict *qdict)
+TargetHumanReadableText *qmp_x_query_cmma(int64_t addr,
+                                          bool has_count,
+                                          int64_t count,
+                                          Error **errp)
 {
+    TargetHumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
     S390StAttribState *sas = s390_get_stattrib_device();
     S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
-    uint64_t addr = qdict_get_int(qdict, "addr");
-    uint64_t buflen = qdict_get_try_int(qdict, "count", 8);
-    uint8_t *vals;
+    g_autofree uint8_t *vals = NULL;
     int cx, len;
 
-    vals = g_try_malloc(buflen);
+    vals = g_try_malloc(count);
     if (!vals) {
-        monitor_printf(mon, "Error: %s\n", strerror(errno));
-        return;
+        error_setg_errno(errp, errno, "cannot allocate CMMA attribute values");
+        return NULL;
     }
 
-    len = sac->peek_stattr(sas, addr / TARGET_PAGE_SIZE, buflen, vals);
+    len = sac->peek_stattr(sas, addr / TARGET_PAGE_SIZE, count, vals);
     if (len < 0) {
-        monitor_printf(mon, "Error: %s", strerror(-len));
-        goto out;
+        error_setg_errno(errp, -len, "cannot peek at CMMA attribute values");
+        return NULL;
     }
 
-    monitor_printf(mon, "  CMMA attributes, "
-                   "pages %" PRIu64 "+%d (0x%" PRIx64 "):\n",
-                   addr / TARGET_PAGE_SIZE, len, addr & ~TARGET_PAGE_MASK);
+    g_string_append_printf(buf, "  CMMA attributes, "
+                           "pages %" PRIu64 "+%d (0x%" PRIx64 "):\n",
+                           addr / TARGET_PAGE_SIZE, len,
+                           addr & ~TARGET_PAGE_MASK);
     for (cx = 0; cx < len; cx++) {
         if (cx % 8 == 7) {
-            monitor_printf(mon, "%02x\n", vals[cx]);
+            g_string_append_printf(buf, "%02x\n", vals[cx]);
         } else {
-            monitor_printf(mon, "%02x", vals[cx]);
+            g_string_append_printf(buf, "%02x", vals[cx]);
         }
     }
-    monitor_printf(mon, "\n");
+    g_string_append_printf(buf, "\n");
+
+    ret = g_new0(TargetHumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
+void hmp_info_cmma(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    g_autoptr(TargetHumanReadableText) info = NULL;
+    uint64_t addr = qdict_get_int(qdict, "addr");
+    uint64_t count = qdict_get_try_int(qdict, "count", 8);
+
+    info = qmp_x_query_cmma(addr, true, count, &err);
+    if (err) {
+        error_report_err(err);
+        return;
+    }
 
-out:
-    g_free(vals);
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 /* Migration support: */
qapi/machine-target.json +14 -0
index 00476bcdd4..9040aff863 100644
@@ -355,6 +355,20 @@
   'data': { 'human-readable-text': 'str' },
   'if': 'TARGET_S390X' }
 
+##
+# @x-query-cmma:
+#
+# Query the values of the CMMA storage attributes for a range of pages
+#
+# Returns: CMMA storage attribute values
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-cmma',
+  'data': { 'addr': 'int', '*count': 'int' },
+  'returns': 'TargetHumanReadableText',
+  'if': 'TARGET_S390X' }
+
 ##
 # @x-query-skeys:
 #
Signature · 1 line
2.31.1
#81 lore raw

PATCH v2 38/53 qapi: introduce x-query-lapic QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info lapic" 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. The existing HMP command is rewritten to call the QMP command.

This command is unable to use the pre-existing HumanReadableText, because if 'common.json' is included into 'machine-target.json' the static marshalling method for HumanReadableText will be reported as unused by the compiler on all architectures except s390x.

Possible options were

1 Support 'if' conditionals on 'include' statements in QAPI 2 Add further commands to 'machine-target.json' that use
HumanReadableText, such that it has at least one usage on all architecture targets.
3 Duplicate HumanReadableText as TargetHumanReadableText
adding conditions

This patch takes option (3) in the belief that we will eventually get to a point where option (2) happens, and TargetHumanReadableText can be removed again.

---
 hw/core/cpu-common.c     |   7 ++
 include/hw/core/cpu.h    |  10 +++
 qapi/machine-target.json |  19 ++++-
 target/i386/cpu-dump.c   | 161 ++++++++++++++++++++-------------------
 target/i386/cpu.h        |   4 +-
 target/i386/monitor.c    |  46 +++++++++--
 6 files changed, 160 insertions(+), 87 deletions(-)
hw/core/cpu-common.c +7 -0
index c2cd33a817..d1ebc77d1b 100644
@@ -49,6 +49,13 @@ CPUState *cpu_by_arch_id(int64_t id)
     return NULL;
 }
 
+int64_t cpu_get_arch_id(CPUState *cpu)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+
+    return cc->get_arch_id(cpu);
+}
+
 bool cpu_exists(int64_t id)
 {
     return !!cpu_by_arch_id(id);
include/hw/core/cpu.h +10 -0
index 1599ef9df3..a0913eedaa 100644
@@ -780,6 +780,16 @@ bool cpu_exists(int64_t id);
  */
 CPUState *cpu_by_arch_id(int64_t id);
 
+/**
+ * cpu_get_arch_id:
+ * @cpu: the CPU to query
+ *
+ * Get the guest exposed CPU ID for @cpu
+ *
+ * Returns: The guest exposed CPU ID
+ */
+int64_t cpu_get_arch_id(CPUState *cpu);
+
 /**
  * cpu_interrupt:
  * @cpu: The CPU to set an interrupt on.
qapi/machine-target.json +18 -1
index 9040aff863..62220d1f08 100644
@@ -353,7 +353,8 @@
 ##
 { 'struct': 'TargetHumanReadableText',
   'data': { 'human-readable-text': 'str' },
-  'if': 'TARGET_S390X' }
+  'if': { 'any': ['TARGET_S390X',
+                  'TARGET_I386' ] } }
 
 ##
 # @x-query-cmma:
@@ -369,6 +370,22 @@
   'returns': 'TargetHumanReadableText',
   'if': 'TARGET_S390X' }
 
+##
+# @x-query-lapic:
+#
+# @apic-id: the local APIC ID to report
+#
+# Query local APIC state.
+#
+# Returns: local APIC state
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-lapic',
+  'data': { 'apic-id': 'int' },
+  'returns': 'TargetHumanReadableText',
+  'if': 'TARGET_I386' }
+
 ##
 # @x-query-skeys:
 #
target/i386/cpu-dump.c +84 -77

233 lines not on this page · raw message

target/i386/cpu.h +3 -1
index d87c8808f6..2bcb175da8 100644
@@ -2201,8 +2201,10 @@ void x86_cpu_set_default_version(X86CPUVersion version);
 #define APIC_DEFAULT_ADDRESS 0xfee00000
 #define APIC_SPACE_SIZE      0x100000
 
+#ifndef CONFIG_USER_ONLY
 /* cpu-dump.c */
-void x86_cpu_dump_local_apic_state(CPUState *cs, int flags);
+GString *x86_cpu_format_local_apic_state(CPUState *cs, int flags, Error **errp);
+#endif /* !CONFIG_USER_ONLY */
 
 /* cpu.c */
 bool cpu_is_bsp(X86CPU *cpu);
target/i386/monitor.c +38 -8

67 lines not on this page · raw message

Signature · 1 line
2.31.1
#84 lore raw

PATCH v2 39/53 qapi: introduce x-query-irq QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info irq" 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. The existing HMP command is rewritten to call the QMP command.

This command is unable to use the pre-existing HumanReadableText, because if 'common.json' is included into 'machine-target.json' the static marshalling method for HumanReadableText will be reported as unused by the compiler on all architectures except s390x.

Possible options were

1 Support 'if' conditionals on 'include' statements in QAPI 2 Add further commands to 'machine-target.json' that use
HumanReadableText, such that it has at least one usage on all architecture targets.
3 Duplicate HumanReadableText as TargetHumanReadableText
adding conditions

This patch takes option (3) in the belief that we will eventually get to a point where option (2) happens, and TargetHumanReadableText can be removed again.

---
 monitor/hmp-cmds.c | 40 ++++++++-------------------------------
 monitor/qmp-cmds.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 qapi/machine.json  | 12 ++++++++++++
 3 files changed, 67 insertions(+), 32 deletions(-)
monitor/hmp-cmds.c +8 -32
index 77533b2d8a..eb2202329d 100644
@@ -784,42 +784,18 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
     }
 }
 
-static int hmp_info_irq_foreach(Object *obj, void *opaque)
+void hmp_info_irq(Monitor *mon, const QDict *qdict)
 {
-    InterruptStatsProvider *intc;
-    InterruptStatsProviderClass *k;
-    Monitor *mon = opaque;
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = NULL;
 
-    if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
-        intc = INTERRUPT_STATS_PROVIDER(obj);
-        k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
-        uint64_t *irq_counts;
-        unsigned int nb_irqs, i;
-        if (k->get_statistics &&
-            k->get_statistics(intc, &irq_counts, &nb_irqs)) {
-            if (nb_irqs > 0) {
-                monitor_printf(mon, "IRQ statistics for %s:\n",
-                               object_get_typename(obj));
-                for (i = 0; i < nb_irqs; i++) {
-                    if (irq_counts[i] > 0) {
-                        monitor_printf(mon, "%2d: %" PRId64 "\n", i,
-                                       irq_counts[i]);
-                    }
-                }
-            }
-        } else {
-            monitor_printf(mon, "IRQ statistics not available for %s.\n",
-                           object_get_typename(obj));
-        }
+    info = qmp_x_query_irq(&err);
+    if (err) {
+        error_report_err(err);
+        return;
     }
 
-    return 0;
-}
-
-void hmp_info_irq(Monitor *mon, const QDict *qdict)
-{
-    object_child_foreach_recursive(object_get_root(),
-                                   hmp_info_irq_foreach, mon);
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 static int hmp_info_pic_foreach(Object *obj, void *opaque)
monitor/qmp-cmds.c +47 -0

56 lines not on this page · raw message

qapi/machine.json +12 -0
index 3ae7beb7cf..e72b47ea7d 100644
@@ -1313,6 +1313,18 @@
      '*threads': 'int',
      '*maxcpus': 'int' } }
 
+##
+# @x-query-irq:
+#
+# Query interrupt statistics
+#
+# Returns: interrupt statistics
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-irq',
+  'returns': 'HumanReadableText' }
+
 ##
 # @x-query-numa:
 #
Signature · 1 line
2.31.1
#85 lore raw

PATCH v2 40/53 hw/core: drop "dump_state" callback from CPU targets

In reply to Daniel P. Berrangé

All targets are now converted to the "format_state" callback.

---
 hw/core/cpu-common.c  | 14 +++-----------
 include/hw/core/cpu.h |  2 --
 2 files changed, 3 insertions(+), 13 deletions(-)
hw/core/cpu-common.c +3 -11
index d1ebc77d1b..494f4f41eb 100644
@@ -108,17 +108,9 @@ static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg)
 
 void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
 {
-    CPUClass *cc = CPU_GET_CLASS(cpu);
-
-    if (cc->dump_state) {
-        cpu_synchronize_state(cpu);
-        cc->dump_state(cpu, f, flags);
-    } else if (cc->format_state) {
-        g_autoptr(GString) buf = g_string_new("");
-        cpu_synchronize_state(cpu);
-        cc->format_state(cpu, buf, flags);
-        qemu_fprintf(f, "%s", buf->str);
-    }
+    g_autoptr(GString) buf = g_string_new("");
+    cpu_format_state(cpu, buf, flags);
+    qemu_fprintf(f, "%s", buf->str);
 }
 
 void cpu_format_state(CPUState *cpu, GString *buf, int flags)
include/hw/core/cpu.h +0 -2
index a0913eedaa..9cfc7d7479 100644
@@ -91,7 +91,6 @@ 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. 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
@@ -136,7 +135,6 @@ struct CPUClass {
     bool (*has_work)(CPUState *cpu);
     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);
Signature · 1 line
2.31.1
#86 lore raw

PATCH v2 41/53 hw/core: drop support for NULL pointer for FILE * in cpu_dump_state

In reply to Daniel P. Berrangé

The monitor is converted to use cpu_format_state, so the only remaining users of cpu_dump_state all pass a non-NULL pointer for the FILE * parameter.

---
 hw/core/cpu-common.c  | 2 +-
 include/hw/core/cpu.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/core/cpu-common.c +1 -1
index 494f4f41eb..ffd9b9e07e 100644
@@ -110,7 +110,7 @@ void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
 {
     g_autoptr(GString) buf = g_string_new("");
     cpu_format_state(cpu, buf, flags);
-    qemu_fprintf(f, "%s", buf->str);
+    fprintf(f, "%s", buf->str);
 }
 
 void cpu_format_state(CPUState *cpu, GString *buf, int flags)
include/hw/core/cpu.h +1 -1
index 9cfc7d7479..4c47e1df18 100644
@@ -531,7 +531,7 @@ enum CPUDumpFlags {
 /**
  * cpu_dump_state:
  * @cpu: The CPU whose state is to be dumped.
- * @f: If non-null, dump to this stream, else to current print sink.
+ * @f: dump to this stream
  *
  * Dumps CPU state.
  */
Signature · 1 line
2.31.1
#87 lore raw

PATCH v2 42/53 hw/core: introduce a 'format_tlb' callback

In reply to Daniel P. Berrangé

This will allow us to reduce duplication between the different targets implementing the 'info tlb' command.

---
 hw/core/cpu-common.c  |  9 +++++++++
 include/hw/core/cpu.h | 11 +++++++++++
 2 files changed, 20 insertions(+)
hw/core/cpu-common.c +9 -0
index ffd9b9e07e..9b11ec3c8d 100644
@@ -123,6 +123,15 @@ void cpu_format_state(CPUState *cpu, GString *buf, int flags)
     }
 }
 
+void cpu_format_tlb(CPUState *cpu, GString *buf)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+
+    if (cc->format_tlb) {
+        cc->format_tlb(cpu, buf);
+    }
+}
+
 void cpu_reset(CPUState *cpu)
 {
     device_cold_reset(DEVICE(cpu));
include/hw/core/cpu.h +11 -0
index 4c47e1df18..64fc57c8d9 100644
@@ -92,6 +92,7 @@ struct SysemuCPUOps;
  * @has_work: Callback for checking if there is work to do.
  * @memory_rw_debug: Callback for GDB memory access.
  * @format_state: Callback for formatting state.
+ * @format_tlb: Callback for formatting memory mappings
  * @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 (*format_state)(CPUState *cpu, GString *buf, int flags);
+    void (*format_tlb)(CPUState *cpu, GString *buf);
     int64_t (*get_arch_id)(CPUState *cpu);
     void (*set_pc)(CPUState *cpu, vaddr value);
     int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
@@ -546,6 +548,15 @@ void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
  */
 void cpu_format_state(CPUState *cpu, GString *buf, int flags);
 
+/**
+ * cpu_format_tlb:
+ * @cpu: The CPU whose memory mappings are to be formatted.
+ * @buf: buffer to format state into
+ *
+ * Formats the memory mappings
+ */
+void cpu_format_tlb(CPUState *cpu, GString *buf);
+
 #ifndef CONFIG_USER_ONLY
 /**
  * cpu_get_phys_page_attrs_debug:
Signature · 1 line
2.31.1
#92 lore raw

PATCH v2 43/53 target/i386: convert to use format_tlb callback

In reply to Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/i386/cpu.c     |   3 ++
 target/i386/cpu.h     |   1 +
 target/i386/monitor.c | 107 +++++++++++++++++++++++-------------------
 3 files changed, 63 insertions(+), 48 deletions(-)
target/i386/cpu.c +3 -0
index 0a5c6a6d19..ab86224ee2 100644
@@ -6765,6 +6765,9 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->parse_features = x86_cpu_parse_featurestr;
     cc->has_work = x86_cpu_has_work;
     cc->format_state = x86_cpu_format_state;
+#ifndef CONFIG_USER_ONLY
+    cc->format_tlb = x86_cpu_format_tlb;
+#endif
     cc->set_pc = x86_cpu_set_pc;
     cc->gdb_read_register = x86_cpu_gdb_read_register;
     cc->gdb_write_register = x86_cpu_gdb_write_register;
target/i386/cpu.h +1 -0
index 2bcb175da8..d61eeef617 100644
@@ -1826,6 +1826,7 @@ void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
                                 Error **errp);
 
 void x86_cpu_format_state(CPUState *cs, GString *buf, int flags);
+void x86_cpu_format_tlb(CPUState *cpu, GString *buf);
 
 hwaddr x86_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
                                          MemTxAttrs *attrs);
target/i386/monitor.c +59 -48

209 lines not on this page · raw message

Signature · 1 line
2.31.1
#93 lore raw

PATCH v2 44/53 target/m68k: convert to use format_tlb callback

In reply to Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/m68k/cpu.c     |   3 +
 target/m68k/cpu.h     |   3 +-
 target/m68k/helper.c  | 132 ++++++++++++++++++++++--------------------
 target/m68k/monitor.c |  11 +++-
 4 files changed, 82 insertions(+), 67 deletions(-)
target/m68k/cpu.c +3 -0
index 4ccf572a68..8f143eb540 100644
@@ -537,6 +537,9 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
     cc->class_by_name = m68k_cpu_class_by_name;
     cc->has_work = m68k_cpu_has_work;
     cc->format_state = m68k_cpu_format_state;
+#ifndef CONFIG_USER_ONLY
+    cc->format_tlb = m68k_cpu_format_tlb;
+#endif
     cc->set_pc = m68k_cpu_set_pc;
     cc->gdb_read_register = m68k_cpu_gdb_read_register;
     cc->gdb_write_register = m68k_cpu_gdb_write_register;
target/m68k/cpu.h +1 -2
index b0641f6d0d..f2d777a1ba 100644
@@ -169,6 +169,7 @@ struct M68kCPU {
 void m68k_cpu_do_interrupt(CPUState *cpu);
 bool m68k_cpu_exec_interrupt(CPUState *cpu, int int_req);
 void m68k_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void m68k_cpu_format_tlb(CPUState *cpu, GString *buf);
 hwaddr m68k_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
@@ -612,6 +613,4 @@ static inline void cpu_get_tb_cpu_state(CPUM68KState *env, target_ulong *pc,
     }
 }
 
-void dump_mmu(CPUM68KState *env);
-
 #endif
target/m68k/helper.c +70 -62

235 lines not on this page · raw message

target/m68k/monitor.c +8 -3
index 2bdf6acae0..003a665246 100644
@@ -9,17 +9,22 @@
 #include "cpu.h"
 #include "monitor/hmp-target.h"
 #include "monitor/monitor.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-machine-target.h"
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env1 = mon_get_cpu_env(mon);
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env1) {
+    if (!cpu) {
         monitor_printf(mon, "No CPU available\n");
         return;
     }
 
-    dump_mmu(env1);
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
 
 static const MonitorDef monitor_defs[] = {
Signature · 1 line
2.31.1
#95 lore raw

PATCH v2 45/53 target/nios2: convert to use format_tlb callback

In reply to Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/nios2/cpu.c     |  3 +++
 target/nios2/cpu.h     |  2 +-
 target/nios2/mmu.c     | 37 +++++++++++++++++++------------------
 target/nios2/monitor.c | 12 ++++++++++--
 4 files changed, 33 insertions(+), 21 deletions(-)
target/nios2/cpu.c +3 -0
index cbf15fb1c9..60162ee692 100644
@@ -242,6 +242,9 @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = nios2_cpu_class_by_name;
     cc->has_work = nios2_cpu_has_work;
     cc->format_state = nios2_cpu_format_state;
+#ifndef CONFIG_USER_ONLY
+    cc->format_tlb = nios2_cpu_format_tlb;
+#endif
     cc->set_pc = nios2_cpu_set_pc;
     cc->disas_set_info = nios2_cpu_disas_set_info;
 #ifndef CONFIG_USER_ONLY
target/nios2/cpu.h +1 -1
index 3b16cd1f3c..1167872bd9 100644
@@ -194,8 +194,8 @@ struct Nios2CPU {
 void nios2_tcg_init(void);
 void nios2_cpu_do_interrupt(CPUState *cs);
 int cpu_nios2_signal_handler(int host_signum, void *pinfo, void *puc);
-void dump_mmu(CPUNios2State *env);
 void nios2_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void nios2_cpu_format_tlb(CPUState *cpu, GString *buf);
 hwaddr nios2_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 void nios2_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
                                    MMUAccessType access_type,
target/nios2/mmu.c +19 -18
index 2545c06761..1c7d3b34c3 100644
@@ -252,29 +252,30 @@ void mmu_init(CPUNios2State *env)
     mmu->tlb = g_new0(Nios2TLBEntry, cpu->tlb_num_entries);
 }
 
-void dump_mmu(CPUNios2State *env)
+void nios2_cpu_format_tlb(CPUState *cpu, GString *buf)
 {
-    Nios2CPU *cpu = env_archcpu(env);
+    CPUNios2State *env = cpu->env_ptr;
+    Nios2CPU *ncpu = env_archcpu(env);
     int i;
 
-    qemu_printf("MMU: ways %d, entries %d, pid bits %d\n",
-                cpu->tlb_num_ways, cpu->tlb_num_entries,
-                cpu->pid_num_bits);
+    g_string_append_printf(buf, "MMU: ways %d, entries %d, pid bits %d\n",
+                           ncpu->tlb_num_ways, ncpu->tlb_num_entries,
+                           ncpu->pid_num_bits);
 
-    for (i = 0; i < cpu->tlb_num_entries; i++) {
+    for (i = 0; i < ncpu->tlb_num_entries; i++) {
         Nios2TLBEntry *entry = &env->mmu.tlb[i];
-        qemu_printf("TLB[%d] = %08X %08X %c VPN %05X "
-                    "PID %02X %c PFN %05X %c%c%c%c\n",
-                    i, entry->tag, entry->data,
-                    (entry->tag & (1 << 10)) ? 'V' : '-',
-                    entry->tag >> 12,
-                    entry->tag & ((1 << cpu->pid_num_bits) - 1),
-                    (entry->tag & (1 << 11)) ? 'G' : '-',
-                    entry->data & CR_TLBACC_PFN_MASK,
-                    (entry->data & CR_TLBACC_C) ? 'C' : '-',
-                    (entry->data & CR_TLBACC_R) ? 'R' : '-',
-                    (entry->data & CR_TLBACC_W) ? 'W' : '-',
-                    (entry->data & CR_TLBACC_X) ? 'X' : '-');
+        g_string_append_printf(buf, "TLB[%d] = %08X %08X %c VPN %05X "
+                               "PID %02X %c PFN %05X %c%c%c%c\n",
+                               i, entry->tag, entry->data,
+                               (entry->tag & (1 << 10)) ? 'V' : '-',
+                               entry->tag >> 12,
+                               entry->tag & ((1 << ncpu->pid_num_bits) - 1),
+                               (entry->tag & (1 << 11)) ? 'G' : '-',
+                               entry->data & CR_TLBACC_PFN_MASK,
+                               (entry->data & CR_TLBACC_C) ? 'C' : '-',
+                               (entry->data & CR_TLBACC_R) ? 'R' : '-',
+                               (entry->data & CR_TLBACC_W) ? 'W' : '-',
+                               (entry->data & CR_TLBACC_X) ? 'X' : '-');
     }
 }
 
target/nios2/monitor.c +10 -2
index 0152dec3fa..99d35e8ef1 100644
@@ -29,7 +29,15 @@
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env1 = mon_get_cpu_env(mon);
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    dump_mmu(env1);
+    if (!cpu) {
+        monitor_printf(mon, "No CPU available\n");
+        return;
+    }
+
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
Signature · 1 line
2.31.1
#96 lore raw

PATCH v2 46/53 target/ppc: convert to use format_tlb callback

In reply to Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/ppc/cpu.h        |   3 +-
 target/ppc/cpu_init.c   |   3 +
 target/ppc/mmu-hash64.c |   8 +-
 target/ppc/mmu-hash64.h |   2 +-
 target/ppc/mmu_common.c | 167 ++++++++++++++++++++++------------------
 target/ppc/monitor.c    |  10 ++-
 6 files changed, 107 insertions(+), 86 deletions(-)
target/ppc/cpu.h +1 -2
index c84ae29b98..37b44bfbc3 100644
@@ -1257,6 +1257,7 @@ DECLARE_OBJ_CHECKERS(PPCVirtualHypervisor, PPCVirtualHypervisorClass,
 void ppc_cpu_do_interrupt(CPUState *cpu);
 bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req);
 void ppc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void ppc_cpu_format_tlb(CPUState *cpu, GString *buf);
 hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
@@ -2667,8 +2668,6 @@ static inline bool ppc_interrupts_little_endian(PowerPCCPU *cpu)
     return false;
 }
 
-void dump_mmu(CPUPPCState *env);
-
 void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len);
 void ppc_store_vscr(CPUPPCState *env, uint32_t vscr);
 uint32_t ppc_get_vscr(CPUPPCState *env);
target/ppc/cpu_init.c +3 -0
index 3456be465c..98d6f40a49 100644
@@ -9044,6 +9044,9 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = ppc_cpu_class_by_name;
     cc->has_work = ppc_cpu_has_work;
     cc->format_state = ppc_cpu_format_state;
+#ifndef CONFIG_USER_ONLY
+    cc->format_tlb = ppc_cpu_format_tlb;
+#endif
     cc->set_pc = ppc_cpu_set_pc;
     cc->gdb_read_register = ppc_cpu_gdb_read_register;
     cc->gdb_write_register = ppc_cpu_gdb_write_register;
target/ppc/mmu-hash64.c +4 -4
index 19832c4b46..73927a0819 100644
@@ -80,7 +80,7 @@ static ppc_slb_t *slb_lookup(PowerPCCPU *cpu, target_ulong eaddr)
     return NULL;
 }
 
-void dump_slb(PowerPCCPU *cpu)
+void dump_slb(PowerPCCPU *cpu, GString *buf)
 {
     CPUPPCState *env = &cpu->env;
     int i;
@@ -88,15 +88,15 @@ void dump_slb(PowerPCCPU *cpu)
 
     cpu_synchronize_state(CPU(cpu));
 
-    qemu_printf("SLB\tESID\t\t\tVSID\n");
+    g_string_append_printf(buf, "SLB\tESID\t\t\tVSID\n");
     for (i = 0; i < cpu->hash64_opts->slb_size; i++) {
         slbe = env->slb[i].esid;
         slbv = env->slb[i].vsid;
         if (slbe == 0 && slbv == 0) {
             continue;
         }
-        qemu_printf("%d\t0x%016" PRIx64 "\t0x%016" PRIx64 "\n",
-                    i, slbe, slbv);
+        g_string_append_printf(buf, "%d\t0x%016" PRIx64 "\t0x%016" PRIx64 "\n",
+                               i, slbe, slbv);
     }
 }
 
target/ppc/mmu-hash64.h +1 -1
index c5b2f97ff7..99e03a5849 100644
@@ -4,7 +4,7 @@
 #ifndef CONFIG_USER_ONLY
 
 #ifdef TARGET_PPC64
-void dump_slb(PowerPCCPU *cpu);
+void dump_slb(PowerPCCPU *cpu, GString *buf);
 int ppc_store_slb(PowerPCCPU *cpu, target_ulong slot,
                   target_ulong esid, target_ulong vsid);
 bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
target/ppc/mmu_common.c +91 -76

280 lines not on this page · raw message

target/ppc/monitor.c +7 -3
index a475108b2d..401a36c2eb 100644
@@ -67,13 +67,17 @@ static target_long monitor_get_tbl(Monitor *mon, const struct MonitorDef *md,
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env1 = mon_get_cpu_env(mon);
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env1) {
+    if (!cpu) {
         monitor_printf(mon, "No CPU available\n");
         return;
     }
-    dump_mmu(env1);
+
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
 
 const MonitorDef monitor_defs[] = {
Signature · 1 line
2.31.1
#98 lore raw

PATCH v2 47/53 target/sh4: convert to use format_tlb callback

In reply to Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/sh4/cpu.c     |  3 +++
 target/sh4/cpu.h     |  1 +
 target/sh4/monitor.c | 48 +++++++++++++++++++++++++++-----------------
 3 files changed, 34 insertions(+), 18 deletions(-)
target/sh4/cpu.c +3 -0
index 0ac881d6af..0e49755b2a 100644
@@ -260,6 +260,9 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = superh_cpu_class_by_name;
     cc->has_work = superh_cpu_has_work;
     cc->format_state = superh_cpu_format_state;
+#ifndef CONFIG_USER_ONLY
+    cc->format_tlb = superh_cpu_format_tlb;
+#endif
     cc->set_pc = superh_cpu_set_pc;
     cc->gdb_read_register = superh_cpu_gdb_read_register;
     cc->gdb_write_register = superh_cpu_gdb_write_register;
target/sh4/cpu.h +1 -0
index 6940ca417a..7c139f561c 100644
@@ -207,6 +207,7 @@ struct SuperHCPU {
 void superh_cpu_do_interrupt(CPUState *cpu);
 bool superh_cpu_exec_interrupt(CPUState *cpu, int int_req);
 void superh_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void superh_cpu_format_tlb(CPUState *cpu, GString *buf);
 hwaddr superh_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/sh4/monitor.c +30 -18

62 lines not on this page · raw message

Signature · 1 line
2.31.1
#99 lore raw

PATCH v2 48/53 target/sparc: convert to use format_tlb callback

In reply to Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/sparc/cpu.c        |  1 +
 target/sparc/cpu.h        |  1 +
 target/sparc/mmu_helper.c | 43 ++++++++++++++++++++++++---------------
 target/sparc/monitor.c    | 10 ++++++---
 4 files changed, 36 insertions(+), 19 deletions(-)
target/sparc/cpu.c +1 -0
index 9346a79239..f78ddc72b5 100644
@@ -898,6 +898,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)
     cc->has_work = sparc_cpu_has_work;
     cc->format_state = sparc_cpu_format_state;
 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
+    cc->format_tlb = sparc_cpu_format_tlb;
     cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
 #endif
     cc->set_pc = sparc_cpu_set_pc;
target/sparc/cpu.h +1 -0
index 65a01a7884..233f0b3eb7 100644
@@ -572,6 +572,7 @@ extern const VMStateDescription vmstate_sparc_cpu;
 
 void sparc_cpu_do_interrupt(CPUState *cpu);
 void sparc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void sparc_cpu_format_tlb(CPUState *cpu, GString *buf);
 hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/sparc/mmu_helper.c +27 -16

70 lines not on this page · raw message

target/sparc/monitor.c +7 -3
index 318413686a..cc7fe74e3e 100644
@@ -30,13 +30,17 @@
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env1 = mon_get_cpu_env(mon);
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env1) {
+    if (!cpu) {
         monitor_printf(mon, "No CPU available\n");
         return;
     }
-    dump_mmu(env1);
+
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
 
 #ifndef TARGET_SPARC64
Signature · 1 line
2.31.1
#101 lore raw

PATCH v2 49/53 target/xtensa: convert to use format_tlb callback

In reply to Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/xtensa/cpu.h        |   2 +-
 target/xtensa/mmu_helper.c | 126 +++++++++++++++++++++----------------
 target/xtensa/monitor.c    |  10 ++-
 3 files changed, 79 insertions(+), 59 deletions(-)
target/xtensa/cpu.h +1 -1
index 97cd6892df..8c82994826 100644
@@ -573,6 +573,7 @@ void xtensa_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
                                       int mmu_idx, MemTxAttrs attrs,
                                       MemTxResult response, uintptr_t retaddr);
 void xtensa_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void xtensa_cpu_format_tlb(CPUState *cpu, GString *buf);
 hwaddr xtensa_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 void xtensa_count_regs(const XtensaConfig *config,
                        unsigned *n_regs, unsigned *n_core_regs);
@@ -678,7 +679,6 @@ int xtensa_get_physical_addr(CPUXtensaState *env, bool update_tlb,
         uint32_t vaddr, int is_write, int mmu_idx,
         uint32_t *paddr, uint32_t *page_size, unsigned *access);
 void reset_mmu(CPUXtensaState *env);
-void dump_mmu(CPUXtensaState *env);
 
 static inline MemoryRegion *xtensa_get_er_region(CPUXtensaState *env)
 {
target/xtensa/mmu_helper.c +71 -55

175 lines not on this page · raw message

target/xtensa/monitor.c +7 -3
index fbf60d5553..99d35e8ef1 100644
@@ -29,11 +29,15 @@
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env1 = mon_get_cpu_env(mon);
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env1) {
+    if (!cpu) {
         monitor_printf(mon, "No CPU available\n");
         return;
     }
-    dump_mmu(env1);
+
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
Signature · 1 line
2.31.1
#103 lore raw

PATCH v2 50/53 monitor: merge duplicate "info tlb" handlers

In reply to Daniel P. Berrangé

Now that all target architectures are converted to use the "format_tlb" callback, we can merge all the duplicate "info tlb" handlers into one and remove the architecture condition on the command.

---
 hmp-commands-info.hx         |  3 ---
 include/monitor/hmp-target.h |  1 -
 monitor/misc.c               | 15 +++++++++++++++
 target/i386/monitor.c        | 15 ---------------
 target/m68k/monitor.c        | 15 ---------------
 target/nios2/monitor.c       | 15 ---------------
 target/ppc/monitor.c         | 15 ---------------
 target/sh4/monitor.c         | 15 ---------------
 target/sparc/monitor.c       | 16 ----------------
 target/xtensa/monitor.c      | 15 ---------------
 10 files changed, 15 insertions(+), 110 deletions(-)
hmp-commands-info.hx +0 -3
index f8312342cd..7bd1e04d46 100644
@@ -206,8 +206,6 @@ SRST
     Show PCI information.
 ERST
 
-#if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \
-    defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K)
     {
         .name       = "tlb",
         .args_type  = "",
@@ -215,7 +213,6 @@ ERST
         .help       = "show virtual to physical memory mappings",
         .cmd        = hmp_info_tlb,
     },
-#endif
 
 SRST
   ``info tlb``
include/monitor/hmp-target.h +0 -1
index df79ad3355..04e02e8895 100644
@@ -45,7 +45,6 @@ CPUArchState *mon_get_cpu_env(Monitor *mon);
 CPUState *mon_get_cpu(Monitor *mon);
 
 void hmp_info_mem(Monitor *mon, const QDict *qdict);
-void hmp_info_tlb(Monitor *mon, const QDict *qdict);
 void hmp_mce(Monitor *mon, const QDict *qdict);
 void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
 
monitor/misc.c +15 -0
index 6b07efdddd..c7d138914d 100644
@@ -936,6 +936,21 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
     mtree_info(flatview, dispatch_tree, owner, disabled);
 }
 
+static void hmp_info_tlb(Monitor *mon, const QDict *qdict)
+{
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
+
+    if (!cpu) {
+        monitor_printf(mon, "No CPU available\n");
+        return;
+    }
+
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
+}
+
 static void hmp_info_profile(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
target/i386/monitor.c +0 -15
index 698fbbc80b..a7eb4205c7 100644
@@ -248,21 +248,6 @@ void x86_cpu_format_tlb(CPUState *cpu, GString *buf)
     }
 }
 
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
-
 static void mem_print(Monitor *mon, CPUArchState *env,
                       hwaddr *pstart, int *plast_prot,
                       hwaddr end, int prot)
target/m68k/monitor.c +0 -15
index 003a665246..0dc729692b 100644
@@ -12,21 +12,6 @@
 #include "qapi/error.h"
 #include "qapi/qapi-commands-machine-target.h"
 
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
-
 static const MonitorDef monitor_defs[] = {
     { "d0", offsetof(CPUM68KState, dregs[0]) },
     { "d1", offsetof(CPUM68KState, dregs[1]) },
target/nios2/monitor.c +0 -15
index 99d35e8ef1..1180a32f80 100644
@@ -26,18 +26,3 @@
 #include "monitor/monitor.h"
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
-
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
target/ppc/monitor.c +0 -15
index 401a36c2eb..3564fd5f45 100644
@@ -65,21 +65,6 @@ static target_long monitor_get_tbl(Monitor *mon, const struct MonitorDef *md,
     return cpu_ppc_load_tbl(env);
 }
 
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
-
 const MonitorDef monitor_defs[] = {
     { "fpscr", offsetof(CPUPPCState, fpscr) },
     /* Next instruction pointer */
target/sh4/monitor.c +0 -15
index 5ccb95af93..d641d95316 100644
@@ -53,18 +53,3 @@ void superh_cpu_format_tlb(CPUState *cpu, GString *buf)
         print_tlb(buf, i, &env->utlb[i]);
     }
 }
-
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
target/sparc/monitor.c +0 -16
index cc7fe74e3e..0c51669c08 100644
@@ -27,22 +27,6 @@
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
-
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
-
 #ifndef TARGET_SPARC64
 static target_long monitor_get_psr(Monitor *mon, const struct MonitorDef *md,
                                    int val)
target/xtensa/monitor.c +0 -15
index 99d35e8ef1..1180a32f80 100644
@@ -26,18 +26,3 @@
 #include "monitor/monitor.h"
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
-
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
Signature · 1 line
2.31.1
#105 lore raw

PATCH v2 51/53 qapi: introduce x-query-tlb QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info tlb" command. It is being added with an "x-" prefix because this QMP command is intended as an ad hoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.

---
 hw/core/machine-qmp-cmds.c | 22 ++++++++++++++++++++++
 monitor/misc.c             | 15 ++++++++++-----
 qapi/machine.json          | 15 +++++++++++++++
 3 files changed, 47 insertions(+), 5 deletions(-)
hw/core/machine-qmp-cmds.c +22 -0
index 4407e967da..c84cef8667 100644
@@ -235,6 +235,28 @@ HumanReadableText *qmp_x_query_registers(bool has_cpu, int64_t cpu,
     return ret;
 }
 
+HumanReadableText *qmp_x_query_tlb(int64_t cpu, Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cs = NULL, *tmp;
+
+    CPU_FOREACH(tmp) {
+        if (cpu == tmp->cpu_index) {
+            cs = tmp;
+        }
+    }
+    if (!cs) {
+        error_setg(errp, "CPU %"PRId64" not available", cpu);
+        return NULL;
+    }
+    cpu_format_tlb(cs, buf);
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
 HumanReadableText *qmp_x_query_numa(Error **errp)
 {
     HumanReadableText *ret;
monitor/misc.c +10 -5
index c7d138914d..7ca529002d 100644
@@ -938,17 +938,22 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
 
 static void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
+    CPUState *cs = mon_get_cpu(mon);
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = NULL;
 
-    if (!cpu) {
+    if (!cs) {
         monitor_printf(mon, "No CPU available\n");
         return;
     }
 
-    cpu_format_tlb(cpu, buf);
+    info = qmp_x_query_tlb(cs->cpu_index, &err);
+    if (err) {
+        error_report_err(err);
+        return;
+    }
 
-    monitor_printf(mon, "%s", buf->str);
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 static void hmp_info_profile(Monitor *mon, const QDict *qdict)
qapi/machine.json +15 -0
index e72b47ea7d..0f537a58e0 100644
@@ -1400,6 +1400,21 @@
 { 'command': 'x-query-roms',
   'returns': 'HumanReadableText' }
 
+##
+# @x-query-tlb:
+#
+# @cpu: the CPU number to query
+#
+# Return information on the CPU memory mappings
+#
+# Returns: memory mappings in an architecture-specific format
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-tlb',
+  'data': {'cpu': 'int' },
+  'returns': 'HumanReadableText' }
+
 ##
 # @x-query-usb:
 #
Signature · 1 line
2.31.1
#106 lore raw

PATCH v2 52/53 qapi: introduce x-query-jit QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info jit" command. It is being added with an "x-" prefix because this QMP command is intended as an ad hoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.

---
 accel/tcg/cpu-exec.c       | 39 +++++++++++++----
 accel/tcg/hmp.c            | 13 ++++--
 accel/tcg/translate-all.c  | 80 ++++++++++++++++++----------------
 include/exec/cpu-all.h     |  4 +-
 include/tcg/tcg.h          |  2 +-
 qapi/machine.json          | 13 ++++++
 tcg/tcg.c                  | 88 ++++++++++++++++++++------------------
 tests/qtest/qmp-cmd-test.c |  2 +
 8 files changed, 148 insertions(+), 93 deletions(-)
accel/tcg/cpu-exec.c +30 -9
index e5c0ccd1a2..6d27fb62f9 100644
@@ -20,6 +20,8 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/qemu-print.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-machine.h"
 #include "hw/core/tcg-cpu-ops.h"
 #include "trace.h"
 #include "disas/disas.h"
@@ -38,6 +40,7 @@
 #include "exec/cpu-all.h"
 #include "sysemu/cpu-timers.h"
 #include "sysemu/replay.h"
+#include "sysemu/tcg.h"
 #include "exec/helper-proto.h"
 #include "tb-hash.h"
 #include "tb-context.h"
@@ -1011,23 +1014,41 @@ void tcg_exec_unrealizefn(CPUState *cpu)
 
 #ifndef CONFIG_USER_ONLY
 
-void dump_drift_info(void)
+void dump_drift_info(GString *buf)
 {
     if (!icount_enabled()) {
         return;
     }
 
-    qemu_printf("Host - Guest clock  %"PRIi64" ms\n",
-                (cpu_get_clock() - icount_get()) / SCALE_MS);
+    g_string_append_printf(buf, "Host - Guest clock  %"PRIi64" ms\n",
+                           (cpu_get_clock() - icount_get()) / SCALE_MS);
     if (icount_align_option) {
-        qemu_printf("Max guest delay     %"PRIi64" ms\n",
-                    -max_delay / SCALE_MS);
-        qemu_printf("Max guest advance   %"PRIi64" ms\n",
-                    max_advance / SCALE_MS);
+        g_string_append_printf(buf, "Max guest delay     %"PRIi64" ms\n",
+                               -max_delay / SCALE_MS);
+        g_string_append_printf(buf, "Max guest advance   %"PRIi64" ms\n",
+                               max_advance / SCALE_MS);
     } else {
-        qemu_printf("Max guest delay     NA\n");
-        qemu_printf("Max guest advance   NA\n");
+        g_string_append_printf(buf, "Max guest delay     NA\n");
+        g_string_append_printf(buf, "Max guest advance   NA\n");
     }
 }
 
+HumanReadableText *qmp_x_query_jit(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+
+    if (!tcg_enabled()) {
+        error_setg(errp, "JIT information is only available with accel=tcg");
+        return NULL;
+    }
+
+    dump_exec_info(buf);
+    dump_drift_info(buf);
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
 #endif /* !CONFIG_USER_ONLY */
accel/tcg/hmp.c +9 -4
index a6e72fdb3e..9d7bcd9185 100644
@@ -1,18 +1,23 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-machine.h"
 #include "exec/exec-all.h"
 #include "monitor/monitor.h"
 #include "sysemu/tcg.h"
 
 static void hmp_info_jit(Monitor *mon, const QDict *qdict)
 {
-    if (!tcg_enabled()) {
-        error_report("JIT information is only available with accel=tcg");
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = NULL;
+
+    info = qmp_x_query_jit(&err);
+    if (err) {
+        error_report_err(err);
         return;
     }
 
-    dump_exec_info();
-    dump_drift_info();
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
accel/tcg/translate-all.c +44 -36

127 lines not on this page · raw message

include/exec/cpu-all.h +2 -2
index 32cfb634c6..d92f6fa7a9 100644
@@ -429,9 +429,9 @@ static inline bool tlb_hit(target_ulong tlb_addr, target_ulong addr)
 
 #ifdef CONFIG_TCG
 /* accel/tcg/cpu-exec.c */
-void dump_drift_info(void);
+void dump_drift_info(GString *buf);
 /* accel/tcg/translate-all.c */
-void dump_exec_info(void);
+void dump_exec_info(GString *buf);
 void dump_opcount_info(void);
 #endif /* CONFIG_TCG */
 
include/tcg/tcg.h +1 -1
index 44ccd86f3e..1b56e382b7 100644
@@ -943,7 +943,7 @@ int tcg_check_temp_count(void);
 #endif
 
 int64_t tcg_cpu_exec_time(void);
-void tcg_dump_info(void);
+void tcg_dump_info(GString *buf);
 void tcg_dump_op_count(void);
 
 #define TCG_CT_CONST  1 /* any constant of register size */
qapi/machine.json +13 -0
index 0f537a58e0..e88aba1199 100644
@@ -1325,6 +1325,19 @@
 { 'command': 'x-query-irq',
   'returns': 'HumanReadableText' }
 
+##
+# @x-query-jit:
+#
+# Query TCG compiler statistics
+#
+# Returns: TCG compiler statistics
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-jit',
+  'returns': 'HumanReadableText',
+  'if': 'CONFIG_TCG' }
+
 ##
 # @x-query-numa:
 #
tcg/tcg.c +47 -41

107 lines not on this page · raw message

tests/qtest/qmp-cmd-test.c +2 -0
index 15875a14c6..6aa628691a 100644
@@ -51,6 +51,8 @@ static int query_error_class(const char *cmd)
 #endif
         /* Only valid with a USB bus added */
         { "x-query-usb", ERROR_CLASS_GENERIC_ERROR },
+        /* Only valid with accel=tcg */
+        { "x-query-jit", ERROR_CLASS_GENERIC_ERROR },
         { NULL, -1 }
     };
     int i;
Signature · 1 line
2.31.1
#107 lore raw

PATCH v2 53/53 qapi: introduce x-query-opcount QMP command

In reply to Daniel P. Berrangé

This is a counterpart to the HMP "info opcount" command. It is being added with an "x-" prefix because this QMP command is intended as an ad hoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.

---
 accel/tcg/cpu-exec.c       | 17 +++++++++++++++++
 accel/tcg/hmp.c            | 11 ++++++++++-
 accel/tcg/translate-all.c  |  4 ++--
 include/exec/cpu-all.h     |  2 +-
 include/tcg/tcg.h          |  2 +-
 qapi/machine.json          | 13 +++++++++++++
 tcg/tcg.c                  | 10 +++++-----
 tests/qtest/qmp-cmd-test.c |  1 +
 8 files changed, 50 insertions(+), 10 deletions(-)
accel/tcg/cpu-exec.c +17 -0
index 6d27fb62f9..613f6fa5be 100644
@@ -1051,4 +1051,21 @@ HumanReadableText *qmp_x_query_jit(Error **errp)
     return ret;
 }
 
+HumanReadableText *qmp_x_query_opcount(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+
+    if (!tcg_enabled()) {
+        error_setg(errp, "JIT information is only available with accel=tcg");
+        return NULL;
+    }
+
+    dump_opcount_info(buf);
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
 #endif /* !CONFIG_USER_ONLY */
accel/tcg/hmp.c +10 -1
index 9d7bcd9185..9b049d1e76 100644
@@ -22,7 +22,16 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
 
 static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
 {
-    dump_opcount_info();
+    Error *err = NULL;
+    g_autoptr(HumanReadableText) info = NULL;
+
+    info = qmp_x_query_opcount(&err);
+    if (err) {
+        error_report_err(err);
+        return;
+    }
+
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 static void hmp_tcg_register(void)
accel/tcg/translate-all.c +2 -2
index 9c3dbe4409..7a8121e70a 100644
@@ -2141,9 +2141,9 @@ void dump_exec_info(GString *buf)
     tcg_dump_info(buf);
 }
 
-void dump_opcount_info(void)
+void dump_opcount_info(GString *buf)
 {
-    tcg_dump_op_count();
+    tcg_dump_op_count(buf);
 }
 
 #else /* CONFIG_USER_ONLY */
include/exec/cpu-all.h +1 -1
index d92f6fa7a9..3c8e24292b 100644
@@ -432,7 +432,7 @@ static inline bool tlb_hit(target_ulong tlb_addr, target_ulong addr)
 void dump_drift_info(GString *buf);
 /* accel/tcg/translate-all.c */
 void dump_exec_info(GString *buf);
-void dump_opcount_info(void);
+void dump_opcount_info(GString *buf);
 #endif /* CONFIG_TCG */
 
 #endif /* !CONFIG_USER_ONLY */
include/tcg/tcg.h +1 -1
index 1b56e382b7..cc7f59070b 100644
@@ -944,7 +944,7 @@ int tcg_check_temp_count(void);
 
 int64_t tcg_cpu_exec_time(void);
 void tcg_dump_info(GString *buf);
-void tcg_dump_op_count(void);
+void tcg_dump_op_count(GString *buf);
 
 #define TCG_CT_CONST  1 /* any constant of register size */
 
qapi/machine.json +13 -0
index e88aba1199..bb24146a40 100644
@@ -1350,6 +1350,19 @@
 { 'command': 'x-query-numa',
   'returns': 'HumanReadableText' }
 
+##
+# @x-query-opcount:
+#
+# Query TCG opcode counters
+#
+# Returns: TCG opcode counters
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-opcount',
+  'returns': 'HumanReadableText',
+  'if': 'CONFIG_TCG' }
+
 ##
 # @x-query-profile:
 #
tcg/tcg.c +5 -5
index 7fcdfd9c0f..d9653990af 100644
@@ -4115,15 +4115,15 @@ static void tcg_profile_snapshot_table(TCGProfile *prof)
     tcg_profile_snapshot(prof, false, true);
 }
 
-void tcg_dump_op_count(void)
+void tcg_dump_op_count(GString *buf)
 {
     TCGProfile prof = {};
     int i;
 
     tcg_profile_snapshot_table(&prof);
     for (i = 0; i < NB_OPS; i++) {
-        qemu_printf("%s %" PRId64 "\n", tcg_op_defs[i].name,
-                    prof.table_op_count[i]);
+        g_string_append_printf(buf, "%s %" PRId64 "\n", tcg_op_defs[i].name,
+                               prof.table_op_count[i]);
     }
 }
 
@@ -4142,9 +4142,9 @@ int64_t tcg_cpu_exec_time(void)
     return ret;
 }
 #else
-void tcg_dump_op_count(void)
+void tcg_dump_op_count(GString *buf)
 {
-    qemu_printf("[TCG profiler not compiled]\n");
+    g_string_append_printf(buf, "[TCG profiler not compiled]\n");
 }
 
 int64_t tcg_cpu_exec_time(void)
tests/qtest/qmp-cmd-test.c +1 -0
index 6aa628691a..251a14ddf7 100644
@@ -53,6 +53,7 @@ static int query_error_class(const char *cmd)
         { "x-query-usb", ERROR_CLASS_GENERIC_ERROR },
         /* Only valid with accel=tcg */
         { "x-query-jit", ERROR_CLASS_GENERIC_ERROR },
+        { "x-query-opcount", ERROR_CLASS_GENERIC_ERROR },
         { NULL, -1 }
     };
     int i;
Signature · 1 line
2.31.1
Reviewed-by on v2 11/53
#26 lore raw

RE: [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method

In reply to Daniel P. Berrangé
Quoted 36 lines

-----Original Message-----
From: Daniel P. Berrangé <[email protected]>
Subject: [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method

This method isn't used in any code and its functionality is already available via the 'info registers' HMP command.

---
 target/hexagon/cpu.c      | 5 -----
 target/hexagon/internal.h | 1 -
 2 files changed, 6 deletions(-)
target/hexagon/cpu.c index renamed from target/hexagon/cpu.c +0 -0

3338365c16..14c628db7a 100644

target/hexagon/cpu.c +0 -4
@@ -169,11 +169,6 @@ static void hexagon_dump_state(CPUState *cs, FILE
 *f, int flags)
     hexagon_dump(env, f);
 }
 
-void hexagon_debug(CPUHexagonState *env) -{
-    hexagon_dump(env, stdout);
-}
-
 static void hexagon_cpu_set_pc(CPUState *cs, vaddr value)  {
     HexagonCPU *cpu = HEXAGON_CPU(cs);
target/hexagon/internal.h index renamed from target/hexagon/internal.h +0 -0

6b20affdfa..167e91026a 100644

target/hexagon/internal.h line 35

Quoted 6 lines
target/hexagon/internal.h +0 -1
@@ -31,7 +31,6 @@
 
 int hexagon_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
 int hexagon_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
-void hexagon_debug(CPUHexagonState *env);
 
 extern const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS];
Reviewed-by on v2 28/53
#66 lore raw

Re: [PATCH v2 28/53] monitor: remove 'info ioapic' HMP command

In reply to Daniel P. Berrangé
Quoted 6 lines · Daniel P. Berrangé

This command was turned into a no-op four years ago in

commit 0c8465440d50c18a7bb13d0a866748f0593e193a
Author: Peter Xu <[email protected]>
Date: Fri Dec 29 15:31:04 2017 +0800

Quoted 8 lines

hmp: obsolete "info ioapic"

---
 hmp-commands-info.hx         | 15 ---------------
 include/monitor/hmp-target.h |  1 -
 target/i386/monitor.c        |  6 ------
 3 files changed, 22 deletions(-)
Reviewed-by on v2 6/53
#14 lore raw

Re: [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state'

In reply to Daniel P. Berrangé
Quoted 10 lines · Daniel P. Berrangé

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.

---
 hw/core/cpu-common.c  | 15 +++++++++++++++
 include/hw/core/cpu.h | 13 ++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)
#88 lore raw

Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback

In reply to Daniel P. Berrangé
Quoted 21 lines · Daniel P. Berrangé

This will allow us to reduce duplication between the different targets implementing the 'info tlb' command.

---
 hw/core/cpu-common.c  |  9 +++++++++
 include/hw/core/cpu.h | 11 +++++++++++
 2 files changed, 20 insertions(+)
include/hw/core/cpu.h +1 -0
index 4c47e1df18..64fc57c8d9 100644
  * @has_work: Callback for checking if there is work to do.
  * @memory_rw_debug: Callback for GDB memory access.
  * @format_state: Callback for formatting state.
+ * @format_tlb: Callback for formatting memory mappings
  * @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

include/hw/core/cpu.h struct CPUClass { · line 140

Quoted 4 lines
include/hw/core/cpu.h +1 -0
@@ -136,6 +137,7 @@ struct CPUClass {
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                            uint8_t *buf, int len, bool is_write);
     void (*format_state)(CPUState *cpu, GString *buf, int flags);
+    void (*format_tlb)(CPUState *cpu, GString *buf);

Doesn't this belong to SysemuCPUOps?

#68 lore raw

Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command

In reply to Daniel P. Berrangé
Quoted 11 lines · Daniel P. Berrangé

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 ad hoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.

---

+++ b/qapi/common.json

qapi/common.json line 206

Quoted 10 lines
qapi/common.json +7 -0
@@ -197,3 +197,14 @@
 { 'enum': 'GrabToggleKeys',
   'data': [ 'ctrl-ctrl', 'alt-alt', 'shift-shift','meta-meta', 'scrolllock',
             'ctrl-scrolllock' ] }
+
+##
+# @HumanReadableText:
+#
+# @human-readable-text: Formatted output intended for humans.
+#
+# Since: 6.2.0

Should be '6.2', not '6.2.0', to match...

Quoted 13 lines
qapi/common.json +4 -0
+#
+##
+{ 'struct': 'HumanReadableText',
+  'data': { 'human-readable-text': 'str' } }
qapi/machine.json +1 -0
index 157712f006..8737efa865 100644
@@ -1312,3 +1312,18 @@
      '*cores': 'int',
      '*threads': 'int',
      '*maxcpus': 'int' } }
+

qapi/machine.json line 1325

Quoted 10 lines
qapi/machine.json +10 -0
+##
+# @x-query-registers:
+#
+# @cpu: the CPU number to query. If omitted, queries all CPUs
+#
+# Query information on the CPU registers
+#
+# Returns: CPU state in an architecture-specific format
+#
+# Since: 6.2

...the prevailing style.

If it were likely that someone might backport just some (but not all) added x- commands, it may be wise to separate the creation of HumanReadableText into its own patch to backport that but not x-query-registers. But I rather suspect anyone backporting this will take the series wholesale, so the coupling in this patch is not worth worrying about.

Quoted 7 lines
qapi/machine.json +4 -0
+##
+{ 'command': 'x-query-registers',
+  'data': {'*cpu': 'int' },
+  'returns': 'HumanReadableText' }
Signature · 1 line
2.31.1
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#72 lore raw

Re: [PATCH v2 30/53] qapi: introduce x-query-roms QMP command

In reply to Daniel P. Berrangé
Quoted 52 lines · Daniel P. Berrangé

This is a counterpart to the HMP "info roms" 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. The existing HMP command is rewritten to call the QMP command.

---
 hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
 qapi/machine.json | 12 +++++++++++
 2 files changed, 50 insertions(+), 17 deletions(-)
hw/core/loader.c +16 -17
-void hmp_info_roms(Monitor *mon, const QDict *qdict)
+HumanReadableText *qmp_x_query_roms(Error **errp)
 {
     Rom *rom;
+    g_autoptr(GString) buf = g_string_new("");
+    HumanReadableText *ret;
 
     QTAILQ_FOREACH(rom, &roms, next) {
         if (rom->mr) {
-            monitor_printf(mon, "%s"
-                           " size=0x%06zx name=\"%s\"\n",
-                           memory_region_name(rom->mr),
-                           rom->romsize,
-                           rom->name);
+            g_string_append_printf(buf, "%s"
+                                   " size=0x%06zx name=\"%s\"\n",
+                                   memory_region_name(rom->mr),
+                                   rom->romsize,
+                                   rom->name);
         } else if (!rom->fw_file) {
-            monitor_printf(mon, "addr=" TARGET_FMT_plx
-                           " size=0x%06zx mem=%s name=\"%s\"\n",
-                           rom->addr, rom->romsize,
-                           rom->isrom ? "rom" : "ram",
-                           rom->name);
+            g_string_append_printf(buf, "addr=" TARGET_FMT_plx
+                                   " size=0x%06zx mem=%s name=\"%s\"\n",
+                                   rom->addr, rom->romsize,
+                                   rom->isrom ? "rom" : "ram",
+                                   rom->name);
         } else {
-            monitor_printf(mon, "fw=%s/%s"
-                           " size=0x%06zx name=\"%s\"\n",
-                           rom->fw_dir,
-                           rom->fw_file,
-                           rom->romsize,
-                           rom->name);
+            g_string_append_printf(buf, "fw=%s/%s"
+                                   " size=0x%06zx name=\"%s\"\n",
+                                   rom->fw_dir,

hw/core/loader.c void *rom_ptr_for_as(AddressSpace *as, hwaddr addr, size_t size) · line 1508

Quoted 10 lines
hw/core/loader.c +8 -0
+                                   rom->fw_file,
+                                   rom->romsize,
+                                   rom->name);
         }
     }
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}

Is it possible to have an helper in 'qapi/qmp/smth.h' such:

HumanReadableText *qmp_human_readable_text_new(GString **pbuf)

{
    HumanReadableText *ret = g_new0(HumanReadableText, 1);

    ret->human_readable_text = g_steal_pointer(pbuf);

    return ret;
}

?

#89 lore raw

Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback

In reply to Philippe Mathieu-Daudé
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Daniel P. Berrangé

This will allow us to reduce duplication between the different targets implementing the 'info tlb' command.

---
 hw/core/cpu-common.c  |  9 +++++++++
 include/hw/core/cpu.h | 11 +++++++++++
 2 files changed, 20 insertions(+)
include/hw/core/cpu.h +1 -0
index 4c47e1df18..64fc57c8d9 100644
  * @has_work: Callback for checking if there is work to do.
  * @memory_rw_debug: Callback for GDB memory access.
  * @format_state: Callback for formatting state.
+ * @format_tlb: Callback for formatting memory mappings
  * @get_arch_id: Callback for getting architecture-dependent CPU ID.
  * @set_pc: Callback for setting the Program Counter register. This
Quoted 8 lines

include/hw/core/cpu.h struct CPUClass { · line 140

Quoted 6 lines

* should have the semantics used by the target architecture when

include/hw/core/cpu.h +1 -0
@@ -136,6 +137,7 @@ struct CPUClass {
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                            uint8_t *buf, int len, bool is_write);
     void (*format_state)(CPUState *cpu, GString *buf, int flags);
+    void (*format_tlb)(CPUState *cpu, GString *buf);

Doesn't this belong to SysemuCPUOps?

I can't really answer, since my knowledge of this area of QEMU code is fairly mimimal. I put it here because it is basically serving the same purpose as the "format_state" callback immediately above it, which was a rename of the existing "dump_state" callback. I assumed whatever was there already was a good practice to follow[1]...

Regards,
Daniel

[1] yes assuming these things is often foolish in QEMU :-)

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#73 lore raw

Re: [PATCH v2 30/53] qapi: introduce x-query-roms QMP command

In reply to Philippe Mathieu-Daudé
Quoted 66 lines · Philippe Mathieu-Daudé
Quoted 52 lines · Daniel P. Berrangé

This is a counterpart to the HMP "info roms" 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. The existing HMP command is rewritten to call the QMP command.

---
 hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
 qapi/machine.json | 12 +++++++++++
 2 files changed, 50 insertions(+), 17 deletions(-)
hw/core/loader.c +16 -17
-void hmp_info_roms(Monitor *mon, const QDict *qdict)
+HumanReadableText *qmp_x_query_roms(Error **errp)
 {
     Rom *rom;
+    g_autoptr(GString) buf = g_string_new("");
+    HumanReadableText *ret;
 
     QTAILQ_FOREACH(rom, &roms, next) {
         if (rom->mr) {
-            monitor_printf(mon, "%s"
-                           " size=0x%06zx name=\"%s\"\n",
-                           memory_region_name(rom->mr),
-                           rom->romsize,
-                           rom->name);
+            g_string_append_printf(buf, "%s"
+                                   " size=0x%06zx name=\"%s\"\n",
+                                   memory_region_name(rom->mr),
+                                   rom->romsize,
+                                   rom->name);
         } else if (!rom->fw_file) {
-            monitor_printf(mon, "addr=" TARGET_FMT_plx
-                           " size=0x%06zx mem=%s name=\"%s\"\n",
-                           rom->addr, rom->romsize,
-                           rom->isrom ? "rom" : "ram",
-                           rom->name);
+            g_string_append_printf(buf, "addr=" TARGET_FMT_plx
+                                   " size=0x%06zx mem=%s name=\"%s\"\n",
+                                   rom->addr, rom->romsize,
+                                   rom->isrom ? "rom" : "ram",
+                                   rom->name);
         } else {
-            monitor_printf(mon, "fw=%s/%s"
-                           " size=0x%06zx name=\"%s\"\n",
-                           rom->fw_dir,
-                           rom->fw_file,
-                           rom->romsize,
-                           rom->name);
+            g_string_append_printf(buf, "fw=%s/%s"
+                                   " size=0x%06zx name=\"%s\"\n",
+                                   rom->fw_dir,

hw/core/loader.c void *rom_ptr_for_as(AddressSpace *as, hwaddr addr, size_t size) · line 1508

Quoted 10 lines
hw/core/loader.c +8 -0
+                                   rom->fw_file,
+                                   rom->romsize,
+                                   rom->name);
         }
     }
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}

Is it possible to have an helper in 'qapi/qmp/smth.h' such:

Quoted 5 lines

HumanReadableText *qmp_human_readable_text_new(GString **pbuf)

{
    HumanReadableText *ret = g_new0(HumanReadableText, 1);

    ret->human_readable_text = g_steal_pointer(pbuf);

NB, we're not stealing the GString, we're stealing the char * inside it.

Quoted 3 lines
    return ret;
}

but yes, we could do a helper like this.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#90 lore raw

Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback

In reply to Daniel P. Berrangé
Quoted 11 lines · Daniel P. Berrangé
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Daniel P. Berrangé

This will allow us to reduce duplication between the different targets implementing the 'info tlb' command.

---
 hw/core/cpu-common.c  |  9 +++++++++
 include/hw/core/cpu.h | 11 +++++++++++
 2 files changed, 20 insertions(+)
Quoted 8 lines
Quoted 8 lines

include/hw/core/cpu.h

Quoted 8 lines
include/hw/core/cpu.h +1 -0
index 4c47e1df18..64fc57c8d9 100644
  * @has_work: Callback for checking if there is work to do.
  * @memory_rw_debug: Callback for GDB memory access.
  * @format_state: Callback for formatting state.
+ * @format_tlb: Callback for formatting memory mappings

"... for formatting translations of virtual to physical memory mappings"

Quoted 11 lines
Quoted 10 lines

include/hw/core/cpu.h struct CPUClass { · line 140

Quoted 8 lines

* @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

include/hw/core/cpu.h +1 -0
@@ -136,6 +137,7 @@ struct CPUClass {
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                            uint8_t *buf, int len, bool is_write);
     void (*format_state)(CPUState *cpu, GString *buf, int flags);
+    void (*format_tlb)(CPUState *cpu, GString *buf);

Doesn't this belong to SysemuCPUOps?

Quoted 5 lines

I can't really answer, since my knowledge of this area of QEMU code is fairly mimimal. I put it here because it is basically serving the same purpose as the "format_state" callback immediately above it, which was a rename of the existing "dump_state" callback. I assumed whatever was there already was a good practice to follow[1]...

Since it involves physical memory, I'm pretty sure this is sysemu specific. Beside in the following patches you guard the handlers with '#ifndef CONFIG_USER_ONLY'.

Good news, there is very few changes needed in your patches, for example the next patch:

-- >8 --

target/i386/cpu.c +1 -0
index ab86224ee23..9d2bd2e2ef4 100644
@@ -6732,6 +6732,7 @@ static Property x86_cpu_properties[] = {
 #include "hw/core/sysemu-cpu-ops.h"
 
 static const struct SysemuCPUOps i386_sysemu_ops = {
+    .format_tlb = x86_cpu_format_tlb,
     .get_memory_mapping = x86_cpu_get_memory_mapping,
     .get_paging_enabled = x86_cpu_get_paging_enabled,
     .get_phys_page_attrs_debug = x86_cpu_get_phys_page_attrs_debug,
@@ -6765,9 +6766,6 @@ static void x86_cpu_common_class_init(ObjectClass

*oc, void *data)

     cc->parse_features = x86_cpu_parse_featurestr;
     cc->has_work = x86_cpu_has_work;
     cc->format_state = x86_cpu_format_state;
-#ifndef CONFIG_USER_ONLY
-    cc->format_tlb = x86_cpu_format_tlb;
-#endif
     cc->set_pc = x86_cpu_set_pc;
     cc->gdb_read_register = x86_cpu_gdb_read_register;
     cc->gdb_write_register = x86_cpu_gdb_write_register;

---

Quoted 6 lines

Regards,
Daniel

[1] yes assuming these things is often foolish in QEMU :-)

#91 lore raw

Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback

Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Daniel P. Berrangé
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Daniel P. Berrangé

This will allow us to reduce duplication between the different targets implementing the 'info tlb' command.

---
 hw/core/cpu-common.c  |  9 +++++++++
 include/hw/core/cpu.h | 11 +++++++++++
 2 files changed, 20 insertions(+)
Quoted 8 lines
Quoted 8 lines

include/hw/core/cpu.h

Quoted 8 lines
include/hw/core/cpu.h +1 -0
index 4c47e1df18..64fc57c8d9 100644
  * @has_work: Callback for checking if there is work to do.
  * @memory_rw_debug: Callback for GDB memory access.
  * @format_state: Callback for formatting state.
+ * @format_tlb: Callback for formatting memory mappings

"... for formatting translations of virtual to physical memory mappings"

Quoted 11 lines
Quoted 10 lines

include/hw/core/cpu.h struct CPUClass { · line 140

Quoted 8 lines

* @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

include/hw/core/cpu.h +1 -0
@@ -136,6 +137,7 @@ struct CPUClass {
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                            uint8_t *buf, int len, bool is_write);
     void (*format_state)(CPUState *cpu, GString *buf, int flags);
+    void (*format_tlb)(CPUState *cpu, GString *buf);

Doesn't this belong to SysemuCPUOps?

Quoted 5 lines

I can't really answer, since my knowledge of this area of QEMU code is fairly mimimal. I put it here because it is basically serving the same purpose as the "format_state" callback immediately above it, which was a rename of the existing "dump_state" callback. I assumed whatever was there already was a good practice to follow[1]...

Quoted 6 lines

Since it involves physical memory, I'm pretty sure this is sysemu specific. Beside in the following patches you guard the handlers with '#ifndef CONFIG_USER_ONLY'.

Good news, there is very few changes needed in your patches, for example the next patch:

.snip..

yes I see what you mean now, and agree this looks like a better approach

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#69 lore raw

Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command

In reply to Eric Blake
Quoted 45 lines · Eric Blake
Quoted 9 lines · Daniel P. Berrangé

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 ad hoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.

---

qapi/common.json line 206

Quoted 6 lines
qapi/common.json +6 -0
+##
+# @HumanReadableText:
+#
+# @human-readable-text: Formatted output intended for humans.
+#
+# Since: 6.2.0

Should be '6.2', not '6.2.0', to match...

Quoted 13 lines
qapi/common.json +4 -0
+#
+##
+{ 'struct': 'HumanReadableText',
+  'data': { 'human-readable-text': 'str' } }
qapi/machine.json +1 -0
index 157712f006..8737efa865 100644
@@ -1312,3 +1312,18 @@
      '*cores': 'int',
      '*threads': 'int',
      '*maxcpus': 'int' } }
+

qapi/machine.json line 1325

Quoted 10 lines
qapi/machine.json +10 -0
+##
+# @x-query-registers:
+#
+# @cpu: the CPU number to query. If omitted, queries all CPUs
+#
+# Query information on the CPU registers
+#
+# Returns: CPU state in an architecture-specific format
+#
+# Since: 6.2

...the prevailing style.

Quoted 6 lines

If it were likely that someone might backport just some (but not all) added x- commands, it may be wise to separate the creation of HumanReadableText into its own patch to backport that but not x-query-registers. But I rather suspect anyone backporting this will take the series wholesale, so the coupling in this patch is not worth worrying about.

IIUC the problem is this breaks bisection, as you get a QAPI error:

qapi/qapi-commands-machine.c:123:13: error:
‘qmp_marshal_output_HumanReadableText’
defined but not used [-Werror=unused-function]
123 | static void
qmp_marshal_output_HumanReadableText(HumanReadableText *ret_in,

      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

See the comment added in commit 1f7b9f3181e ("qapi/commands: add #if conditions to commands").

Quoted 9 lines
Quoted 8 lines
qapi/machine.json +4 -0
+##
+{ 'command': 'x-query-registers',
+  'data': {'*cpu': 'int' },
+  'returns': 'HumanReadableText' }
Signature · 1 line
2.31.1
#70 lore raw

Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command

Quoted 60 lines · Philippe Mathieu-Daudé
Quoted 45 lines · Eric Blake
Quoted 9 lines · Daniel P. Berrangé

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 ad hoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.

---

qapi/common.json line 206

Quoted 6 lines
qapi/common.json +6 -0
+##
+# @HumanReadableText:
+#
+# @human-readable-text: Formatted output intended for humans.
+#
+# Since: 6.2.0

Should be '6.2', not '6.2.0', to match...

Quoted 13 lines
qapi/common.json +4 -0
+#
+##
+{ 'struct': 'HumanReadableText',
+  'data': { 'human-readable-text': 'str' } }
qapi/machine.json +1 -0
index 157712f006..8737efa865 100644
@@ -1312,3 +1312,18 @@
      '*cores': 'int',
      '*threads': 'int',
      '*maxcpus': 'int' } }
+

qapi/machine.json line 1325

Quoted 10 lines
qapi/machine.json +10 -0
+##
+# @x-query-registers:
+#
+# @cpu: the CPU number to query. If omitted, queries all CPUs
+#
+# Query information on the CPU registers
+#
+# Returns: CPU state in an architecture-specific format
+#
+# Since: 6.2

...the prevailing style.

Quoted 6 lines

If it were likely that someone might backport just some (but not all) added x- commands, it may be wise to separate the creation of HumanReadableText into its own patch to backport that but not x-query-registers. But I rather suspect anyone backporting this will take the series wholesale, so the coupling in this patch is not worth worrying about.

IIUC the problem is this breaks bisection, as you get a QAPI error:

qapi/qapi-commands-machine.c:123:13: error:
‘qmp_marshal_output_HumanReadableText’
defined but not used [-Werror=unused-function]
123 | static void
qmp_marshal_output_HumanReadableText(HumanReadableText *ret_in,

Quoted 5 lines
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

See the comment added in commit 1f7b9f3181e ("qapi/commands: add #if conditions to commands").

Oh we already talked about this together in this thread:
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
qapi/machine.json +4 -0
+##
+{ 'command': 'x-query-registers',
+  'data': {'*cpu': 'int' },
+  'returns': 'HumanReadableText' }
Signature · 1 line
2.31.1
Reviewed-by on v2 6/53
#15 lore raw

Re: [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state'

In reply to Daniel P. Berrangé
Quoted 7 lines · On Tue, 14 Sep 2021 15:19:55 +0100 Daniel P. Berrangé <[email protected]>…

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.

---

Quoted 68 lines
 hw/core/cpu-common.c  | 15 +++++++++++++++
 include/hw/core/cpu.h | 13 ++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)
hw/core/cpu-common.c +15 -0
index e2f5a64604..c2cd33a817 100644
@@ -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 = 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 = CPU_GET_CLASS(cpu);
+
+    if (cc->format_state) {
+        cpu_synchronize_state(cpu);
+        cc->format_state(cpu, buf, flags);
     }
 }
 
include/hw/core/cpu.h +12 -1
index bc864564ce..1599ef9df3 100644
@@ -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);
 
+/**
+ * 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:
Acked-by on v2 20/53
#47 lore raw

Re: [PATCH v2 20/53] target/ppc: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 2 lines · On Tue, 14 Sep 2021 15:20:09 +0100 Daniel P. Berrangé <[email protected]>…

---

Quoted 321 lines
 target/ppc/cpu.h      |   2 +-
 target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
 2 files changed, 126 insertions(+), 88 deletions(-)
target/ppc/cpu.h +1 -1
index 500205229c..c84ae29b98 100644
@@ -1256,7 +1256,7 @@ DECLARE_OBJ_CHECKERS(PPCVirtualHypervisor, PPCVirtualHypervisorClass,
 
 void ppc_cpu_do_interrupt(CPUState *cpu);
 bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void ppc_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void ppc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/ppc/cpu_init.c +125 -87
index ad7abc6041..3456be465c 100644
@@ -9043,7 +9043,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = ppc_cpu_class_by_name;
     cc->has_work = ppc_cpu_has_work;
-    cc->dump_state = ppc_cpu_dump_state;
+    cc->format_state = ppc_cpu_format_state;
     cc->set_pc = ppc_cpu_set_pc;
     cc->gdb_read_register = ppc_cpu_gdb_read_register;
     cc->gdb_write_register = ppc_cpu_gdb_write_register;
@@ -9104,7 +9104,7 @@ static void ppc_cpu_register_types(void)
 #endif
 }
 
-void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void ppc_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
 #define RGPL  4
 #define RFPL  4
@@ -9113,39 +9113,41 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     CPUPPCState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "
-                 TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
-                 env->nip, env->lr, env->ctr, cpu_read_xer(env),
-                 cs->cpu_index);
-    qemu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx "  HF "
-                 "%08x iidx %d didx %d\n",
-                 env->msr, env->spr[SPR_HID0], env->hflags,
-                 cpu_mmu_index(env, true), cpu_mmu_index(env, false));
+    g_string_append_printf(buf,
+                           "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "
+                           TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
+                           env->nip, env->lr, env->ctr, cpu_read_xer(env),
+                           cs->cpu_index);
+    g_string_append_printf(buf,
+                           "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx "  HF "
+                           "%08x iidx %d didx %d\n",
+                           env->msr, env->spr[SPR_HID0], env->hflags,
+                           cpu_mmu_index(env, true), cpu_mmu_index(env, false));
 #if !defined(NO_TIMER_DUMP)
-    qemu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
+    g_string_append_printf(buf, "TB %08" PRIu32 " %08" PRIu64
 #if !defined(CONFIG_USER_ONLY)
-                 " DECR " TARGET_FMT_lu
+                           " DECR " TARGET_FMT_lu
 #endif
-                 "\n",
-                 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
+                           "\n",
+                           cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
 #if !defined(CONFIG_USER_ONLY)
-                 , cpu_ppc_load_decr(env)
+                           , cpu_ppc_load_decr(env)
 #endif
         );
 #endif
     for (i = 0; i < 32; i++) {
         if ((i & (RGPL - 1)) == 0) {
-            qemu_fprintf(f, "GPR%02d", i);
+            g_string_append_printf(buf, "GPR%02d", i);
         }
-        qemu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
+        g_string_append_printf(buf, " %016" PRIx64, ppc_dump_gpr(env, i));
         if ((i & (RGPL - 1)) == (RGPL - 1)) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
-    qemu_fprintf(f, "CR ");
+    g_string_append_printf(buf, "CR ");
     for (i = 0; i < 8; i++)
-        qemu_fprintf(f, "%01x", env->crf[i]);
-    qemu_fprintf(f, "  [");
+        g_string_append_printf(buf, "%01x", env->crf[i]);
+    g_string_append_printf(buf, "  [");
     for (i = 0; i < 8; i++) {
         char a = '-';
         if (env->crf[i] & 0x08) {
@@ -9155,75 +9157,97 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         } else if (env->crf[i] & 0x02) {
             a = 'E';
         }
-        qemu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
+        g_string_append_printf(buf, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
     }
-    qemu_fprintf(f, " ]             RES " TARGET_FMT_lx "\n",
-                 env->reserve_addr);
+    g_string_append_printf(buf, " ]             RES " TARGET_FMT_lx "\n",
+                           env->reserve_addr);
 
     if (flags & CPU_DUMP_FPU) {
         for (i = 0; i < 32; i++) {
             if ((i & (RFPL - 1)) == 0) {
-                qemu_fprintf(f, "FPR%02d", i);
+                g_string_append_printf(buf, "FPR%02d", i);
             }
-            qemu_fprintf(f, " %016" PRIx64, *cpu_fpr_ptr(env, i));
+            g_string_append_printf(buf, " %016" PRIx64, *cpu_fpr_ptr(env, i));
             if ((i & (RFPL - 1)) == (RFPL - 1)) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");
             }
         }
-        qemu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
+        g_string_append_printf(buf, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
     }
 
 #if !defined(CONFIG_USER_ONLY)
-    qemu_fprintf(f, " SRR0 " TARGET_FMT_lx "  SRR1 " TARGET_FMT_lx
-                 "    PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
-                 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
-                 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
-
-    qemu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
-                 "  SPRG2 " TARGET_FMT_lx "  SPRG3 " TARGET_FMT_lx "\n",
-                 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
-                 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
-
-    qemu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
-                 "  SPRG6 " TARGET_FMT_lx "  SPRG7 " TARGET_FMT_lx "\n",
-                 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
-                 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
+    g_string_append_printf(buf, " SRR0 " TARGET_FMT_lx "  SRR1 " TARGET_FMT_lx
+                           "    PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx
+                           "\n",
+                           env->spr[SPR_SRR0], env->spr[SPR_SRR1],
+                           env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
+
+    g_string_append_printf(buf, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
+                           "  SPRG2 " TARGET_FMT_lx "  SPRG3 " TARGET_FMT_lx
+                           "\n",
+                           env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
+                           env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
+
+    g_string_append_printf(buf, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
+                           "  SPRG6 " TARGET_FMT_lx "  SPRG7 " TARGET_FMT_lx
+                           "\n",
+                           env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
+                           env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
 
 #if defined(TARGET_PPC64)
     if (env->excp_model == POWERPC_EXCP_POWER7 ||
         env->excp_model == POWERPC_EXCP_POWER8 ||
         env->excp_model == POWERPC_EXCP_POWER9 ||
         env->excp_model == POWERPC_EXCP_POWER10)  {
-        qemu_fprintf(f, "HSRR0 " TARGET_FMT_lx " HSRR1 " TARGET_FMT_lx "\n",
-                     env->spr[SPR_HSRR0], env->spr[SPR_HSRR1]);
+        g_string_append_printf(buf, "HSRR0 " TARGET_FMT_lx
+                               " HSRR1 " TARGET_FMT_lx "\n",
+                               env->spr[SPR_HSRR0], env->spr[SPR_HSRR1]);
     }
 #endif
     if (env->excp_model == POWERPC_EXCP_BOOKE) {
-        qemu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
-                     " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
-                     env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
-
-        qemu_fprintf(f, "  TCR " TARGET_FMT_lx "   TSR " TARGET_FMT_lx
-                     "    ESR " TARGET_FMT_lx "   DEAR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
-                     env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
-
-        qemu_fprintf(f, "  PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
-                     "   IVPR " TARGET_FMT_lx "   EPCR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
-                     env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
-
-        qemu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
-                     "    EPR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
-                     env->spr[SPR_BOOKE_EPR]);
+        g_string_append_printf(buf, "CSRR0 " TARGET_FMT_lx
+                               " CSRR1 " TARGET_FMT_lx
+                               " MCSRR0 " TARGET_FMT_lx
+                               " MCSRR1 " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_CSRR0],
+                               env->spr[SPR_BOOKE_CSRR1],
+                               env->spr[SPR_BOOKE_MCSRR0],
+                               env->spr[SPR_BOOKE_MCSRR1]);
+
+        g_string_append_printf(buf, "  TCR " TARGET_FMT_lx
+                               "   TSR " TARGET_FMT_lx
+                               "    ESR " TARGET_FMT_lx
+                               "   DEAR " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_TCR],
+                               env->spr[SPR_BOOKE_TSR],
+                               env->spr[SPR_BOOKE_ESR],
+                               env->spr[SPR_BOOKE_DEAR]);
+
+        g_string_append_printf(buf, "  PIR " TARGET_FMT_lx
+                               " DECAR " TARGET_FMT_lx
+                               "   IVPR " TARGET_FMT_lx
+                               "   EPCR " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_PIR],
+                               env->spr[SPR_BOOKE_DECAR],
+                               env->spr[SPR_BOOKE_IVPR],
+                               env->spr[SPR_BOOKE_EPCR]);
+
+        g_string_append_printf(buf, " MCSR " TARGET_FMT_lx
+                               " SPRG8 " TARGET_FMT_lx
+                               "    EPR " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_MCSR],
+                               env->spr[SPR_BOOKE_SPRG8],
+                               env->spr[SPR_BOOKE_EPR]);
 
         /* FSL-specific */
-        qemu_fprintf(f, " MCAR " TARGET_FMT_lx "  PID1 " TARGET_FMT_lx
-                     "   PID2 " TARGET_FMT_lx "    SVR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
-                     env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
+        g_string_append_printf(buf, " MCAR " TARGET_FMT_lx
+                               "  PID1 " TARGET_FMT_lx
+                               "   PID2 " TARGET_FMT_lx
+                               "    SVR " TARGET_FMT_lx "\n",
+                               env->spr[SPR_Exxx_MCAR],
+                               env->spr[SPR_BOOKE_PID1],
+                               env->spr[SPR_BOOKE_PID2],
+                               env->spr[SPR_E500_SVR]);
 
         /*
          * IVORs are left out as they are large and do not change often --
@@ -9233,12 +9257,13 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
 
 #if defined(TARGET_PPC64)
     if (env->flags & POWERPC_FLAG_CFAR) {
-        qemu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
+        g_string_append_printf(buf, " CFAR " TARGET_FMT_lx"\n", env->cfar);
     }
 #endif
 
     if (env->spr_cb[SPR_LPCR].name) {
-        qemu_fprintf(f, " LPCR " TARGET_FMT_lx "\n", env->spr[SPR_LPCR]);
+        g_string_append_printf(buf,
+                               " LPCR " TARGET_FMT_lx "\n", env->spr[SPR_LPCR]);
     }
 
     switch (env->mmu_model) {
@@ -9254,29 +9279,42 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     case POWERPC_MMU_3_00:
 #endif
         if (env->spr_cb[SPR_SDR1].name) { /* SDR1 Exists */
-            qemu_fprintf(f, " SDR1 " TARGET_FMT_lx " ", env->spr[SPR_SDR1]);
+            g_string_append_printf(buf, " SDR1 " TARGET_FMT_lx " ",
+                                   env->spr[SPR_SDR1]);
         }
         if (env->spr_cb[SPR_PTCR].name) { /* PTCR Exists */
-            qemu_fprintf(f, " PTCR " TARGET_FMT_lx " ", env->spr[SPR_PTCR]);
+            g_string_append_printf(buf, " PTCR " TARGET_FMT_lx " ",
+                                   env->spr[SPR_PTCR]);
         }
-        qemu_fprintf(f, "  DAR " TARGET_FMT_lx "  DSISR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_DAR], env->spr[SPR_DSISR]);
+        g_string_append_printf(buf, "  DAR " TARGET_FMT_lx "  DSISR "
+                               TARGET_FMT_lx "\n",
+                               env->spr[SPR_DAR], env->spr[SPR_DSISR]);
         break;
     case POWERPC_MMU_BOOKE206:
-        qemu_fprintf(f, " MAS0 " TARGET_FMT_lx "  MAS1 " TARGET_FMT_lx
-                     "   MAS2 " TARGET_FMT_lx "   MAS3 " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
-                     env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
-
-        qemu_fprintf(f, " MAS4 " TARGET_FMT_lx "  MAS6 " TARGET_FMT_lx
-                     "   MAS7 " TARGET_FMT_lx "    PID " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
-                     env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
-
-        qemu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
-                     " TLB1CFG " TARGET_FMT_lx "\n",
-                     env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
-                     env->spr[SPR_BOOKE_TLB1CFG]);
+        g_string_append_printf(buf, " MAS0 " TARGET_FMT_lx
+                               "  MAS1 " TARGET_FMT_lx
+                               "   MAS2 " TARGET_FMT_lx
+                               "   MAS3 " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_MAS0],
+                               env->spr[SPR_BOOKE_MAS1],
+                               env->spr[SPR_BOOKE_MAS2],
+                               env->spr[SPR_BOOKE_MAS3]);
+
+        g_string_append_printf(buf, " MAS4 " TARGET_FMT_lx
+                               "  MAS6 " TARGET_FMT_lx
+                               "   MAS7 " TARGET_FMT_lx
+                               "    PID " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_MAS4],
+                               env->spr[SPR_BOOKE_MAS6],
+                               env->spr[SPR_BOOKE_MAS7],
+                               env->spr[SPR_BOOKE_PID]);
+
+        g_string_append_printf(buf, "MMUCFG " TARGET_FMT_lx
+                               " TLB0CFG " TARGET_FMT_lx
+                               " TLB1CFG " TARGET_FMT_lx "\n",
+                               env->spr[SPR_MMUCFG],
+                               env->spr[SPR_BOOKE_TLB0CFG],
+                               env->spr[SPR_BOOKE_TLB1CFG]);
         break;
     default:
         break;
Acked-by on v2 15/53
#34 lore raw

Re: [PATCH v2 15/53] target/m68k: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé

Le 14/09/2021 à 16:20, Daniel P. Berrangé a écrit :

Quoted 153 lines
---
 target/m68k/cpu.c       |  2 +-
 target/m68k/cpu.h       |  2 +-
 target/m68k/translate.c | 92 ++++++++++++++++++++++-------------------
 3 files changed, 51 insertions(+), 45 deletions(-)
target/m68k/cpu.c +1 -1
index 72de6e9726..4ccf572a68 100644
@@ -536,7 +536,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
 
     cc->class_by_name = m68k_cpu_class_by_name;
     cc->has_work = m68k_cpu_has_work;
-    cc->dump_state = m68k_cpu_dump_state;
+    cc->format_state = m68k_cpu_format_state;
     cc->set_pc = m68k_cpu_set_pc;
     cc->gdb_read_register = m68k_cpu_gdb_read_register;
     cc->gdb_write_register = m68k_cpu_gdb_write_register;
target/m68k/cpu.h +1 -1
index 997d588911..b0641f6d0d 100644
@@ -168,7 +168,7 @@ struct M68kCPU {
 
 void m68k_cpu_do_interrupt(CPUState *cpu);
 bool m68k_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void m68k_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void m68k_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr m68k_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/m68k/translate.c +42 -43
index c34d9aed61..951bbed6bf 100644
@@ -6316,75 +6316,81 @@ static double floatx80_to_double(CPUM68KState *env, uint16_t high, uint64_t low)
     return u.d;
 }
 
-void m68k_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void m68k_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     M68kCPU *cpu = M68K_CPU(cs);
     CPUM68KState *env = &cpu->env;
     int i;
     uint16_t sr;
     for (i = 0; i < 8; i++) {
-        qemu_fprintf(f, "D%d = %08x   A%d = %08x   "
-                     "F%d = %04x %016"PRIx64"  (%12g)\n",
-                     i, env->dregs[i], i, env->aregs[i],
-                     i, env->fregs[i].l.upper, env->fregs[i].l.lower,
-                     floatx80_to_double(env, env->fregs[i].l.upper,
-                                        env->fregs[i].l.lower));
-    }
-    qemu_fprintf(f, "PC = %08x   ", env->pc);
+        g_string_append_printf(buf, "D%d = %08x   A%d = %08x   "
+                               "F%d = %04x %016"PRIx64"  (%12g)\n",
+                               i, env->dregs[i], i, env->aregs[i],
+                               i, env->fregs[i].l.upper, env->fregs[i].l.lower,
+                               floatx80_to_double(env, env->fregs[i].l.upper,
+                                                  env->fregs[i].l.lower));
+    }
+    g_string_append_printf(buf, "PC = %08x   ", env->pc);
     sr = env->sr | cpu_m68k_get_ccr(env);
-    qemu_fprintf(f, "SR = %04x T:%x I:%x %c%c %c%c%c%c%c\n",
-                 sr, (sr & SR_T) >> SR_T_SHIFT, (sr & SR_I) >> SR_I_SHIFT,
-                 (sr & SR_S) ? 'S' : 'U', (sr & SR_M) ? '%' : 'I',
-                 (sr & CCF_X) ? 'X' : '-', (sr & CCF_N) ? 'N' : '-',
-                 (sr & CCF_Z) ? 'Z' : '-', (sr & CCF_V) ? 'V' : '-',
-                 (sr & CCF_C) ? 'C' : '-');
-    qemu_fprintf(f, "FPSR = %08x %c%c%c%c ", env->fpsr,
-                 (env->fpsr & FPSR_CC_A) ? 'A' : '-',
-                 (env->fpsr & FPSR_CC_I) ? 'I' : '-',
-                 (env->fpsr & FPSR_CC_Z) ? 'Z' : '-',
-                 (env->fpsr & FPSR_CC_N) ? 'N' : '-');
-    qemu_fprintf(f, "\n                                "
-                 "FPCR =     %04x ", env->fpcr);
+    g_string_append_printf(buf, "SR = %04x T:%x I:%x %c%c %c%c%c%c%c\n",
+                           sr, (sr & SR_T) >> SR_T_SHIFT,
+                           (sr & SR_I) >> SR_I_SHIFT,
+                           (sr & SR_S) ? 'S' : 'U', (sr & SR_M) ? '%' : 'I',
+                           (sr & CCF_X) ? 'X' : '-', (sr & CCF_N) ? 'N' : '-',
+                           (sr & CCF_Z) ? 'Z' : '-', (sr & CCF_V) ? 'V' : '-',
+                           (sr & CCF_C) ? 'C' : '-');
+    g_string_append_printf(buf, "FPSR = %08x %c%c%c%c ", env->fpsr,
+                           (env->fpsr & FPSR_CC_A) ? 'A' : '-',
+                           (env->fpsr & FPSR_CC_I) ? 'I' : '-',
+                           (env->fpsr & FPSR_CC_Z) ? 'Z' : '-',
+                           (env->fpsr & FPSR_CC_N) ? 'N' : '-');
+    g_string_append_printf(buf, "\n                                "
+                           "FPCR =     %04x ", env->fpcr);
     switch (env->fpcr & FPCR_PREC_MASK) {
     case FPCR_PREC_X:
-        qemu_fprintf(f, "X ");
+        g_string_append_printf(buf, "X ");
         break;
     case FPCR_PREC_S:
-        qemu_fprintf(f, "S ");
+        g_string_append_printf(buf, "S ");
         break;
     case FPCR_PREC_D:
-        qemu_fprintf(f, "D ");
+        g_string_append_printf(buf, "D ");
         break;
     }
     switch (env->fpcr & FPCR_RND_MASK) {
     case FPCR_RND_N:
-        qemu_fprintf(f, "RN ");
+        g_string_append_printf(buf, "RN ");
         break;
     case FPCR_RND_Z:
-        qemu_fprintf(f, "RZ ");
+        g_string_append_printf(buf, "RZ ");
         break;
     case FPCR_RND_M:
-        qemu_fprintf(f, "RM ");
+        g_string_append_printf(buf, "RM ");
         break;
     case FPCR_RND_P:
-        qemu_fprintf(f, "RP ");
+        g_string_append_printf(buf, "RP ");
         break;
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
 #ifdef CONFIG_SOFTMMU
-    qemu_fprintf(f, "%sA7(MSP) = %08x %sA7(USP) = %08x %sA7(ISP) = %08x\n",
-                 env->current_sp == M68K_SSP ? "->" : "  ", env->sp[M68K_SSP],
-                 env->current_sp == M68K_USP ? "->" : "  ", env->sp[M68K_USP],
-                 env->current_sp == M68K_ISP ? "->" : "  ", env->sp[M68K_ISP]);
-    qemu_fprintf(f, "VBR = 0x%08x\n", env->vbr);
-    qemu_fprintf(f, "SFC = %x DFC %x\n", env->sfc, env->dfc);
-    qemu_fprintf(f, "SSW %08x TCR %08x URP %08x SRP %08x\n",
-                 env->mmu.ssw, env->mmu.tcr, env->mmu.urp, env->mmu.srp);
-    qemu_fprintf(f, "DTTR0/1: %08x/%08x ITTR0/1: %08x/%08x\n",
-                 env->mmu.ttr[M68K_DTTR0], env->mmu.ttr[M68K_DTTR1],
-                 env->mmu.ttr[M68K_ITTR0], env->mmu.ttr[M68K_ITTR1]);
-    qemu_fprintf(f, "MMUSR %08x, fault at %08x\n",
-                 env->mmu.mmusr, env->mmu.ar);
+    g_string_append_printf(buf, "%sA7(MSP) = %08x %sA7(USP) = %08x "
+                           "%sA7(ISP) = %08x\n",
+                           env->current_sp == M68K_SSP ?
+                           "->" : "  ", env->sp[M68K_SSP],
+                           env->current_sp == M68K_USP ?
+                           "->" : "  ", env->sp[M68K_USP],
+                           env->current_sp == M68K_ISP ?
+                           "->" : "  ", env->sp[M68K_ISP]);
+    g_string_append_printf(buf, "VBR = 0x%08x\n", env->vbr);
+    g_string_append_printf(buf, "SFC = %x DFC %x\n", env->sfc, env->dfc);
+    g_string_append_printf(buf, "SSW %08x TCR %08x URP %08x SRP %08x\n",

target/m68k/translate.c static double floatx80_to_double(CPUM68KState *env, uint16_t high, uint64_t low) · line 6396

Quoted 10 lines
target/m68k/translate.c +7 -0
+                           env->mmu.ssw, env->mmu.tcr,
+                           env->mmu.urp, env->mmu.srp);
+    g_string_append_printf(buf, "DTTR0/1: %08x/%08x ITTR0/1: %08x/%08x\n",
+                           env->mmu.ttr[M68K_DTTR0], env->mmu.ttr[M68K_DTTR1],
+                           env->mmu.ttr[M68K_ITTR0], env->mmu.ttr[M68K_ITTR1]);
+    g_string_append_printf(buf, "MMUSR %08x, fault at %08x\n",
+                           env->mmu.mmusr, env->mmu.ar);
 #endif
 }
 
Acked-by on v2 44/53
#94 lore raw

Re: [PATCH v2 44/53] target/m68k: convert to use format_tlb callback

In reply to Daniel P. Berrangé

Le 14/09/2021 à 16:20, Daniel P. Berrangé a écrit :

Quoted 307 lines

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/m68k/cpu.c     |   3 +
 target/m68k/cpu.h     |   3 +-
 target/m68k/helper.c  | 132 ++++++++++++++++++++++--------------------
 target/m68k/monitor.c |  11 +++-
 4 files changed, 82 insertions(+), 67 deletions(-)
target/m68k/cpu.c +3 -0
index 4ccf572a68..8f143eb540 100644
@@ -537,6 +537,9 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
     cc->class_by_name = m68k_cpu_class_by_name;
     cc->has_work = m68k_cpu_has_work;
     cc->format_state = m68k_cpu_format_state;
+#ifndef CONFIG_USER_ONLY
+    cc->format_tlb = m68k_cpu_format_tlb;
+#endif
     cc->set_pc = m68k_cpu_set_pc;
     cc->gdb_read_register = m68k_cpu_gdb_read_register;
     cc->gdb_write_register = m68k_cpu_gdb_write_register;
target/m68k/cpu.h +1 -2
index b0641f6d0d..f2d777a1ba 100644
@@ -169,6 +169,7 @@ struct M68kCPU {
 void m68k_cpu_do_interrupt(CPUState *cpu);
 bool m68k_cpu_exec_interrupt(CPUState *cpu, int int_req);
 void m68k_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void m68k_cpu_format_tlb(CPUState *cpu, GString *buf);
 hwaddr m68k_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
@@ -612,6 +613,4 @@ static inline void cpu_get_tb_cpu_state(CPUM68KState *env, target_ulong *pc,
     }
 }
 
-void dump_mmu(CPUM68KState *env);
-
 #endif
target/m68k/helper.c +70 -62
index 137a3e1a3d..050a27d21c 100644
@@ -25,6 +25,7 @@
 #include "exec/helper-proto.h"
 #include "fpu/softfloat.h"
 #include "qemu/qemu-print.h"
+#include "qapi/error.h"
 
 #define SIGNBIT (1u << 31)
 
@@ -483,27 +484,28 @@ void m68k_switch_sp(CPUM68KState *env)
 /* MMU: 68040 only */
 
 static void print_address_zone(uint32_t logical, uint32_t physical,
-                               uint32_t size, int attr)
+                               uint32_t size, int attr, GString *buf)
 {
-    qemu_printf("%08x - %08x -> %08x - %08x %c ",
-                logical, logical + size - 1,
-                physical, physical + size - 1,
-                attr & 4 ? 'W' : '-');
+    g_string_append_printf(buf, "%08x - %08x -> %08x - %08x %c ",
+                           logical, logical + size - 1,
+                           physical, physical + size - 1,
+                           attr & 4 ? 'W' : '-');
     size >>= 10;
     if (size < 1024) {
-        qemu_printf("(%d KiB)\n", size);
+        g_string_append_printf(buf, "(%d KiB)\n", size);
     } else {
         size >>= 10;
         if (size < 1024) {
-            qemu_printf("(%d MiB)\n", size);
+            g_string_append_printf(buf, "(%d MiB)\n", size);
         } else {
             size >>= 10;
-            qemu_printf("(%d GiB)\n", size);
+            g_string_append_printf(buf, "(%d GiB)\n", size);
         }
     }
 }
 
-static void dump_address_map(CPUM68KState *env, uint32_t root_pointer)
+static void dump_address_map(CPUM68KState *env, uint32_t root_pointer,
+                             GString *buf)
 {
     int i, j, k;
     int tic_size, tic_shift;
@@ -573,7 +575,8 @@ static void dump_address_map(CPUM68KState *env, uint32_t root_pointer)
                         size = last_logical + (1 << tic_shift) -
                                first_logical;
                         print_address_zone(first_logical,
-                                           first_physical, size, last_attr);
+                                           first_physical, size, last_attr,
+                                           buf);
                     }
                     first_logical = logical;
                     first_physical = physical;
@@ -583,125 +586,130 @@ static void dump_address_map(CPUM68KState *env, uint32_t root_pointer)
     }
     if (first_logical != logical || (attr & 4) != (last_attr & 4)) {
         size = logical + (1 << tic_shift) - first_logical;
-        print_address_zone(first_logical, first_physical, size, last_attr);
+        print_address_zone(first_logical, first_physical, size, last_attr, buf);
     }
 }
 
 #define DUMP_CACHEFLAGS(a) \
     switch (a & M68K_DESC_CACHEMODE) { \
     case M68K_DESC_CM_WRTHRU: /* cachable, write-through */ \
-        qemu_printf("T"); \
+        g_string_append_printf(buf, "T"); \
         break; \
     case M68K_DESC_CM_COPYBK: /* cachable, copyback */ \
-        qemu_printf("C"); \
+        g_string_append_printf(buf, "C"); \
         break; \
     case M68K_DESC_CM_SERIAL: /* noncachable, serialized */ \
-        qemu_printf("S"); \
+        g_string_append_printf(buf, "S"); \
         break; \
     case M68K_DESC_CM_NCACHE: /* noncachable */ \
-        qemu_printf("N"); \
+        g_string_append_printf(buf, "N"); \
         break; \
     }
 
-static void dump_ttr(uint32_t ttr)
+static void dump_ttr(uint32_t ttr, GString *buf)
 {
     if ((ttr & M68K_TTR_ENABLED) == 0) {
-        qemu_printf("disabled\n");
+        g_string_append_printf(buf, "disabled\n");
         return;
     }
-    qemu_printf("Base: 0x%08x Mask: 0x%08x Control: ",
-                ttr & M68K_TTR_ADDR_BASE,
-                (ttr & M68K_TTR_ADDR_MASK) << M68K_TTR_ADDR_MASK_SHIFT);
+    g_string_append_printf(buf, "Base: 0x%08x Mask: 0x%08x Control: ",
+                           ttr & M68K_TTR_ADDR_BASE,
+                           (ttr & M68K_TTR_ADDR_MASK) <<
+                           M68K_TTR_ADDR_MASK_SHIFT);
     switch (ttr & M68K_TTR_SFIELD) {
     case M68K_TTR_SFIELD_USER:
-        qemu_printf("U");
+        g_string_append_printf(buf, "U");
         break;
     case M68K_TTR_SFIELD_SUPER:
-        qemu_printf("S");
+        g_string_append_printf(buf, "S");
         break;
     default:
-        qemu_printf("*");
+        g_string_append_printf(buf, "*");
         break;
     }
     DUMP_CACHEFLAGS(ttr);
     if (ttr & M68K_DESC_WRITEPROT) {
-        qemu_printf("R");
+        g_string_append_printf(buf, "R");
     } else {
-        qemu_printf("W");
+        g_string_append_printf(buf, "W");
     }
-    qemu_printf(" U: %d\n", (ttr & M68K_DESC_USERATTR) >>
-                               M68K_DESC_USERATTR_SHIFT);
+    g_string_append_printf(buf, " U: %d\n", (ttr & M68K_DESC_USERATTR) >>
+                           M68K_DESC_USERATTR_SHIFT);
 }
 
-void dump_mmu(CPUM68KState *env)
+
+void m68k_cpu_format_tlb(CPUState *cpu, GString *buf)
 {
+    CPUM68KState *env = cpu->env_ptr;
+
     if ((env->mmu.tcr & M68K_TCR_ENABLED) == 0) {
-        qemu_printf("Translation disabled\n");
+        g_string_append_printf(buf, "Translation disabled\n");
         return;
     }
-    qemu_printf("Page Size: ");
+    g_string_append_printf(buf, "Page Size: ");
     if (env->mmu.tcr & M68K_TCR_PAGE_8K) {
-        qemu_printf("8kB\n");
+        g_string_append_printf(buf, "8kB\n");
     } else {
-        qemu_printf("4kB\n");
+        g_string_append_printf(buf, "4kB\n");
     }
 
-    qemu_printf("MMUSR: ");
+    g_string_append_printf(buf, "MMUSR: ");
     if (env->mmu.mmusr & M68K_MMU_B_040) {
-        qemu_printf("BUS ERROR\n");
+        g_string_append_printf(buf, "BUS ERROR\n");
     } else {
-        qemu_printf("Phy=%08x Flags: ", env->mmu.mmusr & 0xfffff000);
+        g_string_append_printf(buf, "Phy=%08x Flags: ",
+                               env->mmu.mmusr & 0xfffff000);
         /* flags found on the page descriptor */
         if (env->mmu.mmusr & M68K_MMU_G_040) {
-            qemu_printf("G"); /* Global */
+            g_string_append_printf(buf, "G"); /* Global */
         } else {
-            qemu_printf(".");
+            g_string_append_printf(buf, ".");
         }
         if (env->mmu.mmusr & M68K_MMU_S_040) {
-            qemu_printf("S"); /* Supervisor */
+            g_string_append_printf(buf, "S"); /* Supervisor */
         } else {
-            qemu_printf(".");
+            g_string_append_printf(buf, ".");
         }
         if (env->mmu.mmusr & M68K_MMU_M_040) {
-            qemu_printf("M"); /* Modified */
+            g_string_append_printf(buf, "M"); /* Modified */
         } else {
-            qemu_printf(".");
+            g_string_append_printf(buf, ".");
         }
         if (env->mmu.mmusr & M68K_MMU_WP_040) {
-            qemu_printf("W"); /* Write protect */
+            g_string_append_printf(buf, "W"); /* Write protect */
         } else {
-            qemu_printf(".");
+            g_string_append_printf(buf, ".");
         }
         if (env->mmu.mmusr & M68K_MMU_T_040) {
-            qemu_printf("T"); /* Transparent */
+            g_string_append_printf(buf, "T"); /* Transparent */
         } else {
-            qemu_printf(".");
+            g_string_append_printf(buf, ".");
         }
         if (env->mmu.mmusr & M68K_MMU_R_040) {
-            qemu_printf("R"); /* Resident */
+            g_string_append_printf(buf, "R"); /* Resident */
         } else {
-            qemu_printf(".");
+            g_string_append_printf(buf, ".");
         }
-        qemu_printf(" Cache: ");
+        g_string_append_printf(buf, " Cache: ");
         DUMP_CACHEFLAGS(env->mmu.mmusr);
-        qemu_printf(" U: %d\n", (env->mmu.mmusr >> 8) & 3);
-        qemu_printf("\n");
+        g_string_append_printf(buf, " U: %d\n", (env->mmu.mmusr >> 8) & 3);
+        g_string_append_printf(buf, "\n");
     }
 
-    qemu_printf("ITTR0: ");
-    dump_ttr(env->mmu.ttr[M68K_ITTR0]);
-    qemu_printf("ITTR1: ");
-    dump_ttr(env->mmu.ttr[M68K_ITTR1]);
-    qemu_printf("DTTR0: ");
-    dump_ttr(env->mmu.ttr[M68K_DTTR0]);
-    qemu_printf("DTTR1: ");
-    dump_ttr(env->mmu.ttr[M68K_DTTR1]);
+    g_string_append_printf(buf, "ITTR0: ");
+    dump_ttr(env->mmu.ttr[M68K_ITTR0], buf);
+    g_string_append_printf(buf, "ITTR1: ");
+    dump_ttr(env->mmu.ttr[M68K_ITTR1], buf);
+    g_string_append_printf(buf, "DTTR0: ");
+    dump_ttr(env->mmu.ttr[M68K_DTTR0], buf);
+    g_string_append_printf(buf, "DTTR1: ");
+    dump_ttr(env->mmu.ttr[M68K_DTTR1], buf);
 
-    qemu_printf("SRP: 0x%08x\n", env->mmu.srp);
-    dump_address_map(env, env->mmu.srp);
+    g_string_append_printf(buf, "SRP: 0x%08x\n", env->mmu.srp);
+    dump_address_map(env, env->mmu.srp, buf);
 
-    qemu_printf("URP: 0x%08x\n", env->mmu.urp);
-    dump_address_map(env, env->mmu.urp);
+    g_string_append_printf(buf, "URP: 0x%08x\n", env->mmu.urp);
+    dump_address_map(env, env->mmu.urp, buf);
 }
 
 static int check_TTR(uint32_t ttr, int *prot, target_ulong addr,
target/m68k/monitor.c +5 -2
index 2bdf6acae0..003a665246 100644
@@ -9,17 +9,22 @@
 #include "cpu.h"
 #include "monitor/hmp-target.h"
 #include "monitor/monitor.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-machine-target.h"
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env1 = mon_get_cpu_env(mon);
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env1) {
+    if (!cpu) {
         monitor_printf(mon, "No CPU available\n");

target/m68k/monitor.c line 30

Quoted 10 lines
target/m68k/monitor.c +3 -1
         return;
     }
 
-    dump_mmu(env1);
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
 
 static const MonitorDef monitor_defs[] = {
Acked-by on v2 50/53
#104 lore raw

Re: [PATCH v2 50/53] monitor: merge duplicate "info tlb" handlers

In reply to Daniel P. Berrangé
Quoted 5 lines · Daniel P. Berrangé

Now that all target architectures are converted to use the "format_tlb" callback, we can merge all the duplicate "info tlb" handlers into one and remove the architecture condition on the command.

ppc parts

Quoted 246 lines
---
 hmp-commands-info.hx         |  3 ---
 include/monitor/hmp-target.h |  1 -
 monitor/misc.c               | 15 +++++++++++++++
 target/i386/monitor.c        | 15 ---------------
 target/m68k/monitor.c        | 15 ---------------
 target/nios2/monitor.c       | 15 ---------------
 target/ppc/monitor.c         | 15 ---------------
 target/sh4/monitor.c         | 15 ---------------
 target/sparc/monitor.c       | 16 ----------------
 target/xtensa/monitor.c      | 15 ---------------
 10 files changed, 15 insertions(+), 110 deletions(-)
hmp-commands-info.hx +0 -3
index f8312342cd..7bd1e04d46 100644
@@ -206,8 +206,6 @@ SRST
     Show PCI information.
 ERST
 
-#if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \
-    defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K)
     {
         .name       = "tlb",
         .args_type  = "",
@@ -215,7 +213,6 @@ ERST
         .help       = "show virtual to physical memory mappings",
         .cmd        = hmp_info_tlb,
     },
-#endif
 
 SRST
   ``info tlb``
include/monitor/hmp-target.h +0 -1
index df79ad3355..04e02e8895 100644
@@ -45,7 +45,6 @@ CPUArchState *mon_get_cpu_env(Monitor *mon);
 CPUState *mon_get_cpu(Monitor *mon);
 
 void hmp_info_mem(Monitor *mon, const QDict *qdict);
-void hmp_info_tlb(Monitor *mon, const QDict *qdict);
 void hmp_mce(Monitor *mon, const QDict *qdict);
 void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
 
monitor/misc.c +15 -0
index 6b07efdddd..c7d138914d 100644
@@ -936,6 +936,21 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
     mtree_info(flatview, dispatch_tree, owner, disabled);
 }
 
+static void hmp_info_tlb(Monitor *mon, const QDict *qdict)
+{
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
+
+    if (!cpu) {
+        monitor_printf(mon, "No CPU available\n");
+        return;
+    }
+
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
+}
+
 static void hmp_info_profile(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
target/i386/monitor.c +0 -15
index 698fbbc80b..a7eb4205c7 100644
@@ -248,21 +248,6 @@ void x86_cpu_format_tlb(CPUState *cpu, GString *buf)
     }
 }
 
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
-
 static void mem_print(Monitor *mon, CPUArchState *env,
                       hwaddr *pstart, int *plast_prot,
                       hwaddr end, int prot)
target/m68k/monitor.c +0 -15
index 003a665246..0dc729692b 100644
@@ -12,21 +12,6 @@
 #include "qapi/error.h"
 #include "qapi/qapi-commands-machine-target.h"
 
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
-
 static const MonitorDef monitor_defs[] = {
     { "d0", offsetof(CPUM68KState, dregs[0]) },
     { "d1", offsetof(CPUM68KState, dregs[1]) },
target/nios2/monitor.c +0 -15
index 99d35e8ef1..1180a32f80 100644
@@ -26,18 +26,3 @@
 #include "monitor/monitor.h"
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
-
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
target/ppc/monitor.c +0 -15
index 401a36c2eb..3564fd5f45 100644
@@ -65,21 +65,6 @@ static target_long monitor_get_tbl(Monitor *mon, const struct MonitorDef *md,
     return cpu_ppc_load_tbl(env);
 }
 
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
-
 const MonitorDef monitor_defs[] = {
     { "fpscr", offsetof(CPUPPCState, fpscr) },
     /* Next instruction pointer */
target/sh4/monitor.c +0 -15
index 5ccb95af93..d641d95316 100644
@@ -53,18 +53,3 @@ void superh_cpu_format_tlb(CPUState *cpu, GString *buf)
         print_tlb(buf, i, &env->utlb[i]);
     }
 }
-
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
target/sparc/monitor.c +0 -16
index cc7fe74e3e..0c51669c08 100644
@@ -27,22 +27,6 @@
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
-
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
-
 #ifndef TARGET_SPARC64
 static target_long monitor_get_psr(Monitor *mon, const struct MonitorDef *md,
                                    int val)
target/xtensa/monitor.c +0 -15
index 99d35e8ef1..1180a32f80 100644
@@ -26,18 +26,3 @@
 #include "monitor/monitor.h"
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
-
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
-{
-    g_autoptr(GString) buf = g_string_new("");
-    CPUState *cpu = mon_get_cpu(mon);
-
-    if (!cpu) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
-
-    cpu_format_tlb(cpu, buf);
-
-    monitor_printf(mon, "%s", buf->str);
-}
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Acked-by on v2 20/53
#48 lore raw

Re: [PATCH v2 20/53] target/ppc: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 1 line · Daniel P. Berrangé
Quoted 322 lines
---
 target/ppc/cpu.h      |   2 +-
 target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
 2 files changed, 126 insertions(+), 88 deletions(-)
target/ppc/cpu.h +1 -1
index 500205229c..c84ae29b98 100644
@@ -1256,7 +1256,7 @@ DECLARE_OBJ_CHECKERS(PPCVirtualHypervisor, PPCVirtualHypervisorClass,
 
 void ppc_cpu_do_interrupt(CPUState *cpu);
 bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void ppc_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void ppc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/ppc/cpu_init.c +125 -87
index ad7abc6041..3456be465c 100644
@@ -9043,7 +9043,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = ppc_cpu_class_by_name;
     cc->has_work = ppc_cpu_has_work;
-    cc->dump_state = ppc_cpu_dump_state;
+    cc->format_state = ppc_cpu_format_state;
     cc->set_pc = ppc_cpu_set_pc;
     cc->gdb_read_register = ppc_cpu_gdb_read_register;
     cc->gdb_write_register = ppc_cpu_gdb_write_register;
@@ -9104,7 +9104,7 @@ static void ppc_cpu_register_types(void)
 #endif
 }
 
-void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void ppc_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
 #define RGPL  4
 #define RFPL  4
@@ -9113,39 +9113,41 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     CPUPPCState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "
-                 TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
-                 env->nip, env->lr, env->ctr, cpu_read_xer(env),
-                 cs->cpu_index);
-    qemu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx "  HF "
-                 "%08x iidx %d didx %d\n",
-                 env->msr, env->spr[SPR_HID0], env->hflags,
-                 cpu_mmu_index(env, true), cpu_mmu_index(env, false));
+    g_string_append_printf(buf,
+                           "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "
+                           TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
+                           env->nip, env->lr, env->ctr, cpu_read_xer(env),
+                           cs->cpu_index);
+    g_string_append_printf(buf,
+                           "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx "  HF "
+                           "%08x iidx %d didx %d\n",
+                           env->msr, env->spr[SPR_HID0], env->hflags,
+                           cpu_mmu_index(env, true), cpu_mmu_index(env, false));
 #if !defined(NO_TIMER_DUMP)
-    qemu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
+    g_string_append_printf(buf, "TB %08" PRIu32 " %08" PRIu64
 #if !defined(CONFIG_USER_ONLY)
-                 " DECR " TARGET_FMT_lu
+                           " DECR " TARGET_FMT_lu
 #endif
-                 "\n",
-                 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
+                           "\n",
+                           cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
 #if !defined(CONFIG_USER_ONLY)
-                 , cpu_ppc_load_decr(env)
+                           , cpu_ppc_load_decr(env)
 #endif
         );
 #endif
     for (i = 0; i < 32; i++) {
         if ((i & (RGPL - 1)) == 0) {
-            qemu_fprintf(f, "GPR%02d", i);
+            g_string_append_printf(buf, "GPR%02d", i);
         }
-        qemu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
+        g_string_append_printf(buf, " %016" PRIx64, ppc_dump_gpr(env, i));
         if ((i & (RGPL - 1)) == (RGPL - 1)) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
-    qemu_fprintf(f, "CR ");
+    g_string_append_printf(buf, "CR ");
     for (i = 0; i < 8; i++)
-        qemu_fprintf(f, "%01x", env->crf[i]);
-    qemu_fprintf(f, "  [");
+        g_string_append_printf(buf, "%01x", env->crf[i]);
+    g_string_append_printf(buf, "  [");
     for (i = 0; i < 8; i++) {
         char a = '-';
         if (env->crf[i] & 0x08) {
@@ -9155,75 +9157,97 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         } else if (env->crf[i] & 0x02) {
             a = 'E';
         }
-        qemu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
+        g_string_append_printf(buf, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
     }
-    qemu_fprintf(f, " ]             RES " TARGET_FMT_lx "\n",
-                 env->reserve_addr);
+    g_string_append_printf(buf, " ]             RES " TARGET_FMT_lx "\n",
+                           env->reserve_addr);
 
     if (flags & CPU_DUMP_FPU) {
         for (i = 0; i < 32; i++) {
             if ((i & (RFPL - 1)) == 0) {
-                qemu_fprintf(f, "FPR%02d", i);
+                g_string_append_printf(buf, "FPR%02d", i);
             }
-            qemu_fprintf(f, " %016" PRIx64, *cpu_fpr_ptr(env, i));
+            g_string_append_printf(buf, " %016" PRIx64, *cpu_fpr_ptr(env, i));
             if ((i & (RFPL - 1)) == (RFPL - 1)) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");
             }
         }
-        qemu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
+        g_string_append_printf(buf, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
     }
 
 #if !defined(CONFIG_USER_ONLY)
-    qemu_fprintf(f, " SRR0 " TARGET_FMT_lx "  SRR1 " TARGET_FMT_lx
-                 "    PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
-                 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
-                 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
-
-    qemu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
-                 "  SPRG2 " TARGET_FMT_lx "  SPRG3 " TARGET_FMT_lx "\n",
-                 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
-                 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
-
-    qemu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
-                 "  SPRG6 " TARGET_FMT_lx "  SPRG7 " TARGET_FMT_lx "\n",
-                 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
-                 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
+    g_string_append_printf(buf, " SRR0 " TARGET_FMT_lx "  SRR1 " TARGET_FMT_lx
+                           "    PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx
+                           "\n",
+                           env->spr[SPR_SRR0], env->spr[SPR_SRR1],
+                           env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
+
+    g_string_append_printf(buf, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
+                           "  SPRG2 " TARGET_FMT_lx "  SPRG3 " TARGET_FMT_lx
+                           "\n",
+                           env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
+                           env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
+
+    g_string_append_printf(buf, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
+                           "  SPRG6 " TARGET_FMT_lx "  SPRG7 " TARGET_FMT_lx
+                           "\n",
+                           env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
+                           env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
 
 #if defined(TARGET_PPC64)
     if (env->excp_model == POWERPC_EXCP_POWER7 ||
         env->excp_model == POWERPC_EXCP_POWER8 ||
         env->excp_model == POWERPC_EXCP_POWER9 ||
         env->excp_model == POWERPC_EXCP_POWER10)  {
-        qemu_fprintf(f, "HSRR0 " TARGET_FMT_lx " HSRR1 " TARGET_FMT_lx "\n",
-                     env->spr[SPR_HSRR0], env->spr[SPR_HSRR1]);
+        g_string_append_printf(buf, "HSRR0 " TARGET_FMT_lx
+                               " HSRR1 " TARGET_FMT_lx "\n",
+                               env->spr[SPR_HSRR0], env->spr[SPR_HSRR1]);
     }
 #endif
     if (env->excp_model == POWERPC_EXCP_BOOKE) {
-        qemu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
-                     " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
-                     env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
-
-        qemu_fprintf(f, "  TCR " TARGET_FMT_lx "   TSR " TARGET_FMT_lx
-                     "    ESR " TARGET_FMT_lx "   DEAR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
-                     env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
-
-        qemu_fprintf(f, "  PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
-                     "   IVPR " TARGET_FMT_lx "   EPCR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
-                     env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
-
-        qemu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
-                     "    EPR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
-                     env->spr[SPR_BOOKE_EPR]);
+        g_string_append_printf(buf, "CSRR0 " TARGET_FMT_lx
+                               " CSRR1 " TARGET_FMT_lx
+                               " MCSRR0 " TARGET_FMT_lx
+                               " MCSRR1 " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_CSRR0],
+                               env->spr[SPR_BOOKE_CSRR1],
+                               env->spr[SPR_BOOKE_MCSRR0],
+                               env->spr[SPR_BOOKE_MCSRR1]);
+
+        g_string_append_printf(buf, "  TCR " TARGET_FMT_lx
+                               "   TSR " TARGET_FMT_lx
+                               "    ESR " TARGET_FMT_lx
+                               "   DEAR " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_TCR],
+                               env->spr[SPR_BOOKE_TSR],
+                               env->spr[SPR_BOOKE_ESR],
+                               env->spr[SPR_BOOKE_DEAR]);
+
+        g_string_append_printf(buf, "  PIR " TARGET_FMT_lx
+                               " DECAR " TARGET_FMT_lx
+                               "   IVPR " TARGET_FMT_lx
+                               "   EPCR " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_PIR],
+                               env->spr[SPR_BOOKE_DECAR],
+                               env->spr[SPR_BOOKE_IVPR],
+                               env->spr[SPR_BOOKE_EPCR]);
+
+        g_string_append_printf(buf, " MCSR " TARGET_FMT_lx
+                               " SPRG8 " TARGET_FMT_lx
+                               "    EPR " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_MCSR],
+                               env->spr[SPR_BOOKE_SPRG8],
+                               env->spr[SPR_BOOKE_EPR]);
 
         /* FSL-specific */
-        qemu_fprintf(f, " MCAR " TARGET_FMT_lx "  PID1 " TARGET_FMT_lx
-                     "   PID2 " TARGET_FMT_lx "    SVR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
-                     env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
+        g_string_append_printf(buf, " MCAR " TARGET_FMT_lx
+                               "  PID1 " TARGET_FMT_lx
+                               "   PID2 " TARGET_FMT_lx
+                               "    SVR " TARGET_FMT_lx "\n",
+                               env->spr[SPR_Exxx_MCAR],
+                               env->spr[SPR_BOOKE_PID1],
+                               env->spr[SPR_BOOKE_PID2],
+                               env->spr[SPR_E500_SVR]);
 
         /*
          * IVORs are left out as they are large and do not change often --
@@ -9233,12 +9257,13 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
 
 #if defined(TARGET_PPC64)
     if (env->flags & POWERPC_FLAG_CFAR) {
-        qemu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
+        g_string_append_printf(buf, " CFAR " TARGET_FMT_lx"\n", env->cfar);
     }
 #endif
 
     if (env->spr_cb[SPR_LPCR].name) {
-        qemu_fprintf(f, " LPCR " TARGET_FMT_lx "\n", env->spr[SPR_LPCR]);
+        g_string_append_printf(buf,
+                               " LPCR " TARGET_FMT_lx "\n", env->spr[SPR_LPCR]);
     }
 
     switch (env->mmu_model) {
@@ -9254,29 +9279,42 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     case POWERPC_MMU_3_00:
 #endif
         if (env->spr_cb[SPR_SDR1].name) { /* SDR1 Exists */
-            qemu_fprintf(f, " SDR1 " TARGET_FMT_lx " ", env->spr[SPR_SDR1]);
+            g_string_append_printf(buf, " SDR1 " TARGET_FMT_lx " ",
+                                   env->spr[SPR_SDR1]);
         }
         if (env->spr_cb[SPR_PTCR].name) { /* PTCR Exists */
-            qemu_fprintf(f, " PTCR " TARGET_FMT_lx " ", env->spr[SPR_PTCR]);
+            g_string_append_printf(buf, " PTCR " TARGET_FMT_lx " ",
+                                   env->spr[SPR_PTCR]);
         }
-        qemu_fprintf(f, "  DAR " TARGET_FMT_lx "  DSISR " TARGET_FMT_lx "\n",
-                     env->spr[SPR_DAR], env->spr[SPR_DSISR]);
+        g_string_append_printf(buf, "  DAR " TARGET_FMT_lx "  DSISR "
+                               TARGET_FMT_lx "\n",
+                               env->spr[SPR_DAR], env->spr[SPR_DSISR]);
         break;
     case POWERPC_MMU_BOOKE206:
-        qemu_fprintf(f, " MAS0 " TARGET_FMT_lx "  MAS1 " TARGET_FMT_lx
-                     "   MAS2 " TARGET_FMT_lx "   MAS3 " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
-                     env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
-
-        qemu_fprintf(f, " MAS4 " TARGET_FMT_lx "  MAS6 " TARGET_FMT_lx
-                     "   MAS7 " TARGET_FMT_lx "    PID " TARGET_FMT_lx "\n",
-                     env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
-                     env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
-
-        qemu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
-                     " TLB1CFG " TARGET_FMT_lx "\n",
-                     env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
-                     env->spr[SPR_BOOKE_TLB1CFG]);
+        g_string_append_printf(buf, " MAS0 " TARGET_FMT_lx
+                               "  MAS1 " TARGET_FMT_lx
+                               "   MAS2 " TARGET_FMT_lx
+                               "   MAS3 " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_MAS0],
+                               env->spr[SPR_BOOKE_MAS1],
+                               env->spr[SPR_BOOKE_MAS2],
+                               env->spr[SPR_BOOKE_MAS3]);
+
+        g_string_append_printf(buf, " MAS4 " TARGET_FMT_lx
+                               "  MAS6 " TARGET_FMT_lx
+                               "   MAS7 " TARGET_FMT_lx
+                               "    PID " TARGET_FMT_lx "\n",
+                               env->spr[SPR_BOOKE_MAS4],
+                               env->spr[SPR_BOOKE_MAS6],
+                               env->spr[SPR_BOOKE_MAS7],
+                               env->spr[SPR_BOOKE_PID]);
+
+        g_string_append_printf(buf, "MMUCFG " TARGET_FMT_lx
+                               " TLB0CFG " TARGET_FMT_lx
+                               " TLB1CFG " TARGET_FMT_lx "\n",
+                               env->spr[SPR_MMUCFG],
+                               env->spr[SPR_BOOKE_TLB0CFG],
+                               env->spr[SPR_BOOKE_TLB1CFG]);
         break;
     default:
         break;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Acked-by on v2 46/53
#97 lore raw

Re: [PATCH v2 46/53] target/ppc: convert to use format_tlb callback

In reply to Daniel P. Berrangé
Quoted 3 lines · Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

Quoted 404 lines
---
 target/ppc/cpu.h        |   3 +-
 target/ppc/cpu_init.c   |   3 +
 target/ppc/mmu-hash64.c |   8 +-
 target/ppc/mmu-hash64.h |   2 +-
 target/ppc/mmu_common.c | 167 ++++++++++++++++++++++------------------
 target/ppc/monitor.c    |  10 ++-
 6 files changed, 107 insertions(+), 86 deletions(-)
target/ppc/cpu.h +1 -2
index c84ae29b98..37b44bfbc3 100644
@@ -1257,6 +1257,7 @@ DECLARE_OBJ_CHECKERS(PPCVirtualHypervisor, PPCVirtualHypervisorClass,
 void ppc_cpu_do_interrupt(CPUState *cpu);
 bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req);
 void ppc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void ppc_cpu_format_tlb(CPUState *cpu, GString *buf);
 hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
@@ -2667,8 +2668,6 @@ static inline bool ppc_interrupts_little_endian(PowerPCCPU *cpu)
     return false;
 }
 
-void dump_mmu(CPUPPCState *env);
-
 void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len);
 void ppc_store_vscr(CPUPPCState *env, uint32_t vscr);
 uint32_t ppc_get_vscr(CPUPPCState *env);
target/ppc/cpu_init.c +3 -0
index 3456be465c..98d6f40a49 100644
@@ -9044,6 +9044,9 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = ppc_cpu_class_by_name;
     cc->has_work = ppc_cpu_has_work;
     cc->format_state = ppc_cpu_format_state;
+#ifndef CONFIG_USER_ONLY
+    cc->format_tlb = ppc_cpu_format_tlb;
+#endif
     cc->set_pc = ppc_cpu_set_pc;
     cc->gdb_read_register = ppc_cpu_gdb_read_register;
     cc->gdb_write_register = ppc_cpu_gdb_write_register;
target/ppc/mmu-hash64.c +4 -4
index 19832c4b46..73927a0819 100644
@@ -80,7 +80,7 @@ static ppc_slb_t *slb_lookup(PowerPCCPU *cpu, target_ulong eaddr)
     return NULL;
 }
 
-void dump_slb(PowerPCCPU *cpu)
+void dump_slb(PowerPCCPU *cpu, GString *buf)
 {
     CPUPPCState *env = &cpu->env;
     int i;
@@ -88,15 +88,15 @@ void dump_slb(PowerPCCPU *cpu)
 
     cpu_synchronize_state(CPU(cpu));
 
-    qemu_printf("SLB\tESID\t\t\tVSID\n");
+    g_string_append_printf(buf, "SLB\tESID\t\t\tVSID\n");
     for (i = 0; i < cpu->hash64_opts->slb_size; i++) {
         slbe = env->slb[i].esid;
         slbv = env->slb[i].vsid;
         if (slbe == 0 && slbv == 0) {
             continue;
         }
-        qemu_printf("%d\t0x%016" PRIx64 "\t0x%016" PRIx64 "\n",
-                    i, slbe, slbv);
+        g_string_append_printf(buf, "%d\t0x%016" PRIx64 "\t0x%016" PRIx64 "\n",
+                               i, slbe, slbv);
     }
 }
 
target/ppc/mmu-hash64.h +1 -1
index c5b2f97ff7..99e03a5849 100644
@@ -4,7 +4,7 @@
 #ifndef CONFIG_USER_ONLY
 
 #ifdef TARGET_PPC64
-void dump_slb(PowerPCCPU *cpu);
+void dump_slb(PowerPCCPU *cpu, GString *buf);
 int ppc_store_slb(PowerPCCPU *cpu, target_ulong slot,
                   target_ulong esid, target_ulong vsid);
 bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
target/ppc/mmu_common.c +91 -76
index 754509e556..d7b716f30a 100644
@@ -937,19 +937,19 @@ static const char *book3e_tsize_to_str[32] = {
     "1T", "2T"
 };
 
-static void mmubooke_dump_mmu(CPUPPCState *env)
+static void mmubooke_dump_mmu(CPUPPCState *env, GString *buf)
 {
     ppcemb_tlb_t *entry;
     int i;
 
     if (kvm_enabled() && !env->kvm_sw_tlb) {
-        qemu_printf("Cannot access KVM TLB\n");
+        g_string_append_printf(buf, "Cannot access KVM TLB\n");
         return;
     }
 
-    qemu_printf("\nTLB:\n");
-    qemu_printf("Effective          Physical           Size PID   Prot     "
-                "Attr\n");
+    g_string_append_printf(buf, "\nTLB:\n");
+    g_string_append_printf(buf, "Effective          Physical           "
+                           "Size PID   Prot     Attr\n");
 
     entry = &env->tlb.tlbe[0];
     for (i = 0; i < env->nb_tlb; i++, entry++) {
@@ -973,22 +973,24 @@ static void mmubooke_dump_mmu(CPUPPCState *env)
         } else {
             snprintf(size_buf, sizeof(size_buf), "%3" PRId64 "k", size / KiB);
         }
-        qemu_printf("0x%016" PRIx64 " 0x%016" PRIx64 " %s %-5u %08x %08x\n",
-                    (uint64_t)ea, (uint64_t)pa, size_buf, (uint32_t)entry->PID,
-                    entry->prot, entry->attr);
+        g_string_append_printf(buf, "0x%016" PRIx64 " 0x%016" PRIx64
+                               " %s %-5u %08x %08x\n",
+                               (uint64_t)ea, (uint64_t)pa, size_buf,
+                               (uint32_t)entry->PID,
+                               entry->prot, entry->attr);
     }
 
 }
 
 static void mmubooke206_dump_one_tlb(CPUPPCState *env, int tlbn, int offset,
-                                     int tlbsize)
+                                     int tlbsize, GString *buf)
 {
     ppcmas_tlb_t *entry;
     int i;
 
-    qemu_printf("\nTLB%d:\n", tlbn);
-    qemu_printf("Effective          Physical           Size TID   TS SRWX"
-                " URWX WIMGE U0123\n");
+    g_string_append_printf(buf, "\nTLB%d:\n", tlbn);
+    g_string_append_printf(buf, "Effective          Physical           "
+                           "Size TID   TS SRWX URWX WIMGE U0123\n");
 
     entry = &env->tlb.tlbm[offset];
     for (i = 0; i < tlbsize; i++, entry++) {
@@ -1004,37 +1006,38 @@ static void mmubooke206_dump_one_tlb(CPUPPCState *env, int tlbn, int offset,
         ea = entry->mas2 & ~(size - 1);
         pa = entry->mas7_3 & ~(size - 1);
 
-        qemu_printf("0x%016" PRIx64 " 0x%016" PRIx64 " %4s %-5u %1u  S%c%c%c"
-                    "U%c%c%c %c%c%c%c%c U%c%c%c%c\n",
-                    (uint64_t)ea, (uint64_t)pa,
-                    book3e_tsize_to_str[tsize],
-                    (entry->mas1 & MAS1_TID_MASK) >> MAS1_TID_SHIFT,
-                    (entry->mas1 & MAS1_TS) >> MAS1_TS_SHIFT,
-                    entry->mas7_3 & MAS3_SR ? 'R' : '-',
-                    entry->mas7_3 & MAS3_SW ? 'W' : '-',
-                    entry->mas7_3 & MAS3_SX ? 'X' : '-',
-                    entry->mas7_3 & MAS3_UR ? 'R' : '-',
-                    entry->mas7_3 & MAS3_UW ? 'W' : '-',
-                    entry->mas7_3 & MAS3_UX ? 'X' : '-',
-                    entry->mas2 & MAS2_W ? 'W' : '-',
-                    entry->mas2 & MAS2_I ? 'I' : '-',
-                    entry->mas2 & MAS2_M ? 'M' : '-',
-                    entry->mas2 & MAS2_G ? 'G' : '-',
-                    entry->mas2 & MAS2_E ? 'E' : '-',
-                    entry->mas7_3 & MAS3_U0 ? '0' : '-',
-                    entry->mas7_3 & MAS3_U1 ? '1' : '-',
-                    entry->mas7_3 & MAS3_U2 ? '2' : '-',
-                    entry->mas7_3 & MAS3_U3 ? '3' : '-');
+        g_string_append_printf(buf, "0x%016" PRIx64 " 0x%016" PRIx64
+                               " %4s %-5u %1u  S%c%c%c"
+                               "U%c%c%c %c%c%c%c%c U%c%c%c%c\n",
+                               (uint64_t)ea, (uint64_t)pa,
+                               book3e_tsize_to_str[tsize],
+                               (entry->mas1 & MAS1_TID_MASK) >> MAS1_TID_SHIFT,
+                               (entry->mas1 & MAS1_TS) >> MAS1_TS_SHIFT,
+                               entry->mas7_3 & MAS3_SR ? 'R' : '-',
+                               entry->mas7_3 & MAS3_SW ? 'W' : '-',
+                               entry->mas7_3 & MAS3_SX ? 'X' : '-',
+                               entry->mas7_3 & MAS3_UR ? 'R' : '-',
+                               entry->mas7_3 & MAS3_UW ? 'W' : '-',
+                               entry->mas7_3 & MAS3_UX ? 'X' : '-',
+                               entry->mas2 & MAS2_W ? 'W' : '-',
+                               entry->mas2 & MAS2_I ? 'I' : '-',
+                               entry->mas2 & MAS2_M ? 'M' : '-',
+                               entry->mas2 & MAS2_G ? 'G' : '-',
+                               entry->mas2 & MAS2_E ? 'E' : '-',
+                               entry->mas7_3 & MAS3_U0 ? '0' : '-',
+                               entry->mas7_3 & MAS3_U1 ? '1' : '-',
+                               entry->mas7_3 & MAS3_U2 ? '2' : '-',
+                               entry->mas7_3 & MAS3_U3 ? '3' : '-');
     }
 }
 
-static void mmubooke206_dump_mmu(CPUPPCState *env)
+static void mmubooke206_dump_mmu(CPUPPCState *env, GString *buf)
 {
     int offset = 0;
     int i;
 
     if (kvm_enabled() && !env->kvm_sw_tlb) {
-        qemu_printf("Cannot access KVM TLB\n");
+        g_string_append_printf(buf, "Cannot access KVM TLB\n");
         return;
     }
 
@@ -1045,12 +1048,12 @@ static void mmubooke206_dump_mmu(CPUPPCState *env)
             continue;
         }
 
-        mmubooke206_dump_one_tlb(env, i, offset, size);
+        mmubooke206_dump_one_tlb(env, i, offset, size, buf);
         offset += size;
     }
 }
 
-static void mmu6xx_dump_BATs(CPUPPCState *env, int type)
+static void mmu6xx_dump_BATs(CPUPPCState *env, int type, GString *buf)
 {
     target_ulong *BATlt, *BATut, *BATu, *BATl;
     target_ulong BEPIl, BEPIu, bl;
@@ -1073,51 +1076,59 @@ static void mmu6xx_dump_BATs(CPUPPCState *env, int type)
         BEPIu = *BATu & 0xF0000000;
         BEPIl = *BATu & 0x0FFE0000;
         bl = (*BATu & 0x00001FFC) << 15;
-        qemu_printf("%s BAT%d BATu " TARGET_FMT_lx
-                    " BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " "
-                    TARGET_FMT_lx " " TARGET_FMT_lx "\n",
-                    type == ACCESS_CODE ? "code" : "data", i,
-                    *BATu, *BATl, BEPIu, BEPIl, bl);
+        g_string_append_printf(buf, "%s BAT%d BATu " TARGET_FMT_lx
+                               " BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " "
+                               TARGET_FMT_lx " " TARGET_FMT_lx "\n",
+                               type == ACCESS_CODE ? "code" : "data", i,
+                               *BATu, *BATl, BEPIu, BEPIl, bl);
     }
 }
 
-static void mmu6xx_dump_mmu(CPUPPCState *env)
+static void mmu6xx_dump_mmu(CPUPPCState *env, GString *buf)
 {
     PowerPCCPU *cpu = env_archcpu(env);
     ppc6xx_tlb_t *tlb;
     target_ulong sr;
     int type, way, entry, i;
 
-    qemu_printf("HTAB base = 0x%"HWADDR_PRIx"\n", ppc_hash32_hpt_base(cpu));
-    qemu_printf("HTAB mask = 0x%"HWADDR_PRIx"\n", ppc_hash32_hpt_mask(cpu));
+    g_string_append_printf(buf, "HTAB base = 0x%"HWADDR_PRIx"\n",
+                           ppc_hash32_hpt_base(cpu));
+    g_string_append_printf(buf, "HTAB mask = 0x%"HWADDR_PRIx"\n",
+                           ppc_hash32_hpt_mask(cpu));
 
-    qemu_printf("\nSegment registers:\n");
+    g_string_append_printf(buf, "\nSegment registers:\n");
     for (i = 0; i < 32; i++) {
         sr = env->sr[i];
         if (sr & 0x80000000) {
-            qemu_printf("%02d T=%d Ks=%d Kp=%d BUID=0x%03x "
-                        "CNTLR_SPEC=0x%05x\n", i,
-                        sr & 0x80000000 ? 1 : 0, sr & 0x40000000 ? 1 : 0,
-                        sr & 0x20000000 ? 1 : 0, (uint32_t)((sr >> 20) & 0x1FF),
-                        (uint32_t)(sr & 0xFFFFF));
+            g_string_append_printf(buf, "%02d T=%d Ks=%d Kp=%d BUID=0x%03x "
+                                   "CNTLR_SPEC=0x%05x\n", i,
+                                   sr & 0x80000000 ? 1 : 0,
+                                   sr & 0x40000000 ? 1 : 0,
+                                   sr & 0x20000000 ? 1 : 0,
+                                   (uint32_t)((sr >> 20) & 0x1FF),
+                                   (uint32_t)(sr & 0xFFFFF));
         } else {
-            qemu_printf("%02d T=%d Ks=%d Kp=%d N=%d VSID=0x%06x\n", i,
-                        sr & 0x80000000 ? 1 : 0, sr & 0x40000000 ? 1 : 0,
-                        sr & 0x20000000 ? 1 : 0, sr & 0x10000000 ? 1 : 0,
-                        (uint32_t)(sr & 0x00FFFFFF));
+            g_string_append_printf(buf, "%02d T=%d Ks=%d Kp=%d N=%d "
+                                   "VSID=0x%06x\n", i,
+                                   sr & 0x80000000 ? 1 : 0,
+                                   sr & 0x40000000 ? 1 : 0,
+                                   sr & 0x20000000 ? 1 : 0,
+                                   sr & 0x10000000 ? 1 : 0,
+                                   (uint32_t)(sr & 0x00FFFFFF));
         }
     }
 
-    qemu_printf("\nBATs:\n");
-    mmu6xx_dump_BATs(env, ACCESS_INT);
-    mmu6xx_dump_BATs(env, ACCESS_CODE);
+    g_string_append_printf(buf, "\nBATs:\n");
+    mmu6xx_dump_BATs(env, ACCESS_INT, buf);
+    mmu6xx_dump_BATs(env, ACCESS_CODE, buf);
 
     if (env->id_tlbs != 1) {
-        qemu_printf("ERROR: 6xx MMU should have separated TLB"
-                    " for code and data\n");
+        g_string_append_printf(buf, "ERROR: 6xx MMU should have separated TLB"
+                               " for code and data\n");
     }
 
-    qemu_printf("\nTLBs                       [EPN    EPN + SIZE]\n");
+    g_string_append_printf(buf,
+                           "\nTLBs                       [EPN    EPN + SIZE]\n");
 
     for (type = 0; type < 2; type++) {
         for (way = 0; way < env->nb_ways; way++) {
@@ -1126,48 +1137,52 @@ static void mmu6xx_dump_mmu(CPUPPCState *env)
                  entry++) {
 
                 tlb = &env->tlb.tlb6[entry];
-                qemu_printf("%s TLB %02d/%02d way:%d %s ["
-                            TARGET_FMT_lx " " TARGET_FMT_lx "]\n",
-                            type ? "code" : "data", entry % env->nb_tlb,
-                            env->nb_tlb, way,
-                            pte_is_valid(tlb->pte0) ? "valid" : "inval",
-                            tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE);
+                g_string_append_printf(buf, "%s TLB %02d/%02d way:%d %s ["
+                                       TARGET_FMT_lx " " TARGET_FMT_lx "]\n",
+                                       type ? "code" : "data",
+                                       entry % env->nb_tlb,
+                                       env->nb_tlb, way,
+                                       pte_is_valid(tlb->pte0) ?
+                                       "valid" : "inval",
+                                       tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE);
             }
         }
     }
 }
 
-void dump_mmu(CPUPPCState *env)
+void ppc_cpu_format_tlb(CPUState *cpu, GString *buf)
 {
+    CPUPPCState *env = cpu->env_ptr;
+
     switch (env->mmu_model) {
     case POWERPC_MMU_BOOKE:
-        mmubooke_dump_mmu(env);
+        mmubooke_dump_mmu(env, buf);
         break;
     case POWERPC_MMU_BOOKE206:
-        mmubooke206_dump_mmu(env);
+        mmubooke206_dump_mmu(env, buf);
         break;
     case POWERPC_MMU_SOFT_6xx:
     case POWERPC_MMU_SOFT_74xx:
-        mmu6xx_dump_mmu(env);
+        mmu6xx_dump_mmu(env, buf);
         break;
 #if defined(TARGET_PPC64)
     case POWERPC_MMU_64B:
     case POWERPC_MMU_2_03:
     case POWERPC_MMU_2_06:
     case POWERPC_MMU_2_07:
-        dump_slb(env_archcpu(env));
+        dump_slb(env_archcpu(env), buf);
         break;
     case POWERPC_MMU_3_00:
         if (ppc64_v3_radix(env_archcpu(env))) {
-            qemu_log_mask(LOG_UNIMP, "%s: the PPC64 MMU is unsupported\n",
-                          __func__);
+            g_string_append_printf(buf, "PPC64 MMU not supported\n");
         } else {
-            dump_slb(env_archcpu(env));
+            dump_slb(env_archcpu(env), buf);
         }
         break;
 #endif
     default:
-        qemu_log_mask(LOG_UNIMP, "%s: unimplemented\n", __func__);
+        g_string_append_printf(buf, "MMU model %d not supported\n",
+                               env->mmu_model);
     }
 }
 
target/ppc/monitor.c +7 -3
index a475108b2d..401a36c2eb 100644
@@ -67,13 +67,17 @@ static target_long monitor_get_tbl(Monitor *mon, const struct MonitorDef *md,
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env1 = mon_get_cpu_env(mon);
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env1) {
+    if (!cpu) {
         monitor_printf(mon, "No CPU available\n");
         return;
     }
-    dump_mmu(env1);
+
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
 
 const MonitorDef monitor_defs[] = {
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Reviewed-by on v2 11/53
#27 lore raw

Re: [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé

This method isn't used in any code and its functionality is already available via the 'info registers' HMP command.

---
 target/hexagon/cpu.c      | 5 -----
 target/hexagon/internal.h | 1 -
 2 files changed, 6 deletions(-)
Reviewed-by on v2 17/53
#41 lore raw

Re: [PATCH v2 17/53] target/mips: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 14 lines · Daniel P. Berrangé
---
 target/mips/cpu.c | 85 +++++++++++++++++++++++++----------------------
 1 file changed, 45 insertions(+), 40 deletions(-)
target/mips/cpu.c +0 -1
index d426918291..9ced90d810 100644
@@ -42,76 +42,81 @@ const char regnames[32][3] = {
     "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
 };
 
-static void fpu_dump_fpr(fpr_t *fpr, FILE *f, bool is_fpu64)

target/mips/cpu.c const char regnames[32][3] = { · line 49

Quoted 10 lines
target/mips/cpu.c +3 -5
+static void fpu_dump_fpr(fpr_t *fpr, GString *buf, bool is_fpu64)
 {
     if (is_fpu64) {
-        qemu_fprintf(f, "w:%08x d:%016" PRIx64 " fd:%13g fs:%13g psu: %13g\n",
-                     fpr->w[FP_ENDIAN_IDX], fpr->d,
-                     (double)fpr->fd,
-                     (double)fpr->fs[FP_ENDIAN_IDX],
-                     (double)fpr->fs[!FP_ENDIAN_IDX]);
+        g_string_append_printf(buf, "w:%08x d:%016" PRIx64
+                               " fd:%13g fs:%13g psu: %13g\n",

IIUC QEMU coding style, the 2nd part of the format should be aligned with the first part. (multiple occurrences in this series).

Otherwise:

Reviewed-by on v2 18/53
#43 lore raw

Re: [PATCH v2 18/53] target/nios2: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 47 lines · Daniel P. Berrangé
---
 target/nios2/cpu.c       |  2 +-
 target/nios2/cpu.h       |  2 +-
 target/nios2/translate.c | 20 ++++++++++----------
 3 files changed, 12 insertions(+), 12 deletions(-)
target/nios2/cpu.c +1 -1
index 5e37defef8..cbf15fb1c9 100644
@@ -241,7 +241,7 @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = nios2_cpu_class_by_name;
     cc->has_work = nios2_cpu_has_work;
-    cc->dump_state = nios2_cpu_dump_state;
+    cc->format_state = nios2_cpu_format_state;
     cc->set_pc = nios2_cpu_set_pc;
     cc->disas_set_info = nios2_cpu_disas_set_info;
 #ifndef CONFIG_USER_ONLY
target/nios2/cpu.h +1 -1
index 2ab82fdc71..3b16cd1f3c 100644
@@ -195,7 +195,7 @@ void nios2_tcg_init(void);
 void nios2_cpu_do_interrupt(CPUState *cs);
 int cpu_nios2_signal_handler(int host_signum, void *pinfo, void *puc);
 void dump_mmu(CPUNios2State *env);
-void nios2_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void nios2_cpu_format_state(CPUState *cpu, GString *buf, int flags);
 hwaddr nios2_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 void nios2_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
                                    MMUAccessType access_type,
target/nios2/translate.c +1 -1
index 08d7ac5398..a5f0f56e1a 100644
@@ -855,7 +855,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
     translator_loop(&nios2_tr_ops, &dc.base, cs, tb, max_insns);
 }
 
-void nios2_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void nios2_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     Nios2CPU *cpu = NIOS2_CPU(cs);
     CPUNios2State *env = &cpu->env;

target/nios2/translate.c void nios2_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 869

Quoted 7 lines
target/nios2/translate.c +2 -2
@@ -865,22 +865,22 @@ void nios2_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         return;
     }
 
-    qemu_fprintf(f, "IN: PC=%x %s\n",
-                 env->regs[R_PC], lookup_symbol(env->regs[R_PC]));
+    g_string_append_printf(buf, "IN: PC=%x %s\n",
+                           env->regs[R_PC], lookup_symbol(env->regs[R_PC]));

Note 1:

Interesting to call lookup_symbol() in dump_state(). Other targets could do that too, but even better doing this in cpu_format_state().

Note 2:

format_state() doesn't belong to translate.c IMO and should be moved to cpu.c.

Anyhow, unrelated to your patch, so:

Reviewed-by on v2 7/53
#17 lore raw

Re: [PATCH v2 07/53] target/alpha: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 38 lines · Daniel P. Berrangé
---
 target/alpha/cpu.c    |  2 +-
 target/alpha/cpu.h    |  2 +-
 target/alpha/helper.c | 28 ++++++++++++++++------------
 3 files changed, 18 insertions(+), 14 deletions(-)
target/alpha/cpu.c +1 -1
index 4871ad0c0a..d0cdda9554 100644
@@ -239,7 +239,7 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = alpha_cpu_class_by_name;
     cc->has_work = alpha_cpu_has_work;
-    cc->dump_state = alpha_cpu_dump_state;
+    cc->format_state = alpha_cpu_format_state;
     cc->set_pc = alpha_cpu_set_pc;
     cc->gdb_read_register = alpha_cpu_gdb_read_register;
     cc->gdb_write_register = alpha_cpu_gdb_write_register;
target/alpha/cpu.h +1 -1
index 82df108967..9e3c80ebcc 100644
@@ -278,7 +278,7 @@ extern const VMStateDescription vmstate_alpha_cpu;
 
 void alpha_cpu_do_interrupt(CPUState *cpu);
 bool alpha_cpu_exec_interrupt(CPUState *cpu, int int_req);
-void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags);
+void alpha_cpu_format_state(CPUState *cs, GString *buf, int flags);
 hwaddr alpha_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 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);
target/alpha/helper.c +0 -0
index 4f56fe4d23..6ed80e8a27 100644

target/alpha/helper.c bool alpha_cpu_exec_interrupt(CPUState *cs, int interrupt_request) · line 455

Quoted 6 lines
target/alpha/helper.c +1 -1
@@ -451,7 +451,7 @@ bool alpha_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
     return false;
 }
 
-void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void alpha_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {

Unrelated, but this code doesn't belong to helper.c IMO, but cpu.c.

Reviewed-by on v2 9/53
#20 lore raw

Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
---
 target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 28 deletions(-)
target/avr/cpu.c +1 -15
index ea14175ca5..17ff21f8be 100644
@@ -145,43 +145,44 @@ static ObjectClass *avr_cpu_class_by_name(const char *cpu_model)
     return oc;
 }
 
-static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static void avr_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     AVRCPU *cpu = AVR_CPU(cs);
     CPUAVRState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "\n");
-    qemu_fprintf(f, "PC:    %06x\n", env->pc_w * 2); /* PC points to words */
-    qemu_fprintf(f, "SP:      %04x\n", env->sp);
-    qemu_fprintf(f, "rampD:     %02x\n", env->rampD >> 16);
-    qemu_fprintf(f, "rampX:     %02x\n", env->rampX >> 16);
-    qemu_fprintf(f, "rampY:     %02x\n", env->rampY >> 16);
-    qemu_fprintf(f, "rampZ:     %02x\n", env->rampZ >> 16);
-    qemu_fprintf(f, "EIND:      %02x\n", env->eind >> 16);
-    qemu_fprintf(f, "X:       %02x%02x\n", env->r[27], env->r[26]);
-    qemu_fprintf(f, "Y:       %02x%02x\n", env->r[29], env->r[28]);
-    qemu_fprintf(f, "Z:       %02x%02x\n", env->r[31], env->r[30]);
-    qemu_fprintf(f, "SREG:    [ %c %c %c %c %c %c %c %c ]\n",
-                 env->sregI ? 'I' : '-',
-                 env->sregT ? 'T' : '-',

target/avr/cpu.c static ObjectClass *avr_cpu_class_by_name(const char *cpu_model) · line 154

Quoted 10 lines
target/avr/cpu.c +1 -9
-                 env->sregH ? 'H' : '-',
-                 env->sregS ? 'S' : '-',
-                 env->sregV ? 'V' : '-',
-                 env->sregN ? '-' : 'N', /* Zf has negative logic */
-                 env->sregZ ? 'Z' : '-',
-                 env->sregC ? 'I' : '-');
-    qemu_fprintf(f, "SKIP:    %02x\n", env->skip);
-
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

This would be g_string_append_c(buf, '\n') but in this particular case it doesn't seem helpful so I'd directly remove it.

Quoted 24 lines
target/avr/cpu.c +23 -0
+    /* PC points to words */
+    g_string_append_printf(buf, "PC:    %06x\n", env->pc_w * 2);
+    g_string_append_printf(buf, "SP:      %04x\n", env->sp);
+    g_string_append_printf(buf, "rampD:     %02x\n", env->rampD >> 16);
+    g_string_append_printf(buf, "rampX:     %02x\n", env->rampX >> 16);
+    g_string_append_printf(buf, "rampY:     %02x\n", env->rampY >> 16);
+    g_string_append_printf(buf, "rampZ:     %02x\n", env->rampZ >> 16);
+    g_string_append_printf(buf, "EIND:      %02x\n", env->eind >> 16);
+    g_string_append_printf(buf, "X:       %02x%02x\n", env->r[27], env->r[26]);
+    g_string_append_printf(buf, "Y:       %02x%02x\n", env->r[29], env->r[28]);
+    g_string_append_printf(buf, "Z:       %02x%02x\n", env->r[31], env->r[30]);
+    g_string_append_printf(buf, "SREG:    [ %c %c %c %c %c %c %c %c ]\n",
+                           env->sregI ? 'I' : '-',
+                           env->sregT ? 'T' : '-',
+                           env->sregH ? 'H' : '-',
+                           env->sregS ? 'S' : '-',
+                           env->sregV ? 'V' : '-',
+                           env->sregN ? '-' : 'N', /* Zf has negative logic */
+                           env->sregZ ? 'Z' : '-',
+                           env->sregC ? 'I' : '-');
+    g_string_append_printf(buf, "SKIP:    %02x\n", env->skip);
+
+    g_string_append_printf(buf, "\n");
     for (i = 0; i < ARRAY_SIZE(env->r); i++) {

target/avr/cpu.c static ObjectClass *avr_cpu_class_by_name(const char *cpu_model) · line 185

Quoted 10 lines
target/avr/cpu.c +3 -3
-        qemu_fprintf(f, "R[%02d]:  %02x   ", i, env->r[i]);
+        g_string_append_printf(buf, "R[%02d]:  %02x   ", i, env->r[i]);
 
         if ((i % 8) == 7) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

Ditto (remove).

Otherwise:

Quoted 1 line
target/avr/cpu.c +0 -0
 }
Reviewed-by on v2 13/53
#31 lore raw

Re: [PATCH v2 13/53] target/hppa: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 24 lines · Daniel P. Berrangé
---
 target/hppa/cpu.c    |  2 +-
 target/hppa/cpu.h    |  2 +-
 target/hppa/helper.c | 25 ++++++++++++++-----------
 3 files changed, 16 insertions(+), 13 deletions(-)
target/hppa/helper.c +5 -4
@@ -110,20 +111,22 @@ void hppa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     psw_c[18] = '\0';
     psw_cb = ((env->psw_cb >> 4) & 0x01111111) | (env->psw_cb_msb << 28);
 
-    qemu_fprintf(f, "PSW  " TREG_FMT_lx " CB   " TREG_FMT_lx " %s\n",
-                 psw, psw_cb, psw_c);
+    g_string_append_printf(buf,
+                           "PSW  " TREG_FMT_lx " CB   " TREG_FMT_lx " %s\n",
+                           psw, psw_cb, psw_c);
 
     for (i = 0; i < 32; i++) {
-        qemu_fprintf(f, "GR%02d " TREG_FMT_lx "%c", i, env->gr[i],
-                     (i & 3) == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, "GR%02d " TREG_FMT_lx "%c", i, env->gr[i],
+                               (i & 3) == 3 ? '\n' : ' ');
     }
 #ifndef CONFIG_USER_ONLY

target/hppa/helper.c void hppa_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 129

Quoted 10 lines
target/hppa/helper.c +4 -3
     for (i = 0; i < 8; i++) {
-        qemu_fprintf(f, "SR%02d %08x%c", i, (uint32_t)(env->sr[i] >> 32),
-                     (i & 3) == 3 ? '\n' : ' ');
+        g_string_append_printf(buf,
+                               "SR%02d %08x%c", i, (uint32_t)(env->sr[i] >> 32),
+                               (i & 3) == 3 ? '\n' : ' ');
     }
 #endif
-     qemu_fprintf(f, "\n");
+     g_string_append_printf(buf, "\n");
        g_string_append_c(buf, '\n');

Otherwise,

Quoted 4 lines
target/hppa/helper.c +0 -0
     /* ??? FR */
 }
 
Reviewed-by on v2 15/53
#35 lore raw

Re: [PATCH v2 15/53] target/m68k: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 31 lines · Daniel P. Berrangé
---
 target/m68k/cpu.c       |  2 +-
 target/m68k/cpu.h       |  2 +-
 target/m68k/translate.c | 92 ++++++++++++++++++++++-------------------
 3 files changed, 51 insertions(+), 45 deletions(-)
     switch (env->fpcr & FPCR_PREC_MASK) {
     case FPCR_PREC_X:
target/m68k/translate.c +5 -5
-        qemu_fprintf(f, "X ");
+        g_string_append_printf(buf, "X ");
         break;
     case FPCR_PREC_S:
-        qemu_fprintf(f, "S ");
+        g_string_append_printf(buf, "S ");
         break;
     case FPCR_PREC_D:
-        qemu_fprintf(f, "D ");
+        g_string_append_printf(buf, "D ");
         break;
     }
     switch (env->fpcr & FPCR_RND_MASK) {
     case FPCR_RND_N:
-        qemu_fprintf(f, "RN ");
+        g_string_append_printf(buf, "RN ");
         break;
     case FPCR_RND_Z:
-        qemu_fprintf(f, "RZ ");
+        g_string_append_printf(buf, "RZ ");
         break;
     case FPCR_RND_M:

target/m68k/translate.c static double floatx80_to_double(CPUM68KState *env, uint16_t high, uint64_t low) · line 6374

Quoted 10 lines
target/m68k/translate.c +3 -3
-        qemu_fprintf(f, "RM ");
+        g_string_append_printf(buf, "RM ");
         break;
     case FPCR_RND_P:
-        qemu_fprintf(f, "RP ");
+        g_string_append_printf(buf, "RP ");
         break;
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

g_string_append_c(), otherwise:

Reviewed-by on v2 16/53
#37 lore raw

Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé
---
 target/microblaze/cpu.c       |  2 +-
 target/microblaze/cpu.h       |  2 +-
 target/microblaze/translate.c | 45 ++++++++++++++++++-----------------
 3 files changed, 25 insertions(+), 24 deletions(-)
     for (i = 0; i < 32; i++) {

target/microblaze/translate.c void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) · line 1899

Quoted 7 lines
target/microblaze/translate.c +3 -3
-        qemu_fprintf(f, "r%2.2d=%08x%c",
-                     i, env->regs[i], i % 4 == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, "r%2.2d=%08x%c",
+                               i, env->regs[i], i % 4 == 3 ? '\n' : ' ');
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

g_string_append_c(), otherwise:

Quoted 4 lines

}

void mb_tcg_init(void)

Reviewed-by on v2 19/53
#45 lore raw

Re: [PATCH v2 19/53] target/openrisc: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 6 lines · Daniel P. Berrangé
---
 target/openrisc/cpu.c       | 2 +-
 target/openrisc/cpu.h       | 2 +-
 target/openrisc/translate.c | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
#38 lore raw

Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state

In reply to Philippe Mathieu-Daudé
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Daniel P. Berrangé
---
 target/microblaze/cpu.c       |  2 +-
 target/microblaze/cpu.h       |  2 +-
 target/microblaze/translate.c | 45 ++++++++++++++++++-----------------
 3 files changed, 25 insertions(+), 24 deletions(-)
     for (i = 0; i < 32; i++) {

target/microblaze/translate.c void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) · line 1899

Quoted 7 lines
target/microblaze/translate.c +3 -3
-        qemu_fprintf(f, "r%2.2d=%08x%c",
-                     i, env->regs[i], i % 4 == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, "r%2.2d=%08x%c",
+                               i, env->regs[i], i % 4 == 3 ? '\n' : ' ');
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
Quoted 1 line

g_string_append_c(), otherwise:

Actually we don't need an extra newline.

Quoted 7 lines
Quoted 4 lines

}

void mb_tcg_init(void)

#39 lore raw

Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state

Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Daniel P. Berrangé
---
 target/microblaze/cpu.c       |  2 +-
 target/microblaze/cpu.h       |  2 +-
 target/microblaze/translate.c | 45 ++++++++++++++++++-----------------
 3 files changed, 25 insertions(+), 24 deletions(-)
     for (i = 0; i < 32; i++) {
target/microblaze/translate.c +3 -3
-        qemu_fprintf(f, "r%2.2d=%08x%c",
-                     i, env->regs[i], i % 4 == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, "r%2.2d=%08x%c",
+                               i, env->regs[i], i % 4 == 3 ? '\n' : ' ');
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
Quoted 3 lines
Quoted 1 line

g_string_append_c(), otherwise:

Actually we don't need an extra newline.

Oops sorry here we do.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

}

void mb_tcg_init(void)

Reviewed-by on v2 24/53
#54 lore raw

Re: [PATCH v2 24/53] target/sh: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 6 lines · Daniel P. Berrangé
---
 target/sh4/cpu.c       |  2 +-
 target/sh4/cpu.h       |  2 +-
 target/sh4/translate.c | 36 ++++++++++++++++++++----------------
 3 files changed, 22 insertions(+), 18 deletions(-)
#56 lore raw

Re: [PATCH v2 25/53] target/sparc: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 11 lines · Daniel P. Berrangé
---
 target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
 target/sparc/cpu.h |  2 +-
 2 files changed, 47 insertions(+), 40 deletions(-)
target/sparc/cpu.c +0 -0
index da6b30ec74..9346a79239 100644

target/sparc/cpu.c void sparc_cpu_list(void) · line 600

Quoted 5 lines
target/sparc/cpu.c +1 -1
@@ -597,11 +597,11 @@ void sparc_cpu_list(void)
                 "fpu_version mmu_version nwindows\n");
 }
 
-static void cpu_print_cc(FILE *f, uint32_t cc)
+static void cpu_print_cc(GString *buf, uint32_t cc)

Rename as cpu_format_cc().

Quoted 27 lines
target/sparc/cpu.c +7 -6
 {
-    qemu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
-                 cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
-                 cc & PSR_CARRY ? 'C' : '-');
+    g_string_append_printf(buf, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
+                           cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
+                           cc & PSR_CARRY ? 'C' : '-');
 }
 
 #ifdef TARGET_SPARC64
@@ -610,34 +610,36 @@ static void cpu_print_cc(FILE *f, uint32_t cc)
 #define REGS_PER_LINE 8
 #endif
 
-void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void sparc_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     SPARCCPU *cpu = SPARC_CPU(cs);
     CPUSPARCState *env = &cpu->env;
     int i, x;
 
-    qemu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
-                 env->npc);
+    g_string_append_printf(buf,
+                           "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n",
+                           env->pc, env->npc);
 

target/sparc/cpu.c static void cpu_print_cc(FILE *f, uint32_t cc) · line 629

Quoted 10 lines
target/sparc/cpu.c +3 -3
     for (i = 0; i < 8; i++) {
         if (i % REGS_PER_LINE == 0) {
-            qemu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
+            g_string_append_printf(buf, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
         }
-        qemu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
+        g_string_append_printf(buf, " " TARGET_FMT_lx, env->gregs[i]);
         if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");

g_string_append_c()

Quoted 6 lines
target/sparc/cpu.c +0 -1
         }
     }
     for (x = 0; x < 3; x++) {
         for (i = 0; i < 8; i++) {
             if (i % REGS_PER_LINE == 0) {
-                qemu_fprintf(f, "%%%c%d-%d: ",

target/sparc/cpu.c static void cpu_print_cc(FILE *f, uint32_t cc) · line 642

Quoted 10 lines
target/sparc/cpu.c +4 -2
+                g_string_append_printf(buf, "%%%c%d-%d: ",
                              x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
                              i, i + REGS_PER_LINE - 1);
             }
-            qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
+            g_string_append_printf(buf, TARGET_FMT_lx " ",
+                                   env->regwptr[i + x * 8]);
             if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");

g_string_append_c()

Quoted 5 lines
target/sparc/cpu.c +0 -0
             }
         }
     }
@@ -645,42 +647,47 @@ void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     if (flags & CPU_DUMP_FPU) {

target/sparc/cpu.c void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 654

Quoted 10 lines
target/sparc/cpu.c +3 -3
         for (i = 0; i < TARGET_DPREGS; i++) {
             if ((i & 3) == 0) {
-                qemu_fprintf(f, "%%f%02d: ", i * 2);
+                g_string_append_printf(buf, "%%f%02d: ", i * 2);
             }
-            qemu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
+            g_string_append_printf(buf, " %016" PRIx64, env->fpr[i].ll);
             if ((i & 3) == 3) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");

g_string_append_c()

Quoted 48 lines
target/sparc/cpu.c +19 -21
             }
         }
     }
 
 #ifdef TARGET_SPARC64
-    qemu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
+    g_string_append_printf(buf, "pstate: %08x ccr: %02x (icc: ", env->pstate,
                  (unsigned)cpu_get_ccr(env));
-    cpu_print_cc(f, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
-    qemu_fprintf(f, " xcc: ");
-    cpu_print_cc(f, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
-    qemu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl,
-                 env->psrpil, env->gl);
-    qemu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: "
-                 TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba);
-    qemu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
-                 "cleanwin: %d cwp: %d\n",
-                 env->cansave, env->canrestore, env->otherwin, env->wstate,
-                 env->cleanwin, env->nwindows - 1 - env->cwp);
-    qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: "
-                 TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs);
+    cpu_print_cc(buf, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
+    g_string_append_printf(buf, " xcc: ");
+    cpu_print_cc(buf, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
+    g_string_append_printf(buf, ") asi: %02x tl: %d pil: %x gl: %d\n",
+                           env->asi, env->tl, env->psrpil, env->gl);
+    g_string_append_printf(buf, "tbr: " TARGET_FMT_lx " hpstate: "
+                           TARGET_FMT_lx " htba: " TARGET_FMT_lx "\n",
+                           env->tbr, env->hpstate, env->htba);
+    g_string_append_printf(buf, "cansave: %d canrestore: %d "
+                           "otherwin: %d wstate: %d "
+                           "cleanwin: %d cwp: %d\n",
+                           env->cansave, env->canrestore,
+                           env->otherwin, env->wstate,
+                           env->cleanwin, env->nwindows - 1 - env->cwp);
+    g_string_append_printf(buf, "fsr: " TARGET_FMT_lx " y: "
+                           TARGET_FMT_lx " fprs: " TARGET_FMT_lx "\n",
+                           env->fsr, env->y, env->fprs);
 
 #else
-    qemu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
-    cpu_print_cc(f, cpu_get_psr(env));
-    qemu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
-                 env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
-                 env->wim);
-    qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
-                 env->fsr, env->y);
+    g_string_append_printf(buf, "psr: %08x (icc: ", cpu_get_psr(env));

target/sparc/cpu.c void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 690

Quoted 10 lines
target/sparc/cpu.c +8 -1
+    cpu_print_cc(buf, cpu_get_psr(env));
+    g_string_append_printf(buf, " SPE: %c%c%c) wim: %08x\n",
+                           env->psrs ? 'S' : '-',
+                           env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
+                           env->wim);
+    g_string_append_printf(buf, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
+                           env->fsr, env->y);
 #endif
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

We probably don't need this last newline anymore.

Quoted 2 lines
target/sparc/cpu.c +0 -0
 }
 
Reviewed-by on v2 26/53
#59 lore raw

Re: [PATCH v2 26/53] target/tricore: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 37 lines · Daniel P. Berrangé
---
 target/tricore/cpu.c       |  2 +-
 target/tricore/cpu.h       |  2 +-
 target/tricore/translate.c | 24 ++++++++++++------------
 3 files changed, 14 insertions(+), 14 deletions(-)
target/tricore/translate.c +9 -9
-void tricore_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void tricore_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     TriCoreCPU *cpu = TRICORE_CPU(cs);
     CPUTriCoreState *env = &cpu->env;
@@ -95,26 +95,26 @@ void tricore_cpu_dump_state(CPUState *cs, FILE *f, int flags)
 
     psw = psw_read(env);
 
-    qemu_fprintf(f, "PC: " TARGET_FMT_lx, env->PC);
-    qemu_fprintf(f, " PSW: " TARGET_FMT_lx, psw);
-    qemu_fprintf(f, " ICR: " TARGET_FMT_lx, env->ICR);
-    qemu_fprintf(f, "\nPCXI: " TARGET_FMT_lx, env->PCXI);
-    qemu_fprintf(f, " FCX: " TARGET_FMT_lx, env->FCX);
-    qemu_fprintf(f, " LCX: " TARGET_FMT_lx, env->LCX);
+    g_string_append_printf(buf, "PC: " TARGET_FMT_lx, env->PC);
+    g_string_append_printf(buf, " PSW: " TARGET_FMT_lx, psw);
+    g_string_append_printf(buf, " ICR: " TARGET_FMT_lx, env->ICR);
+    g_string_append_printf(buf, "\nPCXI: " TARGET_FMT_lx, env->PCXI);
+    g_string_append_printf(buf, " FCX: " TARGET_FMT_lx, env->FCX);
+    g_string_append_printf(buf, " LCX: " TARGET_FMT_lx, env->LCX);
 
     for (i = 0; i < 16; ++i) {
         if ((i & 3) == 0) {
-            qemu_fprintf(f, "\nGPR A%02d:", i);
+            g_string_append_printf(buf, "\nGPR A%02d:", i);
         }
-        qemu_fprintf(f, " " TARGET_FMT_lx, env->gpr_a[i]);
+        g_string_append_printf(buf, " " TARGET_FMT_lx, env->gpr_a[i]);
     }

target/tricore/translate.c void tricore_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 117

Quoted 10 lines
target/tricore/translate.c +3 -3
     for (i = 0; i < 16; ++i) {
         if ((i & 3) == 0) {
-            qemu_fprintf(f, "\nGPR D%02d:", i);
+            g_string_append_printf(buf, "\nGPR D%02d:", i);
         }
-        qemu_fprintf(f, " " TARGET_FMT_lx, env->gpr_d[i]);
+        g_string_append_printf(buf, " " TARGET_FMT_lx, env->gpr_d[i]);
     }
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

g_string_append_c(), otherwise:

Quoted 4 lines
(quoted diff) +0 -0
 }
 
 /*
#61 lore raw

Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 38 lines · Daniel P. Berrangé
---
 target/xtensa/cpu.c       |  2 +-
 target/xtensa/cpu.h       |  2 +-
 target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
 3 files changed, 25 insertions(+), 24 deletions(-)
target/xtensa/translate.c +7 -7
-void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void xtensa_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
     xtensa_isa isa = env->config->isa;
     int i, j;
 
-    qemu_fprintf(f, "PC=%08x\n\n", env->pc);
+    g_string_append_printf(buf, "PC=%08x\n\n", env->pc);
 
     for (i = j = 0; i < xtensa_isa_num_sysregs(isa); ++i) {
         const uint32_t *reg =
@@ -1340,55 +1340,56 @@ void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         int regno = xtensa_sysreg_number(isa, i);
 
         if (regno >= 0) {
-            qemu_fprintf(f, "%12s=%08x%c",
-                         xtensa_sysreg_name(isa, i),
-                         reg[regno],
-                         (j++ % 4) == 3 ? '\n' : ' ');
+            g_string_append_printf(buf, "%12s=%08x%c",
+                                   xtensa_sysreg_name(isa, i),
+                                   reg[regno],
+                                   (j++ % 4) == 3 ? '\n' : ' ');
         }
     }
 
-    qemu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n");
+    g_string_append_printf(buf, (j % 4) == 0 ? "\n" : "\n\n");
 

target/xtensa/translate.c void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 1358

Quoted 10 lines
target/xtensa/translate.c +3 -3
     for (i = 0; i < 16; ++i) {
-        qemu_fprintf(f, " A%02d=%08x%c",
-                     i, env->regs[i], (i % 4) == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, " A%02d=%08x%c",
+                               i, env->regs[i], (i % 4) == 3 ? '\n' : ' ');
     }
 
     xtensa_sync_phys_from_window(env);
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

g_string_append_c(); pre-existing but better to move it before xtensa_sync_phys_from_window().

Quoted 8 lines
target/xtensa/translate.c +1 -1
     for (i = 0; i < env->config->nareg; ++i) {
-        qemu_fprintf(f, "AR%02d=%08x ", i, env->phys_regs[i]);
+        g_string_append_printf(buf, "AR%02d=%08x ", i, env->phys_regs[i]);
         if (i % 4 == 3) {
             bool ws = (env->sregs[WINDOW_START] & (1 << (i / 4))) != 0;
             bool cw = env->sregs[WINDOW_BASE] == i / 4;
 

target/xtensa/translate.c void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 1373

Quoted 10 lines
target/xtensa/translate.c +3 -2
-            qemu_fprintf(f, "%c%c\n", ws ? '<' : ' ', cw ? '=' : ' ');
+            g_string_append_printf(buf, "%c%c\n",
+                                   ws ? '<' : ' ', cw ? '=' : ' ');
         }
     }
 
     if ((flags & CPU_DUMP_FPU) &&
         xtensa_option_enabled(env->config, XTENSA_OPTION_FP_COPROCESSOR)) {
-        qemu_fprintf(f, "\n");
+        g_string_append_printf(buf, "\n");

g_string_append_c(); simpler to move it before this if() statement.

Quoted 8 lines
target/xtensa/translate.c +2 -4
         for (i = 0; i < 16; ++i) {
-            qemu_fprintf(f, "F%02d=%08x (%-+15.8e)%c", i,
-                         float32_val(env->fregs[i].f32[FP_F32_LOW]),
-                         *(float *)(env->fregs[i].f32 + FP_F32_LOW),
-                         (i % 2) == 1 ? '\n' : ' ');
+            g_string_append_printf(buf, "F%02d=%08x (%-+15.8e)%c", i,
+                                   float32_val(env->fregs[i].f32[FP_F32_LOW]),

target/xtensa/translate.c void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 1386

Quoted 10 lines
target/xtensa/translate.c +3 -1
+                                   *(float *)(env->fregs[i].f32 + FP_F32_LOW),
+                                   (i % 2) == 1 ? '\n' : ' ');
         }
     }
 
     if ((flags & CPU_DUMP_FPU) &&
         xtensa_option_enabled(env->config, XTENSA_OPTION_DFP_COPROCESSOR) &&
         !xtensa_option_enabled(env->config, XTENSA_OPTION_DFPU_SINGLE_ONLY)) {
-        qemu_fprintf(f, "\n");
+        g_string_append_printf(buf, "\n");

Ditto (move out).

Quoted 13 lines
target/xtensa/translate.c +4 -4
         for (i = 0; i < 16; ++i) {
-            qemu_fprintf(f, "F%02d=%016"PRIx64" (%-+24.16le)%c", i,
-                         float64_val(env->fregs[i].f64),
-                         *(double *)(&env->fregs[i].f64),
-                         (i % 2) == 1 ? '\n' : ' ');
+            g_string_append_printf(buf, "F%02d=%016"PRIx64" (%-+24.16le)%c", i,
+                                   float64_val(env->fregs[i].f64),
+                                   *(double *)(&env->fregs[i].f64),
+                                   (i % 2) == 1 ? '\n' : ' ');
         }
     }
 }
 
#24 lore raw

Re: [PATCH v2 10/53] target/cris: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 59 lines · Daniel P. Berrangé
---
 target/cris/cpu.c       |  2 +-
 target/cris/cpu.h       |  2 +-
 target/cris/translate.c | 33 +++++++++++++++++----------------
 3 files changed, 19 insertions(+), 18 deletions(-)
target/cris/cpu.c +1 -1
index 70932b1f8c..5159cf6528 100644
@@ -295,7 +295,7 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = cris_cpu_class_by_name;
     cc->has_work = cris_cpu_has_work;
-    cc->dump_state = cris_cpu_dump_state;
+    cc->format_state = cris_cpu_format_state;
     cc->set_pc = cris_cpu_set_pc;
     cc->gdb_read_register = cris_cpu_gdb_read_register;
     cc->gdb_write_register = cris_cpu_gdb_write_register;
target/cris/cpu.h +1 -1
index d3b6492909..908cb051da 100644
@@ -191,7 +191,7 @@ void cris_cpu_do_interrupt(CPUState *cpu);
 void crisv10_cpu_do_interrupt(CPUState *cpu);
 bool cris_cpu_exec_interrupt(CPUState *cpu, int int_req);
 
-void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags);
+void cris_cpu_format_state(CPUState *cs, GString *buf, int flags);
 
 hwaddr cris_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 
target/cris/translate.c +5 -6
index a84b753349..6098693186 100644
@@ -3307,7 +3307,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
     translator_loop(&cris_tr_ops, &dc.base, cs, tb, max_insns);
 }
 
-void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void cris_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     CRISCPU *cpu = CRIS_CPU(cs);
     CPUCRISState *env = &cpu->env;
@@ -3326,40 +3326,41 @@ void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         regnames = regnames_v32;
     }
 
-    qemu_fprintf(f, "PC=%x CCS=%x btaken=%d btarget=%x\n"
-                 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n",
-                 env->pc, env->pregs[PR_CCS], env->btaken, env->btarget,
-                 env->cc_op,
-                 env->cc_src, env->cc_dest, env->cc_result, env->cc_mask);
+    g_string_append_printf(buf, "PC=%x CCS=%x btaken=%d btarget=%x\n"
+                           "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x "
+                           "cc_mask=%x\n",
+                           env->pc, env->pregs[PR_CCS], env->btaken,

target/cris/translate.c void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 3340

Quoted 10 lines
target/cris/translate.c +4 -2
+                           env->btarget, env->cc_op, env->cc_src,
+                           env->cc_dest, env->cc_result, env->cc_mask);
 
 
     for (i = 0; i < 16; i++) {
-        qemu_fprintf(f, "%s=%8.8x ", regnames[i], env->regs[i]);
+        g_string_append_printf(buf, "%s=%8.8x ", regnames[i], env->regs[i]);
         if ((i + 1) % 4 == 0) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");

g_string_append_c() (various).

Quoted 35 lines
target/cris/translate.c +8 -8
         }
     }
-    qemu_fprintf(f, "\nspecial regs:\n");
+    g_string_append_printf(buf, "\nspecial regs:\n");
     for (i = 0; i < 16; i++) {
-        qemu_fprintf(f, "%s=%8.8x ", pregnames[i], env->pregs[i]);
+        g_string_append_printf(buf, "%s=%8.8x ", pregnames[i], env->pregs[i]);
         if ((i + 1) % 4 == 0) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
         }
     }
     if (env->pregs[PR_VR] >= 32) {
         uint32_t srs = env->pregs[PR_SRS];
-        qemu_fprintf(f, "\nsupport function regs bank %x:\n", srs);
+        g_string_append_printf(buf, "\nsupport function regs bank %x:\n", srs);
         if (srs < ARRAY_SIZE(env->sregs)) {
             for (i = 0; i < 16; i++) {
-                qemu_fprintf(f, "s%2.2d=%8.8x ",
-                             i, env->sregs[srs][i]);
+                g_string_append_printf(buf, "s%2.2d=%8.8x ",
+                                       i, env->sregs[srs][i]);
                 if ((i + 1) % 4 == 0) {
-                    qemu_fprintf(f, "\n");
+                    g_string_append_printf(buf, "\n");
                 }
             }
         }
     }
-    qemu_fprintf(f, "\n\n");
+    g_string_append_printf(buf, "\n\n");
 
 }
 
#62 lore raw

Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Review

Quoted 4 lines · Daniel P. Berrangé
     if ((flags & CPU_DUMP_FPU) &&
         xtensa_option_enabled(env->config, XTENSA_OPTION_FP_COPROCESSOR)) {
(quoted diff) +1 -1
-        qemu_fprintf(f, "\n");
+        g_string_append_printf(buf, "\n");

g_string_append_c(); simpler to move it before this if() statement.

It adds spacing between optional blocks, why does it need to be moved out?

Quoted 7 lines

Review

Quoted 5 lines
     if ((flags & CPU_DUMP_FPU) &&
         xtensa_option_enabled(env->config, XTENSA_OPTION_DFP_COPROCESSOR) &&
         !xtensa_option_enabled(env->config, XTENSA_OPTION_DFPU_SINGLE_ONLY)) {
(quoted diff) +1 -1
-        qemu_fprintf(f, "\n");
+        g_string_append_printf(buf, "\n");

Ditto (move out).

Here as well.

Signature · 2 lines
Thanks.
-- Max
#102 lore raw

Re: [PATCH v2 49/53] target/xtensa: convert to use format_tlb callback

In reply to Daniel P. Berrangé
Quoted 26 lines · Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
 target/xtensa/cpu.h        |   2 +-
 target/xtensa/mmu_helper.c | 126 +++++++++++++++++++++----------------
 target/xtensa/monitor.c    |  10 ++-
 3 files changed, 79 insertions(+), 59 deletions(-)
target/xtensa/mmu_helper.c +1 -1
index b01ff9399a..d499255984 100644
@@ -1055,7 +1055,7 @@ int xtensa_get_physical_addr(CPUXtensaState *env, bool update_tlb,
     }
 }
 
-static void dump_tlb(CPUXtensaState *env, bool dtlb)
+static void dump_tlb(CPUXtensaState *env, bool dtlb, GString *buf)
 {
     unsigned wi, ei;
     const xtensa_tlb *conf =
@@ -1094,34 +1094,40 @@ static void dump_tlb(CPUXtensaState *env, bool dtlb)
 
                 if (print_header) {

target/xtensa/mmu_helper.c static void dump_tlb(CPUXtensaState *env, bool dtlb) · line 1102

Quoted 10 lines
target/xtensa/mmu_helper.c +6 -3
                     print_header = false;
-                    qemu_printf("Way %u (%d %s)\n", wi, sz, sz_text);
-                    qemu_printf("\tVaddr       Paddr       ASID  Attr RWX Cache\n"
-                                "\t----------  ----------  ----  ---- --- -------\n");
+                    g_string_append_printf(buf, "Way %u (%d %s)\n",
+                                           wi, sz, sz_text);
+                    g_string_append_printf(buf, "\tVaddr       Paddr       "
+                                           "ASID  Attr RWX Cache\n"
+                                           "\t----------  ----------  ----  "
+                                           "---- --- -------\n");

These lines had a nice visual alignment, now they are broken randomly. Can we please keep them aligned?

Quoted 31 lines
target/xtensa/mmu_helper.c +12 -11
                 }
-                qemu_printf("\t0x%08x  0x%08x  0x%02x  0x%02x %c%c%c %-7s\n",
-                            entry->vaddr,
-                            entry->paddr,
-                            entry->asid,
-                            entry->attr,
-                            (access & PAGE_READ) ? 'R' : '-',
-                            (access & PAGE_WRITE) ? 'W' : '-',
-                            (access & PAGE_EXEC) ? 'X' : '-',
-                            cache_text[cache_idx] ?
-                            cache_text[cache_idx] : "Invalid");
+                g_string_append_printf(buf, "\t0x%08x  0x%08x  0x%02x  "
+                                       "0x%02x %c%c%c %-7s\n",
+                                       entry->vaddr,
+                                       entry->paddr,
+                                       entry->asid,
+                                       entry->attr,
+                                       (access & PAGE_READ) ? 'R' : '-',
+                                       (access & PAGE_WRITE) ? 'W' : '-',
+                                       (access & PAGE_EXEC) ? 'X' : '-',
+                                       cache_text[cache_idx] ?
+                                       cache_text[cache_idx] : "Invalid");
             }
         }
     }
 }
 
 static void dump_mpu(CPUXtensaState *env,
-                     const xtensa_mpu_entry *entry, unsigned n)
+                     const xtensa_mpu_entry *entry, unsigned n, GString *buf)
 {

target/xtensa/mmu_helper.c static void dump_tlb(CPUXtensaState *env, bool dtlb) · line 1128

Quoted 10 lines
target/xtensa/mmu_helper.c +4 -4
     unsigned i;
 
-    qemu_printf("\t%s  Vaddr       Attr        Ring0  Ring1  System Type    CPU cache\n"
-                "\t%s  ----------  ----------  -----  -----  -------------  ---------\n",
-                env ? "En" : "  ",
-                env ? "--" : "  ");
+    g_string_append_printf(buf, "\t%s  Vaddr       Attr        "
+                           "Ring0  Ring1  System Type    CPU cache\n"
+                           "\t%s  ----------  ----------  -----  -----  "
+                           "-------------  ---------\n",

And here as well?

Signature · 2 lines
Thanks.
-- Max
#21 lore raw

Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state

In reply to Philippe Mathieu-Daudé
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 39 lines · Daniel P. Berrangé
---
 target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 28 deletions(-)
target/avr/cpu.c +1 -20
index ea14175ca5..17ff21f8be 100644
@@ -145,43 +145,44 @@ static ObjectClass *avr_cpu_class_by_name(const char *cpu_model)
     return oc;
 }
 
-static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static void avr_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     AVRCPU *cpu = AVR_CPU(cs);
     CPUAVRState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "\n");
-    qemu_fprintf(f, "PC:    %06x\n", env->pc_w * 2); /* PC points to words */
-    qemu_fprintf(f, "SP:      %04x\n", env->sp);
-    qemu_fprintf(f, "rampD:     %02x\n", env->rampD >> 16);
-    qemu_fprintf(f, "rampX:     %02x\n", env->rampX >> 16);
-    qemu_fprintf(f, "rampY:     %02x\n", env->rampY >> 16);
-    qemu_fprintf(f, "rampZ:     %02x\n", env->rampZ >> 16);
-    qemu_fprintf(f, "EIND:      %02x\n", env->eind >> 16);
-    qemu_fprintf(f, "X:       %02x%02x\n", env->r[27], env->r[26]);
-    qemu_fprintf(f, "Y:       %02x%02x\n", env->r[29], env->r[28]);
-    qemu_fprintf(f, "Z:       %02x%02x\n", env->r[31], env->r[30]);
-    qemu_fprintf(f, "SREG:    [ %c %c %c %c %c %c %c %c ]\n",
-                 env->sregI ? 'I' : '-',
-                 env->sregT ? 'T' : '-',
-                 env->sregH ? 'H' : '-',
-                 env->sregS ? 'S' : '-',
-                 env->sregV ? 'V' : '-',
-                 env->sregN ? '-' : 'N', /* Zf has negative logic */
-                 env->sregZ ? 'Z' : '-',
Quoted 8 lines

target/avr/cpu.c static ObjectClass *avr_cpu_class_by_name(const char *cpu_model) · line 154

Quoted 5 lines
target/avr/cpu.c +1 -4
-                 env->sregC ? 'I' : '-');
-    qemu_fprintf(f, "SKIP:    %02x\n", env->skip);
-
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

This would be g_string_append_c(buf, '\n') but in this particular case it doesn't seem helpful so I'd directly remove it.

I don't want to change output format of the commands, with exception of error reporting, as this is intended to be just refactoring patch, not a cleanup patch.

I'm not convinced it is worth special casing single byte strings to use g_string_append_c either really.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#63 lore raw

Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state

In reply to Philippe Mathieu-Daudé
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 45 lines · Daniel P. Berrangé
---
 target/xtensa/cpu.c       |  2 +-
 target/xtensa/cpu.h       |  2 +-
 target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
 3 files changed, 25 insertions(+), 24 deletions(-)
target/xtensa/translate.c +9 -9
-void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void xtensa_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
     xtensa_isa isa = env->config->isa;
     int i, j;
 
-    qemu_fprintf(f, "PC=%08x\n\n", env->pc);
+    g_string_append_printf(buf, "PC=%08x\n\n", env->pc);
 
     for (i = j = 0; i < xtensa_isa_num_sysregs(isa); ++i) {
         const uint32_t *reg =
@@ -1340,55 +1340,56 @@ void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         int regno = xtensa_sysreg_number(isa, i);
 
         if (regno >= 0) {
-            qemu_fprintf(f, "%12s=%08x%c",
-                         xtensa_sysreg_name(isa, i),
-                         reg[regno],
-                         (j++ % 4) == 3 ? '\n' : ' ');
+            g_string_append_printf(buf, "%12s=%08x%c",
+                                   xtensa_sysreg_name(isa, i),
+                                   reg[regno],
+                                   (j++ % 4) == 3 ? '\n' : ' ');
         }
     }
 
-    qemu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n");
+    g_string_append_printf(buf, (j % 4) == 0 ? "\n" : "\n\n");
 
     for (i = 0; i < 16; ++i) {
-        qemu_fprintf(f, " A%02d=%08x%c",
-                     i, env->regs[i], (i % 4) == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, " A%02d=%08x%c",
+                               i, env->regs[i], (i % 4) == 3 ? '\n' : ' ');
     }
 
Quoted 6 lines

target/xtensa/translate.c void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 1358

Quoted 3 lines
target/xtensa/translate.c +1 -1
     xtensa_sync_phys_from_window(env);
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

g_string_append_c(); pre-existing but better to move it before xtensa_sync_phys_from_window().

I don't want to be re-arranging the code in this series. It is just a straight search/replace of qemu_fprintf with g_string_append_printf, with the bare minimum of other changes, to minimize risk of breaking something unexpected.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#22 lore raw

Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 50 lines · Daniel P. Berrangé
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 39 lines · Daniel P. Berrangé
---
 target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 28 deletions(-)
target/avr/cpu.c +1 -20
index ea14175ca5..17ff21f8be 100644
@@ -145,43 +145,44 @@ static ObjectClass *avr_cpu_class_by_name(const char *cpu_model)
     return oc;
 }
 
-static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+static void avr_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     AVRCPU *cpu = AVR_CPU(cs);
     CPUAVRState *env = &cpu->env;
     int i;
 
-    qemu_fprintf(f, "\n");
-    qemu_fprintf(f, "PC:    %06x\n", env->pc_w * 2); /* PC points to words */
-    qemu_fprintf(f, "SP:      %04x\n", env->sp);
-    qemu_fprintf(f, "rampD:     %02x\n", env->rampD >> 16);
-    qemu_fprintf(f, "rampX:     %02x\n", env->rampX >> 16);
-    qemu_fprintf(f, "rampY:     %02x\n", env->rampY >> 16);
-    qemu_fprintf(f, "rampZ:     %02x\n", env->rampZ >> 16);
-    qemu_fprintf(f, "EIND:      %02x\n", env->eind >> 16);
-    qemu_fprintf(f, "X:       %02x%02x\n", env->r[27], env->r[26]);
-    qemu_fprintf(f, "Y:       %02x%02x\n", env->r[29], env->r[28]);
-    qemu_fprintf(f, "Z:       %02x%02x\n", env->r[31], env->r[30]);
-    qemu_fprintf(f, "SREG:    [ %c %c %c %c %c %c %c %c ]\n",
-                 env->sregI ? 'I' : '-',
-                 env->sregT ? 'T' : '-',
-                 env->sregH ? 'H' : '-',
-                 env->sregS ? 'S' : '-',
-                 env->sregV ? 'V' : '-',
-                 env->sregN ? '-' : 'N', /* Zf has negative logic */
-                 env->sregZ ? 'Z' : '-',
Quoted 8 lines

target/avr/cpu.c static ObjectClass *avr_cpu_class_by_name(const char *cpu_model) · line 154

Quoted 5 lines
target/avr/cpu.c +1 -4
-                 env->sregC ? 'I' : '-');
-    qemu_fprintf(f, "SKIP:    %02x\n", env->skip);
-
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

This would be g_string_append_c(buf, '\n') but in this particular case it doesn't seem helpful so I'd directly remove it.

Quoted 3 lines

I don't want to change output format of the commands, with exception of error reporting, as this is intended to be just refactoring patch, not a cleanup patch.

I misread cpu_dump_state(), I thought it was already appending a newline, but it is not:

@@ -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 = g_string_new("");
+        cpu_synchronize_state(cpu);
+        cc->format_state(cpu, buf, flags);
+        qemu_fprintf(f, "%s", buf->str);

So we are fine.

Quoted 2 lines

I'm not convinced it is worth special casing single byte strings to use g_string_append_c either really.

OK. R-b stands ;)

#64 lore raw

Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 54 lines · Daniel P. Berrangé
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 45 lines · Daniel P. Berrangé
---
 target/xtensa/cpu.c       |  2 +-
 target/xtensa/cpu.h       |  2 +-
 target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
 3 files changed, 25 insertions(+), 24 deletions(-)
target/xtensa/translate.c +9 -9
-void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void xtensa_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
     xtensa_isa isa = env->config->isa;
     int i, j;
 
-    qemu_fprintf(f, "PC=%08x\n\n", env->pc);
+    g_string_append_printf(buf, "PC=%08x\n\n", env->pc);
 
     for (i = j = 0; i < xtensa_isa_num_sysregs(isa); ++i) {
         const uint32_t *reg =
@@ -1340,55 +1340,56 @@ void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         int regno = xtensa_sysreg_number(isa, i);
 
         if (regno >= 0) {
-            qemu_fprintf(f, "%12s=%08x%c",
-                         xtensa_sysreg_name(isa, i),
-                         reg[regno],
-                         (j++ % 4) == 3 ? '\n' : ' ');
+            g_string_append_printf(buf, "%12s=%08x%c",
+                                   xtensa_sysreg_name(isa, i),
+                                   reg[regno],
+                                   (j++ % 4) == 3 ? '\n' : ' ');
         }
     }
 
-    qemu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n");
+    g_string_append_printf(buf, (j % 4) == 0 ? "\n" : "\n\n");
 
     for (i = 0; i < 16; ++i) {
-        qemu_fprintf(f, " A%02d=%08x%c",
-                     i, env->regs[i], (i % 4) == 3 ? '\n' : ' ');
+        g_string_append_printf(buf, " A%02d=%08x%c",
+                               i, env->regs[i], (i % 4) == 3 ? '\n' : ' ');
     }
 
Quoted 6 lines

target/xtensa/translate.c void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 1358

Quoted 3 lines
target/xtensa/translate.c +1 -1
     xtensa_sync_phys_from_window(env);
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");

g_string_append_c(); pre-existing but better to move it before xtensa_sync_phys_from_window().

Quoted 4 lines

I don't want to be re-arranging the code in this series. It is just a straight search/replace of qemu_fprintf with g_string_append_printf, with the bare minimum of other changes, to minimize risk of breaking something unexpected.

Fair enough. Max already rejected my suggestions ;) So:

Acked-by on v2 25/53
#57 lore raw

Re: [PATCH v2 25/53] target/sparc: convert to use format_state instead of dump_state

In reply to Daniel P. Berrangé
Quoted 159 lines · Daniel P. Berrangé
---
  target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
  target/sparc/cpu.h |  2 +-
  2 files changed, 47 insertions(+), 40 deletions(-)
target/sparc/cpu.c +46 -39
index da6b30ec74..9346a79239 100644
@@ -597,11 +597,11 @@ void sparc_cpu_list(void)
                  "fpu_version mmu_version nwindows\n");
  }
 
-static void cpu_print_cc(FILE *f, uint32_t cc)
+static void cpu_print_cc(GString *buf, uint32_t cc)
  {
-    qemu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
-                 cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
-                 cc & PSR_CARRY ? 'C' : '-');
+    g_string_append_printf(buf, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
+                           cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
+                           cc & PSR_CARRY ? 'C' : '-');
  }
 
  #ifdef TARGET_SPARC64
@@ -610,34 +610,36 @@ static void cpu_print_cc(FILE *f, uint32_t cc)
  #define REGS_PER_LINE 8
  #endif
 
-void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void sparc_cpu_format_state(CPUState *cs, GString *buf, int flags)
  {
      SPARCCPU *cpu = SPARC_CPU(cs);
      CPUSPARCState *env = &cpu->env;
      int i, x;
 
-    qemu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
-                 env->npc);
+    g_string_append_printf(buf,
+                           "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n",
+                           env->pc, env->npc);
 
      for (i = 0; i < 8; i++) {
          if (i % REGS_PER_LINE == 0) {
-            qemu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
+            g_string_append_printf(buf, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
          }
-        qemu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
+        g_string_append_printf(buf, " " TARGET_FMT_lx, env->gregs[i]);
          if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
-            qemu_fprintf(f, "\n");
+            g_string_append_printf(buf, "\n");
          }
      }
      for (x = 0; x < 3; x++) {
          for (i = 0; i < 8; i++) {
              if (i % REGS_PER_LINE == 0) {
-                qemu_fprintf(f, "%%%c%d-%d: ",
+                g_string_append_printf(buf, "%%%c%d-%d: ",
                               x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
                               i, i + REGS_PER_LINE - 1);
              }
-            qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
+            g_string_append_printf(buf, TARGET_FMT_lx " ",
+                                   env->regwptr[i + x * 8]);
              if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");
              }
          }
      }
@@ -645,42 +647,47 @@ void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
      if (flags & CPU_DUMP_FPU) {
          for (i = 0; i < TARGET_DPREGS; i++) {
              if ((i & 3) == 0) {
-                qemu_fprintf(f, "%%f%02d: ", i * 2);
+                g_string_append_printf(buf, "%%f%02d: ", i * 2);
              }
-            qemu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
+            g_string_append_printf(buf, " %016" PRIx64, env->fpr[i].ll);
              if ((i & 3) == 3) {
-                qemu_fprintf(f, "\n");
+                g_string_append_printf(buf, "\n");
              }
          }
      }
 
  #ifdef TARGET_SPARC64
-    qemu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
+    g_string_append_printf(buf, "pstate: %08x ccr: %02x (icc: ", env->pstate,
                   (unsigned)cpu_get_ccr(env));
-    cpu_print_cc(f, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
-    qemu_fprintf(f, " xcc: ");
-    cpu_print_cc(f, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
-    qemu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl,
-                 env->psrpil, env->gl);
-    qemu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: "
-                 TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba);
-    qemu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
-                 "cleanwin: %d cwp: %d\n",
-                 env->cansave, env->canrestore, env->otherwin, env->wstate,
-                 env->cleanwin, env->nwindows - 1 - env->cwp);
-    qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: "
-                 TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs);
+    cpu_print_cc(buf, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
+    g_string_append_printf(buf, " xcc: ");
+    cpu_print_cc(buf, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
+    g_string_append_printf(buf, ") asi: %02x tl: %d pil: %x gl: %d\n",
+                           env->asi, env->tl, env->psrpil, env->gl);
+    g_string_append_printf(buf, "tbr: " TARGET_FMT_lx " hpstate: "
+                           TARGET_FMT_lx " htba: " TARGET_FMT_lx "\n",
+                           env->tbr, env->hpstate, env->htba);
+    g_string_append_printf(buf, "cansave: %d canrestore: %d "
+                           "otherwin: %d wstate: %d "
+                           "cleanwin: %d cwp: %d\n",
+                           env->cansave, env->canrestore,
+                           env->otherwin, env->wstate,
+                           env->cleanwin, env->nwindows - 1 - env->cwp);
+    g_string_append_printf(buf, "fsr: " TARGET_FMT_lx " y: "
+                           TARGET_FMT_lx " fprs: " TARGET_FMT_lx "\n",
+                           env->fsr, env->y, env->fprs);
 
  #else
-    qemu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
-    cpu_print_cc(f, cpu_get_psr(env));
-    qemu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
-                 env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
-                 env->wim);
-    qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
-                 env->fsr, env->y);
+    g_string_append_printf(buf, "psr: %08x (icc: ", cpu_get_psr(env));
+    cpu_print_cc(buf, cpu_get_psr(env));
+    g_string_append_printf(buf, " SPE: %c%c%c) wim: %08x\n",
+                           env->psrs ? 'S' : '-',
+                           env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
+                           env->wim);
+    g_string_append_printf(buf, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
+                           env->fsr, env->y);
  #endif
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
  }
 
  static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
@@ -889,7 +896,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)
      cc->class_by_name = sparc_cpu_class_by_name;
      cc->parse_features = sparc_cpu_parse_features;
      cc->has_work = sparc_cpu_has_work;
-    cc->dump_state = sparc_cpu_dump_state;
+    cc->format_state = sparc_cpu_format_state;
  #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
      cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
  #endif
target/sparc/cpu.h +0 -0
index ff8ae73002..65a01a7884 100644

target/sparc/cpu.h extern const VMStateDescription vmstate_sparc_cpu; · line 577

Quoted 8 lines
target/sparc/cpu.h +1 -1
@@ -571,7 +571,7 @@ extern const VMStateDescription vmstate_sparc_cpu;
  #endif
 
  void sparc_cpu_do_interrupt(CPUState *cpu);
-void sparc_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+void sparc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
  hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
  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);

ATB,

Mark.

Acked-by on v2 48/53
#100 lore raw

Re: [PATCH v2 48/53] target/sparc: convert to use format_tlb callback

In reply to Daniel P. Berrangé
Quoted 125 lines · Daniel P. Berrangé

Change the "info tlb" implementation to use the format_tlb callback.

---
  target/sparc/cpu.c        |  1 +
  target/sparc/cpu.h        |  1 +
  target/sparc/mmu_helper.c | 43 ++++++++++++++++++++++++---------------
  target/sparc/monitor.c    | 10 ++++++---
  4 files changed, 36 insertions(+), 19 deletions(-)
target/sparc/cpu.c +1 -0
index 9346a79239..f78ddc72b5 100644
@@ -898,6 +898,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)
      cc->has_work = sparc_cpu_has_work;
      cc->format_state = sparc_cpu_format_state;
  #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
+    cc->format_tlb = sparc_cpu_format_tlb;
      cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
  #endif
      cc->set_pc = sparc_cpu_set_pc;
target/sparc/cpu.h +1 -0
index 65a01a7884..233f0b3eb7 100644
@@ -572,6 +572,7 @@ extern const VMStateDescription vmstate_sparc_cpu;
 
  void sparc_cpu_do_interrupt(CPUState *cpu);
  void sparc_cpu_format_state(CPUState *cpu, GString *buf, int flags);
+void sparc_cpu_format_tlb(CPUState *cpu, GString *buf);
  hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
  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);
target/sparc/mmu_helper.c +27 -16
index a44473a1c7..06b16aca6a 100644
@@ -371,37 +371,39 @@ target_ulong mmu_probe(CPUSPARCState *env, target_ulong address, int mmulev)
      return 0;
  }
 
-void dump_mmu(CPUSPARCState *env)
+void sparc_cpu_format_tlb(CPUState *cpu, GString *buf)
  {
-    CPUState *cs = env_cpu(env);
+    CPUSPARCState *env = cpu->env_ptr;
      target_ulong va, va1, va2;
      unsigned int n, m, o;
      hwaddr pa;
      uint32_t pde;
 
-    qemu_printf("Root ptr: " TARGET_FMT_plx ", ctx: %d\n",
-                (hwaddr)env->mmuregs[1] << 4, env->mmuregs[2]);
+    g_string_append_printf(buf, "Root ptr: " TARGET_FMT_plx ", ctx: %d\n",
+                           (hwaddr)env->mmuregs[1] << 4, env->mmuregs[2]);
      for (n = 0, va = 0; n < 256; n++, va += 16 * 1024 * 1024) {
          pde = mmu_probe(env, va, 2);
          if (pde) {
-            pa = cpu_get_phys_page_debug(cs, va);
-            qemu_printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx
-                        " PDE: " TARGET_FMT_lx "\n", va, pa, pde);
+            pa = cpu_get_phys_page_debug(cpu, va);
+            g_string_append_printf(buf, "VA: " TARGET_FMT_lx
+                                   ", PA: " TARGET_FMT_plx
+                                   " PDE: " TARGET_FMT_lx "\n", va, pa, pde);
              for (m = 0, va1 = va; m < 64; m++, va1 += 256 * 1024) {
                  pde = mmu_probe(env, va1, 1);
                  if (pde) {
-                    pa = cpu_get_phys_page_debug(cs, va1);
-                    qemu_printf(" VA: " TARGET_FMT_lx ", PA: "
-                                TARGET_FMT_plx " PDE: " TARGET_FMT_lx "\n",
-                                va1, pa, pde);
+                    pa = cpu_get_phys_page_debug(cpu, va1);
+                    g_string_append_printf(buf, " VA: " TARGET_FMT_lx
+                                           ", PA: " TARGET_FMT_plx
+                                           " PDE: " TARGET_FMT_lx "\n",
+                                           va1, pa, pde);
                      for (o = 0, va2 = va1; o < 64; o++, va2 += 4 * 1024) {
                          pde = mmu_probe(env, va2, 0);
                          if (pde) {
-                            pa = cpu_get_phys_page_debug(cs, va2);
-                            qemu_printf("  VA: " TARGET_FMT_lx ", PA: "
-                                        TARGET_FMT_plx " PTE: "
-                                        TARGET_FMT_lx "\n",
-                                        va2, pa, pde);
+                            pa = cpu_get_phys_page_debug(cpu, va2);
+                            g_string_append_printf(buf, "  VA: " TARGET_FMT_lx
+                                                   ", PA: " TARGET_FMT_plx
+                                                   " PTE: " TARGET_FMT_lx "\n",
+                                                   va2, pa, pde);
                          }
                      }
                  }
@@ -410,6 +412,15 @@ void dump_mmu(CPUSPARCState *env)
      }
  }
 
+void dump_mmu(CPUSPARCState *env)
+{
+    CPUState *cs = env_cpu(env);
+    g_autoptr(GString) buf = g_string_new("");
+
+    sparc_cpu_format_tlb(cs, buf);
+    qemu_printf("%s", buf->str);
+}
+
  /* Gdb expects all registers windows to be flushed in ram. This function handles
   * reads (and only reads) in stack frames as if windows were flushed. We assume
   * that the sparc ABI is followed.
target/sparc/monitor.c +3 -2
index 318413686a..cc7fe74e3e 100644
@@ -30,13 +30,17 @@
 
  void hmp_info_tlb(Monitor *mon, const QDict *qdict)
  {
-    CPUArchState *env1 = mon_get_cpu_env(mon);
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env1) {
+    if (!cpu) {
          monitor_printf(mon, "No CPU available\n");

target/sparc/monitor.c line 46

Quoted 10 lines
target/sparc/monitor.c +4 -1
          return;
      }
-    dump_mmu(env1);
+
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
  }
 
  #ifndef TARGET_SPARC64

ATB,

Mark.

#2 lore raw

Re: [PATCH v2 01/53] docs/devel: rename file for writing monitor commands

In reply to Daniel P. Berrangé
Quoted 28 lines · Daniel P. Berrangé

The file already covers writing new style HMP commands, in addition to the QMP commands, so it deserves a more general name.

---
 docs/devel/index.rst                                        | 2 +-
 ...riting-qmp-commands.rst => writing-monitor-commands.rst} | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
 rename docs/devel/{writing-qmp-commands.rst => writing-monitor-commands.rst} (99%)
docs/devel/index.rst +1 -1
index f95df10b3e..7c25177c5d 100644
@@ -44,4 +44,4 @@ modifying QEMU's source code.
    ebpf_rss
    vfio-migration
    qapi-code-gen
-   writing-qmp-commands
+   writing-monitor-commands
docs/devel/writing-monitor-commands.rst renamed from docs/devel/writing-qmp-commands.rst +0 -0
similarity index 99%
rename from docs/devel/writing-qmp-commands.rst
rename to docs/devel/writing-monitor-commands.rst
index 6a10a06c48..497c9ce0d5 100644

docs/devel/writing-monitor-commands.rst line 5

Quoted 8 lines
docs/devel/writing-monitor-commands.rst renamed from docs/devel/writing-qmp-commands.rst +3 -3
@@ -1,8 +1,8 @@
-How to write QMP commands using the QAPI framework
-==================================================
+How to write monitor commands
+=============================
 
 This document is a step-by-step guide on how to write new QMP commands using
-the QAPI framework. It also shows how to implement new style HMP commands.
+the QAPI framework and new style HMP commands.

Recommend to drop "new style", here and in the commit message.

Back when this file was written, we did have several "styles" of HMP commands:

    typedef struct mon_cmd_t {
        const char *name;
        const char *args_type;
        const char *params;
        const char *help;
        void (*user_print)(Monitor *mon, const QObject *data);
        union {
            void (*info)(Monitor *mon);
            void (*cmd)(Monitor *mon, const QDict *qdict);
            int  (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data);
            int  (*cmd_async)(Monitor *mon, const QDict *params,
                              MonitorCompletion *cb, void *opaque);
        } mhandler;
        bool qapi;
        int flags;
    } mon_cmd_t;
    [...]
    static void handle_user_command(Monitor *mon, const char *cmdline)
    {
        QDict *qdict;
        const mon_cmd_t *cmd;

        qdict = qdict_new();

        cmd = monitor_parse_command(mon, cmdline, qdict);
        if (!cmd)
            goto out;

        if (handler_is_async(cmd)) {
            user_async_cmd_handler(mon, cmd, qdict);
        } else if (handler_is_qobject(cmd)) {
            QObject *data = NULL;

            /* XXX: ignores the error code */
            cmd->mhandler.cmd_new(mon, qdict, &data);
            assert(!monitor_has_error(mon));
            if (data) {
                cmd->user_print(mon, data);
                qobject_decref(data);
            }
        } else {
            cmd->mhandler.cmd(mon, qdict);
        }

    out:
        QDECREF(qdict);
    }

Async: add MONITOR_CMD_ASYNC to ->flags, use ->mhandler.async().

New: set ->user_print and ->mhandler.cmd_new.

Old: keep ->user_print() null, and set ->mhandler.cmd().

"Async" style never really worked, and was buried in commit 65207c59d9 "monitor: Drop broken, unused asynchronous command interface".

"New" style was buried in commit 8a4f501c09 "monitor: Drop unused "new" HMP command interface".

Both burials got merged into master in June 2015. "Old" style has been the only style since then.

Quoted 2 lines
docs/devel/writing-monitor-commands.rst renamed from docs/devel/writing-qmp-commands.rst +0 -0
 This document doesn't discuss QMP protocol level details, nor does it dive
 into the QAPI framework implementation.
Reviewed-by on v2 2/53
#5 lore raw

Re: [PATCH v2 02/53] docs/devel: tweak headings in monitor command docs

In reply to Daniel P. Berrangé
Quoted 24 lines · Daniel P. Berrangé

The new headings reflect the intended structure of the document and will better suit additions that follow.

---
 docs/devel/writing-monitor-commands.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
docs/devel/writing-monitor-commands.rst +2 -2
index 497c9ce0d5..cddb36fb74 100644
@@ -85,8 +85,8 @@ any data". Now you're ready to enter the QMP example commands as explained in
 the following sections.
 
 
-Writing a command that doesn't return data
-------------------------------------------
+Writing a simple command: hello-world
+-------------------------------------
 
 That's the most simple QMP command that can be written. Usually, this kind of
 command carries some meaningful action in QEMU but here it will just print

docs/devel/writing-monitor-commands.rst Please, check the "-monitor" command-line option to know how to open a user · line 347

Quoted 10 lines
docs/devel/writing-monitor-commands.rst +2 -2
@@ -340,8 +340,8 @@ Please, check the "-monitor" command-line option to know how to open a user
 monitor.
 
 
-Writing a command that returns data
------------------------------------
+Writing more complex commands
+-----------------------------
 
 A QMP command is capable of returning any data the QAPI supports like integers,
 strings, booleans, enumerations and user defined types.
Reviewed-by on v2 3/53
#7 lore raw

Re: [PATCH v2 03/53] docs/devel: document expectations for QAPI data modelling for QMP

In reply to Daniel P. Berrangé
Quoted 71 lines · Daniel P. Berrangé

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.

---
 docs/devel/writing-monitor-commands.rst | 27 +++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
docs/devel/writing-monitor-commands.rst +19 -0
index cddb36fb74..d68c552fdd 100644
@@ -350,6 +350,33 @@ In this section we will focus on user defined types. Please, check the QAPI
 documentation for information about the other types.
 
 
+Modelling data in QAPI
+~~~~~~~~~~~~~~~~~~~~~~
+
+For a QMP command that to be considered stable and supported long term,
+there is a requirement returned data should be explicitly modelled
+using fine-grained QAPI types. As a general guide, a caller of the QMP
+command should never need to parse individual returned data fields. If
+a field appears to need parsing, then 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 ad hoc 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 defining 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.

docs/devel/writing-monitor-commands.rst In this section we will focus on user defined types. Please, check the QAPI · line 381

Quoted 10 lines
docs/devel/writing-monitor-commands.rst +8 -0
+This indicates that the command is not guaranteed to be long term
+stable / liable to change in future and is not following QAPI design
+best practices. An example where this approach is taken is the QMP
+command "x-query-registers". This returns a formatted dump of the
+architecture specific CPU state. The way the data is formatted varies
+across QEMU targets, is liable to change over time, and is only
+intended to be consumed as an opaque string by machines.
+
 User Defined Types
 ~~~~~~~~~~~~~~~~~~
#9 lore raw

Re: [PATCH v2 04/53] docs/devel: add example of command returning unstructured text

In reply to Daniel P. Berrangé

docs/devel/writing-monitor-commands.rst has to traverse the list, it's shown below for reference::

Quoted 14 lines · Daniel P. Berrangé

This illustrates how to add a QMP command returning unstructured text, following the guidelines added in the previous patch. The example uses a simplified version of 'info roms'.

---
 docs/devel/writing-monitor-commands.rst | 85 +++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
docs/devel/writing-monitor-commands.rst +0 -0
index d68c552fdd..4cf51ab557 100644
@@ -647,3 +647,88 @@ has to traverse the list, it's shown below for reference::

Modelling data in QAPI
~~~~~~~~~~~~~~~~~~~~~~

For a QMP command that to be considered stable and supported long term, there is a requirement returned data should be explicitly modelled using fine-grained QAPI types. As a general guide, a caller of the QMP command should never need to parse individual returned data fields. If a field appears to need parsing, then 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 ad hoc 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 defining 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 design best practices. An example where this approach is taken is the QMP command "x-query-registers". This returns a formatted dump of the architecture specific CPU state. The way the data is formatted varies across QEMU targets, is liable to change over time, and is only intended to be consumed as an opaque string by machines.

Recommend to add a forward reference to section "Writing a debugging aid ..." here.

[...]

docs/devel/writing-monitor-commands.rst has to traverse the list, it's shown below for reference:: · line 654

Quoted 8 lines
docs/devel/writing-monitor-commands.rst +5 -0
      qapi_free_TimerAlarmMethodList(method_list);
  }
+
+Writing a debugging aid returning unstructured text
+---------------------------------------------------
+
+As discussed at the start of the previous example, it is required that

Suggest 'As discussed in section "Modelling data in QAPI"'.

Quoted 51 lines
docs/devel/writing-monitor-commands.rst +51 -0
+commands expecting machine usage be using fine-grained QAPI data types.
+The exception to this rule applies when the command is solely intended
+as a debugging aid and allows for returning unstructured text. This is
+commonly needed for query commands that report aspects of QEMU's
+internal state that are useful to human operators.
+
+In this example we will consider a simplified variant of the HMP
+command ``info roms``. Following the earlier rules, this command will
+need to live under the ``x-`` name prefix, so its QMP implementation
+will be called ``x-query-roms``. It will have no parameters and will
+return a single text string::
+
+ { 'struct': 'HumanReadableText',
+   'data': { 'human-readable-text': 'str' } }
+
+ { 'command': 'x-query-roms',
+   'returns': 'HumanReadableText' }
+
+The ``HumanReadableText`` struct is intended to be used for all
+commands, under the ``x-`` name prefix that are returning unstructured
+text targetted at humans. It should never be used for commands outside
+the ``x-`` name prefix, as those should be using structured QAPI types.
+
+Implementing the QMP command
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The QMP implementation will typically involve creating a ``GString``
+object and printing formatted data into it::
+
+ HumanReadableText *qmp_x_query_roms(Error **errp)
+ {
+     GString buf = g_string_new("");
+     HumanReadableText ret = g_new0(HumanReadableText, 1);
+     Rom *rom;
+
+     QTAILQ_FOREACH(rom, &roms, next) {
+        g_string_append_printf("%s size=0x%06zx name=\"%s\"\n",
+                               memory_region_name(rom->mr),
+                               rom->romsize,
+                               rom->name);
+     }
+
+     ret->human_readable_text = g_string_free(buf, FALSE);
+
+     return ret;
+ }
+
+
+Implementing the HMP command
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+

docs/devel/writing-monitor-commands.rst has to traverse the list, it's shown below for reference:: · line 715

Quoted 10 lines
docs/devel/writing-monitor-commands.rst +10 -0
+Now that the QMP command is in place, we can also make it available in
+the human monitor (HMP) as shown in previous examples. The HMP
+implementations will all look fairly similar, as all they need do is
+invoke the QMP command and then print the resulting text or error
+message. Here's the implementation of the "info roms" HMP command::
+
+ void hmp_info_roms(Monitor *mon, const QDict *qdict)
+ {
+     Error err = NULL;
+     g_autoptr(HumanReadableText) info = qmp_x_query_roms(&err);

Humor me: blank line between declarations and statements, please.

Quoted 19 lines
docs/devel/writing-monitor-commands.rst +19 -0
+     if (err) {
+         error_report_err(err);
+         return;
+     }
+     monitor_printf(mon, "%s\n", info->human_readable_text);
+ }
+
+Also, you have to add the function's prototype to the hmp.h file.
+
+There's one last step to actually make the command available to
+monitor users, we should add it to the hmp-commands-info.hx file::
+
+    {
+        .name       = "roms",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show roms",
+        .cmd        = hmp_info_roms,
+    },
#11 lore raw

Re: [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future

In reply to Daniel P. Berrangé
Quoted 18 lines · Daniel P. Berrangé

We no longer wish to have commands implemented in HMP only. All commands should start with a QMP implementation and the HMP merely be a shim around this. To reduce the burden of implementing QMP commands where there is low expectation of machine usage, requirements for QAPI modelling are relaxed provided the command is under the "x-" name prefix.

---
 docs/devel/writing-monitor-commands.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
docs/devel/writing-monitor-commands.rst +0 -0
index 4cf51ab557..983130a793 100644
@@ -11,6 +11,16 @@ For an in-depth introduction to the QAPI framework, please refer to
 docs/devel/qapi-code-gen.txt. For documentation about the QMP protocol,

docs/devel/writing-monitor-commands.rst For an in-depth introduction to the QAPI framework, please refer to · line 21

Quoted 10 lines
docs/devel/writing-monitor-commands.rst +8 -0
 start with docs/interop/qmp-intro.txt.
 
+Historically QEMU has permitted new monitor commands to be implemented in HMP
+only, QMP only, or both, depending on whether they needed to be accessible to
+human operators, machines, or both. When both QMP and HMP are implemented it
+is expected the HMP implementation is a shim around the QMP implementation.
+Going forward, the expectation is that new commands are implemented in QMP
+only, or both QMP and HMP. No further commands are to be added to HMP only.
+The long term goal is that all HMP commands will be implemented in terms of
+their QMP equivalent, enabling internals of QEMU to be fully isolated from

This feels a bit too tight. Most HMP commands are going to wrap around their equivalent QMP command. However, high-level HMP commands built from low-level QMP building blocks remain permissble.

docs/devel/writing-monitor-commands.rst For an in-depth introduction to the QAPI framework, please refer to · line 22

Quoted 1 line
docs/devel/writing-monitor-commands.rst +1 -0
+the HMP implementation. Refer to the later topic on modelling data in QAPI

Suggest to use the exact section name for easy searching, or even better, make it a link.

docs/devel/writing-monitor-commands.rst For an in-depth introduction to the QAPI framework, please refer to · line 26

Quoted 4 lines
docs/devel/writing-monitor-commands.rst +1 -0
+for further guidance on commands that would have traditionally been HMP only.
 
 Overview
 --------

Discussing history is quite valuable in commit messages, but less so in a "how to do stuff" document. Consider cutting this down some. What about:

New commands may be implemented in QMP only. New HMP commands should be implemented on top of QMP. The typical HMP command wraps around an equivalent QMP command, but HMP convenience commands built from QMP building blocks are also fine. The long term goal is to make all existing HMP commands conform to this, to fully isolate HMP from the internals of QEMU.

#82 lore raw

Re: [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command

In reply to Daniel P. Berrangé

Hi Daniel,

Quoted 385 lines · Daniel P. Berrangé

This is a counterpart to the HMP "info lapic" 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. The existing HMP command is rewritten to call the QMP command.

This command is unable to use the pre-existing HumanReadableText, because if 'common.json' is included into 'machine-target.json' the static marshalling method for HumanReadableText will be reported as unused by the compiler on all architectures except s390x.

Possible options were

1 Support 'if' conditionals on 'include' statements in QAPI 2 Add further commands to 'machine-target.json' that use
HumanReadableText, such that it has at least one usage on all architecture targets.
3 Duplicate HumanReadableText as TargetHumanReadableText
adding conditions

This patch takes option (3) in the belief that we will eventually get to a point where option (2) happens, and TargetHumanReadableText can be removed again.

---
 hw/core/cpu-common.c     |   7 ++
 include/hw/core/cpu.h    |  10 +++
 qapi/machine-target.json |  19 ++++-
 target/i386/cpu-dump.c   | 161 ++++++++++++++++++++-------------------
 target/i386/cpu.h        |   4 +-
 target/i386/monitor.c    |  46 +++++++++--
 6 files changed, 160 insertions(+), 87 deletions(-)
hw/core/cpu-common.c +7 -0
index c2cd33a817..d1ebc77d1b 100644
@@ -49,6 +49,13 @@ CPUState *cpu_by_arch_id(int64_t id)
     return NULL;
 }
 
+int64_t cpu_get_arch_id(CPUState *cpu)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+
+    return cc->get_arch_id(cpu);
+}
+
 bool cpu_exists(int64_t id)
 {
     return !!cpu_by_arch_id(id);
include/hw/core/cpu.h +10 -0
index 1599ef9df3..a0913eedaa 100644
@@ -780,6 +780,16 @@ bool cpu_exists(int64_t id);
  */
 CPUState *cpu_by_arch_id(int64_t id);
 
+/**
+ * cpu_get_arch_id:
+ * @cpu: the CPU to query
+ *
+ * Get the guest exposed CPU ID for @cpu
+ *
+ * Returns: The guest exposed CPU ID
+ */
+int64_t cpu_get_arch_id(CPUState *cpu);
+
 /**
  * cpu_interrupt:
  * @cpu: The CPU to set an interrupt on.
qapi/machine-target.json +18 -1
index 9040aff863..62220d1f08 100644
@@ -353,7 +353,8 @@
 ##
 { 'struct': 'TargetHumanReadableText',
   'data': { 'human-readable-text': 'str' },
-  'if': 'TARGET_S390X' }
+  'if': { 'any': ['TARGET_S390X',
+                  'TARGET_I386' ] } }
 
 ##
 # @x-query-cmma:
@@ -369,6 +370,22 @@
   'returns': 'TargetHumanReadableText',
   'if': 'TARGET_S390X' }
 
+##
+# @x-query-lapic:
+#
+# @apic-id: the local APIC ID to report
+#
+# Query local APIC state.
+#
+# Returns: local APIC state
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-lapic',
+  'data': { 'apic-id': 'int' },
+  'returns': 'TargetHumanReadableText',
+  'if': 'TARGET_I386' }
+
 ##
 # @x-query-skeys:
 #
target/i386/cpu-dump.c +84 -77
index f30fbcb76e..41a1f64138 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "qemu/qemu-print.h"
+#include "qapi/error.h"
 #ifndef CONFIG_USER_ONLY
 #include "hw/i386/apic_internal.h"
 #endif
@@ -179,24 +180,26 @@ static inline const char *dm2str(uint32_t dm)
     return str[dm];
 }
 
-static void dump_apic_lvt(const char *name, uint32_t lvt, bool is_timer)
+static void format_apic_lvt(const char *name, uint32_t lvt, bool is_timer,
+                            GString *buf)
 {
     uint32_t dm = (lvt & APIC_LVT_DELIV_MOD) >> APIC_LVT_DELIV_MOD_SHIFT;
-    qemu_printf("%s\t 0x%08x %s %-5s %-6s %-7s %-12s %-6s",
-                name, lvt,
-                lvt & APIC_LVT_INT_POLARITY ? "active-lo" : "active-hi",
-                lvt & APIC_LVT_LEVEL_TRIGGER ? "level" : "edge",
-                lvt & APIC_LVT_MASKED ? "masked" : "",
-                lvt & APIC_LVT_DELIV_STS ? "pending" : "",
-                !is_timer ?
-                    "" : lvt & APIC_LVT_TIMER_PERIODIC ?
-                            "periodic" : lvt & APIC_LVT_TIMER_TSCDEADLINE ?
-                                            "tsc-deadline" : "one-shot",
+    g_string_append_printf(buf, "%s\t 0x%08x %s %-5s %-6s %-7s %-12s %-6s",
+                           name, lvt,
+                           lvt & APIC_LVT_INT_POLARITY ?
+                           "active-lo" : "active-hi",
+                           lvt & APIC_LVT_LEVEL_TRIGGER ? "level" : "edge",
+                           lvt & APIC_LVT_MASKED ? "masked" : "",
+                           lvt & APIC_LVT_DELIV_STS ? "pending" : "",
+                           !is_timer ?
+                           "" : lvt & APIC_LVT_TIMER_PERIODIC ?
+                           "periodic" : lvt & APIC_LVT_TIMER_TSCDEADLINE ?
+                           "tsc-deadline" : "one-shot",
                 dm2str(dm));
     if (dm != APIC_DM_NMI) {
-        qemu_printf(" (vec %u)\n", lvt & APIC_VECTOR_MASK);
+        g_string_append_printf(buf, " (vec %u)\n", lvt & APIC_VECTOR_MASK);
     } else {
-        qemu_printf("\n");
+        g_string_append_printf(buf, "\n");
     }
 }
 
@@ -228,7 +231,7 @@ static inline void mask2str(char *str, uint32_t val, uint8_t size)
 
 #define MAX_LOGICAL_APIC_ID_MASK_SIZE 16
 
-static void dump_apic_icr(APICCommonState *s, CPUX86State *env)
+static void format_apic_icr(APICCommonState *s, CPUX86State *env, GString *buf)
 {
     uint32_t icr = s->icr[0], icr2 = s->icr[1];
     uint8_t dest_shorthand = \
@@ -238,16 +241,16 @@ static void dump_apic_icr(APICCommonState *s, CPUX86State *env)
     uint32_t dest_field;
     bool x2apic;
 
-    qemu_printf("ICR\t 0x%08x %s %s %s %s\n",
-                icr,
-                logical_mod ? "logical" : "physical",
-                icr & APIC_ICR_TRIGGER_MOD ? "level" : "edge",
-                icr & APIC_ICR_LEVEL ? "assert" : "de-assert",
-                shorthand2str(dest_shorthand));
+    g_string_append_printf(buf, "ICR\t 0x%08x %s %s %s %s\n",
+                           icr,
+                           logical_mod ? "logical" : "physical",
+                           icr & APIC_ICR_TRIGGER_MOD ? "level" : "edge",
+                           icr & APIC_ICR_LEVEL ? "assert" : "de-assert",
+                           shorthand2str(dest_shorthand));
 
-    qemu_printf("ICR2\t 0x%08x", icr2);
+    g_string_append_printf(buf, "ICR2\t 0x%08x", icr2);
     if (dest_shorthand != 0) {
-        qemu_printf("\n");
+        g_string_append_printf(buf, "\n");
         return;
     }
     x2apic = env->features[FEAT_1_ECX] & CPUID_EXT_X2APIC;
@@ -255,96 +258,100 @@ static void dump_apic_icr(APICCommonState *s, CPUX86State *env)
 
     if (!logical_mod) {
         if (x2apic) {
-            qemu_printf(" cpu %u (X2APIC ID)\n", dest_field);
+            g_string_append_printf(buf, " cpu %u (X2APIC ID)\n", dest_field);
         } else {
-            qemu_printf(" cpu %u (APIC ID)\n",
-                        dest_field & APIC_LOGDEST_XAPIC_ID);
+            g_string_append_printf(buf, " cpu %u (APIC ID)\n",
+                                   dest_field & APIC_LOGDEST_XAPIC_ID);
         }
         return;
     }
 
     if (s->dest_mode == 0xf) { /* flat mode */
         mask2str(apic_id_str, icr2 >> APIC_ICR_DEST_SHIFT, 8);
-        qemu_printf(" mask %s (APIC ID)\n", apic_id_str);
+        g_string_append_printf(buf, " mask %s (APIC ID)\n", apic_id_str);
     } else if (s->dest_mode == 0) { /* cluster mode */
         if (x2apic) {
             mask2str(apic_id_str, dest_field & APIC_LOGDEST_X2APIC_ID, 16);
-            qemu_printf(" cluster %u mask %s (X2APIC ID)\n",
-                        dest_field >> APIC_LOGDEST_X2APIC_SHIFT, apic_id_str);
+            g_string_append_printf(buf, " cluster %u mask %s (X2APIC ID)\n",
+                                   dest_field >> APIC_LOGDEST_X2APIC_SHIFT,
+                                   apic_id_str);
         } else {
             mask2str(apic_id_str, dest_field & APIC_LOGDEST_XAPIC_ID, 4);
-            qemu_printf(" cluster %u mask %s (APIC ID)\n",
-                        dest_field >> APIC_LOGDEST_XAPIC_SHIFT, apic_id_str);
+            g_string_append_printf(buf, " cluster %u mask %s (APIC ID)\n",
+                                   dest_field >> APIC_LOGDEST_XAPIC_SHIFT,
+                                   apic_id_str);
         }
     }
 }
 
-static void dump_apic_interrupt(const char *name, uint32_t *ireg_tab,
-                                uint32_t *tmr_tab)
+static void format_apic_interrupt(const char *name, uint32_t *ireg_tab,
+                                  uint32_t *tmr_tab, GString *buf)
 {
     int i, empty = true;
 
-    qemu_printf("%s\t ", name);
+    g_string_append_printf(buf, "%s\t ", name);
     for (i = 0; i < 256; i++) {
         if (apic_get_bit(ireg_tab, i)) {
-            qemu_printf("%u%s ", i,
-                        apic_get_bit(tmr_tab, i) ? "(level)" : "");
+            g_string_append_printf(buf, "%u%s ", i,
+                                   apic_get_bit(tmr_tab, i) ? "(level)" : "");
             empty = false;
         }
     }
-    qemu_printf("%s\n", empty ? "(none)" : "");
+    g_string_append_printf(buf, "%s\n", empty ? "(none)" : "");
 }
 
-void x86_cpu_dump_local_apic_state(CPUState *cs, int flags)
+GString *x86_cpu_format_local_apic_state(CPUState *cs, int flags, Error **errp)
 {
+    g_autoptr(GString) buf = g_string_new("");
     X86CPU *cpu = X86_CPU(cs);
     APICCommonState *s = APIC_COMMON(cpu->apic_state);
     if (!s) {
-        qemu_printf("local apic state not available\n");
-        return;
+        error_setg(errp, "local apic state not available");
+        return NULL;
     }
     uint32_t *lvt = s->lvt;
 
-    qemu_printf("dumping local APIC state for CPU %-2u\n\n",
-                CPU(cpu)->cpu_index);
-    dump_apic_lvt("LVT0", lvt[APIC_LVT_LINT0], false);
-    dump_apic_lvt("LVT1", lvt[APIC_LVT_LINT1], false);
-    dump_apic_lvt("LVTPC", lvt[APIC_LVT_PERFORM], false);
-    dump_apic_lvt("LVTERR", lvt[APIC_LVT_ERROR], false);
-    dump_apic_lvt("LVTTHMR", lvt[APIC_LVT_THERMAL], false);
-    dump_apic_lvt("LVTT", lvt[APIC_LVT_TIMER], true);
-
-    qemu_printf("Timer\t DCR=0x%x (divide by %u) initial_count = %u"
-                " current_count = %u\n",
-                s->divide_conf & APIC_DCR_MASK,
-                divider_conf(s->divide_conf),
-                s->initial_count, apic_get_current_count(s));
-
-    qemu_printf("SPIV\t 0x%08x APIC %s, focus=%s, spurious vec %u\n",
-                s->spurious_vec,
-                s->spurious_vec & APIC_SPURIO_ENABLED ? "enabled" : "disabled",
-                s->spurious_vec & APIC_SPURIO_FOCUS ? "on" : "off",
-                s->spurious_vec & APIC_VECTOR_MASK);
-
-    dump_apic_icr(s, &cpu->env);
-
-    qemu_printf("ESR\t 0x%08x\n", s->esr);
-
-    dump_apic_interrupt("ISR", s->isr, s->tmr);
-    dump_apic_interrupt("IRR", s->irr, s->tmr);
-
-    qemu_printf("\nAPR 0x%02x TPR 0x%02x DFR 0x%02x LDR 0x%02x",
-                s->arb_id, s->tpr, s->dest_mode, s->log_dest);
+    g_string_append_printf(buf, "dumping local APIC state for CPU %-2u\n\n",
+                           CPU(cpu)->cpu_index);
+    format_apic_lvt("LVT0", lvt[APIC_LVT_LINT0], false, buf);
+    format_apic_lvt("LVT1", lvt[APIC_LVT_LINT1], false, buf);
+    format_apic_lvt("LVTPC", lvt[APIC_LVT_PERFORM], false, buf);
+    format_apic_lvt("LVTERR", lvt[APIC_LVT_ERROR], false, buf);
+    format_apic_lvt("LVTTHMR", lvt[APIC_LVT_THERMAL], false, buf);
+    format_apic_lvt("LVTT", lvt[APIC_LVT_TIMER], true, buf);
+
+    g_string_append_printf(buf,
+                           "Timer\t DCR=0x%x (divide by %u) initial_count = %u"
+                           " current_count = %u\n",
+                           s->divide_conf & APIC_DCR_MASK,
+                           divider_conf(s->divide_conf),
+                           s->initial_count, apic_get_current_count(s));
+
+    g_string_append_printf(buf,
+                           "SPIV\t 0x%08x APIC %s, focus=%s, spurious vec %u\n",
+                           s->spurious_vec,
+                           s->spurious_vec & APIC_SPURIO_ENABLED ?
+                           "enabled" : "disabled",
+                           s->spurious_vec & APIC_SPURIO_FOCUS ? "on" : "off",
+                           s->spurious_vec & APIC_VECTOR_MASK);
+
+    format_apic_icr(s, &cpu->env, buf);
+
+    g_string_append_printf(buf, "ESR\t 0x%08x\n", s->esr);
+
+    format_apic_interrupt("ISR", s->isr, s->tmr, buf);
+    format_apic_interrupt("IRR", s->irr, s->tmr, buf);
+
+    g_string_append_printf(buf, "\nAPR 0x%02x TPR 0x%02x DFR 0x%02x LDR 0x%02x",
+                           s->arb_id, s->tpr, s->dest_mode, s->log_dest);
     if (s->dest_mode == 0) {
-        qemu_printf("(cluster %u: id %u)",
-                    s->log_dest >> APIC_LOGDEST_XAPIC_SHIFT,
-                    s->log_dest & APIC_LOGDEST_XAPIC_ID);
+        g_string_append_printf(buf, "(cluster %u: id %u)",
+                               s->log_dest >> APIC_LOGDEST_XAPIC_SHIFT,
+                               s->log_dest & APIC_LOGDEST_XAPIC_ID);
     }
-    qemu_printf(" PPR 0x%02x\n", apic_get_ppr(s));
-}
-#else
-void x86_cpu_dump_local_apic_state(CPUState *cs, int flags)
-{
+    g_string_append_printf(buf, " PPR 0x%02x\n", apic_get_ppr(s));
+
+    return g_steal_pointer(&buf);
 }
 #endif /* !CONFIG_USER_ONLY */
 
target/i386/cpu.h +3 -1
index d87c8808f6..2bcb175da8 100644
@@ -2201,8 +2201,10 @@ void x86_cpu_set_default_version(X86CPUVersion version);
 #define APIC_DEFAULT_ADDRESS 0xfee00000
 #define APIC_SPACE_SIZE      0x100000
 
+#ifndef CONFIG_USER_ONLY
 /* cpu-dump.c */
-void x86_cpu_dump_local_apic_state(CPUState *cs, int flags);
+GString *x86_cpu_format_local_apic_state(CPUState *cs, int flags, Error **errp);
+#endif /* !CONFIG_USER_ONLY */
 
 /* cpu.c */
 bool cpu_is_bsp(X86CPU *cpu);
target/i386/monitor.c +2 -0
index 19468c4e85..fc09f90059 100644
@@ -33,6 +33,7 @@
 #include "qapi/error.h"
 #include "sev_i386.h"
 #include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qapi-commands-machine-target.h"
 #include "qapi/qapi-commands-misc.h"
 #include "hw/i386/pc.h"
 
@@ -650,23 +651,52 @@ const MonitorDef *target_monitor_defs(void)
     return monitor_defs;
 }
 
+TargetHumanReadableText *qmp_x_query_lapic(int64_t apicid,

target/i386/monitor.c const MonitorDef *target_monitor_defs(void) · line 664

Quoted 10 lines
target/i386/monitor.c +10 -0
+                                           Error **errp)
+{
+    TargetHumanReadableText *ret;
+    g_autoptr(GString) buf = NULL;
+    CPUState *cs = cpu_by_arch_id(apicid);
+
+    if (!cs) {
+        error_setg(errp, "No CPU with APIC ID %" PRId64 " available", apicid);
+        return NULL;
+    }

Suppose the accelerator is KVM, the CPUState (cs) might not be syncrhonized with KVM kernel space (APIC+PIR). As a result, the data is stale.

I sent below patch long time ago but it never got reviewed.

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 12 lines
target/i386/monitor.c +11 -0
+
+    buf = x86_cpu_format_local_apic_state(cs, CPU_DUMP_FPU, errp);
+    if (!buf) {
+        return NULL;
+    }
+
+    ret = g_new0(TargetHumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
 void hmp_info_local_apic(Monitor *mon, const QDict *qdict)

target/i386/monitor.c const MonitorDef *target_monitor_defs(void) · line 683

Quoted 10 lines
target/i386/monitor.c +4 -3
 {
-    CPUState *cs;
+    Error *err = NULL;
+    g_autoptr(TargetHumanReadableText) info = NULL;
+    int64_t apicid;
 
     if (qdict_haskey(qdict, "apic-id")) {
-        int id = qdict_get_try_int(qdict, "apic-id", 0);
-        cs = cpu_by_arch_id(id);
+        apicid = qdict_get_try_int(qdict, "apic-id", 0);

Here is where I used to fix with the patch.

Thank you very much!

Dongli Zhang

Quoted 25 lines
target/i386/monitor.c +11 -5
     } else {
-        cs = mon_get_cpu(mon);
+        CPUState *cs = mon_get_cpu(mon);
+        if (!cs) {
+            monitor_printf(mon, "No CPU available\n");
+            return;
+        }
+        apicid = cpu_get_arch_id(cs);
     }
 
-
-    if (!cs) {
-        monitor_printf(mon, "No CPU available\n");
+    info = qmp_x_query_lapic(apicid, &err);
+    if (err) {
+        error_report_err(err);
         return;
     }
-    x86_cpu_dump_local_apic_state(cs, CPU_DUMP_FPU);
+
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
 SevInfo *qmp_query_sev(Error **errp)
#3 lore raw

Re: [PATCH v2 01/53] docs/devel: rename file for writing monitor commands

In reply to Markus Armbruster
Quoted 35 lines · Markus Armbruster
Quoted 33 lines · Daniel P. Berrangé

The file already covers writing new style HMP commands, in addition to the QMP commands, so it deserves a more general name.

---
 docs/devel/index.rst                                        | 2 +-
 ...riting-qmp-commands.rst => writing-monitor-commands.rst} | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
 rename docs/devel/{writing-qmp-commands.rst => writing-monitor-commands.rst} (99%)
docs/devel/index.rst +1 -1
index f95df10b3e..7c25177c5d 100644
@@ -44,4 +44,4 @@ modifying QEMU's source code.
    ebpf_rss
    vfio-migration
    qapi-code-gen
-   writing-qmp-commands
+   writing-monitor-commands
docs/devel/writing-monitor-commands.rst renamed from docs/devel/writing-qmp-commands.rst +2 -2
similarity index 99%
rename from docs/devel/writing-qmp-commands.rst
rename to docs/devel/writing-monitor-commands.rst
index 6a10a06c48..497c9ce0d5 100644
@@ -1,8 +1,8 @@
-How to write QMP commands using the QAPI framework
-==================================================
+How to write monitor commands
+=============================
 
Quoted 5 lines

docs/devel/writing-monitor-commands.rst line 5

Quoted 3 lines
docs/devel/writing-monitor-commands.rst renamed from docs/devel/writing-qmp-commands.rst +1 -1
 This document is a step-by-step guide on how to write new QMP commands using
-the QAPI framework. It also shows how to implement new style HMP commands.
+the QAPI framework and new style HMP commands.

Recommend to drop "new style", here and in the commit message.

Ok, will do.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#12 lore raw

Re: [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future

In reply to Markus Armbruster
Quoted 49 lines · Markus Armbruster
Quoted 18 lines · Daniel P. Berrangé

We no longer wish to have commands implemented in HMP only. All commands should start with a QMP implementation and the HMP merely be a shim around this. To reduce the burden of implementing QMP commands where there is low expectation of machine usage, requirements for QAPI modelling are relaxed provided the command is under the "x-" name prefix.

---
 docs/devel/writing-monitor-commands.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
docs/devel/writing-monitor-commands.rst +0 -0
index 4cf51ab557..983130a793 100644
@@ -11,6 +11,16 @@ For an in-depth introduction to the QAPI framework, please refer to
 docs/devel/qapi-code-gen.txt. For documentation about the QMP protocol,

docs/devel/writing-monitor-commands.rst For an in-depth introduction to the QAPI framework, please refer to · line 21

Quoted 10 lines
docs/devel/writing-monitor-commands.rst +8 -0
 start with docs/interop/qmp-intro.txt.
 
+Historically QEMU has permitted new monitor commands to be implemented in HMP
+only, QMP only, or both, depending on whether they needed to be accessible to
+human operators, machines, or both. When both QMP and HMP are implemented it
+is expected the HMP implementation is a shim around the QMP implementation.
+Going forward, the expectation is that new commands are implemented in QMP
+only, or both QMP and HMP. No further commands are to be added to HMP only.
+The long term goal is that all HMP commands will be implemented in terms of
+their QMP equivalent, enabling internals of QEMU to be fully isolated from

This feels a bit too tight. Most HMP commands are going to wrap around their equivalent QMP command. However, high-level HMP commands built from low-level QMP building blocks remain permissble.

docs/devel/writing-monitor-commands.rst For an in-depth introduction to the QAPI framework, please refer to · line 22

Quoted 1 line
docs/devel/writing-monitor-commands.rst +1 -0
+the HMP implementation. Refer to the later topic on modelling data in QAPI

Suggest to use the exact section name for easy searching, or even better, make it a link.

docs/devel/writing-monitor-commands.rst For an in-depth introduction to the QAPI framework, please refer to · line 26

Quoted 4 lines
docs/devel/writing-monitor-commands.rst +1 -0
+for further guidance on commands that would have traditionally been HMP only.
 
 Overview
 --------

Discussing history is quite valuable in commit messages, but less so in a "how to do stuff" document. Consider cutting this down some. What about:

Quoted 6 lines

New commands may be implemented in QMP only. New HMP commands should be implemented on top of QMP. The typical HMP command wraps around an equivalent QMP command, but HMP convenience commands built from QMP building blocks are also fine. The long term goal is to make all existing HMP commands conform to this, to fully isolate HMP from the internals of QEMU.

That's good with me. I'll just add the final sentance linking to the later illustration for debugging aids.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#83 lore raw

Re: [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command

In reply to Dongli Zhang
Quoted 69 lines · Dongli Zhang

Hi Daniel,

Quoted 52 lines · Daniel P. Berrangé

This is a counterpart to the HMP "info lapic" 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. The existing HMP command is rewritten to call the QMP command.

This command is unable to use the pre-existing HumanReadableText, because if 'common.json' is included into 'machine-target.json' the static marshalling method for HumanReadableText will be reported as unused by the compiler on all architectures except s390x.

Possible options were

1 Support 'if' conditionals on 'include' statements in QAPI 2 Add further commands to 'machine-target.json' that use
HumanReadableText, such that it has at least one usage on all architecture targets.
3 Duplicate HumanReadableText as TargetHumanReadableText
adding conditions

This patch takes option (3) in the belief that we will eventually get to a point where option (2) happens, and TargetHumanReadableText can be removed again.

---
 hw/core/cpu-common.c     |   7 ++
 include/hw/core/cpu.h    |  10 +++
 qapi/machine-target.json |  19 ++++-
 target/i386/cpu-dump.c   | 161 ++++++++++++++++++++-------------------
 target/i386/cpu.h        |   4 +-
 target/i386/monitor.c    |  46 +++++++++--
 6 files changed, 160 insertions(+), 87 deletions(-)
target/i386/monitor.c +2 -0
index 19468c4e85..fc09f90059 100644
@@ -33,6 +33,7 @@
 #include "qapi/error.h"
 #include "sev_i386.h"
 #include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qapi-commands-machine-target.h"
 #include "qapi/qapi-commands-misc.h"
 #include "hw/i386/pc.h"
 
@@ -650,23 +651,52 @@ const MonitorDef *target_monitor_defs(void)
     return monitor_defs;
 }
 
+TargetHumanReadableText *qmp_x_query_lapic(int64_t apicid,

target/i386/monitor.c const MonitorDef *target_monitor_defs(void) · line 664

Quoted 10 lines
target/i386/monitor.c +10 -0
+                                           Error **errp)
+{
+    TargetHumanReadableText *ret;
+    g_autoptr(GString) buf = NULL;
+    CPUState *cs = cpu_by_arch_id(apicid);
+
+    if (!cs) {
+        error_setg(errp, "No CPU with APIC ID %" PRId64 " available", apicid);
+        return NULL;
+    }

Suppose the accelerator is KVM, the CPUState (cs) might not be syncrhonized with KVM kernel space (APIC+PIR). As a result, the data is stale.

Quoted 3 lines

I sent below patch long time ago but it never got reviewed.

https://lore.kernel.org/qemu-devel/[email protected]/

I'll include your patch in the next version of this series just before this patch, and then update this patch to take it into account.

Quoted 53 lines
Quoted 13 lines
target/i386/monitor.c +11 -0
+
+    buf = x86_cpu_format_local_apic_state(cs, CPU_DUMP_FPU, errp);
+    if (!buf) {
+        return NULL;
+    }
+
+    ret = g_new0(TargetHumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
+
 void hmp_info_local_apic(Monitor *mon, const QDict *qdict)

target/i386/monitor.c const MonitorDef *target_monitor_defs(void) · line 683

Quoted 10 lines
target/i386/monitor.c +4 -3
 {
-    CPUState *cs;
+    Error *err = NULL;
+    g_autoptr(TargetHumanReadableText) info = NULL;
+    int64_t apicid;
 
     if (qdict_haskey(qdict, "apic-id")) {
-        int id = qdict_get_try_int(qdict, "apic-id", 0);
-        cs = cpu_by_arch_id(id);
+        apicid = qdict_get_try_int(qdict, "apic-id", 0);

Here is where I used to fix with the patch.

Thank you very much!

Dongli Zhang

Quoted 23 lines
target/i386/monitor.c +11 -5
     } else {
-        cs = mon_get_cpu(mon);
+        CPUState *cs = mon_get_cpu(mon);
+        if (!cs) {
+            monitor_printf(mon, "No CPU available\n");
+            return;
+        }
+        apicid = cpu_get_arch_id(cs);
     }
 
-
-    if (!cs) {
-        monitor_printf(mon, "No CPU available\n");
+    info = qmp_x_query_lapic(apicid, &err);
+    if (err) {
+        error_report_err(err);
         return;
     }
-    x86_cpu_dump_local_apic_state(cs, CPU_DUMP_FPU);
+
+    monitor_printf(mon, "%s", info->human_readable_text);
 }
 
Quoted 3 lines

target/i386/monitor.c const MonitorDef *target_monitor_defs(void) · line 702

Quoted 2 lines
target/i386/monitor.c +0 -0
 SevInfo *qmp_query_sev(Error **errp)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|