All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/53] monitor: explicitly permit QMP commands to be added for all use cases
@ 2021-09-14 14:19 ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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%)

-- 
2.31.1




^ permalink raw reply	[flat|nested] 216+ messages in thread

* [PATCH v2 00/53] monitor: explicitly permit QMP commands to be added for all use cases
@ 2021-09-14 14:19 ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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%)

-- 
2.31.1




^ permalink raw reply	[flat|nested] 216+ messages in thread

* [PATCH v2 01/53] docs/devel: rename file for writing monitor commands
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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%)

diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index f95df10b3e..7c25177c5d 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -44,4 +44,4 @@ modifying QEMU's source code.
    ebpf_rss
    vfio-migration
    qapi-code-gen
-   writing-qmp-commands
+   writing-monitor-commands
diff --git a/docs/devel/writing-qmp-commands.rst b/docs/devel/writing-monitor-commands.rst
similarity index 99%
rename from docs/devel/writing-qmp-commands.rst
rename to docs/devel/writing-monitor-commands.rst
index 6a10a06c48..497c9ce0d5 100644
--- a/docs/devel/writing-qmp-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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.
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 01/53] docs/devel: rename file for writing monitor commands
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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%)

diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index f95df10b3e..7c25177c5d 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -44,4 +44,4 @@ modifying QEMU's source code.
    ebpf_rss
    vfio-migration
    qapi-code-gen
-   writing-qmp-commands
+   writing-monitor-commands
diff --git a/docs/devel/writing-qmp-commands.rst b/docs/devel/writing-monitor-commands.rst
similarity index 99%
rename from docs/devel/writing-qmp-commands.rst
rename to docs/devel/writing-monitor-commands.rst
index 6a10a06c48..497c9ce0d5 100644
--- a/docs/devel/writing-qmp-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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.
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 02/53] docs/devel: tweak headings in monitor command docs
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/devel/writing-monitor-commands.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index 497c9ce0d5..cddb36fb74 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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.
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 02/53] docs/devel: tweak headings in monitor command docs
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/devel/writing-monitor-commands.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index 497c9ce0d5..cddb36fb74 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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.
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 03/53] docs/devel: document expectations for QAPI data modelling for QMP
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Traditionally we have required that newly added QMP commands will model
any returned data using fine grained QAPI types. This is good for
commands that are intended to be consumed by machines, where clear data
representation is very important. Commands that don't satisfy this have
generally been added to HMP only.

In effect the decision of whether to add a new command to QMP vs HMP has
been used as a proxy for the decision of whether the cost of designing a
fine grained QAPI type is justified by the potential benefits.

As a result the commands present in QMP and HMP are non-overlapping
sets, although HMP comamnds can be accessed indirectly via the QMP
command 'human-monitor-command'.

One of the downsides of 'human-monitor-command' is that the QEMU monitor
APIs remain tied into various internal parts of the QEMU code. For
example any exclusively HMP command will need to use 'monitor_printf'
to get data out. It would be desirable to be able to fully isolate the
monitor implementation from QEMU internals, however, this is only
possible if all commands are exclusively based on QAPI with direct
QMP exposure.

The way to achieve this desired end goal is to finese the requirements
for QMP command design. For cases where the output of a command is only
intended for human consumption, it is reasonable to want to simplify
the implementation by returning a plain string containing formatted
data instead of designing a fine grained QAPI data type. This can be
permitted if-and-only-if the command is exposed under the 'x-' name
prefix. This indicates that the command data format is liable to
future change and that it is not following QAPI design best practice.

The poster child example for this would be the 'info registers' HMP
command which returns printf formatted data representing CPU state.
This information varies enourmously across target architectures and
changes relatively frequently as new CPU features are implemented.
It is there as debugging data for human operators, and any machine
usage would treat it as an opaque blob. It is thus reasonable to
expose this in QMP as 'x-query-registers' returning a 'str' field.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/devel/writing-monitor-commands.rst | 27 +++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index cddb36fb74..d68c552fdd 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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
 ~~~~~~~~~~~~~~~~~~
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 03/53] docs/devel: document expectations for QAPI data modelling for QMP
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/devel/writing-monitor-commands.rst | 27 +++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index cddb36fb74..d68c552fdd 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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
 ~~~~~~~~~~~~~~~~~~
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 04/53] docs/devel: add example of command returning unstructured text
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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'.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/devel/writing-monitor-commands.rst | 85 +++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index d68c552fdd..4cf51ab557 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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,
+    },
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 04/53] docs/devel: add example of command returning unstructured text
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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'.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/devel/writing-monitor-commands.rst | 85 +++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index d68c552fdd..4cf51ab557 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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,
+    },
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/devel/writing-monitor-commands.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index 4cf51ab557..983130a793 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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
 --------
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/devel/writing-monitor-commands.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index 4cf51ab557..983130a793 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -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
 --------
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state'
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

The 'dump_state' callback assumes it will be outputting to a FILE
object. This is fine for HMP, but not so useful for QMP. Introduce
a new 'format_state' callback that returns a formatted GString
instead.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/cpu-common.c  | 15 +++++++++++++++
 include/hw/core/cpu.h | 13 ++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index e2f5a64604..c2cd33a817 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -106,6 +106,21 @@ void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
     if (cc->dump_state) {
         cpu_synchronize_state(cpu);
         cc->dump_state(cpu, f, flags);
+    } else if (cc->format_state) {
+        g_autoptr(GString) buf = 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);
     }
 }
 
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index bc864564ce..1599ef9df3 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -91,7 +91,8 @@ struct SysemuCPUOps;
  * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
  * @has_work: Callback for checking if there is work to do.
  * @memory_rw_debug: Callback for GDB memory access.
- * @dump_state: Callback for dumping state.
+ * @dump_state: Callback for dumping state. Deprecated, use @format_state.
+ * @format_state: Callback for formatting state.
  * @get_arch_id: Callback for getting architecture-dependent CPU ID.
  * @set_pc: Callback for setting the Program Counter register. This
  *       should have the semantics used by the target architecture when
@@ -136,6 +137,7 @@ struct CPUClass {
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                            uint8_t *buf, int len, bool is_write);
     void (*dump_state)(CPUState *cpu, FILE *, int flags);
+    void (*format_state)(CPUState *cpu, GString *buf, int flags);
     int64_t (*get_arch_id)(CPUState *cpu);
     void (*set_pc)(CPUState *cpu, vaddr value);
     int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
@@ -537,6 +539,15 @@ enum CPUDumpFlags {
  */
 void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
 
+/**
+ * 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:
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state'
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/cpu-common.c  | 15 +++++++++++++++
 include/hw/core/cpu.h | 13 ++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index e2f5a64604..c2cd33a817 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -106,6 +106,21 @@ void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
     if (cc->dump_state) {
         cpu_synchronize_state(cpu);
         cc->dump_state(cpu, f, flags);
+    } else if (cc->format_state) {
+        g_autoptr(GString) buf = 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);
     }
 }
 
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index bc864564ce..1599ef9df3 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -91,7 +91,8 @@ struct SysemuCPUOps;
  * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
  * @has_work: Callback for checking if there is work to do.
  * @memory_rw_debug: Callback for GDB memory access.
- * @dump_state: Callback for dumping state.
+ * @dump_state: Callback for dumping state. Deprecated, use @format_state.
+ * @format_state: Callback for formatting state.
  * @get_arch_id: Callback for getting architecture-dependent CPU ID.
  * @set_pc: Callback for setting the Program Counter register. This
  *       should have the semantics used by the target architecture when
@@ -136,6 +137,7 @@ struct CPUClass {
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                            uint8_t *buf, int len, bool is_write);
     void (*dump_state)(CPUState *cpu, FILE *, int flags);
+    void (*format_state)(CPUState *cpu, GString *buf, int flags);
     int64_t (*get_arch_id)(CPUState *cpu);
     void (*set_pc)(CPUState *cpu, vaddr value);
     int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
@@ -537,6 +539,15 @@ enum CPUDumpFlags {
  */
 void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
 
+/**
+ * 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:
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 07/53] target/alpha: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/alpha/cpu.c    |  2 +-
 target/alpha/cpu.h    |  2 +-
 target/alpha/helper.c | 28 ++++++++++++++++------------
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index 4871ad0c0a..d0cdda9554 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -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;
diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h
index 82df108967..9e3c80ebcc 100644
--- a/target/alpha/cpu.h
+++ b/target/alpha/cpu.h
@@ -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);
diff --git a/target/alpha/helper.c b/target/alpha/helper.c
index 4f56fe4d23..6ed80e8a27 100644
--- a/target/alpha/helper.c
+++ b/target/alpha/helper.c
@@ -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.
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 07/53] target/alpha: convert to use format_state instead of dump_state
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/alpha/cpu.c    |  2 +-
 target/alpha/cpu.h    |  2 +-
 target/alpha/helper.c | 28 ++++++++++++++++------------
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index 4871ad0c0a..d0cdda9554 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -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;
diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h
index 82df108967..9e3c80ebcc 100644
--- a/target/alpha/cpu.h
+++ b/target/alpha/cpu.h
@@ -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);
diff --git a/target/alpha/helper.c b/target/alpha/helper.c
index 4f56fe4d23..6ed80e8a27 100644
--- a/target/alpha/helper.c
+++ b/target/alpha/helper.c
@@ -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.
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 08/53] target/arm: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/arm/cpu.c | 152 +++++++++++++++++++++++++----------------------
 1 file changed, 81 insertions(+), 71 deletions(-)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index d631c4683c..5999277e67 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 08/53] target/arm: convert to use format_state instead of dump_state
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/arm/cpu.c | 152 +++++++++++++++++++++++++----------------------
 1 file changed, 81 insertions(+), 71 deletions(-)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index d631c4683c..5999277e67 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 28 deletions(-)

diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index ea14175ca5..17ff21f8be 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 28 deletions(-)

diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index ea14175ca5..17ff21f8be 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 10/53] target/cris: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/cris/cpu.c       |  2 +-
 target/cris/cpu.h       |  2 +-
 target/cris/translate.c | 33 +++++++++++++++++----------------
 3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/target/cris/cpu.c b/target/cris/cpu.c
index 70932b1f8c..5159cf6528 100644
--- a/target/cris/cpu.c
+++ b/target/cris/cpu.c
@@ -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;
diff --git a/target/cris/cpu.h b/target/cris/cpu.h
index d3b6492909..908cb051da 100644
--- a/target/cris/cpu.h
+++ b/target/cris/cpu.h
@@ -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);
 
diff --git a/target/cris/translate.c b/target/cris/translate.c
index a84b753349..6098693186 100644
--- a/target/cris/translate.c
+++ b/target/cris/translate.c
@@ -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");
 
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 10/53] target/cris: convert to use format_state instead of dump_state
@ 2021-09-14 14:19   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/cris/cpu.c       |  2 +-
 target/cris/cpu.h       |  2 +-
 target/cris/translate.c | 33 +++++++++++++++++----------------
 3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/target/cris/cpu.c b/target/cris/cpu.c
index 70932b1f8c..5159cf6528 100644
--- a/target/cris/cpu.c
+++ b/target/cris/cpu.c
@@ -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;
diff --git a/target/cris/cpu.h b/target/cris/cpu.h
index d3b6492909..908cb051da 100644
--- a/target/cris/cpu.h
+++ b/target/cris/cpu.h
@@ -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);
 
diff --git a/target/cris/translate.c b/target/cris/translate.c
index a84b753349..6098693186 100644
--- a/target/cris/translate.c
+++ b/target/cris/translate.c
@@ -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");
 
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/hexagon/cpu.c      | 5 -----
 target/hexagon/internal.h | 1 -
 2 files changed, 6 deletions(-)

diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 3338365c16..14c628db7a 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -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);
diff --git a/target/hexagon/internal.h b/target/hexagon/internal.h
index 6b20affdfa..167e91026a 100644
--- a/target/hexagon/internal.h
+++ b/target/hexagon/internal.h
@@ -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];
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/hexagon/cpu.c      | 5 -----
 target/hexagon/internal.h | 1 -
 2 files changed, 6 deletions(-)

diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 3338365c16..14c628db7a 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -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);
diff --git a/target/hexagon/internal.h b/target/hexagon/internal.h
index 6b20affdfa..167e91026a 100644
--- a/target/hexagon/internal.h
+++ b/target/hexagon/internal.h
@@ -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];
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 12/53] target/hexagon: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/hexagon/cpu.c | 65 ++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 36 deletions(-)

diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 14c628db7a..7802186ad7 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 12/53] target/hexagon: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/hexagon/cpu.c | 65 ++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 36 deletions(-)

diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 14c628db7a..7802186ad7 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 13/53] target/hppa: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/hppa/cpu.c    |  2 +-
 target/hppa/cpu.h    |  2 +-
 target/hppa/helper.c | 25 ++++++++++++++-----------
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
index 2eace4ee12..f7fe7c49d6 100644
--- a/target/hppa/cpu.c
+++ b/target/hppa/cpu.c
@@ -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;
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 748270bfa3..d4f1922545 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -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);
diff --git a/target/hppa/helper.c b/target/hppa/helper.c
index 1ccff5765a..6e30d1ea63 100644
--- a/target/hppa/helper.c
+++ b/target/hppa/helper.c
@@ -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 */
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 13/53] target/hppa: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/hppa/cpu.c    |  2 +-
 target/hppa/cpu.h    |  2 +-
 target/hppa/helper.c | 25 ++++++++++++++-----------
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
index 2eace4ee12..f7fe7c49d6 100644
--- a/target/hppa/cpu.c
+++ b/target/hppa/cpu.c
@@ -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;
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 748270bfa3..d4f1922545 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -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);
diff --git a/target/hppa/helper.c b/target/hppa/helper.c
index 1ccff5765a..6e30d1ea63 100644
--- a/target/hppa/helper.c
+++ b/target/hppa/helper.c
@@ -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 */
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 14/53] target/i386: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/i386/cpu-dump.c | 328 ++++++++++++++++++++++-------------------
 target/i386/cpu.c      |   2 +-
 target/i386/cpu.h      |   2 +-
 3 files changed, 177 insertions(+), 155 deletions(-)

diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c
index 02b635a52c..f30fbcb76e 100644
--- a/target/i386/cpu-dump.c
+++ b/target/i386/cpu-dump.c
@@ -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");
     }
 }
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6b029f1bdf..0a5c6a6d19 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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;
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 71ae3141c3..d87c8808f6 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 14/53] target/i386: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/i386/cpu-dump.c | 328 ++++++++++++++++++++++-------------------
 target/i386/cpu.c      |   2 +-
 target/i386/cpu.h      |   2 +-
 3 files changed, 177 insertions(+), 155 deletions(-)

diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c
index 02b635a52c..f30fbcb76e 100644
--- a/target/i386/cpu-dump.c
+++ b/target/i386/cpu-dump.c
@@ -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");
     }
 }
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6b029f1bdf..0a5c6a6d19 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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;
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 71ae3141c3..d87c8808f6 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 15/53] target/m68k: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/m68k/cpu.c       |  2 +-
 target/m68k/cpu.h       |  2 +-
 target/m68k/translate.c | 92 ++++++++++++++++++++++-------------------
 3 files changed, 51 insertions(+), 45 deletions(-)

diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 72de6e9726..4ccf572a68 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -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;
diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index 997d588911..b0641f6d0d 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -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);
diff --git a/target/m68k/translate.c b/target/m68k/translate.c
index c34d9aed61..951bbed6bf 100644
--- a/target/m68k/translate.c
+++ b/target/m68k/translate.c
@@ -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",
+                           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
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 15/53] target/m68k: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/m68k/cpu.c       |  2 +-
 target/m68k/cpu.h       |  2 +-
 target/m68k/translate.c | 92 ++++++++++++++++++++++-------------------
 3 files changed, 51 insertions(+), 45 deletions(-)

diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 72de6e9726..4ccf572a68 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -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;
diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index 997d588911..b0641f6d0d 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -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);
diff --git a/target/m68k/translate.c b/target/m68k/translate.c
index c34d9aed61..951bbed6bf 100644
--- a/target/m68k/translate.c
+++ b/target/m68k/translate.c
@@ -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",
+                           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
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/microblaze/cpu.c       |  2 +-
 target/microblaze/cpu.h       |  2 +-
 target/microblaze/translate.c | 45 ++++++++++++++++++-----------------
 3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 72d8f2a0da..539b8964bd 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -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;
diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h
index e4bba8a755..3e90970068 100644
--- a/target/microblaze/cpu.h
+++ b/target/microblaze/cpu.h
@@ -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);
diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index a14ffed784..c229ba8789 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -1848,54 +1848,55 @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns)
     translator_loop(&mb_tr_ops, &dc.base, cpu, tb, max_insns);
 }
 
-void mb_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void mb_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
     CPUMBState *env = &cpu->env;
     uint32_t iflags;
     int i;
 
-    qemu_fprintf(f, "pc=0x%08x msr=0x%05x mode=%s(saved=%s) eip=%d ie=%d\n",
-                 env->pc, env->msr,
-                 (env->msr & MSR_UM) ? "user" : "kernel",
-                 (env->msr & MSR_UMS) ? "user" : "kernel",
-                 (bool)(env->msr & MSR_EIP),
-                 (bool)(env->msr & MSR_IE));
+    g_string_append_printf(buf, "pc=0x%08x msr=0x%05x mode=%s(saved=%s) "
+                           "eip=%d ie=%d\n",
+                           env->pc, env->msr,
+                           (env->msr & MSR_UM) ? "user" : "kernel",
+                           (env->msr & MSR_UMS) ? "user" : "kernel",
+                           (bool)(env->msr & MSR_EIP),
+                           (bool)(env->msr & MSR_IE));
 
     iflags = env->iflags;
-    qemu_fprintf(f, "iflags: 0x%08x", iflags);
+    g_string_append_printf(buf, "iflags: 0x%08x", iflags);
     if (iflags & IMM_FLAG) {
-        qemu_fprintf(f, " IMM(0x%08x)", env->imm);
+        g_string_append_printf(buf, " IMM(0x%08x)", env->imm);
     }
     if (iflags & BIMM_FLAG) {
-        qemu_fprintf(f, " BIMM");
+        g_string_append_printf(buf, " BIMM");
     }
     if (iflags & D_FLAG) {
-        qemu_fprintf(f, " D(btarget=0x%08x)", env->btarget);
+        g_string_append_printf(buf, " D(btarget=0x%08x)", env->btarget);
     }
     if (iflags & DRTI_FLAG) {
-        qemu_fprintf(f, " DRTI");
+        g_string_append_printf(buf, " DRTI");
     }
     if (iflags & DRTE_FLAG) {
-        qemu_fprintf(f, " DRTE");
+        g_string_append_printf(buf, " DRTE");
     }
     if (iflags & DRTB_FLAG) {
-        qemu_fprintf(f, " DRTB");
+        g_string_append_printf(buf, " DRTB");
     }
     if (iflags & ESR_ESS_FLAG) {
-        qemu_fprintf(f, " ESR_ESS(0x%04x)", iflags & ESR_ESS_MASK);
+        g_string_append_printf(buf, " ESR_ESS(0x%04x)", iflags & ESR_ESS_MASK);
     }
 
-    qemu_fprintf(f, "\nesr=0x%04x fsr=0x%02x btr=0x%08x edr=0x%x\n"
-                 "ear=0x" TARGET_FMT_lx " slr=0x%x shr=0x%x\n",
-                 env->esr, env->fsr, env->btr, env->edr,
-                 env->ear, env->slr, env->shr);
+    g_string_append_printf(buf, "\nesr=0x%04x fsr=0x%02x btr=0x%08x edr=0x%x\n"
+                           "ear=0x" TARGET_FMT_lx " slr=0x%x shr=0x%x\n",
+                           env->esr, env->fsr, env->btr, env->edr,
+                           env->ear, env->slr, env->shr);
 
     for (i = 0; i < 32; i++) {
-        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");
 }
 
 void mb_tcg_init(void)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/microblaze/cpu.c       |  2 +-
 target/microblaze/cpu.h       |  2 +-
 target/microblaze/translate.c | 45 ++++++++++++++++++-----------------
 3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 72d8f2a0da..539b8964bd 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -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;
diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h
index e4bba8a755..3e90970068 100644
--- a/target/microblaze/cpu.h
+++ b/target/microblaze/cpu.h
@@ -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);
diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index a14ffed784..c229ba8789 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -1848,54 +1848,55 @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns)
     translator_loop(&mb_tr_ops, &dc.base, cpu, tb, max_insns);
 }
 
-void mb_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+void mb_cpu_format_state(CPUState *cs, GString *buf, int flags)
 {
     MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
     CPUMBState *env = &cpu->env;
     uint32_t iflags;
     int i;
 
-    qemu_fprintf(f, "pc=0x%08x msr=0x%05x mode=%s(saved=%s) eip=%d ie=%d\n",
-                 env->pc, env->msr,
-                 (env->msr & MSR_UM) ? "user" : "kernel",
-                 (env->msr & MSR_UMS) ? "user" : "kernel",
-                 (bool)(env->msr & MSR_EIP),
-                 (bool)(env->msr & MSR_IE));
+    g_string_append_printf(buf, "pc=0x%08x msr=0x%05x mode=%s(saved=%s) "
+                           "eip=%d ie=%d\n",
+                           env->pc, env->msr,
+                           (env->msr & MSR_UM) ? "user" : "kernel",
+                           (env->msr & MSR_UMS) ? "user" : "kernel",
+                           (bool)(env->msr & MSR_EIP),
+                           (bool)(env->msr & MSR_IE));
 
     iflags = env->iflags;
-    qemu_fprintf(f, "iflags: 0x%08x", iflags);
+    g_string_append_printf(buf, "iflags: 0x%08x", iflags);
     if (iflags & IMM_FLAG) {
-        qemu_fprintf(f, " IMM(0x%08x)", env->imm);
+        g_string_append_printf(buf, " IMM(0x%08x)", env->imm);
     }
     if (iflags & BIMM_FLAG) {
-        qemu_fprintf(f, " BIMM");
+        g_string_append_printf(buf, " BIMM");
     }
     if (iflags & D_FLAG) {
-        qemu_fprintf(f, " D(btarget=0x%08x)", env->btarget);
+        g_string_append_printf(buf, " D(btarget=0x%08x)", env->btarget);
     }
     if (iflags & DRTI_FLAG) {
-        qemu_fprintf(f, " DRTI");
+        g_string_append_printf(buf, " DRTI");
     }
     if (iflags & DRTE_FLAG) {
-        qemu_fprintf(f, " DRTE");
+        g_string_append_printf(buf, " DRTE");
     }
     if (iflags & DRTB_FLAG) {
-        qemu_fprintf(f, " DRTB");
+        g_string_append_printf(buf, " DRTB");
     }
     if (iflags & ESR_ESS_FLAG) {
-        qemu_fprintf(f, " ESR_ESS(0x%04x)", iflags & ESR_ESS_MASK);
+        g_string_append_printf(buf, " ESR_ESS(0x%04x)", iflags & ESR_ESS_MASK);
     }
 
-    qemu_fprintf(f, "\nesr=0x%04x fsr=0x%02x btr=0x%08x edr=0x%x\n"
-                 "ear=0x" TARGET_FMT_lx " slr=0x%x shr=0x%x\n",
-                 env->esr, env->fsr, env->btr, env->edr,
-                 env->ear, env->slr, env->shr);
+    g_string_append_printf(buf, "\nesr=0x%04x fsr=0x%02x btr=0x%08x edr=0x%x\n"
+                           "ear=0x" TARGET_FMT_lx " slr=0x%x shr=0x%x\n",
+                           env->esr, env->fsr, env->btr, env->edr,
+                           env->ear, env->slr, env->shr);
 
     for (i = 0; i < 32; i++) {
-        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");
 }
 
 void mb_tcg_init(void)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 17/53] target/mips: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/mips/cpu.c | 85 +++++++++++++++++++++++++----------------------
 1 file changed, 45 insertions(+), 40 deletions(-)

diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index d426918291..9ced90d810 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 17/53] target/mips: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/mips/cpu.c | 85 +++++++++++++++++++++++++----------------------
 1 file changed, 45 insertions(+), 40 deletions(-)

diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index d426918291..9ced90d810 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 18/53] target/nios2: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/nios2/cpu.c       |  2 +-
 target/nios2/cpu.h       |  2 +-
 target/nios2/translate.c | 20 ++++++++++----------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
index 5e37defef8..cbf15fb1c9 100644
--- a/target/nios2/cpu.c
+++ b/target/nios2/cpu.c
@@ -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
diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
index 2ab82fdc71..3b16cd1f3c 100644
--- a/target/nios2/cpu.h
+++ b/target/nios2/cpu.h
@@ -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,
diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index 08d7ac5398..a5f0f56e1a 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -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)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 18/53] target/nios2: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/nios2/cpu.c       |  2 +-
 target/nios2/cpu.h       |  2 +-
 target/nios2/translate.c | 20 ++++++++++----------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
index 5e37defef8..cbf15fb1c9 100644
--- a/target/nios2/cpu.c
+++ b/target/nios2/cpu.c
@@ -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
diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
index 2ab82fdc71..3b16cd1f3c 100644
--- a/target/nios2/cpu.h
+++ b/target/nios2/cpu.h
@@ -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,
diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index 08d7ac5398..a5f0f56e1a 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -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)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 19/53] target/openrisc: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/openrisc/cpu.c       | 2 +-
 target/openrisc/cpu.h       | 2 +-
 target/openrisc/translate.c | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
index bd34e429ec..d60d248958 100644
--- a/target/openrisc/cpu.c
+++ b/target/openrisc/cpu.c
@@ -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;
diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h
index 82cbaeb4f8..112b845b10 100644
--- a/target/openrisc/cpu.h
+++ b/target/openrisc/cpu.h
@@ -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);
diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c
index d6ea536744..0155f2b160 100644
--- a/target/openrisc/translate.c
+++ b/target/openrisc/translate.c
@@ -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' : ' ');
     }
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 19/53] target/openrisc: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/openrisc/cpu.c       | 2 +-
 target/openrisc/cpu.h       | 2 +-
 target/openrisc/translate.c | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
index bd34e429ec..d60d248958 100644
--- a/target/openrisc/cpu.c
+++ b/target/openrisc/cpu.c
@@ -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;
diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h
index 82cbaeb4f8..112b845b10 100644
--- a/target/openrisc/cpu.h
+++ b/target/openrisc/cpu.h
@@ -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);
diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c
index d6ea536744..0155f2b160 100644
--- a/target/openrisc/translate.c
+++ b/target/openrisc/translate.c
@@ -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' : ' ');
     }
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 20/53] target/ppc: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/ppc/cpu.h      |   2 +-
 target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
 2 files changed, 126 insertions(+), 88 deletions(-)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 500205229c..c84ae29b98 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -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);
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index ad7abc6041..3456be465c 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 20/53] target/ppc: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/ppc/cpu.h      |   2 +-
 target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
 2 files changed, 126 insertions(+), 88 deletions(-)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 500205229c..c84ae29b98 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -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);
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index ad7abc6041..3456be465c 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 21/53] target/riscv: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/riscv/cpu.c | 105 ++++++++++++++++++++++++++++-----------------
 1 file changed, 66 insertions(+), 39 deletions(-)

diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 1a2b03d579..7a9e013e32 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 21/53] target/riscv: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/riscv/cpu.c | 105 ++++++++++++++++++++++++++++-----------------
 1 file changed, 66 insertions(+), 39 deletions(-)

diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 1a2b03d579..7a9e013e32 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 22/53] target/rx: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/rx/cpu.c       |  2 +-
 target/rx/cpu.h       |  2 +-
 target/rx/translate.c | 14 ++++++++------
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/target/rx/cpu.c b/target/rx/cpu.c
index 96cc96e514..f7f158cfa5 100644
--- a/target/rx/cpu.c
+++ b/target/rx/cpu.c
@@ -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
diff --git a/target/rx/cpu.h b/target/rx/cpu.h
index 0b4b998c7b..97fc1b9ed6 100644
--- a/target/rx/cpu.h
+++ b/target/rx/cpu.h
@@ -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);
diff --git a/target/rx/translate.c b/target/rx/translate.c
index a3cf720455..2d3bdabce4 100644
--- a/target/rx/translate.c
+++ b/target/rx/translate.c
@@ -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]);
     }
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 22/53] target/rx: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/rx/cpu.c       |  2 +-
 target/rx/cpu.h       |  2 +-
 target/rx/translate.c | 14 ++++++++------
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/target/rx/cpu.c b/target/rx/cpu.c
index 96cc96e514..f7f158cfa5 100644
--- a/target/rx/cpu.c
+++ b/target/rx/cpu.c
@@ -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
diff --git a/target/rx/cpu.h b/target/rx/cpu.h
index 0b4b998c7b..97fc1b9ed6 100644
--- a/target/rx/cpu.h
+++ b/target/rx/cpu.h
@@ -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);
diff --git a/target/rx/translate.c b/target/rx/translate.c
index a3cf720455..2d3bdabce4 100644
--- a/target/rx/translate.c
+++ b/target/rx/translate.c
@@ -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]);
     }
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 23/53] target/s390x: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/s390x/cpu-dump.c       | 43 ++++++++++++++++++-----------------
 target/s390x/cpu.c            |  2 +-
 target/s390x/s390x-internal.h |  2 +-
 3 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/target/s390x/cpu-dump.c b/target/s390x/cpu-dump.c
