[PATCH v8 00/19] plugins: Allow to read registers

Akihiko Odaki posted 19 patches 9 months, 1 week ago
Failed in applying to current master (apply log)
There is a newer version of this series
docs/devel/tcg-plugins.rst   |  18 ++-
configure                    |  15 ++-
include/exec/gdbstub.h       |  39 ++++++-
include/hw/core/cpu.h        |   7 +-
include/qemu/qemu-plugin.h   |  56 ++++++++-
target/arm/cpu.h             |  27 ++---
target/arm/internals.h       |  14 +--
target/hexagon/internal.h    |   4 +-
target/microblaze/cpu.h      |   4 +-
target/ppc/cpu-qom.h         |   4 +-
target/ppc/cpu.h             |   3 +-
target/riscv/cpu.h           |   5 +-
target/s390x/cpu.h           |   2 -
contrib/plugins/execlog.c    | 120 ++++++++++++++-----
cpu.c                        |  11 --
gdbstub/gdbstub.c            | 216 ++++++++++++++++++++++++++--------
hw/core/cpu-common.c         |  15 ++-
plugins/api.c                |  20 ++++
target/arm/cpu.c             |   2 -
target/arm/cpu64.c           |   1 -
target/arm/gdbstub.c         | 221 +++++++++++++++++------------------
target/arm/gdbstub64.c       | 117 +++++++++----------
target/avr/cpu.c             |   1 -
target/hexagon/cpu.c         |   4 +-
target/hexagon/gdbstub.c     |  10 +-
target/i386/cpu.c            |   2 -
target/loongarch/cpu.c       |   2 -
target/loongarch/gdbstub.c   |  13 ++-
target/m68k/cpu.c            |   1 -
target/m68k/helper.c         |  26 +++--
target/microblaze/cpu.c      |   6 +-
target/microblaze/gdbstub.c  |   9 +-
target/ppc/cpu_init.c        |   5 +-
target/ppc/gdbstub.c         | 108 ++++++++---------
target/riscv/cpu.c           |  15 ---
target/riscv/gdbstub.c       | 135 +++++++++++----------
target/rx/cpu.c              |   1 -
target/s390x/cpu.c           |   1 -
target/s390x/gdbstub.c       | 105 ++++++++++-------
contrib/plugins/Makefile     |   5 +
contrib/plugins/cc.cc        |  17 +++
plugins/qemu-plugins.symbols |   3 +
scripts/feature_to_c.py      |  58 ++++++++-
tests/tcg/Makefile.target    |   3 +
44 files changed, 921 insertions(+), 530 deletions(-)
create mode 100644 contrib/plugins/cc.cc
[PATCH v8 00/19] plugins: Allow to read registers
Posted by Akihiko Odaki 9 months, 1 week ago
Based-on: <20230912224107.29669-1-akihiko.odaki@daynix.com>
("[PATCH v3 00/12] gdbstub and TCG plugin improvements")

I and other people in the University of Tokyo, where I research processor
design, found TCG plugins are very useful for processor design exploration.

The feature we find missing is the capability to read registers from
plugins. In this series, I propose to add such a capability by reusing
gdbstub code.

The reuse of gdbstub code ensures the long-term stability of the TCG plugin
interface for register access without incurring a burden to maintain yet
another interface for register access.

This process to add TCG plugin involves four major changes. The first one
is to add GDBFeature structure that represents a GDB feature, which usually
includes registers. GDBFeature can be generated from static XML files or
dynamically generated by architecture-specific code. In fact, this is a
refactoring independent of the feature this series adds, and potentially
it's benefitial even without the plugin feature. The plugin feature will
utilize this new structure to describe registers exposed to plugins.

The second one is to make gdb_read_register/gdb_write_register usable
outside of gdbstub context.

The third one is to actually make registers readable for plugins.

The last one is to allow to implement a QEMU plugin in C++. A plugin that
I'll describe later is written in C++.

The below is a summary of patches:
Patch [01, 12] introduces num_regs member to GDBFeature.
Patch 13 adds members useful to identify registers to GDBFeature.
Patch 14 makes registers readable outside of gdbstub context.
Patch [15, 17] add the feature to read registers from plugins.
Patch [18, 19] make it possible to write plugins in C++.

V7 -> V8:
  Rebased to "[PATCH v3 00/12] gdbstub and TCG plugin improvements".
  Clarified that initialization and exit hooks affect TCG state.
  Simplified by adding the core feature to gdb_regs.

V6 -> V7:
  Rebased to "[PATCH v2 00/11] gdbstub and TCG plugin improvements".
  Replaced functions to get register identifiers.

V5 -> V6:
  Rebased to "[PATCH 0/8] gdbstub and TCG plugin improvements".

V4 -> V5:
  Corrected g_rw_lock_writer_lock() call. (Richard Henderson)
  Replaced abort() with g_assert_not_reached(). (Richard Henderson)
  Fixed CSR name leak in target/riscv. (Richard Henderson)
  Removed gdb_has_xml variable.