index 0f5c062994..9c6eaa9938 100644
--- a/target/s390x/cpu-dump.c
+++ b/target/s390x/cpu-dump.c
@@ -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)
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 7b7b05f1d3..b6bf628074 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -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;
diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h
index 7a6aa4dacc..0ee99b8b1e 100644
--- a/target/s390x/s390x-internal.h
+++ b/target/s390x/s390x-internal.h
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 23/53] target/s390x: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/s390x/cpu-dump.c       | 43 ++++++++++++++++++-----------------
 target/s390x/cpu.c            |  2 +-
 target/s390x/s390x-internal.h |  2 +-
 3 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/target/s390x/cpu-dump.c b/target/s390x/cpu-dump.c
index 0f5c062994..9c6eaa9938 100644
--- a/target/s390x/cpu-dump.c
+++ b/target/s390x/cpu-dump.c
@@ -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)
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 7b7b05f1d3..b6bf628074 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -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;
diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h
index 7a6aa4dacc..0ee99b8b1e 100644
--- a/target/s390x/s390x-internal.h
+++ b/target/s390x/s390x-internal.h
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 24/53] target/sh: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/sh4/cpu.c       |  2 +-
 target/sh4/cpu.h       |  2 +-
 target/sh4/translate.c | 36 ++++++++++++++++++++----------------
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 8326922942..0ac881d6af 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -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;
diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
index 01c4344082..6940ca417a 100644
--- a/target/sh4/cpu.h
+++ b/target/sh4/cpu.h
@@ -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);
diff --git a/target/sh4/translate.c b/target/sh4/translate.c
index 8704fea1ca..f6fd8939b0 100644
--- a/target/sh4/translate.c
+++ b/target/sh4/translate.c
@@ -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);
     }
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 24/53] target/sh: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/sh4/cpu.c       |  2 +-
 target/sh4/cpu.h       |  2 +-
 target/sh4/translate.c | 36 ++++++++++++++++++++----------------
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 8326922942..0ac881d6af 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -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;
diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
index 01c4344082..6940ca417a 100644
--- a/target/sh4/cpu.h
+++ b/target/sh4/cpu.h
@@ -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);
diff --git a/target/sh4/translate.c b/target/sh4/translate.c
index 8704fea1ca..f6fd8939b0 100644
--- a/target/sh4/translate.c
+++ b/target/sh4/translate.c
@@ -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);
     }
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 25/53] target/sparc: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
 target/sparc/cpu.h |  2 +-
 2 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index da6b30ec74..9346a79239 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -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
diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index ff8ae73002..65a01a7884 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 25/53] target/sparc: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
 target/sparc/cpu.h |  2 +-
 2 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index da6b30ec74..9346a79239 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -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
diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index ff8ae73002..65a01a7884 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 26/53] target/tricore: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/tricore/cpu.c       |  2 +-
 target/tricore/cpu.h       |  2 +-
 target/tricore/translate.c | 24 ++++++++++++------------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index b95682b7f0..11f1a79247 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -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;
diff --git a/target/tricore/cpu.h b/target/tricore/cpu.h
index 4b61a2c03f..572bda55e7 100644
--- a/target/tricore/cpu.h
+++ b/target/tricore/cpu.h
@@ -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
diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index a0cc0f1cb3..a1e56fba32 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -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");
 }
 
 /*
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 26/53] target/tricore: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/tricore/cpu.c       |  2 +-
 target/tricore/cpu.h       |  2 +-
 target/tricore/translate.c | 24 ++++++++++++------------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index b95682b7f0..11f1a79247 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -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;
diff --git a/target/tricore/cpu.h b/target/tricore/cpu.h
index 4b61a2c03f..572bda55e7 100644
--- a/target/tricore/cpu.h
+++ b/target/tricore/cpu.h
@@ -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
diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index a0cc0f1cb3..a1e56fba32 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -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");
 }
 
 /*
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/xtensa/cpu.c       |  2 +-
 target/xtensa/cpu.h       |  2 +-
 target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
 3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
index 58ec3a0862..a5a416e0b3 100644
--- a/target/xtensa/cpu.c
+++ b/target/xtensa/cpu.c
@@ -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;
diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
index 2345cb59c7..97cd6892df 100644
--- a/target/xtensa/cpu.h
+++ b/target/xtensa/cpu.h
@@ -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);
diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c
index 20399d6a04..0f57d2abaf 100644
--- a/target/xtensa/translate.c
+++ b/target/xtensa/translate.c
@@ -1325,14 +1325,14 @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns)
     translator_loop(&xtensa_translator_ops, &dc.base, cpu, tb, max_insns);
 }
 
-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' : ' ');
     }
 
     xtensa_sync_phys_from_window(env);
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
 
     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;
 
-            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");
 
         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]),
+                                   *(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");
 
         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' : ' ');
         }
     }
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/xtensa/cpu.c       |  2 +-
 target/xtensa/cpu.h       |  2 +-
 target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
 3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
index 58ec3a0862..a5a416e0b3 100644
--- a/target/xtensa/cpu.c
+++ b/target/xtensa/cpu.c
@@ -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;
diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
index 2345cb59c7..97cd6892df 100644
--- a/target/xtensa/cpu.h
+++ b/target/xtensa/cpu.h
@@ -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);
diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c
index 20399d6a04..0f57d2abaf 100644
--- a/target/xtensa/translate.c
+++ b/target/xtensa/translate.c
@@ -1325,14 +1325,14 @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns)
     translator_loop(&xtensa_translator_ops, &dc.base, cpu, tb, max_insns);
 }
 
-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' : ' ');
     }
 
     xtensa_sync_phys_from_window(env);
-    qemu_fprintf(f, "\n");
+    g_string_append_printf(buf, "\n");
 
     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;
 
-            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");
 
         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]),
+                                   *(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");
 
         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' : ' ');
         }
     }
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 28/53] monitor: remove 'info ioapic' HMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

  commit 0c8465440d50c18a7bb13d0a866748f0593e193a
  Author: Peter Xu <peterx@redhat.com>
  Date:   Fri Dec 29 15:31:04 2017 +0800

    hmp: obsolete "info ioapic"

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hmp-commands-info.hx         | 15 ---------------
 include/monitor/hmp-target.h |  1 -
 target/i386/monitor.c        |  6 ------
 3 files changed, 22 deletions(-)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 27206ac049..f8312342cd 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -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  = "",
diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h
index 60fc92722a..df79ad3355 100644
--- a/include/monitor/hmp-target.h
+++ b/include/monitor/hmp-target.h
@@ -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 */
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index 119211f0b0..19468c4e85 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 28/53] monitor: remove 'info ioapic' HMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

  commit 0c8465440d50c18a7bb13d0a866748f0593e193a
  Author: Peter Xu <peterx@redhat.com>
  Date:   Fri Dec 29 15:31:04 2017 +0800

    hmp: obsolete "info ioapic"

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hmp-commands-info.hx         | 15 ---------------
 include/monitor/hmp-target.h |  1 -
 target/i386/monitor.c        |  6 ------
 3 files changed, 22 deletions(-)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 27206ac049..f8312342cd 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -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  = "",
diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h
index 60fc92722a..df79ad3355 100644
--- a/include/monitor/hmp-target.h
+++ b/include/monitor/hmp-target.h
@@ -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 */
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index 119211f0b0..19468c4e85 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 29/53] qapi: introduce x-query-registers QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 216fdfaf3a..c4e384f7d5 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -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;
+}
diff --git a/monitor/misc.c b/monitor/misc.c
index ffe7966870..f25801a1a3 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -67,6 +67,7 @@
 #include "block/block-hmp-cmds.h"
 #include "qapi/qapi-commands-char.h"
 #include "qapi/qapi-commands-control.h"
+#include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-qom.h"
@@ -301,23 +302,29 @@ int monitor_get_cpu_index(Monitor *mon)
 static void hmp_info_registers(Monitor *mon, const QDict *qdict)
 {
     bool all_cpus = 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)
diff --git a/qapi/common.json b/qapi/common.json
index 7c976296f0..de7614ca99 100644
--- a/qapi/common.json
+++ b/qapi/common.json
@@ -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' } }
diff --git a/qapi/machine.json b/qapi/machine.json
index 157712f006..8737efa865 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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' }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 29/53] qapi: introduce x-query-registers QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 216fdfaf3a..c4e384f7d5 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -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;
+}
diff --git a/monitor/misc.c b/monitor/misc.c
index ffe7966870..f25801a1a3 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -67,6 +67,7 @@
 #include "block/block-hmp-cmds.h"
 #include "qapi/qapi-commands-char.h"
 #include "qapi/qapi-commands-control.h"
+#include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-qom.h"
@@ -301,23 +302,29 @@ int monitor_get_cpu_index(Monitor *mon)
 static void hmp_info_registers(Monitor *mon, const QDict *qdict)
 {
     bool all_cpus = 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)
diff --git a/qapi/common.json b/qapi/common.json
index 7c976296f0..de7614ca99 100644
--- a/qapi/common.json
+++ b/qapi/common.json
@@ -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' } }
diff --git a/qapi/machine.json b/qapi/machine.json
index 157712f006..8737efa865 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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' }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 30/53] qapi: introduce x-query-roms QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
 qapi/machine.json | 12 +++++++++++
 2 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index c623318b73..014d131847 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -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;
diff --git a/qapi/machine.json b/qapi/machine.json
index 8737efa865..a4a1727589 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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' }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 30/53] qapi: introduce x-query-roms QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
 qapi/machine.json | 12 +++++++++++
 2 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index c623318b73..014d131847 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -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;
diff --git a/qapi/machine.json b/qapi/machine.json
index 8737efa865..a4a1727589 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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' }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 31/53] qapi: introduce x-query-profile QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/monitor/misc.c b/monitor/misc.c
index f25801a1a3..6b07efdddd 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -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;
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 5c0d5e116b..7bae0770a9 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -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
diff --git a/qapi/machine.json b/qapi/machine.json
index a4a1727589..d74c3f3fef 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index c98b78d033..fbd7ac10fb 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 31/53] qapi: introduce x-query-profile QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/monitor/misc.c b/monitor/misc.c
index f25801a1a3..6b07efdddd 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -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;
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 5c0d5e116b..7bae0770a9 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -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
diff --git a/qapi/machine.json b/qapi/machine.json
index a4a1727589..d74c3f3fef 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index c98b78d033..fbd7ac10fb 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 32/53] qapi: introduce x-query-numa QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c
index 76b22b00d6..cfa01c6933 100644
--- a/hw/core/machine-hmp-cmds.c
+++ b/hw/core/machine-hmp-cmds.c
@@ -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);
 }
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index c4e384f7d5..4407e967da 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -234,3 +234,45 @@ HumanReadableText *qmp_x_query_registers(bool has_cpu, int64_t cpu,
     ret->human_readable_text = g_steal_pointer(&buf->str);
     return ret;
 }
+
+HumanReadableText *qmp_x_query_numa(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+    int i, nb_numa_nodes;
+    NumaNodeMem *node_mem;
+    CpuInfoFastList *cpu_list, *cpu;
+    MachineState *ms = MACHINE(qdev_get_machine());
+
+    nb_numa_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0;
+    g_string_append_printf(buf, "%d nodes\n", nb_numa_nodes);
+    if (!nb_numa_nodes) {
+        goto done;
+    }
+
+    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++) {
+        g_string_append_printf(buf, "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) {
+                g_string_append_printf(buf, " %" PRIi64, cpu->value->cpu_index);
+            }
+        }
+        g_string_append_printf(buf, "\n");
+        g_string_append_printf(buf, "node %d size: %" PRId64 " MB\n", i,
+                               node_mem[i].node_mem >> 20);
+        g_string_append_printf(buf, "node %d plugged: %" PRId64 " MB\n", i,
+                               node_mem[i].node_plugged_mem >> 20);
+    }
+    qapi_free_CpuInfoFastList(cpu_list);
+    g_free(node_mem);
+
+ done:
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index d74c3f3fef..916f855e9b 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 32/53] qapi: introduce x-query-numa QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c
index 76b22b00d6..cfa01c6933 100644
--- a/hw/core/machine-hmp-cmds.c
+++ b/hw/core/machine-hmp-cmds.c
@@ -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);
 }
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index c4e384f7d5..4407e967da 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -234,3 +234,45 @@ HumanReadableText *qmp_x_query_registers(bool has_cpu, int64_t cpu,
     ret->human_readable_text = g_steal_pointer(&buf->str);
     return ret;
 }
+
+HumanReadableText *qmp_x_query_numa(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+    int i, nb_numa_nodes;
+    NumaNodeMem *node_mem;
+    CpuInfoFastList *cpu_list, *cpu;
+    MachineState *ms = MACHINE(qdev_get_machine());
+
+    nb_numa_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0;
+    g_string_append_printf(buf, "%d nodes\n", nb_numa_nodes);
+    if (!nb_numa_nodes) {
+        goto done;
+    }
+
+    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++) {
+        g_string_append_printf(buf, "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) {
+                g_string_append_printf(buf, " %" PRIi64, cpu->value->cpu_index);
+            }
+        }
+        g_string_append_printf(buf, "\n");
+        g_string_append_printf(buf, "node %d size: %" PRId64 " MB\n", i,
+                               node_mem[i].node_mem >> 20);
+        g_string_append_printf(buf, "node %d plugged: %" PRId64 " MB\n", i,
+                               node_mem[i].node_plugged_mem >> 20);
+    }
+    qapi_free_CpuInfoFastList(cpu_list);
+    g_free(node_mem);
+
+ done:
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index d74c3f3fef..916f855e9b 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 33/53] qapi: introduce x-query-usb QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 07083349f5..f94d872429 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -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 */
diff --git a/qapi/machine.json b/qapi/machine.json
index 916f855e9b..39d800c2c1 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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' }
diff --git a/stubs/usb-dev-stub.c b/stubs/usb-dev-stub.c
index b1adeeb454..aa557692b7 100644
--- a/stubs/usb-dev-stub.c
+++ b/stubs/usb-dev-stub.c
@@ -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");
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index fbd7ac10fb..15875a14c6 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 33/53] qapi: introduce x-query-usb QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 07083349f5..f94d872429 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -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 */
diff --git a/qapi/machine.json b/qapi/machine.json
index 916f855e9b..39d800c2c1 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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' }
diff --git a/stubs/usb-dev-stub.c b/stubs/usb-dev-stub.c
index b1adeeb454..aa557692b7 100644
--- a/stubs/usb-dev-stub.c
+++ b/stubs/usb-dev-stub.c
@@ -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");
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index fbd7ac10fb..15875a14c6 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 34/53] qapi: introduce x-query-rdma QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/rdma/rdma_rm.c b/hw/rdma/rdma_rm.c
index 49141d4074..cfd85de3e6 100644
--- a/hw/rdma/rdma_rm.c
+++ b/hw/rdma/rdma_rm.c
@@ -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,
diff --git a/hw/rdma/rdma_rm.h b/hw/rdma/rdma_rm.h
index e8639909cd..d69a917795 100644
--- a/hw/rdma/rdma_rm.h
+++ b/hw/rdma/rdma_rm.h
@@ -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
diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
index 7c0c3551a8..91206dbb8e 100644
--- a/hw/rdma/vmw/pvrdma_main.c
+++ b/hw/rdma/vmw/pvrdma_main.c
@@ -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 = {
diff --git a/include/hw/rdma/rdma.h b/include/hw/rdma/rdma.h
index e77e43a170..80b2e531c4 100644
--- a/include/hw/rdma/rdma.h
+++ b/include/hw/rdma/rdma.h
@@ -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
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index e00255f7ee..d24a1683de 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -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)
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 7bae0770a9..9c2c1e4603 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -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;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index 39d800c2c1..0fe962d916 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 34/53] qapi: introduce x-query-rdma QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/rdma/rdma_rm.c b/hw/rdma/rdma_rm.c
index 49141d4074..cfd85de3e6 100644
--- a/hw/rdma/rdma_rm.c
+++ b/hw/rdma/rdma_rm.c
@@ -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,
diff --git a/hw/rdma/rdma_rm.h b/hw/rdma/rdma_rm.h
index e8639909cd..d69a917795 100644
--- a/hw/rdma/rdma_rm.h
+++ b/hw/rdma/rdma_rm.h
@@ -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
diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
index 7c0c3551a8..91206dbb8e 100644
--- a/hw/rdma/vmw/pvrdma_main.c
+++ b/hw/rdma/vmw/pvrdma_main.c
@@ -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 = {
diff --git a/include/hw/rdma/rdma.h b/include/hw/rdma/rdma.h
index e77e43a170..80b2e531c4 100644
--- a/include/hw/rdma/rdma.h
+++ b/include/hw/rdma/rdma.h
@@ -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
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index e00255f7ee..d24a1683de 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -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)
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 7bae0770a9..9c2c1e4603 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -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;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index 39d800c2c1..0fe962d916 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 35/53] qapi: introduce x-query-ramblock QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/include/exec/ramlist.h b/include/exec/ramlist.h
index ece6497ee2..2ad2a81acc 100644
--- a/include/exec/ramlist.h
+++ b/include/exec/ramlist.h
@@ -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 */
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index d24a1683de..77533b2d8a 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -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)
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 9c2c1e4603..b86fff823e 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -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;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index 0fe962d916..3ae7beb7cf 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 23e77cb771..bc4a8354d3 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -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__
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 35/53] qapi: introduce x-query-ramblock QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/include/exec/ramlist.h b/include/exec/ramlist.h
index ece6497ee2..2ad2a81acc 100644
--- a/include/exec/ramlist.h
+++ b/include/exec/ramlist.h
@@ -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 */
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index d24a1683de..77533b2d8a 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -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)
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 9c2c1e4603..b86fff823e 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -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;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index 0fe962d916..3ae7beb7cf 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 23e77cb771..bc4a8354d3 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -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__
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 36/53] qapi: introduce x-query-skeys QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/s390x/s390-skeys.c    | 37 +++++++++++++++++++++++++++++--------
 qapi/machine-target.json | 27 +++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
index 5024faf411..3a404d0574 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -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)
diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index f5ec4bc172..00476bcdd4 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -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' }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 36/53] qapi: introduce x-query-skeys QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/s390x/s390-skeys.c    | 37 +++++++++++++++++++++++++++++--------
 qapi/machine-target.json | 27 +++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
index 5024faf411..3a404d0574 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -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)
diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index f5ec4bc172..00476bcdd4 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -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' }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 37/53] qapi: introduce x-query-cmma QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/s390x/s390-stattrib.c | 58 +++++++++++++++++++++++++++-------------
 qapi/machine-target.json | 14 ++++++++++
 2 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index 9eda1c3b2a..1ff0142b10 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -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: */
diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index 00476bcdd4..9040aff863 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 37/53] qapi: introduce x-query-cmma QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/s390x/s390-stattrib.c | 58 +++++++++++++++++++++++++++-------------
 qapi/machine-target.json | 14 ++++++++++
 2 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index 9eda1c3b2a..1ff0142b10 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -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: */
diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index 00476bcdd4..9040aff863 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index c2cd33a817..d1ebc77d1b 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 1599ef9df3..a0913eedaa 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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.
diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index 9040aff863..62220d1f08 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -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:
 #
diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c
index f30fbcb76e..41a1f64138 100644
--- a/target/i386/cpu-dump.c
+++ b/target/i386/cpu-dump.c
@@ -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 */
 
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index d87c8808f6..2bcb175da8 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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);
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index 19468c4e85..fc09f90059 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -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,
+                                           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;
+    }
+
+    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)
 {
-    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);
     } 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)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index c2cd33a817..d1ebc77d1b 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 1599ef9df3..a0913eedaa 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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.
diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index 9040aff863..62220d1f08 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -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:
 #
diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c
index f30fbcb76e..41a1f64138 100644
--- a/target/i386/cpu-dump.c
+++ b/target/i386/cpu-dump.c
@@ -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 */
 
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index d87c8808f6..2bcb175da8 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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);
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index 19468c4e85..fc09f90059 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -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,
+                                           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;
+    }
+
+    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)
 {
-    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);
     } 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)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 39/53] qapi: introduce x-query-irq QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 monitor/hmp-cmds.c | 40 ++++++++-------------------------------
 monitor/qmp-cmds.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 qapi/machine.json  | 12 ++++++++++++
 3 files changed, 67 insertions(+), 32 deletions(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 77533b2d8a..eb2202329d 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -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)
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index b86fff823e..cfb98658e4 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -40,6 +40,7 @@
 #include "exec/ramlist.h"
 #include "hw/mem/memory-device.h"
 #include "hw/acpi/acpi_dev_interface.h"
+#include "hw/intc/intc.h"
 #include "hw/rdma/rdma.h"
 
 NameInfo *qmp_query_name(Error **errp)
@@ -430,3 +431,49 @@ HumanReadableText *qmp_x_query_ramblock(Error **errp)
     ret->human_readable_text = g_steal_pointer(&buf->str);
     return ret;
 }
+
+static int qmp_x_query_irq_foreach(Object *obj, void *opaque)
+{
+    InterruptStatsProvider *intc;
+    InterruptStatsProviderClass *k;
+    GString *buf = opaque;
+
+    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) {
+                g_string_append_printf(buf, "IRQ statistics for %s:\n",
+                                       object_get_typename(obj));
+                for (i = 0; i < nb_irqs; i++) {
+                    if (irq_counts[i] > 0) {
+                        g_string_append_printf(buf, "%2d: %" PRId64 "\n", i,
+                                               irq_counts[i]);
+                    }
+                }
+            }
+        } else {
+            g_string_append_printf(buf,
+                                   "IRQ statistics not available for %s.\n",
+                                   object_get_typename(obj));
+        }
+    }
+
+    return 0;
+}
+
+HumanReadableText *qmp_x_query_irq(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+
+    object_child_foreach_recursive(object_get_root(),
+                                   qmp_x_query_irq_foreach, buf);
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index 3ae7beb7cf..e72b47ea7d 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 39/53] qapi: introduce x-query-irq QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 monitor/hmp-cmds.c | 40 ++++++++-------------------------------
 monitor/qmp-cmds.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 qapi/machine.json  | 12 ++++++++++++
 3 files changed, 67 insertions(+), 32 deletions(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 77533b2d8a..eb2202329d 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -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)
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index b86fff823e..cfb98658e4 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -40,6 +40,7 @@
 #include "exec/ramlist.h"
 #include "hw/mem/memory-device.h"
 #include "hw/acpi/acpi_dev_interface.h"
+#include "hw/intc/intc.h"
 #include "hw/rdma/rdma.h"
 
 NameInfo *qmp_query_name(Error **errp)
@@ -430,3 +431,49 @@ HumanReadableText *qmp_x_query_ramblock(Error **errp)
     ret->human_readable_text = g_steal_pointer(&buf->str);
     return ret;
 }
+
+static int qmp_x_query_irq_foreach(Object *obj, void *opaque)
+{
+    InterruptStatsProvider *intc;
+    InterruptStatsProviderClass *k;
+    GString *buf = opaque;
+
+    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) {
+                g_string_append_printf(buf, "IRQ statistics for %s:\n",
+                                       object_get_typename(obj));
+                for (i = 0; i < nb_irqs; i++) {
+                    if (irq_counts[i] > 0) {
+                        g_string_append_printf(buf, "%2d: %" PRId64 "\n", i,
+                                               irq_counts[i]);
+                    }
+                }
+            }
+        } else {
+            g_string_append_printf(buf,
+                                   "IRQ statistics not available for %s.\n",
+                                   object_get_typename(obj));
+        }
+    }
+
+    return 0;
+}
+
+HumanReadableText *qmp_x_query_irq(Error **errp)
+{
+    HumanReadableText *ret;
+    g_autoptr(GString) buf = g_string_new("");
+
+    object_child_foreach_recursive(object_get_root(),
+                                   qmp_x_query_irq_foreach, buf);
+
+    ret = g_new0(HumanReadableText, 1);
+    ret->human_readable_text = g_steal_pointer(&buf->str);
+    return ret;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index 3ae7beb7cf..e72b47ea7d 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 40/53] hw/core: drop "dump_state" callback from CPU targets
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/cpu-common.c  | 14 +++-----------
 include/hw/core/cpu.h |  2 --
 2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index d1ebc77d1b..494f4f41eb 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index a0913eedaa..9cfc7d7479 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 40/53] hw/core: drop "dump_state" callback from CPU targets
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/cpu-common.c  | 14 +++-----------
 include/hw/core/cpu.h |  2 --
 2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index d1ebc77d1b..494f4f41eb 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index a0913eedaa..9cfc7d7479 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 41/53] hw/core: drop support for NULL pointer for FILE * in cpu_dump_state
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/cpu-common.c  | 2 +-
 include/hw/core/cpu.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 494f4f41eb..ffd9b9e07e 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 9cfc7d7479..4c47e1df18 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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.
  */
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 41/53] hw/core: drop support for NULL pointer for FILE * in cpu_dump_state
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/cpu-common.c  | 2 +-
 include/hw/core/cpu.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 494f4f41eb..ffd9b9e07e 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 9cfc7d7479..4c47e1df18 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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.
  */
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/cpu-common.c  |  9 +++++++++
 include/hw/core/cpu.h | 11 +++++++++++
 2 files changed, 20 insertions(+)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index ffd9b9e07e..9b11ec3c8d 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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));
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 4c47e1df18..64fc57c8d9 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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:
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/cpu-common.c  |  9 +++++++++
 include/hw/core/cpu.h | 11 +++++++++++
 2 files changed, 20 insertions(+)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index ffd9b9e07e..9b11ec3c8d 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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));
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 4c47e1df18..64fc57c8d9 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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:
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 43/53] target/i386: convert to use format_tlb callback
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/i386/cpu.c     |   3 ++
 target/i386/cpu.h     |   1 +
 target/i386/monitor.c | 107 +++++++++++++++++++++++-------------------
 3 files changed, 63 insertions(+), 48 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 0a5c6a6d19..ab86224ee2 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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;
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 2bcb175da8..d61eeef617 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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);
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index fc09f90059..698fbbc80b 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -54,27 +54,27 @@ static hwaddr addr_canonical(CPUArchState *env, hwaddr addr)
     return addr;
 }
 
-static void print_pte(Monitor *mon, CPUArchState *env, hwaddr addr,
-                      hwaddr pte, hwaddr mask)
+static void format_pte(GString *buf, CPUArchState *env, hwaddr addr,
+                       hwaddr pte, hwaddr mask)
 {
     addr = addr_canonical(env, addr);
 
-    monitor_printf(mon, TARGET_FMT_plx ": " TARGET_FMT_plx
-                   " %c%c%c%c%c%c%c%c%c\n",
-                   addr,
-                   pte & mask,
-                   pte & PG_NX_MASK ? 'X' : '-',
-                   pte & PG_GLOBAL_MASK ? 'G' : '-',
-                   pte & PG_PSE_MASK ? 'P' : '-',
-                   pte & PG_DIRTY_MASK ? 'D' : '-',
-                   pte & PG_ACCESSED_MASK ? 'A' : '-',
-                   pte & PG_PCD_MASK ? 'C' : '-',
-                   pte & PG_PWT_MASK ? 'T' : '-',
-                   pte & PG_USER_MASK ? 'U' : '-',
-                   pte & PG_RW_MASK ? 'W' : '-');
+    g_string_append_printf(buf, TARGET_FMT_plx ": " TARGET_FMT_plx
+                           " %c%c%c%c%c%c%c%c%c\n",
+                           addr,
+                           pte & mask,
+                           pte & PG_NX_MASK ? 'X' : '-',
+                           pte & PG_GLOBAL_MASK ? 'G' : '-',
+                           pte & PG_PSE_MASK ? 'P' : '-',
+                           pte & PG_DIRTY_MASK ? 'D' : '-',
+                           pte & PG_ACCESSED_MASK ? 'A' : '-',
+                           pte & PG_PCD_MASK ? 'C' : '-',
+                           pte & PG_PWT_MASK ? 'T' : '-',
+                           pte & PG_USER_MASK ? 'U' : '-',
+                           pte & PG_RW_MASK ? 'W' : '-');
 }
 
-static void tlb_info_32(Monitor *mon, CPUArchState *env)
+static void tlb_info_32(GString *buf, CPUArchState *env)
 {
     unsigned int l1, l2;
     uint32_t pgd, pde, pte;
@@ -86,15 +86,15 @@ static void tlb_info_32(Monitor *mon, CPUArchState *env)
         if (pde & PG_PRESENT_MASK) {
             if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
                 /* 4M pages */
-                print_pte(mon, env, (l1 << 22), pde, ~((1 << 21) - 1));
+                format_pte(buf, env, (l1 << 22), pde, ~((1 << 21) - 1));
             } else {
                 for(l2 = 0; l2 < 1024; l2++) {
                     cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
                     pte = le32_to_cpu(pte);
                     if (pte & PG_PRESENT_MASK) {
-                        print_pte(mon, env, (l1 << 22) + (l2 << 12),
-                                  pte & ~PG_PSE_MASK,
-                                  ~0xfff);
+                        format_pte(buf, env, (l1 << 22) + (l2 << 12),
+                                   pte & ~PG_PSE_MASK,
+                                   ~0xfff);
                     }
                 }
             }
@@ -102,7 +102,7 @@ static void tlb_info_32(Monitor *mon, CPUArchState *env)
     }
 }
 
-static void tlb_info_pae32(Monitor *mon, CPUArchState *env)
+static void tlb_info_pae32(GString *buf, CPUArchState *env)
 {
     unsigned int l1, l2, l3;
     uint64_t pdpe, pde, pte;
@@ -120,18 +120,18 @@ static void tlb_info_pae32(Monitor *mon, CPUArchState *env)
                 if (pde & PG_PRESENT_MASK) {
                     if (pde & PG_PSE_MASK) {
                         /* 2M pages with PAE, CR4.PSE is ignored */
-                        print_pte(mon, env, (l1 << 30) + (l2 << 21), pde,
-                                  ~((hwaddr)(1 << 20) - 1));
+                        format_pte(buf, env, (l1 << 30) + (l2 << 21), pde,
+                                   ~((hwaddr)(1 << 20) - 1));
                     } else {
                         pt_addr = pde & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
                             cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8);
                             pte = le64_to_cpu(pte);
                             if (pte & PG_PRESENT_MASK) {
-                                print_pte(mon, env, (l1 << 30) + (l2 << 21)
-                                          + (l3 << 12),
-                                          pte & ~PG_PSE_MASK,
-                                          ~(hwaddr)0xfff);
+                                format_pte(buf, env, (l1 << 30) + (l2 << 21)
+                                           + (l3 << 12),
+                                           pte & ~PG_PSE_MASK,
+                                           ~(hwaddr)0xfff);
                             }
                         }
                     }
@@ -142,7 +142,7 @@ static void tlb_info_pae32(Monitor *mon, CPUArchState *env)
 }
 
 #ifdef TARGET_X86_64
-static void tlb_info_la48(Monitor *mon, CPUArchState *env,
+static void tlb_info_la48(GString *buf, CPUArchState *env,
         uint64_t l0, uint64_t pml4_addr)
 {
     uint64_t l1, l2, l3, l4;
@@ -166,8 +166,8 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env,
 
             if (pdpe & PG_PSE_MASK) {
                 /* 1G pages, CR4.PSE is ignored */
-                print_pte(mon, env, (l0 << 48) + (l1 << 39) + (l2 << 30),
-                        pdpe, 0x3ffffc0000000ULL);
+                format_pte(buf, env, (l0 << 48) + (l1 << 39) + (l2 << 30),
+                           pdpe, 0x3ffffc0000000ULL);
                 continue;
             }
 
@@ -181,8 +181,8 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env,
 
                 if (pde & PG_PSE_MASK) {
                     /* 2M pages, CR4.PSE is ignored */
-                    print_pte(mon, env, (l0 << 48) + (l1 << 39) + (l2 << 30) +
-                            (l3 << 21), pde, 0x3ffffffe00000ULL);
+                    format_pte(buf, env, (l0 << 48) + (l1 << 39) + (l2 << 30) +
+                               (l3 << 21), pde, 0x3ffffffe00000ULL);
                     continue;
                 }
 
@@ -193,9 +193,9 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env,
                             &pte, 8);
                     pte = le64_to_cpu(pte);
                     if (pte & PG_PRESENT_MASK) {
-                        print_pte(mon, env, (l0 << 48) + (l1 << 39) +
-                                (l2 << 30) + (l3 << 21) + (l4 << 12),
-                                pte & ~PG_PSE_MASK, 0x3fffffffff000ULL);
+                        format_pte(buf, env, (l0 << 48) + (l1 << 39) +
+                                   (l2 << 30) + (l3 << 21) + (l4 << 12),
+                                   pte & ~PG_PSE_MASK, 0x3fffffffff000ULL);
                     }
                 }
             }
@@ -203,7 +203,7 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env,
     }
 }
 
-static void tlb_info_la57(Monitor *mon, CPUArchState *env)
+static void tlb_info_la57(GString *buf, CPUArchState *env)
 {
     uint64_t l0;
     uint64_t pml5e;
@@ -214,44 +214,55 @@ static void tlb_info_la57(Monitor *mon, CPUArchState *env)
         cpu_physical_memory_read(pml5_addr + l0 * 8, &pml5e, 8);
         pml5e = le64_to_cpu(pml5e);
         if (pml5e & PG_PRESENT_MASK) {
-            tlb_info_la48(mon, env, l0, pml5e & 0x3fffffffff000ULL);
+            tlb_info_la48(buf, env, l0, pml5e & 0x3fffffffff000ULL);
         }
     }
 }
 #endif /* TARGET_X86_64 */
 
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
+void x86_cpu_format_tlb(CPUState *cpu, GString *buf)
 {
     CPUArchState *env;
 
-    env = mon_get_cpu_env(mon);
-    if (!env) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
+    env = cpu->env_ptr;
 
     if (!(env->cr[0] & CR0_PG_MASK)) {
-        monitor_printf(mon, "PG disabled\n");
+        g_string_append_printf(buf, "PG disabled\n");
         return;
     }
     if (env->cr[4] & CR4_PAE_MASK) {
 #ifdef TARGET_X86_64
         if (env->hflags & HF_LMA_MASK) {
             if (env->cr[4] & CR4_LA57_MASK) {
-                tlb_info_la57(mon, env);
+                tlb_info_la57(buf, env);
             } else {
-                tlb_info_la48(mon, env, 0, env->cr[3] & 0x3fffffffff000ULL);
+                tlb_info_la48(buf, env, 0, env->cr[3] & 0x3fffffffff000ULL);
             }
         } else
 #endif
         {
-            tlb_info_pae32(mon, env);
+            tlb_info_pae32(buf, env);
         }
     } else {
-        tlb_info_32(mon, env);
+        tlb_info_32(buf, 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);
+}
+
 static void mem_print(Monitor *mon, CPUArchState *env,
                       hwaddr *pstart, int *plast_prot,
                       hwaddr end, int prot)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 43/53] target/i386: convert to use format_tlb callback
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/i386/cpu.c     |   3 ++
 target/i386/cpu.h     |   1 +
 target/i386/monitor.c | 107 +++++++++++++++++++++++-------------------
 3 files changed, 63 insertions(+), 48 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 0a5c6a6d19..ab86224ee2 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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;
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 2bcb175da8..d61eeef617 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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);
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index fc09f90059..698fbbc80b 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -54,27 +54,27 @@ static hwaddr addr_canonical(CPUArchState *env, hwaddr addr)
     return addr;
 }
 
-static void print_pte(Monitor *mon, CPUArchState *env, hwaddr addr,
-                      hwaddr pte, hwaddr mask)
+static void format_pte(GString *buf, CPUArchState *env, hwaddr addr,
+                       hwaddr pte, hwaddr mask)
 {
     addr = addr_canonical(env, addr);
 
-    monitor_printf(mon, TARGET_FMT_plx ": " TARGET_FMT_plx
-                   " %c%c%c%c%c%c%c%c%c\n",
-                   addr,
-                   pte & mask,
-                   pte & PG_NX_MASK ? 'X' : '-',
-                   pte & PG_GLOBAL_MASK ? 'G' : '-',
-                   pte & PG_PSE_MASK ? 'P' : '-',
-                   pte & PG_DIRTY_MASK ? 'D' : '-',
-                   pte & PG_ACCESSED_MASK ? 'A' : '-',
-                   pte & PG_PCD_MASK ? 'C' : '-',
-                   pte & PG_PWT_MASK ? 'T' : '-',
-                   pte & PG_USER_MASK ? 'U' : '-',
-                   pte & PG_RW_MASK ? 'W' : '-');
+    g_string_append_printf(buf, TARGET_FMT_plx ": " TARGET_FMT_plx
+                           " %c%c%c%c%c%c%c%c%c\n",
+                           addr,
+                           pte & mask,
+                           pte & PG_NX_MASK ? 'X' : '-',
+                           pte & PG_GLOBAL_MASK ? 'G' : '-',
+                           pte & PG_PSE_MASK ? 'P' : '-',
+                           pte & PG_DIRTY_MASK ? 'D' : '-',
+                           pte & PG_ACCESSED_MASK ? 'A' : '-',
+                           pte & PG_PCD_MASK ? 'C' : '-',
+                           pte & PG_PWT_MASK ? 'T' : '-',
+                           pte & PG_USER_MASK ? 'U' : '-',
+                           pte & PG_RW_MASK ? 'W' : '-');
 }
 
-static void tlb_info_32(Monitor *mon, CPUArchState *env)
+static void tlb_info_32(GString *buf, CPUArchState *env)
 {
     unsigned int l1, l2;
     uint32_t pgd, pde, pte;
@@ -86,15 +86,15 @@ static void tlb_info_32(Monitor *mon, CPUArchState *env)
         if (pde & PG_PRESENT_MASK) {
             if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
                 /* 4M pages */
-                print_pte(mon, env, (l1 << 22), pde, ~((1 << 21) - 1));
+                format_pte(buf, env, (l1 << 22), pde, ~((1 << 21) - 1));
             } else {
                 for(l2 = 0; l2 < 1024; l2++) {
                     cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
                     pte = le32_to_cpu(pte);
                     if (pte & PG_PRESENT_MASK) {
-                        print_pte(mon, env, (l1 << 22) + (l2 << 12),
-                                  pte & ~PG_PSE_MASK,
-                                  ~0xfff);
+                        format_pte(buf, env, (l1 << 22) + (l2 << 12),
+                                   pte & ~PG_PSE_MASK,
+                                   ~0xfff);
                     }
                 }
             }
@@ -102,7 +102,7 @@ static void tlb_info_32(Monitor *mon, CPUArchState *env)
     }
 }
 
-static void tlb_info_pae32(Monitor *mon, CPUArchState *env)
+static void tlb_info_pae32(GString *buf, CPUArchState *env)
 {
     unsigned int l1, l2, l3;
     uint64_t pdpe, pde, pte;
@@ -120,18 +120,18 @@ static void tlb_info_pae32(Monitor *mon, CPUArchState *env)
                 if (pde & PG_PRESENT_MASK) {
                     if (pde & PG_PSE_MASK) {
                         /* 2M pages with PAE, CR4.PSE is ignored */
-                        print_pte(mon, env, (l1 << 30) + (l2 << 21), pde,
-                                  ~((hwaddr)(1 << 20) - 1));
+                        format_pte(buf, env, (l1 << 30) + (l2 << 21), pde,
+                                   ~((hwaddr)(1 << 20) - 1));
                     } else {
                         pt_addr = pde & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
                             cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8);
                             pte = le64_to_cpu(pte);
                             if (pte & PG_PRESENT_MASK) {
-                                print_pte(mon, env, (l1 << 30) + (l2 << 21)
-                                          + (l3 << 12),
-                                          pte & ~PG_PSE_MASK,
-                                          ~(hwaddr)0xfff);
+                                format_pte(buf, env, (l1 << 30) + (l2 << 21)
+                                           + (l3 << 12),
+                                           pte & ~PG_PSE_MASK,
+                                           ~(hwaddr)0xfff);
                             }
                         }
                     }
@@ -142,7 +142,7 @@ static void tlb_info_pae32(Monitor *mon, CPUArchState *env)
 }
 
 #ifdef TARGET_X86_64
-static void tlb_info_la48(Monitor *mon, CPUArchState *env,
+static void tlb_info_la48(GString *buf, CPUArchState *env,
         uint64_t l0, uint64_t pml4_addr)
 {
     uint64_t l1, l2, l3, l4;
@@ -166,8 +166,8 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env,
 
             if (pdpe & PG_PSE_MASK) {
                 /* 1G pages, CR4.PSE is ignored */
-                print_pte(mon, env, (l0 << 48) + (l1 << 39) + (l2 << 30),
-                        pdpe, 0x3ffffc0000000ULL);
+                format_pte(buf, env, (l0 << 48) + (l1 << 39) + (l2 << 30),
+                           pdpe, 0x3ffffc0000000ULL);
                 continue;
             }
 
@@ -181,8 +181,8 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env,
 
                 if (pde & PG_PSE_MASK) {
                     /* 2M pages, CR4.PSE is ignored */
-                    print_pte(mon, env, (l0 << 48) + (l1 << 39) + (l2 << 30) +
-                            (l3 << 21), pde, 0x3ffffffe00000ULL);
+                    format_pte(buf, env, (l0 << 48) + (l1 << 39) + (l2 << 30) +
+                               (l3 << 21), pde, 0x3ffffffe00000ULL);
                     continue;
                 }
 
@@ -193,9 +193,9 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env,
                             &pte, 8);
                     pte = le64_to_cpu(pte);
                     if (pte & PG_PRESENT_MASK) {
-                        print_pte(mon, env, (l0 << 48) + (l1 << 39) +
-                                (l2 << 30) + (l3 << 21) + (l4 << 12),
-                                pte & ~PG_PSE_MASK, 0x3fffffffff000ULL);
+                        format_pte(buf, env, (l0 << 48) + (l1 << 39) +
+                                   (l2 << 30) + (l3 << 21) + (l4 << 12),
+                                   pte & ~PG_PSE_MASK, 0x3fffffffff000ULL);
                     }
                 }
             }
@@ -203,7 +203,7 @@ static void tlb_info_la48(Monitor *mon, CPUArchState *env,
     }
 }
 
-static void tlb_info_la57(Monitor *mon, CPUArchState *env)
+static void tlb_info_la57(GString *buf, CPUArchState *env)
 {
     uint64_t l0;
     uint64_t pml5e;
@@ -214,44 +214,55 @@ static void tlb_info_la57(Monitor *mon, CPUArchState *env)
         cpu_physical_memory_read(pml5_addr + l0 * 8, &pml5e, 8);
         pml5e = le64_to_cpu(pml5e);
         if (pml5e & PG_PRESENT_MASK) {
-            tlb_info_la48(mon, env, l0, pml5e & 0x3fffffffff000ULL);
+            tlb_info_la48(buf, env, l0, pml5e & 0x3fffffffff000ULL);
         }
     }
 }
 #endif /* TARGET_X86_64 */
 
-void hmp_info_tlb(Monitor *mon, const QDict *qdict)
+void x86_cpu_format_tlb(CPUState *cpu, GString *buf)
 {
     CPUArchState *env;
 
-    env = mon_get_cpu_env(mon);
-    if (!env) {
-        monitor_printf(mon, "No CPU available\n");
-        return;
-    }
+    env = cpu->env_ptr;
 
     if (!(env->cr[0] & CR0_PG_MASK)) {
-        monitor_printf(mon, "PG disabled\n");
+        g_string_append_printf(buf, "PG disabled\n");
         return;
     }
     if (env->cr[4] & CR4_PAE_MASK) {
 #ifdef TARGET_X86_64
         if (env->hflags & HF_LMA_MASK) {
             if (env->cr[4] & CR4_LA57_MASK) {
-                tlb_info_la57(mon, env);
+                tlb_info_la57(buf, env);
             } else {
-                tlb_info_la48(mon, env, 0, env->cr[3] & 0x3fffffffff000ULL);
+                tlb_info_la48(buf, env, 0, env->cr[3] & 0x3fffffffff000ULL);
             }
         } else
 #endif
         {
-            tlb_info_pae32(mon, env);
+            tlb_info_pae32(buf, env);
         }
     } else {
-        tlb_info_32(mon, env);
+        tlb_info_32(buf, 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);
+}
+
 static void mem_print(Monitor *mon, CPUArchState *env,
                       hwaddr *pstart, int *plast_prot,
                       hwaddr end, int prot)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 44/53] target/m68k: convert to use format_tlb callback
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 4ccf572a68..8f143eb540 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -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;
diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index b0641f6d0d..f2d777a1ba 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -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
diff --git a/target/m68k/helper.c b/target/m68k/helper.c
index 137a3e1a3d..050a27d21c 100644
--- a/target/m68k/helper.c
+++ b/target/m68k/helper.c
@@ -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,
diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c
index 2bdf6acae0..003a665246 100644
--- a/target/m68k/monitor.c
+++ b/target/m68k/monitor.c
@@ -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[] = {
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 44/53] target/m68k: convert to use format_tlb callback
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 4ccf572a68..8f143eb540 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -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;
diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index b0641f6d0d..f2d777a1ba 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -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
diff --git a/target/m68k/helper.c b/target/m68k/helper.c
index 137a3e1a3d..050a27d21c 100644
--- a/target/m68k/helper.c
+++ b/target/m68k/helper.c
@@ -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,
diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c
index 2bdf6acae0..003a665246 100644
--- a/target/m68k/monitor.c
+++ b/target/m68k/monitor.c
@@ -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[] = {
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 45/53] target/nios2: convert to use format_tlb callback
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
index cbf15fb1c9..60162ee692 100644
--- a/target/nios2/cpu.c
+++ b/target/nios2/cpu.c
@@ -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
diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
index 3b16cd1f3c..1167872bd9 100644
--- a/target/nios2/cpu.h
+++ b/target/nios2/cpu.h
@@ -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,
diff --git a/target/nios2/mmu.c b/target/nios2/mmu.c
index 2545c06761..1c7d3b34c3 100644
--- a/target/nios2/mmu.c
+++ b/target/nios2/mmu.c
@@ -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' : '-');
     }
 }
 
diff --git a/target/nios2/monitor.c b/target/nios2/monitor.c
index 0152dec3fa..99d35e8ef1 100644
--- a/target/nios2/monitor.c
+++ b/target/nios2/monitor.c
@@ -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);
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 45/53] target/nios2: convert to use format_tlb callback
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
index cbf15fb1c9..60162ee692 100644
--- a/target/nios2/cpu.c
+++ b/target/nios2/cpu.c
@@ -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
diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
index 3b16cd1f3c..1167872bd9 100644
--- a/target/nios2/cpu.h
+++ b/target/nios2/cpu.h
@@ -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,
diff --git a/target/nios2/mmu.c b/target/nios2/mmu.c
index 2545c06761..1c7d3b34c3 100644
--- a/target/nios2/mmu.c
+++ b/target/nios2/mmu.c
@@ -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' : '-');
     }
 }
 
diff --git a/target/nios2/monitor.c b/target/nios2/monitor.c
index 0152dec3fa..99d35e8ef1 100644
--- a/target/nios2/monitor.c
+++ b/target/nios2/monitor.c
@@ -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);
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 46/53] target/ppc: convert to use format_tlb callback
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index c84ae29b98..37b44bfbc3 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -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);
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 3456be465c..98d6f40a49 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -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;
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 19832c4b46..73927a0819 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -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);
     }
 }
 
diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h
index c5b2f97ff7..99e03a5849 100644
--- a/target/ppc/mmu-hash64.h
+++ b/target/ppc/mmu-hash64.h
@@ -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,
diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
index 754509e556..d7b716f30a 100644
--- a/target/ppc/mmu_common.c
+++ b/target/ppc/mmu_common.c
@@ -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);
     }
 }
 
diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c
index a475108b2d..401a36c2eb 100644
--- a/target/ppc/monitor.c
+++ b/target/ppc/monitor.c
@@ -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[] = {
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 46/53] target/ppc: convert to use format_tlb callback
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index c84ae29b98..37b44bfbc3 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -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);
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 3456be465c..98d6f40a49 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -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;
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 19832c4b46..73927a0819 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -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);
     }
 }
 
diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h
index c5b2f97ff7..99e03a5849 100644
--- a/target/ppc/mmu-hash64.h
+++ b/target/ppc/mmu-hash64.h
@@ -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,
diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
index 754509e556..d7b716f30a 100644
--- a/target/ppc/mmu_common.c
+++ b/target/ppc/mmu_common.c
@@ -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);
     }
 }
 
diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c
index a475108b2d..401a36c2eb 100644
--- a/target/ppc/monitor.c
+++ b/target/ppc/monitor.c
@@ -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[] = {
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 47/53] target/sh4: convert to use format_tlb callback
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/sh4/cpu.c     |  3 +++
 target/sh4/cpu.h     |  1 +
 target/sh4/monitor.c | 48 +++++++++++++++++++++++++++-----------------
 3 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 0ac881d6af..0e49755b2a 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -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;
diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
index 6940ca417a..7c139f561c 100644
--- a/target/sh4/cpu.h
+++ b/target/sh4/cpu.h
@@ -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);
diff --git a/target/sh4/monitor.c b/target/sh4/monitor.c
index 2da6a5426e..5ccb95af93 100644
--- a/target/sh4/monitor.c
+++ b/target/sh4/monitor.c
@@ -27,32 +27,44 @@
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
-static void print_tlb(Monitor *mon, int idx, tlb_t *tlb)
+static void print_tlb(GString *buf, int idx, tlb_t *tlb)
 {
-    monitor_printf(mon, " tlb%i:\t"
-                   "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
-                   "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
-                   "dirty=%hhu writethrough=%hhu\n",
-                   idx,
-                   tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size,
-                   tlb->v, tlb->sh, tlb->c, tlb->pr,
-                   tlb->d, tlb->wt);
+    g_string_append_printf(buf,  " tlb%i:\t"
+                           "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
+                           "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
+                           "dirty=%hhu writethrough=%hhu\n",
+                           idx,
+                           tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size,
+                           tlb->v, tlb->sh, tlb->c, tlb->pr,
+                           tlb->d, tlb->wt);
+}
+
+void superh_cpu_format_tlb(CPUState *cpu, GString *buf)
+{
+    CPUArchState *env = cpu->env_ptr;
+    size_t i;
+
+    g_string_append_printf(buf,  "ITLB:\n");
+    for (i = 0 ; i < ITLB_SIZE ; i++) {
+        print_tlb(buf, i, &env->itlb[i]);
+    }
+    g_string_append_printf(buf,  "UTLB:\n");
+    for (i = 0 ; i < UTLB_SIZE ; i++) {
+        print_tlb(buf, i, &env->utlb[i]);
+    }
 }
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env = mon_get_cpu_env(mon);
-    int i;
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env) {
+    if (!cpu) {
         monitor_printf(mon, "No CPU available\n");
         return;
     }
 
-    monitor_printf (mon, "ITLB:\n");
-    for (i = 0 ; i < ITLB_SIZE ; i++)
-        print_tlb (mon, i, &env->itlb[i]);
-    monitor_printf (mon, "UTLB:\n");
-    for (i = 0 ; i < UTLB_SIZE ; i++)
-        print_tlb (mon, i, &env->utlb[i]);
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 47/53] target/sh4: convert to use format_tlb callback
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/sh4/cpu.c     |  3 +++
 target/sh4/cpu.h     |  1 +
 target/sh4/monitor.c | 48 +++++++++++++++++++++++++++-----------------
 3 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 0ac881d6af..0e49755b2a 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -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;
diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
index 6940ca417a..7c139f561c 100644
--- a/target/sh4/cpu.h
+++ b/target/sh4/cpu.h
@@ -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);
diff --git a/target/sh4/monitor.c b/target/sh4/monitor.c
index 2da6a5426e..5ccb95af93 100644
--- a/target/sh4/monitor.c
+++ b/target/sh4/monitor.c
@@ -27,32 +27,44 @@
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
-static void print_tlb(Monitor *mon, int idx, tlb_t *tlb)
+static void print_tlb(GString *buf, int idx, tlb_t *tlb)
 {
-    monitor_printf(mon, " tlb%i:\t"
-                   "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
-                   "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
-                   "dirty=%hhu writethrough=%hhu\n",
-                   idx,
-                   tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size,
-                   tlb->v, tlb->sh, tlb->c, tlb->pr,
-                   tlb->d, tlb->wt);
+    g_string_append_printf(buf,  " tlb%i:\t"
+                           "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
+                           "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
+                           "dirty=%hhu writethrough=%hhu\n",
+                           idx,
+                           tlb->asid, tlb->vpn, tlb->ppn, tlb->sz, tlb->size,
+                           tlb->v, tlb->sh, tlb->c, tlb->pr,
+                           tlb->d, tlb->wt);
+}
+
+void superh_cpu_format_tlb(CPUState *cpu, GString *buf)
+{
+    CPUArchState *env = cpu->env_ptr;
+    size_t i;
+
+    g_string_append_printf(buf,  "ITLB:\n");
+    for (i = 0 ; i < ITLB_SIZE ; i++) {
+        print_tlb(buf, i, &env->itlb[i]);
+    }
+    g_string_append_printf(buf,  "UTLB:\n");
+    for (i = 0 ; i < UTLB_SIZE ; i++) {
+        print_tlb(buf, i, &env->utlb[i]);
+    }
 }
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 {
-    CPUArchState *env = mon_get_cpu_env(mon);
-    int i;
+    g_autoptr(GString) buf = g_string_new("");
+    CPUState *cpu = mon_get_cpu(mon);
 
-    if (!env) {
+    if (!cpu) {
         monitor_printf(mon, "No CPU available\n");
         return;
     }
 
-    monitor_printf (mon, "ITLB:\n");
-    for (i = 0 ; i < ITLB_SIZE ; i++)
-        print_tlb (mon, i, &env->itlb[i]);
-    monitor_printf (mon, "UTLB:\n");
-    for (i = 0 ; i < UTLB_SIZE ; i++)
-        print_tlb (mon, i, &env->utlb[i]);
+    cpu_format_tlb(cpu, buf);
+
+    monitor_printf(mon, "%s", buf->str);
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 48/53] target/sparc: convert to use format_tlb callback
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 9346a79239..f78ddc72b5 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -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;
diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index 65a01a7884..233f0b3eb7 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -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);
diff --git a/target/sparc/mmu_helper.c b/target/sparc/mmu_helper.c
index a44473a1c7..06b16aca6a 100644
--- a/target/sparc/mmu_helper.c
+++ b/target/sparc/mmu_helper.c
@@ -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.
diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c
index 318413686a..cc7fe74e3e 100644
--- a/target/sparc/monitor.c
+++ b/target/sparc/monitor.c
@@ -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
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 48/53] target/sparc: convert to use format_tlb callback
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 9346a79239..f78ddc72b5 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -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;
diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index 65a01a7884..233f0b3eb7 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -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);
diff --git a/target/sparc/mmu_helper.c b/target/sparc/mmu_helper.c
index a44473a1c7..06b16aca6a 100644
--- a/target/sparc/mmu_helper.c
+++ b/target/sparc/mmu_helper.c
@@ -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.
diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c
index 318413686a..cc7fe74e3e 100644
--- a/target/sparc/monitor.c
+++ b/target/sparc/monitor.c
@@ -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
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 49/53] target/xtensa: convert to use format_tlb callback
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/xtensa/cpu.h        |   2 +-
 target/xtensa/mmu_helper.c | 126 +++++++++++++++++++++----------------
 target/xtensa/monitor.c    |  10 ++-
 3 files changed, 79 insertions(+), 59 deletions(-)

diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
index 97cd6892df..8c82994826 100644
--- a/target/xtensa/cpu.h
+++ b/target/xtensa/cpu.h
@@ -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)
 {
diff --git a/target/xtensa/mmu_helper.c b/target/xtensa/mmu_helper.c
index b01ff9399a..d499255984 100644
--- a/target/xtensa/mmu_helper.c
+++ b/target/xtensa/mmu_helper.c
@@ -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) {
                     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");
                 }