V3 -> V4:
  Added execlog changes I forgot to include in the last version.

V2 -> V3:
  Added patch "hw/core/cpu: Return static value with gdb_arch_name()".
  Added patch "gdbstub: Dynamically allocate target.xml buffer".
  (Alex Bennée)
  Added patch "gdbstub: Introduce GDBFeatureBuilder". (Alex Bennée)
  Dropped Reviewed-by tags for "target/*: Use GDBFeature for dynamic XML".
  Changed gdb_find_static_feature() to abort on failure. (Alex Bennée)
  Changed the execlog plugin to log the register value only when changed.
  (Alex Bennée)
  Dropped 0x prefixes for register value logs for conciseness.

V1 -> V2:
  Added SPDX-License-Identifier: GPL-2.0-or-later. (Philippe Mathieu-Daudé)
  Split long lines. (Philippe Mathieu-Daudé)
  Renamed gdb_features to gdb_static_features (Philippe Mathieu-Daudé)
  Dropped RFC.

The execlog plugin will have new options to demonstrate the new feature.
I also have a plugin that uses this new feature to generate execution
traces for Sniper processor simulator, which is available at:
https://github.com/shioya-lab/sniper/tree/akihikodaki/bb

Akihiko Odaki (19):
  gdbstub: Add num_regs member to GDBFeature
  gdbstub: Introduce gdb_find_static_feature()
  gdbstub: Introduce GDBFeatureBuilder
  target/arm: Use GDBFeature for dynamic XML
  target/ppc: Use GDBFeature for dynamic XML
  target/riscv: Use GDBFeature for dynamic XML
  gdbstub: Use GDBFeature for gdb_register_coprocessor
  gdbstub: Use GDBFeature for GDBRegisterState
  gdbstub: Change gdb_get_reg_cb and gdb_set_reg_cb
  gdbstub: Simplify XML lookup
  gdbstub: Infer number of core registers from XML
  hw/core/cpu: Remove gdb_get_dynamic_xml member
  gdbstub: Add members to identify registers to GDBFeature
  gdbstub: Expose functions to read registers
  cpu: Call plugin hooks only when ready
  plugins: Allow to read registers
  contrib/plugins: Allow to log registers
  plugins: Support C++
  contrib/plugins: Add cc plugin

 docs/devel/tcg-plugins.rst   |  18 ++-
 configure                    |  15 ++-
 include/exec/gdbstub.h       |  39 ++++++-
 include/hw/core/cpu.h        |   7 +-
 include/qemu/qemu-plugin.h   |  56 ++++++++-
 target/arm/cpu.h             |  27 ++---
 target/arm/internals.h       |  14 +--
 target/hexagon/internal.h    |   4 +-
 target/microblaze/cpu.h      |   4 +-
 target/ppc/cpu-qom.h         |   4 +-
 target/ppc/cpu.h             |   3 +-
 target/riscv/cpu.h           |   5 +-
 target/s390x/cpu.h           |   2 -
 contrib/plugins/execlog.c    | 120 ++++++++++++++-----
 cpu.c                        |  11 --
 gdbstub/gdbstub.c            | 216 ++++++++++++++++++++++++++--------
 hw/core/cpu-common.c         |  15 ++-
 plugins/api.c                |  20 ++++
 target/arm/cpu.c             |   2 -
 target/arm/cpu64.c           |   1 -
 target/arm/gdbstub.c         | 221 +++++++++++++++++------------------
 target/arm/gdbstub64.c       | 117 +++++++++----------
 target/avr/cpu.c             |   1 -
 target/hexagon/cpu.c         |   4 +-
 target/hexagon/gdbstub.c     |  10 +-
 target/i386/cpu.c            |   2 -
 target/loongarch/cpu.c       |   2 -
 target/loongarch/gdbstub.c   |  13 ++-
 target/m68k/cpu.c            |   1 -
 target/m68k/helper.c         |  26 +++--
 target/microblaze/cpu.c      |   6 +-
 target/microblaze/gdbstub.c  |   9 +-
 target/ppc/cpu_init.c        |   5 +-
 target/ppc/gdbstub.c         | 108 ++++++++---------
 target/riscv/cpu.c           |  15 ---
 target/riscv/gdbstub.c       | 135 +++++++++++----------
 target/rx/cpu.c              |   1 -
 target/s390x/cpu.c           |   1 -
 target/s390x/gdbstub.c       | 105 ++++++++++-------
 contrib/plugins/Makefile     |   5 +
 contrib/plugins/cc.cc        |  17 +++
 plugins/qemu-plugins.symbols |   3 +
 scripts/feature_to_c.py      |  58 ++++++++-
 tests/tcg/Makefile.target    |   3 +
 44 files changed, 921 insertions(+), 530 deletions(-)
 create mode 100644 contrib/plugins/cc.cc

-- 
2.42.0