-                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)
 {
     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",
+                           env ? "En" : "  ",
+                           env ? "--" : "  ");
 
     for (i = 0; i < n; ++i) {
         uint32_t attr = entry[i].attr;
@@ -1130,63 +1136,73 @@ static void dump_mpu(CPUXtensaState *env,
         unsigned type = mpu_attr_to_type(attr);
         char cpu_cache = (type & XTENSA_MPU_TYPE_CPU_CACHE) ? '-' : ' ';
 
-        qemu_printf("\t %c  0x%08x  0x%08x   %c%c%c    %c%c%c   ",
-                    env ?
-                    ((env->sregs[MPUENB] & (1u << i)) ? '+' : '-') : ' ',
-                    entry[i].vaddr, attr,
-                    (access0 & PAGE_READ) ? 'R' : '-',
-                    (access0 & PAGE_WRITE) ? 'W' : '-',
-                    (access0 & PAGE_EXEC) ? 'X' : '-',
-                    (access1 & PAGE_READ) ? 'R' : '-',
-                    (access1 & PAGE_WRITE) ? 'W' : '-',
-                    (access1 & PAGE_EXEC) ? 'X' : '-');
+        g_string_append_printf(buf, "\t %c  0x%08x  0x%08x   "
+                               "%c%c%c    %c%c%c   ",
+                               env ? ((env->sregs[MPUENB] & (1u << i)) ?
+                                      '+' : '-') : ' ',
+                               entry[i].vaddr, attr,
+                               (access0 & PAGE_READ) ? 'R' : '-',
+                               (access0 & PAGE_WRITE) ? 'W' : '-',
+                               (access0 & PAGE_EXEC) ? 'X' : '-',
+                               (access1 & PAGE_READ) ? 'R' : '-',
+                               (access1 & PAGE_WRITE) ? 'W' : '-',
+                               (access1 & PAGE_EXEC) ? 'X' : '-');
 
         switch (type & XTENSA_MPU_SYSTEM_TYPE_MASK) {
         case XTENSA_MPU_SYSTEM_TYPE_DEVICE:
-            qemu_printf("Device %cB %3s\n",
-                        (type & XTENSA_MPU_TYPE_B) ? ' ' : 'n',
-                        (type & XTENSA_MPU_TYPE_INT) ? "int" : "");
+            g_string_append_printf(buf, "Device %cB %3s\n",
+                                   (type & XTENSA_MPU_TYPE_B) ? ' ' : 'n',
+                                   (type & XTENSA_MPU_TYPE_INT) ? "int" : "");
             break;
         case XTENSA_MPU_SYSTEM_TYPE_NC:
-            qemu_printf("Sys NC %cB      %c%c%c\n",
-                        (type & XTENSA_MPU_TYPE_B) ? ' ' : 'n',
-                        (type & XTENSA_MPU_TYPE_CPU_R) ? 'r' : cpu_cache,
-                        (type & XTENSA_MPU_TYPE_CPU_W) ? 'w' : cpu_cache,
-                        (type & XTENSA_MPU_TYPE_CPU_C) ? 'c' : cpu_cache);
+            g_string_append_printf(buf, "Sys NC %cB      %c%c%c\n",
+                                   (type & XTENSA_MPU_TYPE_B) ? ' ' : 'n',
+                                   (type & XTENSA_MPU_TYPE_CPU_R) ?
+                                   'r' : cpu_cache,
+                                   (type & XTENSA_MPU_TYPE_CPU_W) ?
+                                   'w' : cpu_cache,
+                                   (type & XTENSA_MPU_TYPE_CPU_C) ?
+                                   'c' : cpu_cache);
             break;
         case XTENSA_MPU_SYSTEM_TYPE_C:
-            qemu_printf("Sys  C %c%c%c     %c%c%c\n",
-                        (type & XTENSA_MPU_TYPE_SYS_R) ? 'R' : '-',
-                        (type & XTENSA_MPU_TYPE_SYS_W) ? 'W' : '-',
-                        (type & XTENSA_MPU_TYPE_SYS_C) ? 'C' : '-',
-                        (type & XTENSA_MPU_TYPE_CPU_R) ? 'r' : cpu_cache,
-                        (type & XTENSA_MPU_TYPE_CPU_W) ? 'w' : cpu_cache,
-                        (type & XTENSA_MPU_TYPE_CPU_C) ? 'c' : cpu_cache);
+            g_string_append_printf(buf, "Sys  C %c%c%c     %c%c%c\n",
+                                   (type & XTENSA_MPU_TYPE_SYS_R) ? 'R' : '-',
+                                   (type & XTENSA_MPU_TYPE_SYS_W) ? 'W' : '-',
+                                   (type & XTENSA_MPU_TYPE_SYS_C) ? 'C' : '-',
+                                   (type & XTENSA_MPU_TYPE_CPU_R) ?
+                                   'r' : cpu_cache,
+                                   (type & XTENSA_MPU_TYPE_CPU_W) ?
+                                   'w' : cpu_cache,
+                                   (type & XTENSA_MPU_TYPE_CPU_C) ?
+                                   'c' : cpu_cache);
             break;
         default:
-            qemu_printf("Unknown\n");
+            g_string_append_printf(buf, "Unknown\n");
             break;
         }
     }
 }
 
-void dump_mmu(CPUXtensaState *env)
+void xtensa_cpu_format_tlb(CPUState *cpu, GString *buf)
 {
+    CPUXtensaState *env = cpu->env_ptr;
+
     if (xtensa_option_bits_enabled(env->config,
                 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION) |
                 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION) |
                 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU))) {
 
-        qemu_printf("ITLB:\n");
-        dump_tlb(env, false);
-        qemu_printf("\nDTLB:\n");
-        dump_tlb(env, true);
+        g_string_append_printf(buf, "ITLB:\n");
+        dump_tlb(env, false, buf);
+        g_string_append_printf(buf, "\nDTLB:\n");
+        dump_tlb(env, true, buf);
     } else if (xtensa_option_enabled(env->config, XTENSA_OPTION_MPU)) {
-        qemu_printf("Foreground map:\n");
-        dump_mpu(env, env->mpu_fg, env->config->n_mpu_fg_segments);
-        qemu_printf("\nBackground map:\n");
-        dump_mpu(NULL, env->config->mpu_bg, env->config->n_mpu_bg_segments);
+        g_string_append_printf(buf, "Foreground map:\n");
+        dump_mpu(env, env->mpu_fg, env->config->n_mpu_fg_segments, buf);
+        g_string_append_printf(buf, "\nBackground map:\n");
+        dump_mpu(NULL, env->config->mpu_bg,
+                 env->config->n_mpu_bg_segments, buf);
     } else {
-        qemu_printf("No TLB for this CPU core\n");
+        g_string_append_printf(buf, "No TLB for this CPU core\n");
     }
 }
diff --git a/target/xtensa/monitor.c b/target/xtensa/monitor.c
index fbf60d5553..99d35e8ef1 100644
--- a/target/xtensa/monitor.c
+++ b/target/xtensa/monitor.c
@@ -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);
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 49/53] target/xtensa: convert to use format_tlb callback
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	Daniel P. Berrangé

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

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 target/xtensa/cpu.h        |   2 +-
 target/xtensa/mmu_helper.c | 126 +++++++++++++++++++++----------------
 target/xtensa/monitor.c    |  10 ++-
 3 files changed, 79 insertions(+), 59 deletions(-)

diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
index 97cd6892df..8c82994826 100644
--- a/target/xtensa/cpu.h
+++ b/target/xtensa/cpu.h
@@ -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)
 {
diff --git a/target/xtensa/mmu_helper.c b/target/xtensa/mmu_helper.c
index b01ff9399a..d499255984 100644
--- a/target/xtensa/mmu_helper.c
+++ b/target/xtensa/mmu_helper.c
@@ -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) {
                     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");
                 }
-                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)
 {
     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",
+                           env ? "En" : "  ",
+                           env ? "--" : "  ");
 
     for (i = 0; i < n; ++i) {
         uint32_t attr = entry[i].attr;
@@ -1130,63 +1136,73 @@ static void dump_mpu(CPUXtensaState *env,
         unsigned type = mpu_attr_to_type(attr);
         char cpu_cache = (type & XTENSA_MPU_TYPE_CPU_CACHE) ? '-' : ' ';
 
-        qemu_printf("\t %c  0x%08x  0x%08x   %c%c%c    %c%c%c   ",
-                    env ?
-                    ((env->sregs[MPUENB] & (1u << i)) ? '+' : '-') : ' ',
-                    entry[i].vaddr, attr,
-                    (access0 & PAGE_READ) ? 'R' : '-',
-                    (access0 & PAGE_WRITE) ? 'W' : '-',
-                    (access0 & PAGE_EXEC) ? 'X' : '-',
-                    (access1 & PAGE_READ) ? 'R' : '-',
-                    (access1 & PAGE_WRITE) ? 'W' : '-',
-                    (access1 & PAGE_EXEC) ? 'X' : '-');
+        g_string_append_printf(buf, "\t %c  0x%08x  0x%08x   "
+                               "%c%c%c    %c%c%c   ",
+                               env ? ((env->sregs[MPUENB] & (1u << i)) ?
+                                      '+' : '-') : ' ',
+                               entry[i].vaddr, attr,
+                               (access0 & PAGE_READ) ? 'R' : '-',
+                               (access0 & PAGE_WRITE) ? 'W' : '-',
+                               (access0 & PAGE_EXEC) ? 'X' : '-',
+                               (access1 & PAGE_READ) ? 'R' : '-',
+                               (access1 & PAGE_WRITE) ? 'W' : '-',
+                               (access1 & PAGE_EXEC) ? 'X' : '-');
 
         switch (type & XTENSA_MPU_SYSTEM_TYPE_MASK) {
         case XTENSA_MPU_SYSTEM_TYPE_DEVICE:
-            qemu_printf("Device %cB %3s\n",
-                        (type & XTENSA_MPU_TYPE_B) ? ' ' : 'n',
-                        (type & XTENSA_MPU_TYPE_INT) ? "int" : "");
+            g_string_append_printf(buf, "Device %cB %3s\n",
+                                   (type & XTENSA_MPU_TYPE_B) ? ' ' : 'n',
+                                   (type & XTENSA_MPU_TYPE_INT) ? "int" : "");
             break;
         case XTENSA_MPU_SYSTEM_TYPE_NC:
-            qemu_printf("Sys NC %cB      %c%c%c\n",
-                        (type & XTENSA_MPU_TYPE_B) ? ' ' : 'n',
-                        (type & XTENSA_MPU_TYPE_CPU_R) ? 'r' : cpu_cache,
-                        (type & XTENSA_MPU_TYPE_CPU_W) ? 'w' : cpu_cache,
-                        (type & XTENSA_MPU_TYPE_CPU_C) ? 'c' : cpu_cache);
+            g_string_append_printf(buf, "Sys NC %cB      %c%c%c\n",
+                                   (type & XTENSA_MPU_TYPE_B) ? ' ' : 'n',
+                                   (type & XTENSA_MPU_TYPE_CPU_R) ?
+                                   'r' : cpu_cache,
+                                   (type & XTENSA_MPU_TYPE_CPU_W) ?
+                                   'w' : cpu_cache,
+                                   (type & XTENSA_MPU_TYPE_CPU_C) ?
+                                   'c' : cpu_cache);
             break;
         case XTENSA_MPU_SYSTEM_TYPE_C:
-            qemu_printf("Sys  C %c%c%c     %c%c%c\n",
-                        (type & XTENSA_MPU_TYPE_SYS_R) ? 'R' : '-',
-                        (type & XTENSA_MPU_TYPE_SYS_W) ? 'W' : '-',
-                        (type & XTENSA_MPU_TYPE_SYS_C) ? 'C' : '-',
-                        (type & XTENSA_MPU_TYPE_CPU_R) ? 'r' : cpu_cache,
-                        (type & XTENSA_MPU_TYPE_CPU_W) ? 'w' : cpu_cache,
-                        (type & XTENSA_MPU_TYPE_CPU_C) ? 'c' : cpu_cache);
+            g_string_append_printf(buf, "Sys  C %c%c%c     %c%c%c\n",
+                                   (type & XTENSA_MPU_TYPE_SYS_R) ? 'R' : '-',
+                                   (type & XTENSA_MPU_TYPE_SYS_W) ? 'W' : '-',
+                                   (type & XTENSA_MPU_TYPE_SYS_C) ? 'C' : '-',
+                                   (type & XTENSA_MPU_TYPE_CPU_R) ?
+                                   'r' : cpu_cache,
+                                   (type & XTENSA_MPU_TYPE_CPU_W) ?
+                                   'w' : cpu_cache,
+                                   (type & XTENSA_MPU_TYPE_CPU_C) ?
+                                   'c' : cpu_cache);
             break;
         default:
-            qemu_printf("Unknown\n");
+            g_string_append_printf(buf, "Unknown\n");
             break;
         }
     }
 }
 
-void dump_mmu(CPUXtensaState *env)
+void xtensa_cpu_format_tlb(CPUState *cpu, GString *buf)
 {
+    CPUXtensaState *env = cpu->env_ptr;
+
     if (xtensa_option_bits_enabled(env->config,
                 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION) |
                 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION) |
                 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU))) {
 
-        qemu_printf("ITLB:\n");
-        dump_tlb(env, false);
-        qemu_printf("\nDTLB:\n");
-        dump_tlb(env, true);
+        g_string_append_printf(buf, "ITLB:\n");
+        dump_tlb(env, false, buf);
+        g_string_append_printf(buf, "\nDTLB:\n");
+        dump_tlb(env, true, buf);
     } else if (xtensa_option_enabled(env->config, XTENSA_OPTION_MPU)) {
-        qemu_printf("Foreground map:\n");
-        dump_mpu(env, env->mpu_fg, env->config->n_mpu_fg_segments);
-        qemu_printf("\nBackground map:\n");
-        dump_mpu(NULL, env->config->mpu_bg, env->config->n_mpu_bg_segments);
+        g_string_append_printf(buf, "Foreground map:\n");
+        dump_mpu(env, env->mpu_fg, env->config->n_mpu_fg_segments, buf);
+        g_string_append_printf(buf, "\nBackground map:\n");
+        dump_mpu(NULL, env->config->mpu_bg,
+                 env->config->n_mpu_bg_segments, buf);
     } else {
-        qemu_printf("No TLB for this CPU core\n");
+        g_string_append_printf(buf, "No TLB for this CPU core\n");
     }
 }
diff --git a/target/xtensa/monitor.c b/target/xtensa/monitor.c
index fbf60d5553..99d35e8ef1 100644
--- a/target/xtensa/monitor.c
+++ b/target/xtensa/monitor.c
@@ -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);
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 50/53] monitor: merge duplicate "info tlb" handlers
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index f8312342cd..7bd1e04d46 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -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``
diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h
index df79ad3355..04e02e8895 100644
--- a/include/monitor/hmp-target.h
+++ b/include/monitor/hmp-target.h
@@ -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);
 
diff --git a/monitor/misc.c b/monitor/misc.c
index 6b07efdddd..c7d138914d 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -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;
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index 698fbbc80b..a7eb4205c7 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -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)
diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c
index 003a665246..0dc729692b 100644
--- a/target/m68k/monitor.c
+++ b/target/m68k/monitor.c
@@ -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]) },
diff --git a/target/nios2/monitor.c b/target/nios2/monitor.c
index 99d35e8ef1..1180a32f80 100644
--- a/target/nios2/monitor.c
+++ b/target/nios2/monitor.c
@@ -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);
-}
diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c
index 401a36c2eb..3564fd5f45 100644
--- a/target/ppc/monitor.c
+++ b/target/ppc/monitor.c
@@ -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 */
diff --git a/target/sh4/monitor.c b/target/sh4/monitor.c
index 5ccb95af93..d641d95316 100644
--- a/target/sh4/monitor.c
+++ b/target/sh4/monitor.c
@@ -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);
-}
diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c
index cc7fe74e3e..0c51669c08 100644
--- a/target/sparc/monitor.c
+++ b/target/sparc/monitor.c
@@ -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)
diff --git a/target/xtensa/monitor.c b/target/xtensa/monitor.c
index 99d35e8ef1..1180a32f80 100644
--- a/target/xtensa/monitor.c
+++ b/target/xtensa/monitor.c
@@ -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);
-}
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 50/53] monitor: merge duplicate "info tlb" handlers
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index f8312342cd..7bd1e04d46 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -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``
diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h
index df79ad3355..04e02e8895 100644
--- a/include/monitor/hmp-target.h
+++ b/include/monitor/hmp-target.h
@@ -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);
 
diff --git a/monitor/misc.c b/monitor/misc.c
index 6b07efdddd..c7d138914d 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -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;
diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index 698fbbc80b..a7eb4205c7 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -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)
diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c
index 003a665246..0dc729692b 100644
--- a/target/m68k/monitor.c
+++ b/target/m68k/monitor.c
@@ -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]) },
diff --git a/target/nios2/monitor.c b/target/nios2/monitor.c
index 99d35e8ef1..1180a32f80 100644
--- a/target/nios2/monitor.c
+++ b/target/nios2/monitor.c
@@ -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);
-}
diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c
index 401a36c2eb..3564fd5f45 100644
--- a/target/ppc/monitor.c
+++ b/target/ppc/monitor.c
@@ -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 */
diff --git a/target/sh4/monitor.c b/target/sh4/monitor.c
index 5ccb95af93..d641d95316 100644
--- a/target/sh4/monitor.c
+++ b/target/sh4/monitor.c
@@ -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);
-}
diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c
index cc7fe74e3e..0c51669c08 100644
--- a/target/sparc/monitor.c
+++ b/target/sparc/monitor.c
@@ -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)
diff --git a/target/xtensa/monitor.c b/target/xtensa/monitor.c
index 99d35e8ef1..1180a32f80 100644
--- a/target/xtensa/monitor.c
+++ b/target/xtensa/monitor.c
@@ -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);
-}
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 51/53] qapi: introduce x-query-tlb QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/machine-qmp-cmds.c | 22 ++++++++++++++++++++++
 monitor/misc.c             | 15 ++++++++++-----
 qapi/machine.json          | 15 +++++++++++++++
 3 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 4407e967da..c84cef8667 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -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;
diff --git a/monitor/misc.c b/monitor/misc.c
index c7d138914d..7ca529002d 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -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)
diff --git a/qapi/machine.json b/qapi/machine.json
index e72b47ea7d..0f537a58e0 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 51/53] qapi: introduce x-query-tlb QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/machine-qmp-cmds.c | 22 ++++++++++++++++++++++
 monitor/misc.c             | 15 ++++++++++-----
 qapi/machine.json          | 15 +++++++++++++++
 3 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 4407e967da..c84cef8667 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -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;
diff --git a/monitor/misc.c b/monitor/misc.c
index c7d138914d..7ca529002d 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -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)
diff --git a/qapi/machine.json b/qapi/machine.json
index e72b47ea7d..0f537a58e0 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 52/53] qapi: introduce x-query-jit QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index e5c0ccd1a2..6d27fb62f9 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -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 */
diff --git a/accel/tcg/hmp.c b/accel/tcg/hmp.c
index a6e72fdb3e..9d7bcd9185 100644
--- a/accel/tcg/hmp.c
+++ b/accel/tcg/hmp.c
@@ -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)
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index bbfcfb698c..9c3dbe4409 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -2014,7 +2014,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
     cpu_loop_exit_noexc(cpu);
 }
 
-static void print_qht_statistics(struct qht_stats hst)
+static void print_qht_statistics(struct qht_stats hst, GString *buf)
 {
     uint32_t hgram_opts;
     size_t hgram_bins;
@@ -2023,9 +2023,11 @@ static void print_qht_statistics(struct qht_stats hst)
     if (!hst.head_buckets) {
         return;
     }
-    qemu_printf("TB hash buckets     %zu/%zu (%0.2f%% head buckets used)\n",
-                hst.used_head_buckets, hst.head_buckets,
-                (double)hst.used_head_buckets / hst.head_buckets * 100);
+    g_string_append_printf(buf, "TB hash buckets     %zu/%zu "
+                           "(%0.2f%% head buckets used)\n",
+                           hst.used_head_buckets, hst.head_buckets,
+                           (double)hst.used_head_buckets /
+                           hst.head_buckets * 100);
 
     hgram_opts =  QDIST_PR_BORDER | QDIST_PR_LABELS;
     hgram_opts |= QDIST_PR_100X   | QDIST_PR_PERCENT;
@@ -2033,8 +2035,9 @@ static void print_qht_statistics(struct qht_stats hst)
         hgram_opts |= QDIST_PR_NODECIMAL;
     }
     hgram = qdist_pr(&hst.occupancy, 10, hgram_opts);
-    qemu_printf("TB hash occupancy   %0.2f%% avg chain occ. Histogram: %s\n",
-                qdist_avg(&hst.occupancy) * 100, hgram);
+    g_string_append_printf(buf, "TB hash occupancy   %0.2f%% avg chain occ. "
+                           "Histogram: %s\n",
+                           qdist_avg(&hst.occupancy) * 100, hgram);
     g_free(hgram);
 
     hgram_opts = QDIST_PR_BORDER | QDIST_PR_LABELS;
@@ -2046,8 +2049,9 @@ static void print_qht_statistics(struct qht_stats hst)
         hgram_opts |= QDIST_PR_NODECIMAL | QDIST_PR_NOBINRANGE;
     }
     hgram = qdist_pr(&hst.chain, hgram_bins, hgram_opts);
-    qemu_printf("TB hash avg chain   %0.3f buckets. Histogram: %s\n",
-                qdist_avg(&hst.chain), hgram);
+    g_string_append_printf(buf, "TB hash avg chain   %0.3f buckets. "
+                           "Histogram: %s\n",
+                           qdist_avg(&hst.chain), hgram);
     g_free(hgram);
 }
 
@@ -2084,7 +2088,7 @@ static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer data)
     return false;
 }
 
-void dump_exec_info(void)
+void dump_exec_info(GString *buf)
 {
     struct tb_tree_stats tst = {};
     struct qht_stats hst;
@@ -2093,44 +2097,48 @@ void dump_exec_info(void)
     tcg_tb_foreach(tb_tree_stats_iter, &tst);
     nb_tbs = tst.nb_tbs;
     /* XXX: avoid using doubles ? */
-    qemu_printf("Translation buffer state:\n");
+    g_string_append_printf(buf, "Translation buffer state:\n");
     /*
      * Report total code size including the padding and TB structs;
      * otherwise users might think "-accel tcg,tb-size" is not honoured.
      * For avg host size we use the precise numbers from tb_tree_stats though.
      */
-    qemu_printf("gen code size       %zu/%zu\n",
-                tcg_code_size(), tcg_code_capacity());
-    qemu_printf("TB count            %zu\n", nb_tbs);
-    qemu_printf("TB avg target size  %zu max=%zu bytes\n",
-                nb_tbs ? tst.target_size / nb_tbs : 0,
-                tst.max_target_size);
-    qemu_printf("TB avg host size    %zu bytes (expansion ratio: %0.1f)\n",
-                nb_tbs ? tst.host_size / nb_tbs : 0,
-                tst.target_size ? (double)tst.host_size / tst.target_size : 0);
-    qemu_printf("cross page TB count %zu (%zu%%)\n", tst.cross_page,
-                nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0);
-    qemu_printf("direct jump count   %zu (%zu%%) (2 jumps=%zu %zu%%)\n",
-                tst.direct_jmp_count,
-                nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0,
-                tst.direct_jmp2_count,
-                nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0);
+    g_string_append_printf(buf, "gen code size       %zu/%zu\n",
+                           tcg_code_size(), tcg_code_capacity());
+    g_string_append_printf(buf, "TB count            %zu\n", nb_tbs);
+    g_string_append_printf(buf, "TB avg target size  %zu max=%zu bytes\n",
+                           nb_tbs ? tst.target_size / nb_tbs : 0,
+                           tst.max_target_size);
+    g_string_append_printf(buf, "TB avg host size    %zu bytes "
+                           "(expansion ratio: %0.1f)\n",
+                           nb_tbs ? tst.host_size / nb_tbs : 0,
+                           tst.target_size ?
+                           (double)tst.host_size / tst.target_size : 0);
+    g_string_append_printf(buf, "cross page TB count %zu (%zu%%)\n",
+                           tst.cross_page,
+                           nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0);
+    g_string_append_printf(buf, "direct jump count   %zu (%zu%%) "
+                           "(2 jumps=%zu %zu%%)\n",
+                           tst.direct_jmp_count,
+                           nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0,
+                           tst.direct_jmp2_count,
+                           nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0);
 
     qht_statistics_init(&tb_ctx.htable, &hst);
-    print_qht_statistics(hst);
+    print_qht_statistics(hst, buf);
     qht_statistics_destroy(&hst);
 
-    qemu_printf("\nStatistics:\n");
-    qemu_printf("TB flush count      %u\n",
-                qatomic_read(&tb_ctx.tb_flush_count));
-    qemu_printf("TB invalidate count %u\n",
-                qatomic_read(&tb_ctx.tb_phys_invalidate_count));
+    g_string_append_printf(buf, "\nStatistics:\n");
+    g_string_append_printf(buf, "TB flush count      %u\n",
+                           qatomic_read(&tb_ctx.tb_flush_count));
+    g_string_append_printf(buf, "TB invalidate count %u\n",
+                           qatomic_read(&tb_ctx.tb_phys_invalidate_count));
 
     tlb_flush_counts(&flush_full, &flush_part, &flush_elide);
-    qemu_printf("TLB full flushes    %zu\n", flush_full);
-    qemu_printf("TLB partial flushes %zu\n", flush_part);
-    qemu_printf("TLB elided flushes  %zu\n", flush_elide);
-    tcg_dump_info();
+    g_string_append_printf(buf, "TLB full flushes    %zu\n", flush_full);
+    g_string_append_printf(buf, "TLB partial flushes %zu\n", flush_part);
+    g_string_append_printf(buf, "TLB elided flushes  %zu\n", flush_elide);
+    tcg_dump_info(buf);
 }
 
 void dump_opcount_info(void)
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 32cfb634c6..d92f6fa7a9 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -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 */
 
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 44ccd86f3e..1b56e382b7 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -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 */
diff --git a/qapi/machine.json b/qapi/machine.json
index 0f537a58e0..e88aba1199 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 4142d42d77..7fcdfd9c0f 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -4382,7 +4382,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
 }
 
 #ifdef CONFIG_PROFILER
-void tcg_dump_info(void)
+void tcg_dump_info(GString *buf)
 {
     TCGProfile prof = {};
     const TCGProfile *s;
@@ -4396,53 +4396,59 @@ void tcg_dump_info(void)
     tb_div_count = tb_count ? tb_count : 1;
     tot = s->interm_time + s->code_time;
 
-    qemu_printf("JIT cycles          %" PRId64 " (%0.3f s at 2.4 GHz)\n",
-                tot, tot / 2.4e9);
-    qemu_printf("translated TBs      %" PRId64 " (aborted=%" PRId64
-                " %0.1f%%)\n",
-                tb_count, s->tb_count1 - tb_count,
-                (double)(s->tb_count1 - s->tb_count)
-                / (s->tb_count1 ? s->tb_count1 : 1) * 100.0);
-    qemu_printf("avg ops/TB          %0.1f max=%d\n",
-                (double)s->op_count / tb_div_count, s->op_count_max);
-    qemu_printf("deleted ops/TB      %0.2f\n",
-                (double)s->del_op_count / tb_div_count);
-    qemu_printf("avg temps/TB        %0.2f max=%d\n",
-                (double)s->temp_count / tb_div_count, s->temp_count_max);
-    qemu_printf("avg host code/TB    %0.1f\n",
-                (double)s->code_out_len / tb_div_count);
-    qemu_printf("avg search data/TB  %0.1f\n",
-                (double)s->search_out_len / tb_div_count);
+    g_string_append_printf(buf, "JIT cycles          %" PRId64
+                           " (%0.3f s at 2.4 GHz)\n",
+                           tot, tot / 2.4e9);
+    g_string_append_printf(buf, "translated TBs      %" PRId64
+                           " (aborted=%" PRId64 " %0.1f%%)\n",
+                           tb_count, s->tb_count1 - tb_count,
+                           (double)(s->tb_count1 - s->tb_count)
+                           / (s->tb_count1 ? s->tb_count1 : 1) * 100.0);
+    g_string_append_printf(buf, "avg ops/TB          %0.1f max=%d\n",
+                           (double)s->op_count / tb_div_count, s->op_count_max);
+    g_string_append_printf(buf, "deleted ops/TB      %0.2f\n",
+                           (double)s->del_op_count / tb_div_count);
+    g_string_append_printf(buf, "avg temps/TB        %0.2f max=%d\n",
+                           (double)s->temp_count / tb_div_count,
+                           s->temp_count_max);
+    g_string_append_printf(buf, "avg host code/TB    %0.1f\n",
+                           (double)s->code_out_len / tb_div_count);
+    g_string_append_printf(buf, "avg search data/TB  %0.1f\n",
+                           (double)s->search_out_len / tb_div_count);
     
-    qemu_printf("cycles/op           %0.1f\n",
-                s->op_count ? (double)tot / s->op_count : 0);
-    qemu_printf("cycles/in byte      %0.1f\n",
-                s->code_in_len ? (double)tot / s->code_in_len : 0);
-    qemu_printf("cycles/out byte     %0.1f\n",
-                s->code_out_len ? (double)tot / s->code_out_len : 0);
-    qemu_printf("cycles/search byte     %0.1f\n",
-                s->search_out_len ? (double)tot / s->search_out_len : 0);
+    g_string_append_printf(buf, "cycles/op           %0.1f\n",
+                           s->op_count ? (double)tot / s->op_count : 0);
+    g_string_append_printf(buf, "cycles/in byte      %0.1f\n",
+                           s->code_in_len ? (double)tot / s->code_in_len : 0);
+    g_string_append_printf(buf, "cycles/out byte     %0.1f\n",
+                           s->code_out_len ? (double)tot / s->code_out_len : 0);
+    g_string_append_printf(buf, "cycles/search byte     %0.1f\n",
+                           s->search_out_len ?
+                           (double)tot / s->search_out_len : 0);
     if (tot == 0) {
         tot = 1;
     }
-    qemu_printf("  gen_interm time   %0.1f%%\n",
-                (double)s->interm_time / tot * 100.0);
-    qemu_printf("  gen_code time     %0.1f%%\n",
-                (double)s->code_time / tot * 100.0);
-    qemu_printf("optim./code time    %0.1f%%\n",
-                (double)s->opt_time / (s->code_time ? s->code_time : 1)
-                * 100.0);
-    qemu_printf("liveness/code time  %0.1f%%\n",
-                (double)s->la_time / (s->code_time ? s->code_time : 1) * 100.0);
-    qemu_printf("cpu_restore count   %" PRId64 "\n",
-                s->restore_count);
-    qemu_printf("  avg cycles        %0.1f\n",
-                s->restore_count ? (double)s->restore_time / s->restore_count : 0);
+    g_string_append_printf(buf, "  gen_interm time   %0.1f%%\n",
+                           (double)s->interm_time / tot * 100.0);
+    g_string_append_printf(buf, "  gen_code time     %0.1f%%\n",
+                           (double)s->code_time / tot * 100.0);
+    g_string_append_printf(buf, "optim./code time    %0.1f%%\n",
+                           (double)s->opt_time / (s->code_time ?
+                                                  s->code_time : 1)
+                           * 100.0);
+    g_string_append_printf(buf, "liveness/code time  %0.1f%%\n",
+                           (double)s->la_time / (s->code_time ?
+                                                 s->code_time : 1) * 100.0);
+    g_string_append_printf(buf, "cpu_restore count   %" PRId64 "\n",
+                           s->restore_count);
+    g_string_append_printf(buf, "  avg cycles        %0.1f\n",
+                           s->restore_count ?
+                           (double)s->restore_time / s->restore_count : 0);
 }
 #else
-void tcg_dump_info(void)
+void tcg_dump_info(GString *buf)
 {
-    qemu_printf("[TCG profiler not compiled]\n");
+    g_string_append_printf(buf, "[TCG profiler not compiled]\n");
 }
 #endif
 
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index 15875a14c6..6aa628691a 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 52/53] qapi: introduce x-query-jit QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index e5c0ccd1a2..6d27fb62f9 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -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 */
diff --git a/accel/tcg/hmp.c b/accel/tcg/hmp.c
index a6e72fdb3e..9d7bcd9185 100644
--- a/accel/tcg/hmp.c
+++ b/accel/tcg/hmp.c
@@ -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)
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index bbfcfb698c..9c3dbe4409 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -2014,7 +2014,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
     cpu_loop_exit_noexc(cpu);
 }
 
-static void print_qht_statistics(struct qht_stats hst)
+static void print_qht_statistics(struct qht_stats hst, GString *buf)
 {
     uint32_t hgram_opts;
     size_t hgram_bins;
@@ -2023,9 +2023,11 @@ static void print_qht_statistics(struct qht_stats hst)
     if (!hst.head_buckets) {
         return;
     }
-    qemu_printf("TB hash buckets     %zu/%zu (%0.2f%% head buckets used)\n",
-                hst.used_head_buckets, hst.head_buckets,
-                (double)hst.used_head_buckets / hst.head_buckets * 100);
+    g_string_append_printf(buf, "TB hash buckets     %zu/%zu "
+                           "(%0.2f%% head buckets used)\n",
+                           hst.used_head_buckets, hst.head_buckets,
+                           (double)hst.used_head_buckets /
+                           hst.head_buckets * 100);
 
     hgram_opts =  QDIST_PR_BORDER | QDIST_PR_LABELS;
     hgram_opts |= QDIST_PR_100X   | QDIST_PR_PERCENT;
@@ -2033,8 +2035,9 @@ static void print_qht_statistics(struct qht_stats hst)
         hgram_opts |= QDIST_PR_NODECIMAL;
     }
     hgram = qdist_pr(&hst.occupancy, 10, hgram_opts);
-    qemu_printf("TB hash occupancy   %0.2f%% avg chain occ. Histogram: %s\n",
-                qdist_avg(&hst.occupancy) * 100, hgram);
+    g_string_append_printf(buf, "TB hash occupancy   %0.2f%% avg chain occ. "
+                           "Histogram: %s\n",
+                           qdist_avg(&hst.occupancy) * 100, hgram);
     g_free(hgram);
 
     hgram_opts = QDIST_PR_BORDER | QDIST_PR_LABELS;
@@ -2046,8 +2049,9 @@ static void print_qht_statistics(struct qht_stats hst)
         hgram_opts |= QDIST_PR_NODECIMAL | QDIST_PR_NOBINRANGE;
     }
     hgram = qdist_pr(&hst.chain, hgram_bins, hgram_opts);
-    qemu_printf("TB hash avg chain   %0.3f buckets. Histogram: %s\n",
-                qdist_avg(&hst.chain), hgram);
+    g_string_append_printf(buf, "TB hash avg chain   %0.3f buckets. "
+                           "Histogram: %s\n",
+                           qdist_avg(&hst.chain), hgram);
     g_free(hgram);
 }
 
@@ -2084,7 +2088,7 @@ static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer data)
     return false;
 }
 
-void dump_exec_info(void)
+void dump_exec_info(GString *buf)
 {
     struct tb_tree_stats tst = {};
     struct qht_stats hst;
@@ -2093,44 +2097,48 @@ void dump_exec_info(void)
     tcg_tb_foreach(tb_tree_stats_iter, &tst);
     nb_tbs = tst.nb_tbs;
     /* XXX: avoid using doubles ? */
-    qemu_printf("Translation buffer state:\n");
+    g_string_append_printf(buf, "Translation buffer state:\n");
     /*
      * Report total code size including the padding and TB structs;
      * otherwise users might think "-accel tcg,tb-size" is not honoured.
      * For avg host size we use the precise numbers from tb_tree_stats though.
      */
-    qemu_printf("gen code size       %zu/%zu\n",
-                tcg_code_size(), tcg_code_capacity());
-    qemu_printf("TB count            %zu\n", nb_tbs);
-    qemu_printf("TB avg target size  %zu max=%zu bytes\n",
-                nb_tbs ? tst.target_size / nb_tbs : 0,
-                tst.max_target_size);
-    qemu_printf("TB avg host size    %zu bytes (expansion ratio: %0.1f)\n",
-                nb_tbs ? tst.host_size / nb_tbs : 0,
-                tst.target_size ? (double)tst.host_size / tst.target_size : 0);
-    qemu_printf("cross page TB count %zu (%zu%%)\n", tst.cross_page,
-                nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0);
-    qemu_printf("direct jump count   %zu (%zu%%) (2 jumps=%zu %zu%%)\n",
-                tst.direct_jmp_count,
-                nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0,
-                tst.direct_jmp2_count,
-                nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0);
+    g_string_append_printf(buf, "gen code size       %zu/%zu\n",
+                           tcg_code_size(), tcg_code_capacity());
+    g_string_append_printf(buf, "TB count            %zu\n", nb_tbs);
+    g_string_append_printf(buf, "TB avg target size  %zu max=%zu bytes\n",
+                           nb_tbs ? tst.target_size / nb_tbs : 0,
+                           tst.max_target_size);
+    g_string_append_printf(buf, "TB avg host size    %zu bytes "
+                           "(expansion ratio: %0.1f)\n",
+                           nb_tbs ? tst.host_size / nb_tbs : 0,
+                           tst.target_size ?
+                           (double)tst.host_size / tst.target_size : 0);
+    g_string_append_printf(buf, "cross page TB count %zu (%zu%%)\n",
+                           tst.cross_page,
+                           nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0);
+    g_string_append_printf(buf, "direct jump count   %zu (%zu%%) "
+                           "(2 jumps=%zu %zu%%)\n",
+                           tst.direct_jmp_count,
+                           nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0,
+                           tst.direct_jmp2_count,
+                           nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0);
 
     qht_statistics_init(&tb_ctx.htable, &hst);
-    print_qht_statistics(hst);
+    print_qht_statistics(hst, buf);
     qht_statistics_destroy(&hst);
 
-    qemu_printf("\nStatistics:\n");
-    qemu_printf("TB flush count      %u\n",
-                qatomic_read(&tb_ctx.tb_flush_count));
-    qemu_printf("TB invalidate count %u\n",
-                qatomic_read(&tb_ctx.tb_phys_invalidate_count));
+    g_string_append_printf(buf, "\nStatistics:\n");
+    g_string_append_printf(buf, "TB flush count      %u\n",
+                           qatomic_read(&tb_ctx.tb_flush_count));
+    g_string_append_printf(buf, "TB invalidate count %u\n",
+                           qatomic_read(&tb_ctx.tb_phys_invalidate_count));
 
     tlb_flush_counts(&flush_full, &flush_part, &flush_elide);
-    qemu_printf("TLB full flushes    %zu\n", flush_full);
-    qemu_printf("TLB partial flushes %zu\n", flush_part);
-    qemu_printf("TLB elided flushes  %zu\n", flush_elide);
-    tcg_dump_info();
+    g_string_append_printf(buf, "TLB full flushes    %zu\n", flush_full);
+    g_string_append_printf(buf, "TLB partial flushes %zu\n", flush_part);
+    g_string_append_printf(buf, "TLB elided flushes  %zu\n", flush_elide);
+    tcg_dump_info(buf);
 }
 
 void dump_opcount_info(void)
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 32cfb634c6..d92f6fa7a9 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -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 */
 
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 44ccd86f3e..1b56e382b7 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -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 */
diff --git a/qapi/machine.json b/qapi/machine.json
index 0f537a58e0..e88aba1199 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 4142d42d77..7fcdfd9c0f 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -4382,7 +4382,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
 }
 
 #ifdef CONFIG_PROFILER
-void tcg_dump_info(void)
+void tcg_dump_info(GString *buf)
 {
     TCGProfile prof = {};
     const TCGProfile *s;
@@ -4396,53 +4396,59 @@ void tcg_dump_info(void)
     tb_div_count = tb_count ? tb_count : 1;
     tot = s->interm_time + s->code_time;
 
-    qemu_printf("JIT cycles          %" PRId64 " (%0.3f s at 2.4 GHz)\n",
-                tot, tot / 2.4e9);
-    qemu_printf("translated TBs      %" PRId64 " (aborted=%" PRId64
-                " %0.1f%%)\n",
-                tb_count, s->tb_count1 - tb_count,
-                (double)(s->tb_count1 - s->tb_count)
-                / (s->tb_count1 ? s->tb_count1 : 1) * 100.0);
-    qemu_printf("avg ops/TB          %0.1f max=%d\n",
-                (double)s->op_count / tb_div_count, s->op_count_max);
-    qemu_printf("deleted ops/TB      %0.2f\n",
-                (double)s->del_op_count / tb_div_count);
-    qemu_printf("avg temps/TB        %0.2f max=%d\n",
-                (double)s->temp_count / tb_div_count, s->temp_count_max);
-    qemu_printf("avg host code/TB    %0.1f\n",
-                (double)s->code_out_len / tb_div_count);
-    qemu_printf("avg search data/TB  %0.1f\n",
-                (double)s->search_out_len / tb_div_count);
+    g_string_append_printf(buf, "JIT cycles          %" PRId64
+                           " (%0.3f s at 2.4 GHz)\n",
+                           tot, tot / 2.4e9);
+    g_string_append_printf(buf, "translated TBs      %" PRId64
+                           " (aborted=%" PRId64 " %0.1f%%)\n",
+                           tb_count, s->tb_count1 - tb_count,
+                           (double)(s->tb_count1 - s->tb_count)
+                           / (s->tb_count1 ? s->tb_count1 : 1) * 100.0);
+    g_string_append_printf(buf, "avg ops/TB          %0.1f max=%d\n",
+                           (double)s->op_count / tb_div_count, s->op_count_max);
+    g_string_append_printf(buf, "deleted ops/TB      %0.2f\n",
+                           (double)s->del_op_count / tb_div_count);
+    g_string_append_printf(buf, "avg temps/TB        %0.2f max=%d\n",
+                           (double)s->temp_count / tb_div_count,
+                           s->temp_count_max);
+    g_string_append_printf(buf, "avg host code/TB    %0.1f\n",
+                           (double)s->code_out_len / tb_div_count);
+    g_string_append_printf(buf, "avg search data/TB  %0.1f\n",
+                           (double)s->search_out_len / tb_div_count);
     
-    qemu_printf("cycles/op           %0.1f\n",
-                s->op_count ? (double)tot / s->op_count : 0);
-    qemu_printf("cycles/in byte      %0.1f\n",
-                s->code_in_len ? (double)tot / s->code_in_len : 0);
-    qemu_printf("cycles/out byte     %0.1f\n",
-                s->code_out_len ? (double)tot / s->code_out_len : 0);
-    qemu_printf("cycles/search byte     %0.1f\n",
-                s->search_out_len ? (double)tot / s->search_out_len : 0);
+    g_string_append_printf(buf, "cycles/op           %0.1f\n",
+                           s->op_count ? (double)tot / s->op_count : 0);
+    g_string_append_printf(buf, "cycles/in byte      %0.1f\n",
+                           s->code_in_len ? (double)tot / s->code_in_len : 0);
+    g_string_append_printf(buf, "cycles/out byte     %0.1f\n",
+                           s->code_out_len ? (double)tot / s->code_out_len : 0);
+    g_string_append_printf(buf, "cycles/search byte     %0.1f\n",
+                           s->search_out_len ?
+                           (double)tot / s->search_out_len : 0);
     if (tot == 0) {
         tot = 1;
     }
-    qemu_printf("  gen_interm time   %0.1f%%\n",
-                (double)s->interm_time / tot * 100.0);
-    qemu_printf("  gen_code time     %0.1f%%\n",
-                (double)s->code_time / tot * 100.0);
-    qemu_printf("optim./code time    %0.1f%%\n",
-                (double)s->opt_time / (s->code_time ? s->code_time : 1)
-                * 100.0);
-    qemu_printf("liveness/code time  %0.1f%%\n",
-                (double)s->la_time / (s->code_time ? s->code_time : 1) * 100.0);
-    qemu_printf("cpu_restore count   %" PRId64 "\n",
-                s->restore_count);
-    qemu_printf("  avg cycles        %0.1f\n",
-                s->restore_count ? (double)s->restore_time / s->restore_count : 0);
+    g_string_append_printf(buf, "  gen_interm time   %0.1f%%\n",
+                           (double)s->interm_time / tot * 100.0);
+    g_string_append_printf(buf, "  gen_code time     %0.1f%%\n",
+                           (double)s->code_time / tot * 100.0);
+    g_string_append_printf(buf, "optim./code time    %0.1f%%\n",
+                           (double)s->opt_time / (s->code_time ?
+                                                  s->code_time : 1)
+                           * 100.0);
+    g_string_append_printf(buf, "liveness/code time  %0.1f%%\n",
+                           (double)s->la_time / (s->code_time ?
+                                                 s->code_time : 1) * 100.0);
+    g_string_append_printf(buf, "cpu_restore count   %" PRId64 "\n",
+                           s->restore_count);
+    g_string_append_printf(buf, "  avg cycles        %0.1f\n",
+                           s->restore_count ?
+                           (double)s->restore_time / s->restore_count : 0);
 }
 #else
-void tcg_dump_info(void)
+void tcg_dump_info(GString *buf)
 {
-    qemu_printf("[TCG profiler not compiled]\n");
+    g_string_append_printf(buf, "[TCG profiler not compiled]\n");
 }
 #endif
 
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index 15875a14c6..6aa628691a 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 53/53] qapi: introduce x-query-opcount QMP command
  2021-09-14 14:19 ` Daniel P. Berrangé
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Daniel P. Berrangé,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 6d27fb62f9..613f6fa5be 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -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 */
diff --git a/accel/tcg/hmp.c b/accel/tcg/hmp.c
index 9d7bcd9185..9b049d1e76 100644
--- a/accel/tcg/hmp.c
+++ b/accel/tcg/hmp.c
@@ -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)
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 9c3dbe4409..7a8121e70a 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -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 */
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index d92f6fa7a9..3c8e24292b 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -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 */
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 1b56e382b7..cc7f59070b 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -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 */
 
diff --git a/qapi/machine.json b/qapi/machine.json
index e88aba1199..bb24146a40 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 7fcdfd9c0f..d9653990af 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -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)
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index 6aa628691a..251a14ddf7 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* [PATCH v2 53/53] qapi: introduce x-query-opcount QMP command
@ 2021-09-14 14:20   ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 14:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff,
	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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 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(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 6d27fb62f9..613f6fa5be 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -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 */
diff --git a/accel/tcg/hmp.c b/accel/tcg/hmp.c
index 9d7bcd9185..9b049d1e76 100644
--- a/accel/tcg/hmp.c
+++ b/accel/tcg/hmp.c
@@ -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)
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 9c3dbe4409..7a8121e70a 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -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 */
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index d92f6fa7a9..3c8e24292b 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -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 */
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 1b56e382b7..cc7f59070b 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -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 */
 
diff --git a/qapi/machine.json b/qapi/machine.json
index e88aba1199..bb24146a40 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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:
 #
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 7fcdfd9c0f..d9653990af 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -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)
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index 6aa628691a..251a14ddf7 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* RE: [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-14 14:50     ` Taylor Simpson
  -1 siblings, 0 replies; 216+ messages in thread
From: Taylor Simpson @ 2021-09-14 14:50 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Alistair Francis, Gerd Hoffmann, Edgar E. Iglesias, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno



> -----Original Message-----
> From: Daniel P. Berrangé <berrange@redhat.com>
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/hexagon/cpu.c      | 5 -----
>  target/hexagon/internal.h | 1 -
>  2 files changed, 6 deletions(-)
> 
> diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index
> 3338365c16..14c628db7a 100644
> --- a/target/hexagon/cpu.c
> +++ b/target/hexagon/cpu.c
> @@ -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);
> diff --git a/target/hexagon/internal.h b/target/hexagon/internal.h index
> 6b20affdfa..167e91026a 100644
> --- a/target/hexagon/internal.h
> +++ b/target/hexagon/internal.h
> @@ -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: Taylor Simpson <tsimpson@quicinc.com>

^ permalink raw reply	[flat|nested] 216+ messages in thread

* RE: [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method
@ 2021-09-14 14:50     ` Taylor Simpson
  0 siblings, 0 replies; 216+ messages in thread
From: Taylor Simpson @ 2021-09-14 14:50 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Gerd Hoffmann,
	qemu-riscv, Max Filippov, Yuval Shaia, Bastian Koppelmann,
	Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff



> -----Original Message-----
> From: Daniel P. Berrangé <berrange@redhat.com>
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/hexagon/cpu.c      | 5 -----
>  target/hexagon/internal.h | 1 -
>  2 files changed, 6 deletions(-)
> 
> diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index
> 3338365c16..14c628db7a 100644
> --- a/target/hexagon/cpu.c
> +++ b/target/hexagon/cpu.c
> @@ -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);
> diff --git a/target/hexagon/internal.h b/target/hexagon/internal.h index
> 6b20affdfa..167e91026a 100644
> --- a/target/hexagon/internal.h
> +++ b/target/hexagon/internal.h
> @@ -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: Taylor Simpson <tsimpson@quicinc.com>

^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 28/53] monitor: remove 'info ioapic' HMP command
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-14 15:50     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 15:50 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> This command was turned into a no-op four years ago in
> 
>   commit 0c8465440d50c18a7bb13d0a866748f0593e193a
>   Author: Peter Xu <peterx@redhat.com>
>   Date:   Fri Dec 29 15:31:04 2017 +0800
> 
>     hmp: obsolete "info ioapic"
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hmp-commands-info.hx         | 15 ---------------
>  include/monitor/hmp-target.h |  1 -
>  target/i386/monitor.c        |  6 ------
>  3 files changed, 22 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 28/53] monitor: remove 'info ioapic' HMP command
@ 2021-09-14 15:50     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 15:50 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> This command was turned into a no-op four years ago in
> 
>   commit 0c8465440d50c18a7bb13d0a866748f0593e193a
>   Author: Peter Xu <peterx@redhat.com>
>   Date:   Fri Dec 29 15:31:04 2017 +0800
> 
>     hmp: obsolete "info ioapic"
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hmp-commands-info.hx         | 15 ---------------
>  include/monitor/hmp-target.h |  1 -
>  target/i386/monitor.c        |  6 ------
>  3 files changed, 22 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state'
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-14 15:53     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 15:53 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> The 'dump_state' callback assumes it will be outputting to a FILE
> object. This is fine for HMP, but not so useful for QMP. Introduce
> a new 'format_state' callback that returns a formatted GString
> instead.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hw/core/cpu-common.c  | 15 +++++++++++++++
>  include/hw/core/cpu.h | 13 ++++++++++++-
>  2 files changed, 27 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state'
@ 2021-09-14 15:53     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 15:53 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> The 'dump_state' callback assumes it will be outputting to a FILE
> object. This is fine for HMP, but not so useful for QMP. Introduce
> a new 'format_state' callback that returns a formatted GString
> instead.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hw/core/cpu-common.c  | 15 +++++++++++++++
>  include/hw/core/cpu.h | 13 ++++++++++++-
>  2 files changed, 27 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-14 15:56     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 15:56 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> This will allow us to reduce duplication between the different targets
> implementing the 'info tlb' command.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hw/core/cpu-common.c  |  9 +++++++++
>  include/hw/core/cpu.h | 11 +++++++++++
>  2 files changed, 20 insertions(+)

> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 4c47e1df18..64fc57c8d9 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
>   * @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);

Doesn't this belong to SysemuCPUOps?



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
@ 2021-09-14 15:56     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 15:56 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> This will allow us to reduce duplication between the different targets
> implementing the 'info tlb' command.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hw/core/cpu-common.c  |  9 +++++++++
>  include/hw/core/cpu.h | 11 +++++++++++
>  2 files changed, 20 insertions(+)

> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 4c47e1df18..64fc57c8d9 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
>   * @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);

Doesn't this belong to SysemuCPUOps?



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-14 16:04     ` Eric Blake
  -1 siblings, 0 replies; 216+ messages in thread
From: Eric Blake @ 2021-09-14 16:04 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz, Yuval Shaia,
	qemu-s390x, qemu-arm, Michael Rolnik, Peter Xu, Stafford Horne,
	David Gibson, qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Tue, Sep 14, 2021 at 03:20:18PM +0100, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

> +++ b/qapi/common.json
> @@ -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...

> +#
> +##
> +{ 'struct': 'HumanReadableText',
> +  'data': { 'human-readable-text': 'str' } }
> diff --git a/qapi/machine.json b/qapi/machine.json
> index 157712f006..8737efa865 100644
> --- a/qapi/machine.json
> +++ b/qapi/machine.json
> @@ -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

...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.

> +##
> +{ 'command': 'x-query-registers',
> +  'data': {'*cpu': 'int' },
> +  'returns': 'HumanReadableText' }
> -- 
> 2.31.1
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command
@ 2021-09-14 16:04     ` Eric Blake
  0 siblings, 0 replies; 216+ messages in thread
From: Eric Blake @ 2021-09-14 16:04 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Richard Henderson, Chris Wulff

On Tue, Sep 14, 2021 at 03:20:18PM +0100, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

> +++ b/qapi/common.json
> @@ -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...

> +#
> +##
> +{ 'struct': 'HumanReadableText',
> +  'data': { 'human-readable-text': 'str' } }
> diff --git a/qapi/machine.json b/qapi/machine.json
> index 157712f006..8737efa865 100644
> --- a/qapi/machine.json
> +++ b/qapi/machine.json
> @@ -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

...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.

> +##
> +{ 'command': 'x-query-registers',
> +  'data': {'*cpu': 'int' },
> +  'returns': 'HumanReadableText' }
> -- 
> 2.31.1
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 30/53] qapi: introduce x-query-roms QMP command
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-14 16:04     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 16:04 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
>  qapi/machine.json | 12 +++++++++++
>  2 files changed, 50 insertions(+), 17 deletions(-)

> -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;
> +}

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;
}

?



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 30/53] qapi: introduce x-query-roms QMP command
@ 2021-09-14 16:04     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 16:04 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
>  qapi/machine.json | 12 +++++++++++
>  2 files changed, 50 insertions(+), 17 deletions(-)

> -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;
> +}

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;
}

?



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
  2021-09-14 15:56     ` Philippe Mathieu-Daudé
@ 2021-09-14 16:34       ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 16:34 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Tue, Sep 14, 2021 at 05:56:09PM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> > This will allow us to reduce duplication between the different targets
> > implementing the 'info tlb' command.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  hw/core/cpu-common.c  |  9 +++++++++
> >  include/hw/core/cpu.h | 11 +++++++++++
> >  2 files changed, 20 insertions(+)
> 
> > diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> > index 4c47e1df18..64fc57c8d9 100644
> > --- a/include/hw/core/cpu.h
> > +++ b/include/hw/core/cpu.h
> >   * @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);
> 
> 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 :-)
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
@ 2021-09-14 16:34       ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 16:34 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Peter Maydell, Chris Wulff, David Hildenbrand,
	Bin Meng, Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang,
	Laurent Vivier, Max Filippov, Taylor Simpson, Alistair Francis,
	Gerd Hoffmann, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Marcel Apfelbaum, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck, qemu-ppc,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On Tue, Sep 14, 2021 at 05:56:09PM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> > This will allow us to reduce duplication between the different targets
> > implementing the 'info tlb' command.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  hw/core/cpu-common.c  |  9 +++++++++
> >  include/hw/core/cpu.h | 11 +++++++++++
> >  2 files changed, 20 insertions(+)
> 
> > diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> > index 4c47e1df18..64fc57c8d9 100644
> > --- a/include/hw/core/cpu.h
> > +++ b/include/hw/core/cpu.h
> >   * @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);
> 
> 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 :-)
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 30/53] qapi: introduce x-query-roms QMP command
  2021-09-14 16:04     ` Philippe Mathieu-Daudé
@ 2021-09-14 16:42       ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 16:42 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Tue, Sep 14, 2021 at 06:04:48PM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> > 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.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
> >  qapi/machine.json | 12 +++++++++++
> >  2 files changed, 50 insertions(+), 17 deletions(-)
> 
> > -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;
> > +}
> 
> 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);

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

> 
>     return ret;
> }

but yes, we could do a helper like this.


Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 30/53] qapi: introduce x-query-roms QMP command
@ 2021-09-14 16:42       ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 16:42 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Peter Maydell, Chris Wulff, David Hildenbrand,
	Bin Meng, Mark Cave-Ayland, Yuval Shaia, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On Tue, Sep 14, 2021 at 06:04:48PM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> > 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.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  hw/core/loader.c  | 55 ++++++++++++++++++++++++++++++++---------------
> >  qapi/machine.json | 12 +++++++++++
> >  2 files changed, 50 insertions(+), 17 deletions(-)
> 
> > -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;
> > +}
> 
> 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);

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

> 
>     return ret;
> }

but yes, we could do a helper like this.


Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
  2021-09-14 16:34       ` Daniel P. Berrangé
@ 2021-09-14 17:02         ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 17:02 UTC (permalink / raw)
  To: Daniel P. Berrangé, Richard Henderson, Paolo Bonzini
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Greg Kurz,
	Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik, Peter Xu,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Chris Wulff, Laurent Vivier, Palmer Dabbelt, Aurelien Jarno,
	Aleksandar Rikalo, Dr. David Alan Gilbert

On 9/14/21 6:34 PM, Daniel P. Berrangé wrote:
> On Tue, Sep 14, 2021 at 05:56:09PM +0200, Philippe Mathieu-Daudé wrote:
>> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
>>> This will allow us to reduce duplication between the different targets
>>> implementing the 'info tlb' command.
>>>
>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>> ---
>>>  hw/core/cpu-common.c  |  9 +++++++++
>>>  include/hw/core/cpu.h | 11 +++++++++++
>>>  2 files changed, 20 insertions(+)
>>
>>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
>>> index 4c47e1df18..64fc57c8d9 100644
>>> --- a/include/hw/core/cpu.h
>>> +++ b/include/hw/core/cpu.h
>>>   * @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"

>>>   * @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);
>>
>> 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]...

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 --
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ab86224ee23..9d2bd2e2ef4 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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;
---

> 
> Regards,
> Daniel
> 
> [1] yes assuming these things is often foolish in QEMU :-)
> 



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
@ 2021-09-14 17:02         ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 17:02 UTC (permalink / raw)
  To: Daniel P. Berrangé, Richard Henderson, Paolo Bonzini
  Cc: qemu-devel, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Peter Maydell, Max Filippov, Taylor Simpson, Alistair Francis,
	Gerd Hoffmann, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Marcel Apfelbaum, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Aleksandar Rikalo,
	Aurelien Jarno

On 9/14/21 6:34 PM, Daniel P. Berrangé wrote:
> On Tue, Sep 14, 2021 at 05:56:09PM +0200, Philippe Mathieu-Daudé wrote:
>> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
>>> This will allow us to reduce duplication between the different targets
>>> implementing the 'info tlb' command.
>>>
>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>> ---
>>>  hw/core/cpu-common.c  |  9 +++++++++
>>>  include/hw/core/cpu.h | 11 +++++++++++
>>>  2 files changed, 20 insertions(+)
>>
>>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
>>> index 4c47e1df18..64fc57c8d9 100644
>>> --- a/include/hw/core/cpu.h
>>> +++ b/include/hw/core/cpu.h
>>>   * @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"

>>>   * @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);
>>
>> 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]...

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 --
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ab86224ee23..9d2bd2e2ef4 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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;
---

> 
> Regards,
> Daniel
> 
> [1] yes assuming these things is often foolish in QEMU :-)
> 



^ permalink raw reply related	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
  2021-09-14 17:02         ` Philippe Mathieu-Daudé
@ 2021-09-14 17:12           ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 17:12 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Tue, Sep 14, 2021 at 07:02:19PM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 6:34 PM, Daniel P. Berrangé wrote:
> > On Tue, Sep 14, 2021 at 05:56:09PM +0200, Philippe Mathieu-Daudé wrote:
> >> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> >>> This will allow us to reduce duplication between the different targets
> >>> implementing the 'info tlb' command.
> >>>
> >>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> >>> ---
> >>>  hw/core/cpu-common.c  |  9 +++++++++
> >>>  include/hw/core/cpu.h | 11 +++++++++++
> >>>  2 files changed, 20 insertions(+)
> >>
> >>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> >>> index 4c47e1df18..64fc57c8d9 100644
> >>> --- a/include/hw/core/cpu.h
> >>> +++ b/include/hw/core/cpu.h
> >>>   * @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"
> 
> >>>   * @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);
> >>
> >> 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]...
> 
> 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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback
@ 2021-09-14 17:12           ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-14 17:12 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Richard Henderson, Paolo Bonzini, qemu-devel, Chris Wulff,
	David Hildenbrand, Bin Meng, Mark Cave-Ayland, Yuval Shaia,
	Jiaxun Yang, Laurent Vivier, Peter Maydell, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Marcel Apfelbaum, Palmer Dabbelt,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck, qemu-ppc,
	Aleksandar Rikalo, Aurelien Jarno

On Tue, Sep 14, 2021 at 07:02:19PM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 6:34 PM, Daniel P. Berrangé wrote:
> > On Tue, Sep 14, 2021 at 05:56:09PM +0200, Philippe Mathieu-Daudé wrote:
> >> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> >>> This will allow us to reduce duplication between the different targets
> >>> implementing the 'info tlb' command.
> >>>
> >>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> >>> ---
> >>>  hw/core/cpu-common.c  |  9 +++++++++
> >>>  include/hw/core/cpu.h | 11 +++++++++++
> >>>  2 files changed, 20 insertions(+)
> >>
> >>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> >>> index 4c47e1df18..64fc57c8d9 100644
> >>> --- a/include/hw/core/cpu.h
> >>> +++ b/include/hw/core/cpu.h
> >>>   * @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"
> 
> >>>   * @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);
> >>
> >> 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]...
> 
> 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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command
  2021-09-14 16:04     ` Eric Blake
@ 2021-09-14 17:15       ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 17:15 UTC (permalink / raw)
  To: Eric Blake, Daniel P. Berrangé,
	Markus Armbruster, Marc-André Lureau
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Marek Vasut, Yoshinori Sato, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Dr. David Alan Gilbert, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 6:04 PM, Eric Blake wrote:
> On Tue, Sep 14, 2021 at 03:20:18PM +0100, Daniel P. Berrangé wrote:
>> 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.
>>
>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>> ---

>> +##
>> +# @HumanReadableText:
>> +#
>> +# @human-readable-text: Formatted output intended for humans.
>> +#
>> +# Since: 6.2.0
> 
> Should be '6.2', not '6.2.0', to match...
> 
>> +#
>> +##
>> +{ 'struct': 'HumanReadableText',
>> +  'data': { 'human-readable-text': 'str' } }
>> diff --git a/qapi/machine.json b/qapi/machine.json
>> index 157712f006..8737efa865 100644
>> --- a/qapi/machine.json
>> +++ b/qapi/machine.json
>> @@ -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
> 
> ...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.

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").

> 
>> +##
>> +{ 'command': 'x-query-registers',
>> +  'data': {'*cpu': 'int' },
>> +  'returns': 'HumanReadableText' }
>> -- 
>> 2.31.1
>>
> 



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command
@ 2021-09-14 17:15       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 17:15 UTC (permalink / raw)
  To: Eric Blake, Daniel P. Berrangé,
	Markus Armbruster, Marc-André Lureau
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Marek Vasut, Yoshinori Sato, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Aurelien Jarno,
	Paolo Bonzini, Aleksandar Rikalo, Dr. David Alan Gilbert

On 9/14/21 6:04 PM, Eric Blake wrote:
> On Tue, Sep 14, 2021 at 03:20:18PM +0100, Daniel P. Berrangé wrote:
>> 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.
>>
>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>> ---

>> +##
>> +# @HumanReadableText:
>> +#
>> +# @human-readable-text: Formatted output intended for humans.
>> +#
>> +# Since: 6.2.0
> 
> Should be '6.2', not '6.2.0', to match...
> 
>> +#
>> +##
>> +{ 'struct': 'HumanReadableText',
>> +  'data': { 'human-readable-text': 'str' } }
>> diff --git a/qapi/machine.json b/qapi/machine.json
>> index 157712f006..8737efa865 100644
>> --- a/qapi/machine.json
>> +++ b/qapi/machine.json
>> @@ -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
> 
> ...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.

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").

> 
>> +##
>> +{ 'command': 'x-query-registers',
>> +  'data': {'*cpu': 'int' },
>> +  'returns': 'HumanReadableText' }
>> -- 
>> 2.31.1
>>
> 



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command
  2021-09-14 17:15       ` Philippe Mathieu-Daudé
@ 2021-09-14 17:18         ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 17:18 UTC (permalink / raw)
  To: Eric Blake, Daniel P. Berrangé,
	Markus Armbruster, Marc-André Lureau
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Marek Vasut, Yoshinori Sato, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Dr. David Alan Gilbert, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 7:15 PM, Philippe Mathieu-Daudé wrote:
> On 9/14/21 6:04 PM, Eric Blake wrote:
>> On Tue, Sep 14, 2021 at 03:20:18PM +0100, Daniel P. Berrangé wrote:
>>> 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.
>>>
>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>> ---
> 
>>> +##
>>> +# @HumanReadableText:
>>> +#
>>> +# @human-readable-text: Formatted output intended for humans.
>>> +#
>>> +# Since: 6.2.0
>>
>> Should be '6.2', not '6.2.0', to match...
>>
>>> +#
>>> +##
>>> +{ 'struct': 'HumanReadableText',
>>> +  'data': { 'human-readable-text': 'str' } }
>>> diff --git a/qapi/machine.json b/qapi/machine.json
>>> index 157712f006..8737efa865 100644
>>> --- a/qapi/machine.json
>>> +++ b/qapi/machine.json
>>> @@ -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
>>
>> ...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.
> 
> 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").

Oh we already talked about this together in this thread:
https://lore.kernel.org/qemu-devel/20210609202952.r4nb2smrptyckvk2@redhat.com/

> 
>>
>>> +##
>>> +{ 'command': 'x-query-registers',
>>> +  'data': {'*cpu': 'int' },
>>> +  'returns': 'HumanReadableText' }
>>> -- 
>>> 2.31.1
>>>
>>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command
@ 2021-09-14 17:18         ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-14 17:18 UTC (permalink / raw)
  To: Eric Blake, Daniel P. Berrangé,
	Markus Armbruster, Marc-André Lureau
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Marek Vasut, Yoshinori Sato, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Aurelien Jarno,
	Paolo Bonzini, Aleksandar Rikalo, Dr. David Alan Gilbert

On 9/14/21 7:15 PM, Philippe Mathieu-Daudé wrote:
> On 9/14/21 6:04 PM, Eric Blake wrote:
>> On Tue, Sep 14, 2021 at 03:20:18PM +0100, Daniel P. Berrangé wrote:
>>> 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.
>>>
>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>> ---
> 
>>> +##
>>> +# @HumanReadableText:
>>> +#
>>> +# @human-readable-text: Formatted output intended for humans.
>>> +#
>>> +# Since: 6.2.0
>>
>> Should be '6.2', not '6.2.0', to match...
>>
>>> +#
>>> +##
>>> +{ 'struct': 'HumanReadableText',
>>> +  'data': { 'human-readable-text': 'str' } }
>>> diff --git a/qapi/machine.json b/qapi/machine.json
>>> index 157712f006..8737efa865 100644
>>> --- a/qapi/machine.json
>>> +++ b/qapi/machine.json
>>> @@ -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
>>
>> ...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.
> 
> 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").

Oh we already talked about this together in this thread:
https://lore.kernel.org/qemu-devel/20210609202952.r4nb2smrptyckvk2@redhat.com/

> 
>>
>>> +##
>>> +{ 'command': 'x-query-registers',
>>> +  'data': {'*cpu': 'int' },
>>> +  'returns': 'HumanReadableText' }
>>> -- 
>>> 2.31.1
>>>
>>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state'
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-14 19:28     ` Greg Kurz
  -1 siblings, 0 replies; 216+ messages in thread
From: Greg Kurz @ 2021-09-14 19:28 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Dr. David Alan Gilbert,
	Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik, Peter Xu,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On Tue, 14 Sep 2021 15:19:55 +0100
Daniel P. Berrangé <berrange@redhat.com> wrote:

> The 'dump_state' callback assumes it will be outputting to a FILE
> object. This is fine for HMP, but not so useful for QMP. Introduce
> a new 'format_state' callback that returns a formatted GString
> instead.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  hw/core/cpu-common.c  | 15 +++++++++++++++
>  include/hw/core/cpu.h | 13 ++++++++++++-
>  2 files changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
> index e2f5a64604..c2cd33a817 100644
> --- a/hw/core/cpu-common.c
> +++ b/hw/core/cpu-common.c
> @@ -106,6 +106,21 @@ void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
>      if (cc->dump_state) {
>          cpu_synchronize_state(cpu);
>          cc->dump_state(cpu, f, flags);
> +    } else if (cc->format_state) {
> +        g_autoptr(GString) buf = 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);
>      }
>  }
>  
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index bc864564ce..1599ef9df3 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -91,7 +91,8 @@ struct SysemuCPUOps;
>   * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
>   * @has_work: Callback for checking if there is work to do.
>   * @memory_rw_debug: Callback for GDB memory access.
> - * @dump_state: Callback for dumping state.
> + * @dump_state: Callback for dumping state. Deprecated, use @format_state.
> + * @format_state: Callback for formatting state.
>   * @get_arch_id: Callback for getting architecture-dependent CPU ID.
>   * @set_pc: Callback for setting the Program Counter register. This
>   *       should have the semantics used by the target architecture when
> @@ -136,6 +137,7 @@ struct CPUClass {
>      int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
>                             uint8_t *buf, int len, bool is_write);
>      void (*dump_state)(CPUState *cpu, FILE *, int flags);
> +    void (*format_state)(CPUState *cpu, GString *buf, int flags);
>      int64_t (*get_arch_id)(CPUState *cpu);
>      void (*set_pc)(CPUState *cpu, vaddr value);
>      int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
> @@ -537,6 +539,15 @@ enum CPUDumpFlags {
>   */
>  void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
>  
> +/**
> + * 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:



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state'
@ 2021-09-14 19:28     ` Greg Kurz
  0 siblings, 0 replies; 216+ messages in thread
From: Greg Kurz @ 2021-09-14 19:28 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff

On Tue, 14 Sep 2021 15:19:55 +0100
Daniel P. Berrangé <berrange@redhat.com> wrote:

> The 'dump_state' callback assumes it will be outputting to a FILE
> object. This is fine for HMP, but not so useful for QMP. Introduce
> a new 'format_state' callback that returns a formatted GString
> instead.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  hw/core/cpu-common.c  | 15 +++++++++++++++
>  include/hw/core/cpu.h | 13 ++++++++++++-
>  2 files changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
> index e2f5a64604..c2cd33a817 100644
> --- a/hw/core/cpu-common.c
> +++ b/hw/core/cpu-common.c
> @@ -106,6 +106,21 @@ void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
>      if (cc->dump_state) {
>          cpu_synchronize_state(cpu);
>          cc->dump_state(cpu, f, flags);
> +    } else if (cc->format_state) {
> +        g_autoptr(GString) buf = 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);
>      }
>  }
>  
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index bc864564ce..1599ef9df3 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -91,7 +91,8 @@ struct SysemuCPUOps;
>   * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
>   * @has_work: Callback for checking if there is work to do.
>   * @memory_rw_debug: Callback for GDB memory access.
> - * @dump_state: Callback for dumping state.
> + * @dump_state: Callback for dumping state. Deprecated, use @format_state.
> + * @format_state: Callback for formatting state.
>   * @get_arch_id: Callback for getting architecture-dependent CPU ID.
>   * @set_pc: Callback for setting the Program Counter register. This
>   *       should have the semantics used by the target architecture when
> @@ -136,6 +137,7 @@ struct CPUClass {
>      int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
>                             uint8_t *buf, int len, bool is_write);
>      void (*dump_state)(CPUState *cpu, FILE *, int flags);
> +    void (*format_state)(CPUState *cpu, GString *buf, int flags);
>      int64_t (*get_arch_id)(CPUState *cpu);
>      void (*set_pc)(CPUState *cpu, vaddr value);
>      int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
> @@ -537,6 +539,15 @@ enum CPUDumpFlags {
>   */
>  void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
>  
> +/**
> + * 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:



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 20/53] target/ppc: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-14 19:30     ` Greg Kurz
  -1 siblings, 0 replies; 216+ messages in thread
From: Greg Kurz @ 2021-09-14 19:30 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Dr. David Alan Gilbert,
	Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik, Peter Xu,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On Tue, 14 Sep 2021 15:20:09 +0100
Daniel P. Berrangé <berrange@redhat.com> wrote:

> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

Acked-by: Greg Kurz <groug@kaod.org>

>  target/ppc/cpu.h      |   2 +-
>  target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
>  2 files changed, 126 insertions(+), 88 deletions(-)
> 
> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
> index 500205229c..c84ae29b98 100644
> --- a/target/ppc/cpu.h
> +++ b/target/ppc/cpu.h
> @@ -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);
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index ad7abc6041..3456be465c 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -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;



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 20/53] target/ppc: convert to use format_state instead of dump_state
@ 2021-09-14 19:30     ` Greg Kurz
  0 siblings, 0 replies; 216+ messages in thread
From: Greg Kurz @ 2021-09-14 19:30 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff

On Tue, 14 Sep 2021 15:20:09 +0100
Daniel P. Berrangé <berrange@redhat.com> wrote:

> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

Acked-by: Greg Kurz <groug@kaod.org>

>  target/ppc/cpu.h      |   2 +-
>  target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
>  2 files changed, 126 insertions(+), 88 deletions(-)
> 
> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
> index 500205229c..c84ae29b98 100644
> --- a/target/ppc/cpu.h
> +++ b/target/ppc/cpu.h
> @@ -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);
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index ad7abc6041..3456be465c 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -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;



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 15/53] target/m68k: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-14 19:58     ` Laurent Vivier
  -1 siblings, 0 replies; 216+ messages in thread
From: Laurent Vivier @ 2021-09-14 19:58 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff,
	Philippe Mathieu-Daudé,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Le 14/09/2021 à 16:20, Daniel P. Berrangé a écrit :
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/m68k/cpu.c       |  2 +-
>  target/m68k/cpu.h       |  2 +-
>  target/m68k/translate.c | 92 ++++++++++++++++++++++-------------------
>  3 files changed, 51 insertions(+), 45 deletions(-)
> 
> diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
> index 72de6e9726..4ccf572a68 100644
> --- a/target/m68k/cpu.c
> +++ b/target/m68k/cpu.c
> @@ -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;
> diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
> index 997d588911..b0641f6d0d 100644
> --- a/target/m68k/cpu.h
> +++ b/target/m68k/cpu.h
> @@ -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);
> diff --git a/target/m68k/translate.c b/target/m68k/translate.c
> index c34d9aed61..951bbed6bf 100644
> --- a/target/m68k/translate.c
> +++ b/target/m68k/translate.c
> @@ -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",
> +                           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: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 15/53] target/m68k: convert to use format_state instead of dump_state
@ 2021-09-14 19:58     ` Laurent Vivier
  0 siblings, 0 replies; 216+ messages in thread
From: Laurent Vivier @ 2021-09-14 19:58 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Edgar E. Iglesias, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Le 14/09/2021 à 16:20, Daniel P. Berrangé a écrit :
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/m68k/cpu.c       |  2 +-
>  target/m68k/cpu.h       |  2 +-
>  target/m68k/translate.c | 92 ++++++++++++++++++++++-------------------
>  3 files changed, 51 insertions(+), 45 deletions(-)
> 
> diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
> index 72de6e9726..4ccf572a68 100644
> --- a/target/m68k/cpu.c
> +++ b/target/m68k/cpu.c
> @@ -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;
> diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
> index 997d588911..b0641f6d0d 100644
> --- a/target/m68k/cpu.h
> +++ b/target/m68k/cpu.h
> @@ -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);
> diff --git a/target/m68k/translate.c b/target/m68k/translate.c
> index c34d9aed61..951bbed6bf 100644
> --- a/target/m68k/translate.c
> +++ b/target/m68k/translate.c
> @@ -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",
> +                           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: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 44/53] target/m68k: convert to use format_tlb callback
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-14 19:59     ` Laurent Vivier
  -1 siblings, 0 replies; 216+ messages in thread
From: Laurent Vivier @ 2021-09-14 19:59 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff,
	Philippe Mathieu-Daudé,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Le 14/09/2021 à 16:20, Daniel P. Berrangé a écrit :
> Change the "info tlb" implementation to use the format_tlb callback.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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(-)
> 
> diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
> index 4ccf572a68..8f143eb540 100644
> --- a/target/m68k/cpu.c
> +++ b/target/m68k/cpu.c
> @@ -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;
> diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
> index b0641f6d0d..f2d777a1ba 100644
> --- a/target/m68k/cpu.h
> +++ b/target/m68k/cpu.h
> @@ -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
> diff --git a/target/m68k/helper.c b/target/m68k/helper.c
> index 137a3e1a3d..050a27d21c 100644
> --- a/target/m68k/helper.c
> +++ b/target/m68k/helper.c
> @@ -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,
> diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c
> index 2bdf6acae0..003a665246 100644
> --- a/target/m68k/monitor.c
> +++ b/target/m68k/monitor.c
> @@ -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[] = {
> 

Acked-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 44/53] target/m68k: convert to use format_tlb callback
@ 2021-09-14 19:59     ` Laurent Vivier
  0 siblings, 0 replies; 216+ messages in thread
From: Laurent Vivier @ 2021-09-14 19:59 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Edgar E. Iglesias, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Le 14/09/2021 à 16:20, Daniel P. Berrangé a écrit :
> Change the "info tlb" implementation to use the format_tlb callback.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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(-)
> 
> diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
> index 4ccf572a68..8f143eb540 100644
> --- a/target/m68k/cpu.c
> +++ b/target/m68k/cpu.c
> @@ -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;
> diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
> index b0641f6d0d..f2d777a1ba 100644
> --- a/target/m68k/cpu.h
> +++ b/target/m68k/cpu.h
> @@ -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
> diff --git a/target/m68k/helper.c b/target/m68k/helper.c
> index 137a3e1a3d..050a27d21c 100644
> --- a/target/m68k/helper.c
> +++ b/target/m68k/helper.c
> @@ -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,
> diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c
> index 2bdf6acae0..003a665246 100644
> --- a/target/m68k/monitor.c
> +++ b/target/m68k/monitor.c
> @@ -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[] = {
> 

Acked-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 20/53] target/ppc: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  1:37     ` David Gibson
  -1 siblings, 0 replies; 216+ messages in thread
From: David Gibson @ 2021-09-15  1:37 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz, Yuval Shaia,
	qemu-s390x, qemu-arm, Michael Rolnik, Peter Xu, Stafford Horne,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 17046 bytes --]

On Tue, Sep 14, 2021 at 03:20:09PM +0100, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  target/ppc/cpu.h      |   2 +-
>  target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
>  2 files changed, 126 insertions(+), 88 deletions(-)
> 
> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
> index 500205229c..c84ae29b98 100644
> --- a/target/ppc/cpu.h
> +++ b/target/ppc/cpu.h
> @@ -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);
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index ad7abc6041..3456be465c 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -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;

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 20/53] target/ppc: convert to use format_state instead of dump_state
@ 2021-09-15  1:37     ` David Gibson
  0 siblings, 0 replies; 216+ messages in thread
From: David Gibson @ 2021-09-15  1:37 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, Marcel Apfelbaum, Laurent Vivier,
	Dr. David Alan Gilbert, Eduardo Habkost, Marek Vasut,
	Markus Armbruster, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

[-- Attachment #1: Type: text/plain, Size: 17046 bytes --]

On Tue, Sep 14, 2021 at 03:20:09PM +0100, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  target/ppc/cpu.h      |   2 +-
>  target/ppc/cpu_init.c | 212 +++++++++++++++++++++++++-----------------
>  2 files changed, 126 insertions(+), 88 deletions(-)
> 
> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
> index 500205229c..c84ae29b98 100644
> --- a/target/ppc/cpu.h
> +++ b/target/ppc/cpu.h
> @@ -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);
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index ad7abc6041..3456be465c 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -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;

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 46/53] target/ppc: convert to use format_tlb callback
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  1:40     ` David Gibson
  -1 siblings, 0 replies; 216+ messages in thread
From: David Gibson @ 2021-09-15  1:40 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz, Yuval Shaia,
	qemu-s390x, qemu-arm, Michael Rolnik, Peter Xu, Stafford Horne,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 18423 bytes --]

On Tue, Sep 14, 2021 at 03:20:35PM +0100, Daniel P. Berrangé wrote:
> Change the "info tlb" implementation to use the format_tlb callback.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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(-)
> 
> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
> index c84ae29b98..37b44bfbc3 100644
> --- a/target/ppc/cpu.h
> +++ b/target/ppc/cpu.h
> @@ -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);
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index 3456be465c..98d6f40a49 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -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;
> diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
> index 19832c4b46..73927a0819 100644
> --- a/target/ppc/mmu-hash64.c
> +++ b/target/ppc/mmu-hash64.c
> @@ -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);
>      }
>  }
>  
> diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h
> index c5b2f97ff7..99e03a5849 100644
> --- a/target/ppc/mmu-hash64.h
> +++ b/target/ppc/mmu-hash64.h
> @@ -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,
> diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
> index 754509e556..d7b716f30a 100644
> --- a/target/ppc/mmu_common.c
> +++ b/target/ppc/mmu_common.c
> @@ -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);
>      }
>  }
>  
> diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c
> index a475108b2d..401a36c2eb 100644
> --- a/target/ppc/monitor.c
> +++ b/target/ppc/monitor.c
> @@ -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[] = {

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 46/53] target/ppc: convert to use format_tlb callback
@ 2021-09-15  1:40     ` David Gibson
  0 siblings, 0 replies; 216+ messages in thread
From: David Gibson @ 2021-09-15  1:40 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, Marcel Apfelbaum, Laurent Vivier,
	Dr. David Alan Gilbert, Eduardo Habkost, Marek Vasut,
	Markus Armbruster, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

[-- Attachment #1: Type: text/plain, Size: 18423 bytes --]

On Tue, Sep 14, 2021 at 03:20:35PM +0100, Daniel P. Berrangé wrote:
> Change the "info tlb" implementation to use the format_tlb callback.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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(-)
> 
> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
> index c84ae29b98..37b44bfbc3 100644
> --- a/target/ppc/cpu.h
> +++ b/target/ppc/cpu.h
> @@ -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);
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index 3456be465c..98d6f40a49 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -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;
> diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
> index 19832c4b46..73927a0819 100644
> --- a/target/ppc/mmu-hash64.c
> +++ b/target/ppc/mmu-hash64.c
> @@ -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);
>      }
>  }
>  
> diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h
> index c5b2f97ff7..99e03a5849 100644
> --- a/target/ppc/mmu-hash64.h
> +++ b/target/ppc/mmu-hash64.h
> @@ -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,
> diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
> index 754509e556..d7b716f30a 100644
> --- a/target/ppc/mmu_common.c
> +++ b/target/ppc/mmu_common.c
> @@ -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);
>      }
>  }
>  
> diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c
> index a475108b2d..401a36c2eb 100644
> --- a/target/ppc/monitor.c
> +++ b/target/ppc/monitor.c
> @@ -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[] = {

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 50/53] monitor: merge duplicate "info tlb" handlers
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  1:41     ` David Gibson
  -1 siblings, 0 replies; 216+ messages in thread
From: David Gibson @ 2021-09-15  1:41 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz, Yuval Shaia,
	qemu-s390x, qemu-arm, Michael Rolnik, Peter Xu, Stafford Horne,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 8283 bytes --]

On Tue, Sep 14, 2021 at 03:20:39PM +0100, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

ppc parts
Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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(-)
> 
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index f8312342cd..7bd1e04d46 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -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``
> diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h
> index df79ad3355..04e02e8895 100644
> --- a/include/monitor/hmp-target.h
> +++ b/include/monitor/hmp-target.h
> @@ -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);
>  
> diff --git a/monitor/misc.c b/monitor/misc.c
> index 6b07efdddd..c7d138914d 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -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;
> diff --git a/target/i386/monitor.c b/target/i386/monitor.c
> index 698fbbc80b..a7eb4205c7 100644
> --- a/target/i386/monitor.c
> +++ b/target/i386/monitor.c
> @@ -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)
> diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c
> index 003a665246..0dc729692b 100644
> --- a/target/m68k/monitor.c
> +++ b/target/m68k/monitor.c
> @@ -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]) },
> diff --git a/target/nios2/monitor.c b/target/nios2/monitor.c
> index 99d35e8ef1..1180a32f80 100644
> --- a/target/nios2/monitor.c
> +++ b/target/nios2/monitor.c
> @@ -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);
> -}
> diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c
> index 401a36c2eb..3564fd5f45 100644
> --- a/target/ppc/monitor.c
> +++ b/target/ppc/monitor.c
> @@ -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 */
> diff --git a/target/sh4/monitor.c b/target/sh4/monitor.c
> index 5ccb95af93..d641d95316 100644
> --- a/target/sh4/monitor.c
> +++ b/target/sh4/monitor.c
> @@ -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);
> -}
> diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c
> index cc7fe74e3e..0c51669c08 100644
> --- a/target/sparc/monitor.c
> +++ b/target/sparc/monitor.c
> @@ -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)
> diff --git a/target/xtensa/monitor.c b/target/xtensa/monitor.c
> index 99d35e8ef1..1180a32f80 100644
> --- a/target/xtensa/monitor.c
> +++ b/target/xtensa/monitor.c
> @@ -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);
> -}

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 50/53] monitor: merge duplicate "info tlb" handlers
@ 2021-09-15  1:41     ` David Gibson
  0 siblings, 0 replies; 216+ messages in thread
From: David Gibson @ 2021-09-15  1:41 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, Marcel Apfelbaum, Laurent Vivier,
	Dr. David Alan Gilbert, Eduardo Habkost, Marek Vasut,
	Markus Armbruster, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

[-- Attachment #1: Type: text/plain, Size: 8283 bytes --]

On Tue, Sep 14, 2021 at 03:20:39PM +0100, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

ppc parts
Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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(-)
> 
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index f8312342cd..7bd1e04d46 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -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``
> diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h
> index df79ad3355..04e02e8895 100644
> --- a/include/monitor/hmp-target.h
> +++ b/include/monitor/hmp-target.h
> @@ -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);
>  
> diff --git a/monitor/misc.c b/monitor/misc.c
> index 6b07efdddd..c7d138914d 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -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;
> diff --git a/target/i386/monitor.c b/target/i386/monitor.c
> index 698fbbc80b..a7eb4205c7 100644
> --- a/target/i386/monitor.c
> +++ b/target/i386/monitor.c
> @@ -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)
> diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c
> index 003a665246..0dc729692b 100644
> --- a/target/m68k/monitor.c
> +++ b/target/m68k/monitor.c
> @@ -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]) },
> diff --git a/target/nios2/monitor.c b/target/nios2/monitor.c
> index 99d35e8ef1..1180a32f80 100644
> --- a/target/nios2/monitor.c
> +++ b/target/nios2/monitor.c
> @@ -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);
> -}
> diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c
> index 401a36c2eb..3564fd5f45 100644
> --- a/target/ppc/monitor.c
> +++ b/target/ppc/monitor.c
> @@ -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 */
> diff --git a/target/sh4/monitor.c b/target/sh4/monitor.c
> index 5ccb95af93..d641d95316 100644
> --- a/target/sh4/monitor.c
> +++ b/target/sh4/monitor.c
> @@ -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);
> -}
> diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c
> index cc7fe74e3e..0c51669c08 100644
> --- a/target/sparc/monitor.c
> +++ b/target/sparc/monitor.c
> @@ -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)
> diff --git a/target/xtensa/monitor.c b/target/xtensa/monitor.c
> index 99d35e8ef1..1180a32f80 100644
> --- a/target/xtensa/monitor.c
> +++ b/target/xtensa/monitor.c
> @@ -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);
> -}

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:00     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:00 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> This method isn't used in any code and its functionality is already
> available via the 'info registers' HMP command.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/hexagon/cpu.c      | 5 -----
>  target/hexagon/internal.h | 1 -
>  2 files changed, 6 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method
@ 2021-09-15  7:00     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:00 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> This method isn't used in any code and its functionality is already
> available via the 'info registers' HMP command.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/hexagon/cpu.c      | 5 -----
>  target/hexagon/internal.h | 1 -
>  2 files changed, 6 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 17/53] target/mips: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:04     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:04 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/mips/cpu.c | 85 +++++++++++++++++++++++++----------------------
>  1 file changed, 45 insertions(+), 40 deletions(-)
> 
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index d426918291..9ced90d810 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -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",

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: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 17/53] target/mips: convert to use format_state instead of dump_state
@ 2021-09-15  7:04     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:04 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/mips/cpu.c | 85 +++++++++++++++++++++++++----------------------
>  1 file changed, 45 insertions(+), 40 deletions(-)
> 
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index d426918291..9ced90d810 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -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",

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: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 18/53] target/nios2: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:08     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:08 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel, Richard Henderson
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/nios2/cpu.c       |  2 +-
>  target/nios2/cpu.h       |  2 +-
>  target/nios2/translate.c | 20 ++++++++++----------
>  3 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
> index 5e37defef8..cbf15fb1c9 100644
> --- a/target/nios2/cpu.c
> +++ b/target/nios2/cpu.c
> @@ -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
> diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
> index 2ab82fdc71..3b16cd1f3c 100644
> --- a/target/nios2/cpu.h
> +++ b/target/nios2/cpu.h
> @@ -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,
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c
> index 08d7ac5398..a5f0f56e1a 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -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]));

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: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 18/53] target/nios2: convert to use format_state instead of dump_state
@ 2021-09-15  7:08     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:08 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel, Richard Henderson
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck, qemu-ppc,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/nios2/cpu.c       |  2 +-
>  target/nios2/cpu.h       |  2 +-
>  target/nios2/translate.c | 20 ++++++++++----------
>  3 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
> index 5e37defef8..cbf15fb1c9 100644
> --- a/target/nios2/cpu.c
> +++ b/target/nios2/cpu.c
> @@ -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
> diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
> index 2ab82fdc71..3b16cd1f3c 100644
> --- a/target/nios2/cpu.h
> +++ b/target/nios2/cpu.h
> @@ -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,
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c
> index 08d7ac5398..a5f0f56e1a 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -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]));

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: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 07/53] target/alpha: convert to use format_state instead of dump_state
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-15  7:10     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:10 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel, Richard Henderson
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/alpha/cpu.c    |  2 +-
>  target/alpha/cpu.h    |  2 +-
>  target/alpha/helper.c | 28 ++++++++++++++++------------
>  3 files changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
> index 4871ad0c0a..d0cdda9554 100644
> --- a/target/alpha/cpu.c
> +++ b/target/alpha/cpu.c
> @@ -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;
> diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h
> index 82df108967..9e3c80ebcc 100644
> --- a/target/alpha/cpu.h
> +++ b/target/alpha/cpu.h
> @@ -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);
> diff --git a/target/alpha/helper.c b/target/alpha/helper.c
> index 4f56fe4d23..6ed80e8a27 100644
> --- a/target/alpha/helper.c
> +++ b/target/alpha/helper.c
> @@ -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: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 07/53] target/alpha: convert to use format_state instead of dump_state
@ 2021-09-15  7:10     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:10 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel, Richard Henderson
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck, qemu-ppc,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/alpha/cpu.c    |  2 +-
>  target/alpha/cpu.h    |  2 +-
>  target/alpha/helper.c | 28 ++++++++++++++++------------
>  3 files changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
> index 4871ad0c0a..d0cdda9554 100644
> --- a/target/alpha/cpu.c
> +++ b/target/alpha/cpu.c
> @@ -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;
> diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h
> index 82df108967..9e3c80ebcc 100644
> --- a/target/alpha/cpu.h
> +++ b/target/alpha/cpu.h
> @@ -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);
> diff --git a/target/alpha/helper.c b/target/alpha/helper.c
> index 4f56fe4d23..6ed80e8a27 100644
> --- a/target/alpha/helper.c
> +++ b/target/alpha/helper.c
> @@ -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: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-15  7:13     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:13 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
>  1 file changed, 29 insertions(+), 28 deletions(-)
> 
> diff --git a/target/avr/cpu.c b/target/avr/cpu.c
> index ea14175ca5..17ff21f8be 100644
> --- a/target/avr/cpu.c
> +++ b/target/avr/cpu.c
> @@ -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");

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.

> +    /* 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");

Ditto (remove).

Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  }


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state
@ 2021-09-15  7:13     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:13 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
>  1 file changed, 29 insertions(+), 28 deletions(-)
> 
> diff --git a/target/avr/cpu.c b/target/avr/cpu.c
> index ea14175ca5..17ff21f8be 100644
> --- a/target/avr/cpu.c
> +++ b/target/avr/cpu.c
> @@ -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");

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.

> +    /* 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");

Ditto (remove).

Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  }


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 12/53] target/hexagon: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:14     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:14 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/hexagon/cpu.c | 65 ++++++++++++++++++++------------------------
>  1 file changed, 29 insertions(+), 36 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 12/53] target/hexagon: convert to use format_state instead of dump_state
@ 2021-09-15  7:14     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:14 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/hexagon/cpu.c | 65 ++++++++++++++++++++------------------------
>  1 file changed, 29 insertions(+), 36 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 13/53] target/hppa: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:15     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:15 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/hppa/cpu.c    |  2 +-
>  target/hppa/cpu.h    |  2 +-
>  target/hppa/helper.c | 25 ++++++++++++++-----------
>  3 files changed, 16 insertions(+), 13 deletions(-)

> @@ -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");

        g_string_append_c(buf, '\n');

Otherwise,
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  
>      /* ??? FR */
>  }
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 13/53] target/hppa: convert to use format_state instead of dump_state
@ 2021-09-15  7:15     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:15 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/hppa/cpu.c    |  2 +-
>  target/hppa/cpu.h    |  2 +-
>  target/hppa/helper.c | 25 ++++++++++++++-----------
>  3 files changed, 16 insertions(+), 13 deletions(-)

> @@ -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");

        g_string_append_c(buf, '\n');

Otherwise,
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  
>      /* ??? FR */
>  }
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 15/53] target/m68k: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:17     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:17 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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:
> -        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");

g_string_append_c(), otherwise:

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 15/53] target/m68k: convert to use format_state instead of dump_state
@ 2021-09-15  7:17     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:17 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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:
> -        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");

g_string_append_c(), otherwise:

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:18     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:18 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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++) {
> -        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:

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  }
>  
>  void mb_tcg_init(void)
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state
@ 2021-09-15  7:18     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:18 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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++) {
> -        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:

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  }
>  
>  void mb_tcg_init(void)
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 19/53] target/openrisc: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:19     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:19 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/openrisc/cpu.c       | 2 +-
>  target/openrisc/cpu.h       | 2 +-
>  target/openrisc/translate.c | 8 ++++----
>  3 files changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 19/53] target/openrisc: convert to use format_state instead of dump_state
@ 2021-09-15  7:19     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:19 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/openrisc/cpu.c       | 2 +-
>  target/openrisc/cpu.h       | 2 +-
>  target/openrisc/translate.c | 8 ++++----
>  3 files changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 22/53] target/rx: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:20     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:20 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/rx/cpu.c       |  2 +-
>  target/rx/cpu.h       |  2 +-
>  target/rx/translate.c | 14 ++++++++------
>  3 files changed, 10 insertions(+), 8 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 22/53] target/rx: convert to use format_state instead of dump_state
@ 2021-09-15  7:20     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:20 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/rx/cpu.c       |  2 +-
>  target/rx/cpu.h       |  2 +-
>  target/rx/translate.c | 14 ++++++++------
>  3 files changed, 10 insertions(+), 8 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state
  2021-09-15  7:18     ` Philippe Mathieu-Daudé
@ 2021-09-15  7:21       ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:21 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Cornelia Huck, Laurent Vivier, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/15/21 9:18 AM, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>> ---
>>  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++) {
>> -        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:

Actually we don't need an extra newline.

> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
>>  }
>>  
>>  void mb_tcg_init(void)
>>
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state
@ 2021-09-15  7:21       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:21 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/15/21 9:18 AM, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>> ---
>>  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++) {
>> -        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:

Actually we don't need an extra newline.

> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
>>  }
>>  
>>  void mb_tcg_init(void)
>>
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state
  2021-09-15  7:21       ` Philippe Mathieu-Daudé
@ 2021-09-15  7:23         ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:23 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel@nongnu.org Developers
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, open list:vfio-ccw, qemu-arm,
	Michael Rolnik, Stafford Horne, David Gibson,
	open list:RISC-V TCG CPUs, Bastian Koppelmann, Cornelia Huck,
	Laurent Vivier, qemu-ppc@nongnu.org list:PowerPC, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On Wed, Sep 15, 2021 at 9:21 AM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> On 9/15/21 9:18 AM, Philippe Mathieu-Daudé wrote:
> > On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> >> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> >> ---
> >>  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++) {
> >> -        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:
>
> Actually we don't need an extra newline.

Oops sorry here we do.

> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> >
> >>  }
> >>
> >>  void mb_tcg_init(void)
> >>
> >


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 16/53] target/microblaze: convert to use format_state instead of dump_state
@ 2021-09-15  7:23         ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:23 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel@nongnu.org Developers
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	qemu-ppc@nongnu.org list:PowerPC, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, open list:vfio-ccw, qemu-arm,
	Michael Rolnik, Stafford Horne, David Gibson,
	open list:RISC-V TCG CPUs, Bastian Koppelmann, Chris Wulff,
	Laurent Vivier, Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo,
	Aurelien Jarno

On Wed, Sep 15, 2021 at 9:21 AM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> On 9/15/21 9:18 AM, Philippe Mathieu-Daudé wrote:
> > On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> >> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> >> ---
> >>  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++) {
> >> -        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:
>
> Actually we don't need an extra newline.

Oops sorry here we do.

> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> >
> >>  }
> >>
> >>  void mb_tcg_init(void)
> >>
> >


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 24/53] target/sh: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:24     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:24 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/sh4/cpu.c       |  2 +-
>  target/sh4/cpu.h       |  2 +-
>  target/sh4/translate.c | 36 ++++++++++++++++++++----------------
>  3 files changed, 22 insertions(+), 18 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 24/53] target/sh: convert to use format_state instead of dump_state
@ 2021-09-15  7:24     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:24 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/sh4/cpu.c       |  2 +-
>  target/sh4/cpu.h       |  2 +-
>  target/sh4/translate.c | 36 ++++++++++++++++++++----------------
>  3 files changed, 22 insertions(+), 18 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 25/53] target/sparc: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:27     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:27 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
>  target/sparc/cpu.h |  2 +-
>  2 files changed, 47 insertions(+), 40 deletions(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index da6b30ec74..9346a79239 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -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().

>  {
> -    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");

g_string_append_c()

>          }
>      }
>      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");

g_string_append_c()

>              }
>          }
>      }
> @@ -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");

g_string_append_c()

>              }
>          }
>      }
>  
>  #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");

We probably don't need this last newline anymore.

>  }
>  


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 25/53] target/sparc: convert to use format_state instead of dump_state
@ 2021-09-15  7:27     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:27 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
>  target/sparc/cpu.h |  2 +-
>  2 files changed, 47 insertions(+), 40 deletions(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index da6b30ec74..9346a79239 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -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().

>  {
> -    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");

g_string_append_c()

>          }
>      }
>      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");

g_string_append_c()

>              }
>          }
>      }
> @@ -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");

g_string_append_c()

>              }
>          }
>      }
>  
>  #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");

We probably don't need this last newline anymore.

>  }
>  


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 26/53] target/tricore: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:29     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:29 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/tricore/cpu.c       |  2 +-
>  target/tricore/cpu.h       |  2 +-
>  target/tricore/translate.c | 24 ++++++++++++------------
>  3 files changed, 14 insertions(+), 14 deletions(-)

> -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");

g_string_append_c(), otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  }
>  
>  /*
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 26/53] target/tricore: convert to use format_state instead of dump_state
@ 2021-09-15  7:29     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:29 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/tricore/cpu.c       |  2 +-
>  target/tricore/cpu.h       |  2 +-
>  target/tricore/translate.c | 24 ++++++++++++------------
>  3 files changed, 14 insertions(+), 14 deletions(-)

> -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");

g_string_append_c(), otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>  }
>  
>  /*
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  7:32     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:32 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/xtensa/cpu.c       |  2 +-
>  target/xtensa/cpu.h       |  2 +-
>  target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
>  3 files changed, 25 insertions(+), 24 deletions(-)

> -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' : ' ');
>      }
>  
>      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().

>  
>      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;
>  
> -            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.

>  
>          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]),
> +                                   *(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).

>          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' : ' ');
>          }
>      }
>  }
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
@ 2021-09-15  7:32     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:32 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/xtensa/cpu.c       |  2 +-
>  target/xtensa/cpu.h       |  2 +-
>  target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
>  3 files changed, 25 insertions(+), 24 deletions(-)

> -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' : ' ');
>      }
>  
>      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().

>  
>      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;
>  
> -            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.

>  
>          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]),
> +                                   *(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).

>          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' : ' ');
>          }
>      }
>  }
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 10/53] target/cris: convert to use format_state instead of dump_state
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-15  7:33     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:33 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/cris/cpu.c       |  2 +-
>  target/cris/cpu.h       |  2 +-
>  target/cris/translate.c | 33 +++++++++++++++++----------------
>  3 files changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/target/cris/cpu.c b/target/cris/cpu.c
> index 70932b1f8c..5159cf6528 100644
> --- a/target/cris/cpu.c
> +++ b/target/cris/cpu.c
> @@ -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;
> diff --git a/target/cris/cpu.h b/target/cris/cpu.h
> index d3b6492909..908cb051da 100644
> --- a/target/cris/cpu.h
> +++ b/target/cris/cpu.h
> @@ -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);
>  
> diff --git a/target/cris/translate.c b/target/cris/translate.c
> index a84b753349..6098693186 100644
> --- a/target/cris/translate.c
> +++ b/target/cris/translate.c
> @@ -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");

g_string_append_c() (various).

>          }
>      }
> -    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");
>  
>  }
>  
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 10/53] target/cris: convert to use format_state instead of dump_state
@ 2021-09-15  7:33     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  7:33 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Eric Blake, Marek Vasut, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Marcel Apfelbaum,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/cris/cpu.c       |  2 +-
>  target/cris/cpu.h       |  2 +-
>  target/cris/translate.c | 33 +++++++++++++++++----------------
>  3 files changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/target/cris/cpu.c b/target/cris/cpu.c
> index 70932b1f8c..5159cf6528 100644
> --- a/target/cris/cpu.c
> +++ b/target/cris/cpu.c
> @@ -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;
> diff --git a/target/cris/cpu.h b/target/cris/cpu.h
> index d3b6492909..908cb051da 100644
> --- a/target/cris/cpu.h
> +++ b/target/cris/cpu.h
> @@ -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);
>  
> diff --git a/target/cris/translate.c b/target/cris/translate.c
> index a84b753349..6098693186 100644
> --- a/target/cris/translate.c
> +++ b/target/cris/translate.c
> @@ -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");

g_string_append_c() (various).

>          }
>      }
> -    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");
>  
>  }
>  
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
  2021-09-15  7:32     ` Philippe Mathieu-Daudé
@ 2021-09-15  7:54       ` Max Filippov
  -1 siblings, 0 replies; 216+ messages in thread
From: Max Filippov @ 2021-09-15  7:54 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Peter Xu, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Edgar E. Iglesias, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	qemu-riscv, Stafford Horne, David Gibson, Daniel P. Berrangé,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Wed, Sep 15, 2021 at 12:32 AM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> >      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.

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

> >      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).

Here as well.

-- 
Thanks.
-- Max


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
@ 2021-09-15  7:54       ` Max Filippov
  0 siblings, 0 replies; 216+ messages in thread
From: Max Filippov @ 2021-09-15  7:54 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Daniel P. Berrangé,
	qemu-devel, Peter Maydell, Chris Wulff, David Hildenbrand,
	Bin Meng, Mark Cave-Ayland, Yuval Shaia, Laurent Vivier,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On Wed, Sep 15, 2021 at 12:32 AM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> >      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.

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

> >      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).

Here as well.

-- 
Thanks.
-- Max


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 49/53] target/xtensa: convert to use format_tlb callback
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-15  8:01     ` Max Filippov
  -1 siblings, 0 replies; 216+ messages in thread
From: Max Filippov @ 2021-09-15  8:01 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Edgar E. Iglesias, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Tue, Sep 14, 2021 at 7:35 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> Change the "info tlb" implementation to use the format_tlb callback.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/xtensa/cpu.h        |   2 +-
>  target/xtensa/mmu_helper.c | 126 +++++++++++++++++++++----------------
>  target/xtensa/monitor.c    |  10 ++-
>  3 files changed, 79 insertions(+), 59 deletions(-)
>
> diff --git a/target/xtensa/mmu_helper.c b/target/xtensa/mmu_helper.c
> index b01ff9399a..d499255984 100644
> --- a/target/xtensa/mmu_helper.c
> +++ b/target/xtensa/mmu_helper.c
> @@ -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) {
>                      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?

>                  }
> -                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)
>  {
>      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?

-- 
Thanks.
-- Max


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 49/53] target/xtensa: convert to use format_tlb callback
@ 2021-09-15  8:01     ` Max Filippov
  0 siblings, 0 replies; 216+ messages in thread
From: Max Filippov @ 2021-09-15  8:01 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Yuval Shaia, Bastian Koppelmann,
	Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff

On Tue, Sep 14, 2021 at 7:35 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> Change the "info tlb" implementation to use the format_tlb callback.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  target/xtensa/cpu.h        |   2 +-
>  target/xtensa/mmu_helper.c | 126 +++++++++++++++++++++----------------
>  target/xtensa/monitor.c    |  10 ++-
>  3 files changed, 79 insertions(+), 59 deletions(-)
>
> diff --git a/target/xtensa/mmu_helper.c b/target/xtensa/mmu_helper.c
> index b01ff9399a..d499255984 100644
> --- a/target/xtensa/mmu_helper.c
> +++ b/target/xtensa/mmu_helper.c
> @@ -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) {
>                      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?

>                  }
> -                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)
>  {
>      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?

-- 
Thanks.
-- Max


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state
  2021-09-15  7:13     ` Philippe Mathieu-Daudé
@ 2021-09-15  8:49       ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-15  8:49 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Wed, Sep 15, 2021 at 09:13:14AM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
> >  1 file changed, 29 insertions(+), 28 deletions(-)
> > 
> > diff --git a/target/avr/cpu.c b/target/avr/cpu.c
> > index ea14175ca5..17ff21f8be 100644
> > --- a/target/avr/cpu.c
> > +++ b/target/avr/cpu.c
> > @@ -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");
> 
> 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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state
@ 2021-09-15  8:49       ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-15  8:49 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Peter Maydell, Chris Wulff, David Hildenbrand,
	Bin Meng, Mark Cave-Ayland, Yuval Shaia, Jiaxun Yang,
	Laurent Vivier, Max Filippov, Taylor Simpson, Alistair Francis,
	Gerd Hoffmann, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Marcel Apfelbaum, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck, qemu-ppc,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On Wed, Sep 15, 2021 at 09:13:14AM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
> >  1 file changed, 29 insertions(+), 28 deletions(-)
> > 
> > diff --git a/target/avr/cpu.c b/target/avr/cpu.c
> > index ea14175ca5..17ff21f8be 100644
> > --- a/target/avr/cpu.c
> > +++ b/target/avr/cpu.c
> > @@ -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");
> 
> 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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
  2021-09-15  7:32     ` Philippe Mathieu-Daudé
@ 2021-09-15  8:52       ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-15  8:52 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Chris Wulff, Laurent Vivier, Palmer Dabbelt,
	Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Wed, Sep 15, 2021 at 09:32:38AM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  target/xtensa/cpu.c       |  2 +-
> >  target/xtensa/cpu.h       |  2 +-
> >  target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
> >  3 files changed, 25 insertions(+), 24 deletions(-)
> 
> > -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' : ' ');
> >      }
> >  
> >      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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
@ 2021-09-15  8:52       ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-15  8:52 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Peter Maydell, Chris Wulff, David Hildenbrand,
	Bin Meng, Mark Cave-Ayland, Yuval Shaia, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, qemu-ppc, Paolo Bonzini,
	Aleksandar Rikalo, Aurelien Jarno

On Wed, Sep 15, 2021 at 09:32:38AM +0200, Philippe Mathieu-Daudé wrote:
> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  target/xtensa/cpu.c       |  2 +-
> >  target/xtensa/cpu.h       |  2 +-
> >  target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
> >  3 files changed, 25 insertions(+), 24 deletions(-)
> 
> > -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' : ' ');
> >      }
> >  
> >      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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state
  2021-09-15  8:49       ` Daniel P. Berrangé
@ 2021-09-15  8:58         ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  8:58 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Eric Blake, Marek Vasut,
	Dr. David Alan Gilbert, Yoshinori Sato, Markus Armbruster,
	Halil Pasic, Christian Borntraeger, Palmer Dabbelt,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck, Laurent Vivier,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/15/21 10:49 AM, Daniel P. Berrangé wrote:
> On Wed, Sep 15, 2021 at 09:13:14AM +0200, Philippe Mathieu-Daudé wrote:
>> On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>> ---
>>>  target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
>>>  1 file changed, 29 insertions(+), 28 deletions(-)
>>>
>>> diff --git a/target/avr/cpu.c b/target/avr/cpu.c
>>> index ea14175ca5..17ff21f8be 100644
>>> --- a/target/avr/cpu.c
>>> +++ b/target/avr/cpu.c
>>> @@ -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");
>>
>> 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 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.
> I'm not convinced it is worth special casing single byte strings to
> use g_string_append_c either really.

OK. R-b stands ;)


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 09/53] target/avr: convert to use format_state instead of dump_state
@ 2021-09-15  8:58         ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  8:58 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Jiaxun Yang, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Marcel Apfelbaum, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On 9/15/21 10:49 AM, Daniel P. Berrangé wrote:
> On Wed, Sep 15, 2021 at 09:13:14AM +0200, Philippe Mathieu-Daudé wrote:
>> On 9/14/21 4:19 PM, Daniel P. Berrangé wrote:
>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>> ---
>>>  target/avr/cpu.c | 57 ++++++++++++++++++++++++------------------------
>>>  1 file changed, 29 insertions(+), 28 deletions(-)
>>>
>>> diff --git a/target/avr/cpu.c b/target/avr/cpu.c
>>> index ea14175ca5..17ff21f8be 100644
>>> --- a/target/avr/cpu.c
>>> +++ b/target/avr/cpu.c
>>> @@ -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");
>>
>> 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 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.
> I'm not convinced it is worth special casing single byte strings to
> use g_string_append_c either really.

OK. R-b stands ;)


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
  2021-09-15  8:52       ` Daniel P. Berrangé
@ 2021-09-15  9:01         ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  9:01 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Dr. David Alan Gilbert, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, Laurent Vivier, qemu-ppc,
	Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 9/15/21 10:52 AM, Daniel P. Berrangé wrote:
> On Wed, Sep 15, 2021 at 09:32:38AM +0200, Philippe Mathieu-Daudé wrote:
>> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>> ---
>>>  target/xtensa/cpu.c       |  2 +-
>>>  target/xtensa/cpu.h       |  2 +-
>>>  target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
>>>  3 files changed, 25 insertions(+), 24 deletions(-)
>>
>>> -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' : ' ');
>>>      }
>>>  
>>>      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.

Fair enough. Max already rejected my suggestions ;) So:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 27/53] target/xtensa: convert to use format_state instead of dump_state
@ 2021-09-15  9:01         ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 216+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  9:01 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Peter Xu, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, qemu-ppc, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm, Michael Rolnik,
	Stafford Horne, David Gibson, qemu-riscv, Bastian Koppelmann,
	Chris Wulff, Laurent Vivier, Palmer Dabbelt, Aurelien Jarno,
	Paolo Bonzini, Aleksandar Rikalo, Dr. David Alan Gilbert

On 9/15/21 10:52 AM, Daniel P. Berrangé wrote:
> On Wed, Sep 15, 2021 at 09:32:38AM +0200, Philippe Mathieu-Daudé wrote:
>> On 9/14/21 4:20 PM, Daniel P. Berrangé wrote:
>>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>>> ---
>>>  target/xtensa/cpu.c       |  2 +-
>>>  target/xtensa/cpu.h       |  2 +-
>>>  target/xtensa/translate.c | 45 ++++++++++++++++++++-------------------
>>>  3 files changed, 25 insertions(+), 24 deletions(-)
>>
>>> -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' : ' ');
>>>      }
>>>  
>>>      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.

Fair enough. Max already rejected my suggestions ;) So:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 25/53] target/sparc: convert to use format_state instead of dump_state
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-16 10:53     ` Mark Cave-Ayland
  -1 siblings, 0 replies; 216+ messages in thread
From: Mark Cave-Ayland @ 2021-09-16 10:53 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Yuval Shaia, Laurent Vivier, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Edgar E. Iglesias, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 14/09/2021 15:20, Daniel P. Berrangé wrote:

> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
>   target/sparc/cpu.h |  2 +-
>   2 files changed, 47 insertions(+), 40 deletions(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index da6b30ec74..9346a79239 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -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
> diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
> index ff8ae73002..65a01a7884 100644
> --- a/target/sparc/cpu.h
> +++ b/target/sparc/cpu.h
> @@ -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);

Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 25/53] target/sparc: convert to use format_state instead of dump_state
@ 2021-09-16 10:53     ` Mark Cave-Ayland
  0 siblings, 0 replies; 216+ messages in thread
From: Mark Cave-Ayland @ 2021-09-16 10:53 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Paolo Bonzini,
	qemu-arm, Michael Rolnik, Peter Maydell, Palmer Dabbelt,
	Alistair Francis, Halil Pasic, Taylor Simpson, Gerd Hoffmann,
	qemu-riscv, Max Filippov, Yuval Shaia, Bastian Koppelmann,
	Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff

On 14/09/2021 15:20, Daniel P. Berrangé wrote:

> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   target/sparc/cpu.c | 85 +++++++++++++++++++++++++---------------------
>   target/sparc/cpu.h |  2 +-
>   2 files changed, 47 insertions(+), 40 deletions(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index da6b30ec74..9346a79239 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -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
> diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
> index ff8ae73002..65a01a7884 100644
> --- a/target/sparc/cpu.h
> +++ b/target/sparc/cpu.h
> @@ -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);

Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 48/53] target/sparc: convert to use format_tlb callback
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-16 10:54     ` Mark Cave-Ayland
  -1 siblings, 0 replies; 216+ messages in thread
From: Mark Cave-Ayland @ 2021-09-16 10:54 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Yuval Shaia, Laurent Vivier, Max Filippov, Taylor Simpson,
	Alistair Francis, Gerd Hoffmann, Edgar E. Iglesias, Eric Blake,
	Marek Vasut, Yoshinori Sato, Markus Armbruster, Halil Pasic,
	Christian Borntraeger, Palmer Dabbelt, Artyom Tarasenko,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Richard Henderson,
	Greg Kurz, Dr. David Alan Gilbert, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On 14/09/2021 15:20, Daniel P. Berrangé wrote:

> Change the "info tlb" implementation to use the format_tlb callback.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   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(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index 9346a79239..f78ddc72b5 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -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;
> diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
> index 65a01a7884..233f0b3eb7 100644
> --- a/target/sparc/cpu.h
> +++ b/target/sparc/cpu.h
> @@ -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);
> diff --git a/target/sparc/mmu_helper.c b/target/sparc/mmu_helper.c
> index a44473a1c7..06b16aca6a 100644
> --- a/target/sparc/mmu_helper.c
> +++ b/target/sparc/mmu_helper.c
> @@ -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.
> diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c
> index 318413686a..cc7fe74e3e 100644
> --- a/target/sparc/monitor.c
> +++ b/target/sparc/monitor.c
> @@ -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

Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 48/53] target/sparc: convert to use format_tlb callback
@ 2021-09-16 10:54     ` Mark Cave-Ayland
  0 siblings, 0 replies; 216+ messages in thread
From: Mark Cave-Ayland @ 2021-09-16 10:54 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Paolo Bonzini,
	qemu-arm, Michael Rolnik, Peter Maydell, Palmer Dabbelt,
	Alistair Francis, Halil Pasic, Taylor Simpson, Gerd Hoffmann,
	qemu-riscv, Max Filippov, Yuval Shaia, Bastian Koppelmann,
	Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff

On 14/09/2021 15:20, Daniel P. Berrangé wrote:

> Change the "info tlb" implementation to use the format_tlb callback.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   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(-)
> 
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index 9346a79239..f78ddc72b5 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -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;
> diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
> index 65a01a7884..233f0b3eb7 100644
> --- a/target/sparc/cpu.h
> +++ b/target/sparc/cpu.h
> @@ -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);
> diff --git a/target/sparc/mmu_helper.c b/target/sparc/mmu_helper.c
> index a44473a1c7..06b16aca6a 100644
> --- a/target/sparc/mmu_helper.c
> +++ b/target/sparc/mmu_helper.c
> @@ -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.
> diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c
> index 318413686a..cc7fe74e3e 100644
> --- a/target/sparc/monitor.c
> +++ b/target/sparc/monitor.c
> @@ -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

Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 01/53] docs/devel: rename file for writing monitor commands
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-20  7:42     ` Markus Armbruster
  -1 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  7:42 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Halil Pasic, Christian Borntraeger, Palmer Dabbelt,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

Daniel P. Berrangé <berrange@redhat.com> writes:

> The file already covers writing new style HMP commands, in addition to
> the QMP commands, so it deserves a more general name.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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%)
>
> diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> index f95df10b3e..7c25177c5d 100644
> --- a/docs/devel/index.rst
> +++ b/docs/devel/index.rst
> @@ -44,4 +44,4 @@ modifying QEMU's source code.
>     ebpf_rss
>     vfio-migration
>     qapi-code-gen
> -   writing-qmp-commands
> +   writing-monitor-commands
> diff --git a/docs/devel/writing-qmp-commands.rst b/docs/devel/writing-monitor-commands.rst
> similarity index 99%
> rename from docs/devel/writing-qmp-commands.rst
> rename to docs/devel/writing-monitor-commands.rst
> index 6a10a06c48..497c9ce0d5 100644
> --- a/docs/devel/writing-qmp-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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.

>  This document doesn't discuss QMP protocol level details, nor does it dive
>  into the QAPI framework implementation.



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 01/53] docs/devel: rename file for writing monitor commands
@ 2021-09-20  7:42     ` Markus Armbruster
  0 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  7:42 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

Daniel P. Berrangé <berrange@redhat.com> writes:

> The file already covers writing new style HMP commands, in addition to
> the QMP commands, so it deserves a more general name.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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%)
>
> diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> index f95df10b3e..7c25177c5d 100644
> --- a/docs/devel/index.rst
> +++ b/docs/devel/index.rst
> @@ -44,4 +44,4 @@ modifying QEMU's source code.
>     ebpf_rss
>     vfio-migration
>     qapi-code-gen
> -   writing-qmp-commands
> +   writing-monitor-commands
> diff --git a/docs/devel/writing-qmp-commands.rst b/docs/devel/writing-monitor-commands.rst
> similarity index 99%
> rename from docs/devel/writing-qmp-commands.rst
> rename to docs/devel/writing-monitor-commands.rst
> index 6a10a06c48..497c9ce0d5 100644
> --- a/docs/devel/writing-qmp-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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.

>  This document doesn't discuss QMP protocol level details, nor does it dive
>  into the QAPI framework implementation.



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 02/53] docs/devel: tweak headings in monitor command docs
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-20  7:42     ` Markus Armbruster
  -1 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  7:42 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Halil Pasic, Christian Borntraeger, Palmer Dabbelt,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

Daniel P. Berrangé <berrange@redhat.com> writes:

> The new headings reflect the intended structure of the document and will
> better suit additions that follow.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/devel/writing-monitor-commands.rst | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index 497c9ce0d5..cddb36fb74 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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.

Reviewed-by: Markus Armbruster <armbru@redhat.com>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 02/53] docs/devel: tweak headings in monitor command docs
@ 2021-09-20  7:42     ` Markus Armbruster
  0 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  7:42 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

Daniel P. Berrangé <berrange@redhat.com> writes:

> The new headings reflect the intended structure of the document and will
> better suit additions that follow.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/devel/writing-monitor-commands.rst | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index 497c9ce0d5..cddb36fb74 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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.

Reviewed-by: Markus Armbruster <armbru@redhat.com>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 03/53] docs/devel: document expectations for QAPI data modelling for QMP
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-20  7:44     ` Markus Armbruster
  -1 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  7:44 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz, Yuval Shaia,
	qemu-s390x, qemu-arm, Michael Rolnik, Peter Xu, Stafford Horne,
	David Gibson, qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

Daniel P. Berrangé <berrange@redhat.com> writes:

> Traditionally we have required that newly added QMP commands will model
> any returned data using fine grained QAPI types. This is good for
> commands that are intended to be consumed by machines, where clear data
> representation is very important. Commands that don't satisfy this have
> generally been added to HMP only.
>
> In effect the decision of whether to add a new command to QMP vs HMP has
> been used as a proxy for the decision of whether the cost of designing a
> fine grained QAPI type is justified by the potential benefits.
>
> As a result the commands present in QMP and HMP are non-overlapping
> sets, although HMP comamnds can be accessed indirectly via the QMP
> command 'human-monitor-command'.
>
> One of the downsides of 'human-monitor-command' is that the QEMU monitor
> APIs remain tied into various internal parts of the QEMU code. For
> example any exclusively HMP command will need to use 'monitor_printf'
> to get data out. It would be desirable to be able to fully isolate the
> monitor implementation from QEMU internals, however, this is only
> possible if all commands are exclusively based on QAPI with direct
> QMP exposure.
>
> The way to achieve this desired end goal is to finese the requirements
> for QMP command design. For cases where the output of a command is only
> intended for human consumption, it is reasonable to want to simplify
> the implementation by returning a plain string containing formatted
> data instead of designing a fine grained QAPI data type. This can be
> permitted if-and-only-if the command is exposed under the 'x-' name
> prefix. This indicates that the command data format is liable to
> future change and that it is not following QAPI design best practice.
>
> The poster child example for this would be the 'info registers' HMP
> command which returns printf formatted data representing CPU state.
> This information varies enourmously across target architectures and
> changes relatively frequently as new CPU features are implemented.
> It is there as debugging data for human operators, and any machine
> usage would treat it as an opaque blob. It is thus reasonable to
> expose this in QMP as 'x-query-registers' returning a 'str' field.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/devel/writing-monitor-commands.rst | 27 +++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index cddb36fb74..d68c552fdd 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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
>  ~~~~~~~~~~~~~~~~~~

Reviewed-by: Markus Armbruster <armbru@redhat.com>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 03/53] docs/devel: document expectations for QAPI data modelling for QMP
@ 2021-09-20  7:44     ` Markus Armbruster
  0 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  7:44 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Markus Armbruster, Aurelien Jarno, qemu-s390x,
	Laurent Vivier, Eric Blake, Richard Henderson, Chris Wulff

Daniel P. Berrangé <berrange@redhat.com> writes:

> Traditionally we have required that newly added QMP commands will model
> any returned data using fine grained QAPI types. This is good for
> commands that are intended to be consumed by machines, where clear data
> representation is very important. Commands that don't satisfy this have
> generally been added to HMP only.
>
> In effect the decision of whether to add a new command to QMP vs HMP has
> been used as a proxy for the decision of whether the cost of designing a
> fine grained QAPI type is justified by the potential benefits.
>
> As a result the commands present in QMP and HMP are non-overlapping
> sets, although HMP comamnds can be accessed indirectly via the QMP
> command 'human-monitor-command'.
>
> One of the downsides of 'human-monitor-command' is that the QEMU monitor
> APIs remain tied into various internal parts of the QEMU code. For
> example any exclusively HMP command will need to use 'monitor_printf'
> to get data out. It would be desirable to be able to fully isolate the
> monitor implementation from QEMU internals, however, this is only
> possible if all commands are exclusively based on QAPI with direct
> QMP exposure.
>
> The way to achieve this desired end goal is to finese the requirements
> for QMP command design. For cases where the output of a command is only
> intended for human consumption, it is reasonable to want to simplify
> the implementation by returning a plain string containing formatted
> data instead of designing a fine grained QAPI data type. This can be
> permitted if-and-only-if the command is exposed under the 'x-' name
> prefix. This indicates that the command data format is liable to
> future change and that it is not following QAPI design best practice.
>
> The poster child example for this would be the 'info registers' HMP
> command which returns printf formatted data representing CPU state.
> This information varies enourmously across target architectures and
> changes relatively frequently as new CPU features are implemented.
> It is there as debugging data for human operators, and any machine
> usage would treat it as an opaque blob. It is thus reasonable to
> expose this in QMP as 'x-query-registers' returning a 'str' field.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/devel/writing-monitor-commands.rst | 27 +++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index cddb36fb74..d68c552fdd 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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
>  ~~~~~~~~~~~~~~~~~~

Reviewed-by: Markus Armbruster <armbru@redhat.com>



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 04/53] docs/devel: add example of command returning unstructured text
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-20  7:51     ` Markus Armbruster
  -1 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  7:51 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Halil Pasic, Christian Borntraeger, Palmer Dabbelt,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

Daniel P. Berrangé <berrange@redhat.com> writes:

> 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'.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/devel/writing-monitor-commands.rst | 85 +++++++++++++++++++++++++
>  1 file changed, 85 insertions(+)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index d68c552fdd..4cf51ab557 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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.

[...]
>  
>       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"'.

> +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);

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

> +     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,
> +    },



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 04/53] docs/devel: add example of command returning unstructured text
@ 2021-09-20  7:51     ` Markus Armbruster
  0 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  7:51 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

Daniel P. Berrangé <berrange@redhat.com> writes:

> 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'.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/devel/writing-monitor-commands.rst | 85 +++++++++++++++++++++++++
>  1 file changed, 85 insertions(+)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index d68c552fdd..4cf51ab557 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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.

[...]
>  
>       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"'.

> +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);

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

> +     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,
> +    },



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future
  2021-09-14 14:19   ` Daniel P. Berrangé
@ 2021-09-20  8:06     ` Markus Armbruster
  -1 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  8:06 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Halil Pasic, Christian Borntraeger, Palmer Dabbelt,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

Daniel P. Berrangé <berrange@redhat.com> writes:

> 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.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/devel/writing-monitor-commands.rst | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index 4cf51ab557..983130a793 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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

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.

> +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.

> +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.



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future
@ 2021-09-20  8:06     ` Markus Armbruster
  0 siblings, 0 replies; 216+ messages in thread
From: Markus Armbruster @ 2021-09-20  8:06 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

Daniel P. Berrangé <berrange@redhat.com> writes:

> 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.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/devel/writing-monitor-commands.rst | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index 4cf51ab557..983130a793 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -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

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.

> +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.

> +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.



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command
  2021-09-14 14:20   ` Daniel P. Berrangé
@ 2021-09-21  5:27     ` Dongli Zhang
  -1 siblings, 0 replies; 216+ messages in thread
From: Dongli Zhang @ 2021-09-21  5:27 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Cornelia Huck, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Peter Xu,
	Philippe Mathieu-Daudé,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Hi Daniel,

On 9/14/21 7:20 AM, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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(-)
> 
> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
> index c2cd33a817..d1ebc77d1b 100644
> --- a/hw/core/cpu-common.c
> +++ b/hw/core/cpu-common.c
> @@ -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);
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 1599ef9df3..a0913eedaa 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -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.
> diff --git a/qapi/machine-target.json b/qapi/machine-target.json
> index 9040aff863..62220d1f08 100644
> --- a/qapi/machine-target.json
> +++ b/qapi/machine-target.json
> @@ -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:
>  #
> diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c
> index f30fbcb76e..41a1f64138 100644
> --- a/target/i386/cpu-dump.c
> +++ b/target/i386/cpu-dump.c
> @@ -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 */
>  
> diff --git a/target/i386/cpu.h b/target/i386/cpu.h
> index d87c8808f6..2bcb175da8 100644
> --- a/target/i386/cpu.h
> +++ b/target/i386/cpu.h
> @@ -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);
> diff --git a/target/i386/monitor.c b/target/i386/monitor.c
> index 19468c4e85..fc09f90059 100644
> --- a/target/i386/monitor.c
> +++ b/target/i386/monitor.c
> @@ -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,
> +                                           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/20210908143803.29191-1-dongli.zhang@oracle.com/

> +
> +    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)
>  {
> -    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

>      } 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)
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command
@ 2021-09-21  5:27     ` Dongli Zhang
  0 siblings, 0 replies; 216+ messages in thread
From: Dongli Zhang @ 2021-09-21  5:27 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, Yuval Shaia, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz,
	Dr. David Alan Gilbert, qemu-s390x, qemu-arm, Michael Rolnik,
	Peter Xu, Stafford Horne, David Gibson, qemu-riscv,
	Bastian Koppelmann, Cornelia Huck, Philippe Mathieu-Daudé,
	qemu-ppc, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

Hi Daniel,

On 9/14/21 7:20 AM, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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(-)
> 
> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
> index c2cd33a817..d1ebc77d1b 100644
> --- a/hw/core/cpu-common.c
> +++ b/hw/core/cpu-common.c
> @@ -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);
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 1599ef9df3..a0913eedaa 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -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.
> diff --git a/qapi/machine-target.json b/qapi/machine-target.json
> index 9040aff863..62220d1f08 100644
> --- a/qapi/machine-target.json
> +++ b/qapi/machine-target.json
> @@ -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:
>  #
> diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c
> index f30fbcb76e..41a1f64138 100644
> --- a/target/i386/cpu-dump.c
> +++ b/target/i386/cpu-dump.c
> @@ -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 */
>  
> diff --git a/target/i386/cpu.h b/target/i386/cpu.h
> index d87c8808f6..2bcb175da8 100644
> --- a/target/i386/cpu.h
> +++ b/target/i386/cpu.h
> @@ -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);
> diff --git a/target/i386/monitor.c b/target/i386/monitor.c
> index 19468c4e85..fc09f90059 100644
> --- a/target/i386/monitor.c
> +++ b/target/i386/monitor.c
> @@ -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,
> +                                           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/20210908143803.29191-1-dongli.zhang@oracle.com/

> +
> +    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)
>  {
> -    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

>      } 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)
> 


^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 01/53] docs/devel: rename file for writing monitor commands
  2021-09-20  7:42     ` Markus Armbruster
@ 2021-09-22 16:02       ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-22 16:02 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Halil Pasic, Christian Borntraeger, Palmer Dabbelt,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Mon, Sep 20, 2021 at 09:42:02AM +0200, Markus Armbruster wrote:
> Daniel P. Berrangé <berrange@redhat.com> writes:
> 
> > The file already covers writing new style HMP commands, in addition to
> > the QMP commands, so it deserves a more general name.
> >
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  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%)
> >
> > diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> > index f95df10b3e..7c25177c5d 100644
> > --- a/docs/devel/index.rst
> > +++ b/docs/devel/index.rst
> > @@ -44,4 +44,4 @@ modifying QEMU's source code.
> >     ebpf_rss
> >     vfio-migration
> >     qapi-code-gen
> > -   writing-qmp-commands
> > +   writing-monitor-commands
> > diff --git a/docs/devel/writing-qmp-commands.rst b/docs/devel/writing-monitor-commands.rst
> > similarity index 99%
> > rename from docs/devel/writing-qmp-commands.rst
> > rename to docs/devel/writing-monitor-commands.rst
> > index 6a10a06c48..497c9ce0d5 100644
> > --- a/docs/devel/writing-qmp-commands.rst
> > +++ b/docs/devel/writing-monitor-commands.rst
> > @@ -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.

Ok, will do.

Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 01/53] docs/devel: rename file for writing monitor commands
@ 2021-09-22 16:02       ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-22 16:02 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

On Mon, Sep 20, 2021 at 09:42:02AM +0200, Markus Armbruster wrote:
> Daniel P. Berrangé <berrange@redhat.com> writes:
> 
> > The file already covers writing new style HMP commands, in addition to
> > the QMP commands, so it deserves a more general name.
> >
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  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%)
> >
> > diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> > index f95df10b3e..7c25177c5d 100644
> > --- a/docs/devel/index.rst
> > +++ b/docs/devel/index.rst
> > @@ -44,4 +44,4 @@ modifying QEMU's source code.
> >     ebpf_rss
> >     vfio-migration
> >     qapi-code-gen
> > -   writing-qmp-commands
> > +   writing-monitor-commands
> > diff --git a/docs/devel/writing-qmp-commands.rst b/docs/devel/writing-monitor-commands.rst
> > similarity index 99%
> > rename from docs/devel/writing-qmp-commands.rst
> > rename to docs/devel/writing-monitor-commands.rst
> > index 6a10a06c48..497c9ce0d5 100644
> > --- a/docs/devel/writing-qmp-commands.rst
> > +++ b/docs/devel/writing-monitor-commands.rst
> > @@ -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.

Ok, will do.

Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future
  2021-09-20  8:06     ` Markus Armbruster
@ 2021-09-22 16:14       ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-22 16:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Laurent Vivier, Max Filippov,
	Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Halil Pasic, Christian Borntraeger, Palmer Dabbelt,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Yuval Shaia, qemu-s390x, qemu-arm,
	Michael Rolnik, Peter Xu, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Mon, Sep 20, 2021 at 10:06:35AM +0200, Markus Armbruster wrote:
> Daniel P. Berrangé <berrange@redhat.com> writes:
> 
> > 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.
> >
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  docs/devel/writing-monitor-commands.rst | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> > index 4cf51ab557..983130a793 100644
> > --- a/docs/devel/writing-monitor-commands.rst
> > +++ b/docs/devel/writing-monitor-commands.rst
> > @@ -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
> 
> 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.
> 
> > +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.
> 
> > +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.

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

Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future
@ 2021-09-22 16:14       ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-22 16:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, Greg Kurz, Bin Meng, Yoshinori Sato, Stafford Horne,
	Cornelia Huck, David Hildenbrand, Edgar E. Iglesias, Jiaxun Yang,
	Peter Xu, Christian Borntraeger, qemu-ppc, Mark Cave-Ayland,
	Paolo Bonzini, qemu-arm, Michael Rolnik, Peter Maydell,
	Palmer Dabbelt, Alistair Francis, Halil Pasic, Taylor Simpson,
	Gerd Hoffmann, qemu-riscv, Max Filippov, Yuval Shaia,
	Bastian Koppelmann, Artyom Tarasenko, Philippe Mathieu-Daudé,
	Thomas Huth, Aleksandar Rikalo, David Gibson, Marcel Apfelbaum,
	Laurent Vivier, Dr. David Alan Gilbert, Eduardo Habkost,
	Marek Vasut, Aurelien Jarno, qemu-s390x, Laurent Vivier,
	Eric Blake, Richard Henderson, Chris Wulff

On Mon, Sep 20, 2021 at 10:06:35AM +0200, Markus Armbruster wrote:
> Daniel P. Berrangé <berrange@redhat.com> writes:
> 
> > 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.
> >
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  docs/devel/writing-monitor-commands.rst | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> > index 4cf51ab557..983130a793 100644
> > --- a/docs/devel/writing-monitor-commands.rst
> > +++ b/docs/devel/writing-monitor-commands.rst
> > @@ -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
> 
> 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.
> 
> > +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.
> 
> > +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.

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

Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command
  2021-09-21  5:27     ` Dongli Zhang
@ 2021-09-22 16:30       ` Daniel P. Berrangé
  -1 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-22 16:30 UTC (permalink / raw)
  To: Dongli Zhang
  Cc: Peter Maydell, Chris Wulff, David Hildenbrand, Bin Meng,
	Mark Cave-Ayland, qemu-devel, Peter Xu, Laurent Vivier,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger,
	Palmer Dabbelt, Artyom Tarasenko, Laurent Vivier, Thomas Huth,
	Eduardo Habkost, Richard Henderson, Greg Kurz, Yuval Shaia,
	qemu-s390x, qemu-arm, Michael Rolnik, Stafford Horne,
	David Gibson, qemu-riscv, Bastian Koppelmann, Cornelia Huck,
	Philippe Mathieu-Daudé,
	qemu-ppc, Aurelien Jarno, Paolo Bonzini, Aleksandar Rikalo,
	Dr. David Alan Gilbert

On Mon, Sep 20, 2021 at 10:27:06PM -0700, Dongli Zhang wrote:
> Hi Daniel,
> 
> On 9/14/21 7:20 AM, Daniel P. Berrangé wrote:
> > 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.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  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(-)


> > diff --git a/target/i386/monitor.c b/target/i386/monitor.c
> > index 19468c4e85..fc09f90059 100644
> > --- a/target/i386/monitor.c
> > +++ b/target/i386/monitor.c
> > @@ -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,
> > +                                           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/20210908143803.29191-1-dongli.zhang@oracle.com/

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.

> 
> > +
> > +    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)
> >  {
> > -    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
> 
> >      } 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)
> > 
> 

Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

* Re: [PATCH v2 38/53] qapi: introduce x-query-lapic QMP command
@ 2021-09-22 16:30       ` Daniel P. Berrangé
  0 siblings, 0 replies; 216+ messages in thread
From: Daniel P. Berrangé @ 2021-09-22 16:30 UTC (permalink / raw)
  To: Dongli Zhang
  Cc: qemu-devel, Peter Maydell, Cornelia Huck, David Hildenbrand,
	Bin Meng, Mark Cave-Ayland, Yuval Shaia, Peter Xu,
	Philippe Mathieu-Daudé,
	Max Filippov, Taylor Simpson, Alistair Francis, Gerd Hoffmann,
	Edgar E. Iglesias, Eric Blake, Marek Vasut, Yoshinori Sato,
	Markus Armbruster, Halil Pasic, Christian Borntraeger, qemu-ppc,
	Artyom Tarasenko, Laurent Vivier, Thomas Huth, Eduardo Habkost,
	Richard Henderson, Greg Kurz, Dr. David Alan Gilbert, qemu-s390x,
	qemu-arm, Michael Rolnik, Stafford Horne, David Gibson,
	qemu-riscv, Bastian Koppelmann, Chris Wulff, Laurent Vivier,
	Palmer Dabbelt, Paolo Bonzini, Aleksandar Rikalo, Aurelien Jarno

On Mon, Sep 20, 2021 at 10:27:06PM -0700, Dongli Zhang wrote:
> Hi Daniel,
> 
> On 9/14/21 7:20 AM, Daniel P. Berrangé wrote:
> > 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.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  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(-)


> > diff --git a/target/i386/monitor.c b/target/i386/monitor.c
> > index 19468c4e85..fc09f90059 100644
> > --- a/target/i386/monitor.c
> > +++ b/target/i386/monitor.c
> > @@ -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,
> > +                                           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/20210908143803.29191-1-dongli.zhang@oracle.com/

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.

> 
> > +
> > +    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)
> >  {
> > -    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
> 
> >      } 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)
> > 
> 

Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 216+ messages in thread

end of thread, other threads:[~2021-09-22 16:48 UTC | newest]

Thread overview: 216+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 14:19 [PATCH v2 00/53] monitor: explicitly permit QMP commands to be added for all use cases Daniel P. Berrangé
2021-09-14 14:19 ` Daniel P. Berrangé
2021-09-14 14:19 ` [PATCH v2 01/53] docs/devel: rename file for writing monitor commands Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-20  7:42   ` Markus Armbruster
2021-09-20  7:42     ` Markus Armbruster
2021-09-22 16:02     ` Daniel P. Berrangé
2021-09-22 16:02       ` Daniel P. Berrangé
2021-09-14 14:19 ` [PATCH v2 02/53] docs/devel: tweak headings in monitor command docs Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-20  7:42   ` Markus Armbruster
2021-09-20  7:42     ` Markus Armbruster
2021-09-14 14:19 ` [PATCH v2 03/53] docs/devel: document expectations for QAPI data modelling for QMP Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-20  7:44   ` Markus Armbruster
2021-09-20  7:44     ` Markus Armbruster
2021-09-14 14:19 ` [PATCH v2 04/53] docs/devel: add example of command returning unstructured text Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-20  7:51   ` Markus Armbruster
2021-09-20  7:51     ` Markus Armbruster
2021-09-14 14:19 ` [PATCH v2 05/53] docs/devel: document expectations for HMP commands in the future Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-20  8:06   ` Markus Armbruster
2021-09-20  8:06     ` Markus Armbruster
2021-09-22 16:14     ` Daniel P. Berrangé
2021-09-22 16:14       ` Daniel P. Berrangé
2021-09-14 14:19 ` [PATCH v2 06/53] hw/core: introduce 'format_state' callback to replace 'dump_state' Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-14 15:53   ` Philippe Mathieu-Daudé
2021-09-14 15:53     ` Philippe Mathieu-Daudé
2021-09-14 19:28   ` Greg Kurz
2021-09-14 19:28     ` Greg Kurz
2021-09-14 14:19 ` [PATCH v2 07/53] target/alpha: convert to use format_state instead of dump_state Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-15  7:10   ` Philippe Mathieu-Daudé
2021-09-15  7:10     ` Philippe Mathieu-Daudé
2021-09-14 14:19 ` [PATCH v2 08/53] target/arm: " Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-14 14:19 ` [PATCH v2 09/53] target/avr: " Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-15  7:13   ` Philippe Mathieu-Daudé
2021-09-15  7:13     ` Philippe Mathieu-Daudé
2021-09-15  8:49     ` Daniel P. Berrangé
2021-09-15  8:49       ` Daniel P. Berrangé
2021-09-15  8:58       ` Philippe Mathieu-Daudé
2021-09-15  8:58         ` Philippe Mathieu-Daudé
2021-09-14 14:19 ` [PATCH v2 10/53] target/cris: " Daniel P. Berrangé
2021-09-14 14:19   ` Daniel P. Berrangé
2021-09-15  7:33   ` Philippe Mathieu-Daudé
2021-09-15  7:33     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 11/53] target/hexagon: delete unused hexagon_debug() method Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:50   ` Taylor Simpson
2021-09-14 14:50     ` Taylor Simpson
2021-09-15  7:00   ` Philippe Mathieu-Daudé
2021-09-15  7:00     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 12/53] target/hexagon: convert to use format_state instead of dump_state Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:14   ` Philippe Mathieu-Daudé
2021-09-15  7:14     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 13/53] target/hppa: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:15   ` Philippe Mathieu-Daudé
2021-09-15  7:15     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 14/53] target/i386: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 15/53] target/m68k: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 19:58   ` Laurent Vivier
2021-09-14 19:58     ` Laurent Vivier
2021-09-15  7:17   ` Philippe Mathieu-Daudé
2021-09-15  7:17     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 16/53] target/microblaze: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:18   ` Philippe Mathieu-Daudé
2021-09-15  7:18     ` Philippe Mathieu-Daudé
2021-09-15  7:21     ` Philippe Mathieu-Daudé
2021-09-15  7:21       ` Philippe Mathieu-Daudé
2021-09-15  7:23       ` Philippe Mathieu-Daudé
2021-09-15  7:23         ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 17/53] target/mips: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:04   ` Philippe Mathieu-Daudé
2021-09-15  7:04     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 18/53] target/nios2: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:08   ` Philippe Mathieu-Daudé
2021-09-15  7:08     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 19/53] target/openrisc: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:19   ` Philippe Mathieu-Daudé
2021-09-15  7:19     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 20/53] target/ppc: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 19:30   ` Greg Kurz
2021-09-14 19:30     ` Greg Kurz
2021-09-15  1:37   ` David Gibson
2021-09-15  1:37     ` David Gibson
2021-09-14 14:20 ` [PATCH v2 21/53] target/riscv: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 22/53] target/rx: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:20   ` Philippe Mathieu-Daudé
2021-09-15  7:20     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 23/53] target/s390x: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 24/53] target/sh: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:24   ` Philippe Mathieu-Daudé
2021-09-15  7:24     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 25/53] target/sparc: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:27   ` Philippe Mathieu-Daudé
2021-09-15  7:27     ` Philippe Mathieu-Daudé
2021-09-16 10:53   ` Mark Cave-Ayland
2021-09-16 10:53     ` Mark Cave-Ayland
2021-09-14 14:20 ` [PATCH v2 26/53] target/tricore: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:29   ` Philippe Mathieu-Daudé
2021-09-15  7:29     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 27/53] target/xtensa: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  7:32   ` Philippe Mathieu-Daudé
2021-09-15  7:32     ` Philippe Mathieu-Daudé
2021-09-15  7:54     ` Max Filippov
2021-09-15  7:54       ` Max Filippov
2021-09-15  8:52     ` Daniel P. Berrangé
2021-09-15  8:52       ` Daniel P. Berrangé
2021-09-15  9:01       ` Philippe Mathieu-Daudé
2021-09-15  9:01         ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 28/53] monitor: remove 'info ioapic' HMP command Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 15:50   ` Philippe Mathieu-Daudé
2021-09-14 15:50     ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 29/53] qapi: introduce x-query-registers QMP command Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 16:04   ` Eric Blake
2021-09-14 16:04     ` Eric Blake
2021-09-14 17:15     ` Philippe Mathieu-Daudé
2021-09-14 17:15       ` Philippe Mathieu-Daudé
2021-09-14 17:18       ` Philippe Mathieu-Daudé
2021-09-14 17:18         ` Philippe Mathieu-Daudé
2021-09-14 14:20 ` [PATCH v2 30/53] qapi: introduce x-query-roms " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 16:04   ` Philippe Mathieu-Daudé
2021-09-14 16:04     ` Philippe Mathieu-Daudé
2021-09-14 16:42     ` Daniel P. Berrangé
2021-09-14 16:42       ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 31/53] qapi: introduce x-query-profile " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 32/53] qapi: introduce x-query-numa " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 33/53] qapi: introduce x-query-usb " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 34/53] qapi: introduce x-query-rdma " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 35/53] qapi: introduce x-query-ramblock " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 36/53] qapi: introduce x-query-skeys " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 37/53] qapi: introduce x-query-cmma " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 38/53] qapi: introduce x-query-lapic " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-21  5:27   ` Dongli Zhang
2021-09-21  5:27     ` Dongli Zhang
2021-09-22 16:30     ` Daniel P. Berrangé
2021-09-22 16:30       ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 39/53] qapi: introduce x-query-irq " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 40/53] hw/core: drop "dump_state" callback from CPU targets Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 41/53] hw/core: drop support for NULL pointer for FILE * in cpu_dump_state Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 15:56   ` Philippe Mathieu-Daudé
2021-09-14 15:56     ` Philippe Mathieu-Daudé
2021-09-14 16:34     ` Daniel P. Berrangé
2021-09-14 16:34       ` Daniel P. Berrangé
2021-09-14 17:02       ` Philippe Mathieu-Daudé
2021-09-14 17:02         ` Philippe Mathieu-Daudé
2021-09-14 17:12         ` Daniel P. Berrangé
2021-09-14 17:12           ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 43/53] target/i386: convert to use format_tlb callback Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 44/53] target/m68k: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 19:59   ` Laurent Vivier
2021-09-14 19:59     ` Laurent Vivier
2021-09-14 14:20 ` [PATCH v2 45/53] target/nios2: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 46/53] target/ppc: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  1:40   ` David Gibson
2021-09-15  1:40     ` David Gibson
2021-09-14 14:20 ` [PATCH v2 47/53] target/sh4: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 48/53] target/sparc: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-16 10:54   ` Mark Cave-Ayland
2021-09-16 10:54     ` Mark Cave-Ayland
2021-09-14 14:20 ` [PATCH v2 49/53] target/xtensa: " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  8:01   ` Max Filippov
2021-09-15  8:01     ` Max Filippov
2021-09-14 14:20 ` [PATCH v2 50/53] monitor: merge duplicate "info tlb" handlers Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-15  1:41   ` David Gibson
2021-09-15  1:41     ` David Gibson
2021-09-14 14:20 ` [PATCH v2 51/53] qapi: introduce x-query-tlb QMP command Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 52/53] qapi: introduce x-query-jit " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé
2021-09-14 14:20 ` [PATCH v2 53/53] qapi: introduce x-query-opcount " Daniel P. Berrangé
2021-09-14 14:20   ` Daniel P. Berrangé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.